@@ -1447,9 +1447,18 @@ private void RefreshMidiOutputDevices()
14471447 label_channel . Enabled = true ;
14481448 comboBox_midi_output_channel . SelectedIndex = TemporarySettings . MIDIDevices . MIDIOutputDeviceChannel ;
14491449 comboBox_midi_output_channel . Enabled = true ;
1450- label_instrument . Enabled = true ;
1451- comboBox_midi_output_instrument . SelectedIndex = TemporarySettings . MIDIDevices . MIDIOutputInstrument ;
1452- comboBox_midi_output_instrument . Enabled = true ;
1450+ if ( TemporarySettings . MIDIDevices . MIDIOutputDeviceChannel != 9 )
1451+ {
1452+ label_instrument . Enabled = true ;
1453+ comboBox_midi_output_instrument . SelectedIndex = TemporarySettings . MIDIDevices . MIDIOutputInstrument ;
1454+ comboBox_midi_output_instrument . Enabled = true ;
1455+ }
1456+ else
1457+ {
1458+ label_instrument . Enabled = false ;
1459+ comboBox_midi_output_instrument . Enabled = false ;
1460+ comboBox_midi_output_instrument . SelectedIndex = - 1 ; // Deselect instrument
1461+ }
14531462 }
14541463 else
14551464 {
@@ -1521,19 +1530,47 @@ private void checkBox_use_midi_output_CheckedChanged(object sender, EventArgs e)
15211530
15221531 private void comboBox_midi_output_devices_SelectedIndexChanged ( object sender , EventArgs e )
15231532 {
1533+ if ( comboBox_midi_output_devices . SelectedIndex < 0 )
1534+ {
1535+ return ; // No device selected or deselected due to no available devices
1536+ }
15241537 TemporarySettings . MIDIDevices . MIDIOutputDevice = comboBox_midi_output_devices . SelectedIndex ;
15251538 MIDIIOUtils . ChangeOutputDevice ( TemporarySettings . MIDIDevices . MIDIOutputDevice ) ;
15261539 Logger . Log ( "MIDI output device selected: " + comboBox_midi_output_devices . SelectedItem . ToString ( ) , Logger . LogTypes . Info ) ;
15271540 }
15281541
15291542 private void comboBox_midi_output_channel_SelectedIndexChanged ( object sender , EventArgs e )
15301543 {
1544+ if ( comboBox_midi_output_channel . SelectedIndex < 0 )
1545+ {
1546+ return ; // No channel selected or deselected due to no available devices
1547+ }
15311548 TemporarySettings . MIDIDevices . MIDIOutputDeviceChannel = comboBox_midi_output_channel . SelectedIndex ;
1532- Logger . Log ( "MIDI output channel selected: " + comboBox_midi_output_channel . SelectedItem . ToString ( ) , Logger . LogTypes . Info ) ;
1549+ Logger . Log ( "MIDI output channel selected: Channel " + ( ( comboBox_midi_output_channel . SelectedIndex + 1 ) != 10 ?
1550+ ( comboBox_midi_output_channel . SelectedIndex + 1 ) . ToString ( ) :
1551+ ( comboBox_midi_output_channel . SelectedIndex + 1 ) . ToString ( ) + " (Percussion)" ) ,
1552+ Logger . LogTypes . Info ) ; // +1 to convert zero-based index to one-based channel number while logging
1553+ if ( TemporarySettings . MIDIDevices . MIDIOutputDeviceChannel == 9 ) // Percussion channel
1554+ {
1555+ label_instrument . Enabled = false ; // Disable the label
1556+ comboBox_midi_output_instrument . Enabled = false ; // Disable instrument selection
1557+ comboBox_midi_output_instrument . SelectedIndex = - 1 ; // Deselect instrument
1558+ Logger . Log ( "Percussion or sound effects channel selected; instrument selection disabled." , Logger . LogTypes . Info ) ;
1559+ }
1560+ else
1561+ {
1562+ label_instrument . Enabled = true ; // Enable the label
1563+ comboBox_midi_output_instrument . SelectedIndex = TemporarySettings . MIDIDevices . MIDIOutputInstrument ;
1564+ comboBox_midi_output_instrument . Enabled = true ; // Enable instrument selection
1565+ }
15331566 }
15341567
15351568 private void comboBox_midi_output_instrument_SelectedIndexChanged ( object sender , EventArgs e )
15361569 {
1570+ if ( comboBox_midi_output_instrument . SelectedIndex < 0 )
1571+ {
1572+ return ; // No instrument selected or deselected by percussion channel or no available devices
1573+ }
15371574 TemporarySettings . MIDIDevices . MIDIOutputInstrument = comboBox_midi_output_instrument . SelectedIndex ;
15381575 MIDIIOUtils . ChangeInstrument ( MIDIIOUtils . _midiOut , TemporarySettings . MIDIDevices . MIDIOutputInstrument ,
15391576 TemporarySettings . MIDIDevices . MIDIOutputDeviceChannel ) ;
0 commit comments