Browse Source

cmXScore.h/c : Moved edit file processing into cmXScoreInitialize().

master
kevin 8 years ago
parent
commit
8e4f32c0c1
2 changed files with 113 additions and 119 deletions
  1. 106
    101
      app/cmXScore.c
  2. 7
    18
      app/cmXScore.h

+ 106
- 101
app/cmXScore.c View File

@@ -1842,89 +1842,6 @@ cmXsRC_t _cmXScoreProcessGraceNotes( cmXScore_t* p )
1842 1842
   return rc;
1843 1843
 }
1844 1844
 
1845
-cmXsRC_t cmXScoreInitialize( cmCtx_t* ctx, cmXsH_t* hp, const cmChar_t* xmlFn )
1846
-{
1847
-  cmXsRC_t rc = kOkXsRC;
1848
-
1849
-  if((rc = cmXScoreFinalize(hp)) != kOkXsRC )
1850
-    return rc;
1851
-
1852
-  cmXScore_t* p = cmMemAllocZ(cmXScore_t,1);
1853
-
1854
-  cmErrSetup(&p->err,&ctx->rpt,"XScore");
1855
-
1856
-  // create a local linked heap
1857
-  if( cmLHeapIsValid( p->lhH = cmLHeapCreate(8196,ctx)) == false )
1858
-    return cmErrMsg(&p->err,kLHeapFailXsRC,"Lheap create failed.");
1859
-
1860
-  // open the music xml file
1861
-  if( cmXmlAlloc(ctx, &p->xmlH, xmlFn) != kOkXmlRC )
1862
-  {
1863
-    rc = cmErrMsg(&p->err,kXmlFailXsRC,"Unable to open the MusicXML file '%s'.",cmStringNullGuard(xmlFn));
1864
-    goto errLabel;
1865
-  }
1866
-
1867
-  //cmXmlPrint(p->xmlH,&ctx->rpt);
1868
-
1869
-  // parse the part-list
1870
-  if((rc = _cmXScoreParsePartList( p )) != kOkXsRC )
1871
-    goto errLabel;
1872
-
1873
-  // parse each score 'part'
1874
-  cmXsPart_t* pp = p->partL;
1875
-  for(; pp!=NULL; pp=pp->link)
1876
-    if((rc = _cmXScoreParsePart(p,pp)) != kOkXsRC )
1877
-      goto errLabel;
1878
-
1879
-  // fill in the note->slink chain to link the notes in each measure in time order
1880
-  _cmXScoreSort(p);
1881
-
1882
-  _cmXScoreSpreadGraceNotes(p);
1883
-
1884
-  _cmXScoreSort(p);
1885
-
1886
-  _cmXScoreResolveTiesAndLoc(p);
1887
-
1888
-  _cmXScoreRemoveDuplicateNotes(p);
1889
-
1890
-  _cmXScoreSetMeasGroups(p,kEvenXsFl);
1891
-  _cmXScoreSetMeasGroups(p,kDynXsFl);
1892
-  _cmXScoreSetMeasGroups(p,kTempoXsFl);
1893
-
1894
-  //_cmXScoreResolveOctaveShift(p);
1895
-
1896
-  // CSV output initialize failed.
1897
-  if( cmCsvInitialize(&p->csvH,ctx) != kOkCsvRC )
1898
-    rc = cmErrMsg(&p->err,kCsvFailXsRC,"CSV output object create failed.");
1899
-
1900
- errLabel:
1901
-  if( rc != kOkXsRC )
1902
-    _cmXScoreFinalize(p);
1903
-  else
1904
-    hp->h = p;
1905
-
1906
-  return rc;
1907
-}
1908
-
1909
-cmXsRC_t cmXScoreFinalize( cmXsH_t* hp )
1910
-{
1911
-  cmXsRC_t rc = kOkXsRC;
1912
-
1913
-  if( hp == NULL || cmXScoreIsValid(*hp)==false )
1914
-    return kOkXsRC;
1915
-
1916
-  cmXScore_t* p = _cmXScoreHandleToPtr(*hp);
1917
-
1918
-  if((rc = _cmXScoreFinalize(p)) != kOkXsRC )
1919
-    return rc;
1920
-
1921
-  hp->h = NULL;
1922
-
1923
-  return rc;
1924
-}
1925
-
1926
-bool     cmXScoreIsValid( cmXsH_t h )
1927
-{ return h.h != NULL; }
1928 1845
 
1929 1846
 //-------------------------------------------------------------------------------------------
1930 1847
 
@@ -2365,12 +2282,11 @@ cmXsRC_t  _cmXScoreReorderParsePitch(cmXScore_t* p, const cmChar_t* b, unsigned
2365 2282
   return rc;  
2366 2283
 }
2367 2284
 
2368
-cmXsRC_t cmXScoreReorder( cmXsH_t h, const cmChar_t* fn )
2285
+cmXsRC_t _cmXsApplyEditFile( cmXScore_t* p, const cmChar_t* fn )
2369 2286
 {
2370 2287
   typedef enum { kFindMeasStId, kFindEventStId, kReadEventStId } stateId_t;
2371 2288
 
2372 2289
   cmXsRC_t      rc       = kOkXsRC;
2373
-  cmXScore_t*   p        = _cmXScoreHandleToPtr(h);
2374 2290
   cmFileH_t     fH       = cmFileNullHandle;
2375 2291
   cmChar_t*     b        = NULL;
2376 2292
   unsigned      bN       = 0;
@@ -2538,6 +2454,107 @@ cmXsRC_t cmXScoreReorder( cmXsH_t h, const cmChar_t* fn )
2538 2454
 
2539 2455
 
2540 2456
 
2457
+cmXsRC_t cmXScoreInitialize( cmCtx_t* ctx, cmXsH_t* hp, const cmChar_t* xmlFn, const cmChar_t* editFn )
2458
+{
2459
+  cmXsRC_t rc = kOkXsRC;
2460
+
2461
+  if((rc = cmXScoreFinalize(hp)) != kOkXsRC )
2462
+    return rc;
2463
+
2464
+  cmXScore_t* p = cmMemAllocZ(cmXScore_t,1);
2465
+
2466
+  cmErrSetup(&p->err,&ctx->rpt,"XScore");
2467
+
2468
+  // create a local linked heap
2469
+  if( cmLHeapIsValid( p->lhH = cmLHeapCreate(8196,ctx)) == false )
2470
+    return cmErrMsg(&p->err,kLHeapFailXsRC,"Lheap create failed.");
2471
+
2472
+  // open the music xml file
2473
+  if( cmXmlAlloc(ctx, &p->xmlH, xmlFn) != kOkXmlRC )
2474
+  {
2475
+    rc = cmErrMsg(&p->err,kXmlFailXsRC,"Unable to open the MusicXML file '%s'.",cmStringNullGuard(xmlFn));
2476
+    goto errLabel;
2477
+  }
2478
+
2479
+  //cmXmlPrint(p->xmlH,&ctx->rpt);
2480
+
2481
+  // parse the part-list
2482
+  if((rc = _cmXScoreParsePartList( p )) != kOkXsRC )
2483
+    goto errLabel;
2484
+
2485
+  // parse each score 'part'
2486
+  cmXsPart_t* pp = p->partL;
2487
+  for(; pp!=NULL; pp=pp->link)
2488
+    if((rc = _cmXScoreParsePart(p,pp)) != kOkXsRC )
2489
+      goto errLabel;
2490
+
2491
+  // fill in the note->slink chain to link the notes in each measure in time order
2492
+  _cmXScoreSort(p);
2493
+
2494
+  _cmXScoreSpreadGraceNotes(p);
2495
+
2496
+  _cmXScoreSort(p);
2497
+
2498
+  _cmXScoreResolveTiesAndLoc(p);
2499
+
2500
+  _cmXScoreRemoveDuplicateNotes(p);
2501
+
2502
+  _cmXScoreSetMeasGroups(p,kEvenXsFl);
2503
+  _cmXScoreSetMeasGroups(p,kDynXsFl);
2504
+  _cmXScoreSetMeasGroups(p,kTempoXsFl);
2505
+
2506
+  //_cmXScoreResolveOctaveShift(p);
2507
+
2508
+  // CSV output initialize failed.
2509
+  if( cmCsvInitialize(&p->csvH,ctx) != kOkCsvRC )
2510
+    rc = cmErrMsg(&p->err,kCsvFailXsRC,"CSV output object create failed.");
2511
+
2512
+  if( editFn != NULL )
2513
+  {
2514
+    if((rc = _cmXsApplyEditFile(p,editFn)) != kOkXsRC )
2515
+    {
2516
+      cmErrMsg(&ctx->err,rc,"XScore reorder failed.");
2517
+      goto errLabel;
2518
+    }
2519
+  }
2520
+
2521
+  // assign durations to pedal down events
2522
+  _cmXScoreProcessPedals(p);
2523
+
2524
+  // remove some notes which share a pitch and are overlapped or embedded within another note.
2525
+  _cmXScoreProcessOverlappingNotes(p);
2526
+
2527
+  
2528
+ errLabel:
2529
+  if( rc != kOkXsRC )
2530
+    _cmXScoreFinalize(p);
2531
+  else
2532
+    hp->h = p;
2533
+
2534
+  return rc;
2535
+}
2536
+
2537
+cmXsRC_t cmXScoreFinalize( cmXsH_t* hp )
2538
+{
2539
+  cmXsRC_t rc = kOkXsRC;
2540
+
2541
+  if( hp == NULL || cmXScoreIsValid(*hp)==false )
2542
+    return kOkXsRC;
2543
+
2544
+  cmXScore_t* p = _cmXScoreHandleToPtr(*hp);
2545
+
2546
+  if((rc = _cmXScoreFinalize(p)) != kOkXsRC )
2547
+    return rc;
2548
+
2549
+  hp->h = NULL;
2550
+
2551
+  return rc;
2552
+}
2553
+
2554
+bool     cmXScoreIsValid( cmXsH_t h )
2555
+{ return h.h != NULL; }
2556
+
2557
+
2541 2558
 
2542 2559
 
2543 2560
 /* CSV score columns
@@ -3626,32 +3643,21 @@ cmXsRC_t _cmXScoreGenSvg( cmCtx_t* ctx, cmXsH_t h, const cmChar_t* dir, const cm
3626 3643
   return _cmXsWriteMidiSvg( ctx, p, &mf, dir, fn );
3627 3644
 }
3628 3645
 
3646
+
3629 3647
 cmXsRC_t cmXScoreTest(
3630 3648
   cmCtx_t* ctx,
3631 3649
   const cmChar_t* xmlFn,
3632
-  const cmChar_t* reorderFn,
3650
+  const cmChar_t* editFn,
3633 3651
   const cmChar_t* csvOutFn,
3634 3652
   const cmChar_t* midiOutFn)
3635 3653
 {
3636 3654
   cmXsRC_t rc;
3637 3655
   cmXsH_t h = cmXsNullHandle;
3638 3656
 
3639
-  if((rc = cmXScoreInitialize( ctx, &h, xmlFn)) != kOkXsRC )
3657
+  // Parse the XML file and apply the changes in editFn.
3658
+  if((rc = cmXScoreInitialize( ctx, &h, xmlFn,editFn)) != kOkXsRC )
3640 3659
     return cmErrMsg(&ctx->err,rc,"XScore alloc failed.");
3641 3660
 
3642
-  if( reorderFn != NULL )
3643
-    if((rc = cmXScoreReorder(h,reorderFn)) != kOkXsRC )
3644
-    {
3645
-      cmErrMsg(&ctx->err,rc,"XScore reorder failed.");
3646
-      goto errLabel;
3647
-    }
3648
-
3649
-  // assign durations to pedal down events
3650
-  _cmXScoreProcessPedals(_cmXScoreHandleToPtr(h));
3651
-
3652
-  // remove some notes which share a pitch and are overlapped or embedded within another note.
3653
-  _cmXScoreProcessOverlappingNotes(_cmXScoreHandleToPtr(h));
3654
-
3655 3661
   if( csvOutFn != NULL )
3656 3662
   {
3657 3663
     cmScH_t scH = cmScNullHandle;
@@ -3694,7 +3700,6 @@ cmXsRC_t cmXScoreTest(
3694 3700
   
3695 3701
   //cmXScoreReport(h,&ctx->rpt,true);
3696 3702
 
3697
- errLabel:
3698 3703
   return cmXScoreFinalize(&h);
3699 3704
 
3700 3705
 }

+ 7
- 18
app/cmXScore.h View File

@@ -43,26 +43,15 @@ extern "C" {
43 43
   //
44 44
   // M-x load-file ~/src/emacs/proc_music_xml.el
45 45
   //
46
-  // 3) How to assigned dynamic markings (they are not attached to notes). (from MIDI file?)
47
-  // 4) Tempo syntax is inconsistent (only a problem in full part2 score)     
48
-  // 5) Heel is being parsed but not used. 
49
-  // 6) Sostenuto pedal events are not being parsed because they are not pedal events.
50
-  // 7) What is a 'pedal-change' event vs. a 'pedal-stop' event.
51
-  // 8) Verify the colors. (done)
52
-  // 9) Remove blank bars at end (done in xml - do in score)
53
-  //10) Need to assign section targets (always default to next section)
54
-  //11) Mark tied notes for skip. (done)
55
-  //12) Determine note off locations based on ties and slurs - defer 'pedal' to player
56
-  //13) Check that the measures are given in sorted order.
57
-  //14) Current implementation assumes meter changes only occur at measure boundaries.
58
-  //15) Score Fixes: Add meter to bar 1, fix time errors (shown in voice report)
59
-  //16) The order of notes is now correct (4/6/16) after applying
60
-  //    the grace note ordering changed specified in 'score_print_mk_edit.txt',
61
-  //    via cmXScoreReorder() however the ticks are now incorrect - fix them.
62
-  
63
-  cmXsRC_t cmXScoreInitialize( cmCtx_t* ctx, cmXsH_t* hp, const cmChar_t* xmlFn );
46
+
47
+  // Initialize an cmXScore object from a Sibelius generated MusicXML file.
48
+  // Optionally include an 'edit' file to attach additional score information.
49
+  // Note that the 'edit' file is created by marking up a file created via
50
+  // cmXScoreReport().
51
+  cmXsRC_t cmXScoreInitialize( cmCtx_t* ctx, cmXsH_t* hp, const cmChar_t* xmlFn, const cmChar_t* editFn );
64 52
   cmXsRC_t cmXScoreFinalize( cmXsH_t* hp );
65 53
 
54
+  
66 55
   bool     cmXScoreIsValid( cmXsH_t h );
67 56
 
68 57
   cmXsRC_t cmXScoreWriteCsv( cmXsH_t h, const cmChar_t* csvFn );

Loading…
Cancel
Save