Midifile View on GitHub

Note list


Print a list of note attacks in a MIDI file The following example program will print a list of all note-ons in the MIDI file. The notes are will be time sorted, and each note will be prefixed with the absolute time tick value.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "MidiFile.h"
#include "Options.h"
#include <iostream>
using namespace std;

int main(int argc, char** argv) {
   Options options;
   options.process(argc, argv);
   if (options.getArgCount() != 1) {
      cerr << "At least one MIDI filename is required.\n";
      exit(1);
   }
   MidiFile midifile;
   midifile.read(options.getArg(1));
   if (!midifile.status()) {
      cerr << "Error reading MIDI file " << options.getArg(1)) << endl;
      exit(1);
   }
   midifile.joinTracks();
   int track = 0;
   for (int i=0; i<midifile[track].size(); i++) {
      if (!midifile[track][i].isNoteOn()) {
         continue;
      }
      cout << midifile[track][i].time 
           << '\t' << midifile[track][i][1] 
           << endl;
   }
}
Library functions used in this example:
  • MidiEventList::operator[]
  • MidiFile::absoluteTime
  • MidiFile::joinTracks
  • MidiFile::operator[]
  • MidiFile::read
  • MidiFile::size
  • MidiFile::status
  • MidiMessage::isNoteOn
  • MidiMessage::operator[]
  • Options::getArg
  • Options::getArgCount
  • Options::process