Skip to content

Commit 45942ac

Browse files
committed
Reset Channel Instruments on File Load
1 parent cf33de8 commit 45942ac

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

src/gui/MainWindow.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,18 @@ void MainWindow::setFile(MidiFile *newFile) {
749749
copiedEventsChanged();
750750
checkEnableActionsForSelection();
751751

752+
// Reset MIDI output channel programs and apply initial program changes
753+
if (MidiOutput::isConnected()) {
754+
MidiOutput::resetChannelPrograms();
755+
// Send program change events from the beginning of the file
756+
for (int ch = 0; ch < 16; ch++) {
757+
int prog = file->channel(ch)->progAtTick(0);
758+
if (prog >= 0) {
759+
MidiOutput::sendProgram(ch, prog);
760+
}
761+
}
762+
}
763+
752764
// Clean up the old file after everything has been switched to the new file
753765
// This ensures all widgets have switched to the new file before cleanup
754766
if (oldFile) {

src/midi/MidiOutput.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,14 @@ void MidiOutput::sendProgram(int channel, int prog) {
149149
sendCommand(array);
150150
}
151151

152+
void MidiOutput::resetChannelPrograms()
153+
{
154+
// Reset all 16 MIDI channels to program 0 (Acoustic Grand Piano in GM)
155+
for (int channel = 0; channel < 16; channel++) {
156+
sendProgram(channel, 0);
157+
}
158+
}
159+
152160
bool MidiOutput::isConnected() {
153161
return _outPort != "";
154162
}

src/midi/MidiOutput.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ class MidiOutput : public QObject {
131131
*/
132132
static void sendProgram(int channel, int prog);
133133

134+
/**
135+
* \brief Resets the MIDI channel program instruments.
136+
*/
137+
static void resetChannelPrograms();
138+
134139
// === Public State Variables ===
135140

136141
/** \brief Flag indicating if using alternative player */

0 commit comments

Comments
 (0)