Skip to content

Commit

Permalink
OS-X dynamic device fix
Browse files Browse the repository at this point in the history
  • Loading branch information
garyscavone committed Dec 28, 2013
1 parent 408610f commit c80bfb6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
10 changes: 8 additions & 2 deletions RtMidi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ void MidiInCore :: openPort( unsigned int portNumber, const std::string portName
return;
}

CFRunLoopRunInMode( kCFRunLoopDefaultMode, 0, false );
unsigned int nSrc = MIDIGetNumberOfSources();
if (nSrc < 1) {
errorString_ = "MidiInCore::openPort: no MIDI input sources found!";
Expand Down Expand Up @@ -633,6 +634,7 @@ void MidiInCore :: closePort( void )

unsigned int MidiInCore :: getPortCount()
{
CFRunLoopRunInMode( kCFRunLoopDefaultMode, 0, false );
return MIDIGetNumberOfSources();
}

Expand Down Expand Up @@ -768,6 +770,7 @@ std::string MidiInCore :: getPortName( unsigned int portNumber )
char name[128];

std::string stringName;
CFRunLoopRunInMode( kCFRunLoopDefaultMode, 0, false );
if ( portNumber >= MIDIGetNumberOfSources() ) {
ost << "MidiInCore::getPortName: the 'portNumber' argument (" << portNumber << ") is invalid.";
errorString_ = ost.str();
Expand Down Expand Up @@ -825,6 +828,7 @@ void MidiOutCore :: initialize( const std::string& clientName )

unsigned int MidiOutCore :: getPortCount()
{
CFRunLoopRunInMode( kCFRunLoopDefaultMode, 0, false );
return MIDIGetNumberOfDestinations();
}

Expand All @@ -836,6 +840,7 @@ std::string MidiOutCore :: getPortName( unsigned int portNumber )
char name[128];

std::string stringName;
CFRunLoopRunInMode( kCFRunLoopDefaultMode, 0, false );
if ( portNumber >= MIDIGetNumberOfDestinations() ) {
ost << "MidiOutCore::getPortName: the 'portNumber' argument (" << portNumber << ") is invalid.";
errorString_ = ost.str();
Expand All @@ -860,6 +865,7 @@ void MidiOutCore :: openPort( unsigned int portNumber, const std::string portNam
return;
}

CFRunLoopRunInMode( kCFRunLoopDefaultMode, 0, false );
unsigned int nDest = MIDIGetNumberOfDestinations();
if (nDest < 1) {
errorString_ = "MidiOutCore::openPort: no MIDI output destinations found!";
Expand Down Expand Up @@ -1206,7 +1212,7 @@ extern "C" void *alsaMidiHandler( void *ptr )
if ( !( data->ignoreFlags & 0x02 ) ) doDecode = true;
break;

case SND_SEQ_EVENT_TICK: // MIDI timing tick
case SND_SEQ_EVENT_CLOCK: // MIDI timing tick
if ( !( data->ignoreFlags & 0x02 ) ) doDecode = true;
break;

Expand Down Expand Up @@ -2429,7 +2435,7 @@ class CKsEnumFilters
throw std::runtime_error("CKsEnumFilters: no devices found");

// Loop through members of the set and get details for each
for (int iClassMember=0;;iClassMember++) {
for ( int iClassMember=0; iClassMember++ ) {
try {
SP_DEVICE_INTERFACE_DATA DID;
DID.cbSize = sizeof(DID);
Expand Down
5 changes: 4 additions & 1 deletion doc/release.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
RtMidi - a set of C++ classes that provides a common API for realtime MIDI input/output across Linux (ALSA & Jack), Macintosh OS X (CoreMidi & Jack), and Windows (Multimedia).

By Gary P. Scavone, 2003-2012.
By Gary P. Scavone, 2003-2012

v2.0.2: (?? 2014)
- fix to CoreMidi implementation to support dynamic port changes

v2.0.1: (26 July 2012)
- small fixes for problems reported by Chris Arndt (scoping, preprocessor, and include)
Expand Down
2 changes: 1 addition & 1 deletion tests/cmidiin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ bool chooseMidiPort( RtMidiIn *rtmidi )
std::cout << "\nChoose a port number: ";
std::cin >> i;
} while ( i >= nPorts );
std::getline( std::cin, keyHit ); // used to clear out stdin
}

std::getline( std::cin, keyHit ); // used to clear out stdin
rtmidi->openPort( i );

return true;
Expand Down

0 comments on commit c80bfb6

Please sign in to comment.