Skip to content
This repository has been archived by the owner on Aug 21, 2023. It is now read-only.

Commit

Permalink
A2JMIDI: Simplify UI
Browse files Browse the repository at this point in the history
- Remove "Export HW Ports" button
- Make the "Export Ports" checkbox apply changes immediately
- Change the status label to show when ports are exported
  • Loading branch information
terencode authored and falkTX committed Nov 17, 2019
1 parent b69d157 commit a2e733a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 33 deletions.
9 changes: 1 addition & 8 deletions resources/ui/cadence.ui
Expand Up @@ -782,13 +782,6 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="b_a2j_export_hw">
<property name="text">
<string>Export HW ports</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_8">
<property name="orientation">
Expand Down Expand Up @@ -825,7 +818,7 @@
<item>
<widget class="QCheckBox" name="cb_a2j_autoexport">
<property name="text">
<string>Export ports on startup</string>
<string>Export hardware ports</string>
</property>
</widget>
</item>
Expand Down
33 changes: 8 additions & 25 deletions src/cadence.py
Expand Up @@ -1063,7 +1063,6 @@ def __init__(self, parent=None):
self.systray.addMenu("a2j", self.tr("ALSA MIDI Bridge"))
self.systray.addMenuAction("a2j", "a2j_start", self.tr("Start"))
self.systray.addMenuAction("a2j", "a2j_stop", self.tr("Stop"))
self.systray.addMenuAction("a2j", "a2j_export_hw", self.tr("Export Hardware Ports..."))
self.systray.addMenu("pulse", self.tr("PulseAudio Bridge"))
self.systray.addMenuAction("pulse", "pulse_start", self.tr("Start"))
self.systray.addMenuAction("pulse", "pulse_stop", self.tr("Stop"))
Expand All @@ -1085,7 +1084,6 @@ def __init__(self, parent=None):
self.systray.connect("alsa_stop", self.slot_AlsaBridgeStop)
self.systray.connect("a2j_start", self.slot_A2JBridgeStart)
self.systray.connect("a2j_stop", self.slot_A2JBridgeStop)
self.systray.connect("a2j_export_hw", self.slot_A2JBridgeExportHW)
self.systray.connect("pulse_start", self.slot_PulseAudioBridgeStart)
self.systray.connect("pulse_stop", self.slot_PulseAudioBridgeStop)

Expand Down Expand Up @@ -1130,7 +1128,6 @@ def __init__(self, parent=None):

self.b_a2j_start.clicked.connect(self.slot_A2JBridgeStart)
self.b_a2j_stop.clicked.connect(self.slot_A2JBridgeStop)
self.b_a2j_export_hw.clicked.connect(self.slot_A2JBridgeExportHW)
self.b_pulse_start.clicked.connect(self.slot_PulseAudioBridgeStart)
self.b_pulse_stop.clicked.connect(self.slot_PulseAudioBridgeStop)
self.tb_pulse_options.clicked.connect(self.slot_PulseAudioBridgeOptions)
Expand Down Expand Up @@ -1189,6 +1186,7 @@ def __init__(self, parent=None):
# org.gna.home.a2jmidid.control
self.DBusA2JBridgeStartedCallback.connect(self.slot_DBusA2JBridgeStartedCallback)
self.DBusA2JBridgeStoppedCallback.connect(self.slot_DBusA2JBridgeStoppedCallback)
self.cb_a2j_autoexport.stateChanged[int].connect(self.slot_A2JBridgeExportHW)

# -------------------------------------------------------------

Expand Down Expand Up @@ -1342,21 +1340,12 @@ def jackStarted(self):
if GlobalSettings.value("A2J/AutoStart", True, type=bool):
if not portsExported and GlobalSettings.value("A2J/AutoExport", True, type=bool):
gDBus.a2j.set_hw_export(True)
self.systray.setActionEnabled("a2j_start", False)
portsExported = True
gDBus.a2j.start()
else:
self.b_a2j_start.setEnabled(True)
self.b_a2j_export_hw.setEnabled(True)
self.systray.setActionEnabled("a2j_start", True)

if portsExported:
self.b_a2j_export_hw.setText('Ports exported!')

# It is only needed to export the ports initially, new ones will appear automatically
self.b_a2j_export_hw.setEnabled(not portsExported)
self.systray.setActionEnabled("a2j_export_hw", not portsExported)

self.checkAlsaAudio()
self.checkPulseAudio()

Expand Down Expand Up @@ -1388,10 +1377,7 @@ def jackStopped(self):

if gDBus.a2j:
self.b_a2j_start.setEnabled(False)
self.b_a2j_export_hw.setEnabled(False)
self.systray.setActionEnabled("a2j_start", False)
if bool(gDBus.a2j.get_hw_export()):
self.b_a2j_export_hw.setText('Ports exported!')

global jackClientIdALSA, jackClientIdPulse
jackClientIdALSA = -1
Expand All @@ -1406,17 +1392,17 @@ def a2jStarted(self):
self.b_a2j_stop.setEnabled(True)
self.systray.setActionEnabled("a2j_start", False)
self.systray.setActionEnabled("a2j_stop", True)
self.label_bridge_a2j.setText(self.tr("ALSA MIDI Bridge is running"))
if bool(gDBus.a2j.get_hw_export()):
self.label_bridge_a2j.setText(self.tr("ALSA MIDI Bridge is running, ports are exported"))
else :
self.label_bridge_a2j.setText(self.tr("ALSA MIDI Bridge is running"))

def a2jStopped(self):
jackRunning = bool(gDBus.jack and gDBus.jack.IsStarted())
needExport = bool(not gDBus.a2j.get_hw_export() and jackRunning)
self.b_a2j_start.setEnabled(jackRunning)
self.b_a2j_stop.setEnabled(False)
self.systray.setActionEnabled("a2j_start", jackRunning)
self.systray.setActionEnabled("a2j_stop", False)
self.systray.setActionEnabled("a2j_export_hw", needExport)
self.b_a2j_export_hw.setEnabled(needExport)
self.label_bridge_a2j.setText(self.tr("ALSA MIDI Bridge is stopped"))

def checkAlsaAudio(self):
Expand Down Expand Up @@ -1788,17 +1774,14 @@ def slot_A2JBridgeStart(self):
def slot_A2JBridgeStop(self):
gDBus.a2j.stop()

@pyqtSlot()
def slot_A2JBridgeExportHW(self):
@pyqtSlot(int)
def slot_A2JBridgeExportHW(self, state):
a2jWasStarted = bool(gDBus.a2j.is_started())

if a2jWasStarted:
gDBus.a2j.stop()

gDBus.a2j.set_hw_export(True)
self.b_a2j_export_hw.setText('Ports exported!')
self.b_a2j_export_hw.setEnabled(False)
self.systray.setActionEnabled("a2j_export_hw", False)
gDBus.a2j.set_hw_export(bool(state))

if a2jWasStarted:
gDBus.a2j.start()
Expand Down

0 comments on commit a2e733a

Please sign in to comment.