Requires functions.cpp, which contains command line I/O functions.
#include "../include/manager.h"
#include "../include/thru.h"
#include "functions.h"
#include <iostream>
#include <string>
using namespace std;
extern string command, par1, par2;
const char helpstring[] =
"\nAvailable commands:\n\
ports : Enumerates MIDI IN and OUT ports\n\
outport port [chan] : Sets port as current thru output device\n\
(default: port 0, chan all)\n\
inport port [chan] : Sets port as current input device\n\
(default: port 0, chan all)\n\
thru on/off : Sets MIDI thru on/off\n\
program prog : Sets the MIDI program (patch) number for\n\
the current out channel (only if a single\n\
channel is selected)\n\
print on/off : Turns on and off the printing of incoming\n\
messages\n\
status : Prints the status of the thru\n\
help : Prints this help screen\n\
quit : Exits\n\n\
MIDI channels are numbered 0 .. 15, and -1 stands for \"all channels\"";
int main( int argc, char **argv ) {
try {
}
catch( ... ) {
cout << "The MIDIThru constructor throws an exception if in the system are not present\n" <<
"almost a MIDI in and a MIDI out ports!\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 << "\tMIDI IN PORTS:" << endl;
}
cout << "\tMIDI OUT PORTS:\n";
}
}
else if (command == "outport") {
int port = atoi(par1.c_str());
int chan = -1;
if (par2.length() > 0)
chan = atoi(par2.c_str());
cout << "Out port for MIDI thru:\nPort: " << port << "\tChan: " << chan << endl;
else
cout << "Invalid parameters";
}
else if (command == "inport") {
int port = atoi(par1.c_str());
int chan = -1;
if (par2.length() > 0)
chan = atoi(par2.c_str());
cout << "In port for MIDI thru:\nPort: " << port << "\tChan: " << chan << endl;
else
cout << "Invalid parameters";
}
else if (command == "thru") {
if (par1 == "on") {
}
else if (par1 == "off") {
cout << "MIDI thru off" << endl;
}
else
cout << "You must specify on or off" << endl;
}
else if (command == "program") {
unsigned int prog = atoi(par1.c_str()) & 0x7f;
if (chan == -1)
if (chan == -1)
cout << "IN and OUT set to all channels. This command has no effect!" << endl;
else {
<< " channel " << chan << endl;
}
}
else if (command == "print") {
if (par1 == "on") {
}
else if (par1 == "off") {
cout << "Print off" << endl;
}
else
cout << "You must specify on or off" << endl;
}
else if (command == "status") {
cout << "\nTHRU STATUS:" << endl;
cout << "MIDI in channel: ";
cout << "all" << endl;
else
cout << "MIDI out channel: ";
cout << "all" << endl;
else
cout << "MIDI thru: ";
cout << (thru->
IsPlaying() ?
"ON" :
"OFF") << endl;
cout << "Print incoming messages : ";
cout << (printer.
GetPrint() ?
"ON" :
"OFF") << endl;
}
else if (command == "help")
cout << helpstring;
else if (command != "quit" )
cout << "Unrecognized command" << endl;
}
delete thru;
return EXIT_SUCCESS;
}
static unsigned int GetNumMIDIOuts()
Returns the number of MIDI out ports in the system.
static MIDIOutDriver * GetOutDriver(unsigned int n)
Returns a pointer to the MIDIOutDriver with given port id.
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.
void SetProgramChange(unsigned char chan, unsigned char prog)
Makes the message a program change message with given channel and program.
virtual void OutputMessage(const MIDITimedMessage &msg)
Makes a copy of the message, processes it with the out processor and then sends it to the hardware po...
A MIDIProcessor which prints a human-readable description of the processed messages to a std::ostream...
Definition: processor.h:184
bool GetPrint() const
Returns the printing status.
Definition: processor.h:195
void SetPrint(bool on_off)
Sets the printing on and off (default is on).
Definition: processor.h:200
A MIDITickComponent which immediately echoes to an out MIDI port all messages incoming from an in MID...
Definition: thru.h:44
virtual void Stop()
Stops the MIDI thru.
unsigned int GetOutPort() const
Returns a pointer to the MIDIOutDriver to whom messages are actually being sent.
Definition: thru.h:63
virtual void SetProcessor(MIDIProcessor *proc)
Sets the out processor, which can manipulate messages arrived to the in port before they are sent to ...
unsigned int GetInPort() const
Returns the number of the MIDI in port from which messages are actually being received.
Definition: thru.h:61
virtual bool SetOutChannel(int chan)
Sets the channel for outgoing thru messages.
virtual bool SetOutPort(unsigned int port)
Selects the hardware out port to whom messages will be sent.
int GetOutChannel() const
Returns the thru out channel (see SetOutChannel())
Definition: thru.h:71
virtual bool SetInPort(unsigned int port)
Selects the hardware in port from which messages will be received.
virtual void Start()
Starts the MIDI thru.
int GetInChannel() const
Returns the thru in channel (see SetInChannel())
Definition: thru.h:69
virtual bool SetInChannel(int chan)
Sets the channel for incoming thru messages.
bool IsPlaying() const
Returns true if the callback procedure is active.
Definition: tick.h:92
The MIDITimedMessage class inherits from the MIDIMessage and represents a message associated with a s...
Definition: msg.h:382