Browse Source

update template

master
Nils 4 years ago
parent
commit
8c90857e9a
  1. 7
      template/engine/api.py
  2. 11
      template/engine/sampler_sf2.py
  3. 4
      template/engine/session.py
  4. 6
      template/helper.py
  5. 2
      template/qtgui/mainwindow.py
  6. 20
      template/qtgui/nsmclient.py
  7. 6
      template/start.py

7
template/engine/api.py

@ -130,6 +130,8 @@ class Callbacks(object):
def _setPlaybackTicks(self): def _setPlaybackTicks(self):
"""This gets called very very often. Any connected function needs to watch closely
for performance issues"""
ppqn = cbox.Transport.status().pos_ppqn ppqn = cbox.Transport.status().pos_ppqn
status = playbackStatus() status = playbackStatus()
for func in self.setPlaybackTicks: for func in self.setPlaybackTicks:
@ -146,6 +148,8 @@ class Callbacks(object):
This is deprecated. Append to _checkPlaybackStatusAndSendSignal which is checked by the This is deprecated. Append to _checkPlaybackStatusAndSendSignal which is checked by the
event loop. event loop.
""" """
raise NotImplementedError("this function was deprecated. use _checkPlaybackStatusAndSendSignal")
pass #only keep for the docstring and to keep the pattern. pass #only keep for the docstring and to keep the pattern.
def _checkPlaybackStatusAndSendSignal(self): def _checkPlaybackStatusAndSendSignal(self):
@ -286,6 +290,7 @@ def startEngine(nsmClient):
it takes after imports. it takes after imports.
""" """
logger.info("Starting template api engine")
assert session assert session
assert callbacks assert callbacks
@ -301,6 +306,8 @@ def startEngine(nsmClient):
callbacks._recordingModeChanged() #recording mode is in the save file. callbacks._recordingModeChanged() #recording mode is in the save file.
callbacks._historyChanged() #send initial undo status to the GUI, which will probably deactivate its undo/redo menu because it is empty. callbacks._historyChanged() #send initial undo status to the GUI, which will probably deactivate its undo/redo menu because it is empty.
logger.info("Template api engine started")
def _deprecated_updatePlayback(): def _deprecated_updatePlayback():
"""The only place in the program to update the cbox playback besides startEngine. """The only place in the program to update the cbox playback besides startEngine.

11
template/engine/sampler_sf2.py

@ -76,8 +76,15 @@ class Sampler_sf2(Data):
#Create a dynamic pair of audio output ports and route all stereo pairs to our summing channel. #Create a dynamic pair of audio output ports and route all stereo pairs to our summing channel.
#This does _not_ need updating when loading another sf2 or changing instruments. #This does _not_ need updating when loading another sf2 or changing instruments.
lmixUuid = cbox.JackIO.create_audio_output('left_mix', "#1") #add "#1" as second parameter for auto-connection to system out 1
rmixUuid = cbox.JackIO.create_audio_output('right_mix', "#2") #add "#2" as second parameter for auto-connection to system out 2 assert not self.parentSession.standaloneMode is None
if self.parentSession.standaloneMode:
lmixUuid = cbox.JackIO.create_audio_output('left_mix', "#1") #add "#1" as second parameter for auto-connection to system out 1
rmixUuid = cbox.JackIO.create_audio_output('right_mix', "#2") #add "#2" as second parameter for auto-connection to system out 2
else:
lmixUuid = cbox.JackIO.create_audio_output('left_mix')
rmixUuid = cbox.JackIO.create_audio_output('right_mix')
for i in range(16): for i in range(16):
router = cbox.JackIO.create_audio_output_router(lmixUuid, rmixUuid) router = cbox.JackIO.create_audio_output_router(lmixUuid, rmixUuid)
router.set_gain(-3.0) router.set_gain(-3.0)

4
template/engine/session.py

