Browse Source

cmXScore.h/c : Added _cmXScoreWriteScorePlotFile() and _cmXSCoreWriteMidiPlotFile().

master
kevin 8 years ago
parent
commit
dbc6c77c17
2 changed files with 83 additions and 14 deletions
  1. 81
    13
      app/cmXScore.c
  2. 2
    1
      app/cmXScore.h

+ 81
- 13
app/cmXScore.c View File

272
   unsigned midi = cmSciPitchToMidi(buf);
272
   unsigned midi = cmSciPitchToMidi(buf);
273
 
273
 
274
   midi         += (12 * octave);
274
   midi         += (12 * octave);
275
-
276
   midi         += alter;
275
   midi         += alter;
277
 
276
 
278
-  np->pitch = midi;
279
-  np->step  = *step;
277
+  np->pitch  = midi;
278
+  np->step   = *step;
280
   np->octave = octave;
279
   np->octave = octave;
281
   np->alter  = alter;
280
   np->alter  = alter;
282
   np->flags |= kOnsetXsFl;
281
   np->flags |= kOnsetXsFl;
945
   return note;
944
   return note;
946
 }
945
 }
947
 
946
 
947
+cmXsRC_t _cmXScoreWriteScorePlotFile( cmXScore_t* p, const cmChar_t* fn )
948
+{
949
+  cmXsRC_t  rc            = kOkXsRC;
950
+  cmFileH_t fH            = cmFileNullHandle;
951
+  double    ticks_per_sec = 0;
952
+  double    onset_secs    = 0;
953
+  
954
+  if( cmFileOpen(&fH,fn,kWriteFileFl,p->err.rpt) != kOkFileRC )
955
+    return cmErrMsg(&p->err,kFileFailXsRC,"Unable to create the file '%s'.",cmStringNullGuard(fn));
956
+  
957
+  cmXsPart_t* pp = p->partL;
958
+  for(; pp!=NULL; pp=pp->link)
959
+  {
960
+    cmXsMeas_t* mp   = pp->measL;
961
+    for(; mp!=NULL; mp=mp->link)
962
+    {
963
+      cmFilePrintf(fH,"b %f %i %s B\n",onset_secs,mp->number,"bar");
964
+
965
+      cmXsNote_t* np    = mp->noteL;
966
+      unsigned    tick0 = 0;
967
+      for(; np!=NULL; np=np->slink)
968
+      {
969
+        if( cmIsFlag(np->flags,kMetronomeXsFl) )
970
+        {
971
+          double bps =  np->duration / 60.0;
972
+
973
+          // t   b  t
974
+          // - = -  -
975
+          // s   s  b
976
+          
977
+          ticks_per_sec = bps * mp->divisions; 
978
+        }
979
+        else
980
+        {
981
+          if( cmIsFlag(np->flags,kOnsetXsFl) )
982
+          {
983
+            onset_secs += (np->tick - tick0) / ticks_per_sec;
984
+            tick0       = np->tick;
985
+            cmFilePrintf(fH,"n %f %f %s %s\n",onset_secs,np->duration/ticks_per_sec,cmMidiToSciPitch(np->pitch,NULL,0),cmIsFlag(np->flags,kGraceXsFl)?"G":"N");
986
+          }
987
+        }
988
+      }
989
+
990
+      onset_secs += (mp->divisions * mp->beats - tick0) / ticks_per_sec;
991
+    }
992
+  }
993
+
994
+  cmFileClose(&fH);
995
+
996
+  return rc;
997
+}
998
+
999
+cmXsRC_t _cmXScoreWriteMidiPlotFile( cmXScore_t* p, cmChar_t* fn, const cmMidiTrackMsg_t** m, unsigned mN )
1000
+{
1001
+  cmXsRC_t  rc = kOkXsRC;
1002
+  cmFileH_t fH = cmFileNullHandle;
1003
+  unsigned  i  = 0;
1004
+  
1005
+  if( cmFileOpen(&fH,fn,kWriteFileFl,p->err.rpt) != kOkFileRC )
1006
+    return cmErrMsg(&p->err,kFileFailXsRC,"Unable to create the file '%s'.",cmStringNullGuard(fn));
1007
+
1008
+  for(i=0; i<mN; ++i)
1009
+    if( (m[i]!=NULL) && cmMidiIsChStatus(m[i]->status) && cmMidiIsNoteOn(m[i]->status) && (m[i]->u.chMsgPtr->d1>0) )
1010
+      cmFilePrintf(fH,"n %f %f %s\n",m[i]->amicro/1000000.0,m[i]->u.chMsgPtr->durMicros/1000000.0,cmMidiToSciPitch(m[i]->u.chMsgPtr->d0,NULL,0));
1011
+
1012
+  
1013
+  cmFileClose(&fH);
1014
+  return rc;
1015
+}
1016
+
948
 
