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.

2386 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.addMenu("pulse", self.tr("PulseAudio Bridge"))
  848. self.systray.addMenuAction("pulse", "pulse_start", self.tr("Start"))
  849. self.systray.addMenuAction("pulse", "pulse_stop", self.tr("Stop"))
  850. self.systray.setActionIcon("jack_start", "media-playback-start")
  851. self.systray.setActionIcon("jack_stop", "media-playback-stop")
  852. self.systray.setActionIcon("jack_configure", "configure")
  853. self.systray.setActionIcon("alsa_start", "media-playback-start")
  854. self.systray.setActionIcon("alsa_stop", "media-playback-stop")
  855. self.systray.setActionIcon("a2j_start", "media-playback-start")
  856. self.systray.setActionIcon("a2j_stop", "media-playback-stop")
  857. self.systray.setActionIcon("pulse_start", "media-playback-start")
  858. self.systray.setActionIcon("pulse_stop", "media-playback-stop")
  859. self.systray.connect("jack_start", self.slot_JackServerStart)
  860. self.systray.connect("jack_stop", self.slot_JackServerStop)
  861. self.systray.connect("jack_configure", self.slot_JackServerConfigure)
  862. self.systray.connect("alsa_start", self.slot_AlsaBridgeStart)
  863. self.systray.connect("alsa_stop", self.slot_AlsaBridgeStop)
  864. self.systray.connect("a2j_start", self.slot_A2JBridgeStart)
  865. self.systray.connect("a2j_stop", self.slot_A2JBridgeStop)
  866. self.systray.connect("pulse_start", self.slot_PulseAudioBridgeStart)
  867. self.systray.connect("pulse_stop", self.slot_PulseAudioBridgeStop)
  868. self.systray.addMenu("tools", self.tr("Tools"))
  869. self.systray.addMenuAction("tools", "app_catarina", "Catarina")
  870. self.systray.addMenuAction("tools", "app_catia", "Catia")
  871. self.systray.addMenuAction("tools", "app_claudia", "Claudia")
  872. self.systray.addMenuSeparator("tools", "tools_sep")
  873. self.systray.addMenuAction("tools", "app_logs", "Logs")
  874. self.systray.addMenuAction("tools", "app_meter_in", "Meter (Inputs)")
  875. self.systray.addMenuAction("tools", "app_meter_out", "Meter (Output)")
  876. self.systray.addMenuAction("tools", "app_render", "Render")
  877. self.systray.addMenuAction("tools", "app_xy-controller", "XY-Controller")
  878. self.systray.addSeparator("sep2")
  879. self.systray.connect("app_catarina", self.func_start_catarina)
  880. self.systray.connect("app_catia", self.func_start_catia)
  881. self.systray.connect("app_claudia", self.func_start_claudia)
  882. self.systray.connect("app_logs", self.func_start_logs)
  883. self.systray.connect("app_meter_in", self.func_start_jackmeter_in)
  884. self.systray.connect("app_meter_out", self.func_start_jackmeter)
  885. self.systray.connect("app_render", self.func_start_render)
  886. self.systray.connect("app_xy-controller", self.func_start_xycontroller)
  887. self.systray.setToolTip("Cadence")
  888. self.systray.show()
  889. # -------------------------------------------------------------
  890. # Set-up connections
  891. self.b_jack_start.clicked.connect(self.slot_JackServerStart)
  892. self.b_jack_stop.clicked.connect(self.slot_JackServerStop)
  893. self.b_jack_restart.clicked.connect(self.slot_JackServerForceRestart)
  894. self.b_jack_configure.clicked.connect(self.slot_JackServerConfigure)
  895. self.b_jack_switchmaster.clicked.connect(self.slot_JackServerSwitchMaster)
  896. self.tb_jack_options.clicked.connect(self.slot_JackOptions)
  897. self.b_alsa_start.clicked.connect(self.slot_AlsaBridgeStart)
  898. self.b_alsa_stop.clicked.connect(self.slot_AlsaBridgeStop)
  899. self.cb_alsa_type.currentIndexChanged[int].connect(self.slot_AlsaBridgeChanged)
  900. self.tb_alsa_options.clicked.connect(self.slot_AlsaAudioBridgeOptions)
  901. self.b_a2j_start.clicked.connect(self.slot_A2JBridgeStart)
  902. self.b_a2j_stop.clicked.connect(self.slot_A2JBridgeStop)
  903. self.b_pulse_start.clicked.connect(self.slot_PulseAudioBridgeStart)
  904. self.b_pulse_stop.clicked.connect(self.slot_PulseAudioBridgeStop)
  905. self.tb_pulse_options.clicked.connect(self.slot_PulseAudioBridgeOptions)
  906. self.pic_catia.clicked.connect(self.func_start_catia)
  907. self.pic_claudia.clicked.connect(self.func_start_claudia)
  908. self.pic_meter_in.clicked.connect(self.func_start_jackmeter_in)
  909. self.pic_meter_out.clicked.connect(self.func_start_jackmeter)
  910. self.pic_logs.clicked.connect(self.func_start_logs)
  911. self.pic_render.clicked.connect(self.func_start_render)
  912. self.pic_xycontroller.clicked.connect(self.func_start_xycontroller)
  913. self.b_tweaks_apply_now.clicked.connect(self.slot_tweaksApply)
  914. self.b_tweak_plugins_add.clicked.connect(self.slot_tweakPluginAdd)
  915. self.b_tweak_plugins_change.clicked.connect(self.slot_tweakPluginChange)
  916. self.b_tweak_plugins_remove.clicked.connect(self.slot_tweakPluginRemove)
  917. self.b_tweak_plugins_reset.clicked.connect(self.slot_tweakPluginReset)
  918. self.tb_tweak_plugins.currentChanged.connect(self.slot_tweakPluginTypeChanged)
  919. self.list_LADSPA.currentRowChanged.connect(self.slot_tweakPluginsLadspaRowChanged)
  920. self.list_DSSI.currentRowChanged.connect(self.slot_tweakPluginsDssiRowChanged)
  921. self.list_LV2.currentRowChanged.connect(self.slot_tweakPluginsLv2RowChanged)
  922. self.list_VST.currentRowChanged.connect(self.slot_tweakPluginsVstRowChanged)
  923. self.ch_app_image.clicked.connect(self.slot_tweaksSettingsChanged_apps)
  924. self.cb_app_image.highlighted.connect(self.slot_tweakAppImageHighlighted)
  925. self.cb_app_image.currentIndexChanged[int].connect(self.slot_tweakAppImageChanged)
  926. self.ch_app_music.clicked.connect(self.slot_tweaksSettingsChanged_apps)
  927. self.cb_app_music.highlighted.connect(self.slot_tweakAppMusicHighlighted)
  928. self.cb_app_music.currentIndexChanged[int].connect(self.slot_tweakAppMusicChanged)
  929. self.ch_app_video.clicked.connect(self.slot_tweaksSettingsChanged_apps)
  930. self.cb_app_video.highlighted.connect(self.slot_tweakAppVideoHighlighted)
  931. self.cb_app_video.currentIndexChanged[int].connect(self.slot_tweakAppVideoChanged)
  932. self.ch_app_text.clicked.connect(self.slot_tweaksSettingsChanged_apps)
  933. self.cb_app_text.highlighted.connect(self.slot_tweakAppTextHighlighted)
  934. self.cb_app_text.currentIndexChanged[int].connect(self.slot_tweakAppTextChanged)
  935. self.ch_app_browser.clicked.connect(self.slot_tweaksSettingsChanged_apps)
  936. self.cb_app_browser.highlighted.connect(self.slot_tweakAppBrowserHighlighted)
  937. self.cb_app_browser.currentIndexChanged[int].connect(self.slot_tweakAppBrowserChanged)
  938. self.sb_wineasio_ins.valueChanged.connect(self.slot_tweaksSettingsChanged_wineasio)
  939. self.sb_wineasio_outs.valueChanged.connect(self.slot_tweaksSettingsChanged_wineasio)
  940. self.cb_wineasio_hw.clicked.connect(self.slot_tweaksSettingsChanged_wineasio)
  941. self.cb_wineasio_autostart.clicked.connect(self.slot_tweaksSettingsChanged_wineasio)
  942. self.cb_wineasio_fixed_bsize.clicked.connect(self.slot_tweaksSettingsChanged_wineasio)
  943. self.cb_wineasio_bsizes.currentIndexChanged[int].connect(self.slot_tweaksSettingsChanged_wineasio)
  944. # org.jackaudio.JackControl
  945. self.DBusJackServerStartedCallback.connect(self.slot_DBusJackServerStartedCallback)
  946. self.DBusJackServerStoppedCallback.connect(self.slot_DBusJackServerStoppedCallback)
  947. # org.jackaudio.JackPatchbay
  948. self.DBusJackClientAppearedCallback.connect(self.slot_DBusJackClientAppearedCallback)
  949. self.DBusJackClientDisappearedCallback.connect(self.slot_DBusJackClientDisappearedCallback)
  950. # org.gna.home.a2jmidid.control
  951. self.DBusA2JBridgeStartedCallback.connect(self.slot_DBusA2JBridgeStartedCallback)
  952. self.DBusA2JBridgeStoppedCallback.connect(self.slot_DBusA2JBridgeStoppedCallback)
  953. self.cb_a2j_autoexport.stateChanged[int].connect(self.slot_A2JBridgeExportHW)
  954. # -------------------------------------------------------------
  955. self.m_last_dsp_load = None
  956. self.m_last_xruns = None
  957. self.m_last_buffer_size = None
  958. self.m_timer500 = None
  959. self.m_timer2000 = self.startTimer(2000)
  960. self.DBusReconnect()
  961. if haveDBus:
  962. gDBus.bus.add_signal_receiver(self.DBusSignalReceiver, destination_keyword='dest', path_keyword='path',
  963. member_keyword='member', interface_keyword='interface', sender_keyword='sender', )
  964. def DBusReconnect(self):
  965. if haveDBus:
  966. try:
  967. gDBus.jack = gDBus.bus.get_object("org.jackaudio.service", "/org/jackaudio/Controller")
  968. gDBus.patchbay = dbus.Interface(gDBus.jack, "org.jackaudio.JackPatchbay")
  969. jacksettings.initBus(gDBus.bus)
  970. except:
  971. gDBus.jack = None
  972. gDBus.patchbay = None
  973. try:
  974. gDBus.a2j = dbus.Interface(gDBus.bus.get_object("org.gna.home.a2jmidid", "/"), "org.gna.home.a2jmidid.control")
  975. except:
  976. gDBus.a2j = None
  977. if gDBus.jack:
  978. if gDBus.jack.IsStarted():
  979. # Check for pulseaudio in jack graph
  980. try:
  981. version, groups, conns = gDBus.patchbay.GetGraph(0)
  982. except:
  983. version, groups, conns = (list(), list(), list())
  984. for group_id, group_name, ports in groups:
  985. if group_name == "alsa2jack":
  986. global jackClientIdALSA
  987. jackClientIdALSA = group_id
  988. elif group_name == "PulseAudio JACK Sink":
  989. global jackClientIdPulse
  990. jackClientIdPulse = group_id
  991. self.jackStarted()
  992. else:
  993. self.jackStopped()
  994. self.label_jack_realtime.setText("Yes" if jacksettings.isRealtime() else "No")
  995. else:
  996. self.jackStopped()
  997. self.label_jack_status.setText("Unavailable")
  998. self.label_jack_status_ico.setPixmap(self.pix_error)
  999. self.label_jack_realtime.setText("Unknown")
  1000. self.label_jack_realtime_ico.setPixmap(self.pix_error)
  1001. self.groupBox_jack.setEnabled(False)
  1002. self.groupBox_jack.setTitle("-- jackdbus is not available --")
  1003. self.b_jack_start.setEnabled(False)
  1004. self.b_jack_stop.setEnabled(False)
  1005. self.b_jack_restart.setEnabled(False)
  1006. self.b_jack_configure.setEnabled(False)
  1007. self.b_jack_switchmaster.setEnabled(False)
  1008. self.groupBox_bridges.setEnabled(False)
  1009. if gDBus.a2j:
  1010. try:
  1011. started = gDBus.a2j.is_started()
  1012. except:
  1013. started = False
  1014. if started:
  1015. self.a2jStarted()
  1016. else:
  1017. self.a2jStopped()
  1018. else:
  1019. self.toolBox_alsamidi.setEnabled(False)
  1020. self.cb_a2j_autostart.setChecked(False)
  1021. self.cb_a2j_autoexport.setChecked(False)
  1022. self.label_bridge_a2j.setText("ALSA MIDI Bridge is not installed")
  1023. self.settings.setValue("A2J/AutoStart", False)
  1024. self.updateSystrayTooltip()
  1025. def DBusSignalReceiver(self, *args, **kwds):
  1026. if kwds['interface'] == "org.freedesktop.DBus" and kwds['path'] == "/org/freedesktop/DBus" and kwds['member'] == "NameOwnerChanged":
  1027. appInterface, appId, newId = args
  1028. if not newId:
  1029. # Something crashed
  1030. if appInterface == "org.jackaudio.service":
  1031. QTimer.singleShot(0, self.slot_handleCrash_jack)
  1032. elif appInterface == "org.gna.home.a2jmidid":
  1033. QTimer.singleShot(0, self.slot_handleCrash_a2j)
  1034. elif kwds['interface'] == "org.jackaudio.JackControl":
  1035. if DEBUG: print("org.jackaudio.JackControl", kwds['member'])
  1036. if kwds['member'] == "ServerStarted":
  1037. self.DBusJackServerStartedCallback.emit()
  1038. elif kwds['member'] == "ServerStopped":
  1039. self.DBusJackServerStoppedCallback.emit()
  1040. elif kwds['interface'] == "org.jackaudio.JackPatchbay":
  1041. if gDBus.patchbay and kwds['path'] == gDBus.patchbay.object_path:
  1042. if DEBUG: print("org.jackaudio.JackPatchbay,", kwds['member'])
  1043. if kwds['member'] == "ClientAppeared":
  1044. self.DBusJackClientAppearedCallback.emit(args[iJackClientId], args[iJackClientName])
  1045. elif kwds['member'] == "ClientDisappeared":
  1046. self.DBusJackClientDisappearedCallback.emit(args[iJackClientId])
  1047. elif kwds['interface'] == "org.gna.home.a2jmidid.control":
  1048. if DEBUG: print("org.gna.home.a2jmidid.control", kwds['member'])
  1049. if kwds['member'] == "bridge_started":
  1050. self.DBusA2JBridgeStartedCallback.emit()
  1051. elif kwds['member'] == "bridge_stopped":
  1052. self.DBusA2JBridgeStoppedCallback.emit()
  1053. def jackStarted(self):
  1054. self.m_last_dsp_load = gDBus.jack.GetLoad()
  1055. self.m_last_xruns = int(gDBus.jack.GetXruns())
  1056. self.m_last_buffer_size = gDBus.jack.GetBufferSize()
  1057. self.b_jack_start.setEnabled(False)
  1058. self.b_jack_stop.setEnabled(True)
  1059. self.b_jack_switchmaster.setEnabled(True)
  1060. self.systray.setActionEnabled("jack_start", False)
  1061. self.systray.setActionEnabled("jack_stop", True)
  1062. self.label_jack_status.setText("Started")
  1063. self.label_jack_status_ico.setPixmap(self.pix_apply)
  1064. if gDBus.jack.IsRealtime():
  1065. self.label_jack_realtime.setText("Yes")
  1066. self.label_jack_realtime_ico.setPixmap(self.pix_apply)
  1067. else:
  1068. self.label_jack_realtime.setText("No")
  1069. self.label_jack_realtime_ico.setPixmap(self.pix_cancel)
  1070. self.label_jack_dsp.setText("%.2f%%" % self.m_last_dsp_load)
  1071. self.label_jack_xruns.setText(str(self.m_last_xruns))
  1072. self.label_jack_bfsize.setText("%i samples" % self.m_last_buffer_size)
  1073. self.label_jack_srate.setText("%i Hz" % gDBus.jack.GetSampleRate())
  1074. self.label_jack_latency.setText("%.1f ms" % gDBus.jack.GetLatency())
  1075. self.m_timer500 = self.startTimer(500)
  1076. if gDBus.a2j and not gDBus.a2j.is_started():
  1077. portsExported = bool(gDBus.a2j.get_hw_export())
  1078. if GlobalSettings.value("A2J/AutoStart", True, type=bool):
  1079. if not portsExported and GlobalSettings.value("A2J/AutoExport", True, type=bool):
  1080. gDBus.a2j.set_hw_export(True)
  1081. portsExported = True
  1082. gDBus.a2j.start()
  1083. else:
  1084. self.b_a2j_start.setEnabled(True)
  1085. self.systray.setActionEnabled("a2j_start", True)
  1086. self.checkAlsaAudio()
  1087. self.checkPulseAudio()
  1088. def jackStopped(self):
  1089. if self.m_timer500:
  1090. self.killTimer(self.m_timer500)
  1091. self.m_timer500 = None
  1092. self.m_last_dsp_load = None
  1093. self.m_last_xruns = None
  1094. self.m_last_buffer_size = None
  1095. self.b_jack_start.setEnabled(True)
  1096. self.b_jack_stop.setEnabled(False)
  1097. self.b_jack_switchmaster.setEnabled(False)
  1098. if haveDBus:
  1099. self.systray.setActionEnabled("jack_start", True)
  1100. self.systray.setActionEnabled("jack_stop", False)
  1101. self.label_jack_status.setText("Stopped")
  1102. self.label_jack_status_ico.setPixmap(self.pix_cancel)
  1103. self.label_jack_dsp.setText("---")
  1104. self.label_jack_xruns.setText("---")
  1105. self.label_jack_bfsize.setText("---")
  1106. self.label_jack_srate.setText("---")
  1107. self.label_jack_latency.setText("---")
  1108. if gDBus.a2j:
  1109. self.b_a2j_start.setEnabled(False)
  1110. self.systray.setActionEnabled("a2j_start", False)
  1111. global jackClientIdALSA, jackClientIdPulse
  1112. jackClientIdALSA = -1
  1113. jackClientIdPulse = -1
  1114. if haveDBus:
  1115. self.checkAlsaAudio()
  1116. self.checkPulseAudio()
  1117. def a2jStarted(self):
  1118. self.b_a2j_start.setEnabled(False)
  1119. self.b_a2j_stop.setEnabled(True)
  1120. self.systray.setActionEnabled("a2j_start", False)
  1121. self.systray.setActionEnabled("a2j_stop", True)
  1122. if bool(gDBus.a2j.get_hw_export()):
  1123. self.label_bridge_a2j.setText(self.tr("ALSA MIDI Bridge is running, ports are exported"))
  1124. else :
  1125. self.label_bridge_a2j.setText(self.tr("ALSA MIDI Bridge is running"))
  1126. def a2jStopped(self):
  1127. jackRunning = bool(gDBus.jack and gDBus.jack.IsStarted())
  1128. self.b_a2j_start.setEnabled(jackRunning)
  1129. self.b_a2j_stop.setEnabled(False)
  1130. self.systray.setActionEnabled("a2j_start", jackRunning)
  1131. self.systray.setActionEnabled("a2j_stop", False)
  1132. self.label_bridge_a2j.setText(self.tr("ALSA MIDI Bridge is stopped"))
  1133. def checkAlsaAudio(self):
  1134. asoundrcFile = os.path.join(HOME, ".asoundrc")
  1135. if not os.path.exists(asoundrcFile):
  1136. self.b_alsa_start.setEnabled(False)
  1137. self.b_alsa_stop.setEnabled(False)
  1138. self.cb_alsa_type.setCurrentIndex(iAlsaFileNone)
  1139. self.tb_alsa_options.setEnabled(False)
  1140. self.label_bridge_alsa.setText(self.tr("No bridge in use"))
  1141. self.m_lastAlsaIndexType = -1 # null
  1142. return
  1143. asoundrcFd = open(asoundrcFile, "r")
  1144. asoundrcRead = asoundrcFd.read().strip()
  1145. asoundrcFd.close()
  1146. if asoundrcRead.startswith(asoundrc_aloop_check):
  1147. if isAlsaAudioBridged():
  1148. self.b_alsa_start.setEnabled(False)
  1149. self.b_alsa_stop.setEnabled(True)
  1150. self.systray.setActionEnabled("alsa_start", False)
  1151. self.systray.setActionEnabled("alsa_stop", True)
  1152. self.label_bridge_alsa.setText(self.tr("Using Cadence snd-aloop daemon, started"))
  1153. else:
  1154. try:
  1155. jackRunning = bool(gDBus.jack and gDBus.jack.IsStarted())
  1156. except:
  1157. jackRunning = False
  1158. self.b_alsa_start.setEnabled(jackRunning)
  1159. self.b_alsa_stop.setEnabled(False)
  1160. self.systray.setActionEnabled("alsa_start", jackRunning)
  1161. self.systray.setActionEnabled("alsa_stop", False)
  1162. self.label_bridge_alsa.setText(self.tr("Using Cadence snd-aloop daemon, stopped"))
  1163. self.cb_alsa_type.setCurrentIndex(iAlsaFileLoop)
  1164. self.tb_alsa_options.setEnabled(True)
  1165. elif asoundrcRead == asoundrc_jack:
  1166. self.b_alsa_start.setEnabled(False)
  1167. self.b_alsa_stop.setEnabled(False)
  1168. self.systray.setActionEnabled("alsa_start", False)
  1169. self.systray.setActionEnabled("alsa_stop", False)
  1170. self.cb_alsa_type.setCurrentIndex(iAlsaFileJACK)
  1171. self.tb_alsa_options.setEnabled(False)
  1172. self.label_bridge_alsa.setText(self.tr("Using JACK plugin bridge (Always on)"))
  1173. elif asoundrcRead == asoundrc_pulse:
  1174. self.b_alsa_start.setEnabled(False)
  1175. self.b_alsa_stop.setEnabled(False)
  1176. self.systray.setActionEnabled("alsa_start", False)
  1177. self.systray.setActionEnabled("alsa_stop", False)
  1178. self.cb_alsa_type.setCurrentIndex(iAlsaFilePulse)
  1179. self.tb_alsa_options.setEnabled(False)
  1180. self.label_bridge_alsa.setText(self.tr("Using PulseAudio plugin bridge (Always on)"))
  1181. else:
  1182. self.b_alsa_start.setEnabled(False)
  1183. self.b_alsa_stop.setEnabled(False)
  1184. self.systray.setActionEnabled("alsa_start", False)
  1185. self.systray.setActionEnabled("alsa_stop", False)
  1186. self.cb_alsa_type.addItem(self.tr("Custom"))
  1187. self.cb_alsa_type.setCurrentIndex(iAlsaFileMax)
  1188. self.tb_alsa_options.setEnabled(True)
  1189. self.label_bridge_alsa.setText(self.tr("Using custom asoundrc, not managed by Cadence"))
  1190. self.m_lastAlsaIndexType = self.cb_alsa_type.currentIndex()
  1191. def checkPulseAudio(self):
  1192. if not havePulseAudio:
  1193. self.systray.setActionEnabled("pulse_start", False)
  1194. self.systray.setActionEnabled("pulse_stop", False)
  1195. return
  1196. if isPulseAudioStarted():
  1197. if isPulseAudioBridged():
  1198. self.b_pulse_start.setEnabled(False)
  1199. self.b_pulse_stop.setEnabled(True)
  1200. self.systray.setActionEnabled("pulse_start", False)
  1201. self.systray.setActionEnabled("pulse_stop", True)
  1202. self.label_bridge_pulse.setText(self.tr("PulseAudio is started and bridged to JACK"))
  1203. else:
  1204. jackRunning = bool(gDBus.jack and gDBus.jack.IsStarted())
  1205. self.b_pulse_start.setEnabled(jackRunning)
  1206. self.b_pulse_stop.setEnabled(False)
  1207. self.systray.setActionEnabled("pulse_start", jackRunning)
  1208. self.systray.setActionEnabled("pulse_stop", False)
  1209. self.label_bridge_pulse.setText(self.tr("PulseAudio is started but not bridged"))
  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 not started"))
  1217. def setAppDetails(self, desktop):
  1218. appContents = getDesktopFileContents(desktop)
  1219. name = getXdgProperty(appContents, "Name")
  1220. icon = getXdgProperty(appContents, "Icon")
  1221. comment = getXdgProperty(appContents, "Comment")
  1222. if not name:
  1223. name = self.cb_app_image.currentText().replace(".desktop","").title()
  1224. if not icon:
  1225. icon = ""
  1226. if not comment:
  1227. comment = ""
  1228. self.ico_app.setPixmap(getIcon(icon, 48).pixmap(48, 48))
  1229. self.label_app_name.setText(name)
  1230. self.label_app_comment.setText(comment)
  1231. def updateSystrayTooltip(self):
  1232. systrayText = "Cadence<br/>"
  1233. systrayText += "<font size=\"-1\">"
  1234. systrayText += "<b>%s:</b>&nbsp;%s<br/>" % (self.tr("JACK Status"), self.label_jack_status.text())
  1235. systrayText += "<b>%s:</b>&nbsp;%s<br/>" % (self.tr("Realtime"), self.label_jack_realtime.text())
  1236. systrayText += "<b>%s:</b>&nbsp;%s<br/>" % (self.tr("DSP Load"), self.label_jack_dsp.text())
  1237. systrayText += "<b>%s:</b>&nbsp;%s<br/>" % (self.tr("Xruns"), self.label_jack_xruns.text())
  1238. systrayText += "<b>%s:</b>&nbsp;%s<br/>" % (self.tr("Buffer Size"), self.label_jack_bfsize.text())
  1239. systrayText += "<b>%s:</b>&nbsp;%s<br/>" % (self.tr("Sample Rate"), self.label_jack_srate.text())
  1240. systrayText += "<b>%s:</b>&nbsp;%s" % (self.tr("Block Latency"), self.label_jack_latency.text())
  1241. systrayText += "</font><font size=\"-2\"><br/></font>"
  1242. self.systray.setToolTip(systrayText)
  1243. @pyqtSlot()
  1244. def func_start_catarina(self):
  1245. self.func_start_tool("catarina")
  1246. @pyqtSlot()
  1247. def func_start_catia(self):
  1248. self.func_start_tool("catia")
  1249. @pyqtSlot()
  1250. def func_start_claudia(self):
  1251. self.func_start_tool("claudia")
  1252. @pyqtSlot()
  1253. def func_start_logs(self):
  1254. self.func_start_tool("cadence-logs")
  1255. @pyqtSlot()
  1256. def func_start_jackmeter(self):
  1257. self.func_start_tool("cadence-jackmeter")
  1258. @pyqtSlot()
  1259. def func_start_jackmeter_in(self):
  1260. self.func_start_tool("cadence-jackmeter -in")
  1261. @pyqtSlot()
  1262. def func_start_render(self):
  1263. self.func_start_tool("cadence-render")
  1264. @pyqtSlot()
  1265. def func_start_xycontroller(self):
  1266. self.func_start_tool("cadence-xycontroller")
  1267. def func_start_tool(self, tool):
  1268. if sys.argv[0].endswith(".py"):
  1269. if tool == "cadence-logs":
  1270. tool = "logs"
  1271. elif tool == "cadence-render":
  1272. tool = "render"
  1273. stool = tool.split(" ", 1)[0]
  1274. if stool in ("cadence-jackmeter", "cadence-xycontroller"):
  1275. python = ""
  1276. localPath = os.path.join(sys.path[0], "..", "c++", stool.replace("cadence-", ""))
  1277. if os.path.exists(os.path.join(localPath, stool)):
  1278. base = localPath + os.sep
  1279. else:
  1280. base = ""
  1281. else:
  1282. python = sys.executable
  1283. tool += ".py"
  1284. base = sys.argv[0].rsplit("cadence.py", 1)[0]
  1285. if python:
  1286. python += " "
  1287. cmd = "%s%s%s &" % (python, base, tool)
  1288. print(cmd)
  1289. os.system(cmd)
  1290. elif sys.argv[0].endswith("/cadence"):
  1291. base = sys.argv[0].rsplit("/cadence", 1)[0]
  1292. os.system("%s/%s &" % (base, tool))
  1293. else:
  1294. os.system("%s &" % tool)
  1295. def func_settings_changed(self, stype):
  1296. if stype not in self.settings_changed_types:
  1297. self.settings_changed_types.append(stype)
  1298. self.frame_tweaks_settings.setVisible(True)
  1299. @pyqtSlot()
  1300. def slot_DBusJackServerStartedCallback(self):
  1301. self.jackStarted()
  1302. @pyqtSlot()
  1303. def slot_DBusJackServerStoppedCallback(self):
  1304. self.jackStopped()
  1305. @pyqtSlot(int, str)
  1306. def slot_DBusJackClientAppearedCallback(self, group_id, group_name):
  1307. if group_name == "alsa2jack":
  1308. global jackClientIdALSA
  1309. jackClientIdALSA = group_id
  1310. self.checkAlsaAudio()
  1311. elif group_name == "PulseAudio JACK Sink":
  1312. global jackClientIdPulse
  1313. jackClientIdPulse = group_id
  1314. self.checkPulseAudio()
  1315. @pyqtSlot(int)
  1316. def slot_DBusJackClientDisappearedCallback(self, group_id):
  1317. global jackClientIdALSA, jackClientIdPulse
  1318. if group_id == jackClientIdALSA:
  1319. jackClientIdALSA = -1
  1320. self.checkAlsaAudio()
  1321. elif group_id == jackClientIdPulse:
  1322. jackClientIdPulse = -1
  1323. self.checkPulseAudio()
  1324. @pyqtSlot()
  1325. def slot_DBusA2JBridgeStartedCallback(self):
  1326. self.a2jStarted()
  1327. @pyqtSlot()
  1328. def slot_DBusA2JBridgeStoppedCallback(self):
  1329. self.a2jStopped()
  1330. @pyqtSlot()
  1331. def slot_JackServerStart(self):
  1332. self.saveSettings()
  1333. try:
  1334. gDBus.jack.StartServer()
  1335. except:
  1336. QMessageBox.warning(self, self.tr("Warning"), self.tr("Failed to start JACK, please check the logs for more information."))
  1337. @pyqtSlot()
  1338. def slot_JackServerStop(self):
  1339. if gDBus.a2j and bool(gDBus.a2j.is_started()):
  1340. gDBus.a2j.stop()
  1341. try:
  1342. gDBus.jack.StopServer()
  1343. except:
  1344. QMessageBox.warning(self, self.tr("Warning"), self.tr("Failed to stop JACK, please check the logs for more information."))
  1345. @pyqtSlot()
  1346. def slot_JackServerForceRestart(self):
  1347. if gDBus.jack.IsStarted():
  1348. ask = CustomMessageBox(self, QMessageBox.Warning, self.tr("Warning"),
  1349. self.tr("This will force kill all JACK applications!<br>Make sure to save your projects before continue."),
  1350. self.tr("Are you sure you want to force the restart of JACK?"))
  1351. if ask != QMessageBox.Yes:
  1352. return
  1353. if self.m_timer500:
  1354. self.killTimer(self.m_timer500)
  1355. self.m_timer500 = None
  1356. self.saveSettings()
  1357. ForceWaitDialog(self).exec_()
  1358. @pyqtSlot()
  1359. def slot_JackServerConfigure(self):
  1360. jacksettingsW = jacksettings.JackSettingsW(self)
  1361. jacksettingsW.exec_()
  1362. del jacksettingsW
  1363. @pyqtSlot()
  1364. def slot_JackServerSwitchMaster(self):
  1365. try:
  1366. gDBus.jack.SwitchMaster()
  1367. except:
  1368. QMessageBox.warning(self, self.tr("Warning"), self.tr("Failed to switch JACK master, please check the logs for more information."))
  1369. return
  1370. self.jackStarted()
  1371. @pyqtSlot()
  1372. def slot_JackOptions(self):
  1373. ToolBarJackDialog(self).exec_()
  1374. @pyqtSlot()
  1375. def slot_JackClearXruns(self):
  1376. if gDBus.jack:
  1377. gDBus.jack.ResetXruns()
  1378. @pyqtSlot()
  1379. def slot_AlsaBridgeStart(self):
  1380. self.slot_AlsaBridgeStop()
  1381. startAlsaAudioLoopBridge()
  1382. @pyqtSlot()
  1383. def slot_AlsaBridgeStop(self):
  1384. checkFile = "/tmp/.cadence-aloop-daemon.x"
  1385. if os.path.exists(checkFile):
  1386. os.remove(checkFile)
  1387. @pyqtSlot(int)
  1388. def slot_AlsaBridgeChanged(self, index):
  1389. if self.m_lastAlsaIndexType == -2 or self.m_lastAlsaIndexType == index:
  1390. return
  1391. if self.m_lastAlsaIndexType == iAlsaFileMax:
  1392. ask = CustomMessageBox(self, QMessageBox.Warning, self.tr("Warning"),
  1393. self.tr(""
  1394. "You're using a custom ~/.asoundrc file not managed by Cadence.<br/>"
  1395. "By choosing to use a Cadence ALSA-Audio bridge, <b>the file will be replaced</b>."
  1396. ""),
  1397. self.tr("Are you sure you want to do this?"))
  1398. if ask == QMessageBox.Yes:
  1399. self.cb_alsa_type.blockSignals(True)
  1400. self.cb_alsa_type.removeItem(iAlsaFileMax)
  1401. self.cb_alsa_type.setCurrentIndex(index)
  1402. self.cb_alsa_type.blockSignals(False)
  1403. else:
  1404. self.cb_alsa_type.blockSignals(True)
  1405. self.cb_alsa_type.setCurrentIndex(iAlsaFileMax)
  1406. self.cb_alsa_type.blockSignals(False)
  1407. return
  1408. asoundrcFile = os.path.join(HOME, ".asoundrc")
  1409. if index == iAlsaFileNone:
  1410. os.remove(asoundrcFile)
  1411. elif index == iAlsaFileLoop:
  1412. asoundrcFd = open(asoundrcFile, "w")
  1413. asoundrcFd.write(asoundrc_aloop+"\n")
  1414. asoundrcFd.close()
  1415. elif index == iAlsaFileJACK:
  1416. asoundrcFd = open(asoundrcFile, "w")
  1417. asoundrcFd.write(asoundrc_jack+"\n")
  1418. asoundrcFd.close()
  1419. elif index == iAlsaFilePulse:
  1420. asoundrcFd = open(asoundrcFile, "w")
  1421. asoundrcFd.write(asoundrc_pulse+"\n")
  1422. asoundrcFd.close()
  1423. else:
  1424. print("Cadence::AlsaBridgeChanged(%i) - invalid index" % index)
  1425. self.checkAlsaAudio()
  1426. @pyqtSlot()
  1427. def slot_AlsaAudioBridgeOptions(self):
  1428. ToolBarAlsaAudioDialog(self, (self.cb_alsa_type.currentIndex() != iAlsaFileLoop)).exec_()
  1429. @pyqtSlot()
  1430. def slot_A2JBridgeStart(self):
  1431. gDBus.a2j.start()
  1432. @pyqtSlot()
  1433. def slot_A2JBridgeStop(self):
  1434. gDBus.a2j.stop()
  1435. @pyqtSlot(int)
  1436. def slot_A2JBridgeExportHW(self, state):
  1437. a2jWasStarted = bool(gDBus.a2j.is_started())
  1438. if a2jWasStarted:
  1439. gDBus.a2j.stop()
  1440. gDBus.a2j.set_hw_export(bool(state))
  1441. if a2jWasStarted:
  1442. gDBus.a2j.start()
  1443. @pyqtSlot()
  1444. def slot_PulseAudioBridgeStart(self):
  1445. if GlobalSettings.value("Pulse2JACK/PlaybackModeOnly", False, type=bool):
  1446. os.system("cadence-pulse2jack -p")
  1447. else:
  1448. os.system("cadence-pulse2jack")
  1449. @pyqtSlot()
  1450. def slot_PulseAudioBridgeStop(self):
  1451. os.system("pulseaudio -k")
  1452. @pyqtSlot()
  1453. def slot_PulseAudioBridgeOptions(self):
  1454. ToolBarPADialog(self).exec_()
  1455. @pyqtSlot()
  1456. def slot_handleCrash_jack(self):
  1457. self.DBusReconnect()
  1458. @pyqtSlot()
  1459. def slot_handleCrash_a2j(self):
  1460. pass
  1461. @pyqtSlot(str)
  1462. def slot_changeGovernorMode(self, newMode):
  1463. bus = dbus.SystemBus(mainloop=gDBus.loop)
  1464. #proxy = bus.get_object("org.cadence.CpufreqSelector", "/Selector", introspect=False)
  1465. #print(proxy.hello())
  1466. proxy = bus.get_object("com.ubuntu.IndicatorCpufreqSelector", "/Selector", introspect=False)
  1467. proxy.SetGovernor(self.m_curGovCPUs, newMode, dbus_interface="com.ubuntu.IndicatorCpufreqSelector")
  1468. @pyqtSlot()
  1469. def slot_governorFileChanged(self):
  1470. curGovFd = open(self.m_curGovPath, "r")
  1471. curGovRead = curGovFd.read().strip()
  1472. curGovFd.close()
  1473. customTr = self.tr("Custom")
  1474. if self.cb_cpufreq.currentIndex() == -1:
  1475. # First init
  1476. self.cb_cpufreq.currentIndexChanged[str].connect(self.slot_changeGovernorMode)
  1477. self.cb_cpufreq.blockSignals(True)
  1478. if curGovRead in self.m_availGovList:
  1479. self.cb_cpufreq.setCurrentIndex(self.m_availGovList.index(curGovRead))
  1480. if customTr in self.m_availGovList:
  1481. self.m_availGovList.remove(customTr)
  1482. else:
  1483. if customTr not in self.m_availGovList:
  1484. self.cb_cpufreq.addItem(customTr)
  1485. self.m_availGovList.append(customTr)
  1486. self.cb_cpufreq.setCurrentIndex(len(self.m_availGovList)-1)
  1487. self.cb_cpufreq.blockSignals(False)
  1488. @pyqtSlot()
  1489. def slot_tweaksApply(self):
  1490. if "plugins" in self.settings_changed_types:
  1491. EXTRA_LADSPA_DIRS = []
  1492. EXTRA_DSSI_DIRS = []
  1493. EXTRA_LV2_DIRS = []
  1494. EXTRA_VST_DIRS = []
  1495. for i in range(self.list_LADSPA.count()):
  1496. iPath = self.list_LADSPA.item(i).text()
  1497. if iPath not in DEFAULT_LADSPA_PATH and iPath not in EXTRA_LADSPA_DIRS:
  1498. EXTRA_LADSPA_DIRS.append(iPath)
  1499. for i in range(self.list_DSSI.count()):
  1500. iPath = self.list_DSSI.item(i).text()
  1501. if iPath not in DEFAULT_DSSI_PATH and iPath not in EXTRA_DSSI_DIRS:
  1502. EXTRA_DSSI_DIRS.append(iPath)
  1503. for i in range(self.list_LV2.count()):
  1504. iPath = self.list_LV2.item(i).text()
  1505. if iPath not in DEFAULT_LV2_PATH and iPath not in EXTRA_LV2_DIRS:
  1506. EXTRA_LV2_DIRS.append(iPath)
  1507. for i in range(self.list_VST.count()):
  1508. iPath = self.list_VST.item(i).text()
  1509. if iPath not in DEFAULT_VST_PATH and iPath not in EXTRA_VST_DIRS:
  1510. EXTRA_VST_DIRS.append(iPath)
  1511. GlobalSettings.setValue("AudioPlugins/EXTRA_LADSPA_PATH", ":".join(EXTRA_LADSPA_DIRS))
  1512. GlobalSettings.setValue("AudioPlugins/EXTRA_DSSI_PATH", ":".join(EXTRA_DSSI_DIRS))
  1513. GlobalSettings.setValue("AudioPlugins/EXTRA_LV2_PATH", ":".join(EXTRA_LV2_DIRS))
  1514. GlobalSettings.setValue("AudioPlugins/EXTRA_VST_PATH", ":".join(EXTRA_VST_DIRS))
  1515. if "apps" in self.settings_changed_types:
  1516. mimeFileContent = ""
  1517. # Fix common mime errors
  1518. mimeFileContent += "application/x-designer=designer-qt4.desktop;\n"
  1519. mimeFileContent += "application/x-ms-dos-executable=wine.desktop;\n"
  1520. mimeFileContent += "audio/x-minipsf=audacious.desktop;\n"
  1521. mimeFileContent += "audio/x-psf=audacious.desktop;\n"
  1522. if self.ch_app_image.isChecked():
  1523. imageApp = self.cb_app_image.currentText().replace("/","-")
  1524. mimeFileContent += "image/bmp=%s;\n" % imageApp
  1525. mimeFileContent += "image/gif=%s;\n" % imageApp
  1526. mimeFileContent += "image/jp2=%s;\n" % imageApp
  1527. mimeFileContent += "image/jpeg=%s;\n" % imageApp
  1528. mimeFileContent += "image/png=%s;\n" % imageApp
  1529. mimeFileContent += "image/svg+xml=%s;\n" % imageApp
  1530. mimeFileContent += "image/svg+xml-compressed=%s;\n" % imageApp
  1531. mimeFileContent += "image/tiff=%s;\n" % imageApp
  1532. mimeFileContent += "image/x-canon-cr2=%s;\n" % imageApp
  1533. mimeFileContent += "image/x-canon-crw=%s;\n" % imageApp
  1534. mimeFileContent += "image/x-eps=%s;\n" % imageApp
  1535. mimeFileContent += "image/x-kodak-dcr=%s;\n" % imageApp
  1536. mimeFileContent += "image/x-kodak-k25=%s;\n" % imageApp
  1537. mimeFileContent += "image/x-kodak-kdc=%s;\n" % imageApp
  1538. mimeFileContent += "image/x-nikon-nef=%s;\n" % imageApp
  1539. mimeFileContent += "image/x-olympus-orf=%s;\n" % imageApp
  1540. mimeFileContent += "image/x-panasonic-raw=%s;\n" % imageApp
  1541. mimeFileContent += "image/x-pcx=%s;\n" % imageApp
  1542. mimeFileContent += "image/x-pentax-pef=%s;\n" % imageApp
  1543. mimeFileContent += "image/x-portable-anymap=%s;\n" % imageApp
  1544. mimeFileContent += "image/x-portable-bitmap=%s;\n" % imageApp
  1545. mimeFileContent += "image/x-portable-graymap=%s;\n" % imageApp
  1546. mimeFileContent += "image/x-portable-pixmap=%s;\n" % imageApp
  1547. mimeFileContent += "image/x-sony-arw=%s;\n" % imageApp
  1548. mimeFileContent += "image/x-sony-sr2=%s;\n" % imageApp
  1549. mimeFileContent += "image/x-sony-srf=%s;\n" % imageApp
  1550. mimeFileContent += "image/x-tga=%s;\n" % imageApp
  1551. mimeFileContent += "image/x-xbitmap=%s;\n" % imageApp
  1552. mimeFileContent += "image/x-xpixmap=%s;\n" % imageApp
  1553. if self.ch_app_music.isChecked():
  1554. musicApp = self.cb_app_music.currentText().replace("/","-")
  1555. mimeFileContent += "application/vnd.apple.mpegurl=%s;\n" % musicApp
  1556. mimeFileContent += "application/xspf+xml=%s;\n" % musicApp
  1557. mimeFileContent += "application/x-smaf=%s;\n" % musicApp
  1558. mimeFileContent += "audio/AMR=%s;\n" % musicApp
  1559. mimeFileContent += "audio/AMR-WB=%s;\n" % musicApp
  1560. mimeFileContent += "audio/aac=%s;\n" % musicApp
  1561. mimeFileContent += "audio/ac3=%s;\n" % musicApp
  1562. mimeFileContent += "audio/basic=%s;\n" % musicApp
  1563. mimeFileContent += "audio/flac=%s;\n" % musicApp
  1564. mimeFileContent += "audio/m3u=%s;\n" % musicApp
  1565. mimeFileContent += "audio/mp2=%s;\n" % musicApp
  1566. mimeFileContent += "audio/mp4=%s;\n" % musicApp
  1567. mimeFileContent += "audio/mpeg=%s;\n" % musicApp
  1568. mimeFileContent += "audio/ogg=%s;\n" % musicApp
  1569. mimeFileContent += "audio/vnd.rn-realaudio=%s;\n" % musicApp
  1570. mimeFileContent += "audio/vorbis=%s;\n" % musicApp
  1571. mimeFileContent += "audio/webm=%s;\n" % musicApp
  1572. mimeFileContent += "audio/wav=%s;\n" % musicApp
  1573. mimeFileContent += "audio/x-adpcm=%s;\n" % musicApp
  1574. mimeFileContent += "audio/x-aifc=%s;\n" % musicApp
  1575. mimeFileContent += "audio/x-aiff=%s;\n" % musicApp
  1576. mimeFileContent += "audio/x-aiffc=%s;\n" % musicApp
  1577. mimeFileContent += "audio/x-ape=%s;\n" % musicApp
  1578. mimeFileContent += "audio/x-cda=%s;\n" % musicApp
  1579. mimeFileContent += "audio/x-flac=%s;\n" % musicApp
  1580. mimeFileContent += "audio/x-flac+ogg=%s;\n" % musicApp
  1581. mimeFileContent += "audio/x-gsm=%s;\n" % musicApp
  1582. mimeFileContent += "audio/x-m4b=%s;\n" % musicApp
  1583. mimeFileContent += "audio/x-matroska=%s;\n" % musicApp
  1584. mimeFileContent += "audio/x-mp2=%s;\n" % musicApp
  1585. mimeFileContent += "audio/x-mpegurl=%s;\n" % musicApp
  1586. mimeFileContent += "audio/x-ms-asx=%s;\n" % musicApp
  1587. mimeFileContent += "audio/x-ms-wma=%s;\n" % musicApp
  1588. mimeFileContent += "audio/x-musepack=%s;\n" % musicApp
  1589. mimeFileContent += "audio/x-ogg=%s;\n" % musicApp
  1590. mimeFileContent += "audio/x-oggflac=%s;\n" % musicApp
  1591. mimeFileContent += "audio/x-pn-realaudio-plugin=%s;\n" % musicApp
  1592. mimeFileContent += "audio/x-riff=%s;\n" % musicApp
  1593. mimeFileContent += "audio/x-scpls=%s;\n" % musicApp
  1594. mimeFileContent += "audio/x-speex=%s;\n" % musicApp
  1595. mimeFileContent += "audio/x-speex+ogg=%s;\n" % musicApp
  1596. mimeFileContent += "audio/x-tta=%s;\n" % musicApp
  1597. mimeFileContent += "audio/x-vorbis+ogg=%s;\n" % musicApp
  1598. mimeFileContent += "audio/x-wav=%s;\n" % musicApp
  1599. mimeFileContent += "audio/x-wavpack=%s;\n" % musicApp
  1600. if self.ch_app_video.isChecked():
  1601. videoApp = self.cb_app_video.currentText().replace("/","-")
  1602. mimeFileContent +="application/mxf=%s;\n" % videoApp
  1603. mimeFileContent +="application/ogg=%s;\n" % videoApp
  1604. mimeFileContent +="application/ram=%s;\n" % videoApp
  1605. mimeFileContent +="application/vnd.ms-asf=%s;\n" % videoApp
  1606. mimeFileContent +="application/vnd.ms-wpl=%s;\n" % videoApp
  1607. mimeFileContent +="application/vnd.rn-realmedia=%s;\n" % videoApp
  1608. mimeFileContent +="application/x-ms-wmp=%s;\n" % videoApp
  1609. mimeFileContent +="application/x-ms-wms=%s;\n" % videoApp
  1610. mimeFileContent +="application/x-netshow-channel=%s;\n" % videoApp
  1611. mimeFileContent +="application/x-ogg=%s;\n" % videoApp
  1612. mimeFileContent +="application/x-quicktime-media-link=%s;\n" % videoApp
  1613. mimeFileContent +="video/3gpp=%s;\n" % videoApp
  1614. mimeFileContent +="video/3gpp2=%s;\n" % videoApp
  1615. mimeFileContent +="video/divx=%s;\n" % videoApp
  1616. mimeFileContent +="video/dv=%s;\n" % videoApp
  1617. mimeFileContent +="video/flv=%s;\n" % videoApp
  1618. mimeFileContent +="video/mp2t=%s;\n" % videoApp
  1619. mimeFileContent +="video/mp4=%s;\n" % videoApp
  1620. mimeFileContent +="video/mpeg=%s;\n" % videoApp
  1621. mimeFileContent +="video/ogg=%s;\n" % videoApp
  1622. mimeFileContent +="video/quicktime=%s;\n" % videoApp
  1623. mimeFileContent +="video/vivo=%s;\n" % videoApp
  1624. mimeFileContent +="video/vnd.rn-realvideo=%s;\n" % videoApp
  1625. mimeFileContent +="video/webm=%s;\n" % videoApp
  1626. mimeFileContent +="video/x-anim=%s;\n" % videoApp
  1627. mimeFileContent +="video/x-flic=%s;\n" % videoApp
  1628. mimeFileContent +="video/x-flv=%s;\n" % videoApp
  1629. mimeFileContent +="video/x-m4v=%s;\n" % videoApp
  1630. mimeFileContent +="video/x-matroska=%s;\n" % videoApp
  1631. mimeFileContent +="video/x-ms-asf=%s;\n" % videoApp
  1632. mimeFileContent +="video/x-ms-wm=%s;\n" % videoApp
  1633. mimeFileContent +="video/x-ms-wmp=%s;\n" % videoApp
  1634. mimeFileContent +="video/x-ms-wmv=%s;\n" % videoApp
  1635. mimeFileContent +="video/x-ms-wvx=%s;\n" % videoApp
  1636. mimeFileContent +="video/x-msvideo=%s;\n" % videoApp
  1637. mimeFileContent +="video/x-nsv=%s;\n" % videoApp
  1638. mimeFileContent +="video/x-ogg=%s;\n" % videoApp
  1639. mimeFileContent +="video/x-ogm=%s;\n" % videoApp
  1640. mimeFileContent +="video/x-ogm+ogg=%s;\n" % videoApp
  1641. mimeFileContent +="video/x-theora=%s;\n" % videoApp
  1642. mimeFileContent +="video/x-theora+ogg=%s;\n" % videoApp
  1643. mimeFileContent +="video/x-wmv=%s;\n" % videoApp
  1644. if self.ch_app_text.isChecked():
  1645. # TODO - more mimetypes
  1646. textApp = self.cb_app_text.currentText().replace("/","-")
  1647. mimeFileContent +="application/rdf+xml=%s;\n" % textApp
  1648. mimeFileContent +="application/xml=%s;\n" % textApp
  1649. mimeFileContent +="application/xml-dtd=%s;\n" % textApp
  1650. mimeFileContent +="application/xml-external-parsed-entity=%s;\n" % textApp
  1651. mimeFileContent +="application/xsd=%s;\n" % textApp
  1652. mimeFileContent +="application/xslt+xml=%s;\n" % textApp
  1653. mimeFileContent +="application/x-trash=%s;\n" % textApp
  1654. mimeFileContent +="application/x-wine-extension-inf=%s;\n" % textApp
  1655. mimeFileContent +="application/x-wine-extension-ini=%s;\n" % textApp
  1656. mimeFileContent +="application/x-zerosize=%s;\n" % textApp
  1657. mimeFileContent +="text/css=%s;\n" % textApp
  1658. mimeFileContent +="text/plain=%s;\n" % textApp
  1659. mimeFileContent +="text/x-authors=%s;\n" % textApp
  1660. mimeFileContent +="text/x-c++-hdr=%s;\n" % textApp
  1661. mimeFileContent +="text/x-c++-src=%s;\n" % textApp
  1662. mimeFileContent +="text/x-changelog=%s;\n" % textApp
  1663. mimeFileContent +="text/x-chdr=%s;\n" % textApp
  1664. mimeFileContent +="text/x-cmake=%s;\n" % textApp
  1665. mimeFileContent +="text/x-copying=%s;\n" % textApp
  1666. mimeFileContent +="text/x-credits=%s;\n" % textApp
  1667. mimeFileContent +="text/x-csharp=%s;\n" % textApp
  1668. mimeFileContent +="text/x-csrc=%s;\n" % textApp
  1669. mimeFileContent +="text/x-install=%s;\n" % textApp
  1670. mimeFileContent +="text/x-log=%s;\n" % textApp
  1671. mimeFileContent +="text/x-lua=%s;\n" % textApp
  1672. mimeFileContent +="text/x-makefile=%s;\n" % textApp
  1673. mimeFileContent +="text/x-ms-regedit=%s;\n" % textApp
  1674. mimeFileContent +="text/x-nfo=%s;\n" % textApp
  1675. mimeFileContent +="text/x-objchdr=%s;\n" % textApp
  1676. mimeFileContent +="text/x-objcsrc=%s;\n" % textApp
  1677. mimeFileContent +="text/x-pascal=%s;\n" % textApp
  1678. mimeFileContent +="text/x-patch=%s;\n" % textApp
  1679. mimeFileContent +="text/x-python=%s;\n" % textApp
  1680. mimeFileContent +="text/x-readme=%s;\n" % textApp
  1681. mimeFileContent +="text/x-vhdl=%s;\n" % textApp
  1682. if self.ch_app_browser.isChecked():
  1683. # TODO - needs something else for default browser
  1684. browserApp = self.cb_app_browser.currentText().replace("/","-")
  1685. mimeFileContent +="application/atom+xml=%s;\n" % browserApp
  1686. mimeFileContent +="application/rss+xml=%s;\n" % browserApp
  1687. mimeFileContent +="application/vnd.mozilla.xul+xml=%s;\n" % browserApp
  1688. mimeFileContent +="application/x-mozilla-bookmarks=%s;\n" % browserApp
  1689. mimeFileContent +="application/x-mswinurl=%s;\n" % browserApp
  1690. mimeFileContent +="application/x-xbel=%s;\n" % browserApp
  1691. mimeFileContent +="application/xhtml+xml=%s;\n" % browserApp
  1692. mimeFileContent +="text/html=%s;\n" % browserApp
  1693. mimeFileContent +="text/opml+xml=%s;\n" % browserApp
  1694. realMimeFileContent ="[Default Applications]\n"
  1695. realMimeFileContent += mimeFileContent
  1696. realMimeFileContent +="\n"
  1697. realMimeFileContent +="[Added Associations]\n"
  1698. realMimeFileContent += mimeFileContent
  1699. realMimeFileContent +="\n"
  1700. local_xdg_defaults = os.path.join(HOME, ".local", "share", "applications", "defaults.list")
  1701. local_xdg_mimeapps = os.path.join(HOME, ".local", "share", "applications", "mimeapps.list")
  1702. writeFile = open(local_xdg_defaults, "w")
  1703. writeFile.write(realMimeFileContent)
  1704. writeFile.close()
  1705. writeFile = open(local_xdg_mimeapps, "w")
  1706. writeFile.write(realMimeFileContent)
  1707. writeFile.close()
  1708. if "wineasio" in self.settings_changed_types:
  1709. REGFILE = 'REGEDIT4\n'
  1710. REGFILE += '\n'
  1711. REGFILE += '[HKEY_CURRENT_USER\Software\Wine\WineASIO]\n'
  1712. REGFILE += '"Autostart server"=dword:0000000%i\n' % int(1 if self.cb_wineasio_autostart.isChecked() else 0)
  1713. REGFILE += '"Connect to hardware"=dword:0000000%i\n' % int(1 if self.cb_wineasio_hw.isChecked() else 0)
  1714. REGFILE += '"Fixed buffersize"=dword:0000000%i\n' % int(1 if self.cb_wineasio_fixed_bsize.isChecked() else 0)
  1715. REGFILE += '"Number of inputs"=dword:000000%s\n' % smartHex(self.sb_wineasio_ins.value(), 2)
  1716. REGFILE += '"Number of outputs"=dword:000000%s\n' % smartHex(self.sb_wineasio_outs.value(), 2)
  1717. REGFILE += '"Preferred buffersize"=dword:0000%s\n' % smartHex(int(self.cb_wineasio_bsizes.currentText()), 4)
  1718. writeFile = open("/tmp/cadence-wineasio.reg", "w")
  1719. writeFile.write(REGFILE)
  1720. writeFile.close()
  1721. os.system("regedit /tmp/cadence-wineasio.reg")
  1722. self.settings_changed_types = []
  1723. self.frame_tweaks_settings.setVisible(False)
  1724. @pyqtSlot()
  1725. def slot_tweaksSettingsChanged_apps(self):
  1726. self.func_settings_changed("apps")
  1727. @pyqtSlot()
  1728. def slot_tweaksSettingsChanged_wineasio(self):
  1729. self.func_settings_changed("wineasio")
  1730. @pyqtSlot(int)
  1731. def slot_tweakAppImageHighlighted(self, index):
  1732. self.setAppDetails(self.cb_app_image.itemText(index))
  1733. @pyqtSlot(int)
  1734. def slot_tweakAppImageChanged(self, ignored):
  1735. self.setAppDetails(self.cb_app_image.currentText())
  1736. self.func_settings_changed("apps")
  1737. @pyqtSlot(int)
  1738. def slot_tweakAppMusicHighlighted(self, index):
  1739. self.setAppDetails(self.cb_app_music.itemText(index))
  1740. @pyqtSlot(int)
  1741. def slot_tweakAppMusicChanged(self, ignored):
  1742. self.setAppDetails(self.cb_app_music.currentText())
  1743. self.func_settings_changed("apps")
  1744. @pyqtSlot(int)
  1745. def slot_tweakAppVideoHighlighted(self, index):
  1746. self.setAppDetails(self.cb_app_video.itemText(index))
  1747. @pyqtSlot(int)
  1748. def slot_tweakAppVideoChanged(self, ignored):
  1749. self.setAppDetails(self.cb_app_video.currentText())
  1750. self.func_settings_changed("apps")
  1751. @pyqtSlot(int)
  1752. def slot_tweakAppTextHighlighted(self, index):
  1753. self.setAppDetails(self.cb_app_text.itemText(index))
  1754. @pyqtSlot(int)
  1755. def slot_tweakAppTextChanged(self, ignored):
  1756. self.setAppDetails(self.cb_app_text.currentText())
  1757. self.func_settings_changed("apps")
  1758. @pyqtSlot(int)
  1759. def slot_tweakAppBrowserHighlighted(self, index):
  1760. self.setAppDetails(self.cb_app_browser.itemText(index))
  1761. @pyqtSlot(int)
  1762. def slot_tweakAppBrowserChanged(self, ignored):
  1763. self.setAppDetails(self.cb_app_browser.currentText())
  1764. self.func_settings_changed("apps")
  1765. @pyqtSlot()
  1766. def slot_tweakPluginAdd(self):
  1767. newPath = QFileDialog.getExistingDirectory(self, self.tr("Add Path"), "", QFileDialog.ShowDirsOnly)
  1768. if not newPath:
  1769. return
  1770. if self.tb_tweak_plugins.currentIndex() == 0:
  1771. self.list_LADSPA.addItem(newPath)
  1772. elif self.tb_tweak_plugins.currentIndex() == 1:
  1773. self.list_DSSI.addItem(newPath)
  1774. elif self.tb_tweak_plugins.currentIndex() == 2:
  1775. self.list_LV2.addItem(newPath)
  1776. elif self.tb_tweak_plugins.currentIndex() == 3:
  1777. self.list_VST.addItem(newPath)
  1778. self.func_settings_changed("plugins")
  1779. @pyqtSlot()
  1780. def slot_tweakPluginChange(self):
  1781. if self.tb_tweak_plugins.currentIndex() == 0:
  1782. curPath = self.list_LADSPA.item(self.list_LADSPA.currentRow()).text()
  1783. elif self.tb_tweak_plugins.currentIndex() == 1:
  1784. curPath = self.list_DSSI.item(self.list_DSSI.currentRow()).text()
  1785. elif self.tb_tweak_plugins.currentIndex() == 2:
  1786. curPath = self.list_LV2.item(self.list_LV2.currentRow()).text()
  1787. elif self.tb_tweak_plugins.currentIndex() == 3:
  1788. curPath = self.list_VST.item(self.list_VST.currentRow()).text()
  1789. else:
  1790. curPath = ""
  1791. newPath = QFileDialog.getExistingDirectory(self, self.tr("Change Path"), curPath, QFileDialog.ShowDirsOnly)
  1792. if not newPath:
  1793. return
  1794. if self.tb_tweak_plugins.currentIndex() == 0:
  1795. self.list_LADSPA.item(self.list_LADSPA.currentRow()).setText(newPath)
  1796. elif self.tb_tweak_plugins.currentIndex() == 1:
  1797. self.list_DSSI.item(self.list_DSSI.currentRow()).setText(newPath)
  1798. elif self.tb_tweak_plugins.currentIndex() == 2:
  1799. self.list_LV2.item(self.list_LV2.currentRow()).setText(newPath)
  1800. elif self.tb_tweak_plugins.currentIndex() == 3:
  1801. self.list_VST.item(self.list_VST.currentRow()).setText(newPath)
  1802. self.func_settings_changed("plugins")
  1803. @pyqtSlot()
  1804. def slot_tweakPluginRemove(self):
  1805. if self.tb_tweak_plugins.currentIndex() == 0:
  1806. self.list_LADSPA.takeItem(self.list_LADSPA.currentRow())
  1807. elif self.tb_tweak_plugins.currentIndex() == 1:
  1808. self.list_DSSI.takeItem(self.list_DSSI.currentRow())
  1809. elif self.tb_tweak_plugins.currentIndex() == 2:
  1810. self.list_LV2.takeItem(self.list_LV2.currentRow())
  1811. elif self.tb_tweak_plugins.currentIndex() == 3:
  1812. self.list_VST.takeItem(self.list_VST.currentRow())
  1813. self.func_settings_changed("plugins")
  1814. @pyqtSlot()
  1815. def slot_tweakPluginReset(self):
  1816. if self.tb_tweak_plugins.currentIndex() == 0:
  1817. self.list_LADSPA.clear()
  1818. for iPath in DEFAULT_LADSPA_PATH:
  1819. self.list_LADSPA.addItem(iPath)
  1820. elif self.tb_tweak_plugins.currentIndex() == 1:
  1821. self.list_DSSI.clear()
  1822. for iPath in DEFAULT_DSSI_PATH:
  1823. self.list_DSSI.addItem(iPath)
  1824. elif self.tb_tweak_plugins.currentIndex() == 2:
  1825. self.list_LV2.clear()
  1826. for iPath in DEFAULT_LV2_PATH:
  1827. self.list_LV2.addItem(iPath)
  1828. elif self.tb_tweak_plugins.currentIndex() == 3:
  1829. self.list_VST.clear()
  1830. for iPath in DEFAULT_VST_PATH:
  1831. self.list_VST.addItem(iPath)
  1832. self.func_settings_changed("plugins")
  1833. @pyqtSlot(int)
  1834. def slot_tweakPluginTypeChanged(self, index):
  1835. # Force row change
  1836. if index == 0:
  1837. self.list_LADSPA.setCurrentRow(-1)
  1838. self.list_LADSPA.setCurrentRow(0)
  1839. elif index == 1:
  1840. self.list_DSSI.setCurrentRow(-1)
  1841. self.list_DSSI.setCurrentRow(0)
  1842. elif index == 2:
  1843. self.list_LV2.setCurrentRow(-1)
  1844. self.list_LV2.setCurrentRow(0)
  1845. elif index == 3:
  1846. self.list_VST.setCurrentRow(-1)
  1847. self.list_VST.setCurrentRow(0)
  1848. @pyqtSlot(int)
  1849. def slot_tweakPluginsLadspaRowChanged(self, index):
  1850. nonRemovable = (index >= 0 and self.list_LADSPA.item(index).text() not in DEFAULT_LADSPA_PATH)
  1851. self.b_tweak_plugins_change.setEnabled(nonRemovable)
  1852. self.b_tweak_plugins_remove.setEnabled(nonRemovable)
  1853. @pyqtSlot(int)
  1854. def slot_tweakPluginsDssiRowChanged(self, index):
  1855. nonRemovable = (index >= 0 and self.list_DSSI.item(index).text() not in DEFAULT_DSSI_PATH)
  1856. self.b_tweak_plugins_change.setEnabled(nonRemovable)
  1857. self.b_tweak_plugins_remove.setEnabled(nonRemovable)
  1858. @pyqtSlot(int)
  1859. def slot_tweakPluginsLv2RowChanged(self, index):
  1860. nonRemovable = (index >= 0 and self.list_LV2.item(index).text() not in DEFAULT_LV2_PATH)
  1861. self.b_tweak_plugins_change.setEnabled(nonRemovable)
  1862. self.b_tweak_plugins_remove.setEnabled(nonRemovable)
  1863. @pyqtSlot(int)
  1864. def slot_tweakPluginsVstRowChanged(self, index):
  1865. nonRemovable = (index >= 0 and self.list_VST.item(index).text() not in DEFAULT_VST_PATH)
  1866. self.b_tweak_plugins_change.setEnabled(nonRemovable)
  1867. self.b_tweak_plugins_remove.setEnabled(nonRemovable)
  1868. def saveSettings(self):
  1869. self.settings.setValue("Geometry", self.saveGeometry())
  1870. GlobalSettings.setValue("JACK/AutoStart", self.cb_jack_autostart.isChecked())
  1871. GlobalSettings.setValue("ALSA-Audio/BridgeIndexType", self.cb_alsa_type.currentIndex())
  1872. GlobalSettings.setValue("A2J/AutoStart", self.cb_a2j_autostart.isChecked())
  1873. GlobalSettings.setValue("A2J/AutoExport", self.cb_a2j_autoexport.isChecked())
  1874. GlobalSettings.setValue("Pulse2JACK/AutoStart", (havePulseAudio and self.cb_pulse_autostart.isChecked()))
  1875. def loadSettings(self, geometry):
  1876. if geometry:
  1877. self.restoreGeometry(self.settings.value("Geometry", b""))
  1878. usingAlsaLoop = bool(GlobalSettings.value("ALSA-Audio/BridgeIndexType", iAlsaFileNone, type=int) == iAlsaFileLoop)
  1879. self.cb_jack_autostart.setChecked(GlobalSettings.value("JACK/AutoStart", wantJackStart, type=bool))
  1880. self.cb_a2j_autostart.setChecked(GlobalSettings.value("A2J/AutoStart", True, type=bool))
  1881. self.cb_a2j_autoexport.setChecked(GlobalSettings.value("A2J/AutoExport", True, type=bool))
  1882. self.cb_pulse_autostart.setChecked(GlobalSettings.value("Pulse2JACK/AutoStart", havePulseAudio and not usingAlsaLoop, type=bool))
  1883. def timerEvent(self, event):
  1884. if event.timerId() == self.m_timer500:
  1885. if gDBus.jack and self.m_last_dsp_load != None:
  1886. next_dsp_load = gDBus.jack.GetLoad()
  1887. next_xruns = int(gDBus.jack.GetXruns())
  1888. needUpdateTip = False
  1889. if self.m_last_dsp_load != next_dsp_load:
  1890. self.m_last_dsp_load = next_dsp_load
  1891. self.label_jack_dsp.setText("%.2f%%" % self.m_last_dsp_load)
  1892. needUpdateTip = True
  1893. if self.m_last_xruns != next_xruns:
  1894. self.m_last_xruns = next_xruns
  1895. self.label_jack_xruns.setText(str(self.m_last_xruns))
  1896. needUpdateTip = True
  1897. if needUpdateTip:
  1898. self.updateSystrayTooltip()
  1899. elif event.timerId() == self.m_timer2000:
  1900. if gDBus.jack and self.m_last_buffer_size != None:
  1901. next_buffer_size = gDBus.jack.GetBufferSize()
  1902. if self.m_last_buffer_size != next_buffer_size:
  1903. self.m_last_buffer_size = next_buffer_size
  1904. self.label_jack_bfsize.setText("%i samples" % self.m_last_buffer_size)
  1905. self.label_jack_latency.setText("%.1f ms" % gDBus.jack.GetLatency())
  1906. else:
  1907. self.update()
  1908. QMainWindow.timerEvent(self, event)
  1909. def closeEvent(self, event):
  1910. self.saveSettings()
  1911. self.systray.handleQtCloseEvent(event)
  1912. # ------------------------------------------------------------------------------------------------------------
  1913. def runFunctionInMainThread(task):
  1914. waiter = QSemaphore(1)
  1915. def taskInMainThread():
  1916. task()
  1917. waiter.release()
  1918. QTimer.singleShot(0, taskInMainThread)
  1919. waiter.tryAcquire()
  1920. #--------------- main ------------------
  1921. if __name__ == '__main__':
  1922. # App initialization
  1923. app = QApplication(sys.argv)
  1924. app.setApplicationName("Cadence")
  1925. app.setApplicationVersion(VERSION)
  1926. app.setOrganizationName("Cadence")
  1927. app.setWindowIcon(QIcon(":/scalable/cadence.svg"))
  1928. if haveDBus:
  1929. gDBus.loop = DBusQtMainLoop(set_as_default=True)
  1930. gDBus.bus = dbus.SessionBus(mainloop=gDBus.loop)
  1931. initSystemChecks()
  1932. # Show GUI
  1933. gui = CadenceMainW()
  1934. # Set-up custom signal handling
  1935. setUpSignals(gui)
  1936. if "--minimized" in app.arguments():
  1937. gui.hide()
  1938. gui.systray.setActionText("show", gui.tr("Restore"))
  1939. app.setQuitOnLastWindowClosed(False)
  1940. else:
  1941. gui.show()
  1942. # Exit properly
  1943. sys.exit(gui.systray.exec_(app))