Exemplo n.º 1
0
void printMidiEvent(MidiEvent& event) {
   // print the time:
   cout << "v" << event.tick << "\t";

   // print the command byte in hex format (two digits):
   int commandbyte = event[0];
   printHexByte(commandbyte);
   int i;

   switch (commandbyte & 0xf0) {
   case 0x90:
   case 0x80:
      for (i=1; i<(int)event.size(); i++) {
         cout << " ";
         printDecByte(event[i]);
      }
      break;
   default:
      for (i=1; i<(int)event.size(); i++) {
         cout << " ";
         printHexByte(event[i]);
      }
   }

   cout << endl;
}
Exemplo n.º 2
0
MidiEvent::MidiEvent(const MidiEvent& mfevent) {
   tick  = mfevent.tick;
   track = mfevent.track;
   eventlink = NULL;
   this->resize(mfevent.size());
   for (int i=0; i<this->size(); i++) {
      (*this)[i] = mfevent[i];
   }
}
Exemplo n.º 3
0
MidiEvent::MidiEvent(const MidiEvent& mfevent) : MidiMessage() {
	track   = mfevent.track;
	tick    = mfevent.tick;
	seconds = mfevent.seconds;
	seq     = mfevent.seq;
	m_eventlink = NULL;

	this->resize(mfevent.size());
	for (int i=0; i<(int)this->size(); i++) {
		(*this)[i] = mfevent[i];
	}
}
Exemplo n.º 4
0
int getTrackByteCount(MidiFile& midifile, int track) {
   int sum = 0;
   int i;
   int eventcount = midifile.getEventCount(track);
   MidiEvent event;

   for (i=0; i<eventcount; i++) {
      event = midifile.getEvent(track, i);
      sum += getVlvSize(event.tick);
      sum += event.size();
   }
   return sum;
}
Exemplo n.º 5
0
void processMidiFile(MidiFile& midifile) {
   midifile.absoluteTicks();
   midifile.joinTracks();
   int i, j;
   int eventcount = midifile.getEventCount(0);
   int track;
   int timeinticks;
   double timeinsecs;
   MidiEvent *ptr;
   int attack;
   for (i=0; i<eventcount; i++) {
      ptr = &(midifile[0][i]);
      track       = ptr->track;
      timeinticks = ptr->tick;
      timeinsecs  = midifile.getTimeInSeconds(0, i);
      attack = ((*ptr)[0] & 0xf0) == 0x90;
      if (onsetQ && !attack) {
         continue;
      }
      if (onsetQ && attack) {
         if ((*ptr)[2] == 0) {
            continue;
         }
      }
      
      cout << timeinticks << "\t";
      cout << timeinsecs << "\t";
      cout << track << "\t";
      cout << i << "\t";
      for (j=0; j<(int)ptr->size(); j++) {
         if (j == 0) {
            cout << "0x" << hex << (int)(*ptr)[j] << dec << " ";
         } else {
            cout << (int)(*ptr)[j] << " ";
         }
      }
      cout << endl;
   }
}
Exemplo n.º 6
0
void processEvent(MidiEvent& event, double& tempo, double& curtime) {
   int i;

   if (((event[0] & 0xf0) == 0x80) || (((event[0] & 0xf0) == 0x90) &&
         (event[2] == 0)) ) {
      // note-off MIDI message
      if (track >= 0 && track != event.track) { return; }
      cout << "NoteOff\t\t=";
      cout.width(9);
      cout.setf(ios::left);
      cout << curtime << "\t" << event.track << "\t"
           << (int)event[1] << "\t" << (int)event[2] << endl;
   } else if ((event[0] & 0xf0) == 0x90) {
      // note-on MIDI message
      if (track >= 0 && track != event.track) { return; }
      cout << "NoteOn\t\t=";
      cout.width(9);
      cout.setf(ios::left);
      cout << curtime << "\t" << event.track << "\t"
           << (int)event[1] << "\t" << (int)event[2] << endl;
   } else if ((event[0] & 0xf0) == 0xb0) {
      // continuous controller MIDI message
      if (track >= 0 && track != event.track) { return; }
      if (event[1] == 7) {
         cout << "Volume\t\t=";
         cout.width(9);
         cout.setf(ios::left);
         cout << curtime << "\t" << event.track << "\t"
              << "\t" << (int)event[2] << endl;
      } else {
         cout << "ControlChange\t=";
         cout.width(9);
         cout.setf(ios::left);
         cout << curtime << "\t" << event.track << "\t"
              << (int)event[1] << "\t" << (int)event[2] << endl;
      }
   } else if ((event.size() > 3) && (event[0] == 0xff) &&
         (event[1] == 0x51)) {
      // Tempo meta event
      int microseconds = (unsigned int)event[3];
      microseconds = microseconds << 8;
      microseconds |= (unsigned int)event[4];
      microseconds = microseconds << 8;
      microseconds |= (unsigned int)event[5];
      tempo = 1000000.0 / microseconds * 60.0;
      cout << "// time:=" << curtime << " tempo: " << tempo << endl;
   } else if ((event.size() > 3) && (event[0] == 0xff) &&
         (event[1] == 0x03)) {
      // Track name MIDI meta event
      if (track >= 0 && track != event.track) { return; }
      cout << "//";
      cout << " time:=" << curtime;
      cout << " track:" << event.track;
      cout << " text: ";
      for (i=3; i<(int)event.size(); i++) {
         cout << (char)event[i];
      }
      cout << endl;
   } else {
      // a MIDI event with an unknown mapping into SKINI, print as comment
      if (track >= 0 && track != event.track) { return; }
      cout << "//"
           << " time:=" << curtime
           << " track:" << event.track
           << " midi-data: ";
      for (i=0; i<(int)event.size(); i++) {
           cout << (int)event[i] << " ";
      }
      cout << endl;
   }
}