1017
 
949
 cmXsRC_t    _cmXScoreProcessMidi(cmXScore_t* p, cmCtx_t* ctx, const cmChar_t* midiFn)
1018
 cmXsRC_t    _cmXScoreProcessMidi(cmXScore_t* p, cmCtx_t* ctx, const cmChar_t* midiFn)
950
 {
1019
 {
999
       j = i;
1068
       j = i;
1000
     }
1069
     }
1001
 
1070
 
1071
+  cmMidiFileCalcNoteDurations( mfH );
1072
+  
1073
+  _cmXScoreWriteScorePlotFile(p, "/Users/kevin/temp/score.txt" );
1074
+  _cmXScoreWriteMidiPlotFile(p,  "/Users/kevin/temp/midi.txt", m, mN );
1075
+
1076
+
1002
   cmSeqAlignReport(s,p->err.rpt);
1077
   cmSeqAlignReport(s,p->err.rpt);
1003
   cmSeqAlignFree(&s);
1078
   cmSeqAlignFree(&s);
1004
   cmCtxFree(&c);
1079
   cmCtxFree(&c);
1032
   return rc;
1107
   return rc;
1033
 }
1108
 }
1034
 
1109
 
1035
-
1036
 cmXsRC_t cmXScoreInitialize( cmCtx_t* ctx, cmXsH_t* hp, const cmChar_t* xmlFn, const cmChar_t* midiFn )
1110
 cmXsRC_t cmXScoreInitialize( cmCtx_t* ctx, cmXsH_t* hp, const cmChar_t* xmlFn, const cmChar_t* midiFn )
1037
 {
1111
 {
1038
   cmXsRC_t rc = kOkXsRC;
1112
   cmXsRC_t rc = kOkXsRC;
1436
           }
1510
           }
1437
         
1511
         
1438
         rowIdx += 1;
1512
         rowIdx += 1;
1439
-        
1440
-
1441
       }
1513
       }
1442
 
1514
 
1443
       sec = sec0;
1515
       sec = sec0;
1444
-    }
1445
-    
1516
+    }    
1446
   }
1517
   }
1447
 
1518
 
1448
   if( cmCsvWrite( p->csvH, csvFn ) != kOkCsvRC )
1519
   if( cmCsvWrite( p->csvH, csvFn ) != kOkCsvRC )
1503
 
1574
 
1504
         }
1575
         }
1505
       }
1576
       }
1506
-
1507
-      
1508
-  
1509
-
1510
     }
1577
     }
1511
   }  
1578
   }  
1512
 }
1579
 }
1513
 
1580
 
1581
+
1514
 cmXsRC_t cmXScoreWriteMidi( cmXsH_t h, const cmChar_t* fn )
1582
 cmXsRC_t cmXScoreWriteMidi( cmXsH_t h, const cmChar_t* fn )
1515
 {
1583
 {
1516
   assert(0); // function not implemented
1584
   assert(0); // function not implemented
1541
     return cmErrMsg(&ctx->err,rc,"XScore alloc failed.");
1609
     return cmErrMsg(&ctx->err,rc,"XScore alloc failed.");
1542
 
1610
 
1543
   cmXScoreWriteCsv(h,"/Users/kevin/temp/a0.csv");
1611
   cmXScoreWriteCsv(h,"/Users/kevin/temp/a0.csv");
1544
-  cmXScoreReport(h,&ctx->rpt,true);
1612
+  cmXScoreReport(h,&ctx->rpt,false);
1545
   
1613
   
1546
   return cmXScoreFinalize(&h);
1614
   return cmXScoreFinalize(&h);
1547
 
1615
 

+ 2
- 1
app/cmXScore.h View File

15
     kUnterminatedTieXsRC,
15
     kUnterminatedTieXsRC,
16
     kUnterminatedSlurXsRC,
16
     kUnterminatedSlurXsRC,
17
     kUnterminatedOctaveShiftXsrRC,
17
     kUnterminatedOctaveShiftXsrRC,
18
-    kMidiFailXsRC
18
+    kMidiFailXsRC,
19
+    kFileFailXsRC
19
   };
20
   };
20
 
21
 
21
   typedef cmRC_t     cmXsRC_t;
22
   typedef cmRC_t     cmXsRC_t;

Loading…
Cancel
Save