1 // midiprobe.cpp
2 //
3 // Simple program to check MIDI inputs and outputs.
4 //
5 // by Gary Scavone, 2003-2004.
6 
7 #include <iostream>
8 #include <cstdlib>
9 #include "RtMidi.h"
10 
11 int main()
12 {
13   RtMidiIn  *midiin = 0;
14   RtMidiOut *midiout = 0;
15 
16   // RtMidiIn constructor
17   try {
18     midiin = new RtMidiIn();
19   }
20   catch ( RtMidiError &error ) {
21     error.printMessage();
22     exit( EXIT_FAILURE );
23   }
24 
25   // Check inputs.
usage(void)26   unsigned int nPorts = midiin->getPortCount();
27   std::cout << "\nThere are " << nPorts << " MIDI input sources available.\n";
28   std::string portName;
29   unsigned int i;
30   for ( i=0; i<nPorts; i++ ) {
31     try {
32       portName = midiin->getPortName(i);
33     }
34     catch ( RtMidiError &error ) {
35       error.printMessage();
36       goto cleanup;
37     }
main(int argc,char * argv[])38     std::cout << "  Input Port #" << i+1 << ": " << portName << '\n';
39   }
40 
41   // RtMidiOut constructor
42   try {
43     midiout = new RtMidiOut();
44   }
45   catch ( RtMidiError &error ) {
46     error.printMessage();
47     exit( EXIT_FAILURE );
48   }
49 
50   // Check outputs.
51   nPorts = midiout->getPortCount();
52   std::cout << "\nThere are " << nPorts << " MIDI output ports available.\n";
53   for ( i=0; i<nPorts; i++ ) {
54     try {
55       portName = midiout->getPortName(i);
56     }
57     catch ( RtMidiError &error ) {
58       error.printMessage();
59       goto cleanup;
60     }
61     std::cout << "  Output Port #" << i+1 << ": " << portName << '\n';
62   }
63   std::cout << '\n';
64 
65   // Clean up
66  cleanup:
67   delete midiin;
68   delete midiout;
69 
70   return 0;
71 }
72