NiCMidi 1.1.0
A MIDI library derived from J.D.Koftinoff jdksmidi
Loading and playing MIDI files

If you only want to load and play MIDI files you can use the AdvancedSequencer class.

It is an all-in-one object easy to use and with all the common features of a sequencer. These include:

  • Loading MIDI files
  • Playing and stopping the file at any time
  • Jumping from a time to another, even when playing
  • Muting, soloing, transposing, velocity scaling for individual tracks
  • MIDI out port assign and time shifting for individual tracks
  • Global tempo scaling
  • Embeds a MIDIThru object, so you can play along with the sequencer

Here is a simple example of its usage:

#include "timer.h" // for Wait()
int main() {
AdvancedSequencer seq; // creates the AdvancedSequencer
seq.Load("twinkle.mid"); // loads a MIDI file into it
seq.Play(); // plays the file
while (seq.IsPlaying()) // waits until the end (the sequencer auto stops)
MIDITimer::Wait(10); // 10 msecs
return 0;
}
Contains the definition of the classes MIDISequencerTrackProcessor and AdvancedSequencer.
An enhanced MIDISequencer, able to directly load and play MIDI files and many more.
Definition: advancedsequencer.h:93
virtual bool Load(const char *fname)
Loads a MIDIFile into the internal MIDIMultiTrack.
virtual void Play()
This is an alias of Start().
Definition: sequencer.h:455
bool IsPlaying() const
Returns true if the callback procedure is active.
Definition: tick.h:92
static void Wait(unsigned int msecs)
Stops the calling thread for the given number of milliseconds.
Definition: timer.h:105
Contains the definition of the MIDITimer class and some other typedef related to MIDI timing.

Here is a more complex example using some of the class features (in a real environment you could do these commands interactively) while the sequencer is playing:

#include "timer.h" // for Wait()
int main() {
AdvancedSequencer seq; // creates the AdvancedSequencer
seq.Load("twinkle.mid"); // loads a MIDI file into it
seq.Play(); // plays the file
while(seq.GetCurrentMeasure() < 4) // waits until measure 4
MIDITimer::Wait(10); // 10 msecs
seq.SetTrackTranspose(1, 12); // transposes track 1 by one octave up
while(seq.GetCurrentMeasure() < 8)
seq.SetTrackMute(1, true); // mutes track 1
while(seq.GetCurrentMeasure() < 12)
seq.SetTrackSolo(2); // soloes track 2 ...
seq.SetTempoScale(200); // ... and doubles the tempo
while(seq.IsPlaying() // waits until the end
return 0;
}
bool SetTrackMute(unsigned int trk_num, bool f)
Mutes/unmutes the given track (it has no effect on others).
bool SetTrackSolo(unsigned int trk_num)
Soloes the given track muting all others.
bool SetTrackTranspose(unsigned int trk_num, int amt)
Sets a transpose amount in semitones for the given track.
unsigned int GetCurrentMeasure() const
Returns the current measure number (first is 0). See Numbering conventions.
virtual bool SetTempoScale(unsigned int scale)
Sets the global tempo scale.

You can see two more elaborated examples that let you interact with the class: