Requires functions.cpp, which contains command line I/O functions.
#include "../include/manager.h"
#include "../include/metronome.h"
#include "functions.h"
using namespace std;
extern string command, par1, par2;
const char helpstring[] =
"\nAvailable commands:\n\
ports : Enumerates MIDI In and OUT ports\n\
start : Starts the metronome\n\
stop : Stops the metronome\n\
tempo bpm : Sets the metronome tempo (bpm is a float)\n\
tscale scale : Sets global tempo scale. scale is in percent\n\
(ex. 200 = twice faster, 50 = twice slower)\n\
subd n : Sets the number of subdivisions (n can be\n\
0, 2, 3, 4, 5, 6, 0 disables subdivisions)\n\
meas n : Sets the number of beats of a measure (0 disables\n\
measure clicks)\n\
measnote nn : Sets the MIDI note for first beat of the measure\n\
beatnote nn : Sets the MIDI note for ordinary beats\n\
subdnote nn : Sets the MIDI note for subdivisions\n\
outport port : Sets the MIDI out port\n\
outchan ch : Sets the MIDI out channel\n\
status : Prints the status of the metronome\n\
help : Prints this help screen\n\
quit : Exits\n\
MIDI channels are numbered 0 .. 15\n\
All commands can be given during playback\n";
int main( int argc, char **argv ) {
try {
}
catch( ... ) {
cout << "The Metronome constructor throws an exception if in the system is not present\n" <<
"almost a MIDI out port!\n" <<
"Press a key to quit\n";
cin.get();
return EXIT_SUCCESS;
}
cout << "TYPE help TO GET A LIST OF AVAILABLE COMMANDS\n\n";
while (command != "quit") {
GetCommand();
if(command == "")
continue;
if (command == "ports") {
cout << "MIDI IN PORTS:" << endl;
}
else
cout << "NO MIDI IN PORTS" << endl;
cout << "MIDI OUT PORTS:" << endl;
}
else if (command == "start") {
cout << "Metronome started" << endl;
}
else if (command == "stop") {
}
else if (command == "tempo") {
float tempo = atof(par1.c_str());
cout << "Tempo set to " << tempo <<
}
else
cout << "Invalid tempo" << endl;
}
else if (command == "tscale") {
int scale = atoi(par1.c_str());
cout << "Tempo scale : " << scale <<
}
else
cout << "Invalid tempo scale" << endl;
}
else if (command == "subd") {
unsigned int type = atoi(par1.c_str());
if (type == 0)
cout << "Subdivision click disabled" << endl;
else
cout << "Number of subdivisions set to " << type << endl;
}
else
cout << "Invalid number of subdivisions" << endl;
}
else if (command == "meas") {
unsigned int beats = atoi(par1.c_str());
if (beats == 0)
cout << "First beat disabled" << endl;
else
cout << "Beats set to " << beats << endl;
}
else if (command == "measnote") {
unsigned int note = atoi(par1.c_str()) & 0x7f;
cout << "First beat note set to " << note << endl;
}
else if (command == "beatnote") {
unsigned int note = atoi(par1.c_str()) & 0x7f;
cout << "Beat note set to " << note << endl;
}
else if (command == "subdnote") {
unsigned int note = atoi(par1.c_str()) & 0x7f;
cout << "Subdivision note set to " << note << endl;
}
else if (command == "outport") {
int port = atoi(par1.c_str());
cout << "Assigned out port n. " << port << endl;
else
cout << "Invalid port number" << endl;
}
else if (command == "outchan") {
int chan = atoi(par1.c_str());
cout << "Assigned out channel n. " << (int)chan << endl;
else
cout << "Invalid channel number" << endl;
}
else if (command == "status") {
cout << "\nMETRONOME STATUS:\n";
cout <<
"MIDI out channel: " << int(metro->
GetOutChannel()) << endl;
cout <<
"Tempo scale: " << metro->
GetTempoScale() <<
"% (effective tempo: " <<
cout << (metro->
GetSubdType() == 0 ?
" (disabled)" :
"") << endl;
cout <<
"Measure beat note: " << int(metro->
GetMeasNote()) << endl;
cout <<
"Ordinary beat note: " << int(metro->
GetBeatNote()) << endl;
cout <<
"Subdivision note: " << int(metro->
GetSubdNote()) << endl;
}
else if (command == "help")
cout << helpstring;
else if (command != "quit" )
cout << "Unrecognized command" << endl;
}
delete metro;
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.
A MIDITickComponent implementing a metronome.
Definition: metronome.h:46
unsigned char GetTimeSigNumerator() const
Returns the numerator of the current timesig.
Definition: metronome.h:87
bool SetOutPort(unsigned int port)
Sets the MIDI out port for the metronome clicks.
unsigned int GetCurrentBeat() const
Returns current beat in the measure (1st beat is 0).
Definition: metronome.h:65
unsigned int GetOutChannel() const
Returns the number of the MIDI channel assigned to the metronome.
Definition: metronome.h:76
bool SetTempoScale(unsigned int scale)
Sets the global tempo scale.
unsigned char GetSubdNote() const
Returns the MIDI note number for the subdivision click.
Definition: metronome.h:82
virtual void Stop()
Stops the metronome.
float GetTempoWithoutScale() const
Returns current tempo (BPM) without scaling.
Definition: metronome.h:69
void SetSubdNote(unsigned char note)
Sets the MIDI note number for the subdivision click.
unsigned char GetSubdType() const
Returns the subdivision type. It can be 0 (subd clicks disabled), 2, 3, 4, 5, 6.
Definition: metronome.h:84
virtual void Start()
Starts the metronome.
void SetMeasNote(unsigned char note)
Sets the MIDI note number for the measure click (the 1st beat of the measure).
unsigned char GetBeatNote() const
Returns the MIDI note number for the ordinary beat click.
Definition: metronome.h:80
void SetTimeSigNumerator(unsigned char n)
Sets the numerator of the current timesig.
unsigned int GetOutPort() const
Returns the number of the MIDI out port assigned to the metronome.
Definition: metronome.h:73
unsigned int GetCurrentMeasure() const
Returns current measure (1st measure is 0).
Definition: metronome.h:63
void SetBeatNote(unsigned char note)
Sets the MIDI note number for the ordinary beat click.
unsigned char GetMeasNote() const
Returns the MIDI note number for the measure click.
Definition: metronome.h:78
bool SetTempo(float t)
Sets the musical tempo.
unsigned int GetTempoScale() const
Returns current tempo scale in percentage (100 = no scaling, 200 = twice faster, etc....
Definition: metronome.h:67
bool SetOutChannel(unsigned int chan)
Sets the MIDI channel for the metronome clicks.
bool SetSubdType(unsigned char type)
Sets the subdivision type.
float GetTempoWithScale() const
Returns current tempo (BPM) taking into account scaling (this is the true actual tempo).
Definition: metronome.h:71