Browse Source

fix overprotective GUI when switching to banks not present in current sf2

master
Nils 1 year ago
parent
commit
603a12602b
  1. 13
      qtgui/mainwindow.py

13
qtgui/mainwindow.py

@ -297,8 +297,11 @@ class ChannelTreeItem(QtWidgets.QTreeWidgetItem):
def _populateComboBox_Program(self, bank:int, program:int):
self.comboBoxProgram.clear()
assert self.patchlist[bank] #not empty.
assert 0 <= program < 128, program
logger.info(f"populate: {bank}:{program}")
if not bank in self.patchlist:
logger.warning(f"Bank {bank} requested but not in sf2. Falling back to bank 0")
bank = 0
nowProgram = self.comboBoxProgram.currentIndex() #if below fails at least we don't get an error. Worst case is the wrong label.
for prgnr, patchname in self.patchlist[bank].items():
#Not every program is in every bank. But we don' want a drop down list with gaps.
@ -352,9 +355,8 @@ class ChannelTreeItem(QtWidgets.QTreeWidgetItem):
def reactToBankOrProgramChange(self, newIndex): #discard newIndex
bank = self.comboBoxBank.currentData()
program = self.comboBoxProgram.currentData()
assert not bank is None, bank
assert not program is None, program
api.setPatch(self.channelNumber, bank, program) # triggers self.callback_channelChanged
if not bank is None and not program is None:
api.setPatch(self.channelNumber, bank, program) # triggers self.callback_channelChanged
def callback_channelChanged(self, exportDict):
"""Either triggered by a GUI action, routed through the api, or by incoming midi message"""
@ -364,7 +366,8 @@ class ChannelTreeItem(QtWidgets.QTreeWidgetItem):
comboIndex = self.comboBoxBank.findData(exportDict["bank"])
if comboIndex == -1: #qt for "not found"
raise ValueError("Bank not in patchlist")
#This was stupid. A bank change to a non-existing instrument is valid: raise ValueError("Bank not in patchlist")
pass
else:
self.comboBoxBank.setCurrentIndex(comboIndex) #both 0 based

Loading…
Cancel
Save