2 # -*- coding: utf-8 -*-
5 # Copyright (C) 2011-2022 Filipe Coelho <falktx@falktx.com>
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License as
9 # published by the Free Software Foundation; either version 2 of
10 # the License, or any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # For a full copy of the GNU General Public License see the doc/GPL.txt file.
19 # ---------------------------------------------------------------------------------------------------------------------
24 from PyQt5
.QtCore
import pyqtSlot
, Qt
25 from PyQt5
.QtWidgets
import QDialog
, QDialogButtonBox
, QWidget
27 # ---------------------------------------------------------------------------------------------------------------------
30 from utils
import QSafeSettings
32 # ---------------------------------------------------------------------------------------------------------------------
35 from jackappdialog_ui
import Ui_JackAppDialog
37 # ---------------------------------------------------------------------------------------------------------------------
43 SESSION_MGR_LADISH
= 3
46 FLAG_CONTROL_WINDOW
= 0x01
47 FLAG_CAPTURE_FIRST_WINDOW
= 0x02
48 FLAG_BUFFERS_ADDITION_MODE
= 0x10
49 FLAG_MIDI_OUTPUT_CHANNEL_MIXDOWN
= 0x20
50 FLAG_EXTERNAL_START
= 0x40
52 # ---------------------------------------------------------------------------------------------------------------------
53 # Jack Application Dialog
59 class JackAppDialog(QDialog
):
60 def __init__(self
, parent
: QWidget
, projectFilename
: str):
61 QDialog
.__init
__(self
, parent
)
62 self
.ui
= Ui_JackAppDialog()
65 self
.fProjectFilename
= projectFilename
67 # --------------------------------------------------------------------------------------------------------------
70 self
.ui
.group_error
.setVisible(False)
72 self
.setWindowFlags(self
.windowFlags() & ~Qt
.WindowContextHelpButtonHint
)
74 # --------------------------------------------------------------------------------------------------------------
79 # --------------------------------------------------------------------------------------------------------------
82 self
.finished
.connect(self
._slot
_saveSettings
)
83 self
.ui
.cb_session_mgr
.currentIndexChanged
.connect(self
._slot
_sessionManagerChanged
)
84 self
.ui
.le_command
.textChanged
.connect(self
._slot
_commandChanged
)
86 # -----------------------------------------------------------------------------------------------------------------
89 def getCommandAndFlags(self
):
90 name
= self
.ui
.le_name
.text()
91 command
= self
.ui
.le_command
.text()
92 smgr
= SESSION_MGR_NONE
96 name
= os
.path
.basename(command
.split(" ",1)[0]).title()
98 uiSessionMgrIndex
= self
.ui
.cb_session_mgr
.currentIndex()
99 if uiSessionMgrIndex
== UI_SESSION_LADISH
:
100 smgr
= SESSION_MGR_LADISH
101 elif uiSessionMgrIndex
== UI_SESSION_NSM
:
102 smgr
= SESSION_MGR_NSM
104 if self
.ui
.cb_manage_window
.isChecked():
105 flags |
= FLAG_CONTROL_WINDOW
106 if self
.ui
.cb_capture_first_window
.isChecked():
107 flags |
= FLAG_CAPTURE_FIRST_WINDOW
108 if self
.ui
.cb_buffers_addition_mode
.isChecked():
109 flags |
= FLAG_BUFFERS_ADDITION_MODE
110 if self
.ui
.cb_out_midi_mixdown
.isChecked():
111 flags |
= FLAG_MIDI_OUTPUT_CHANNEL_MIXDOWN
112 if self
.ui
.cb_external_start
.isChecked():
113 flags |
= FLAG_EXTERNAL_START
116 v1
= chr(bv
+ self
.ui
.sb_audio_ins
.value())
117 v2
= chr(bv
+ self
.ui
.sb_audio_outs
.value())
118 v3
= chr(bv
+ self
.ui
.sb_midi_ins
.value())
119 v4
= chr(bv
+ self
.ui
.sb_midi_outs
.value())
122 labelSetup
= f
"{v1}{v2}{v3}{v4}{v5}{v6}"
124 return (command
, name
, labelSetup
)
126 # -----------------------------------------------------------------------------------------------------------------
129 def _checkIfButtonBoxShouldBeEnabled(self
, index
: int, command
: str):
130 enabled
= len(command
) > 0
133 # NSM applications must not be abstract or absolute paths, and must not contain arguments
134 if enabled
and index
== UI_SESSION_NSM
:
135 if command
[0] in (".", "/"):
136 showErr
= self
.tr("NSM applications cannot use abstract or absolute paths")
137 elif " " in command
or ";" in command
or "&" in command
:
138 showErr
= self
.tr("NSM applications cannot use CLI arguments")
139 elif not self
.fProjectFilename
:
140 showErr
= self
.tr("You need to save the current Carla project before NSM can be used")
144 self
.ui
.l_error
.setText(showErr
)
145 self
.ui
.group_error
.setVisible(True)
147 self
.ui
.group_error
.setVisible(False)
149 self
.ui
.buttonBox
.button(QDialogButtonBox
.Ok
).setEnabled(enabled
)
151 def _loadSettings(self
):
152 settings
= QSafeSettings("falkTX", "CarlaAddJackApp")
154 smName
= settings
.value("SessionManager", "", str)
156 if smName
== "LADISH (SIGUSR1)":
157 self
.ui
.cb_session_mgr
.setCurrentIndex(UI_SESSION_LADISH
)
158 elif smName
== "NSM":
159 self
.ui
.cb_session_mgr
.setCurrentIndex(UI_SESSION_NSM
)
161 self
.ui
.cb_session_mgr
.setCurrentIndex(UI_SESSION_NONE
)
163 self
.ui
.le_command
.setText(settings
.value("Command", "", str))
164 self
.ui
.le_name
.setText(settings
.value("Name", "", str))
165 self
.ui
.sb_audio_ins
.setValue(settings
.value("NumAudioIns", 2, int))
166 self
.ui
.sb_audio_ins
.setValue(settings
.value("NumAudioIns", 2, int))
167 self
.ui
.sb_audio_outs
.setValue(settings
.value("NumAudioOuts", 2, int))
168 self
.ui
.sb_midi_ins
.setValue(settings
.value("NumMidiIns", 0, int))
169 self
.ui
.sb_midi_outs
.setValue(settings
.value("NumMidiOuts", 0, int))
170 self
.ui
.cb_manage_window
.setChecked(settings
.value("ManageWindow", True, bool))
171 self
.ui
.cb_capture_first_window
.setChecked(settings
.value("CaptureFirstWindow", False, bool))
172 self
.ui
.cb_out_midi_mixdown
.setChecked(settings
.value("MidiOutMixdown", False, bool))
174 self
._checkIfButtonBoxShouldBeEnabled
(self
.ui
.cb_session_mgr
.currentIndex(),
175 self
.ui
.le_command
.text())
177 # -----------------------------------------------------------------------------------------------------------------
181 def _slot_commandChanged(self
, command
: str):
182 self
._checkIfButtonBoxShouldBeEnabled
(self
.ui
.cb_session_mgr
.currentIndex(), command
)
185 def _slot_sessionManagerChanged(self
, index
: int):
186 self
._checkIfButtonBoxShouldBeEnabled
(index
, self
.ui
.le_command
.text())
189 def _slot_saveSettings(self
):
190 settings
= QSafeSettings("falkTX", "CarlaAddJackApp")
191 settings
.setValue("Command", self
.ui
.le_command
.text())
192 settings
.setValue("Name", self
.ui
.le_name
.text())
193 settings
.setValue("SessionManager", self
.ui
.cb_session_mgr
.currentText())
194 settings
.setValue("NumAudioIns", self
.ui
.sb_audio_ins
.value())
195 settings
.setValue("NumAudioOuts", self
.ui
.sb_audio_outs
.value())
196 settings
.setValue("NumMidiIns", self
.ui
.sb_midi_ins
.value())
197 settings
.setValue("NumMidiOuts", self
.ui
.sb_midi_outs
.value())
198 settings
.setValue("ManageWindow", self
.ui
.cb_manage_window
.isChecked())
199 settings
.setValue("CaptureFirstWindow", self
.ui
.cb_capture_first_window
.isChecked())
200 settings
.setValue("MidiOutMixdown", self
.ui
.cb_out_midi_mixdown
.isChecked())
202 # ---------------------------------------------------------------------------------------------------------------------
205 if __name__
== '__main__':
207 # pylint: disable=ungrouped-imports
208 from PyQt5
.QtWidgets
import QApplication
209 # pylint: enable=ungrouped-imports
211 _app
= QApplication(sys
.argv
)
212 _gui
= JackAppDialog(None, "")
215 _command
, _name
, _labelSetup
= _gui
.getCommandAndFlags()
217 print(f
"\tCommand: {_command}")
218 print(f
"\tName: {_name}")
219 print(f
"\tLabelSetup: {_labelSetup}")
221 # ---------------------------------------------------------------------------------------------------------------------