From 5f44febbcd2fc46788d07c922327ac5fdd97f5a0 Mon Sep 17 00:00:00 2001 From: falkTX Date: Mon, 10 Sep 2012 00:14:40 +0100 Subject: [PATCH] Cadence: Implement jack options and force-restart --- Makefile | 8 +- src/cadence.py | 158 ++++++++++++++++++++++++++++++++++- src/systray.py | 2 +- src/ui/cadence.ui | 40 +++++++-- src/ui/cadence_rwait.ui | 43 ++++++++++ src/ui/cadence_tb_jack.ui | 169 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 406 insertions(+), 14 deletions(-) create mode 100644 src/ui/cadence_rwait.ui create mode 100644 src/ui/cadence_tb_jack.ui diff --git a/Makefile b/Makefile index 7d8740e..2b6ae3a 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ all: UI RES CPP UI: cadence catarina catia claudia carla tools -cadence: src/ui_cadence.py +cadence: src/ui_cadence.py src/ui_cadence_tb_jack.py src/ui_cadence_rwait.py catarina: src/ui_catarina.py \ src/ui_catarina_addgroup.py src/ui_catarina_removegroup.py src/ui_catarina_renamegroup.py \ @@ -51,6 +51,12 @@ tools: \ src/ui_cadence.py: src/ui/cadence.ui $(PYUIC) $< -o $@ +src/ui_cadence_tb_jack.py: src/ui/cadence_tb_jack.ui + $(PYUIC) $< -o $@ + +src/ui_cadence_rwait.py: src/ui/cadence_rwait.ui + $(PYUIC) $< -o $@ + src/ui_catarina.py: src/ui/catarina.ui $(PYUIC) $< -o $@ diff --git a/src/cadence.py b/src/cadence.py index 652c223..200c01d 100755 --- a/src/cadence.py +++ b/src/cadence.py @@ -24,10 +24,12 @@ except: # Imports (Global) from platform import architecture +from PyQt4.QtCore import QThread from PyQt4.QtGui import QApplication, QLabel, QMainWindow, QSizePolicy # Imports (Custom Stuff) import ui_cadence +import ui_cadence_tb_jack, ui_cadence_rwait import systray from shared_cadence import * from shared_jack import * @@ -319,6 +321,140 @@ def initSystemChecks(): # --------------------------------------------------------------------- +# Wait while JACK restarts +class ForceRestartThread(QThread): + def __init__(self, parent): + QThread.__init__(self, parent) + + self.m_wasStarted = False + + def wasJackStarted(self): + return self.m_wasStarted + + def run(self): + # Not started yet + self.m_wasStarted = False + self.emit(SIGNAL("progressChanged(int)"), 0) + + # Kill All + stopAllAudioProcesses() + self.emit(SIGNAL("progressChanged(int)"), 30) + + # Connect to jackdbus + self.parent().DBusReconnect() + + if not DBus.jack: + return + + for x in range(30): + self.emit(SIGNAL("progressChanged(int)"), 30+x*2) + procsList = getProcList() + if "jackdbus" in procsList: + break + else: + sleep(0.1) + + self.emit(SIGNAL("progressChanged(int)"), 90) + + # Start it + DBus.jack.StartServer() + self.emit(SIGNAL("progressChanged(int)"), 95) + + # If we made it this far, then JACK is started + self.m_wasStarted = True + + # Start A2J and Pulse according to user settings + if GlobalSettings.value("A2J/AutoStart", True, type=bool) and DBus.a2j and not bool(DBus.a2j.is_started()): + a2jExportHW = GlobalSettings.value("A2J/ExportHW", True, type=bool) + DBus.a2j.set_hw_export(a2jExportHW) + DBus.a2j.start() + + self.emit(SIGNAL("progressChanged(int)"), 100) + + # TODO + #if GlobalSettings.value("Pulse2JACK/AutoStart", True, type=bool) and not PA_is_bridged(): + #if GlobalSettings.value("Pulse2JACK/PlaybackModeOnly", False, type=bool): + #os.system("cadence-pulse2jack -p") + #else: + #os.system("cadence-pulse2jack") + +# Force Restart Dialog +class ForceWaitDialog(QDialog, ui_cadence_rwait.Ui_Dialog): + def __init__(self, parent): + QDialog.__init__(self, parent) + self.setupUi(self) + self.setWindowFlags(Qt.Dialog|Qt.WindowCloseButtonHint) + + self.rThread = ForceRestartThread(self) + self.rThread.start() + + self.connect(self.rThread, SIGNAL("progressChanged(int)"), self.progressBar, SLOT("setValue(int)")) + self.connect(self.rThread, SIGNAL("finished()"), SLOT("slot_rThreadFinished()")) + + def DBusReconnect(self): + self.parent().DBusReconnect() + + @pyqtSlot() + def slot_rThreadFinished(self): + self.close() + + if self.rThread.wasJackStarted(): + QMessageBox.information(self, self.tr("Info"), self.tr("JACK was re-started sucessfully")) + else: + QMessageBox.critical(self, self.tr("Error"), self.tr("Could not start JACK!")) + +# Additional JACK options +class ToolBarJackDialog(QDialog, ui_cadence_tb_jack.Ui_Dialog): + def __init__(self, parent): + QDialog.__init__(self, parent) + self.setupUi(self) + + self.m_ladishLoaded = False + + if haveDBus: + if GlobalSettings.value("JACK/AutoLoadLadishStudio", False, type=bool): + self.rb_ladish.setChecked(True) + self.m_ladishLoaded = True + elif "org.ladish" in DBus.bus.list_names(): + self.m_ladishLoaded = True + else: + self.rb_ladish.setEnabled(False) + self.rb_jack.setChecked(True) + + if self.m_ladishLoaded: + self.fillStudioNames() + + self.connect(self, SIGNAL("accepted()"), SLOT("slot_setOptions()")) + self.connect(self.rb_ladish, SIGNAL("clicked()"), SLOT("slot_maybeFillStudioNames()")) + + def fillStudioNames(self): + DBus.ladish_control = DBus.bus.get_object("org.ladish", "/org/ladish/Control") + + ladishStudioName = dbus.String(GlobalSettings.value("JACK/LadishStudioName", "", type=str)) + ladishStudioListDump = DBus.ladish_control.GetStudioList() + + if len(ladishStudioListDump) == 0: + self.rb_ladish.setEnabled(False) + self.rb_jack.setChecked(True) + else: + i=0 + for thisStudioName, thisStudioDict in ladishStudioListDump: + self.cb_studio_name.addItem(thisStudioName) + if ladishStudioName and thisStudioName == ladishStudioName: + self.cb_studio_name.setCurrentIndex(i) + i += 1 + + @pyqtSlot() + def slot_maybeFillStudioNames(self): + if not self.m_ladishLoaded: + self.fillStudioNames() + self.m_ladishLoaded = True + + @pyqtSlot() + def slot_setOptions(self): + GlobalSettings.setValue("JACK/AutoLoadLadishStudio", self.rb_ladish.isChecked()) + GlobalSettings.setValue("JACK/LadishStudioName", self.cb_studio_name.currentText()) + # Main Window class CadenceMainW(QMainWindow, ui_cadence.Ui_CadenceMainW): def __init__(self, parent=None): @@ -328,9 +464,6 @@ class CadenceMainW(QMainWindow, ui_cadence.Ui_CadenceMainW): self.settings = QSettings("Cadence", "Cadence") self.loadSettings(True) - # TODO - self.b_jack_restart.setEnabled(False) - self.pix_apply = QIcon(getIcon("dialog-ok-apply", 16)).pixmap(16, 16) self.pix_cancel = QIcon(getIcon("dialog-cancel", 16)).pixmap(16, 16) self.pix_error = QIcon(getIcon("dialog-error", 16)).pixmap(16, 16) @@ -584,6 +717,7 @@ class CadenceMainW(QMainWindow, ui_cadence.Ui_CadenceMainW): self.connect(self.b_jack_stop, SIGNAL("clicked()"), SLOT("slot_JackServerStop()")) self.connect(self.b_jack_restart, SIGNAL("clicked()"), SLOT("slot_JackServerForceRestart()")) self.connect(self.b_jack_configure, SIGNAL("clicked()"), SLOT("slot_JackServerConfigure()")) + self.connect(self.tb_jack_options, SIGNAL("clicked()"), SLOT("slot_JackOptions()")) self.connect(self.act_tools_catarina, SIGNAL("triggered()"), lambda tool="catarina": self.func_start_tool(tool)) self.connect(self.act_tools_catia, SIGNAL("triggered()"), lambda tool="catia": self.func_start_tool(tool)) @@ -793,7 +927,19 @@ class CadenceMainW(QMainWindow, ui_cadence.Ui_CadenceMainW): @pyqtSlot() def slot_JackServerForceRestart(self): - pass + if DBus.jack.IsStarted(): + ask = CustomMessageBox(self, QMessageBox.Warning, self.tr("Warning"), + self.tr("This will force kill all JACK applications!
Make sure to save your projects before continue."), + self.tr("Are you sure you want to force the restart of JACK?")) + + if ask != QMessageBox.Yes: + return + + if self.m_timer250: + self.killTimer(self.m_timer250) + self.m_timer250 = None + + ForceWaitDialog(self).exec_() @pyqtSlot() def slot_JackServerConfigure(self): @@ -801,6 +947,10 @@ class CadenceMainW(QMainWindow, ui_cadence.Ui_CadenceMainW): jacksettingsW.exec_() del jacksettingsW + @pyqtSlot() + def slot_JackOptions(self): + ToolBarJackDialog(self).exec_() + @pyqtSlot() def slot_JackClearXruns(self): if DBus.jack: diff --git a/src/systray.py b/src/systray.py index e5e26ef..777f14f 100644 --- a/src/systray.py +++ b/src/systray.py @@ -48,7 +48,7 @@ try: TrayEngine = "AppIndicator" - elif getenv("KDE_FULL_SESSION"): + elif getenv("KDE_FULL_SESSION") or getenv("DESKTOP_SESSION") == "kde-plasma": from PyKDE4.kdeui import KAction, KIcon, KMenu, KStatusNotifierItem TrayEngine = "KDE" diff --git a/src/ui/cadence.ui b/src/ui/cadence.ui index cbe53d2..dd71d58 100644 --- a/src/ui/cadence.ui +++ b/src/ui/cadence.ui @@ -455,7 +455,7 @@ - + ... @@ -474,7 +474,15 @@ - + + + + 0 + 0 + 343 + 89 + + ALSA Audio @@ -586,7 +594,15 @@ - + + + + 0 + 0 + 298 + 81 + + ALSA MIDI @@ -691,7 +707,15 @@ - + + + + 0 + 0 + 212 + 81 + + PulseAudio @@ -1382,7 +1406,7 @@ 0 0 - 76 + 94 76 @@ -1400,7 +1424,7 @@ 0 0 - 89 + 94 76 @@ -1418,7 +1442,7 @@ 0 0 - 89 + 94 76 @@ -1436,7 +1460,7 @@ 0 0 - 89 + 94 76 diff --git a/src/ui/cadence_rwait.ui b/src/ui/cadence_rwait.ui new file mode 100644 index 0000000..4df1114 --- /dev/null +++ b/src/ui/cadence_rwait.ui @@ -0,0 +1,43 @@ + + + Dialog + + + + 0 + 0 + 315 + 120 + + + + Restarting JACK + + + + + + + 12 + + + + Please wait... + + + Qt::AlignCenter + + + + + + + 0 + + + + + + + + diff --git a/src/ui/cadence_tb_jack.ui b/src/ui/cadence_tb_jack.ui new file mode 100644 index 0000000..e447493 --- /dev/null +++ b/src/ui/cadence_tb_jack.ui @@ -0,0 +1,169 @@ + + + Dialog + + + + 0 + 0 + 389 + 118 + + + + JACK Options + + + + + + Load JACK Default Settings + + + true + + + + + + + Load LADISH Studio + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + false + + + Studio Name: + + + + + + + false + + + + 0 + 0 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + Dialog + accept() + + + 224 + 113 + + + 157 + 129 + + + + + buttonBox + rejected() + Dialog + reject() + + + 292 + 119 + + + 286 + 129 + + + + + rb_ladish + toggled(bool) + label + setEnabled(bool) + + + 83 + 38 + + + 78 + 63 + + + + + rb_ladish + toggled(bool) + cb_studio_name + setEnabled(bool) + + + 115 + 34 + + + 163 + 67 + + + + +