Browse Source

cmXScore.c : Changed to fix problem with dynamic forks interpretation.

master
kevin larke 7 years ago
parent
commit
4461d1c128
1 changed files with 47 additions and 23 deletions
  1. 47
    23
      app/cmXScore.c

+ 47
- 23
app/cmXScore.c View File

33
 
33
 
34
 #include "cmSvgWriter.h"
34
 #include "cmSvgWriter.h"
35
 
35
 
36
+
37
+
36
 cmXsH_t cmXsNullHandle = cmSTATIC_NULL_HANDLE;
38
 cmXsH_t cmXsNullHandle = cmSTATIC_NULL_HANDLE;
37
 
39
 
38
 enum
40
 enum
1880
 }
1882
 }
1881
 
1883
 
1882
 
1884
 
1883
-cmXsNote_t* _cmXScoreDynamicForkEndNote( cmXsNote_t* bnp )
1885
+cmXsNote_t* _cmXScoreDynamicForkEndNote( cmXScore_t* p, cmXsNote_t* bnp )
1884
 {
1886
 {
1885
   assert( cmIsFlag(bnp->flags,kDynBegForkXsFl) );
1887
   assert( cmIsFlag(bnp->flags,kDynBegForkXsFl) );
1886
 
1888
 
1891
   {    
1893
   {    
1892
     for(; np!=NULL; np=np->slink)
1894
     for(; np!=NULL; np=np->slink)
1893
     {
1895
     {
1894
-      if( cmIsFlag(np->flags,kDynEndForkXsFl) && np->voice->id == bnp->voice->id )
1896
+      if( cmIsFlag(np->flags,kDynBegForkXsFl) )
1897
+      {
1898
+        cmErrMsg(&p->err,kSyntaxErrorXsRC,"The a dynamic fork begin (meas:%i loc:%i) was found prior to a matched end.",np->meas->number,np->locIdx);
1899
+        return NULL;
1900
+      }   
1901
+        
1902
+      if( cmIsFlag(np->flags,kDynEndForkXsFl) /*&& np->voice->id == bnp->voice->id*/ )
1895
         return np;
1903
         return np;
1896
     }
1904
     }
1897
   }
1905
   }
1903
 {
1911
 {
1904
   cmXsNote_t* enp;
1912
   cmXsNote_t* enp;
1905
 
1913
 
1906
-  if((enp = _cmXScoreDynamicForkEndNote(bnp)) == NULL)
1907
-    return cmErrMsg(&p->err,kSyntaxErrorXsRC,"The dynamic fork beginning in measure %i at tick %i voice %i was not terminated.", bnp->meas->number,bnp->tick,bnp->voice->id);
1908
-
1914
+  if((enp = _cmXScoreDynamicForkEndNote(p,bnp)) == NULL)
1915
+    return cmErrMsg(&p->err,kSyntaxErrorXsRC,"The dynamic fork beginning in measure %i at tick %i voice %i loc:%i was not terminated.", bnp->meas->number,bnp->tick,bnp->voice->id,bnp->locIdx);
1909
 
1916
 
1917
+  //cmRptPrintf( p->err.rpt, "Dynamic Fork: meas:%i tick:%i loc:%i to meas:%i tick:%i loc:%i\n", bnp->meas->number, bnp->tick, bnp->locIdx, enp->meas->number, enp->tick, enp->locIdx );
1918
+  
1910
   double begDynFrac = bnp->dynamics;
1919
   double begDynFrac = bnp->dynamics;
1911
   double begVelFrac = bnp->vel;
1920
   double begVelFrac = bnp->vel;
1912
   double endDynFrac = enp->dynamics;
1921
   double endDynFrac = enp->dynamics;
1915
   cmXsMeas_t* mp = bnp->meas;
1924
   cmXsMeas_t* mp = bnp->meas;
1916
   cmXsNote_t* np = bnp->slink;
1925
   cmXsNote_t* np = bnp->slink;
1917
 
1926
 
1918
-  for(; mp!=NULL && np!=enp; mp=mp->link,np=mp==NULL ? NULL : mp->noteL)
1927
+  while( mp != NULL )
1919
   {
1928
   {
1920
-    for(; np!=NULL && np!=enp; np=np->slink)
1921
-
1922
-      /*
1923
-
1924
-        Conditioning this on np->dynamics==0 will may cause 'silent' notes to be assigned 
1925
-        a non-zero dynamics value - this is best fixed by using a different special value
1926
-        for silent notes
1927
-
1928
-        BUG BUG BUG BUG BUG
1929
+    for(; np!=NULL; np=np->slink)
1930
+    {
1929
 
1931
 
1930
-       */       
1931
-      if( np->voice == bnp->voice && np->dynamics == 0 )
1932
+      //Conditioning this on np->dynamics==0 will may would cause 'silent' notes to be assigned 
1933
+      //  a non-zero dynamics value - so we condition on np->vel instead.
1934
+      if( cmIsFlag(np->flags,kOnsetXsFl) && np->vel == 0 )
1932
       {
1935
       {
1933
         double frac     = ((double)np->tick - bnp->tick) / (enp->tick - bnp->tick);
1936
         double frac     = ((double)np->tick - bnp->tick) / (enp->tick - bnp->tick);
1934
         np->dynamics =  lround(begDynFrac + ((endDynFrac - begDynFrac) * frac));
1937
         np->dynamics =  lround(begDynFrac + ((endDynFrac - begDynFrac) * frac));
1935
         np->vel      =  lround(begVelFrac + ((endVelFrac - begVelFrac) * frac));        
1938
         np->vel      =  lround(begVelFrac + ((endVelFrac - begVelFrac) * frac));        
1936
       }
1939
       }
1940
+
1941
+      if( np == enp )
1942
+        break;
1943
+    }
1944
+
1945
+    if( np == enp)
1946
+      break;
1947
+        
1948
+    if( (mp=mp->link) != NULL )
1949
+      np=mp->noteL;
1937
   }
1950
   }
1938
 
1951
 
1939
   return kOkXsRC;
1952
   return kOkXsRC;
3203
 
3216
 
3204
   if( note->graceGroupId != 0)
3217
   if( note->graceGroupId != 0)
3205
     cmRptPrintf(rpt," g=%i",note->graceGroupId);
3218
     cmRptPrintf(rpt," g=%i",note->graceGroupId);
3219
+
3220
+  if( note->dynamics != 0)
3221
+    cmRptPrintf(rpt," dyn=%i %i",note->dynamics,note->vel);
3222
+  
3206
   /*
3223
   /*
3207
   if( cmIsFlag(note->flags,kBegGraceXsFl) )
3224
   if( cmIsFlag(note->flags,kBegGraceXsFl) )
3208
     cmRptPrintf(rpt," B");
3225
     cmRptPrintf(rpt," B");
3210
   if( cmIsFlag(note->flags,kEndGraceXsFl) )
3227
   if( cmIsFlag(note->flags,kEndGraceXsFl) )
3211
     cmRptPrintf(rpt," E");
3228
     cmRptPrintf(rpt," E");
3212
 
3229
 
3213
-  if( note->dynamics != 0)
3214
-    cmRptPrintf(rpt," dyn=%i",note->dynamics);
3215
 
3230
 
3216
   if( cmIsFlag(note->flags,kDynBegForkXsFl) )
3231
   if( cmIsFlag(note->flags,kDynBegForkXsFl) )
3217
     cmRptPrintf(rpt," B");
3232
     cmRptPrintf(rpt," B");
3563
       if( mp->divisions != ticksPerQN )
3578
       if( mp->divisions != ticksPerQN )
3564
         cmErrWarnMsg(&p->err,kMidiFailXsRC,"The 'tick per quarter note' (divisions) field in measure %i does not match the value in the first measure (%i).",mp->divisions,ticksPerQN);
3579
         cmErrWarnMsg(&p->err,kMidiFailXsRC,"The 'tick per quarter note' (divisions) field in measure %i does not match the value in the first measure (%i).",mp->divisions,ticksPerQN);
3565
 
3580
 
3581
+      unsigned ni = 0;
3566
       // for each note in this measure
3582
       // for each note in this measure
3567
-      for(; np!=NULL; np=np->slink)
3583
+      for(; np!=NULL; np=np->slink,++ni)
3568
       {
3584
       {
3569
         switch( np->flags & (kOnsetXsFl|kMetronomeXsFl|kDampDnXsFl|kDampUpDnXsFl|kSostDnXsFl) )
3585
         switch( np->flags & (kOnsetXsFl|kMetronomeXsFl|kDampDnXsFl|kDampUpDnXsFl|kSostDnXsFl) )
3570
         {
3586
         {
3572
             {
3588
             {
3573
               if( np->tied_dur <= 0 )
3589
               if( np->tied_dur <= 0 )
3574
                 cmErrWarnMsg(&p->err,kOkXsRC,"A zero length note was encountered bar:%i tick:%i %s",np->meas->number,np->tick,cmMidiToSciPitch(np->pitch,NULL,0));
3590
                 cmErrWarnMsg(&p->err,kOkXsRC,"A zero length note was encountered bar:%i tick:%i %s",np->meas->number,np->tick,cmMidiToSciPitch(np->pitch,NULL,0));
3591
+
3592
+              /*
3593
+              if( mp->number == 20 )
3594
+              {
3595
+                _cmXScoreReportNote(ctx->err.rpt,np,ni);
3596
+                cmRptPrintf(ctx->err.rpt,"\n");
3597
+              }
3598
+              */
3575
               
3599
               
3576
               if( cmMidiFileInsertTrackChMsg(mfH, 1, np->tick,                kNoteOnMdId,  np->pitch, np->vel ) != kOkMfRC
3600
               if( cmMidiFileInsertTrackChMsg(mfH, 1, np->tick,                kNoteOnMdId,  np->pitch, np->vel ) != kOkMfRC
3577
                 ||cmMidiFileInsertTrackChMsg(mfH, 1, np->tick + np->tied_dur, kNoteOffMdId, np->pitch, 0 )       != kOkMfRC )
3601
                 ||cmMidiFileInsertTrackChMsg(mfH, 1, np->tick + np->tied_dur, kNoteOffMdId, np->pitch, 0 )       != kOkMfRC )
3732
       // if this is a note
3756
       // if this is a note
3733
       case kOnsetXsFl:
3757
       case kOnsetXsFl:
3734
         {
3758
         {
3735
-          const cmChar_t* classLabel = "note";
3759
+          //const cmChar_t* classLabel = "note";
3736
       
3760
       
3737
           t0 = cmTsPrintfP(t0,"note_%i%s",e->voice, cmIsFlag(e->flags,kGraceXsFl) ? "_g":"");
3761
           t0 = cmTsPrintfP(t0,"note_%i%s",e->voice, cmIsFlag(e->flags,kGraceXsFl) ? "_g":"");
3738
       
3762
       
3739
-          if( cmIsFlag(e->flags,kGraceXsFl) )
3740
-            classLabel = "grace";
3763
+          //if( cmIsFlag(e->flags,kGraceXsFl) )
3764
+          //  classLabel = "grace";
3741
       
3765
       
3742
           if( cmSvgWriterRect(svgH, e->tick, e->d0 * noteHeight,  e->durTicks,  noteHeight-1, t0 ) != kOkSvgRC )
3766
           if( cmSvgWriterRect(svgH, e->tick, e->d0 * noteHeight,  e->durTicks,  noteHeight-1, t0 ) != kOkSvgRC )
3743
             rc = kSvgFailXsRC;
3767
             rc = kSvgFailXsRC;

Loading…
Cancel
Save