Ver código fonte

Version 1.0.5

Gary Scavone 11 anos atrás
pai
commit
5642ef1ff2
5 arquivos alterados com 110 adições e 49 exclusões
  1. 81 17
      RtMidi.cpp
  2. 7 7
      RtMidi.h
  3. 12 7
      doc/doxygen/tutorial.txt
  4. 5 0
      doc/release.txt
  5. 5 18
      tests/midiout.cpp

+ 81 - 17
RtMidi.cpp

@@ -35,7 +35,7 @@
 */
 */
 /**********************************************************************/
 /**********************************************************************/
 
 
-// RtMidi: Version 1.0.4, 14 October 2005
+// RtMidi: Version 1.0.5, in development
 
 
 #include "RtMidi.h"
 #include "RtMidi.h"
 #include <sstream>
 #include <sstream>
@@ -383,13 +383,15 @@ void RtMidiIn :: openPort( unsigned int portNumber )
   connected_ = true;
   connected_ = true;
 }
 }
 
 
-void RtMidiIn :: openVirtualPort()
+void RtMidiIn :: openVirtualPort( const std::string portName )
 {
 {
   CoreMidiData *data = static_cast<CoreMidiData *> (apiData_);
   CoreMidiData *data = static_cast<CoreMidiData *> (apiData_);
 
 
   // Create a virtual MIDI input destination.
   // Create a virtual MIDI input destination.
   MIDIEndpointRef endpoint;
   MIDIEndpointRef endpoint;
-  OSStatus result = MIDIDestinationCreate( data->client, CFSTR("RtMidi Input"), midiInputCallback, (void *)&inputData_, &endpoint );
+  OSStatus result = MIDIDestinationCreate( data->client,
+                                           CFStringCreateWithCString( NULL, portName.c_str(), kCFStringEncodingASCII ),
+                                           midiInputCallback, (void *)&inputData_, &endpoint );
   if ( result != noErr ) {
   if ( result != noErr ) {
     errorString_ = "RtMidiIn::openVirtualPort: error creating virtual OS-X MIDI destination.";
     errorString_ = "RtMidiIn::openVirtualPort: error creating virtual OS-X MIDI destination.";
     error( RtError::DRIVER_ERROR );
     error( RtError::DRIVER_ERROR );
@@ -548,7 +550,7 @@ void RtMidiOut :: closePort( void )
   }
   }
 }
 }
 
 
