Skip to content

Commit

Permalink
Only open selected MIDI device if specified
Browse files Browse the repository at this point in the history
  • Loading branch information
softins committed Dec 4, 2024
1 parent 7e11100 commit 82182e9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/sound/midi-win/midi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ extern CSound* pSound;

void CMidi::MidiStart()
{
QString selMIDIDevice = pSound->GetMIDIDevice();

/* Get the number of MIDI In devices in this computer */
iMidiDevs = midiInGetNumDevs();
if ( iMidiDevs > MAX_MIDI_DEVS )
Expand All @@ -58,10 +60,20 @@ void CMidi::MidiStart()
if ( result != MMSYSERR_NOERROR )
{
qWarning() << qUtf8Printable ( QString ( "! Failed to identify MIDI input device %1. Error code: %2" ).arg ( i ).arg ( result ) );
hMidiIn[i] = 0;
continue; // try next device, if any
}

QString midiDev ( mic.szPname );

if ( !selMIDIDevice.isEmpty() && selMIDIDevice != midiDev )
{
qInfo() << qUtf8Printable ( QString ( " %1: %2 (ignored)" ).arg ( i ).arg ( midiDev ) );
hMidiIn[i] = 0;
continue; // try next device, if any
}

qInfo() << qUtf8Printable ( QString ( " %1: %2" ).arg ( i ).arg ( mic.szPname ) );
qInfo() << qUtf8Printable ( QString ( " %1: %2" ).arg ( i ).arg ( midiDev ) );

result = midiInOpen ( &hMidiIn[i], i, (DWORD_PTR) MidiCallback, 0, CALLBACK_FUNCTION );

Expand Down
2 changes: 1 addition & 1 deletion src/sound/soundbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ void CSoundBase::ParseCommandLineArgument ( const QString& strMIDISetup )
if ( eTyp == Device )
{
// save MIDI device name to select
strMIDIDevice = sParm.mid ( 1 );
strMIDIDevice = sParm.mid ( 1 );
}
else
{
Expand Down
2 changes: 2 additions & 0 deletions src/sound/soundbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ class CSoundBase : public QThread

virtual void OpenDriverSetup() {}

virtual const QString& GetMIDIDevice() { return strMIDIDevice; }

bool IsRunning() const { return bRun; }
bool IsCallbackEntered() const { return bCallbackEntered; }

Expand Down

0 comments on commit 82182e9

Please sign in to comment.