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.

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