-void RtMidiOut :: openVirtualPort()
+void RtMidiOut :: openVirtualPort( std::string portName )
 {
 {
   CoreMidiData *data = static_cast<CoreMidiData *> (apiData_);
   CoreMidiData *data = static_cast<CoreMidiData *> (apiData_);
 
 
@@ -560,7 +562,9 @@ void RtMidiOut :: openVirtualPort()
 
 
   // Create a virtual MIDI output source.
   // Create a virtual MIDI output source.
   MIDIEndpointRef endpoint;
   MIDIEndpointRef endpoint;
-  OSStatus result = MIDISourceCreate( data->client, CFSTR("RtMidi Output"), &endpoint );
+  OSStatus result = MIDISourceCreate( data->client,
+                                      CFStringCreateWithCString( NULL, portName.c_str(), kCFStringEncodingASCII ),
+                                      &endpoint );
   if ( result != noErr ) {
   if ( result != noErr ) {
     errorString_ = "RtMidiOut::initialize: error creating OS-X virtual MIDI source.";
     errorString_ = "RtMidiOut::initialize: error creating OS-X virtual MIDI source.";
     error( RtError::DRIVER_ERROR );
     error( RtError::DRIVER_ERROR );
@@ -957,7 +961,7 @@ void RtMidiIn :: openPort( unsigned int portNumber )
   connected_ = true;
   connected_ = true;
 }
 }
 
 
-void RtMidiIn :: openVirtualPort()
+void RtMidiIn :: openVirtualPort( std::string portName )
 {
 {
   AlsaMidiData *data = static_cast<AlsaMidiData *> (apiData_);
   AlsaMidiData *data = static_cast<AlsaMidiData *> (apiData_);
   if ( data->vport < 0 ) {
   if ( data->vport < 0 ) {
@@ -973,7 +977,7 @@ void RtMidiIn :: openVirtualPort()
     snd_seq_port_info_set_timestamping(pinfo, 1);
     snd_seq_port_info_set_timestamping(pinfo, 1);
     snd_seq_port_info_set_timestamp_real(pinfo, 1);    
     snd_seq_port_info_set_timestamp_real(pinfo, 1);    
     snd_seq_port_info_set_timestamp_queue(pinfo, data->queue_id);
     snd_seq_port_info_set_timestamp_queue(pinfo, data->queue_id);
-    snd_seq_port_info_set_name(pinfo, "RtMidi Input");
+    snd_seq_port_info_set_name(pinfo, portName.c_str());
     data->vport = snd_seq_create_port(data->seq, pinfo);
     data->vport = snd_seq_create_port(data->seq, pinfo);
 
 
     if ( data->vport < 0 ) {
     if ( data->vport < 0 ) {
@@ -1195,11 +1199,11 @@ void RtMidiOut :: closePort( void )
   }
   }
 }
 }
 
 
-void RtMidiOut :: openVirtualPort()
+void RtMidiOut :: openVirtualPort( std::string portName )
 {
 {
   AlsaMidiData *data = static_cast<AlsaMidiData *> (apiData_);
   AlsaMidiData *data = static_cast<AlsaMidiData *> (apiData_);
   if ( data->vport < 0 ) {
   if ( data->vport < 0 ) {
-    data->vport = snd_seq_create_simple_port( data->seq, "RtMidi Output",
+    data->vport = snd_seq_create_simple_port( data->seq, portName.c_str(),
                                               SND_SEQ_PORT_CAP_READ|SND_SEQ_PORT_CAP_SUBS_READ,
                                               SND_SEQ_PORT_CAP_READ|SND_SEQ_PORT_CAP_SUBS_READ,
                                               SND_SEQ_PORT_TYPE_MIDI_GENERIC );
                                               SND_SEQ_PORT_TYPE_MIDI_GENERIC );
 
 
@@ -1484,7 +1488,7 @@ void RtMidiIn :: openPort( unsigned int portNumber )
   connected_ = true;
   connected_ = true;
 }
 }
 
 
-void RtMidiIn :: openVirtualPort()
+void RtMidiIn :: openVirtualPort( std::string portName )
 {
 {
   // This function cannot be implemented for the Irix MIDI API.
   // This function cannot be implemented for the Irix MIDI API.
   errorString_ = "RtMidiIn::openVirtualPort: cannot be implemented in Irix MIDI API!";
   errorString_ = "RtMidiIn::openVirtualPort: cannot be implemented in Irix MIDI API!";
@@ -1617,7 +1621,7 @@ void RtMidiOut :: closePort( void )
   }
   }
 }
 }
 
 
-void RtMidiOut :: openVirtualPort()
+void RtMidiOut :: openVirtualPort( std::string portName )
 {
 {
   // This function cannot be implemented for the Irix MIDI API.
   // This function cannot be implemented for the Irix MIDI API.
   errorString_ = "RtMidiOut::openVirtualPort: cannot be implemented in Irix MIDI API!";
   errorString_ = "RtMidiOut::openVirtualPort: cannot be implemented in Irix MIDI API!";
@@ -1676,6 +1680,8 @@ void RtMidiOut :: sendMessage( std::vector<unsigned char> *message )
 // API information deciphered from:
 // API information deciphered from:
 //  - http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_midi_reference.asp
 //  - http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_midi_reference.asp
 
 
+// Thanks to Jean-Baptiste Berruchon for the sysex code.
+
 #if defined(__WINDOWS_MM__)
 #if defined(__WINDOWS_MM__)
 
 
 // The Windows MM API is based on the use of a callback function for
 // The Windows MM API is based on the use of a callback function for
@@ -1693,8 +1699,11 @@ struct WinMidiData {
   HMIDIOUT outHandle;  // Handle to Midi Output Device
   HMIDIOUT outHandle;  // Handle to Midi Output Device
   DWORD lastTime;
   DWORD lastTime;
   RtMidiIn::MidiMessage message;
   RtMidiIn::MidiMessage message;
+  LPMIDIHDR sysexBuffer;
 };
 };
 
 
+#define  RT_SYSEX_BUFFER_SIZE 1024
+
 //*********************************************************************//
 //*********************************************************************//
 //  API: Windows MM
 //  API: Windows MM
 //  Class Definitions: RtMidiIn
 //  Class Definitions: RtMidiIn
@@ -1748,11 +1757,21 @@ static void CALLBACK midiInputCallback( HMIDIOUT hmin,
     unsigned char *ptr = (unsigned char *) &midiMessage;
     unsigned char *ptr = (unsigned char *) &midiMessage;
     for ( int i=0; i<nBytes; i++ ) apiData->message.bytes.push_back( *ptr++ );
     for ( int i=0; i<nBytes; i++ ) apiData->message.bytes.push_back( *ptr++ );
   }
   }
-  else { // Sysex message
+  else if ( !(data->ignoreFlags & 0x01) ) {
+    // Sysex message and we're not ignoring it
     MIDIHDR *sysex = ( MIDIHDR *) midiMessage;
     MIDIHDR *sysex = ( MIDIHDR *) midiMessage;
     for ( int i=0; i<(int)sysex->dwBytesRecorded; i++ )
     for ( int i=0; i<(int)sysex->dwBytesRecorded; i++ )
       apiData->message.bytes.push_back( sysex->lpData[i] );
       apiData->message.bytes.push_back( sysex->lpData[i] );
-    if ( apiData->message.bytes.back() != 0xF7 ) return;
+
+    // When the callback has to be unaffected (application closes), 
+    // it seems WinMM calls it with an empty sysex to de-queue the buffer
+    // If the buffer is requeued afer that message, the PC suddenly reboots
+    // after one or two minutes (JB).
+    if ( apiData->sysexBuffer->dwBytesRecorded > 0 ) {
+      MMRESULT result = midiInAddBuffer( apiData->inHandle, apiData->sysexBuffer, sizeof(MIDIHDR) );
+      if ( result != MMSYSERR_NOERROR )
+        std::cerr << "\nRtMidiIn::midiInputCallback: error sending sysex to Midi device!!\n\n";
+    }
   }
   }
 
 
   if ( data->usingCallback ) {
   if ( data->usingCallback ) {
@@ -1822,6 +1841,27 @@ void RtMidiIn :: openPort( unsigned int portNumber )
     error( RtError::DRIVER_ERROR );
     error( RtError::DRIVER_ERROR );
   }
   }
 
 
+  // Allocate and init the sysex buffer.
+  data->sysexBuffer = (MIDIHDR*) new char[ sizeof(MIDIHDR) ];
+  data->sysexBuffer->lpData = new char[1024];
+  data->sysexBuffer->dwBufferLength = 1024;
+  data->sysexBuffer->dwFlags = 0;
+
+  result = midiInPrepareHeader( data->inHandle, data->sysexBuffer, sizeof(MIDIHDR) );
+  if ( result != MMSYSERR_NOERROR ) {
+    midiInClose( data->inHandle );
+    errorString_ = "RtMidiIn::openPort: error starting Windows MM MIDI input port (PrepareHeader).";
+    error( RtError::DRIVER_ERROR );
+  }
+
+  // Register the buffer.
+  result = midiInAddBuffer( data->inHandle, data->sysexBuffer, sizeof(MIDIHDR) );
+  if ( result != MMSYSERR_NOERROR ) {
+    midiInClose( data->inHandle );
+    errorString_ = "RtMidiIn::openPort: error starting Windows MM MIDI input port (AddBuffer).";
+    error( RtError::DRIVER_ERROR );
+  }
+
   result = midiInStart( data->inHandle );
   result = midiInStart( data->inHandle );
   if ( result != MMSYSERR_NOERROR ) {
   if ( result != MMSYSERR_NOERROR ) {
     midiInClose( data->inHandle );
     midiInClose( data->inHandle );
@@ -1832,7 +1872,7 @@ void RtMidiIn :: openPort( unsigned int portNumber )
   connected_ = true;
   connected_ = true;
 }
 }
 
 
-void RtMidiIn :: openVirtualPort()
+void RtMidiIn :: openVirtualPort( std::string portName )
 {
 {
   // This function cannot be implemented for the Windows MM MIDI API.
   // This function cannot be implemented for the Windows MM MIDI API.
   errorString_ = "RtMidiIn::openVirtualPort: cannot be implemented in Windows MM MIDI API!";
   errorString_ = "RtMidiIn::openVirtualPort: cannot be implemented in Windows MM MIDI API!";
@@ -1845,6 +1885,16 @@ void RtMidiIn :: closePort( void )
     WinMidiData *data = static_cast<WinMidiData *> (apiData_);
     WinMidiData *data = static_cast<WinMidiData *> (apiData_);
     midiInReset( data->inHandle );
     midiInReset( data->inHandle );
     midiInStop( data->inHandle );
     midiInStop( data->inHandle );
+
+    int result = midiInUnprepareHeader(data->inHandle, data->sysexBuffer, sizeof(MIDIHDR));
+    delete [] data->sysexBuffer->lpData;
+    delete [] data->sysexBuffer;
+    if ( result != MMSYSERR_NOERROR ) {
+      midiInClose( data->inHandle );
+      errorString_ = "RtMidiIn::openPort: error closing Windows MM MIDI input port (midiInUnprepareHeader).";
+      error( RtError::DRIVER_ERROR );
+    }
+
     midiInClose( data->inHandle );
     midiInClose( data->inHandle );
     connected_ = false;
     connected_ = false;
   }
   }
@@ -1878,7 +1928,14 @@ std::string RtMidiIn :: getPortName( unsigned int portNumber )
   MIDIINCAPS deviceCaps;
   MIDIINCAPS deviceCaps;
   MMRESULT result = midiInGetDevCaps( portNumber, &deviceCaps, sizeof(MIDIINCAPS));
   MMRESULT result = midiInGetDevCaps( portNumber, &deviceCaps, sizeof(MIDIINCAPS));
 
 
-  std::string stringName = std::string( deviceCaps.szPname );
+  // For some reason, we need to copy character by character with
+  // UNICODE (thanks to Eduardo Coutinho!).
+  //std::string stringName = std::string( deviceCaps.szPname );
+  char nameString[MAXPNAMELEN];
+  for( int i=0; i<MAXPNAMELEN; i++ )
+    nameString[i] = (char)( deviceCaps.szPname[i] );
+
+  std::string stringName( nameString );
   return stringName;
   return stringName;
 }
 }
 
 
@@ -1905,7 +1962,14 @@ std::string RtMidiOut :: getPortName( unsigned int portNumber )
   MIDIOUTCAPS deviceCaps;
   MIDIOUTCAPS deviceCaps;
   MMRESULT result = midiOutGetDevCaps( portNumber, &deviceCaps, sizeof(MIDIOUTCAPS));
   MMRESULT result = midiOutGetDevCaps( portNumber, &deviceCaps, sizeof(MIDIOUTCAPS));
 
 
-  std::string stringName = std::string( deviceCaps.szPname );
+  // For some reason, we need to copy character by character with
+  // UNICODE (thanks to Eduardo Coutinho!).
+  //std::string stringName = std::string( deviceCaps.szPname );
+  char nameString[MAXPNAMELEN];
+  for( int i=0; i<MAXPNAMELEN; i++ )
+    nameString[i] = (char)( deviceCaps.szPname[i] );
+
+  std::string stringName( nameString );
   return stringName;
   return stringName;
 }
 }
 
 
