diff options
| author | Gary Scavone <gary@music.mcgill.ca> | 2013-10-11 14:49:11 +0200 |
|---|---|---|
| committer | Stephen Sinclair <sinclair@music.mcgill.ca> | 2013-10-11 14:49:11 +0200 |
| commit | 8fec3d71d441efbada609d2139ddf8ff6aa7b914 (patch) | |
| tree | 760e2e74be6be3f4c81bc35b9e8a5d932e0338d8 /tests | |
| parent | 94ef7a9c9202314c5fe9de2dc24b16ded6b7d98c (diff) | |
Version 1.0.12
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/Makefile.in | 9 | ||||
| -rw-r--r-- | tests/cmidiin.cpp | 93 | ||||
| -rw-r--r-- | tests/midiout.cpp | 18 | ||||
| -rw-r--r-- | tests/midiprobe.cpp | 62 |
4 files changed, 105 insertions, 77 deletions
diff --git a/tests/Makefile.in b/tests/Makefile.in index f33d669..f8966bf 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -37,9 +37,12 @@ sysextest : sysextest.cpp $(OBJECTS) $(CC) $(CFLAGS) $(DEFS) -o sysextest sysextest.cpp $(OBJECT_PATH)/RtMidi.o $(LIBRARY) clean : - -rm $(OBJECT_PATH)/*.o - -rm $(PROGRAMS) *.exe - -rm -f *~ + $(RM) -f $(OBJECT_PATH)/*.o + $(RM) -f $(PROGRAMS) *.exe + $(RM) -f *~ + +distclean: clean + $(RM) -f Makefile strip : strip $(PROGRAMS) diff --git a/tests/cmidiin.cpp b/tests/cmidiin.cpp index 0556b80..f2f392b 100644 --- a/tests/cmidiin.cpp +++ b/tests/cmidiin.cpp @@ -28,6 +28,11 @@ void mycallback( double deltatime, std::vector< unsigned char > *message, void * std::cout << "stamp = " << deltatime << std::endl; } +// This function should be embedded in a try/catch block in case of +// an exception. It offers the user a choice of MIDI ports to open. +// It returns false if there are no ports available. +bool chooseMidiPort( RtMidiIn *rtmidi ); + int main( int argc, char *argv[] ) { RtMidiIn *midiin = 0; @@ -35,48 +40,72 @@ int main( int argc, char *argv[] ) // Minimal command-line check. if ( argc > 2 ) usage(); - // RtMidiIn constructor try { + + // RtMidiIn constructor midiin = new RtMidiIn(); - } - catch ( RtError &error ) { - error.printMessage(); - exit( EXIT_FAILURE ); - } - // Check available ports vs. specified. - unsigned int port = 0; - unsigned int nPorts = midiin->getPortCount(); - if ( argc == 2 ) port = (unsigned int) atoi( argv[1] ); - if ( port >= nPorts ) { - delete midiin; - std::cout << "Invalid port specifier!\n"; - usage(); - } + // Call function to select port. + if ( chooseMidiPort( midiin ) == false ) goto cleanup; - try { - midiin->openPort( port ); - } - catch ( RtError &error ) { - error.printMessage(); - goto cleanup; - } + // Set our callback function. This should be done immediately after + // opening the port to avoid having incoming messages written to the + // queue instead of sent to the callback function. + midiin->setCallback( &mycallback ); - // Set our callback function. This should be done immediately after - // opening the port to avoid having incoming messages written to the - // queue instead of sent to the callback function. - midiin->setCallback( &mycallback ); + // Don't ignore sysex, timing, or active sensing messages. + midiin->ignoreTypes( false, false, false ); - // Don't ignore sysex, timing, or active sensing messages. - midiin->ignoreTypes( false, false, false ); + std::cout << "\nReading MIDI input ... press <enter> to quit.\n"; + char input; + std::cin.get(input); - std::cout << "\nReading MIDI input ... press <enter> to quit.\n"; - char input; - std::cin.get(input); + } catch ( RtError &error ) { + error.printMessage(); + } - // Clean up cleanup: + delete midiin; return 0; } + +bool chooseMidiPort( RtMidiIn *rtmidi ) +{ + std::cout << "\nWould you like to open a virtual input port? [y/N] "; + + std::string keyHit; + std::getline( std::cin, keyHit ); + if ( keyHit == "y" ) { + rtmidi->openVirtualPort(); + return true; + } + + std::string portName; + unsigned int i = 0, nPorts = rtmidi->getPortCount(); + if ( nPorts == 0 ) { + std::cout << "No input ports available!" << std::endl; + return false; + } + + if ( nPorts == 1 ) { + std::cout << "\nOpening " << rtmidi->getPortName() << std::endl; + } + else { + for ( i=0; i<nPorts; i++ ) { + portName = rtmidi->getPortName(i); + std::cout << " Input port #" << i << ": " << portName << '\n'; + } + + do { + std::cout << "\nChoose a port number: "; + std::cin >> i; + } while ( i >= nPorts ); + } + + std::getline( std::cin, keyHit ); // used to clear out stdin + rtmidi->openPort( i ); + + return true; +} diff --git a/tests/midiout.cpp b/tests/midiout.cpp index ed65b0d..4da65c1 100644 --- a/tests/midiout.cpp +++ b/tests/midiout.cpp @@ -54,6 +54,12 @@ int main( int argc, char *argv[] ) message.push_back( 5 ); midiout->sendMessage( &message ); + SLEEP( 500 ); + + message[0] = 0xF1; + message[1] = 60; + midiout->sendMessage( &message ); + // Control Change: 176, 7, 100 (volume) message[0] = 176; message[1] = 7; @@ -74,7 +80,17 @@ int main( int argc, char *argv[] ) message[2] = 40; midiout->sendMessage( &message ); - // Sysex: 240, 67, 16, 4, 3, 2, 247 + SLEEP( 500 ); + + // Control Change: 176, 7, 40 + message[0] = 176; + message[1] = 7; + message[2] = 40; + midiout->sendMessage( &message ); + + SLEEP( 500 ); + + // Sysex: 240, 67, 4, 3, 2, 247 message[0] = 240; message[1] = 67; message[2] = 4; diff --git a/tests/midiprobe.cpp b/tests/midiprobe.cpp index 06d9497..e9ba757 100644 --- a/tests/midiprobe.cpp +++ b/tests/midiprobe.cpp @@ -13,57 +13,37 @@ int main() RtMidiIn *midiin = 0; RtMidiOut *midiout = 0; - // RtMidiIn constructor try { + + // RtMidiIn constructor ... exception possible midiin = new RtMidiIn(); - } - catch ( RtError &error ) { - error.printMessage(); - exit( EXIT_FAILURE ); - } - // Check inputs. - unsigned int nPorts = midiin->getPortCount(); - std::cout << "\nThere are " << nPorts << " MIDI input sources available.\n"; - std::string portName; - unsigned int i; - for ( i=0; i<nPorts; i++ ) { - try { - portName = midiin->getPortName(i); - } - catch ( RtError &error ) { - error.printMessage(); - goto cleanup; + // Check inputs. + unsigned int nPorts = midiin->getPortCount(); + std::cout << "\nThere are " << nPorts << " MIDI input sources available.\n"; + + for ( unsigned i=0; i<nPorts; i++ ) { + std::string portName = midiin->getPortName(i); + std::cout << " Input Port #" << i+1 << ": " << portName << '\n'; } - std::cout << " Input Port #" << i+1 << ": " << portName << '\n'; - } - // RtMidiOut constructor - try { + // RtMidiOut constructor ... exception possible midiout = new RtMidiOut(); - } - catch ( RtError &error ) { - error.printMessage(); - exit( EXIT_FAILURE ); - } - // Check outputs. - nPorts = midiout->getPortCount(); - std::cout << "\nThere are " << nPorts << " MIDI output ports available.\n"; - for ( i=0; i<nPorts; i++ ) { - try { - portName = midiout->getPortName(i); - } - catch ( RtError &error ) { - error.printMessage(); - goto cleanup; + // Check outputs. + nPorts = midiout->getPortCount(); + std::cout << "\nThere are " << nPorts << " MIDI output ports available.\n"; + + for ( unsigned i=0; i<nPorts; i++ ) { + std::string portName = midiout->getPortName(i); + std::cout << " Output Port #" << i+1 << ": " << portName << std::endl; } - std::cout << " Output Port #" << i+1 << ": " << portName << '\n'; + std::cout << std::endl; + + } catch ( RtError &error ) { + error.printMessage(); } - std::cout << '\n'; - // Clean up - cleanup: delete midiin; delete midiout; |
