Cadence: Run DBus stuff only on main thread

This commit is contained in:
falkTX 2018-03-19 09:51:52 +01:00
parent 9bf9965d20
commit 4489a66d51
2 changed files with 31 additions and 10 deletions

View File

@ -22,10 +22,10 @@
from platform import architecture from platform import architecture
if True: if True:
from PyQt5.QtCore import QFileSystemWatcher, QThread from PyQt5.QtCore import QFileSystemWatcher, QThread, QSemaphore
from PyQt5.QtWidgets import QApplication, QDialogButtonBox, QLabel, QMainWindow, QSizePolicy from PyQt5.QtWidgets import QApplication, QDialogButtonBox, QLabel, QMainWindow, QSizePolicy
else: else:
from PyQt4.QtCore import QFileSystemWatcher, QThread from PyQt4.QtCore import QFileSystemWatcher, QThread, QSemaphore
from PyQt4.QtGui import QApplication, QDialogButtonBox, QLabel, QMainWindow, QSizePolicy from PyQt4.QtGui import QApplication, QDialogButtonBox, QLabel, QMainWindow, QSizePolicy
# ------------------------------------------------------------------------------------------------------------ # ------------------------------------------------------------------------------------------------------------
@ -528,21 +528,30 @@ class ForceRestartThread(QThread):
QThread.__init__(self, parent) QThread.__init__(self, parent)
self.m_wasStarted = False self.m_wasStarted = False
self.m_a2jExportHW = False
def wasJackStarted(self): def wasJackStarted(self):
return self.m_wasStarted return self.m_wasStarted
def startA2J(self):
gDBus.a2j.set_hw_export(self.m_a2jExportHW)
gDBus.a2j.start()
def run(self): def run(self):
# Not started yet # Not started yet
self.m_wasStarted = False self.m_wasStarted = False
self.progressChanged.emit(0) self.progressChanged.emit(0)
# Stop JACK safely first, if possible
runFunctionInMainThread(tryCloseJackDBus)
self.progressChanged.emit(20)
# Kill All # Kill All
stopAllAudioProcesses() stopAllAudioProcesses(False)
self.progressChanged.emit(30) self.progressChanged.emit(30)
# Connect to jackdbus # Connect to jackdbus
self.parent().DBusReconnect() runFunctionInMainThread(self.parent().DBusReconnect)
if not gDBus.jack: if not gDBus.jack:
return return
@ -558,7 +567,7 @@ class ForceRestartThread(QThread):
self.progressChanged.emit(90) self.progressChanged.emit(90)
# Start it # Start it
gDBus.jack.StartServer() runFunctionInMainThread(gDBus.jack.StartServer)
self.progressChanged.emit(93) self.progressChanged.emit(93)
# If we made it this far, then JACK is started # If we made it this far, then JACK is started
@ -575,9 +584,8 @@ class ForceRestartThread(QThread):
# ALSA-MIDI # ALSA-MIDI
if GlobalSettings.value("A2J/AutoStart", True, type=bool) and gDBus.a2j and not bool(gDBus.a2j.is_started()): if GlobalSettings.value("A2J/AutoStart", True, type=bool) and gDBus.a2j and not bool(gDBus.a2j.is_started()):
a2jExportHW = GlobalSettings.value("A2J/ExportHW", True, type=bool) self.m_a2jExportHW = GlobalSettings.value("A2J/ExportHW", True, type=bool)
gDBus.a2j.set_hw_export(a2jExportHW) runFunctionInMainThread(self.startA2J)
gDBus.a2j.start()
self.progressChanged.emit(96) self.progressChanged.emit(96)
@ -2325,6 +2333,18 @@ class CadenceMainW(QMainWindow, ui_cadence.Ui_CadenceMainW):
self.saveSettings() self.saveSettings()
self.systray.handleQtCloseEvent(event) self.systray.handleQtCloseEvent(event)
# ------------------------------------------------------------------------------------------------------------
def runFunctionInMainThread(task):
waiter = QSemaphore(1)
def taskInMainThread():
task()
waiter.release()
QTimer.singleShot(0, taskInMainThread)
waiter.tryAcquire()
#--------------- main ------------------ #--------------- main ------------------
if __name__ == '__main__': if __name__ == '__main__':
# App initialization # App initialization

View File

@ -139,8 +139,9 @@ def tryCloseJackDBus():
# ------------------------------------------------------------------------------------------------------------ # ------------------------------------------------------------------------------------------------------------
# Stop all audio processes, used for force-restart # Stop all audio processes, used for force-restart
def stopAllAudioProcesses(): def stopAllAudioProcesses(tryCloseJack = True):
tryCloseJackDBus() if tryCloseJack:
tryCloseJackDBus()
if not (HAIKU or LINUX or MACOS): if not (HAIKU or LINUX or MACOS):
print("stopAllAudioProcesses() - Not supported in this system") print("stopAllAudioProcesses() - Not supported in this system")