|
@@ -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
|
}
|