Explorar el Código

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

master
kevin hace 8 años
padre
commit
dbc6c77c17
Se han modificado 2 ficheros con 83 adiciones y 14 borrados
  1. 81
    13
      app/cmXScore.c
  2. 2
    1
      app/cmXScore.h

+ 81
- 13
app/cmXScore.c Ver fichero

@@ -272,11 +272,10 @@ cmXsRC_t  _cmXScoreParsePitch( cmXScore_t* p, const cmXmlNode_t* nnp, cmXsNote_t
272 272
   unsigned midi = cmSciPitchToMidi(buf);
273 273
 
274 274
   midi         += (12 * octave);
275
-
276 275
   midi         += alter;
277 276
 
278
-  np->pitch = midi;
279
-  np->step  = *step;
277
+  np->pitch  = midi;
278
+  np->step   = *step;
280 279
   np->octave = octave;
281 280
   np->alter  = alter;
282 281
   np->flags |= kOnsetXsFl;
@@ -945,6 +944,76 @@ cmXsNote_t* _cmXScoreNextNote( cmXsPart_t* pp, cmXsNote_t* note )
945 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 1018
 cmXsRC_t    _cmXScoreProcessMidi(cmXScore_t* p, cmCtx_t* ctx, const cmChar_t* midiFn)
950 1019
 {
@@ -999,6 +1068,12 @@ cmXsRC_t    _cmXScoreProcessMidi(cmXScore_t* p, cmCtx_t* ctx, const cmChar_t* mi
999 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 1077
   cmSeqAlignReport(s,p->err.rpt);
1003 1078
   cmSeqAlignFree(&s);
1004 1079
   cmCtxFree(&c);
@@ -1032,7 +1107,6 @@ cmXsRC_t    _cmXScoreProcessMidi(cmXScore_t* p, cmCtx_t* ctx, const cmChar_t* mi
1032 1107
   return rc;
1033 1108
 }
1034 1109
 
1035
-
1036 1110
 cmXsRC_t cmXScoreInitialize( cmCtx_t* ctx, cmXsH_t* hp, const cmChar_t* xmlFn, const cmChar_t* midiFn )
1037 1111
 {
1038 1112
   cmXsRC_t rc = kOkXsRC;
@@ -1436,13 +1510,10 @@ cmXsRC_t cmXScoreWriteCsv( cmXsH_t h, const cmChar_t* csvFn )
1436 1510
           }
1437 1511
         
1438 1512
         rowIdx += 1;
1439
-        
1440
-
1441 1513
       }
1442 1514
 
1443 1515
       sec = sec0;
1444
-    }
1445
-    
1516
+    }    
1446 1517
   }
1447 1518
 
1448 1519
   if( cmCsvWrite( p->csvH, csvFn ) != kOkCsvRC )
@@ -1503,14 +1574,11 @@ void  cmXScoreReport( cmXsH_t h, cmRpt_t* rpt, bool sortFl )
1503 1574
 
1504 1575
         }
1505 1576
       }
1506
-
1507
-      
1508
-  
1509
-
1510 1577
     }
1511 1578
   }  
1512 1579
 }
1513 1580
 
1581
+
1514 1582
 cmXsRC_t cmXScoreWriteMidi( cmXsH_t h, const cmChar_t* fn )
1515 1583
 {
1516 1584
   assert(0); // function not implemented
@@ -1541,7 +1609,7 @@ cmXsRC_t cmXScoreTest( cmCtx_t* ctx, const cmChar_t* xmlFn, const cmChar_t* midi
1541 1609
     return cmErrMsg(&ctx->err,rc,"XScore alloc failed.");
1542 1610
 
1543 1611
   cmXScoreWriteCsv(h,"/Users/kevin/temp/a0.csv");
1544
-  cmXScoreReport(h,&ctx->rpt,true);
1612
+  cmXScoreReport(h,&ctx->rpt,false);
1545 1613
   
1546 1614
   return cmXScoreFinalize(&h);
1547 1615
 

+ 2
- 1
app/cmXScore.h Ver fichero

@@ -15,7 +15,8 @@ extern "C" {
15 15
     kUnterminatedTieXsRC,
16 16
     kUnterminatedSlurXsRC,
17 17
     kUnterminatedOctaveShiftXsrRC,
18
-    kMidiFailXsRC
18
+    kMidiFailXsRC,
19
+    kFileFailXsRC
19 20
   };
20 21
 
21 22
   typedef cmRC_t     cmXsRC_t;

Loading…
Cancelar
Guardar