midiinfo.cpp 1.4 KB

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