Collection of tools useful for audio production
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2389 lines
92KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Cadence, JACK utilities
  4. # Copyright (C) 2010-2018 Filipe Coelho <falktx@falktx.com>
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # For a full copy of the GNU General Public License see the COPYING file
  17. # ------------------------------------------------------------------------------------------------------------
  18. # Imports (Global)
  19. from platform import architecture
  20. if True:
  21. from PyQt5.QtCore import QFileSystemWatcher, QThread, QSemaphore
  22. from PyQt5.QtWidgets import QApplication, QDialogButtonBox, QLabel, QMainWindow, QSizePolicy
  23. else:
  24. from PyQt4.QtCore import QFileSystemWatcher, QThread, QSemaphore
  25. from PyQt4.QtGui import QApplication, QDialogButtonBox, QLabel, QMainWindow, QSizePolicy
  26. # ------------------------------------------------------------------------------------------------------------
  27. # Imports (Custom Stuff)
  28. import systray
  29. import ui_cadence
  30. import ui_cadence_tb_jack
  31. import ui_cadence_tb_alsa
  32. import ui_cadence_tb_a2j
  33. import ui_cadence_tb_pa
  34. import ui_cadence_rwait
  35. from shared import getDaemonLockfile
  36. from shared_cadence import *
  37. from shared_canvasjack import *
  38. from shared_settings import *
  39. # ------------------------------------------------------------------------------------------------------------
  40. # Import getoutput
  41. from subprocess import getoutput
  42. import tempfile
  43. import subprocess
  44. # ------------------------------------------------------------------------------------------------------------
  45. # Try Import DBus
  46. try:
  47. import dbus
  48. from dbus.mainloop.pyqt5 import DBusQtMainLoop as DBusMainLoop
  49. haveDBus = True
  50. except:
  51. try:
  52. # Try falling back to GMainLoop
  53. from dbus.mainloop.glib import DBusGMainLoop as DBusMainLoop
  54. haveDBus = True
  55. except:
  56. haveDBus = False
  57. # ------------------------------------------------------------------------------------------------------------
  58. # Check for PulseAudio and Wine
  59. havePulseAudio = os.path.exists("/usr/bin/pulseaudio")
  60. haveWine = os.path.exists("/usr/bin/regedit")
  61. if haveWine:
  62. WINEPREFIX = os.getenv("WINEPREFIX")
  63. if not WINEPREFIX:
  64. WINEPREFIX = os.path.join(HOME, ".wine")
  65. # ---------------------------------------------------------------------
  66. DESKTOP_X_IMAGE = [
  67. "eog.desktop",
  68. "kde4/digikam.desktop",
  69. "kde4/gwenview.desktop",
  70. "org.kde.digikam.desktop",
  71. "org.kde.gwenview.desktop",
  72. ]
  73. DESKTOP_X_MUSIC = [
  74. "audacious.desktop",
  75. "clementine.desktop",
  76. "smplayer.desktop",
  77. "vlc.desktop",
  78. "kde4/amarok.desktop",
  79. "org.kde.amarok.desktop",
  80. ]
  81. DESKTOP_X_VIDEO = [
  82. "smplayer.desktop",
  83. "vlc.desktop",
  84. ]
  85. DESKTOP_X_TEXT = [
  86. "gedit.desktop",
  87. "kde4/kate.desktop",
  88. "kde4/kwrite.desktop",
  89. "org.kde.kate.desktop",
  90. "org.kde.kwrite.desktop",
  91. ]
  92. DESKTOP_X_BROWSER = [
  93. "chrome.desktop",
  94. "firefox.desktop",
  95. "iceweasel.desktop",
  96. "kde4/konqbrowser.desktop",
  97. "org.kde.konqbrowser.desktop",
  98. ]
  99. XDG_APPLICATIONS_PATH = [
  100. "/usr/share/applications",
  101. "/usr/local/share/applications"
  102. ]
  103. # ---------------------------------------------------------------------
  104. global jackClientIdALSA, jackClientIdPulse
  105. jackClientIdALSA = -1
  106. jackClientIdPulse = -1
  107. # jackdbus indexes
  108. iGraphVersion = 0
  109. iJackClientId = 1
  110. iJackClientName = 2
  111. iJackPortId = 3
  112. iJackPortName = 4
  113. iJackPortNewName = 5
  114. iJackPortFlags = 5
  115. iJackPortType = 6
  116. asoundrc_aloop = (""
  117. "# ------------------------------------------------------\n"
  118. "# Custom asoundrc file for use with snd-aloop and JACK\n"
  119. "#\n"
  120. "# use it like this:\n"
  121. "# env JACK_SAMPLE_RATE=44100 JACK_PERIOD_SIZE=1024 alsa_in (...)\n"
  122. "#\n"
  123. "\n"
  124. "# ------------------------------------------------------\n"
  125. "# playback device\n"
  126. "pcm.aloopPlayback {\n"
  127. " type dmix\n"
  128. " ipc_key 1\n"
  129. " ipc_key_add_uid true\n"
  130. " slave {\n"
  131. " pcm \"hw:Loopback,0,0\"\n"
  132. " format S32_LE\n"
  133. " rate {\n"
  134. " @func igetenv\n"
  135. " vars [ JACK_SAMPLE_RATE ]\n"
  136. " default 44100\n"
  137. " }\n"
  138. " period_size {\n"
  139. " @func igetenv\n"
  140. " vars [ JACK_PERIOD_SIZE ]\n"
  141. " default 1024\n"
  142. " }\n"
  143. " buffer_size 4096\n"
  144. " }\n"
  145. "}\n"
  146. "\n"
  147. "# capture device\n"
  148. "pcm.aloopCapture {\n"
  149. " type dsnoop\n"
  150. " ipc_key 2\n"
  151. " ipc_key_add_uid true\n"
  152. " slave {\n"
  153. " pcm \"hw:Loopback,0,1\"\n"
  154. " format S32_LE\n"
  155. " rate {\n"
  156. " @func igetenv\n"
  157. " vars [ JACK_SAMPLE_RATE ]\n"
  158. " default 44100\n"
  159. " }\n"
  160. " period_size {\n"
  161. " @func igetenv\n"
  162. " vars [ JACK_PERIOD_SIZE ]\n"
  163. " default 1024\n"
  164. " }\n"
  165. " buffer_size 4096\n"
  166. " }\n"
  167. "}\n"
  168. "\n"
  169. "# duplex device\n"
  170. "pcm.aloopDuplex {\n"
  171. " type asym\n"
  172. " playback.pcm \"aloopPlayback\"\n"
  173. " capture.pcm \"aloopCapture\"\n"
  174. "}\n"
  175. "\n"
  176. "# ------------------------------------------------------\n"
  177. "# default device\n"
  178. "pcm.!default {\n"
  179. " type plug\n"
  180. " slave.pcm \"aloopDuplex\"\n"
  181. "}\n"
  182. "\n"
  183. "# ------------------------------------------------------\n"
  184. "# alsa_in -j alsa_in -dcloop -q 1\n"
  185. "pcm.cloop {\n"
  186. " type dsnoop\n"
  187. " ipc_key 3\n"
  188. " ipc_key_add_uid true\n"
  189. " slave {\n"
  190. " pcm \"hw:Loopback,1,0\"\n"
  191. " channels 2\n"
  192. " format S32_LE\n"
  193. " rate {\n"
  194. " @func igetenv\n"
  195. " vars [ JACK_SAMPLE_RATE ]\n"
  196. " default 44100\n"
  197. " }\n"
  198. " period_size {\n"
  199. " @func igetenv\n"
  200. " vars [ JACK_PERIOD_SIZE ]\n"
  201. " default 1024\n"
  202. " }\n"
  203. " buffer_size 32768\n"
  204. " }\n"
  205. "}\n"
  206. "\n"
  207. "# ------------------------------------------------------\n"
  208. "# alsa_out -j alsa_out -dploop -q 1\n"
  209. "pcm.ploop {\n"
  210. " type plug\n"
  211. " slave.pcm \"hw:Loopback,1,1\"\n"
  212. "}")
  213. asoundrc_aloop_check = asoundrc_aloop.split("pcm.aloopPlayback", 1)[0]
  214. asoundrc_jack = (""
  215. "pcm.!default {\n"
  216. " type plug\n"
  217. " slave { pcm \"jack\" }\n"
  218. "}\n"
  219. "\n"
  220. "pcm.jack {\n"
  221. " type jack\n"
  222. " playback_ports {\n"
  223. " 0 system:playback_1\n"
  224. " 1 system:playback_2\n"
  225. " }\n"
  226. " capture_ports {\n"
  227. " 0 system:capture_1\n"
  228. " 1 system:capture_2\n"
  229. " }\n"
  230. "}\n"
  231. "\n"
  232. "ctl.mixer0 {\n"
  233. " type hw\n"
  234. " card 0\n"
  235. "}")
  236. asoundrc_pulse = (""
  237. "pcm.!default {\n"
  238. " type plug\n"
  239. " slave { pcm \"pulse\" }\n"
  240. "}\n"
  241. "\n"
  242. "pcm.pulse {\n"
  243. " type pulse\n"
  244. "}\n"
  245. "\n"
  246. "ctl.mixer0 {\n"
  247. " type hw\n"
  248. " card 0\n"
  249. "}")
  250. # ---------------------------------------------------------------------
  251. def get_architecture():
  252. return architecture()[0]
  253. def get_haiku_information():
  254. # TODO
  255. return ("Haiku OS", "Unknown")
  256. def get_linux_information():
  257. if os.path.exists("/etc/lsb-release"):
  258. distro = getoutput(". /etc/lsb-release && echo $DISTRIB_DESCRIPTION")
  259. elif os.path.exists("/etc/arch-release"):
  260. distro = "ArchLinux"
  261. else:
  262. distro = os.uname()[0]
  263. kernel = os.uname()[2]
  264. return (distro, kernel)
  265. def get_mac_information():
  266. # TODO
  267. return ("Mac OS", "Unknown")
  268. def get_windows_information():
  269. major = sys.getwindowsversion()[0]
  270. minor = sys.getwindowsversion()[1]
  271. servp = sys.getwindowsversion()[4]
  272. os = "Windows"
  273. version = servp
  274. if major == 4 and minor == 0:
  275. os = "Windows 95"
  276. version = "RTM"
  277. elif major == 4 and minor == 10:
  278. os = "Windows 98"
  279. version = "Second Edition"
  280. elif major == 5 and minor == 0:
  281. os = "Windows 2000"
  282. elif major == 5 and minor == 1:
  283. os = "Windows XP"
  284. elif major == 5 and minor == 2:
  285. os = "Windows Server 2003"
  286. elif major == 6 and minor == 0:
  287. os = "Windows Vista"
  288. elif major == 6 and minor == 1:
  289. os = "Windows 7"
  290. elif major == 6 and minor == 2:
  291. os = "Windows 8"
  292. return (os, version)
  293. # ---------------------------------------------------------------------
  294. def isAlsaAudioBridged():
  295. global jackClientIdALSA
  296. return bool(jackClientIdALSA != -1)
  297. def isPulseAudioStarted():
  298. return bool("pulseaudio" in getProcList())
  299. def isPulseAudioBridged():
  300. global jackClientIdPulse
  301. return bool(jackClientIdPulse != -1)
  302. def isDesktopFileInstalled(desktop):
  303. for X_PATH in XDG_APPLICATIONS_PATH:
  304. if os.path.exists(os.path.join(X_PATH, desktop)):
  305. return True
  306. return False
  307. def getDesktopFileContents(desktop):
  308. for X_PATH in XDG_APPLICATIONS_PATH:
  309. if os.path.exists(os.path.join(X_PATH, desktop)):
  310. fd = open(os.path.join(X_PATH, desktop), "r")
  311. contents = fd.read()
  312. fd.close()
  313. return contents
  314. return None
  315. def getXdgProperty(fileRead, key):
  316. fileReadSplit = fileRead.split(key, 1)
  317. if len(fileReadSplit) > 1:
  318. fileReadLine = fileReadSplit[1].split("\n",1)[0]
  319. fileReadLineStripped = fileReadLine.rsplit(";",1)[0].strip()
  320. value = fileReadLineStripped.replace("=","",1)
  321. return value
  322. return None
  323. def getWineAsioKeyValue(key, default):
  324. wineFile = os.path.join(WINEPREFIX, "user.reg")
  325. if not os.path.exists(wineFile):
  326. return default
  327. wineDumpF = open(wineFile, "r")
  328. wineDump = wineDumpF.read()
  329. wineDumpF.close()
  330. wineDumpSplit = wineDump.split("[Software\\\\Wine\\\\WineASIO]")
  331. if len(wineDumpSplit) <= 1:
  332. return default
  333. wineDumpSmall = wineDumpSplit[1].split("[")[0]
  334. keyDumpSplit = wineDumpSmall.split('"%s"' % key)
  335. if len(keyDumpSplit) <= 1:
  336. return default
  337. keyDumpSmall = keyDumpSplit[1].split(":")[1].split("\n")[0]
  338. return keyDumpSmall
  339. def searchAndSetComboBoxValue(comboBox, value):
  340. for i in range(comboBox.count()):
  341. if comboBox.itemText(i).replace("/","-") == value:
  342. comboBox.setCurrentIndex(i)
  343. comboBox.setEnabled(True)
  344. return True
  345. return False
  346. def smartHex(value, length):
  347. hexStr = hex(value).replace("0x","")
  348. if len(hexStr) < length:
  349. zeroCount = length - len(hexStr)
  350. hexStr = "%s%s" % ("0"*zeroCount, hexStr)
  351. return hexStr
  352. # ---------------------------------------------------------------------
  353. cadenceSystemChecks = []
  354. class CadenceSystemCheck(object):
  355. ICON_ERROR = 0
  356. ICON_WARN = 1
  357. ICON_OK = 2
  358. def __init__(self):
  359. object.__init__(self)
  360. self.name = self.tr("check")
  361. self.icon = self.ICON_OK
  362. self.result = self.tr("yes")
  363. self.moreInfo = self.tr("nothing to report")
  364. def tr(self, text):
  365. return app.translate("CadenceSystemCheck", text)
  366. class CadenceSystemCheck_audioGroup(CadenceSystemCheck):
  367. def __init__(self):
  368. CadenceSystemCheck.__init__(self)
  369. self.name = self.tr("User in audio group")
  370. user = getoutput("whoami").strip()
  371. groups = getoutput("groups").strip().split(" ")
  372. if "audio" in groups:
  373. self.icon = self.ICON_OK
  374. self.result = self.tr("Yes")
  375. self.moreInfo = None
  376. else:
  377. fd = open("/etc/group", "r")
  378. groupRead = fd.read().strip().split("\n")
  379. fd.close()
  380. onAudioGroup = False
  381. for lineRead in groupRead:
  382. if lineRead.startswith("audio:"):
  383. groups = lineRead.split(":")[-1].split(",")
  384. if user in groups:
  385. onAudioGroup = True
  386. break
  387. if onAudioGroup:
  388. self.icon = self.ICON_WARN
  389. self.result = self.tr("Yes, but needs relogin")
  390. self.moreInfo = None
  391. else:
  392. self.icon = self.ICON_ERROR
  393. self.result = self.tr("No")
  394. self.moreInfo = None
  395. class CadenceSystemCheck_kernel(CadenceSystemCheck):
  396. def __init__(self):
  397. CadenceSystemCheck.__init__(self)
  398. self.name = self.tr("Current kernel")
  399. uname3 = os.uname()[2]
  400. versionInt = []
  401. versionStr = uname3.split("-",1)[0]
  402. versionSplit = versionStr.split(".")
  403. for split in versionSplit:
  404. if split.isdigit():
  405. versionInt.append(int(split))
  406. else:
  407. versionInt = [0, 0, 0]
  408. break
  409. self.result = versionStr + " "
  410. if "-" not in uname3:
  411. self.icon = self.ICON_WARN
  412. self.result += self.tr("Vanilla")
  413. self.moreInfo = None
  414. else:
  415. if uname3.endswith("-pae"):
  416. kernelType = uname3.split("-")[-2].lower()
  417. self.result += kernelType.title() + " (PAE)"
  418. else:
  419. kernelType = uname3.split("-")[-1].lower()
  420. self.result += kernelType.title()
  421. if kernelType in ("rt", "realtime") or (kernelType == "lowlatency" and versionInt >= [2, 6, 39]):
  422. self.icon = self.ICON_OK
  423. self.moreInfo = None
  424. elif versionInt >= [2, 6, 39]:
  425. self.icon = self.ICON_WARN
  426. self.moreInfo = None
  427. else:
  428. self.icon = self.ICON_ERROR
  429. self.moreInfo = None
  430. def initSystemChecks():
  431. if LINUX:
  432. cadenceSystemChecks.append(CadenceSystemCheck_kernel())
  433. cadenceSystemChecks.append(CadenceSystemCheck_audioGroup())
  434. # ---------------------------------------------------------------------
  435. # Wait while JACK restarts
  436. class ForceRestartThread(QThread):
  437. progressChanged = pyqtSignal(int)
  438. def __init__(self, parent):
  439. QThread.__init__(self, parent)
  440. self.m_wasStarted = False
  441. def wasJackStarted(self):
  442. return self.m_wasStarted
  443. def startA2J(self):
  444. if not gDBus.a2j.get_hw_export() and GlobalSettings.value("A2J/AutoExport", True, type=bool):
  445. gDBus.a2j.set_hw_export(True)
  446. gDBus.a2j.start()
  447. def run(self):
  448. # Not started yet
  449. self.m_wasStarted = False
  450. self.progressChanged.emit(0)
  451. # Stop JACK safely first, if possible
  452. runFunctionInMainThread(tryCloseJackDBus)
  453. self.progressChanged.emit(20)
  454. # Kill All
  455. stopAllAudioProcesses(False)
  456. self.progressChanged.emit(30)
  457. # Connect to jackdbus
  458. runFunctionInMainThread(self.parent().DBusReconnect)
  459. if not gDBus.jack:
  460. return
  461. for x in range(30):
  462. self.progressChanged.emit(30+x*2)
  463. procsList = getProcList()
  464. if "jackdbus" in procsList:
  465. break
  466. else:
  467. sleep(0.1)
  468. self.progressChanged.emit(90)
  469. # Start it
  470. runFunctionInMainThread(gDBus.jack.StartServer)
  471. self.progressChanged.emit(93)
  472. # If we made it this far, then JACK is started
  473. self.m_wasStarted = True
  474. # Start bridges according to user settings
  475. # ALSA-Audio
  476. if GlobalSettings.value("ALSA-Audio/BridgeIndexType", iAlsaFileNone, type=int) == iAlsaFileLoop:
  477. startAlsaAudioLoopBridge()
  478. sleep(0.5)
  479. self.progressChanged.emit(94)
  480. # ALSA-MIDI
  481. if GlobalSettings.value("A2J/AutoStart", True, type=bool) and not bool(gDBus.a2j.is_started()):
  482. runFunctionInMainThread(self.startA2J)
  483. self.progressChanged.emit(96)
  484. # PulseAudio
  485. if GlobalSettings.value("Pulse2JACK/AutoStart", True, type=bool) and not isPulseAudioBridged():
  486. if GlobalSettings.value("Pulse2JACK/PlaybackModeOnly", False, type=bool):
  487. os.system("cadence-pulse2jack -p")
  488. else:
  489. os.system("cadence-pulse2jack")
  490. self.progressChanged.emit(100)
  491. # Force Restart Dialog
  492. class ForceWaitDialog(QDialog, ui_cadence_rwait.Ui_Dialog):
  493. def __init__(self, parent):
  494. QDialog.__init__(self, parent)
  495. self.setupUi(self)
  496. self.setWindowFlags(Qt.Dialog|Qt.WindowCloseButtonHint)
  497. self.rThread = ForceRestartThread(self)
  498. self.rThread.start()
  499. self.rThread.progressChanged.connect(self.progressBar.setValue)
  500. self.rThread.finished.connect(self.slot_rThreadFinished)
  501. def DBusReconnect(self):
  502. self.parent().DBusReconnect()
  503. @pyqtSlot()
  504. def slot_rThreadFinished(self):
  505. self.close()
  506. if self.rThread.wasJackStarted():
  507. QMessageBox.information(self, self.tr("Info"), self.tr("JACK was re-started sucessfully"))
  508. else:
  509. QMessageBox.critical(self, self.tr("Error"), self.tr("Could not start JACK!"))
  510. def done(self, r):
  511. QDialog.done(self, r)
  512. self.close()
  513. # Additional JACK options
  514. class ToolBarJackDialog(QDialog, ui_cadence_tb_jack.Ui_Dialog):
  515. def __init__(self, parent):
  516. QDialog.__init__(self, parent)
  517. self.setupUi(self)
  518. self.m_ladishLoaded = False
  519. if haveDBus:
  520. if GlobalSettings.value("JACK/AutoLoadLadishStudio", False, type=bool):
  521. self.rb_ladish.setChecked(True)
  522. self.m_ladishLoaded = True
  523. elif "org.ladish" in gDBus.bus.list_names():
  524. self.m_ladishLoaded = True
  525. else:
  526. self.rb_ladish.setEnabled(False)
  527. self.rb_jack.setChecked(True)
  528. if self.m_ladishLoaded:
  529. self.fillStudioNames()
  530. self.accepted.connect(self.slot_setOptions)
  531. self.rb_ladish.clicked.connect(self.slot_maybeFillStudioNames)
  532. def fillStudioNames(self):
  533. gDBus.ladish_control = gDBus.bus.get_object("org.ladish", "/org/ladish/Control")
  534. ladishStudioName = dbus.String(GlobalSettings.value("JACK/LadishStudioName", "", type=str))
  535. ladishStudioListDump = gDBus.ladish_control.GetStudioList()
  536. if len(ladishStudioListDump) == 0:
  537. self.rb_ladish.setEnabled(False)
  538. self.rb_jack.setChecked(True)
  539. else:
  540. i=0
  541. for thisStudioName, thisStudioDict in ladishStudioListDump:
  542. self.cb_studio_name.addItem(thisStudioName)
  543. if ladishStudioName and thisStudioName == ladishStudioName:
  544. self.cb_studio_name.setCurrentIndex(i)
  545. i += 1
  546. @pyqtSlot()
  547. def slot_maybeFillStudioNames(self):
  548. if not self.m_ladishLoaded:
  549. self.fillStudioNames()
  550. self.m_ladishLoaded = True
  551. @pyqtSlot()
  552. def slot_setOptions(self):
  553. GlobalSettings.setValue("JACK/AutoLoadLadishStudio", self.rb_ladish.isChecked())
  554. GlobalSettings.setValue("JACK/LadishStudioName", self.cb_studio_name.currentText())
  555. def done(self, r):
  556. QDialog.done(self, r)
  557. self.close()
  558. # Additional ALSA Audio options
  559. class ToolBarAlsaAudioDialog(QDialog, ui_cadence_tb_alsa.Ui_Dialog):
  560. def __init__(self, parent, customMode):
  561. QDialog.__init__(self, parent)
  562. self.setupUi(self)
  563. self.asoundrcFile = os.path.join(HOME, ".asoundrc")
  564. self.fCustomMode = customMode
  565. if customMode:
  566. asoundrcFd = open(self.asoundrcFile, "r")
  567. asoundrcRead = asoundrcFd.read().strip()
  568. asoundrcFd.close()
  569. self.textBrowser.setPlainText(asoundrcRead)
  570. self.stackedWidget.setCurrentIndex(0)
  571. self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel)
  572. else:
  573. self.textBrowser.hide()
  574. self.stackedWidget.setCurrentIndex(1)
  575. self.adjustSize()
  576. self.spinBox.setValue(GlobalSettings.value("ALSA-Audio/BridgeChannels", 2, type=int))
  577. if GlobalSettings.value("ALSA-Audio/BridgeTool", "alsa_in", type=str) == "zita":
  578. self.comboBox.setCurrentIndex(1)
  579. else:
  580. self.comboBox.setCurrentIndex(0)
  581. self.accepted.connect(self.slot_setOptions)
  582. @pyqtSlot()
  583. def slot_setOptions(self):
  584. channels = self.spinBox.value()
  585. GlobalSettings.setValue("ALSA-Audio/BridgeChannels", channels)
  586. GlobalSettings.setValue("ALSA-Audio/BridgeTool", "zita" if (self.comboBox.currentIndex() == 1) else "alsa_in")
  587. asoundrcFd = open(self.asoundrcFile, "w")
  588. asoundrcFd.write(asoundrc_aloop.replace("channels 2\n", "channels %i\n" % channels) + "\n")
  589. asoundrcFd.close()
  590. def done(self, r):
  591. QDialog.done(self, r)
  592. self.close()
  593. # Additional PulseAudio options
  594. class ToolBarPADialog(QDialog, ui_cadence_tb_pa.Ui_Dialog):
  595. def __init__(self, parent):
  596. QDialog.__init__(self, parent)
  597. self.setupUi(self)
  598. self.cb_playback_only.setChecked(GlobalSettings.value("Pulse2JACK/PlaybackModeOnly", False, type=bool))
  599. self.accepted.connect(self.slot_setOptions)
  600. @pyqtSlot()
  601. def slot_setOptions(self):
  602. GlobalSettings.setValue("Pulse2JACK/PlaybackModeOnly", self.cb_playback_only.isChecked())
  603. def done(self, r):
  604. QDialog.done(self, r)
  605. self.close()
  606. # Main Window
  607. class CadenceMainW(QMainWindow, ui_cadence.Ui_CadenceMainW):
  608. DBusJackServerStartedCallback = pyqtSignal()
  609. DBusJackServerStoppedCallback = pyqtSignal()
  610. DBusJackClientAppearedCallback = pyqtSignal(int, str)
  611. DBusJackClientDisappearedCallback = pyqtSignal(int)
  612. DBusA2JBridgeStartedCallback = pyqtSignal()
  613. DBusA2JBridgeStoppedCallback = pyqtSignal()
  614. SIGTERM = pyqtSignal()
  615. SIGUSR1 = pyqtSignal()
  616. SIGUSR2 = pyqtSignal()
  617. def __init__(self, parent=None):
  618. QMainWindow.__init__(self, parent)
  619. self.setupUi(self)
  620. self.settings = QSettings("Cadence", "Cadence")
  621. self.loadSettings(True)
  622. self.pix_apply = QIcon(getIcon("dialog-ok-apply", 16)).pixmap(16, 16)
  623. self.pix_cancel = QIcon(getIcon("dialog-cancel", 16)).pixmap(16, 16)
  624. self.pix_error = QIcon(getIcon("dialog-error", 16)).pixmap(16, 16)
  625. self.pix_warning = QIcon(getIcon("dialog-warning", 16)).pixmap(16, 16)
  626. self.m_lastAlsaIndexType = -2 # invalid
  627. if jacklib and not jacklib.JACK2:
  628. self.b_jack_switchmaster.setEnabled(False)
  629. # -------------------------------------------------------------
  630. # Set-up GUI (System Information)
  631. if HAIKU:
  632. info = get_haiku_information()
  633. elif LINUX:
  634. info = get_linux_information()
  635. elif MACOS:
  636. info = get_mac_information()
  637. elif WINDOWS:
  638. info = get_windows_information()
  639. else:
  640. info = ("Unknown", "Unknown")
  641. self.label_info_os.setText(info[0])
  642. self.label_info_version.setText(info[1])
  643. self.label_info_arch.setText(get_architecture())
  644. # -------------------------------------------------------------
  645. # Set-up GUI (System Status)
  646. self.m_availGovPath = "/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors"
  647. self.m_curGovPath = "/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"
  648. self.m_curGovPaths = []
  649. self.m_curGovCPUs = []
  650. try:
  651. fBus = dbus.SystemBus(mainloop=gDBus.loop)
  652. fProxy = fBus.get_object("com.ubuntu.IndicatorCpufreqSelector", "/Selector", introspect=False)
  653. haveFreqSelector = True
  654. except:
  655. haveFreqSelector = False
  656. if haveFreqSelector and os.path.exists(self.m_availGovPath) and os.path.exists(self.m_curGovPath):
  657. self.m_govWatcher = QFileSystemWatcher(self)
  658. self.m_govWatcher.addPath(self.m_curGovPath)
  659. self.m_govWatcher.fileChanged.connect(self.slot_governorFileChanged)
  660. QTimer.singleShot(0, self.slot_governorFileChanged)
  661. availGovFd = open(self.m_availGovPath, "r")
  662. availGovRead = availGovFd.read().strip()
  663. availGovFd.close()
  664. self.m_availGovList = availGovRead.split(" ")
  665. for availGov in self.m_availGovList:
  666. self.cb_cpufreq.addItem(availGov)
  667. for root, dirs, files in os.walk("/sys/devices/system/cpu/"):
  668. for dir_ in [dir_ for dir_ in dirs if dir_.startswith("cpu")]:
  669. if not dir_.replace("cpu", "", 1).isdigit():
  670. continue
  671. cpuGovPath = os.path.join(root, dir_, "cpufreq", "scaling_governor")
  672. if os.path.exists(cpuGovPath):
  673. self.m_curGovPaths.append(cpuGovPath)
  674. self.m_curGovCPUs.append(int(dir_.replace("cpu", "", 1)))
  675. self.cb_cpufreq.setCurrentIndex(-1)
  676. else:
  677. self.m_govWatcher = None
  678. self.cb_cpufreq.setEnabled(False)
  679. self.label_cpufreq.setEnabled(False)
  680. # -------------------------------------------------------------
  681. # Set-up GUI (System Checks)
  682. #self.label_check_helper1.setVisible(False)
  683. #self.label_check_helper2.setVisible(False)
  684. #self.label_check_helper3.setVisible(False)
  685. index = 2
  686. checksLayout = self.groupBox_checks.layout()
  687. for check in cadenceSystemChecks:
  688. widgetName = QLabel("%s:" % check.name)
  689. widgetIcon = QLabel("")
  690. widgetResult = QLabel(check.result)
  691. if check.moreInfo:
  692. widgetName.setToolTip(check.moreInfo)
  693. widgetIcon.setToolTip(check.moreInfo)
  694. widgetResult.setToolTip(check.moreInfo)
  695. #widgetName.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
  696. #widgetIcon.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
  697. #widgetIcon.setMinimumSize(16, 16)
  698. #widgetIcon.setMaximumSize(16, 16)
  699. #widgetResult.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
  700. if check.icon == check.ICON_ERROR:
  701. widgetIcon.setPixmap(self.pix_error)
  702. elif check.icon == check.ICON_WARN:
  703. widgetIcon.setPixmap(self.pix_warning)
  704. elif check.icon == check.ICON_OK:
  705. widgetIcon.setPixmap(self.pix_apply)
  706. else:
  707. widgetIcon.setPixmap(self.pix_cancel)
  708. checksLayout.addWidget(widgetName, index, 0, Qt.AlignRight)
  709. checksLayout.addWidget(widgetIcon, index, 1, Qt.AlignHCenter)
  710. checksLayout.addWidget(widgetResult, index, 2, Qt.AlignLeft)
  711. index += 1
  712. # -------------------------------------------------------------
  713. # Set-up GUI (JACK Bridges)
  714. if not havePulseAudio:
  715. self.toolBox_pulseaudio.setEnabled(False)
  716. self.label_bridge_pulse.setText(self.tr("PulseAudio is not installed"))
  717. # Not available in cxfreeze builds
  718. if sys.argv[0].endswith("/cadence"):
  719. self.groupBox_bridges.setEnabled(False)
  720. self.cb_jack_autostart.setEnabled(False)
  721. self.tb_jack_options.setEnabled(False)
  722. # -------------------------------------------------------------
  723. # Set-up GUI (Tweaks)
  724. self.settings_changed_types = []
  725. self.frame_tweaks_settings.setVisible(False)
  726. for i in range(self.tw_tweaks.rowCount()):
  727. self.tw_tweaks.item(i, 0).setTextAlignment(Qt.AlignCenter)
  728. self.tw_tweaks.setCurrentCell(0, 0)
  729. # -------------------------------------------------------------
  730. # Set-up GUI (Tweaks, Audio Plugins PATH)
  731. self.b_tweak_plugins_change.setEnabled(False)
  732. self.b_tweak_plugins_remove.setEnabled(False)
  733. for iPath in DEFAULT_LADSPA_PATH:
  734. self.list_LADSPA.addItem(iPath)
  735. for iPath in DEFAULT_DSSI_PATH:
  736. self.list_DSSI.addItem(iPath)
  737. for iPath in DEFAULT_LV2_PATH:
  738. self.list_LV2.addItem(iPath)
  739. for iPath in DEFAULT_VST_PATH:
  740. self.list_VST.addItem(iPath)
  741. EXTRA_LADSPA_DIRS = GlobalSettings.value("AudioPlugins/EXTRA_LADSPA_PATH", "", type=str)
  742. EXTRA_DSSI_DIRS = GlobalSettings.value("AudioPlugins/EXTRA_DSSI_PATH", "", type=str)
  743. EXTRA_LV2_DIRS = GlobalSettings.value("AudioPlugins/EXTRA_LV2_PATH", "", type=str)
  744. EXTRA_VST_DIRS = GlobalSettings.value("AudioPlugins/EXTRA_VST_PATH", "", type=str)
  745. for iPath in EXTRA_LADSPA_DIRS.split(":"):
  746. if os.path.exists(iPath):
  747. self.list_LADSPA.addItem(iPath)
  748. for iPath in EXTRA_DSSI_DIRS.split(":"):
  749. if os.path.exists(iPath):
  750. self.list_DSSI.addItem(iPath)
  751. for iPath in EXTRA_LV2_DIRS.split(":"):
  752. if os.path.exists(iPath):
  753. self.list_LV2.addItem(iPath)
  754. for iPath in EXTRA_VST_DIRS.split(":"):
  755. if os.path.exists(iPath):
  756. self.list_VST.addItem(iPath)
  757. self.list_LADSPA.sortItems(Qt.AscendingOrder)
  758. self.list_DSSI.sortItems(Qt.AscendingOrder)
  759. self.list_LV2.sortItems(Qt.AscendingOrder)
  760. self.list_VST.sortItems(Qt.AscendingOrder)
  761. self.list_LADSPA.setCurrentRow(0)
  762. self.list_DSSI.setCurrentRow(0)
  763. self.list_LV2.setCurrentRow(0)
  764. self.list_VST.setCurrentRow(0)
  765. # -------------------------------------------------------------
  766. # Set-up GUI (Tweaks, Default Applications)
  767. for desktop in DESKTOP_X_IMAGE:
  768. if isDesktopFileInstalled(desktop):
  769. self.cb_app_image.addItem(desktop)
  770. for desktop in DESKTOP_X_MUSIC:
  771. if isDesktopFileInstalled(desktop):
  772. self.cb_app_music.addItem(desktop)
  773. for desktop in DESKTOP_X_VIDEO:
  774. if isDesktopFileInstalled(desktop):
  775. self.cb_app_video.addItem(desktop)
  776. for desktop in DESKTOP_X_TEXT:
  777. if isDesktopFileInstalled(desktop):
  778. self.cb_app_text.addItem(desktop)
  779. for desktop in DESKTOP_X_BROWSER:
  780. if isDesktopFileInstalled(desktop):
  781. self.cb_app_browser.addItem(desktop)
  782. if self.cb_app_image.count() == 0:
  783. self.ch_app_image.setEnabled(False)
  784. if self.cb_app_music.count() == 0:
  785. self.ch_app_music.setEnabled(False)
  786. if self.cb_app_video.count() == 0:
  787. self.ch_app_video.setEnabled(False)
  788. if self.cb_app_text.count() == 0:
  789. self.ch_app_text.setEnabled(False)
  790. if self.cb_app_browser.count() == 0:
  791. self.ch_app_browser.setEnabled(False)
  792. mimeappsPath = os.path.join(HOME, ".local", "share", "applications", "mimeapps.list")
  793. if os.path.exists(mimeappsPath):
  794. fd = open(mimeappsPath, "r")
  795. mimeappsRead = fd.read()
  796. fd.close()
  797. x_image = getXdgProperty(mimeappsRead, "image/bmp")
  798. x_music = getXdgProperty(mimeappsRead, "audio/wav")
  799. x_video = getXdgProperty(mimeappsRead, "video/webm")
  800. x_text = getXdgProperty(mimeappsRead, "text/plain")
  801. x_browser = getXdgProperty(mimeappsRead, "text/html")
  802. if x_image and searchAndSetComboBoxValue(self.cb_app_image, x_image):
  803. self.ch_app_image.setChecked(True)
  804. if x_music and searchAndSetComboBoxValue(self.cb_app_music, x_music):
  805. self.ch_app_music.setChecked(True)
  806. if x_video and searchAndSetComboBoxValue(self.cb_app_video, x_video):
  807. self.ch_app_video.setChecked(True)
  808. if x_text and searchAndSetComboBoxValue(self.cb_app_text, x_text):
  809. self.ch_app_text.setChecked(True)
  810. if x_browser and searchAndSetComboBoxValue(self.cb_app_browser, x_browser):
  811. self.ch_app_browser.setChecked(True)
  812. else: # ~/.local/share/applications/mimeapps.list doesn't exist
  813. if not os.path.exists(os.path.join(HOME, ".local")):
  814. os.mkdir(os.path.join(HOME, ".local"))
  815. elif not os.path.exists(os.path.join(HOME, ".local", "share")):
  816. os.mkdir(os.path.join(HOME, ".local", "share"))
  817. elif not os.path.exists(os.path.join(HOME, ".local", "share", "applications")):
  818. os.mkdir(os.path.join(HOME, ".local", "share", "applications"))
  819. # -------------------------------------------------------------
  820. # Set-up GUI (Tweaks, WineASIO)
  821. if haveWine:
  822. ins = int(getWineAsioKeyValue("Number of inputs", "00000010"), 16)
  823. outs = int(getWineAsioKeyValue("Number of outputs", "00000010"), 16)
  824. hw = bool(int(getWineAsioKeyValue("Connect to hardware", "00000001"), 10))
  825. autostart = bool(int(getWineAsioKeyValue("Autostart server", "00000000"), 10))
  826. fixed_bsize = bool(int(getWineAsioKeyValue("Fixed buffersize", "00000001"), 10))
  827. prefer_bsize = int(getWineAsioKeyValue("Preferred buffersize", "00000400"), 16)
  828. for bsize in BUFFER_SIZE_LIST:
  829. self.cb_wineasio_bsizes.addItem(str(bsize))
  830. if bsize == prefer_bsize:
  831. self.cb_wineasio_bsizes.setCurrentIndex(self.cb_wineasio_bsizes.count()-1)
  832. self.sb_wineasio_ins.setValue(ins)
  833. self.sb_wineasio_outs.setValue(outs)
  834. self.cb_wineasio_hw.setChecked(hw)
  835. self.cb_wineasio_autostart.setChecked(autostart)
  836. self.cb_wineasio_fixed_bsize.setChecked(fixed_bsize)
  837. else:
  838. # No Wine
  839. self.tw_tweaks.hideRow(2)
  840. # -------------------------------------------------------------
  841. # Set-up systray
  842. self.systray = systray.GlobalSysTray(self, "Cadence", "cadence")
  843. if haveDBus:
  844. self.systray.addAction("jack_start", self.tr("Start JACK"))
  845. self.systray.addAction("jack_stop", self.tr("Stop JACK"))
  846. self.systray.addAction("jack_configure", self.tr("Configure JACK"))
  847. self.systray.addSeparator("sep1")
  848. self.systray.addMenu("alsa", self.tr("ALSA Audio Bridge"))
  849. self.systray.addMenuAction("alsa", "alsa_start", self.tr("Start"))
  850. self.systray.addMenuAction("alsa", "alsa_stop", self.tr("Stop"))
  851. self.systray.addMenu("a2j", self.tr("ALSA MIDI Bridge"))
  852. self.systray.addMenuAction("a2j", "a2j_start", self.tr("Start"))
  853. self.systray.addMenuAction("a2j", "a2j_stop", self.tr("Stop"))
  854. self.systray.addMenu("pulse", self.tr("PulseAudio Bridge"))
  855. self.systray.addMenuAction("pulse", "pulse_start", self.tr("Start"))
  856. self.systray.addMenuAction("pulse", "pulse_stop", self.tr("Stop"))
  857. self.systray.setActionIcon("jack_start", "media-playback-start")
  858. self.systray.setActionIcon("jack_stop", "media-playback-stop")
  859. self.systray.setActionIcon("jack_configure", "configure")
  860. self.systray.setActionIcon("alsa_start", "media-playback-start")
  861. self.systray.setActionIcon("alsa_stop", "media-playback-stop")
  862. self.systray.setActionIcon("a2j_start", "media-playback-start")
  863. self.systray.setActionIcon("a2j_stop", "media-playback-stop")
  864. self.systray.setActionIcon("pulse_start", "media-playback-start")
  865. self.systray.setActionIcon("pulse_stop", "media-playback-stop")
  866. self.systray.connect("jack_start", self.slot_JackServerStart)
  867. self.systray.connect("jack_stop", self.slot_JackServerStop)
  868. self.systray.connect("jack_configure", self.slot_JackServerConfigure)
  869. self.systray.connect("alsa_start", self.slot_AlsaBridgeStart)
  870. self.systray.connect("alsa_stop", self.slot_AlsaBridgeStop)
  871. self.systray.connect("a2j_start", self.slot_A2JBridgeStart)
  872. self.systray.connect("a2j_stop", self.slot_A2JBridgeStop)
  873. self.systray.connect("pulse_start", self.slot_PulseAudioBridgeStart)
  874. self.systray.connect("pulse_stop", self.slot_PulseAudioBridgeStop)
  875. self.systray.addMenu("tools", self.tr("Tools"))
  876. self.systray.addMenuAction("tools", "app_catarina", "Catarina")
  877. self.systray.addMenuAction("tools", "app_catia", "Catia")
  878. self.systray.addMenuAction("tools", "app_claudia", "Claudia")
  879. self.systray.addMenuSeparator("tools", "tools_sep")
  880. self.systray.addMenuAction("tools", "app_logs", "Logs")
  881. self.systray.addMenuAction("tools", "app_meter_in", "Meter (Inputs)")
  882. self.systray.addMenuAction("tools", "app_meter_out", "Meter (Output)")
  883. self.systray.addMenuAction("tools", "app_render", "Render")
  884. self.systray.addMenuAction("tools", "app_xy-controller", "XY-Controller")
  885. self.systray.addSeparator("sep2")
  886. self.systray.connect("app_catarina", self.func_start_catarina)
  887. self.systray.connect("app_catia", self.func_start_catia)
  888. self.systray.connect("app_claudia", self.func_start_claudia)
  889. self.systray.connect("app_logs", self.func_start_logs)
  890. self.systray.connect("app_meter_in", self.func_start_jackmeter_in)
  891. self.systray.connect("app_meter_out", self.func_start_jackmeter)
  892. self.systray.connect("app_render", self.func_start_render)
  893. self.systray.connect("app_xy-controller", self.func_start_xycontroller)
  894. self.systray.setToolTip("Cadence")
  895. self.systray.show()
  896. # -------------------------------------------------------------
  897. # Set-up connections
  898. self.b_jack_start.clicked.connect(self.slot_JackServerStart)
  899. self.b_jack_stop.clicked.connect(self.slot_JackServerStop)
  900. self.b_jack_restart.clicked.connect(self.slot_JackServerForceRestart)
  901. self.b_jack_configure.clicked.connect(self.slot_JackServerConfigure)
  902. self.b_jack_switchmaster.clicked.connect(self.slot_JackServerSwitchMaster)
  903. self.tb_jack_options.clicked.connect(self.slot_JackOptions)
  904. self.b_alsa_start.clicked.connect(self.slot_AlsaBridgeStart)
  905. self.b_alsa_stop.clicked.connect(self.slot_AlsaBridgeStop)
  906. self.cb_alsa_type.currentIndexChanged[int].connect(self.slot_AlsaBridgeChanged)
  907. self.tb_alsa_options.clicked.connect(self.slot_AlsaAudioBridgeOptions)
  908. self.b_a2j_start.clicked.connect(self.slot_A2JBridgeStart)
  909. self.b_a2j_stop.clicked.connect(self.slot_A2JBridgeStop)
  910. self.b_pulse_start.clicked.connect(self.slot_PulseAudioBridgeStart)
  911. self.b_pulse_stop.clicked.connect(self.slot_PulseAudioBridgeStop)
  912. self.tb_pulse_options.clicked.connect(self.slot_PulseAudioBridgeOptions)
  913. self.pic_catia.clicked.connect(self.func_start_catia)
  914. self.pic_claudia.clicked.connect(self.func_start_claudia)
  915. self.pic_meter_in.clicked.connect(self.func_start_jackmeter_in)
  916. self.pic_meter_out.clicked.connect(self.func_start_jackmeter)
  917. self.pic_logs.clicked.connect(self.func_start_logs)
  918. self.pic_render.clicked.connect(self.func_start_render)
  919. self.pic_xycontroller.clicked.connect(self.func_start_xycontroller)
  920. self.b_tweaks_apply_now.clicked.connect(self.slot_tweaksApply)
  921. self.b_tweak_plugins_add.clicked.connect(self.slot_tweakPluginAdd)
  922. self.b_tweak_plugins_change.clicked.connect(self.slot_tweakPluginChange)
  923. self.b_tweak_plugins_remove.clicked.connect(self.slot_tweakPluginRemove)
  924. self.b_tweak_plugins_reset.clicked.connect(self.slot_tweakPluginReset)
  925. self.tb_tweak_plugins.currentChanged.connect(self.slot_tweakPluginTypeChanged)
  926. self.list_LADSPA.currentRowChanged.connect(self.slot_tweakPluginsLadspaRowChanged)
  927. self.list_DSSI.currentRowChanged.connect(self.slot_tweakPluginsDssiRowChanged)
  928. self.list_LV2.currentRowChanged.connect(self.slot_tweakPluginsLv2RowChanged)
  929. self.list_VST.currentRowChanged.connect(self.slot_tweakPluginsVstRowChanged)
  930. self.ch_app_image.clicked.connect(self.slot_tweaksSettingsChanged_apps)
  931. self.cb_app_image.highlighted.connect(self.slot_tweakAppImageHighlighted)
  932. self.cb_app_image.currentIndexChanged[int].connect(self.slot_tweakAppImageChanged)
  933. self.ch_app_music.clicked.connect(self.slot_tweaksSettingsChanged_apps)
  934. self.cb_app_music.highlighted.connect(self.slot_tweakAppMusicHighlighted)
  935. self.cb_app_music.currentIndexChanged[int].connect(self.slot_tweakAppMusicChanged)
  936. self.ch_app_video.clicked.connect(self.slot_tweaksSettingsChanged_apps)
  937. self.cb_app_video.highlighted.connect(self.slot_tweakAppVideoHighlighted)
  938. self.cb_app_video.currentIndexChanged[int].connect(self.slot_tweakAppVideoChanged)
  939. self.ch_app_text.clicked.connect(self.slot_tweaksSettingsChanged_apps)
  940. self.cb_app_text.highlighted.connect(self.slot_tweakAppTextHighlighted)
  941. self.cb_app_text.currentIndexChanged[int].connect(self.slot_tweakAppTextChanged)
  942. self.ch_app_browser.clicked.connect(self.slot_tweaksSettingsChanged_apps)
  943. self.cb_app_browser.highlighted.connect(self.slot_tweakAppBrowserHighlighted)
  944. self.cb_app_browser.currentIndexChanged[int].connect(self.slot_tweakAppBrowserChanged)
  945. self.sb_wineasio_ins.valueChanged.connect(self.slot_tweaksSettingsChanged_wineasio)
  946. self.sb_wineasio_outs.valueChanged.connect(self.slot_tweaksSettingsChanged_wineasio)
  947. self.cb_wineasio_hw.clicked.connect(self.slot_tweaksSettingsChanged_wineasio)
  948. self.cb_wineasio_autostart.clicked.connect(self.slot_tweaksSettingsChanged_wineasio)
  949. self.cb_wineasio_fixed_bsize.clicked.connect(self.slot_tweaksSettingsChanged_wineasio)
  950. self.cb_wineasio_bsizes.currentIndexChanged[int].connect(self.slot_tweaksSettingsChanged_wineasio)
  951. # org.jackaudio.JackControl
  952. self.DBusJackServerStartedCallback.connect(self.slot_DBusJackServerStartedCallback)
  953. self.DBusJackServerStoppedCallback.connect(self.slot_DBusJackServerStoppedCallback)
  954. # org.jackaudio.JackPatchbay
  955. self.DBusJackClientAppearedCallback.connect(self.slot_DBusJackClientAppearedCallback)
  956. self.DBusJackClientDisappearedCallback.connect(self.slot_DBusJackClientDisappearedCallback)
  957. # org.gna.home.a2jmidid.control
  958. self.DBusA2JBridgeStartedCallback.connect(self.slot_DBusA2JBridgeStartedCallback)
  959. self.DBusA2JBridgeStoppedCallback.connect(self.slot_DBusA2JBridgeStoppedCallback)
  960. self.cb_a2j_autoexport.stateChanged[int].connect(self.slot_A2JBridgeExportHW)
  961. # -------------------------------------------------------------
  962. self.m_last_dsp_load = None
  963. self.m_last_xruns = None
  964. self.m_last_buffer_size = None
  965. self.m_timer500 = None
  966. self.m_timer2000 = self.startTimer(2000)
  967. self.DBusReconnect()
  968. if haveDBus:
  969. gDBus.bus.add_signal_receiver(self.DBusSignalReceiver, destination_keyword='dest', path_keyword='path',
  970. member_keyword='member', interface_keyword='interface', sender_keyword='sender', )
  971. def DBusReconnect(self):
  972. if haveDBus:
  973. try:
  974. gDBus.jack = gDBus.bus.get_object("org.jackaudio.service", "/org/jackaudio/Controller")
  975. gDBus.patchbay = dbus.Interface(gDBus.jack, "org.jackaudio.JackPatchbay")
  976. jacksettings.initBus(gDBus.bus)
  977. except:
  978. gDBus.jack = None
  979. gDBus.patchbay = None
  980. try:
  981. gDBus.a2j = dbus.Interface(gDBus.bus.get_object("org.gna.home.a2jmidid", "/"), "org.gna.home.a2jmidid.control")
  982. except:
  983. gDBus.a2j = None
  984. if gDBus.jack:
  985. if gDBus.jack.IsStarted():
  986. # Check for pulseaudio in jack graph
  987. try:
  988. version, groups, conns = gDBus.patchbay.GetGraph(0)
  989. except:
  990. version, groups, conns = (list(), list(), list())
  991. for group_id, group_name, ports in groups:
  992. if group_name == "alsa2jack":
  993. global jackClientIdALSA
  994. jackClientIdALSA = group_id
  995. elif group_name == "PulseAudio JACK Sink":
  996. global jackClientIdPulse
  997. jackClientIdPulse = group_id
  998. self.jackStarted()
  999. else:
  1000. self.jackStopped()
  1001. self.label_jack_realtime.setText("Yes" if jacksettings.isRealtime() else "No")
  1002. else:
  1003. self.jackStopped()
  1004. self.label_jack_status.setText("Unavailable")
  1005. self.label_jack_status_ico.setPixmap(self.pix_error)
  1006. self.label_jack_realtime.setText("Unknown")
  1007. self.label_jack_realtime_ico.setPixmap(self.pix_error)
  1008. self.groupBox_jack.setEnabled(False)
  1009. self.groupBox_jack.setTitle("-- jackdbus is not available --")
  1010. self.b_jack_start.setEnabled(False)
  1011. self.b_jack_stop.setEnabled(False)
  1012. self.b_jack_restart.setEnabled(False)
  1013. self.b_jack_configure.setEnabled(False)
  1014. self.b_jack_switchmaster.setEnabled(False)
  1015. self.groupBox_bridges.setEnabled(False)
  1016. if gDBus.a2j:
  1017. try:
  1018. started = gDBus.a2j.is_started()
  1019. except:
  1020. started = False
  1021. if started:
  1022. self.a2jStarted()
  1023. else:
  1024. self.a2jStopped()
  1025. else:
  1026. self.toolBox_alsamidi.setEnabled(False)
  1027. self.cb_a2j_autostart.setChecked(False)
  1028. self.cb_a2j_autoexport.setChecked(False)
  1029. self.label_bridge_a2j.setText("ALSA MIDI Bridge is not installed")
  1030. self.settings.setValue("A2J/AutoStart", False)
  1031. self.updateSystrayTooltip()
  1032. def DBusSignalReceiver(self, *args, **kwds):
  1033. if kwds['interface'] == "org.freedesktop.DBus" and kwds['path'] == "/org/freedesktop/DBus" and kwds['member'] == "NameOwnerChanged":
  1034. appInterface, appId, newId = args
  1035. if not newId:
  1036. # Something crashed
  1037. if appInterface == "org.jackaudio.service":
  1038. QTimer.singleShot(0, self.slot_handleCrash_jack)
  1039. elif appInterface == "org.gna.home.a2jmidid":
  1040. QTimer.singleShot(0, self.slot_handleCrash_a2j)
  1041. elif kwds['interface'] == "org.jackaudio.JackControl":
  1042. if DEBUG: print("org.jackaudio.JackControl", kwds['member'])
  1043. if kwds['member'] == "ServerStarted":
  1044. self.DBusJackServerStartedCallback.emit()
  1045. elif kwds['member'] == "ServerStopped":
  1046. self.DBusJackServerStoppedCallback.emit()
  1047. elif kwds['interface'] == "org.jackaudio.JackPatchbay":
  1048. if gDBus.patchbay and kwds['path'] == gDBus.patchbay.object_path:
  1049. if DEBUG: print("org.jackaudio.JackPatchbay,", kwds['member'])
  1050. if kwds['member'] == "ClientAppeared":
  1051. self.DBusJackClientAppearedCallback.emit(args[iJackClientId], args[iJackClientName])
  1052. elif kwds['member'] == "ClientDisappeared":
  1053. self.DBusJackClientDisappearedCallback.emit(args[iJackClientId])
  1054. elif kwds['interface'] == "org.gna.home.a2jmidid.control":
  1055. if DEBUG: print("org.gna.home.a2jmidid.control", kwds['member'])
  1056. if kwds['member'] == "bridge_started":
  1057. self.DBusA2JBridgeStartedCallback.emit()
  1058. elif kwds['member'] == "bridge_stopped":
  1059. self.DBusA2JBridgeStoppedCallback.emit()
  1060. def jackStarted(self):
  1061. self.m_last_dsp_load = gDBus.jack.GetLoad()
  1062. self.m_last_xruns = int(gDBus.jack.GetXruns())
  1063. self.m_last_buffer_size = gDBus.jack.GetBufferSize()
  1064. self.b_jack_start.setEnabled(False)
  1065. self.b_jack_stop.setEnabled(True)
  1066. self.b_jack_switchmaster.setEnabled(True)
  1067. self.systray.setActionEnabled("jack_start", False)
  1068. self.systray.setActionEnabled("jack_stop", True)
  1069. self.label_jack_status.setText("Started")
  1070. self.label_jack_status_ico.setPixmap(self.pix_apply)
  1071. if gDBus.jack.IsRealtime():
  1072. self.label_jack_realtime.setText("Yes")
  1073. self.label_jack_realtime_ico.setPixmap(self.pix_apply)
  1074. else:
  1075. self.label_jack_realtime.setText("No")
  1076. self.label_jack_realtime_ico.setPixmap(self.pix_cancel)
  1077. self.label_jack_dsp.setText("%.2f%%" % self.m_last_dsp_load)
  1078. self.label_jack_xruns.setText(str(self.m_last_xruns))
  1079. self.label_jack_bfsize.setText("%i samples" % self.m_last_buffer_size)
  1080. self.label_jack_srate.setText("%i Hz" % gDBus.jack.GetSampleRate())
  1081. self.label_jack_latency.setText("%.1f ms" % gDBus.jack.GetLatency())
  1082. self.m_timer500 = self.startTimer(500)
  1083. if gDBus.a2j and not gDBus.a2j.is_started():
  1084. portsExported = bool(gDBus.a2j.get_hw_export())
  1085. if GlobalSettings.value("A2J/AutoStart", True, type=bool):
  1086. if not portsExported and GlobalSettings.value("A2J/AutoExport", True, type=bool):
  1087. gDBus.a2j.set_hw_export(True)
  1088. portsExported = True
  1089. gDBus.a2j.start()
  1090. else:
  1091. self.b_a2j_start.setEnabled(True)
  1092. self.systray.setActionEnabled("a2j_start", True)
  1093. self.checkAlsaAudio()
  1094. self.checkPulseAudio()
  1095. def jackStopped(self):
  1096. if self.m_timer500:
  1097. self.killTimer(self.m_timer500)
  1098. self.m_timer500 = None
  1099. self.m_last_dsp_load = None
  1100. self.m_last_xruns = None
  1101. self.m_last_buffer_size = None
  1102. self.b_jack_start.setEnabled(True)
  1103. self.b_jack_stop.setEnabled(False)
  1104. self.b_jack_switchmaster.setEnabled(False)
  1105. if haveDBus:
  1106. self.systray.setActionEnabled("jack_start", True)
  1107. self.systray.setActionEnabled("jack_stop", False)
  1108. self.label_jack_status.setText("Stopped")
  1109. self.label_jack_status_ico.setPixmap(self.pix_cancel)
  1110. self.label_jack_dsp.setText("---")
  1111. self.label_jack_xruns.setText("---")
  1112. self.label_jack_bfsize.setText("---")
  1113. self.label_jack_srate.setText("---")
  1114. self.label_jack_latency.setText("---")
  1115. if gDBus.a2j:
  1116. self.b_a2j_start.setEnabled(False)
  1117. self.systray.setActionEnabled("a2j_start", False)
  1118. global jackClientIdALSA, jackClientIdPulse
  1119. jackClientIdALSA = -1
  1120. jackClientIdPulse = -1
  1121. if haveDBus:
  1122. self.checkAlsaAudio()
  1123. self.checkPulseAudio()
  1124. def a2jStarted(self):
  1125. self.b_a2j_start.setEnabled(False)
  1126. self.b_a2j_stop.setEnabled(True)
  1127. self.systray.setActionEnabled("a2j_start", False)
  1128. self.systray.setActionEnabled("a2j_stop", True)
  1129. if bool(gDBus.a2j.get_hw_export()):
  1130. self.label_bridge_a2j.setText(self.tr("ALSA MIDI Bridge is running, ports are exported"))
  1131. else :
  1132. self.label_bridge_a2j.setText(self.tr("ALSA MIDI Bridge is running"))
  1133. def a2jStopped(self):
  1134. jackRunning = bool(gDBus.jack and gDBus.jack.IsStarted())
  1135. self.b_a2j_start.setEnabled(jackRunning)
  1136. self.b_a2j_stop.setEnabled(False)
  1137. self.systray.setActionEnabled("a2j_start", jackRunning)
  1138. self.systray.setActionEnabled("a2j_stop", False)
  1139. self.label_bridge_a2j.setText(self.tr("ALSA MIDI Bridge is stopped"))
  1140. def checkAlsaAudio(self):
  1141. asoundrcFile = os.path.join(HOME, ".asoundrc")
  1142. if not os.path.exists(asoundrcFile):
  1143. self.b_alsa_start.setEnabled(False)
  1144. self.b_alsa_stop.setEnabled(False)
  1145. self.cb_alsa_type.setCurrentIndex(iAlsaFileNone)
  1146. self.tb_alsa_options.setEnabled(False)
  1147. self.label_bridge_alsa.setText(self.tr("No bridge in use"))
  1148. self.m_lastAlsaIndexType = -1 # null
  1149. return
  1150. asoundrcFd = open(asoundrcFile, "r")
  1151. asoundrcRead = asoundrcFd.read().strip()
  1152. asoundrcFd.close()
  1153. if asoundrcRead.startswith(asoundrc_aloop_check):
  1154. if isAlsaAudioBridged():
  1155. self.b_alsa_start.setEnabled(False)
  1156. self.b_alsa_stop.setEnabled(True)
  1157. self.systray.setActionEnabled("alsa_start", False)
  1158. self.systray.setActionEnabled("alsa_stop", True)
  1159. self.label_bridge_alsa.setText(self.tr("Using Cadence snd-aloop daemon, started"))
  1160. else:
  1161. try:
  1162. jackRunning = bool(gDBus.jack and gDBus.jack.IsStarted())
  1163. except:
  1164. jackRunning = False
  1165. self.b_alsa_start.setEnabled(jackRunning)
  1166. self.b_alsa_stop.setEnabled(False)
  1167. self.systray.setActionEnabled("alsa_start", jackRunning)
  1168. self.systray.setActionEnabled("alsa_stop", False)
  1169. self.label_bridge_alsa.setText(self.tr("Using Cadence snd-aloop daemon, stopped"))
  1170. self.cb_alsa_type.setCurrentIndex(iAlsaFileLoop)
  1171. self.tb_alsa_options.setEnabled(True)
  1172. elif asoundrcRead == asoundrc_jack:
  1173. self.b_alsa_start.setEnabled(False)
  1174. self.b_alsa_stop.setEnabled(False)
  1175. self.systray.setActionEnabled("alsa_start", False)
  1176. self.systray.setActionEnabled("alsa_stop", False)
  1177. self.cb_alsa_type.setCurrentIndex(iAlsaFileJACK)
  1178. self.tb_alsa_options.setEnabled(False)
  1179. self.label_bridge_alsa.setText(self.tr("Using JACK plugin bridge (Always on)"))
  1180. elif asoundrcRead == asoundrc_pulse:
  1181. self.b_alsa_start.setEnabled(False)
  1182. self.b_alsa_stop.setEnabled(False)
  1183. self.systray.setActionEnabled("alsa_start", False)
  1184. self.systray.setActionEnabled("alsa_stop", False)
  1185. self.cb_alsa_type.setCurrentIndex(iAlsaFilePulse)
  1186. self.tb_alsa_options.setEnabled(False)
  1187. self.label_bridge_alsa.setText(self.tr("Using PulseAudio plugin bridge (Always on)"))
  1188. else:
  1189. self.b_alsa_start.setEnabled(False)
  1190. self.b_alsa_stop.setEnabled(False)
  1191. self.systray.setActionEnabled("alsa_start", False)
  1192. self.systray.setActionEnabled("alsa_stop", False)
  1193. self.cb_alsa_type.addItem(self.tr("Custom"))
  1194. self.cb_alsa_type.setCurrentIndex(iAlsaFileMax)
  1195. self.tb_alsa_options.setEnabled(True)
  1196. self.label_bridge_alsa.setText(self.tr("Using custom asoundrc, not managed by Cadence"))
  1197. self.m_lastAlsaIndexType = self.cb_alsa_type.currentIndex()
  1198. def checkPulseAudio(self):
  1199. if not havePulseAudio:
  1200. self.systray.setActionEnabled("pulse_start", False)
  1201. self.systray.setActionEnabled("pulse_stop", False)
  1202. return
  1203. if isPulseAudioStarted():
  1204. if isPulseAudioBridged():
  1205. self.b_pulse_start.setEnabled(False)
  1206. self.b_pulse_stop.setEnabled(True)
  1207. self.systray.setActionEnabled("pulse_start", False)
  1208. self.systray.setActionEnabled("pulse_stop", True)
  1209. self.label_bridge_pulse.setText(self.tr("PulseAudio is started and bridged to JACK"))
  1210. else:
  1211. jackRunning = bool(gDBus.jack and gDBus.jack.IsStarted())
  1212. self.b_pulse_start.setEnabled(jackRunning)
  1213. self.b_pulse_stop.setEnabled(False)
  1214. self.systray.setActionEnabled("pulse_start", jackRunning)
  1215. self.systray.setActionEnabled("pulse_stop", False)
  1216. self.label_bridge_pulse.setText(self.tr("PulseAudio is started but not bridged"))
  1217. else:
  1218. jackRunning = bool(gDBus.jack and gDBus.jack.IsStarted())
  1219. self.b_pulse_start.setEnabled(jackRunning)
  1220. self.b_pulse_stop.setEnabled(False)
  1221. self.systray.setActionEnabled("pulse_start", jackRunning)
  1222. self.systray.setActionEnabled("pulse_stop", False)
  1223. self.label_bridge_pulse.setText(self.tr("PulseAudio is not started"))
  1224. def setAppDetails(self, desktop):
  1225. appContents = getDesktopFileContents(desktop)
  1226. name = getXdgProperty(appContents, "Name")
  1227. icon = getXdgProperty(appContents, "Icon")
  1228. comment = getXdgProperty(appContents, "Comment")
  1229. if not name:
  1230. name = self.cb_app_image.currentText().replace(".desktop","").title()
  1231. if not icon:
  1232. icon = ""
  1233. if not comment:
  1234. comment = ""
  1235. self.ico_app.setPixmap(getIcon(icon, 48).pixmap(48, 48))
  1236. self.label_app_name.setText(name)
  1237. self.label_app_comment.setText(comment)
  1238. def updateSystrayTooltip(self):
  1239. systrayText = "Cadence\n"
  1240. systrayText += "%s: %s\n" % (self.tr("JACK Status"), self.label_jack_status.text())
  1241. systrayText += "%s: %s\n" % (self.tr("Realtime"), self.label_jack_realtime.text())
  1242. systrayText += "%s: %s\n" % (self.tr("DSP Load"), self.label_jack_dsp.text())
  1243. systrayText += "%s: %s\n" % (self.tr("Xruns"), self.label_jack_xruns.text())
  1244. systrayText += "%s: %s\n" % (self.tr("Buffer Size"), self.label_jack_bfsize.text())
  1245. systrayText += "%s: %s\n" % (self.tr("Sample Rate"), self.label_jack_srate.text())
  1246. systrayText += "%s: %s" % (self.tr("Block Latency"), self.label_jack_latency.text())
  1247. self.systray.setToolTip(systrayText)
  1248. @pyqtSlot()
  1249. def func_start_catarina(self):
  1250. self.func_start_tool("catarina")
  1251. @pyqtSlot()
  1252. def func_start_catia(self):
  1253. self.func_start_tool("catia")
  1254. @pyqtSlot()
  1255. def func_start_claudia(self):
  1256. self.func_start_tool("claudia")
  1257. @pyqtSlot()
  1258. def func_start_logs(self):
  1259. self.func_start_tool("cadence-logs")
  1260. @pyqtSlot()
  1261. def func_start_jackmeter(self):
  1262. self.func_start_tool("cadence-jackmeter")
  1263. @pyqtSlot()
  1264. def func_start_jackmeter_in(self):
  1265. self.func_start_tool("cadence-jackmeter -in")
  1266. @pyqtSlot()
  1267. def func_start_render(self):
  1268. self.func_start_tool("cadence-render")
  1269. @pyqtSlot()
  1270. def func_start_xycontroller(self):
  1271. self.func_start_tool("cadence-xycontroller")
  1272. def func_start_tool(self, tool):
  1273. if sys.argv[0].endswith(".py"):
  1274. if tool == "cadence-logs":
  1275. tool = "logs"
  1276. elif tool == "cadence-render":
  1277. tool = "render"
  1278. stool = tool.split(" ", 1)[0]
  1279. if stool in ("cadence-jackmeter", "cadence-xycontroller"):
  1280. python = ""
  1281. localPath = os.path.join(sys.path[0], "..", "c++", stool.replace("cadence-", ""))
  1282. if os.path.exists(os.path.join(localPath, stool)):
  1283. base = localPath + os.sep
  1284. else:
  1285. base = ""
  1286. else:
  1287. python = sys.executable
  1288. tool += ".py"
  1289. base = sys.argv[0].rsplit("cadence.py", 1)[0]
  1290. if python:
  1291. python += " "
  1292. cmd = "%s%s%s &" % (python, base, tool)
  1293. print(cmd)
  1294. os.system(cmd)
  1295. elif sys.argv[0].endswith("/cadence"):
  1296. base = sys.argv[0].rsplit("/cadence", 1)[0]
  1297. os.system("%s/%s &" % (base, tool))
  1298. else:
  1299. os.system("%s &" % tool)
  1300. def func_settings_changed(self, stype):
  1301. if stype not in self.settings_changed_types:
  1302. self.settings_changed_types.append(stype)
  1303. self.frame_tweaks_settings.setVisible(True)
  1304. @pyqtSlot()
  1305. def slot_DBusJackServerStartedCallback(self):
  1306. self.jackStarted()
  1307. @pyqtSlot()
  1308. def slot_DBusJackServerStoppedCallback(self):
  1309. self.jackStopped()
  1310. @pyqtSlot(int, str)
  1311. def slot_DBusJackClientAppearedCallback(self, group_id, group_name):
  1312. if group_name == "alsa2jack":
  1313. global jackClientIdALSA
  1314. jackClientIdALSA = group_id
  1315. self.checkAlsaAudio()
  1316. elif group_name == "PulseAudio JACK Sink":
  1317. global jackClientIdPulse
  1318. jackClientIdPulse = group_id
  1319. self.checkPulseAudio()
  1320. @pyqtSlot(int)
  1321. def slot_DBusJackClientDisappearedCallback(self, group_id):
  1322. global jackClientIdALSA, jackClientIdPulse
  1323. if group_id == jackClientIdALSA:
  1324. jackClientIdALSA = -1
  1325. self.checkAlsaAudio()
  1326. elif group_id == jackClientIdPulse:
  1327. jackClientIdPulse = -1
  1328. self.checkPulseAudio()
  1329. @pyqtSlot()
  1330. def slot_DBusA2JBridgeStartedCallback(self):
  1331. self.a2jStarted()
  1332. @pyqtSlot()
  1333. def slot_DBusA2JBridgeStoppedCallback(self):
  1334. self.a2jStopped()
  1335. @pyqtSlot()
  1336. def slot_JackServerStart(self):
  1337. self.saveSettings()
  1338. try:
  1339. gDBus.jack.StartServer()
  1340. except:
  1341. QMessageBox.warning(self, self.tr("Warning"), self.tr("Failed to start JACK, please check the logs for more information."))
  1342. @pyqtSlot()
  1343. def slot_JackServerStop(self):
  1344. if gDBus.a2j and bool(gDBus.a2j.is_started()):
  1345. gDBus.a2j.stop()
  1346. try:
  1347. gDBus.jack.StopServer()
  1348. except:
  1349. QMessageBox.warning(self, self.tr("Warning"), self.tr("Failed to stop JACK, please check the logs for more information."))
  1350. @pyqtSlot()
  1351. def slot_JackServerForceRestart(self):
  1352. if gDBus.jack.IsStarted():
  1353. ask = CustomMessageBox(self, QMessageBox.Warning, self.tr("Warning"),
  1354. self.tr("This will force kill all JACK applications!<br>Make sure to save your projects before continue."),
  1355. self.tr("Are you sure you want to force the restart of JACK?"))
  1356. if ask != QMessageBox.Yes:
  1357. return
  1358. if self.m_timer500:
  1359. self.killTimer(self.m_timer500)
  1360. self.m_timer500 = None
  1361. self.saveSettings()
  1362. ForceWaitDialog(self).exec_()
  1363. @pyqtSlot()
  1364. def slot_JackServerConfigure(self):
  1365. jacksettingsW = jacksettings.JackSettingsW(self)
  1366. jacksettingsW.exec_()
  1367. del jacksettingsW
  1368. @pyqtSlot()
  1369. def slot_JackServerSwitchMaster(self):
  1370. try:
  1371. gDBus.jack.SwitchMaster()
  1372. except:
  1373. QMessageBox.warning(self, self.tr("Warning"), self.tr("Failed to switch JACK master, please check the logs for more information."))
  1374. return
  1375. self.jackStarted()
  1376. @pyqtSlot()
  1377. def slot_JackOptions(self):
  1378. ToolBarJackDialog(self).exec_()
  1379. @pyqtSlot()
  1380. def slot_JackClearXruns(self):
  1381. if gDBus.jack:
  1382. gDBus.jack.ResetXruns()
  1383. @pyqtSlot()
  1384. def slot_AlsaBridgeStart(self):
  1385. self.slot_AlsaBridgeStop()
  1386. startAlsaAudioLoopBridge()
  1387. @pyqtSlot()
  1388. def slot_AlsaBridgeStop(self):
  1389. checkFile = self.getDaemonLockfile("cadence-aloop-daemon")
  1390. if os.path.exists(checkFile):
  1391. os.remove(checkFile)
  1392. @pyqtSlot(int)
  1393. def slot_AlsaBridgeChanged(self, index):
  1394. if self.m_lastAlsaIndexType == -2 or self.m_lastAlsaIndexType == index:
  1395. return
  1396. if self.m_lastAlsaIndexType == iAlsaFileMax:
  1397. ask = CustomMessageBox(self, QMessageBox.Warning, self.tr("Warning"),
  1398. self.tr(""
  1399. "You're using a custom ~/.asoundrc file not managed by Cadence.<br/>"
  1400. "By choosing to use a Cadence ALSA-Audio bridge, <b>the file will be replaced</b>."
  1401. ""),
  1402. self.tr("Are you sure you want to do this?"))
  1403. if ask == QMessageBox.Yes:
  1404. self.cb_alsa_type.blockSignals(True)
  1405. self.cb_alsa_type.removeItem(iAlsaFileMax)
  1406. self.cb_alsa_type.setCurrentIndex(index)
  1407. self.cb_alsa_type.blockSignals(False)
  1408. else:
  1409. self.cb_alsa_type.blockSignals(True)
  1410. self.cb_alsa_type.setCurrentIndex(iAlsaFileMax)
  1411. self.cb_alsa_type.blockSignals(False)
  1412. return
  1413. asoundrcFile = os.path.join(HOME, ".asoundrc")
  1414. if index == iAlsaFileNone:
  1415. os.remove(asoundrcFile)
  1416. elif index == iAlsaFileLoop:
  1417. asoundrcFd = open(asoundrcFile, "w")
  1418. asoundrcFd.write(asoundrc_aloop+"\n")
  1419. asoundrcFd.close()
  1420. elif index == iAlsaFileJACK:
  1421. asoundrcFd = open(asoundrcFile, "w")
  1422. asoundrcFd.write(asoundrc_jack+"\n")
  1423. asoundrcFd.close()
  1424. elif index == iAlsaFilePulse:
  1425. asoundrcFd = open(asoundrcFile, "w")
  1426. asoundrcFd.write(asoundrc_pulse+"\n")
  1427. asoundrcFd.close()
  1428. else:
  1429. print("Cadence::AlsaBridgeChanged(%i) - invalid index" % index)
  1430. self.checkAlsaAudio()
  1431. @pyqtSlot()
  1432. def slot_AlsaAudioBridgeOptions(self):
  1433. ToolBarAlsaAudioDialog(self, (self.cb_alsa_type.currentIndex() != iAlsaFileLoop)).exec_()
  1434. @pyqtSlot()
  1435. def slot_A2JBridgeStart(self):
  1436. gDBus.a2j.start()
  1437. @pyqtSlot()
  1438. def slot_A2JBridgeStop(self):
  1439. gDBus.a2j.stop()
  1440. @pyqtSlot(int)
  1441. def slot_A2JBridgeExportHW(self, state):
  1442. a2jWasStarted = bool(gDBus.a2j.is_started())
  1443. if a2jWasStarted:
  1444. gDBus.a2j.stop()
  1445. gDBus.a2j.set_hw_export(bool(state))
  1446. if a2jWasStarted:
  1447. gDBus.a2j.start()
  1448. @pyqtSlot()
  1449. def slot_PulseAudioBridgeStart(self):
  1450. if GlobalSettings.value("Pulse2JACK/PlaybackModeOnly", False, type=bool):
  1451. os.system("cadence-pulse2jack -p")
  1452. else:
  1453. os.system("cadence-pulse2jack")
  1454. @pyqtSlot()
  1455. def slot_PulseAudioBridgeStop(self):
  1456. os.system("pulseaudio -k")
  1457. @pyqtSlot()
  1458. def slot_PulseAudioBridgeOptions(self):
  1459. ToolBarPADialog(self).exec_()
  1460. @pyqtSlot()
  1461. def slot_handleCrash_jack(self):
  1462. self.DBusReconnect()
  1463. @pyqtSlot()
  1464. def slot_handleCrash_a2j(self):
  1465. pass
  1466. @pyqtSlot(str)
  1467. def slot_changeGovernorMode(self, newMode):
  1468. bus = dbus.SystemBus(mainloop=gDBus.loop)
  1469. #proxy = bus.get_object("org.cadence.CpufreqSelector", "/Selector", introspect=False)
  1470. #print(proxy.hello())
  1471. proxy = bus.get_object("com.ubuntu.IndicatorCpufreqSelector", "/Selector", introspect=False)
  1472. proxy.SetGovernor(self.m_curGovCPUs, newMode, dbus_interface="com.ubuntu.IndicatorCpufreqSelector")
  1473. @pyqtSlot()
  1474. def slot_governorFileChanged(self):
  1475. curGovFd = open(self.m_curGovPath, "r")
  1476. curGovRead = curGovFd.read().strip()
  1477. curGovFd.close()
  1478. customTr = self.tr("Custom")
  1479. if self.cb_cpufreq.currentIndex() == -1:
  1480. # First init
  1481. self.cb_cpufreq.currentIndexChanged[str].connect(self.slot_changeGovernorMode)
  1482. self.cb_cpufreq.blockSignals(True)
  1483. if curGovRead in self.m_availGovList:
  1484. self.cb_cpufreq.setCurrentIndex(self.m_availGovList.index(curGovRead))
  1485. if customTr in self.m_availGovList:
  1486. self.m_availGovList.remove(customTr)
  1487. else:
  1488. if customTr not in self.m_availGovList:
  1489. self.cb_cpufreq.addItem(customTr)
  1490. self.m_availGovList.append(customTr)
  1491. self.cb_cpufreq.setCurrentIndex(len(self.m_availGovList)-1)
  1492. self.cb_cpufreq.blockSignals(False)
  1493. @pyqtSlot()
  1494. def slot_tweaksApply(self):
  1495. if "plugins" in self.settings_changed_types:
  1496. EXTRA_LADSPA_DIRS = []
  1497. EXTRA_DSSI_DIRS = []
  1498. EXTRA_LV2_DIRS = []
  1499. EXTRA_VST_DIRS = []
  1500. for i in range(self.list_LADSPA.count()):
  1501. iPath = self.list_LADSPA.item(i).text()
  1502. if iPath not in DEFAULT_LADSPA_PATH and iPath not in EXTRA_LADSPA_DIRS:
  1503. EXTRA_LADSPA_DIRS.append(iPath)
  1504. for i in range(self.list_DSSI.count()):
  1505. iPath = self.list_DSSI.item(i).text()
  1506. if iPath not in DEFAULT_DSSI_PATH and iPath not in EXTRA_DSSI_DIRS:
  1507. EXTRA_DSSI_DIRS.append(iPath)
  1508. for i in range(self.list_LV2.count()):
  1509. iPath = self.list_LV2.item(i).text()
  1510. if iPath not in DEFAULT_LV2_PATH and iPath not in EXTRA_LV2_DIRS:
  1511. EXTRA_LV2_DIRS.append(iPath)
  1512. for i in range(self.list_VST.count()):
  1513. iPath = self.list_VST.item(i).text()
  1514. if iPath not in DEFAULT_VST_PATH and iPath not in EXTRA_VST_DIRS:
  1515. EXTRA_VST_DIRS.append(iPath)
  1516. GlobalSettings.setValue("AudioPlugins/EXTRA_LADSPA_PATH", ":".join(EXTRA_LADSPA_DIRS))
  1517. GlobalSettings.setValue("AudioPlugins/EXTRA_DSSI_PATH", ":".join(EXTRA_DSSI_DIRS))
  1518. GlobalSettings.setValue("AudioPlugins/EXTRA_LV2_PATH", ":".join(EXTRA_LV2_DIRS))
  1519. GlobalSettings.setValue("AudioPlugins/EXTRA_VST_PATH", ":".join(EXTRA_VST_DIRS))
  1520. if "apps" in self.settings_changed_types:
  1521. mimeFileContent = ""
  1522. # Fix common mime errors
  1523. mimeFileContent += "application/x-designer=designer-qt4.desktop;\n"
  1524. mimeFileContent += "application/x-ms-dos-executable=wine.desktop;\n"
  1525. mimeFileContent += "audio/x-minipsf=audacious.desktop;\n"
  1526. mimeFileContent += "audio/x-psf=audacious.desktop;\n"
  1527. if self.ch_app_image.isChecked():
  1528. imageApp = self.cb_app_image.currentText().replace("/","-")
  1529. mimeFileContent += "image/bmp=%s;\n" % imageApp
  1530. mimeFileContent += "image/gif=%s;\n" % imageApp
  1531. mimeFileContent += "image/jp2=%s;\n" % imageApp
  1532. mimeFileContent += "image/jpeg=%s;\n" % imageApp
  1533. mimeFileContent += "image/png=%s;\n" % imageApp
  1534. mimeFileContent += "image/svg+xml=%s;\n" % imageApp
  1535. mimeFileContent += "image/svg+xml-compressed=%s;\n" % imageApp
  1536. mimeFileContent += "image/tiff=%s;\n" % imageApp
  1537. mimeFileContent += "image/x-canon-cr2=%s;\n" % imageApp
  1538. mimeFileContent += "image/x-canon-crw=%s;\n" % imageApp
  1539. mimeFileContent += "image/x-eps=%s;\n" % imageApp
  1540. mimeFileContent += "image/x-kodak-dcr=%s;\n" % imageApp
  1541. mimeFileContent += "image/x-kodak-k25=%s;\n" % imageApp
  1542. mimeFileContent += "image/x-kodak-kdc=%s;\n" % imageApp
  1543. mimeFileContent += "image/x-nikon-nef=%s;\n" % imageApp
  1544. mimeFileContent += "image/x-olympus-orf=%s;\n" % imageApp
  1545. mimeFileContent += "image/x-panasonic-raw=%s;\n" % imageApp
  1546. mimeFileContent += "image/x-pcx=%s;\n" % imageApp
  1547. mimeFileContent += "image/x-pentax-pef=%s;\n" % imageApp
  1548. mimeFileContent += "image/x-portable-anymap=%s;\n" % imageApp
  1549. mimeFileContent += "image/x-portable-bitmap=%s;\n" % imageApp
  1550. mimeFileContent += "image/x-portable-graymap=%s;\n" % imageApp
  1551. mimeFileContent += "image/x-portable-pixmap=%s;\n" % imageApp
  1552. mimeFileContent += "image/x-sony-arw=%s;\n" % imageApp
  1553. mimeFileContent += "image/x-sony-sr2=%s;\n" % imageApp
  1554. mimeFileContent += "image/x-sony-srf=%s;\n" % imageApp
  1555. mimeFileContent += "image/x-tga=%s;\n" % imageApp
  1556. mimeFileContent += "image/x-xbitmap=%s;\n" % imageApp
  1557. mimeFileContent += "image/x-xpixmap=%s;\n" % imageApp
  1558. if self.ch_app_music.isChecked():
  1559. musicApp = self.cb_app_music.currentText().replace("/","-")
  1560. mimeFileContent += "application/vnd.apple.mpegurl=%s;\n" % musicApp
  1561. mimeFileContent += "application/xspf+xml=%s;\n" % musicApp
  1562. mimeFileContent += "application/x-smaf=%s;\n" % musicApp
  1563. mimeFileContent += "audio/AMR=%s;\n" % musicApp
  1564. mimeFileContent += "audio/AMR-WB=%s;\n" % musicApp
  1565. mimeFileContent += "audio/aac=%s;\n" % musicApp
  1566. mimeFileContent += "audio/ac3=%s;\n" % musicApp
  1567. mimeFileContent += "audio/basic=%s;\n" % musicApp
  1568. mimeFileContent += "audio/flac=%s;\n" % musicApp
  1569. mimeFileContent += "audio/m3u=%s;\n" % musicApp
  1570. mimeFileContent += "audio/mp2=%s;\n" % musicApp
  1571. mimeFileContent += "audio/mp4=%s;\n" % musicApp
  1572. mimeFileContent += "audio/mpeg=%s;\n" % musicApp
  1573. mimeFileContent += "audio/ogg=%s;\n" % musicApp
  1574. mimeFileContent += "audio/vnd.rn-realaudio=%s;\n" % musicApp
  1575. mimeFileContent += "audio/vorbis=%s;\n" % musicApp
  1576. mimeFileContent += "audio/webm=%s;\n" % musicApp
  1577. mimeFileContent += "audio/wav=%s;\n" % musicApp
  1578. mimeFileContent += "audio/x-adpcm=%s;\n" % musicApp
  1579. mimeFileContent += "audio/x-aifc=%s;\n" % musicApp
  1580. mimeFileContent += "audio/x-aiff=%s;\n" % musicApp
  1581. mimeFileContent += "audio/x-aiffc=%s;\n" % musicApp
  1582. mimeFileContent += "audio/x-ape=%s;\n" % musicApp
  1583. mimeFileContent += "audio/x-cda=%s;\n" % musicApp
  1584. mimeFileContent += "audio/x-flac=%s;\n" % musicApp
  1585. mimeFileContent += "audio/x-flac+ogg=%s;\n" % musicApp
  1586. mimeFileContent += "audio/x-gsm=%s;\n" % musicApp
  1587. mimeFileContent += "audio/x-m4b=%s;\n" % musicApp
  1588. mimeFileContent += "audio/x-matroska=%s;\n" % musicApp
  1589. mimeFileContent += "audio/x-mp2=%s;\n" % musicApp
  1590. mimeFileContent += "audio/x-mpegurl=%s;\n" % musicApp
  1591. mimeFileContent += "audio/x-ms-asx=%s;\n" % musicApp
  1592. mimeFileContent += "audio/x-ms-wma=%s;\n" % musicApp
  1593. mimeFileContent += "audio/x-musepack=%s;\n" % musicApp
  1594. mimeFileContent += "audio/x-ogg=%s;\n" % musicApp
  1595. mimeFileContent += "audio/x-oggflac=%s;\n" % musicApp
  1596. mimeFileContent += "audio/x-pn-realaudio-plugin=%s;\n" % musicApp
  1597. mimeFileContent += "audio/x-riff=%s;\n" % musicApp
  1598. mimeFileContent += "audio/x-scpls=%s;\n" % musicApp
  1599. mimeFileContent += "audio/x-speex=%s;\n" % musicApp
  1600. mimeFileContent += "audio/x-speex+ogg=%s;\n" % musicApp
  1601. mimeFileContent += "audio/x-tta=%s;\n" % musicApp
  1602. mimeFileContent += "audio/x-vorbis+ogg=%s;\n" % musicApp
  1603. mimeFileContent += "audio/x-wav=%s;\n" % musicApp
  1604. mimeFileContent += "audio/x-wavpack=%s;\n" % musicApp
  1605. if self.ch_app_video.isChecked():
  1606. videoApp = self.cb_app_video.currentText().replace("/","-")
  1607. mimeFileContent +="application/mxf=%s;\n" % videoApp
  1608. mimeFileContent +="application/ogg=%s;\n" % videoApp
  1609. mimeFileContent +="application/ram=%s;\n" % videoApp
  1610. mimeFileContent +="application/vnd.ms-asf=%s;\n" % videoApp
  1611. mimeFileContent +="application/vnd.ms-wpl=%s;\n" % videoApp
  1612. mimeFileContent +="application/vnd.rn-realmedia=%s;\n" % videoApp
  1613. mimeFileContent +="application/x-ms-wmp=%s;\n" % videoApp
  1614. mimeFileContent +="application/x-ms-wms=%s;\n" % videoApp
  1615. mimeFileContent +="application/x-netshow-channel=%s;\n" % videoApp
  1616. mimeFileContent +="application/x-ogg=%s;\n" % videoApp
  1617. mimeFileContent +="application/x-quicktime-media-link=%s;\n" % videoApp
  1618. mimeFileContent +="video/3gpp=%s;\n" % videoApp
  1619. mimeFileContent +="video/3gpp2=%s;\n" % videoApp
  1620. mimeFileContent +="video/divx=%s;\n" % videoApp
  1621. mimeFileContent +="video/dv=%s;\n" % videoApp
  1622. mimeFileContent +="video/flv=%s;\n" % videoApp
  1623. mimeFileContent +="video/mp2t=%s;\n" % videoApp
  1624. mimeFileContent +="video/mp4=%s;\n" % videoApp
  1625. mimeFileContent +="video/mpeg=%s;\n" % videoApp
  1626. mimeFileContent +="video/ogg=%s;\n" % videoApp
  1627. mimeFileContent +="video/quicktime=%s;\n" % videoApp
  1628. mimeFileContent +="video/vivo=%s;\n" % videoApp
  1629. mimeFileContent +="video/vnd.rn-realvideo=%s;\n" % videoApp
  1630. mimeFileContent +="video/webm=%s;\n" % videoApp
  1631. mimeFileContent +="video/x-anim=%s;\n" % videoApp
  1632. mimeFileContent +="video/x-flic=%s;\n" % videoApp
  1633. mimeFileContent +="video/x-flv=%s;\n" % videoApp
  1634. mimeFileContent +="video/x-m4v=%s;\n" % videoApp
  1635. mimeFileContent +="video/x-matroska=%s;\n" % videoApp
  1636. mimeFileContent +="video/x-ms-asf=%s;\n" % videoApp
  1637. mimeFileContent +="video/x-ms-wm=%s;\n" % videoApp
  1638. mimeFileContent +="video/x-ms-wmp=%s;\n" % videoApp
  1639. mimeFileContent +="video/x-ms-wmv=%s;\n" % videoApp
  1640. mimeFileContent +="video/x-ms-wvx=%s;\n" % videoApp
  1641. mimeFileContent +="video/x-msvideo=%s;\n" % videoApp
  1642. mimeFileContent +="video/x-nsv=%s;\n" % videoApp
  1643. mimeFileContent +="video/x-ogg=%s;\n" % videoApp
  1644. mimeFileContent +="video/x-ogm=%s;\n" % videoApp
  1645. mimeFileContent +="video/x-ogm+ogg=%s;\n" % videoApp
  1646. mimeFileContent +="video/x-theora=%s;\n" % videoApp
  1647. mimeFileContent +="video/x-theora+ogg=%s;\n" % videoApp
  1648. mimeFileContent +="video/x-wmv=%s;\n" % videoApp
  1649. if self.ch_app_text.isChecked():
  1650. # TODO - more mimetypes
  1651. textApp = self.cb_app_text.currentText().replace("/","-")
  1652. mimeFileContent +="application/rdf+xml=%s;\n" % textApp
  1653. mimeFileContent +="application/xml=%s;\n" % textApp
  1654. mimeFileContent +="application/xml-dtd=%s;\n" % textApp
  1655. mimeFileContent +="application/xml-external-parsed-entity=%s;\n" % textApp
  1656. mimeFileContent +="application/xsd=%s;\n" % textApp
  1657. mimeFileContent +="application/xslt+xml=%s;\n" % textApp
  1658. mimeFileContent +="application/x-trash=%s;\n" % textApp
  1659. mimeFileContent +="application/x-wine-extension-inf=%s;\n" % textApp
  1660. mimeFileContent +="application/x-wine-extension-ini=%s;\n" % textApp
  1661. mimeFileContent +="application/x-zerosize=%s;\n" % textApp
  1662. mimeFileContent +="text/css=%s;\n" % textApp
  1663. mimeFileContent +="text/plain=%s;\n" % textApp
  1664. mimeFileContent +="text/x-authors=%s;\n" % textApp
  1665. mimeFileContent +="text/x-c++-hdr=%s;\n" % textApp
  1666. mimeFileContent +="text/x-c++-src=%s;\n" % textApp
  1667. mimeFileContent +="text/x-changelog=%s;\n" % textApp
  1668. mimeFileContent +="text/x-chdr=%s;\n" % textApp
  1669. mimeFileContent +="text/x-cmake=%s;\n" % textApp
  1670. mimeFileContent +="text/x-copying=%s;\n" % textApp
  1671. mimeFileContent +="text/x-credits=%s;\n" % textApp
  1672. mimeFileContent +="text/x-csharp=%s;\n" % textApp
  1673. mimeFileContent +="text/x-csrc=%s;\n" % textApp
  1674. mimeFileContent +="text/x-install=%s;\n" % textApp
  1675. mimeFileContent +="text/x-log=%s;\n" % textApp
  1676. mimeFileContent +="text/x-lua=%s;\n" % textApp
  1677. mimeFileContent +="text/x-makefile=%s;\n" % textApp
  1678. mimeFileContent +="text/x-ms-regedit=%s;\n" % textApp
  1679. mimeFileContent +="text/x-nfo=%s;\n" % textApp
  1680. mimeFileContent +="text/x-objchdr=%s;\n" % textApp
  1681. mimeFileContent +="text/x-objcsrc=%s;\n" % textApp
  1682. mimeFileContent +="text/x-pascal=%s;\n" % textApp
  1683. mimeFileContent +="text/x-patch=%s;\n" % textApp
  1684. mimeFileContent +="text/x-python=%s;\n" % textApp
  1685. mimeFileContent +="text/x-readme=%s;\n" % textApp
  1686. mimeFileContent +="text/x-vhdl=%s;\n" % textApp
  1687. if self.ch_app_browser.isChecked():
  1688. # TODO - needs something else for default browser
  1689. browserApp = self.cb_app_browser.currentText().replace("/","-")
  1690. mimeFileContent +="application/atom+xml=%s;\n" % browserApp
  1691. mimeFileContent +="application/rss+xml=%s;\n" % browserApp
  1692. mimeFileContent +="application/vnd.mozilla.xul+xml=%s;\n" % browserApp
  1693. mimeFileContent +="application/x-mozilla-bookmarks=%s;\n" % browserApp
  1694. mimeFileContent +="application/x-mswinurl=%s;\n" % browserApp
  1695. mimeFileContent +="application/x-xbel=%s;\n" % browserApp
  1696. mimeFileContent +="application/xhtml+xml=%s;\n" % browserApp
  1697. mimeFileContent +="text/html=%s;\n" % browserApp
  1698. mimeFileContent +="text/opml+xml=%s;\n" % browserApp
  1699. realMimeFileContent ="[Default Applications]\n"
  1700. realMimeFileContent += mimeFileContent
  1701. realMimeFileContent +="\n"
  1702. realMimeFileContent +="[Added Associations]\n"
  1703. realMimeFileContent += mimeFileContent
  1704. realMimeFileContent +="\n"
  1705. local_xdg_defaults = os.path.join(HOME, ".local", "share", "applications", "defaults.list")
  1706. local_xdg_mimeapps = os.path.join(HOME, ".local", "share", "applications", "mimeapps.list")
  1707. writeFile = open(local_xdg_defaults, "w")
  1708. writeFile.write(realMimeFileContent)
  1709. writeFile.close()
  1710. writeFile = open(local_xdg_mimeapps, "w")
  1711. writeFile.write(realMimeFileContent)
  1712. writeFile.close()
  1713. if "wineasio" in self.settings_changed_types:
  1714. REGFILE = 'REGEDIT4\n'
  1715. REGFILE += '\n'
  1716. REGFILE += '[HKEY_CURRENT_USER\Software\Wine\WineASIO]\n'
  1717. REGFILE += '"Autostart server"=dword:0000000%i\n' % int(1 if self.cb_wineasio_autostart.isChecked() else 0)
  1718. REGFILE += '"Connect to hardware"=dword:0000000%i\n' % int(1 if self.cb_wineasio_hw.isChecked() else 0)
  1719. REGFILE += '"Fixed buffersize"=dword:0000000%i\n' % int(1 if self.cb_wineasio_fixed_bsize.isChecked() else 0)
  1720. REGFILE += '"Number of inputs"=dword:000000%s\n' % smartHex(self.sb_wineasio_ins.value(), 2)
  1721. REGFILE += '"Number of outputs"=dword:000000%s\n' % smartHex(self.sb_wineasio_outs.value(), 2)
  1722. REGFILE += '"Preferred buffersize"=dword:0000%s\n' % smartHex(int(self.cb_wineasio_bsizes.currentText()), 4)
  1723. with tempfile.NamedTemporaryFile('w') as tmpfile:
  1724. tmpfile.write(REGFILE)
  1725. tmpfile.flush()
  1726. subprocess.run(["regedit", tmpfile.name])
  1727. self.settings_changed_types = []
  1728. self.frame_tweaks_settings.setVisible(False)
  1729. @pyqtSlot()
  1730. def slot_tweaksSettingsChanged_apps(self):
  1731. self.func_settings_changed("apps")
  1732. @pyqtSlot()
  1733. def slot_tweaksSettingsChanged_wineasio(self):
  1734. self.func_settings_changed("wineasio")
  1735. @pyqtSlot(int)
  1736. def slot_tweakAppImageHighlighted(self, index):
  1737. self.setAppDetails(self.cb_app_image.itemText(index))
  1738. @pyqtSlot(int)
  1739. def slot_tweakAppImageChanged(self, ignored):
  1740. self.setAppDetails(self.cb_app_image.currentText())
  1741. self.func_settings_changed("apps")
  1742. @pyqtSlot(int)
  1743. def slot_tweakAppMusicHighlighted(self, index):
  1744. self.setAppDetails(self.cb_app_music.itemText(index))
  1745. @pyqtSlot(int)
  1746. def slot_tweakAppMusicChanged(self, ignored):
  1747. self.setAppDetails(self.cb_app_music.currentText())
  1748. self.func_settings_changed("apps")
  1749. @pyqtSlot(int)
  1750. def slot_tweakAppVideoHighlighted(self, index):
  1751. self.setAppDetails(self.cb_app_video.itemText(index))
  1752. @pyqtSlot(int)
  1753. def slot_tweakAppVideoChanged(self, ignored):
  1754. self.setAppDetails(self.cb_app_video.currentText())
  1755. self.func_settings_changed("apps")
  1756. @pyqtSlot(int)
  1757. def slot_tweakAppTextHighlighted(self, index):
  1758. self.setAppDetails(self.cb_app_text.itemText(index))
  1759. @pyqtSlot(int)
  1760. def slot_tweakAppTextChanged(self, ignored):
  1761. self.setAppDetails(self.cb_app_text.currentText())
  1762. self.func_settings_changed("apps")
  1763. @pyqtSlot(int)
  1764. def slot_tweakAppBrowserHighlighted(self, index):
  1765. self.setAppDetails(self.cb_app_browser.itemText(index))
  1766. @pyqtSlot(int)
  1767. def slot_tweakAppBrowserChanged(self, ignored):
  1768. self.setAppDetails(self.cb_app_browser.currentText())
  1769. self.func_settings_changed("apps")
  1770. @pyqtSlot()
  1771. def slot_tweakPluginAdd(self):
  1772. newPath = QFileDialog.getExistingDirectory(self, self.tr("Add Path"), "", QFileDialog.ShowDirsOnly)
  1773. if not newPath:
  1774. return
  1775. if self.tb_tweak_plugins.currentIndex() == 0:
  1776. self.list_LADSPA.addItem(newPath)
  1777. elif self.tb_tweak_plugins.currentIndex() == 1:
  1778. self.list_DSSI.addItem(newPath)
  1779. elif self.tb_tweak_plugins.currentIndex() == 2:
  1780. self.list_LV2.addItem(newPath)
  1781. elif self.tb_tweak_plugins.currentIndex() == 3:
  1782. self.list_VST.addItem(newPath)
  1783. self.func_settings_changed("plugins")
  1784. @pyqtSlot()
  1785. def slot_tweakPluginChange(self):
  1786. if self.tb_tweak_plugins.currentIndex() == 0:
  1787. curPath = self.list_LADSPA.item(self.list_LADSPA.currentRow()).text()
  1788. elif self.tb_tweak_plugins.currentIndex() == 1:
  1789. curPath = self.list_DSSI.item(self.list_DSSI.currentRow()).text()
  1790. elif self.tb_tweak_plugins.currentIndex() == 2:
  1791. curPath = self.list_LV2.item(self.list_LV2.currentRow()).text()
  1792. elif self.tb_tweak_plugins.currentIndex() == 3:
  1793. curPath = self.list_VST.item(self.list_VST.currentRow()).text()
  1794. else:
  1795. curPath = ""
  1796. newPath = QFileDialog.getExistingDirectory(self, self.tr("Change Path"), curPath, QFileDialog.ShowDirsOnly)
  1797. if not newPath:
  1798. return
  1799. if self.tb_tweak_plugins.currentIndex() == 0:
  1800. self.list_LADSPA.item(self.list_LADSPA.currentRow()).setText(newPath)
  1801. elif self.tb_tweak_plugins.currentIndex() == 1:
  1802. self.list_DSSI.item(self.list_DSSI.currentRow()).setText(newPath)
  1803. elif self.tb_tweak_plugins.currentIndex() == 2:
  1804. self.list_LV2.item(self.list_LV2.currentRow()).setText(newPath)
  1805. elif self.tb_tweak_plugins.currentIndex() == 3:
  1806. self.list_VST.item(self.list_VST.currentRow()).setText(newPath)
  1807. self.func_settings_changed("plugins")
  1808. @pyqtSlot()
  1809. def slot_tweakPluginRemove(self):
  1810. if self.tb_tweak_plugins.currentIndex() == 0:
  1811. self.list_LADSPA.takeItem(self.list_LADSPA.currentRow())
  1812. elif self.tb_tweak_plugins.currentIndex() == 1:
  1813. self.list_DSSI.takeItem(self.list_DSSI.currentRow())
  1814. elif self.tb_tweak_plugins.currentIndex() == 2:
  1815. self.list_LV2.takeItem(self.list_LV2.currentRow())
  1816. elif self.tb_tweak_plugins.currentIndex() == 3:
  1817. self.list_VST.takeItem(self.list_VST.currentRow())
  1818. self.func_settings_changed("plugins")
  1819. @pyqtSlot()
  1820. def slot_tweakPluginReset(self):
  1821. if self.tb_tweak_plugins.currentIndex() == 0:
  1822. self.list_LADSPA.clear()
  1823. for iPath in DEFAULT_LADSPA_PATH:
  1824. self.list_LADSPA.addItem(iPath)
  1825. elif self.tb_tweak_plugins.currentIndex() == 1:
  1826. self.list_DSSI.clear()
  1827. for iPath in DEFAULT_DSSI_PATH:
  1828. self.list_DSSI.addItem(iPath)
  1829. elif self.tb_tweak_plugins.currentIndex() == 2:
  1830. self.list_LV2.clear()
  1831. for iPath in DEFAULT_LV2_PATH:
  1832. self.list_LV2.addItem(iPath)
  1833. elif self.tb_tweak_plugins.currentIndex() == 3:
  1834. self.list_VST.clear()
  1835. for iPath in DEFAULT_VST_PATH:
  1836. self.list_VST.addItem(iPath)
  1837. self.func_settings_changed("plugins")
  1838. @pyqtSlot(int)
  1839. def slot_tweakPluginTypeChanged(self, index):
  1840. # Force row change
  1841. if index == 0:
  1842. self.list_LADSPA.setCurrentRow(-1)
  1843. self.list_LADSPA.setCurrentRow(0)
  1844. elif index == 1:
  1845. self.list_DSSI.setCurrentRow(-1)
  1846. self.list_DSSI.setCurrentRow(0)
  1847. elif index == 2:
  1848. self.list_LV2.setCurrentRow(-1)
  1849. self.list_LV2.setCurrentRow(0)
  1850. elif index == 3:
  1851. self.list_VST.setCurrentRow(-1)
  1852. self.list_VST.setCurrentRow(0)
  1853. @pyqtSlot(int)
  1854. def slot_tweakPluginsLadspaRowChanged(self, index):
  1855. nonRemovable = (index >= 0 and self.list_LADSPA.item(index).text() not in DEFAULT_LADSPA_PATH)
  1856. self.b_tweak_plugins_change.setEnabled(nonRemovable)
  1857. self.b_tweak_plugins_remove.setEnabled(nonRemovable)
  1858. @pyqtSlot(int)
  1859. def slot_tweakPluginsDssiRowChanged(self, index):
  1860. nonRemovable = (index >= 0 and self.list_DSSI.item(index).text() not in DEFAULT_DSSI_PATH)
  1861. self.b_tweak_plugins_change.setEnabled(nonRemovable)
  1862. self.b_tweak_plugins_remove.setEnabled(nonRemovable)
  1863. @pyqtSlot(int)
  1864. def slot_tweakPluginsLv2RowChanged(self, index):
  1865. nonRemovable = (index >= 0 and self.list_LV2.item(index).text() not in DEFAULT_LV2_PATH)
  1866. self.b_tweak_plugins_change.setEnabled(nonRemovable)
  1867. self.b_tweak_plugins_remove.setEnabled(nonRemovable)
  1868. @pyqtSlot(int)
  1869. def slot_tweakPluginsVstRowChanged(self, index):
  1870. nonRemovable = (index >= 0 and self.list_VST.item(index).text() not in DEFAULT_VST_PATH)
  1871. self.b_tweak_plugins_change.setEnabled(nonRemovable)
  1872. self.b_tweak_plugins_remove.setEnabled(nonRemovable)
  1873. def saveSettings(self):
  1874. self.settings.setValue("Geometry", self.saveGeometry())
  1875. GlobalSettings.setValue("JACK/AutoStart", self.cb_jack_autostart.isChecked())
  1876. GlobalSettings.setValue("ALSA-Audio/BridgeIndexType", self.cb_alsa_type.currentIndex())
  1877. GlobalSettings.setValue("A2J/AutoStart", self.cb_a2j_autostart.isChecked())
  1878. GlobalSettings.setValue("A2J/AutoExport", self.cb_a2j_autoexport.isChecked())
  1879. GlobalSettings.setValue("Pulse2JACK/AutoStart", (havePulseAudio and self.cb_pulse_autostart.isChecked()))
  1880. def loadSettings(self, geometry):
  1881. if geometry:
  1882. self.restoreGeometry(self.settings.value("Geometry", b""))
  1883. usingAlsaLoop = bool(GlobalSettings.value("ALSA-Audio/BridgeIndexType", iAlsaFileNone, type=int) == iAlsaFileLoop)
  1884. self.cb_jack_autostart.setChecked(GlobalSettings.value("JACK/AutoStart", wantJackStart, type=bool))
  1885. self.cb_a2j_autostart.setChecked(GlobalSettings.value("A2J/AutoStart", True, type=bool))
  1886. self.cb_a2j_autoexport.setChecked(GlobalSettings.value("A2J/AutoExport", True, type=bool))
  1887. self.cb_pulse_autostart.setChecked(GlobalSettings.value("Pulse2JACK/AutoStart", havePulseAudio and not usingAlsaLoop, type=bool))
  1888. def timerEvent(self, event):
  1889. if event.timerId() == self.m_timer500:
  1890. if gDBus.jack and self.m_last_dsp_load != None:
  1891. next_dsp_load = gDBus.jack.GetLoad()
  1892. next_xruns = int(gDBus.jack.GetXruns())
  1893. needUpdateTip = False
  1894. if self.m_last_dsp_load != next_dsp_load:
  1895. self.m_last_dsp_load = next_dsp_load
  1896. self.label_jack_dsp.setText("%.2f%%" % self.m_last_dsp_load)
  1897. needUpdateTip = True
  1898. if self.m_last_xruns != next_xruns:
  1899. self.m_last_xruns = next_xruns
  1900. self.label_jack_xruns.setText(str(self.m_last_xruns))
  1901. needUpdateTip = True
  1902. if needUpdateTip:
  1903. self.updateSystrayTooltip()
  1904. elif event.timerId() == self.m_timer2000:
  1905. if gDBus.jack and self.m_last_buffer_size != None:
  1906. next_buffer_size = gDBus.jack.GetBufferSize()
  1907. if self.m_last_buffer_size != next_buffer_size:
  1908. self.m_last_buffer_size = next_buffer_size
  1909. self.label_jack_bfsize.setText("%i samples" % self.m_last_buffer_size)
  1910. self.label_jack_latency.setText("%.1f ms" % gDBus.jack.GetLatency())
  1911. else:
  1912. self.update()
  1913. QMainWindow.timerEvent(self, event)
  1914. def closeEvent(self, event):
  1915. self.saveSettings()
  1916. self.systray.handleQtCloseEvent(event)
  1917. # ------------------------------------------------------------------------------------------------------------
  1918. def runFunctionInMainThread(task):
  1919. waiter = QSemaphore(1)
  1920. def taskInMainThread():
  1921. task()
  1922. waiter.release()
  1923. QTimer.singleShot(0, taskInMainThread)
  1924. waiter.tryAcquire()
  1925. #--------------- main ------------------
  1926. if __name__ == '__main__':
  1927. # App initialization
  1928. app = QApplication(sys.argv)
  1929. app.setApplicationName("Cadence")
  1930. app.setApplicationVersion(VERSION)
  1931. app.setOrganizationName("Cadence")
  1932. app.setWindowIcon(QIcon(":/scalable/cadence.svg"))
  1933. if haveDBus:
  1934. gDBus.loop = DBusMainLoop(set_as_default=True)
  1935. gDBus.bus = dbus.SessionBus(mainloop=gDBus.loop)
  1936. initSystemChecks()
  1937. # Show GUI
  1938. gui = CadenceMainW()
  1939. # Set-up custom signal handling
  1940. setUpSignals(gui)
  1941. if "--minimized" in app.arguments():
  1942. gui.hide()
  1943. gui.systray.setActionText("show", gui.tr("Restore"))
  1944. app.setQuitOnLastWindowClosed(False)
  1945. else:
  1946. gui.show()
  1947. # Exit properly
  1948. sys.exit(gui.systray.exec_(app))