Ejemplo n.º 1
0
int main(int argc, char** argv) {
   options.setOptions(argc, argv);
   checkOptions(options);

   int status;
   MidiFile midifile;
   if (options.getArgCount()) {
      status = midifile.read(options.getArg(1));
   } else {
      status = midifile.read(cin);
   }
   if (status == 0) {
      cerr << "Error: could not read MIDI file" << endl;
      exit(1);
   }

   int tpq = midifile.getTicksPerQuarterNote();
   midifile.linkNotePairs();
   if (joinQ) {
      midifile.joinTracks();
   }
   MidiEvent* mev;
   double duration;

   if (secondsQ) {
      midifile.doTimeAnalysis();
   }

   if (secondsQ) {
      cout << "SEC\tDUR\tTRACK\tNOTE\n";
   } else if (quarterQ) {
      cout << "QTRS\tDUR\tTRACK\tNOTE\n";
   } else {
      cout << "TICKS\tDUR\tTRACK\tNOTE\n";
   }
   cout << "============================\n";

   for (int track=0; track < midifile.getTrackCount(); track++) {
      for (int i=0; i<midifile[track].size(); i++) {
         mev = &midifile[track][i];
         if (!mev->isNoteOn()) {
            continue;
         }
         if (secondsQ) {
            duration = mev->getDurationInSeconds();
         } else {
            duration = mev->getTickDuration();
         }

         if (secondsQ) {
            cout << mev->seconds << '\t';
            cout << duration << '\t';
         } else if (quarterQ) {
            cout << mev->tick/tpq << '\t';
            cout << duration/tpq << '\t';
         } else {
            cout << mev->tick << '\t';
            cout << duration << '\t';
         }
         cout << mev->track << '\t';
         cout << mev->getKeyNumber();
         cout << endl;
      }
      if (midifile.getTrackCount() > 1) {
         cout << endl;
      }
   }

   return 0;
}