Requires functions.cpp, which contains command line I/O functions.
#include "../include/sequencer.h"
#include "../include/manager.h"
#include "../include/notifier.h"
#include "../include/filereadmultitrack.h"
#include "functions.h"
using namespace std;
extern string command, par1, par2;
const char helpstring[] =
"\nAvailable commands:\n\
load filename : Loads the file into the sequencer\n\
ports : Enumerates MIDI In and OUT ports\n\
play : Starts playback from current time\n\
loop meas1 meas2 : Sets loop play (doesn't start it!) from\n\
meas1 to meas2. Give 0 0 for non loop play\n\
stop : Stops playback\n\
rew : Goes to the beginning (stops the playback)\n\
goto meas [beat] : Moves current time to given meas and beat\n\
(numbered from 0)\n\
playmode u/b : Sets the play mode (bounded or unbounded)\n\
dump [trk] : Prints a dump of all midi events in the file\n\
(or in the track trk)\n\
outport track port : Sets the MIDI port for the given track\n\
tscale scale : Sets global tempo scale. scale is in percent\n\
(ex. 200 = twice faster, 50 = twice slower)\n\
tshift track amt : Sets the time shift for given track. The amount can\n\
be positive or negative.\n\
trackinfo [v] : Shows info about all tracks of the file. If you\n\
add the v the info are more complete.\n\
notify on/off : Turns on and off the notifier\n\
b : (backward) Moves current time to the previous measure\n\
f : (forward) Moves current time to the next measure\n\
help : Prints this help screen\n\
quit : Exits\n\
All commands can be given during playback\n";
int main(int argc, char **argv) {
cout << "TYPE help TO GET A LIST OF AVAILABLE COMMANDS" << endl << endl;
while (command != "quit") {
GetCommand();
if(command == "")
continue;
if (command == "load") {
cout << "Loaded file " << par1 << endl;
else
cout << "Error loading file" << endl;
sequencer.Reset();
}
else if (command == "ports") {
cout << "MIDI IN PORTS:" << endl;
}
else
cout << "NO MIDI IN PORTS" << endl;
cout << "MIDI OUT PORTS:" << endl;
}
else
cout << "NO MIDI OUT PORTS" << endl;
}
else if (command == "play") {
sequencer.Play();
cout << "Sequencer started at measure: " << sequencer.GetCurrentMeasure() << ":"
<< sequencer.GetCurrentBeat() << endl;
}
else if (command == "loop") {
int beg = atoi(par1.c_str());
int end = atoi(par2.c_str());
if (!(beg == 0 && end == 0)) {
if (sequencer.SetRepeatPlay(true, beg, end))
cout << "Repeat play set from measure " << beg << " to measure " << end << endl;
else
cout << "Invalid parameters: repeat play cleared" << endl;
}
else {
sequencer.SetRepeatPlay(false, 0, 0);
cout << "Repeat play cleared" << endl;
}
}
else if (command == "stop") {
sequencer.Stop();
cout << "Sequencer stopped at measure: " << sequencer.GetCurrentMeasure() << ":"
<< sequencer.GetCurrentBeat() << endl;
}
else if (command == "rew") {
sequencer.Stop();
sequencer.GoToZero();
cout << "Rewind to 0:0" << endl;
}
else if (command == "goto") {
int meas = atoi(par1.c_str());
int beat = atoi (par2.c_str());
if (sequencer.GoToMeasure(meas, beat))
cout << "Actual position: " << sequencer.GetCurrentMeasure() << ":"
<< sequencer.GetCurrentBeat() << endl;
else
cout << "Invalid position" << endl;
}
else if (command == "playmode") {
if (par1 == "u") {
cout << "Set sequencer play mode to UNBOUNDED" << endl;
}
else if (par1 == "b") {
cout << "Set sequencer play mode to BOUNDED" << endl;
}
else
cout << "Invalid parameter" << endl;
}
else if (command == "dump") {
if (par1.size() == 0)
DumpMIDIMultiTrackWithPauses(&multitrack);
else {
int trk_num = atoi(par1.c_str());
DumpMIDITrackWithPauses(trk, trk_num);
}
else
cout << "Invalid track number" << endl;
}
}
else if (command == "outport") {
int trk_num = atoi(par1.c_str());
int port = atoi(par2.c_str());
if (sequencer.SetTrackOutPort(trk_num, port))
cout << "Assigned out port n. " << sequencer.GetTrackOutPort(trk_num)
<< " to track " << trk_num << endl;
else
cout << "Invalid parameters" << endl;
}
else if (command == "tscale") {
int scale = atoi(par1.c_str());
sequencer.SetTempoScale(scale);
cout << "Tempo scale : " << scale << "% " <<
" Effective tempo: " << sequencer.GetTempoWithScale() << " bpm" << endl;
}
else if (command == "tshift") {
int trk_num = atoi(par1.c_str());
int amount = atoi(par2.c_str());
sequencer.SetTrackTimeShift(trk_num, amount);
cout << "Track " << trk_num << " time shifted by " << amount << " MIDI ticks" << endl;
}
else if (command == "trackinfo") {
bool verbose = (par1 == "v");
DumpAllTracksAttr(&multitrack, verbose);
}
else if (command == "notify") {
if (par1 == "on") {
cout << "Notifier on" << endl;
}
else if (par1 == "off") {
cout << "Notifier off" << endl;
}
}
else if (command == "b") {
int meas = sequencer.GetCurrentMeasure();
if (sequencer.GoToMeasure(--meas))
cout << "Actual position: " << sequencer.GetCurrentMeasure() << ":"
<< sequencer.GetCurrentBeat() << endl;
}
else if (command == "f") {
int meas = sequencer.GetCurrentMeasure();
if (sequencer.GoToMeasure(++meas))
cout << "Actual position: " << sequencer.GetCurrentMeasure() << ":"
<< sequencer.GetCurrentBeat() << endl;
}
else if (command == "help")
cout << helpstring;
else if (command != "quit")
cout << "Unrecognized command" << endl;
}
return EXIT_SUCCESS;
}
static unsigned int GetNumMIDIOuts()
Returns the number of MIDI out ports in the system.
static const std::string & GetMIDIInName(unsigned int n)
Returns the system name of the given MIDI in port.
static unsigned int GetNumMIDIIns()
Returns the number of MIDI in ports in the system.
static const std::string & GetMIDIOutName(unsigned int n)
Returns the system name of the given MIDI out port.
Holds an array of pointers to MIDITrack objects to be played simultaneously.
Definition: multitrack.h:50
bool IsValidTrackNumber(unsigned int trk_num) const
Returns true if trk_num is in thee range 0 ... GetNumTracks() - 1.
Definition: multitrack.h:96
MIDITrack * GetTrack(unsigned int trk_num)
Returns the pointer to the track.
Definition: multitrack.h:79
virtual void SetEnable(bool f)
Sets message sending on/off.
Definition: notifier.h:179
A MIDISequencerGUINotifier which sends text messages to a std::ostream (std::cout as default).
Definition: notifier.h:191
A MIDITickComponent which implements a basic sequencer, able to play the MIDI events contained in a M...
Definition: sequencer.h:193
@ PLAY_BOUNDED
See SetPlayMode()
Definition: sequencer.h:478
@ PLAY_UNBOUNDED
See SetPlayMode()
Definition: sequencer.h:479
Manages a std::vector of MIDITimedMessage objects storing MIDI events, with methods for editing them.
Definition: track.h:86
bool LoadMIDIFile(const char *filename, MIDIMultiTrack *tracks, MIDIFileHeader *const head=0)
Loads a MIDI file into a MIDIMultiTrack object.