Explorar o código

Commented out use of MIDISendSysex() in OS-X, so sysexes are sent as normal messages. This avoids a problem where virtual ports were not receiving the sysex messages.

Gary Scavone %!s(int64=11) %!d(string=hai) anos
pai
achega
9523a1b50c
Modificáronse 3 ficheiros con 25 adicións e 76 borrados
  1. 12 4
      RtMidi.cpp
  2. 1 1
      doc/release.txt
  3. 12 71
      tests/sysextest.cpp

+ 12 - 4
RtMidi.cpp

@@ -993,10 +993,12 @@ void MidiOutCore :: openVirtualPort( std::string portName )
   data->endpoint = endpoint;
 }
 
-static void sysexCompletionProc( MIDISysexSendRequest *sreq )
-{
-  free( sreq );
-}
+// Not necessary if we don't treat sysex messages any differently than
+// normal messages ... see below.
+//static void sysexCompletionProc( MIDISysexSendRequest *sreq )
+//{
+//  free( sreq );
+//}
 
 void MidiOutCore :: sendMessage( std::vector<unsigned char> *message )
 {
@@ -1015,6 +1017,11 @@ void MidiOutCore :: sendMessage( std::vector<unsigned char> *message )
   CoreMidiData *data = static_cast<CoreMidiData *> (apiData_);
   OSStatus result;
 
+  /*
+    // I don't think this code is necessary.  We can send sysex
+    // messages through the normal mechanism.  In addition, this avoids
+    // the problem of virtual ports not receiving sysex messages.
+
   if ( message->at(0) == 0xF0 ) {
 
     // Apple's fantastic API requires us to free the allocated data in
@@ -1051,6 +1058,7 @@ void MidiOutCore :: sendMessage( std::vector<unsigned char> *message )
     error( RtMidiError::WARNING, errorString_ );
     return;
   }
+  */
 
   MIDIPacketList packetList;
   MIDIPacket *packet = MIDIPacketListInit( &packetList );

+ 1 - 1
doc/release.txt

@@ -12,7 +12,7 @@ v2.1.0: (?? 2014)
 - fix for unicode conversion in WinMM (Dan Wilcox)
 - added custom error hook that allows the client to capture an RtMidi error outside of the RtMidi code (Pavel Mogilevskiy)
 - added RtMidi::isPortOpen function (Pavel Mogilevskiy)
-- updated OS-X sysex sending mechanism (ptarabbia)
+- updated OS-X sysex sending mechanism to use normal message sending, which fixes a problem where virtual ports didn't receive sysex messages
 - Windows update to avoid lockups when shutting down while sending/receiving sysex messages (ptarabbia)
 - OS-X fix to avoid empty messages in callbacks when ignoring sysex messages and split sysexes are received (codepainters)
 

+ 12 - 71
tests/sysextest.cpp

@@ -26,11 +26,6 @@ void usage( void ) {
   #define SLEEP( milliseconds ) usleep( (unsigned long) (milliseconds * 1000.0) )
 #endif
 
-// 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( RtMidi *rtmidi );
-
 void mycallback( double deltatime, std::vector< unsigned char > *message, void *userData )
 {
   unsigned int nBytes = message->size();
@@ -64,10 +59,9 @@ int main( int argc, char *argv[] )
   // Don't ignore sysex, timing, or active sensing messages.
   midiin->ignoreTypes( false, true, true );
 
-  // Call function to select ports
   try {
-    if ( chooseMidiPort( midiin ) == false ) goto cleanup;
-    if ( chooseMidiPort( midiout ) == false ) goto cleanup;
+  midiin->openVirtualPort( "MyVirtualInputPort" );
+  midiout->openPort( 0 );
   }
   catch ( RtMidiError &error ) {
     error.printMessage();
@@ -80,18 +74,17 @@ int main( int argc, char *argv[] )
   midiout->sendMessage( &message );
   SLEEP( 500 ); // pause a little
 
-  // Create a long sysex message of numbered bytes and send it out.
+  // Create a long sysex message of numbered bytes and send it out ... twice.
   for ( int n=0; n<2; n++ ) {
-  message.clear();
-  message.push_back( 240 );
-  for ( i=0; i<nBytes; i++ )
-    message.push_back( i % 128 );
-  message.push_back( 247 );
-  midiout->sendMessage( &message );
-
-  SLEEP( 500 ); // pause a little
-
-}
+    message.clear();
+    message.push_back( 240 );
+    for ( i=0; i<nBytes; i++ )
+      message.push_back( i % 128 );
+    message.push_back( 247 );
+    midiout->sendMessage( &message );
+
+    SLEEP( 500 ); // pause a little
+  }
 
   // Clean up
  cleanup:
@@ -100,55 +93,3 @@ int main( int argc, char *argv[] )
 
   return 0;
 }
-
-bool chooseMidiPort( RtMidi *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::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 ) {
-    if ( isInput )
-      std::cout << "No input ports available!" << std::endl;
-    else
-      std::cout << "No output 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);
-      if ( isInput )
-        std::cout << "  Input port #" << i << ": " << portName << '\n';
-      else
-        std::cout << "  Output port #" << i << ": " << portName << '\n';
-    }
-
-    do {
-      std::cout << "\nChoose a port number: ";
-      std::cin >> i;
-    } while ( i >= nPorts );
-  }
-
-  std::cout << std::endl;
-  rtmidi->openPort( i );
-
-  return true;
-}