@ -51,7 +51,7 @@ class Session(object):
self.recordingEnabled = False #MidiInput callbacks can use this to prevent/allow data creation. Handled via api callback. Saved. self.recordingEnabled = False #MidiInput callbacks can use this to prevent/allow data creation. Handled via api callback. Saved.
self.eventLoop = None # added in api.startEngine self.eventLoop = None # added in api.startEngine
self.data = None #nsm_openOrNewCallback self.data = None #nsm_openOrNewCallback
self.standaloneMode = None #fake NSM single server for LaborejoSoftwareSuite programs or not. Set in nsm_openOrNewCallback
def addSessionPrefix(self, jsonDataAsString:str): def addSessionPrefix(self, jsonDataAsString:str):
"""During load the current session prefix gets added. Turning pseudo-relative paths into """During load the current session prefix gets added. Turning pseudo-relative paths into
@ -103,6 +103,8 @@ class Session(object):
self.sessionPrefix = ourPath #if we want to save and load resources they need to be in the session dir. We never load from outside, the scheme is always "import first, load local file" self.sessionPrefix = ourPath #if we want to save and load resources they need to be in the session dir. We never load from outside, the scheme is always "import first, load local file"
self.absoluteJsonFilePath = os.path.join(ourPath, "save." + METADATA["shortName"] + ".json") self.absoluteJsonFilePath = os.path.join(ourPath, "save." + METADATA["shortName"] + ".json")
self.standaloneMode = sessionName == "NOT-A-SESSION"
try: try:
self.data = self.openFromJson(self.absoluteJsonFilePath) self.data = self.openFromJson(self.absoluteJsonFilePath)
except FileNotFoundError: except FileNotFoundError:

6
template/helper.py

@ -95,4 +95,10 @@ def whoCalled():
print() print()
def provokecrash():
"""Obviously for testing"""
import ctypes
p = ctypes.pointer(ctypes.c_char.from_address(5))
p[0] = b'x'

2
template/qtgui/mainwindow.py

@ -186,7 +186,7 @@ class MainWindow(QtWidgets.QMainWindow):
if not settings.contains("showAboutDialog"): if not settings.contains("showAboutDialog"):
settings.setValue("showAboutDialog", METADATA["showAboutDialogFirstStart"]) settings.setValue("showAboutDialog", METADATA["showAboutDialogFirstStart"])
self.about = About(mainWindow=self) self.about = About(mainWindow=self) #This does not show, it only creates. Showing is decided in self.start
self.ui.menubar.setNativeMenuBar(False) #Force a real menu bar. Qt on wayland will not display it otherwise. self.ui.menubar.setNativeMenuBar(False) #Force a real menu bar. Qt on wayland will not display it otherwise.
self.menu = Menu(mainWindow=self) #needs the about dialog, save file and the api.session ready. self.menu = Menu(mainWindow=self) #needs the about dialog, save file and the api.session ready.

20
template/qtgui/nsmclient.py

@ -548,18 +548,14 @@ class NSMClient(object):
"""If you want a very strict client you can block any non-NSM quit-attempts, like ignoring a """If you want a very strict client you can block any non-NSM quit-attempts, like ignoring a
qt closeEvent, and instead send the NSM Server a request to close this client. qt closeEvent, and instead send the NSM Server a request to close this client.
This method is a shortcut to do just that. This method is a shortcut to do just that.
"""
Using this method will not result in a NSM-"client died unexpectedly" message that usually logger.info("Sending SIGTERM to ourselves to trigger the exit callback.")
happens a client quits on its own. This message is harmless but may confuse a user.""" #if "server-control" in self.serverFeatures:
# message = _OutgoingMessage("/nsm/server/stop")
logger.info("instructing the NSM-Server to send SIGTERM to ourselves.") # message.add_arg("{}".format(self.ourClientId))
if "server-control" in self.serverFeatures: # self.sock.sendto(message.build(), self.nsmOSCUrl)
message = _OutgoingMessage("/nsm/server/stop") #else:
message.add_arg("{}".format(self.ourClientId)) kill(getpid(), SIGTERM) #this calls the exit callback
self.sock.sendto(message.build(), self.nsmOSCUrl)
else:
logger.warning("...but the NSM-Server does not support server control. Quitting on our own. Server only supports: {}".format(self.serverFeatures))
kill(getpid(), SIGTERM) #this calls the exit callback but nsm will output something like "client died unexpectedly."
def serverSendSaveToSelf(self): def serverSendSaveToSelf(self):
"""Some clients want to offer a manual Save function, mostly for psychological reasons. """Some clients want to offer a manual Save function, mostly for psychological reasons.

6
template/start.py

@ -360,3 +360,9 @@ except Exception as e:
exitWithMessage("Calfbox module could not be loaded") exitWithMessage("Calfbox module could not be loaded")
#Capture Ctlr+C / SIGINT and let @atexit handle the rest.
import signal
import sys
def signal_handler(sig, frame):
sys.exit(0) #atexit will trigger
signal.signal(signal.SIGINT, signal_handler)

Loading…
Cancel
Save