From 47e0505b7382b0fd52988af24815c694ca7b4e7f Mon Sep 17 00:00:00 2001 From: Nils <> Date: Sat, 13 Feb 2021 20:16:26 +0100 Subject: [PATCH] update template --- template/engine/sequencer.py | 13 ++++++++++++- template/qtgui/mainwindow.py | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/template/engine/sequencer.py b/template/engine/sequencer.py index 2541da2..a68af4f 100644 --- a/template/engine/sequencer.py +++ b/template/engine/sequencer.py @@ -61,6 +61,7 @@ class Score(Data): self.tracks = [] #see docstring self.tempoMap = TempoMap(parentData = self) self._template_processAfterInit() + self._tracksFailedLookup = [] def _template_processAfterInit(self): #needs a different name because there is an inherited class with the same method. """Call this after either init or instanceFromSerializedData""" @@ -119,11 +120,21 @@ class Score(Data): except Exception as e: #No Jack Meta Data or Error with ports. logger.error(e) + def trackById(self, trackId:int): + """Returns a track or None, if not found""" for track in self.tracks: if trackId == id(track): return track - raise ValueError(f"Track {trackId} not found. Current Tracks: {[id(tr) for tr in self.tracks]}") + else: + #Previously this crashed with a ValueError. However, after a rare bug that a gui widget focussed out because a track was deleted and then tried to send its value to the engine we realize that this lookup can gracefully return None. + #Nothing will break: Functions that are not aware yet, that None is an option will crash when they try to access None as a track object. For this case we present the following logger error: + if not trackId in self._tracksFailedLookup: + logger.error(f"Track {trackId} not found. Current Tracks: {[id(tr) for tr in self.tracks]}") + self._tracksFailedLookup.append(trackId) #prevent multiple error messages for the same track in a row. + return None + #raise ValueError(f"Track {trackId} not found. Current Tracks: {[id(tr) for tr in self.tracks]}") + #Save / Load / Export diff --git a/template/qtgui/mainwindow.py b/template/qtgui/mainwindow.py index 9c4149c..4e9ee7a 100644 --- a/template/qtgui/mainwindow.py +++ b/template/qtgui/mainwindow.py @@ -57,6 +57,7 @@ api.session.eventLoop = EventLoop() #Setup the translator before classes are set up. Otherwise we can't use non-template translation. #to test use LANGUAGE=de_DE.UTF-8 . not LANG= +#Language variants like de_AT.UTF-8 will be detected automatically and will result in Qt language detection as "German" language = QtCore.QLocale().languageToString(QtCore.QLocale().language()) logger.info("{}: Language set to {}".format(METADATA["name"], language)) if language in METADATA["supportedLanguages"]: