Browse Source

Remember and restore jack connections when changing the sample dir during runtime

master
Nils 2 years ago
parent
commit
37f73aa822
  1. 47
      engine/main.py

47
engine/main.py

@ -104,6 +104,9 @@ class Data(TemplateData):
libsToDelete.remove(defaultLib.id)
logger.info(f"Start opening and parsing instrument metadata from {baseSamplePath}")
checkForDuplicateLibraryFiles = set() #lib ids. only one lib with the same id is allowed.
for f in basePath.glob('*.tar'):
if f.is_file() and f.suffix == ".tar":
#First load the library (this is .ini parsing, not sample loading, so it is cheap) and create a library object
@ -113,6 +116,15 @@ class Data(TemplateData):
except PermissionError as e:
logger.error(f"Library {f} could not be loaded. The reason follows: {e}")
continue
#Check for duplication error.
if lib.id in checkForDuplicateLibraryFiles:
logger.error(f"Library {f} with id {lib.id} has a duplicate library id and will not be loaded. This only happens when manually copying and duplicating files in the sample dir. Don't do that, please.")
continue
else:
checkForDuplicateLibraryFiles.add(lib.id)
#Then compare if this is actually a file we already knew:
#we loaded this before and it still exists. We will NOT delete it below.
@ -403,8 +415,43 @@ class Library(object):
tmpKeySw = oldInstrument.currentKeySwitch
tmpMix = oldInstrument.mixerLevel
#Remember current jack connections, if any.
try:
lname = cbox.JackIO.status().client_name + ":" + oldInstrument.midiInputPortName +"_L"
portlistLeft = cbox.JackIO.get_connected_ports(lname)
except: #port not found.
portlistLeft = []
try:
rname = cbox.JackIO.status().client_name + ":" + oldInstrument.midiInputPortName +"_R"
portlistRight = cbox.JackIO.get_connected_ports(rname)
except: #port not found.
portlistRight = []
try:
midiname = cbox.JackIO.status().client_name + ":" + oldInstrument.midiInputPortName
portlistMidi = cbox.JackIO.get_connected_ports(midiname)
except: #port not found.
portlistMidi = []
oldInstrument.disable() #frees jack port names
ourNewInstrument.enable()
#Reconnect jack connections, if any.
for port in portlistLeft:
try:
cbox.JackIO.port_connect(lname, port) #order matters
except:
pass
for port in portlistRight:
try:
cbox.JackIO.port_connect(rname, port) #order matters
except:
pass
for port in portlistMidi:
try:
cbox.JackIO.port_connect(port, midiname) #order matters
except:
pass
ourNewInstrument.chooseVariant(tmpCurVar)
if tmpKeySw:
ourNewInstrument.setKeySwitch(tmpKeySw)

Loading…
Cancel
Save