@@ -1969,7 +2033,7 @@ void RtMidiOut :: closePort( void )
   }
   }
 }
 }
 
 
-void RtMidiOut :: openVirtualPort()
+void RtMidiOut :: openVirtualPort( std::string portName )
 {
 {
   // This function cannot be implemented for the Windows MM MIDI API.
   // This function cannot be implemented for the Windows MM MIDI API.
   errorString_ = "RtMidiOut::openVirtualPort: cannot be implemented in Windows MM MIDI API!";
   errorString_ = "RtMidiOut::openVirtualPort: cannot be implemented in Windows MM MIDI API!";

+ 7 - 7
RtMidi.h

@@ -35,7 +35,7 @@
 */
 */
 /**********************************************************************/
 /**********************************************************************/
 
 
-// RtMidi: Version 1.0.4, 14 October 2005
+// RtMidi: Version 1.0.5, in development
 
 
 #ifndef RTMIDI_H
 #ifndef RTMIDI_H
 #define RTMIDI_H
 #define RTMIDI_H
@@ -51,7 +51,7 @@ class RtMidi
   virtual void openPort( unsigned int portNumber = 0 ) = 0;
   virtual void openPort( unsigned int portNumber = 0 ) = 0;
 
 
   //! Pure virtual openVirtualPort() function.
   //! Pure virtual openVirtualPort() function.
-  virtual void openVirtualPort() = 0;
+  virtual void openVirtualPort( const std::string portName = std::string( "RtMidi" ) ) = 0;
 
 
   //! Pure virtual getPortCount() function.
   //! Pure virtual getPortCount() function.
   virtual unsigned int getPortCount() = 0;
   virtual unsigned int getPortCount() = 0;
@@ -121,14 +121,14 @@ class RtMidiIn : public RtMidi
   */
   */
   void openPort( unsigned int portNumber = 0 );
   void openPort( unsigned int portNumber = 0 );
 
 
-  //! Create a virtual input port to allow software connections (OS X and ALSA only).
+  //! Create a virtual input port, with optional name, to allow software connections (OS X and ALSA only).
   /*!
   /*!
       This function creates a virtual MIDI input port to which other
       This function creates a virtual MIDI input port to which other
       software applications can connect.  This type of functionality
       software applications can connect.  This type of functionality
       is currently only supported by the Macintosh OS-X and Linux ALSA
       is currently only supported by the Macintosh OS-X and Linux ALSA
       APIs (the function does nothing for the other APIs).
       APIs (the function does nothing for the other APIs).
   */
   */
-  void openVirtualPort();
+  void openVirtualPort( const std::string portName = std::string( "RtMidi Input" ) );
 
 
   //! Set a callback function to be invoked for incoming MIDI messages.
   //! Set a callback function to be invoked for incoming MIDI messages.
   /*!
   /*!
@@ -261,7 +261,7 @@ class RtMidiOut : public RtMidi
   //! Close an open MIDI connection (if one exists).
   //! Close an open MIDI connection (if one exists).
   void closePort();
   void closePort();
 
 
-  //! Create a virtual output port to allow software connections (OS X and ALSA only).
+  //! Create a virtual output port, with optional name, to allow software connections (OS X and ALSA only).
   /*!
   /*!
       This function creates a virtual MIDI output port to which other
       This function creates a virtual MIDI output port to which other
       software applications can connect.  This type of functionality
       software applications can connect.  This type of functionality
@@ -270,7 +270,7 @@ class RtMidiOut : public RtMidi
       exception is thrown if an error occurs while attempting to create
       exception is thrown if an error occurs while attempting to create
       the virtual port.
       the virtual port.
   */
   */
-  void openVirtualPort();
+  void openVirtualPort( const std::string portName = std::string( "RtMidi Output" ) );
 
 
   //! Return the number of available MIDI output ports.
   //! Return the number of available MIDI output ports.
   unsigned int getPortCount();
   unsigned int getPortCount();
@@ -279,7 +279,7 @@ class RtMidiOut : public RtMidi
   /*!
   /*!
       An exception is thrown if an invalid port specifier is provided.
       An exception is thrown if an invalid port specifier is provided.
   */
   */
-  std::string getPortName( unsigned int portNumber );
+  std::string getPortName( unsigned int portNumber = 0 );
 
 
   //! Immediately send a single message out an open MIDI output port.
   //! Immediately send a single message out an open MIDI output port.
   /*!
   /*!

+ 12 - 7
doc/doxygen/tutorial.txt

@@ -17,7 +17,7 @@ MIDI input and output functionality are separated into two classes, RtMidiIn and
 
 
 \section download Download
 \section download Download
 
 
-Latest Release (14 October 2005): <A href="http://music.mcgill.ca/~gary/rtmidi/release/rtmidi-1.0.4.tar.gz">Version 1.0.4</A>
+Latest Release (18 November 2005): <A href="http://music.mcgill.ca/~gary/rtmidi/release/rtmidi-1.0.5.tar.gz">Version 1.0.5</A>
 
 
 \section start Getting Started
 \section start Getting Started
 
 
@@ -45,7 +45,7 @@ int main()
 }
 }
 \endcode
 \endcode
 
 
-Obviously, this example doesn't demonstrate any of the real functionality of RtMidi.  However, all uses of RtMidi must begin with construction and must end with class destruction.  Further, it is necessary that all class methods which can throw a C++ exception be called within a try/catch block.
+Obviously, this example doesn't demonstrate any of the real functionality of RtMidi.  However, all uses of RtMidi must begin with construction and must end with class destruction.  Further, it is necessary that all class methods that can throw a C++ exception be called within a try/catch block.
 
 
 
 
 \section error Error Handling
 \section error Error Handling
@@ -320,7 +320,7 @@ In order to compile RtMidi for a specific OS and API, it is necessary to supply
 <TABLE BORDER=2 COLS=5 WIDTH="100%">
 <TABLE BORDER=2 COLS=5 WIDTH="100%">
 <TR BGCOLOR="beige">
 <TR BGCOLOR="beige">
   <TD WIDTH="5%"><B>OS:</B></TD>
   <TD WIDTH="5%"><B>OS:</B></TD>
-  <TD WIDTH="5%"><B>Audio API:</B></TD>
+  <TD WIDTH="5%"><B>MIDI API:</B></TD>
   <TD WIDTH="5%"><B>Preprocessor Definition:</B></TD>
   <TD WIDTH="5%"><B>Preprocessor Definition:</B></TD>
   <TD WIDTH="5%"><B>Library or Framework:</B></TD>
   <TD WIDTH="5%"><B>Library or Framework:</B></TD>
   <TD><B>Example Compiler Statement:</B></TD>
   <TD><B>Example Compiler Statement:</B></TD>
@@ -334,10 +334,10 @@ In order to compile RtMidi for a specific OS and API, it is necessary to supply
 </TR>
 </TR>
 <TR>
 <TR>
   <TD>Macintosh OS X</TD>
   <TD>Macintosh OS X</TD>
-  <TD>CoreAudio</TD>
+  <TD>CoreMidi</TD>
   <TD>__MACOSX_CORE__</TD>
   <TD>__MACOSX_CORE__</TD>
-  <TD><TT>pthread, stdc++, CoreAudio</TT></TD>
-  <TD><TT>g++ -Wall -D__MACOSX_CORE__ -o midiinfo midiinfo.cpp RtMidi.cpp -framework CoreMidi -lpthread</TT></TD>
+  <TD><TT>CoreMidi, CoreAudio, CoreFoundation</TT></TD>
+  <TD><TT>g++ -Wall -D__MACOSX_CORE__ -o midiinfo midiinfo.cpp RtMidi.cpp -framework CoreMidi -framework CoreAudio -framework CoreFoundation</TT></TD>
 </TR>
 </TR>
 <TR>
 <TR>
   <TD>Irix</TD>
   <TD>Irix</TD>
@@ -384,7 +384,12 @@ The Windows Multimedia library MIDI calls used in RtMidi do not make use of stre
 
 
 \section acknowledge Acknowledgements
 \section acknowledge Acknowledgements
 
 
-Many thanks to Pedro Lopez-Cabanillas for his help with the ALSA sequencer API!
+Many thanks to the following people for providing bug fixes:
+<UL>
+<LI>Pedro Lopez-Cabanillas (ALSA sequencer API)</LI>
+<LI>Eduardo Coutinho (Windows device names)</LI>
+<LI>Jean-Baptiste Berruchon (Windows sysex code)</LI>
+</UL>
 
 
 \section license License
 \section license License
 
 

+ 5 - 0
doc/release.txt

@@ -2,6 +2,11 @@ RtMidi - a set of C++ classes that provides a common API for realtime MIDI input
 
 
 By Gary P. Scavone, 2003-2005.
 By Gary P. Scavone, 2003-2005.
 
 
+v1.0.5: (18 November 2005)
+- added optional port name to openVirtualPort() functions
+- fixed UNICODE problem in Windows getting device names (thanks Eduardo Coutinho!).
+- fixed bug in Windows with respect to getting Sysex data (thanks Jean-Baptiste Berruchon!)
+
 v1.0.4: (14 October 2005)
 v1.0.4: (14 October 2005)
 - added check for status byte == 0xF8 if ignoring timing messages
 - added check for status byte == 0xF8 if ignoring timing messages
 - changed pthread attribute to SCHED_OTHER (from SCHED_RR) to avoid thread problem when realtime cababilities are not enabled.
 - changed pthread attribute to SCHED_OTHER (from SCHED_RR) to avoid thread problem when realtime cababilities are not enabled.

+ 5 - 18
tests/midiout.cpp

@@ -21,7 +21,7 @@
 // This function should be embedded in a try/catch block in case of
 // 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.
 // an exception.  It offers the user a choice of MIDI ports to open.
 // It returns false if there are no ports available.
 // It returns false if there are no ports available.
-bool chooseMidiPort( RtMidi *rtmidi );
+bool chooseMidiPort( RtMidiOut *rtmidi );
 
 
 int main(int argc, char *argv[])
 int main(int argc, char *argv[])
 {
 {
@@ -89,16 +89,9 @@ int main(int argc, char *argv[])
   return 0;
   return 0;
 }
 }
 
 
-bool chooseMidiPort( RtMidi *rtmidi )
+bool chooseMidiPort( RtMidiOut *rtmidi )
 {
 {
-  bool isInput = false;
-  if ( typeid( *rtmidi ) == typeid( RtMidiIn ) )
-    isInput = true;
-
-  if ( isInput )
-    std::cout << "\nWould you like to open a virtual input port? [y/N] ";
-  else
-    std::cout << "\nWould you like to open a virtual output port? [y/N] ";
+  std::cout << "\nWould you like to open a virtual output port? [y/N] ";
 
 
   std::string keyHit;
   std::string keyHit;
   std::getline( std::cin, keyHit );
   std::getline( std::cin, keyHit );
@@ -110,10 +103,7 @@ bool chooseMidiPort( RtMidi *rtmidi )
   std::string portName;
   std::string portName;
   unsigned int i = 0, nPorts = rtmidi->getPortCount();
   unsigned int i = 0, nPorts = rtmidi->getPortCount();
   if ( nPorts == 0 ) {
   if ( nPorts == 0 ) {
-    if ( isInput )
-      std::cout << "No input ports available!" << std::endl;
-    else
-      std::cout << "No output ports available!" << std::endl;
+    std::cout << "No output ports available!" << std::endl;
     return false;
     return false;
   }
   }
 
 
@@ -123,10 +113,7 @@ bool chooseMidiPort( RtMidi *rtmidi )
   else {
   else {
     for ( i=0; i<nPorts; i++ ) {
     for ( i=0; i<nPorts; i++ ) {
       portName = rtmidi->getPortName(i);
       portName = rtmidi->getPortName(i);
-      if ( isInput )
-        std::cout << "  Input port #" << i << ": " << portName << '\n';
-      else
-        std::cout << "  Output port #" << i << ": " << portName << '\n';
+      std::cout << "  Output port #" << i << ": " << portName << '\n';
     }
     }
 
 
     do {
     do {