Example #1
0
void printOutput(HumdrumFile& hfile) {
   Array<double> tempo;
   hfile.analyzeTempoMarkings(tempo, tdefault);

   double currentmillisecond = 0.0;
   double lastduration = 0.0;

   double linestarttime = 0.0;
   double lineendtime = 0.0;

   int founddata = 0;

   int metlev;
   int i, j, k;
   char buffer1[1024] = {0};
   char buffer2[1024] = {0};
   double duration;
   for (i=0; i<hfile.getNumLines(); i++) {
      currentmillisecond = currentmillisecond + 
            lastduration * 60000.0 / tempo[i];
      lastduration = hfile[i].getDuration();

      if (hfile[i].getType() == E_humrec_global_comment) {
         cout << "%% " << &(hfile[i].getLine()[3]) << endl;
      }

      if (hfile[i].getType() == E_humrec_bibliography) {
         cout << "%%%" << &(hfile[i].getLine()[3]) << endl;
      }


      if (hfile[i].getType() != E_humrec_data) {
         continue;
      }

      if (debugQ) {
         cout << "RECORD: " << hfile[i] << endl;
      }

      if (founddata == 0) {
         founddata = 1;

         comment(cout, 2, humdrumQ);
         cout << " Data column information:\n";
         comment(cout, 3, humdrumQ);
         cout << "col01: abstime\t" << 
                 "(average absolute time in milliseconds of human "
              << "beats)\n";
         comment(cout, 3, humdrumQ);
         cout << "col02: duration\t" <<
                 "(expected duration in ms based "
              << "on score duration)\n";
         comment(cout, 3, humdrumQ);
         cout << "col03: note\t\t" << 
                 "(MIDI note number of pitch)\n";
         comment(cout, 3, humdrumQ);
         cout << "col04: metlev\t" << 
                 "(metric level: 1 = downbeat; "
              <<  "0 = beat; -1 = offbeat)\n";
         comment(cout, 3, humdrumQ);
         cout << "col05: measure\t" <<
                  "(measure number in which note occurs)\n";
         comment(cout, 3, humdrumQ);
         cout << "col06: absbeat\t" <<
                 "(absolute beat from starting beat at 0)\n";
         comment(cout, 3, humdrumQ);
         cout << "col07: trackno\t" << 
                 "(hand which plays the note: 1 = left; 2=right)\n";
	 if (!auxdataQ) {
            comment(cout, 3, humdrumQ);
            cout << "col08: mintime\t" << 
                    "(minimum absolute time of human beat for this note)\n";
            comment(cout, 3, humdrumQ);
            cout << "col09: maxtime\t" << 
                    "(maximum absolute time of human beat for this note)\n";
            comment(cout, 3, humdrumQ);
            cout << "col10: sd\t\t" << 
                    "(standard deviation of human beat time in ms.)\n";
	 } else {
            //comment(cout, 3, humdrumQ);
            //cout << "col08: paccid\t" <<
	    //	    "(printed accidental 0=none, -1=flat, +1=sharp, 10=nat)\n";
            comment(cout, 3, humdrumQ);
            cout << "col08: saccid\t" <<
		    "(sounding accidental 0=natural, -1=flat, +1=sharp)\n";
         }
		   
         if (humdrumQ) {
            cout << "**start\t**dur\t**key\t**metr\t**meas\t**absb\t**track\t**saccid\n";
         }
      }
	        

      linestarttime = -1.0;
      // find current time value and save 
      for (j=0; j<hfile[i].getFieldCount(); j++) {
         if (strcmp(hfile[i].getExInterp(j), "**time") == 0) {
            sscanf(hfile[i][j], "%lf", &linestarttime);
            break;
         }
      }

      for (j=0; j<hfile[i].getFieldCount(); j++) {
         if (hfile[i].getExInterpNum(j) != E_KERN_EXINT) {
            continue;
         }

         for (k=0; k<hfile[i].getTokenCount(j); k++) {
            if (strcmp(hfile[i][j], ".") == 0) {
               continue;
            }
            hfile[i].getToken(buffer1, j, k);
            if (strchr(buffer1, '_') != NULL) {
               // ignore notes which are tied
               continue;
            }
            if (strchr(buffer1, ']') != NULL) {
               // ignore notes which are tied
               continue;
            }

            preparePitch(buffer2, buffer1);
            duration = hfile.getTiedDuration(i, j, k);
            lineendtime = getEndTime(hfile, i, duration);

            int note = Convert::kernToMidiNoteNumber(buffer2);
            if (classQ) {
               note = note % 12;
            }
            if (note < 0) {
               // don't display rests.
               continue;
            }
            if (note < 0 || note > 127) {
               cerr << "Error reading MIDI pitch number from string: " 
                    << buffer2 << endl;
               exit(1);
            }

            //cout << "Note\t";
            // cout << hfile.getAbsBeat(i) << "\t";
            // cout << (int)(currentmillisecond+0.5) << "\t";
            cout << linestarttime << "\t";

            if (debugQ && (lineendtime - linestarttime < 0)) {
               cerr << "Error duration of note on line: " << hfile[i] << endl;
               cerr << "Starttime: " << linestarttime << endl;
               cerr << "Endtime:   " << lineendtime << endl;
               cerr << "Line Index:     " << i << endl;
               exit(1);
            } 
            if (lineendtime != -1) {
               cout << lineendtime - linestarttime << "\t";
            } else {
               cout << (int)(getTimeToEnd(hfile, linestarttime, i) + 0.5) 
                    << "\t";
            }

            cout << note;

            cout << "\t";
            
            metlev = getMetricLevel(hfile, i);
            cout << metlev;

            cout << "\t" << getMeasureNum(hfile, i);

            cout << "\t" << hfile[i].getAbsBeat();

            // you must make sure that the spine order is
            // correct or this data will be bad
            cout << "\t" << hfile[i].getPrimaryTrack(j)-1;
   
            cout << "\t"; 
	    printSaccid(cout, buffer2);
 
            cout << "\n";
         }
      }
   }

   if (humdrumQ) {
      cout << "*-\t*-\t*-\t*-\t*-\t*-\t*-\t*-\n";
   }
}
Example #2
0
void printOutput(HumdrumFile& hfile) {
   Array<double> tempo;
   hfile.analyzeTempoMarkings(tempo, tdefault);

   double currentmillisecond = 0.0;
   double lastduration = 0.0;
   double endmillisecond;

   int i, j, k;
   char buffer1[1024] = {0};
   char buffer2[1024] = {0};
   double duration;
   for (i=0; i<hfile.getNumLines(); i++) {
      currentmillisecond = currentmillisecond + 
            lastduration * 60000.0 / tempo[i];
      lastduration = hfile[i].getDuration();

      if (hfile[i].getType() == E_humrec_global_comment) {
         cout << "Comment\t" << &(hfile[i].getLine()[3]) << endl;
      }

      if (hfile[i].getType() == E_humrec_bibliography) {
         cout << "Reference " << &(hfile[i].getLine()[3]) << endl;
      }

      if (hfile[i].getType() == E_humrec_interpretation) {
         for (j=0; j<hfile[i].getFieldCount(); j++) {
            if (hfile[i].getExInterpNum(j) != E_KERN_EXINT) {
               continue;
            }
            int direction = 0;
            int acount = 0;
            if (strncmp(hfile[i][j], "*k[", 3) == 0) {
               if (strchr(hfile[i][j], '-') != NULL) {
                  direction = -1;
               } else if (strchr(hfile[i][j], '#') != NULL) {
                  direction = 1;
               }
               acount = (strlen(hfile[i][j]) - 4)/2;
               if (direction == 0) {
                  cout << "Info keysig no accidentals" << endl;
                  break;
               } else {
                  cout << "Info keysig " << acount;
                  if (acount < 0) {
                     cout << " flat";
                  } else {
                     cout << " sharp";
                  }
                  if (acount > 1) {
                     cout << "s";
                  }
                  cout << endl;
                  break;
               }
            }
         }
      }

      // look for key interpretations
      if (hfile[i].getType() == E_humrec_interpretation) {
         for (j=0; j<hfile[i].getFieldCount(); j++) {
            if (hfile[i].getExInterpNum(j) != E_KERN_EXINT) {
               continue;
            }
            int length = strlen(hfile[i][j]);
            if (length < 3 || length > 4) {
               continue;
            }
            if (hfile[i][j][length-1] == ':') {
               cout << "Info key ";
               cout << (char)toupper(hfile[i][j][1]);
               if (hfile[i][j][2] == '-') {
                  cout << "-flat";
               }
               if (hfile[i][j][2] == '#') {
                  cout << "-sharp";
               }
               if (std::islower(hfile[i][j][1])) {
                  cout << " Minor";
               } else {
                  cout << " Major";
               }
               cout << endl;
               break;
            }
         }
      }

      // look for tempo markings
      if (hfile[i].getType() == E_humrec_interpretation) {
         for (j=0; j<hfile[i].getFieldCount(); j++) {
            if (hfile[i].getExInterpNum(j) != E_KERN_EXINT) {
               continue;
            }
            double tempomark = 0.0;
            if (strncmp(hfile[i][j], "*MM", 3) == 0 && 
                  std::isdigit(hfile[i][j][3])) {
               sscanf(hfile[i][j], "*MM%lf", &tempomark);
               cout << "Info Tempo " << tempomark << " MM per quarter note" 
                    << endl;
               break;
            }
         }
      }

      if (hfile[i].getType() != E_humrec_data) {
         continue;
      }

      for (j=0; j<hfile[i].getFieldCount(); j++) {
         if (hfile[i].getExInterpNum(j) != E_KERN_EXINT) {
            continue;
         }

         for (k=0; k<hfile[i].getTokenCount(j); k++) {
            if (strcmp(hfile[i][j], ".") == 0) {
               continue;
            }
            hfile[i].getToken(buffer1, j, k);
            if (strchr(buffer1, '_') != NULL) {
               // ignore notes which are tied
               continue;
            }
            if (strchr(buffer1, ']') != NULL) {
               // ignore notes which are tied
               continue;
            }

            preparePitch(buffer2, buffer1);
            duration = hfile.getTiedDuration(i, j, k);

            int note = Convert::kernToMidiNoteNumber(buffer2);
            if (classQ) {
               note = note % 12;
            }
            if (note < 0) {
               // don't display rests.
               continue;
            }

            cout << "Note\t";
            // cout << hfile.getAbsBeat(i) << "\t";
            cout << (int)(currentmillisecond+0.5) << "\t";

            // cout << duration << "\t";
            endmillisecond = currentmillisecond + duration * 60000 / tempo[i];
            if (int(endmillisecond+0.5) == int(currentmillisecond+0.5)) {
               // give grace notes 1 millisecond duration...
               cout << (int)(endmillisecond+0.5)+1 << "\t";
            } else {
               cout << (int)(endmillisecond+0.5) << "\t";
            }

            cout << note;

            cout << "\n";
         }
      }
   }
}