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.

2399 lines
93KB

  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. self.m_a2jExportHW = False
  435. def wasJackStarted(self):
  436. return self.m_wasStarted
  437. def startA2J(self):
  438. gDBus.a2j.set_hw_export(self.m_a2jExportHW)
  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 gDBus.a2j and not bool(gDBus.a2j.is_started()):
  475. self.m_a2jExportHW = GlobalSettings.value("A2J/ExportHW", True, type=bool)
  476. runFunctionInMainThread(self.startA2J)
  477. self.progressChanged.emit(96)
  478. # PulseAudio
  479. if GlobalSettings.value("Pulse2JACK/AutoStart", True, type=bool) and not isPulseAudioBridged():
  480. if GlobalSettings.value("Pulse2JACK/PlaybackModeOnly", False, type=bool):
  481. os.system("cadence-pulse2jack -p")
  482. else:
  483. os.system("cadence-pulse2jack")
  484. self.progressChanged.emit(100)
  485. # Force Restart Dialog
  486. class ForceWaitDialog(QDialog, ui_cadence_rwait.Ui_Dialog):
  487. def __init__(self, parent):
  488. QDialog.__init__(self, parent)
  489. self.setupUi(self)
  490. self.setWindowFlags(Qt.Dialog|Qt.WindowCloseButtonHint)
  491. self.rThread = ForceRestartThread(self)
  492. self.rThread.start()
  493. self.rThread.progressChanged.connect(self.progressBar.setValue)
  494. self.rThread.finished.connect(self.slot_rThreadFinished)
  495. def DBusReconnect(self):
  496. self.parent().DBusReconnect()
  497. @pyqtSlot()
  498. def slot_rThreadFinished(self):
  499. self.close()
  500. if self.rThread.wasJackStarted():
  501. QMessageBox.information(self, self.tr("Info"), self.tr("JACK was re-started sucessfully"))
  502. else:
  503. QMessageBox.critical(self, self.tr("Error"), self.tr("Could not start JACK!"))
  504. def done(self, r):
  505. QDialog.done(self, r)
  506. self.close()
  507. # Additional JACK options
  508. class ToolBarJackDialog(QDialog, ui_cadence_tb_jack.Ui_Dialog):
  509. def __init__(self, parent):
  510. QDialog.__init__(self, parent)
  511. self.setupUi(self)
  512. self.m_ladishLoaded = False
  513. if haveDBus:
  514. if GlobalSettings.value("JACK/AutoLoadLadishStudio", False, type=bool):
  515. self.rb_ladish.setChecked(True)
  516. self.m_ladishLoaded = True
  517. elif "org.ladish" in gDBus.bus.list_names():
  518. self.m_ladishLoaded = True
  519. else:
  520. self.rb_ladish.setEnabled(False)
  521. self.rb_jack.setChecked(True)
  522. if self.m_ladishLoaded:
  523. self.fillStudioNames()
  524. self.accepted.connect(self.slot_setOptions)
  525. self.rb_ladish.clicked.connect(self.slot_maybeFillStudioNames)
  526. def fillStudioNames(self):
  527. gDBus.ladish_control = gDBus.bus.get_object("org.ladish", "/org/ladish/Control")
  528. ladishStudioName = dbus.String(GlobalSettings.value("JACK/LadishStudioName", "", type=str))
  529. ladishStudioListDump = gDBus.ladish_control.GetStudioList()
  530. if len(ladishStudioListDump) == 0:
  531. self.rb_ladish.setEnabled(False)
  532. self.rb_jack.setChecked(True)
  533. else:
  534. i=0
  535. for thisStudioName, thisStudioDict in ladishStudioListDump:
  536. self.cb_studio_name.addItem(thisStudioName)
  537. if ladishStudioName and thisStudioName == ladishStudioName:
  538. self.cb_studio_name.setCurrentIndex(i)
  539. i += 1
  540. @pyqtSlot()
  541. def slot_maybeFillStudioNames(self):
  542. if not self.m_ladishLoaded:
  543. self.fillStudioNames()
  544. self.m_ladishLoaded = True
  545. @pyqtSlot()
  546. def slot_setOptions(self):
  547. GlobalSettings.setValue("JACK/AutoLoadLadishStudio", self.rb_ladish.isChecked())
  548. GlobalSettings.setValue("JACK/LadishStudioName", self.cb_studio_name.currentText())
  549. def done(self, r):
  550. QDialog.done(self, r)
  551. self.close()
  552. # Additional ALSA Audio options
  553. class ToolBarAlsaAudioDialog(QDialog, ui_cadence_tb_alsa.Ui_Dialog):
  554. def __init__(self, parent, customMode):
  555. QDialog.__init__(self, parent)
  556. self.setupUi(self)
  557. self.asoundrcFile = os.path.join(HOME, ".asoundrc")
  558. self.fCustomMode = customMode
  559. if customMode:
  560. asoundrcFd = open(self.asoundrcFile, "r")
  561. asoundrcRead = asoundrcFd.read().strip()
  562. asoundrcFd.close()
  563. self.textBrowser.setPlainText(asoundrcRead)
  564. self.stackedWidget.setCurrentIndex(0)
  565. self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel)
  566. else:
  567. self.textBrowser.hide()
  568. self.stackedWidget.setCurrentIndex(1)
  569. self.adjustSize()
  570. self.spinBox.setValue(GlobalSettings.value("ALSA-Audio/BridgeChannels", 2, type=int))
  571. if GlobalSettings.value("ALSA-Audio/BridgeTool", "alsa_in", type=str) == "zita":
  572. self.comboBox.setCurrentIndex(1)
  573. else:
  574. self.comboBox.setCurrentIndex(0)
  575. self.accepted.connect(self.slot_setOptions)
  576. @pyqtSlot()
  577. def slot_setOptions(self):
  578. channels = self.spinBox.value()
  579. GlobalSettings.setValue("ALSA-Audio/BridgeChannels", channels)
  580. GlobalSettings.setValue("ALSA-Audio/BridgeTool", "zita" if (self.comboBox.currentIndex() == 1) else "alsa_in")
  581. asoundrcFd = open(self.asoundrcFile, "w")
  582. asoundrcFd.write(asoundrc_aloop.replace("channels 2\n", "channels %i\n" % channels) + "\n")
  583. asoundrcFd.close()
  584. def done(self, r):
  585. QDialog.done(self, r)
  586. self.close()
  587. # Additional ALSA MIDI options
  588. class ToolBarA2JDialog(QDialog, ui_cadence_tb_a2j.Ui_Dialog):
  589. def __init__(self, parent):
  590. QDialog.__init__(self, parent)
  591. self.setupUi(self)
  592. self.cb_export_hw.setChecked(GlobalSettings.value("A2J/ExportHW", True, type=bool))
  593. self.accepted.connect(self.slot_setOptions)
  594. @pyqtSlot()
  595. def slot_setOptions(self):
  596. GlobalSettings.setValue("A2J/ExportHW", self.cb_export_hw.isChecked())
  597. def done(self, r):
  598. QDialog.done(self, r)
  599. self.close()
  600. # Additional PulseAudio options
  601. class ToolBarPADialog(QDialog, ui_cadence_tb_pa.Ui_Dialog):
  602. def __init__(self, parent):
  603. QDialog.__init__(self, parent)
  604. self.setupUi(self)
  605. self.cb_playback_only.setChecked(GlobalSettings.value("Pulse2JACK/PlaybackModeOnly", False, type=bool))
  606. self.accepted.connect(self.slot_setOptions)
  607. @pyqtSlot()
  608. def slot_setOptions(self):
  609. GlobalSettings.setValue("Pulse2JACK/PlaybackModeOnly", self.cb_playback_only.isChecked())
  610. def done(self, r):
  611. QDialog.done(self, r)
  612. self.close()
  613. # Main Window
  614. class CadenceMainW(QMainWindow, ui_cadence.Ui_CadenceMainW):
  615. DBusJackServerStartedCallback = pyqtSignal()
  616. DBusJackServerStoppedCallback = pyqtSignal()
  617. DBusJackClientAppearedCallback = pyqtSignal(int, str)
  618. DBusJackClientDisappearedCallback = pyqtSignal(int)
  619. DBusA2JBridgeStartedCallback = pyqtSignal()
  620. DBusA2JBridgeStoppedCallback = pyqtSignal()
  621. SIGTERM = pyqtSignal()
  622. SIGUSR1 = pyqtSignal()
  623. SIGUSR2 = pyqtSignal()
  624. def __init__(self, parent=None):
  625. QMainWindow.__init__(self, parent)
  626. self.setupUi(self)
  627. self.settings = QSettings("Cadence", "Cadence")
  628. self.loadSettings(True)
  629. self.pix_apply = QIcon(getIcon("dialog-ok-apply", 16)).pixmap(16, 16)
  630. self.pix_cancel = QIcon(getIcon("dialog-cancel", 16)).pixmap(16, 16)
  631. self.pix_error = QIcon(getIcon("dialog-error", 16)).pixmap(16, 16)
  632. self.pix_warning = QIcon(getIcon("dialog-warning", 16)).pixmap(16, 16)
  633. self.m_lastAlsaIndexType = -2 # invalid
  634. if jacklib and not jacklib.JACK2:
  635. self.b_jack_switchmaster.setEnabled(False)
  636. # -------------------------------------------------------------
  637. # Set-up GUI (System Information)
  638. if HAIKU:
  639. info = get_haiku_information()
  640. elif LINUX:
  641. info = get_linux_information()
  642. elif MACOS:
  643. info = get_mac_information()
  644. elif WINDOWS:
  645. info = get_windows_information()
  646. else:
  647. info = ("Unknown", "Unknown")
  648. self.label_info_os.setText(info[0])
  649. self.label_info_version.setText(info[1])
  650. self.label_info_arch.setText(get_architecture())
  651. # -------------------------------------------------------------
  652. # Set-up GUI (System Status)
  653. self.m_availGovPath = "/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors"
  654. self.m_curGovPath = "/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"
  655. self.m_curGovPaths = []
  656. self.m_curGovCPUs = []
  657. try:
  658. fBus = dbus.SystemBus(mainloop=gDBus.loop)
  659. fProxy = fBus.get_object("com.ubuntu.IndicatorCpufreqSelector", "/Selector", introspect=False)
  660. haveFreqSelector = True
  661. except:
  662. haveFreqSelector = False
  663. if haveFreqSelector and os.path.exists(self.m_availGovPath) and os.path.exists(self.m_curGovPath):
  664. self.m_govWatcher = QFileSystemWatcher(self)
  665. self.m_govWatcher.addPath(self.m_curGovPath)
  666. self.m_govWatcher.fileChanged.connect(self.slot_governorFileChanged)
  667. QTimer.singleShot(0, self.slot_governorFileChanged)
  668. availGovFd = open(self.m_availGovPath, "r")
  669. availGovRead = availGovFd.read().strip()
  670. availGovFd.close()
  671. self.m_availGovList = availGovRead.split(" ")
  672. for availGov in self.m_availGovList:
  673. self.cb_cpufreq.addItem(availGov)
  674. for root, dirs, files in os.walk("/sys/devices/system/cpu/"):
  675. for dir_ in [dir_ for dir_ in dirs if dir_.startswith("cpu")]:
  676. if not dir_.replace("cpu", "", 1).isdigit():
  677. continue
  678. cpuGovPath = os.path.join(root, dir_, "cpufreq", "scaling_governor")
  679. if os.path.exists(cpuGovPath):
  680. self.m_curGovPaths.append(cpuGovPath)
  681. self.m_curGovCPUs.append(int(dir_.replace("cpu", "", 1)))
  682. self.cb_cpufreq.setCurrentIndex(-1)
  683. else:
  684. self.m_govWatcher = None
  685. self.cb_cpufreq.setEnabled(False)
  686. self.label_cpufreq.setEnabled(False)
  687. # -------------------------------------------------------------
  688. # Set-up GUI (System Checks)
  689. #self.label_check_helper1.setVisible(False)
  690. #self.label_check_helper2.setVisible(False)
  691. #self.label_check_helper3.setVisible(False)
  692. index = 2
  693. checksLayout = self.groupBox_checks.layout()
  694. for check in cadenceSystemChecks:
  695. widgetName = QLabel("%s:" % check.name)
  696. widgetIcon = QLabel("")
  697. widgetResult = QLabel(check.result)
  698. if check.moreInfo:
  699. widgetName.setToolTip(check.moreInfo)
  700. widgetIcon.setToolTip(check.moreInfo)
  701. widgetResult.setToolTip(check.moreInfo)
  702. #widgetName.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
  703. #widgetIcon.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
  704. #widgetIcon.setMinimumSize(16, 16)
  705. #widgetIcon.setMaximumSize(16, 16)
  706. #widgetResult.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
  707. if check.icon == check.ICON_ERROR:
  708. widgetIcon.setPixmap(self.pix_error)
  709. elif check.icon == check.ICON_WARN:
  710. widgetIcon.setPixmap(self.pix_warning)
  711. elif check.icon == check.ICON_OK:
  712. widgetIcon.setPixmap(self.pix_apply)
  713. else:
  714. widgetIcon.setPixmap(self.pix_cancel)
  715. checksLayout.addWidget(widgetName, index, 0, Qt.AlignRight)
  716. checksLayout.addWidget(widgetIcon, index, 1, Qt.AlignHCenter)
  717. checksLayout.addWidget(widgetResult, index, 2, Qt.AlignLeft)
  718. index += 1
  719. # -------------------------------------------------------------
  720. # Set-up GUI (JACK Bridges)
  721. if not havePulseAudio:
  722. self.toolBox_pulseaudio.setEnabled(False)
  723. self.label_bridge_pulse.setText(self.tr("PulseAudio is not installed"))
  724. # Not available in cxfreeze builds
  725. if sys.argv[0].endswith("/cadence"):
  726. self.groupBox_bridges.setEnabled(False)
  727. self.cb_jack_autostart.setEnabled(False)
  728. self.tb_jack_options.setEnabled(False)
  729. # -------------------------------------------------------------
  730. # Set-up GUI (Tweaks)
  731. self.settings_changed_types = []
  732. self.frame_tweaks_settings.setVisible(False)
  733. for i in range(self.tw_tweaks.rowCount()):
  734. self.tw_tweaks.item(i, 0).setTextAlignment(Qt.AlignCenter)
  735. self.tw_tweaks.setCurrentCell(0, 0)
  736. # -------------------------------------------------------------
  737. # Set-up GUI (Tweaks, Audio Plugins PATH)
  738. self.b_tweak_plugins_change.setEnabled(False)
  739. self.b_tweak_plugins_remove.setEnabled(False)
  740. for iPath in DEFAULT_LADSPA_PATH:
  741. self.list_LADSPA.addItem(iPath)
  742. for iPath in DEFAULT_DSSI_PATH:
  743. self.list_DSSI.addItem(iPath)
  744. for iPath in DEFAULT_LV2_PATH:
  745. self.list_LV2.addItem(iPath)
  746. for iPath in DEFAULT_VST_PATH:
  747. self.list_VST.addItem(iPath)
  748. EXTRA_LADSPA_DIRS = GlobalSettings.value("AudioPlugins/EXTRA_LADSPA_PATH", "", type=str)
  749. EXTRA_DSSI_DIRS = GlobalSettings.value("AudioPlugins/EXTRA_DSSI_PATH", "", type=str)
  750. EXTRA_LV2_DIRS = GlobalSettings.value("AudioPlugins/EXTRA_LV2_PATH", "", type=str)
  751. EXTRA_VST_DIRS = GlobalSettings.value("AudioPlugins/EXTRA_VST_PATH", "", type=str)
  752. for iPath in EXTRA_LADSPA_DIRS.split(":"):
  753. if os.path.exists(iPath):
  754. self.list_LADSPA.addItem(iPath)
  755. for iPath in EXTRA_DSSI_DIRS.split(":"):
  756. if os.path.exists(iPath):
  757. self.list_DSSI.addItem(iPath)
  758. for iPath in EXTRA_LV2_DIRS.split(":"):
  759. if os.path.exists(iPath):
  760. self.list_LV2.addItem(iPath)
  761. for iPath in EXTRA_VST_DIRS.split(":"):
  762. if os.path.exists(iPath):
  763. self.list_VST.addItem(iPath)
  764. self.list_LADSPA.sortItems(Qt.AscendingOrder)
  765. self.list_DSSI.sortItems(Qt.AscendingOrder)
  766. self.list_LV2.sortItems(Qt.AscendingOrder)
  767. self.list_VST.sortItems(Qt.AscendingOrder)
  768. self.list_LADSPA.setCurrentRow(0)
  769. self.list_DSSI.setCurrentRow(0)
  770. self.list_LV2.setCurrentRow(0)
  771. self.list_VST.setCurrentRow(0)
  772. # -------------------------------------------------------------
  773. # Set-up GUI (Tweaks, Default Applications)
  774. for desktop in DESKTOP_X_IMAGE:
  775. if isDesktopFileInstalled(desktop):
  776. self.cb_app_image.addItem(desktop)
  777. for desktop in DESKTOP_X_MUSIC:
  778. if isDesktopFileInstalled(desktop):
  779. self.cb_app_music.addItem(desktop)
  780. for desktop in DESKTOP_X_VIDEO:
  781. if isDesktopFileInstalled(desktop):
  782. self.cb_app_video.addItem(desktop)
  783. for desktop in DESKTOP_X_TEXT:
  784. if isDesktopFileInstalled(desktop):
  785. self.cb_app_text.addItem(desktop)
  786. for desktop in DESKTOP_X_BROWSER:
  787. if isDesktopFileInstalled(desktop):
  788. self.cb_app_browser.addItem(desktop)
  789. if self.cb_app_image.count() == 0:
  790. self.ch_app_image.setEnabled(False)
  791. if self.cb_app_music.count() == 0:
  792. self.ch_app_music.setEnabled(False)
  793. if self.cb_app_video.count() == 0:
  794. self.ch_app_video.setEnabled(False)
  795. if self.cb_app_text.count() == 0:
  796. self.ch_app_text.setEnabled(False)
  797. if self.cb_app_browser.count() == 0:
  798. self.ch_app_browser.setEnabled(False)
  799. mimeappsPath = os.path.join(HOME, ".local", "share", "applications", "mimeapps.list")
  800. if os.path.exists(mimeappsPath):
  801. fd = open(mimeappsPath, "r")
  802. mimeappsRead = fd.read()
  803. fd.close()
  804. x_image = getXdgProperty(mimeappsRead, "image/bmp")
  805. x_music = getXdgProperty(mimeappsRead, "audio/wav")
  806. x_video = getXdgProperty(mimeappsRead, "video/webm")
  807. x_text = getXdgProperty(mimeappsRead, "text/plain")
  808. x_browser = getXdgProperty(mimeappsRead, "text/html")
  809. if x_image and searchAndSetComboBoxValue(self.cb_app_image, x_image):
  810. self.ch_app_image.setChecked(True)
  811. if x_music and searchAndSetComboBoxValue(self.cb_app_music, x_music):
  812. self.ch_app_music.setChecked(True)
  813. if x_video and searchAndSetComboBoxValue(self.cb_app_video, x_video):
  814. self.ch_app_video.setChecked(True)
  815. if x_text and searchAndSetComboBoxValue(self.cb_app_text, x_text):
  816. self.ch_app_text.setChecked(True)
  817. if x_browser and searchAndSetComboBoxValue(self.cb_app_browser, x_browser):
  818. self.ch_app_browser.setChecked(True)
  819. else: # ~/.local/share/applications/mimeapps.list doesn't exist
  820. if not os.path.exists(os.path.join(HOME, ".local")):
  821. os.mkdir(os.path.join(HOME, ".local"))
  822. elif not os.path.exists(os.path.join(HOME, ".local", "share")):
  823. os.mkdir(os.path.join(HOME, ".local", "share"))
  824. elif not os.path.exists(os.path.join(HOME, ".local", "share", "applications")):
  825. os.mkdir(os.path.join(HOME, ".local", "share", "applications"))
  826. # -------------------------------------------------------------
  827. # Set-up GUI (Tweaks, WineASIO)
  828. if haveWine:
  829. ins = int(getWineAsioKeyValue("Number of inputs", "00000010"), 16)
  830. outs = int(getWineAsioKeyValue("Number of outputs", "00000010"), 16)
  831. hw = bool(int(getWineAsioKeyValue("Connect to hardware", "00000001"), 10))
  832. autostart = bool(int(getWineAsioKeyValue("Autostart server", "00000000"), 10))
  833. fixed_bsize = bool(int(getWineAsioKeyValue("Fixed buffersize", "00000001"), 10))
  834. prefer_bsize = int(getWineAsioKeyValue("Preferred buffersize", "00000400"), 16)
  835. for bsize in BUFFER_SIZE_LIST:
  836. self.cb_wineasio_bsizes.addItem(str(bsize))
  837. if bsize == prefer_bsize:
  838. self.cb_wineasio_bsizes.setCurrentIndex(self.cb_wineasio_bsizes.count()-1)
  839. self.sb_wineasio_ins.setValue(ins)
  840. self.sb_wineasio_outs.setValue(outs)
  841. self.cb_wineasio_hw.setChecked(hw)
  842. self.cb_wineasio_autostart.setChecked(autostart)
  843. self.cb_wineasio_fixed_bsize.setChecked(fixed_bsize)
  844. else:
  845. # No Wine
  846. self.tw_tweaks.hideRow(2)
  847. # -------------------------------------------------------------
  848. # Set-up systray
  849. self.systray = systray.GlobalSysTray(self, "Cadence", "cadence")
  850. if haveDBus:
  851. self.systray.addAction("jack_start", self.tr("Start JACK"))
  852. self.systray.addAction("jack_stop", self.tr("Stop JACK"))
  853. self.systray.addAction("jack_configure", self.tr("Configure JACK"))
  854. self.systray.addSeparator("sep1")
  855. self.systray.addMenu("alsa", self.tr("ALSA Audio Bridge"))
  856. self.systray.addMenuAction("alsa", "alsa_start", self.tr("Start"))
  857. self.systray.addMenuAction("alsa", "alsa_stop", self.tr("Stop"))
  858. self.systray.addMenu("a2j", self.tr("ALSA MIDI Bridge"))
  859. self.systray.addMenuAction("a2j", "a2j_start", self.tr("Start"))
  860. self.systray.addMenuAction("a2j", "a2j_stop", self.tr("Stop"))
  861. self.systray.addMenuAction("a2j", "a2j_export_hw", self.tr("Export Hardware Ports..."))
  862. self.systray.addMenu("pulse", self.tr("PulseAudio Bridge"))
  863. self.systray.addMenuAction("pulse", "pulse_start", self.tr("Start"))
  864. self.systray.addMenuAction("pulse", "pulse_stop", self.tr("Stop"))
  865. self.systray.setActionIcon("jack_start", "media-playback-start")
  866. self.systray.setActionIcon("jack_stop", "media-playback-stop")
  867. self.systray.setActionIcon("jack_configure", "configure")
  868. self.systray.setActionIcon("alsa_start", "media-playback-start")
  869. self.systray.setActionIcon("alsa_stop", "media-playback-stop")
  870. self.systray.setActionIcon("a2j_start", "media-playback-start")
  871. self.systray.setActionIcon("a2j_stop", "media-playback-stop")
  872. self.systray.setActionIcon("pulse_start", "media-playback-start")
  873. self.systray.setActionIcon("pulse_stop", "media-playback-stop")
  874. self.systray.connect("jack_start", self.slot_JackServerStart)
  875. self.systray.connect("jack_stop", self.slot_JackServerStop)
  876. self.systray.connect("jack_configure", self.slot_JackServerConfigure)
  877. self.systray.connect("alsa_start", self.slot_AlsaBridgeStart)
  878. self.systray.connect("alsa_stop", self.slot_AlsaBridgeStop)
  879. self.systray.connect("a2j_start", self.slot_A2JBridgeStart)
  880. self.systray.connect("a2j_stop", self.slot_A2JBridgeStop)
  881. self.systray.connect("a2j_export_hw", self.slot_A2JBridgeExportHW)
  882. self.systray.connect("pulse_start", self.slot_PulseAudioBridgeStart)
  883. self.systray.connect("pulse_stop", self.slot_PulseAudioBridgeStop)
  884. self.systray.addMenu("tools", self.tr("Tools"))
  885. self.systray.addMenuAction("tools", "app_catarina", "Catarina")
  886. self.systray.addMenuAction("tools", "app_catia", "Catia")
  887. self.systray.addMenuAction("tools", "app_claudia", "Claudia")
  888. self.systray.addMenuSeparator("tools", "tools_sep")
  889. self.systray.addMenuAction("tools", "app_logs", "Logs")
  890. self.systray.addMenuAction("tools", "app_meter_in", "Meter (Inputs)")
  891. self.systray.addMenuAction("tools", "app_meter_out", "Meter (Output)")
  892. self.systray.addMenuAction("tools", "app_render", "Render")
  893. self.systray.addMenuAction("tools", "app_xy-controller", "XY-Controller")
  894. self.systray.addSeparator("sep2")
  895. self.systray.connect("app_catarina", self.func_start_catarina)
  896. self.systray.connect("app_catia", self.func_start_catia)
  897. self.systray.connect("app_claudia", self.func_start_claudia)
  898. self.systray.connect("app_logs", self.func_start_logs)
  899. self.systray.connect("app_meter_in", self.func_start_jackmeter_in)
  900. self.systray.connect("app_meter_out", self.func_start_jackmeter)
  901. self.systray.connect("app_render", self.func_start_render)
  902. self.systray.connect("app_xy-controller", self.func_start_xycontroller)
  903. self.systray.setToolTip("Cadence")
  904. self.systray.show()
  905. # -------------------------------------------------------------
  906. # Set-up connections
  907. self.b_jack_start.clicked.connect(self.slot_JackServerStart)
  908. self.b_jack_stop.clicked.connect(self.slot_JackServerStop)
  909. self.b_jack_restart.clicked.connect(self.slot_JackServerForceRestart)
  910. self.b_jack_configure.clicked.connect(self.slot_JackServerConfigure)
  911. self.b_jack_switchmaster.clicked.connect(self.slot_JackServerSwitchMaster)
  912. self.tb_jack_options.clicked.connect(self.slot_JackOptions)
  913. self.b_alsa_start.clicked.connect(self.slot_AlsaBridgeStart)
  914. self.b_alsa_stop.clicked.connect(self.slot_AlsaBridgeStop)
  915. self.cb_alsa_type.currentIndexChanged[int].connect(self.slot_AlsaBridgeChanged)
  916. self.tb_alsa_options.clicked.connect(self.slot_AlsaAudioBridgeOptions)
  917. self.b_a2j_start.clicked.connect(self.slot_A2JBridgeStart)
  918. self.b_a2j_stop.clicked.connect(self.slot_A2JBridgeStop)
  919. self.b_a2j_export_hw.clicked.connect(self.slot_A2JBridgeExportHW)
  920. self.tb_a2j_options.clicked.connect(self.slot_A2JBridgeOptions)
  921. self.b_pulse_start.clicked.connect(self.slot_PulseAudioBridgeStart)
  922. self.b_pulse_stop.clicked.connect(self.slot_PulseAudioBridgeStop)
  923. self.tb_pulse_options.clicked.connect(self.slot_PulseAudioBridgeOptions)
  924. self.pic_catia.clicked.connect(self.func_start_catia)
  925. self.pic_claudia.clicked.connect(self.func_start_claudia)
  926. self.pic_meter_in.clicked.connect(self.func_start_jackmeter_in)
  927. self.pic_meter_out.clicked.connect(self.func_start_jackmeter)
  928. self.pic_logs.clicked.connect(self.func_start_logs)
  929. self.pic_render.clicked.connect(self.func_start_render)
  930. self.pic_xycontroller.clicked.connect(self.func_start_xycontroller)
  931. self.b_tweaks_apply_now.clicked.connect(self.slot_tweaksApply)
  932. self.b_tweak_plugins_add.clicked.connect(self.slot_tweakPluginAdd)
  933. self.b_tweak_plugins_change.clicked.connect(self.slot_tweakPluginChange)
  934. self.b_tweak_plugins_remove.clicked.connect(self.slot_tweakPluginRemove)
  935. self.b_tweak_plugins_reset.clicked.connect(self.slot_tweakPluginReset)
  936. self.tb_tweak_plugins.currentChanged.connect(self.slot_tweakPluginTypeChanged)
  937. self.list_LADSPA.currentRowChanged.connect(self.slot_tweakPluginsLadspaRowChanged)
  938. self.list_DSSI.currentRowChanged.connect(self.slot_tweakPluginsDssiRowChanged)
  939. self.list_LV2.currentRowChanged.connect(self.slot_tweakPluginsLv2RowChanged)
  940. self.list_VST.currentRowChanged.connect(self.slot_tweakPluginsVstRowChanged)
  941. self.ch_app_image.clicked.connect(self.slot_tweaksSettingsChanged_apps)
  942. self.cb_app_image.highlighted.connect(self.slot_tweakAppImageHighlighted)
  943. self.cb_app_image.currentIndexChanged[int].connect(self.slot_tweakAppImageChanged)
  944. self.ch_app_music.clicked.connect(self.slot_tweaksSettingsChanged_apps)
  945. self.cb_app_music.highlighted.connect(self.slot_tweakAppMusicHighlighted)
  946. self.cb_app_music.currentIndexChanged[int].connect(self.slot_tweakAppMusicChanged)
  947. self.ch_app_video.clicked.connect(self.slot_tweaksSettingsChanged_apps)
  948. self.cb_app_video.highlighted.connect(self.slot_tweakAppVideoHighlighted)
  949. self.cb_app_video.currentIndexChanged[int].connect(self.slot_tweakAppVideoChanged)
  950. self.ch_app_text.clicked.connect(self.slot_tweaksSettingsChanged_apps)
  951. self.cb_app_text.highlighted.connect(self.slot_tweakAppTextHighlighted)
  952. self.cb_app_text.currentIndexChanged[int].connect(self.slot_tweakAppTextChanged)
  953. self.ch_app_browser.clicked.connect(self.slot_tweaksSettingsChanged_apps)
  954. self.cb_app_browser.highlighted.connect(self.slot_tweakAppBrowserHighlighted)
  955. self.cb_app_browser.currentIndexChanged[int].connect(self.slot_tweakAppBrowserChanged)
  956. self.sb_wineasio_ins.valueChanged.connect(self.slot_tweaksSettingsChanged_wineasio)
  957. self.sb_wineasio_outs.valueChanged.connect(self.slot_tweaksSettingsChanged_wineasio)
  958. self.cb_wineasio_hw.clicked.connect(self.slot_tweaksSettingsChanged_wineasio)
  959. self.cb_wineasio_autostart.clicked.connect(self.slot_tweaksSettingsChanged_wineasio)
  960. self.cb_wineasio_fixed_bsize.clicked.connect(self.slot_tweaksSettingsChanged_wineasio)
  961. self.cb_wineasio_bsizes.currentIndexChanged[int].connect(self.slot_tweaksSettingsChanged_wineasio)
  962. # org.jackaudio.JackControl
  963. self.DBusJackServerStartedCallback.connect(self.slot_DBusJackServerStartedCallback)
  964. self.DBusJackServerStoppedCallback.connect(self.slot_DBusJackServerStoppedCallback)
  965. # org.jackaudio.JackPatchbay
  966. self.DBusJackClientAppearedCallback.connect(self.slot_DBusJackClientAppearedCallback)
  967. self.DBusJackClientDisappearedCallback.connect(self.slot_DBusJackClientDisappearedCallback)
  968. # org.gna.home.a2jmidid.control
  969. self.DBusA2JBridgeStartedCallback.connect(self.slot_DBusA2JBridgeStartedCallback)
  970. self.DBusA2JBridgeStoppedCallback.connect(self.slot_DBusA2JBridgeStoppedCallback)
  971. # -------------------------------------------------------------
  972. self.m_last_dsp_load = None
  973. self.m_last_xruns = None
  974. self.m_last_buffer_size = None
  975. self.m_timer500 = None
  976. self.m_timer2000 = self.startTimer(2000)
  977. self.DBusReconnect()
  978. if haveDBus:
  979. gDBus.bus.add_signal_receiver(self.DBusSignalReceiver, destination_keyword='dest', path_keyword='path',
  980. member_keyword='member', interface_keyword='interface', sender_keyword='sender', )
  981. def DBusReconnect(self):
  982. if haveDBus:
  983. try:
  984. gDBus.jack = gDBus.bus.get_object("org.jackaudio.service", "/org/jackaudio/Controller")
  985. gDBus.patchbay = dbus.Interface(gDBus.jack, "org.jackaudio.JackPatchbay")
  986. jacksettings.initBus(gDBus.bus)
  987. except:
  988. gDBus.jack = None
  989. gDBus.patchbay = None
  990. try:
  991. gDBus.a2j = dbus.Interface(gDBus.bus.get_object("org.gna.home.a2jmidid", "/"), "org.gna.home.a2jmidid.control")
  992. except:
  993. gDBus.a2j = None
  994. if gDBus.jack:
  995. if gDBus.jack.IsStarted():
  996. # Check for pulseaudio in jack graph
  997. try:
  998. version, groups, conns = gDBus.patchbay.GetGraph(0)
  999. except:
  1000. version, groups, conns = (list(), list(), list())
  1001. for group_id, group_name, ports in groups:
  1002. if group_name == "alsa2jack":
  1003. global jackClientIdALSA
  1004. jackClientIdALSA = group_id
  1005. elif group_name == "PulseAudio JACK Sink":
  1006. global jackClientIdPulse
  1007. jackClientIdPulse = group_id
  1008. self.jackStarted()
  1009. else:
  1010. self.jackStopped()
  1011. self.label_jack_realtime.setText("Yes" if jacksettings.isRealtime() else "No")
  1012. else:
  1013. self.jackStopped()
  1014. self.label_jack_status.setText("Unavailable")
  1015. self.label_jack_status_ico.setPixmap(self.pix_error)
  1016. self.label_jack_realtime.setText("Unknown")
  1017. self.label_jack_realtime_ico.setPixmap(self.pix_error)
  1018. self.groupBox_jack.setEnabled(False)
  1019. self.groupBox_jack.setTitle("-- jackdbus is not available --")
  1020. self.b_jack_start.setEnabled(False)
  1021. self.b_jack_stop.setEnabled(False)
  1022. self.b_jack_restart.setEnabled(False)
  1023. self.b_jack_configure.setEnabled(False)
  1024. self.b_jack_switchmaster.setEnabled(False)
  1025. self.groupBox_bridges.setEnabled(False)
  1026. if gDBus.a2j:
  1027. try:
  1028. started = gDBus.a2j.is_started()
  1029. except:
  1030. started = False
  1031. if started:
  1032. self.a2jStarted()
  1033. else:
  1034. self.a2jStopped()
  1035. else:
  1036. self.toolBox_alsamidi.setEnabled(False)
  1037. self.cb_a2j_autostart.setChecked(False)
  1038. self.label_bridge_a2j.setText("ALSA MIDI Bridge is not installed")
  1039. self.settings.setValue("A2J/AutoStart", False)
  1040. self.updateSystrayTooltip()
  1041. def DBusSignalReceiver(self, *args, **kwds):
  1042. if kwds['interface'] == "org.freedesktop.DBus" and kwds['path'] == "/org/freedesktop/DBus" and kwds['member'] == "NameOwnerChanged":
  1043. appInterface, appId, newId = args
  1044. if not newId:
  1045. # Something crashed
  1046. if appInterface == "org.jackaudio.service":
  1047. QTimer.singleShot(0, self.slot_handleCrash_jack)
  1048. elif appInterface == "org.gna.home.a2jmidid":
  1049. QTimer.singleShot(0, self.slot_handleCrash_a2j)
  1050. elif kwds['interface'] == "org.jackaudio.JackControl":
  1051. if DEBUG: print("org.jackaudio.JackControl", kwds['member'])
  1052. if kwds['member'] == "ServerStarted":
  1053. self.DBusJackServerStartedCallback.emit()
  1054. elif kwds['member'] == "ServerStopped":
  1055. self.DBusJackServerStoppedCallback.emit()
  1056. elif kwds['interface'] == "org.jackaudio.JackPatchbay":
  1057. if gDBus.patchbay and kwds['path'] == gDBus.patchbay.object_path:
  1058. if DEBUG: print("org.jackaudio.JackPatchbay,", kwds['member'])
  1059. if kwds['member'] == "ClientAppeared":
  1060. self.DBusJackClientAppearedCallback.emit(args[iJackClientId], args[iJackClientName])
  1061. elif kwds['member'] == "ClientDisappeared":
  1062. self.DBusJackClientDisappearedCallback.emit(args[iJackClientId])
  1063. elif kwds['interface'] == "org.gna.home.a2jmidid.control":
  1064. if DEBUG: print("org.gna.home.a2jmidid.control", kwds['member'])
  1065. if kwds['member'] == "bridge_started":
  1066. self.DBusA2JBridgeStartedCallback.emit()
  1067. elif kwds['member'] == "bridge_stopped":
  1068. self.DBusA2JBridgeStoppedCallback.emit()
  1069. def jackStarted(self):
  1070. self.m_last_dsp_load = gDBus.jack.GetLoad()
  1071. self.m_last_xruns = gDBus.jack.GetXruns()
  1072. self.m_last_buffer_size = gDBus.jack.GetBufferSize()
  1073. self.b_jack_start.setEnabled(False)
  1074. self.b_jack_stop.setEnabled(True)
  1075. self.b_jack_switchmaster.setEnabled(True)
  1076. self.systray.setActionEnabled("jack_start", False)
  1077. self.systray.setActionEnabled("jack_stop", True)
  1078. self.label_jack_status.setText("Started")
  1079. self.label_jack_status_ico.setPixmap(self.pix_apply)
  1080. if gDBus.jack.IsRealtime():
  1081. self.label_jack_realtime.setText("Yes")
  1082. self.label_jack_realtime_ico.setPixmap(self.pix_apply)
  1083. else:
  1084. self.label_jack_realtime.setText("No")
  1085. self.label_jack_realtime_ico.setPixmap(self.pix_cancel)
  1086. self.label_jack_dsp.setText("%.2f%%" % self.m_last_dsp_load)
  1087. self.label_jack_xruns.setText(str(self.m_last_xruns))
  1088. self.label_jack_bfsize.setText("%i samples" % self.m_last_buffer_size)
  1089. self.label_jack_srate.setText("%i Hz" % gDBus.jack.GetSampleRate())
  1090. self.label_jack_latency.setText("%.1f ms" % gDBus.jack.GetLatency())
  1091. self.m_timer500 = self.startTimer(500)
  1092. if gDBus.a2j and not gDBus.a2j.is_started():
  1093. self.b_a2j_start.setEnabled(True)
  1094. self.systray.setActionEnabled("a2j_start", True)
  1095. self.checkAlsaAudio()
  1096. self.checkPulseAudio()
  1097. def jackStopped(self):
  1098. if self.m_timer500:
  1099. self.killTimer(self.m_timer500)
  1100. self.m_timer500 = None
  1101. self.m_last_dsp_load = None
  1102. self.m_last_xruns = None
  1103. self.m_last_buffer_size = None
  1104. self.b_jack_start.setEnabled(True)
  1105. self.b_jack_stop.setEnabled(False)
  1106. self.b_jack_switchmaster.setEnabled(False)
  1107. if haveDBus:
  1108. self.systray.setActionEnabled("jack_start", True)
  1109. self.systray.setActionEnabled("jack_stop", False)
  1110. self.label_jack_status.setText("Stopped")
  1111. self.label_jack_status_ico.setPixmap(self.pix_cancel)
  1112. self.label_jack_dsp.setText("---")
  1113. self.label_jack_xruns.setText("---")
  1114. self.label_jack_bfsize.setText("---")
  1115. self.label_jack_srate.setText("---")
  1116. self.label_jack_latency.setText("---")
  1117. if gDBus.a2j:
  1118. self.b_a2j_start.setEnabled(False)
  1119. self.systray.setActionEnabled("a2j_start", False)
  1120. global jackClientIdALSA, jackClientIdPulse
  1121. jackClientIdALSA = -1
  1122. jackClientIdPulse = -1
  1123. if haveDBus:
  1124. self.checkAlsaAudio()
  1125. self.checkPulseAudio()
  1126. def a2jStarted(self):
  1127. self.b_a2j_start.setEnabled(False)
  1128. self.b_a2j_stop.setEnabled(True)
  1129. self.b_a2j_export_hw.setEnabled(False)
  1130. self.systray.setActionEnabled("a2j_start", False)
  1131. self.systray.setActionEnabled("a2j_stop", True)
  1132. self.systray.setActionEnabled("a2j_export_hw", False)
  1133. self.label_bridge_a2j.setText(self.tr("ALSA MIDI Bridge is running"))
  1134. def a2jStopped(self):
  1135. jackRunning = bool(gDBus.jack and gDBus.jack.IsStarted())
  1136. self.b_a2j_start.setEnabled(jackRunning)
  1137. self.b_a2j_stop.setEnabled(False)
  1138. self.b_a2j_export_hw.setEnabled(True)
  1139. self.systray.setActionEnabled("a2j_start", jackRunning)
  1140. self.systray.setActionEnabled("a2j_stop", False)
  1141. self.systray.setActionEnabled("a2j_export_hw", True)
  1142. self.label_bridge_a2j.setText(self.tr("ALSA MIDI Bridge is stopped"))
  1143. def checkAlsaAudio(self):
  1144. asoundrcFile = os.path.join(HOME, ".asoundrc")
  1145. if not os.path.exists(asoundrcFile):
  1146. self.b_alsa_start.setEnabled(False)
  1147. self.b_alsa_stop.setEnabled(False)
  1148. self.cb_alsa_type.setCurrentIndex(iAlsaFileNone)
  1149. self.tb_alsa_options.setEnabled(False)
  1150. self.label_bridge_alsa.setText(self.tr("No bridge in use"))
  1151. self.m_lastAlsaIndexType = -1 # null
  1152. return
  1153. asoundrcFd = open(asoundrcFile, "r")
  1154. asoundrcRead = asoundrcFd.read().strip()
  1155. asoundrcFd.close()
  1156. if asoundrcRead.startswith(asoundrc_aloop_check):
  1157. if isAlsaAudioBridged():
  1158. self.b_alsa_start.setEnabled(False)
  1159. self.b_alsa_stop.setEnabled(True)
  1160. self.systray.setActionEnabled("alsa_start", False)
  1161. self.systray.setActionEnabled("alsa_stop", True)
  1162. self.label_bridge_alsa.setText(self.tr("Using Cadence snd-aloop daemon, started"))
  1163. else:
  1164. try:
  1165. jackRunning = bool(gDBus.jack and gDBus.jack.IsStarted())
  1166. except:
  1167. jackRunning = False
  1168. self.b_alsa_start.setEnabled(jackRunning)
  1169. self.b_alsa_stop.setEnabled(False)
  1170. self.systray.setActionEnabled("alsa_start", jackRunning)
  1171. self.systray.setActionEnabled("alsa_stop", False)
  1172. self.label_bridge_alsa.setText(self.tr("Using Cadence snd-aloop daemon, stopped"))
  1173. self.cb_alsa_type.setCurrentIndex(iAlsaFileLoop)
  1174. self.tb_alsa_options.setEnabled(True)
  1175. elif asoundrcRead == asoundrc_jack:
  1176. self.b_alsa_start.setEnabled(False)
  1177. self.b_alsa_stop.setEnabled(False)
  1178. self.systray.setActionEnabled("alsa_start", False)
  1179. self.systray.setActionEnabled("alsa_stop", False)
  1180. self.cb_alsa_type.setCurrentIndex(iAlsaFileJACK)
  1181. self.tb_alsa_options.setEnabled(False)
  1182. self.label_bridge_alsa.setText(self.tr("Using JACK plugin bridge (Always on)"))
  1183. elif asoundrcRead == asoundrc_pulse:
  1184. self.b_alsa_start.setEnabled(False)
  1185. self.b_alsa_stop.setEnabled(False)
  1186. self.systray.setActionEnabled("alsa_start", False)
  1187. self.systray.setActionEnabled("alsa_stop", False)
  1188. self.cb_alsa_type.setCurrentIndex(iAlsaFilePulse)
  1189. self.tb_alsa_options.setEnabled(False)
  1190. self.label_bridge_alsa.setText(self.tr("Using PulseAudio plugin bridge (Always on)"))
  1191. else:
  1192. self.b_alsa_start.setEnabled(False)
  1193. self.b_alsa_stop.setEnabled(False)
  1194. self.systray.setActionEnabled("alsa_start", False)
  1195. self.systray.setActionEnabled("alsa_stop", False)
  1196. self.cb_alsa_type.addItem(self.tr("Custom"))
  1197. self.cb_alsa_type.setCurrentIndex(iAlsaFileMax)
  1198. self.tb_alsa_options.setEnabled(True)
  1199. self.label_bridge_alsa.setText(self.tr("Using custom asoundrc, not managed by Cadence"))
  1200. self.m_lastAlsaIndexType = self.cb_alsa_type.currentIndex()
  1201. def checkPulseAudio(self):
  1202. if not havePulseAudio:
  1203. self.systray.setActionEnabled("pulse_start", False)
  1204. self.systray.setActionEnabled("pulse_stop", False)
  1205. return
  1206. if isPulseAudioStarted():
  1207. if isPulseAudioBridged():
  1208. self.b_pulse_start.setEnabled(False)
  1209. self.b_pulse_stop.setEnabled(True)
  1210. self.systray.setActionEnabled("pulse_start", False)
  1211. self.systray.setActionEnabled("pulse_stop", True)
  1212. self.label_bridge_pulse.setText(self.tr("PulseAudio is started and bridged to JACK"))
  1213. else:
  1214. jackRunning = bool(gDBus.jack and gDBus.jack.IsStarted())
  1215. self.b_pulse_start.setEnabled(jackRunning)
  1216. self.b_pulse_stop.setEnabled(False)
  1217. self.systray.setActionEnabled("pulse_start", jackRunning)
  1218. self.systray.setActionEnabled("pulse_stop", False)
  1219. self.label_bridge_pulse.setText(self.tr("PulseAudio is started but not bridged"))
  1220. else:
  1221. jackRunning = bool(gDBus.jack and gDBus.jack.IsStarted())
  1222. self.b_pulse_start.setEnabled(jackRunning)
  1223. self.b_pulse_stop.setEnabled(False)
  1224. self.systray.setActionEnabled("pulse_start", jackRunning)
  1225. self.systray.setActionEnabled("pulse_stop", False)
  1226. self.label_bridge_pulse.setText(self.tr("PulseAudio is not started"))
  1227. def setAppDetails(self, desktop):
  1228. appContents = getDesktopFileContents(desktop)
  1229. name = getXdgProperty(appContents, "Name")
  1230. icon = getXdgProperty(appContents, "Icon")
  1231. comment = getXdgProperty(appContents, "Comment")
  1232. if not name:
  1233. name = self.cb_app_image.currentText().replace(".desktop","").title()
  1234. if not icon:
  1235. icon = ""
  1236. if not comment:
  1237. comment = ""
  1238. self.ico_app.setPixmap(getIcon(icon, 48).pixmap(48, 48))
  1239. self.label_app_name.setText(name)
  1240. self.label_app_comment.setText(comment)
  1241. def updateSystrayTooltip(self):
  1242. systrayText = "Cadence<br/>"
  1243. systrayText += "<font size=\"-1\">"
  1244. systrayText += "<b>%s:</b>&nbsp;%s<br/>" % (self.tr("JACK Status"), self.label_jack_status.text())
  1245. systrayText += "<b>%s:</b>&nbsp;%s<br/>" % (self.tr("Realtime"), self.label_jack_realtime.text())
  1246. systrayText += "<b>%s:</b>&nbsp;%s<br/>" % (self.tr("DSP Load"), self.label_jack_dsp.text())
  1247. systrayText += "<b>%s:</b>&nbsp;%s<br/>" % (self.tr("Xruns"), self.label_jack_xruns.text())
  1248. systrayText += "<b>%s:</b>&nbsp;%s<br/>" % (self.tr("Buffer Size"), self.label_jack_bfsize.text())
  1249. systrayText += "<b>%s:</b>&nbsp;%s<br/>" % (self.tr("Sample Rate"), self.label_jack_srate.text())
  1250. systrayText += "<b>%s:</b>&nbsp;%s" % (self.tr("Block Latency"), self.label_jack_latency.text())
  1251. systrayText += "</font><font size=\"-2\"><br/></font>"
  1252. self.systray.setToolTip(systrayText)
  1253. @pyqtSlot()
  1254. def func_start_catarina(self):
  1255. self.func_start_tool("catarina")
  1256. @pyqtSlot()
  1257. def func_start_catia(self):
  1258. self.func_start_tool("catia")
  1259. @pyqtSlot()
  1260. def func_start_claudia(self):
  1261. self.func_start_tool("claudia")
  1262. @pyqtSlot()
  1263. def func_start_logs(self):
  1264. self.func_start_tool("cadence-logs")
  1265. @pyqtSlot()
  1266. def func_start_jackmeter(self):
  1267. self.func_start_tool("cadence-jackmeter")
  1268. @pyqtSlot()
  1269. def func_start_jackmeter_in(self):
  1270. self.func_start_tool("cadence-jackmeter -in")
  1271. @pyqtSlot()
  1272. def func_start_render(self):
  1273. self.func_start_tool("cadence-render")
  1274. @pyqtSlot()
  1275. def func_start_xycontroller(self):
  1276. self.func_start_tool("cadence-xycontroller")
  1277. def func_start_tool(self, tool):
  1278. if sys.argv[0].endswith(".py"):
  1279. if tool == "cadence-logs":
  1280. tool = "logs"
  1281. elif tool == "cadence-render":
  1282. tool = "render"
  1283. stool = tool.split(" ", 1)[0]
  1284. if stool in ("cadence-jackmeter", "cadence-xycontroller"):
  1285. python = ""
  1286. localPath = os.path.join(sys.path[0], "..", "c++", stool.replace("cadence-", ""))
  1287. if os.path.exists(os.path.join(localPath, stool)):
  1288. base = localPath + os.sep
  1289. else:
  1290. base = ""
  1291. else:
  1292. python = sys.executable
  1293. tool += ".py"
  1294. base = sys.argv[0].rsplit("cadence.py", 1)[0]
  1295. if python:
  1296. python += " "
  1297. cmd = "%s%s%s &" % (python, base, tool)
  1298. print(cmd)
  1299. os.system(cmd)
  1300. elif sys.argv[0].endswith("/cadence"):
  1301. base = sys.argv[0].rsplit("/cadence", 1)[0]
  1302. os.system("%s/%s &" % (base, tool))
  1303. else:
  1304. os.system("%s &" % tool)
  1305. def func_settings_changed(self, stype):
  1306. if stype not in self.settings_changed_types:
  1307. self.settings_changed_types.append(stype)
  1308. self.frame_tweaks_settings.setVisible(True)
  1309. @pyqtSlot()
  1310. def slot_DBusJackServerStartedCallback(self):
  1311. self.jackStarted()
  1312. @pyqtSlot()
  1313. def slot_DBusJackServerStoppedCallback(self):
  1314. self.jackStopped()
  1315. @pyqtSlot(int, str)
  1316. def slot_DBusJackClientAppearedCallback(self, group_id, group_name):
  1317. if group_name == "alsa2jack":
  1318. global jackClientIdALSA
  1319. jackClientIdALSA = group_id
  1320. self.checkAlsaAudio()
  1321. elif group_name == "PulseAudio JACK Sink":
  1322. global jackClientIdPulse
  1323. jackClientIdPulse = group_id
  1324. self.checkPulseAudio()
  1325. @pyqtSlot(int)
  1326. def slot_DBusJackClientDisappearedCallback(self, group_id):
  1327. global jackClientIdALSA, jackClientIdPulse
  1328. if group_id == jackClientIdALSA:
  1329. jackClientIdALSA = -1
  1330. self.checkAlsaAudio()
  1331. elif group_id == jackClientIdPulse:
  1332. jackClientIdPulse = -1
  1333. self.checkPulseAudio()
  1334. @pyqtSlot()
  1335. def slot_DBusA2JBridgeStartedCallback(self):
  1336. self.a2jStarted()
  1337. @pyqtSlot()
  1338. def slot_DBusA2JBridgeStoppedCallback(self):
  1339. self.a2jStopped()
  1340. @pyqtSlot()
  1341. def slot_JackServerStart(self):
  1342. self.saveSettings()
  1343. try:
  1344. gDBus.jack.StartServer()
  1345. except:
  1346. QMessageBox.warning(self, self.tr("Warning"), self.tr("Failed to start JACK, please check the logs for more information."))
  1347. @pyqtSlot()
  1348. def slot_JackServerStop(self):
  1349. try:
  1350. gDBus.jack.StopServer()
  1351. except:
  1352. QMessageBox.warning(self, self.tr("Warning"), self.tr("Failed to stop JACK, please check the logs for more information."))
  1353. @pyqtSlot()
  1354. def slot_JackServerForceRestart(self):
  1355. if gDBus.jack.IsStarted():
  1356. ask = CustomMessageBox(self, QMessageBox.Warning, self.tr("Warning"),
  1357. self.tr("This will force kill all JACK applications!<br>Make sure to save your projects before continue."),
  1358. self.tr("Are you sure you want to force the restart of JACK?"))
  1359. if ask != QMessageBox.Yes:
  1360. return
  1361. if self.m_timer500:
  1362. self.killTimer(self.m_timer500)
  1363. self.m_timer500 = None
  1364. self.saveSettings()
  1365. ForceWaitDialog(self).exec_()
  1366. @pyqtSlot()
  1367. def slot_JackServerConfigure(self):
  1368. jacksettingsW = jacksettings.JackSettingsW(self)
  1369. jacksettingsW.exec_()
  1370. del jacksettingsW
  1371. @pyqtSlot()
  1372. def slot_JackServerSwitchMaster(self):
  1373. try:
  1374. gDBus.jack.SwitchMaster()
  1375. except:
  1376. QMessageBox.warning(self, self.tr("Warning"), self.tr("Failed to switch JACK master, please check the logs for more information."))
  1377. return
  1378. self.jackStarted()
  1379. @pyqtSlot()
  1380. def slot_JackOptions(self):
  1381. ToolBarJackDialog(self).exec_()
  1382. @pyqtSlot()
  1383. def slot_JackClearXruns(self):
  1384. if gDBus.jack:
  1385. gDBus.jack.ResetXruns()
  1386. @pyqtSlot()
  1387. def slot_AlsaBridgeStart(self):
  1388. self.slot_AlsaBridgeStop()
  1389. startAlsaAudioLoopBridge()
  1390. @pyqtSlot()
  1391. def slot_AlsaBridgeStop(self):
  1392. checkFile = "/tmp/.cadence-aloop-daemon.x"
  1393. if os.path.exists(checkFile):
  1394. os.remove(checkFile)
  1395. @pyqtSlot(int)
  1396. def slot_AlsaBridgeChanged(self, index):
  1397. if self.m_lastAlsaIndexType == -2 or self.m_lastAlsaIndexType == index:
  1398. return
  1399. if self.m_lastAlsaIndexType == iAlsaFileMax:
  1400. ask = CustomMessageBox(self, QMessageBox.Warning, self.tr("Warning"),
  1401. self.tr(""
  1402. "You're using a custom ~/.asoundrc file not managed by Cadence.<br/>"
  1403. "By choosing to use a Cadence ALSA-Audio bridge, <b>the file will be replaced</b>."
  1404. ""),
  1405. self.tr("Are you sure you want to do this?"))
  1406. if ask == QMessageBox.Yes:
  1407. self.cb_alsa_type.blockSignals(True)
  1408. self.cb_alsa_type.removeItem(iAlsaFileMax)
  1409. self.cb_alsa_type.setCurrentIndex(index)
  1410. self.cb_alsa_type.blockSignals(False)
  1411. else:
  1412. self.cb_alsa_type.blockSignals(True)
  1413. self.cb_alsa_type.setCurrentIndex(iAlsaFileMax)
  1414. self.cb_alsa_type.blockSignals(False)
  1415. return
  1416. asoundrcFile = os.path.join(HOME, ".asoundrc")
  1417. if index == iAlsaFileNone:
  1418. os.remove(asoundrcFile)
  1419. elif index == iAlsaFileLoop:
  1420. asoundrcFd = open(asoundrcFile, "w")
  1421. asoundrcFd.write(asoundrc_aloop+"\n")
  1422. asoundrcFd.close()
  1423. elif index == iAlsaFileJACK:
  1424. asoundrcFd = open(asoundrcFile, "w")
  1425. asoundrcFd.write(asoundrc_jack+"\n")
  1426. asoundrcFd.close()
  1427. elif index == iAlsaFilePulse:
  1428. asoundrcFd = open(asoundrcFile, "w")
  1429. asoundrcFd.write(asoundrc_pulse+"\n")
  1430. asoundrcFd.close()
  1431. else:
  1432. print("Cadence::AlsaBridgeChanged(%i) - invalid index" % index)
  1433. self.checkAlsaAudio()
  1434. @pyqtSlot()
  1435. def slot_AlsaAudioBridgeOptions(self):
  1436. ToolBarAlsaAudioDialog(self, (self.cb_alsa_type.currentIndex() != iAlsaFileLoop)).exec_()
  1437. @pyqtSlot()
  1438. def slot_A2JBridgeStart(self):
  1439. gDBus.a2j.start()
  1440. @pyqtSlot()
  1441. def slot_A2JBridgeStop(self):
  1442. gDBus.a2j.stop()
  1443. @pyqtSlot()
  1444. def slot_A2JBridgeExportHW(self):
  1445. ask = QMessageBox.question(self, self.tr("ALSA MIDI Hardware Export"), self.tr("Enable Hardware Export on the ALSA MIDI Bridge?"), QMessageBox.Yes|QMessageBox.No|QMessageBox.Cancel, QMessageBox.Yes)
  1446. if ask == QMessageBox.Yes:
  1447. gDBus.a2j.set_hw_export(True)
  1448. elif ask == QMessageBox.No:
  1449. gDBus.a2j.set_hw_export(False)
  1450. @pyqtSlot()
  1451. def slot_A2JBridgeOptions(self):
  1452. ToolBarA2JDialog(self).exec_()
  1453. @pyqtSlot()
  1454. def slot_PulseAudioBridgeStart(self):
  1455. if GlobalSettings.value("Pulse2JACK/PlaybackModeOnly", False, type=bool):
  1456. os.system("cadence-pulse2jack -p")
  1457. else:
  1458. os.system("cadence-pulse2jack")
  1459. @pyqtSlot()
  1460. def slot_PulseAudioBridgeStop(self):
  1461. os.system("pulseaudio -k")
  1462. @pyqtSlot()
  1463. def slot_PulseAudioBridgeOptions(self):
  1464. ToolBarPADialog(self).exec_()
  1465. @pyqtSlot()
  1466. def slot_handleCrash_jack(self):
  1467. self.DBusReconnect()
  1468. @pyqtSlot()
  1469. def slot_handleCrash_a2j(self):
  1470. pass
  1471. @pyqtSlot(str)
  1472. def slot_changeGovernorMode(self, newMode):
  1473. bus = dbus.SystemBus(mainloop=gDBus.loop)
  1474. #proxy = bus.get_object("org.cadence.CpufreqSelector", "/Selector", introspect=False)
  1475. #print(proxy.hello())
  1476. proxy = bus.get_object("com.ubuntu.IndicatorCpufreqSelector", "/Selector", introspect=False)
  1477. proxy.SetGovernor(self.m_curGovCPUs, newMode, dbus_interface="com.ubuntu.IndicatorCpufreqSelector")
  1478. @pyqtSlot()
  1479. def slot_governorFileChanged(self):
  1480. curGovFd = open(self.m_curGovPath, "r")
  1481. curGovRead = curGovFd.read().strip()
  1482. curGovFd.close()
  1483. customTr = self.tr("Custom")
  1484. if self.cb_cpufreq.currentIndex() == -1:
  1485. # First init
  1486. self.cb_cpufreq.currentIndexChanged[str].connect(self.slot_changeGovernorMode)
  1487. self.cb_cpufreq.blockSignals(True)
  1488. if curGovRead in self.m_availGovList:
  1489. self.cb_cpufreq.setCurrentIndex(self.m_availGovList.index(curGovRead))
  1490. if customTr in self.m_availGovList:
  1491. self.m_availGovList.remove(customTr)
  1492. else:
  1493. if customTr not in self.m_availGovList:
  1494. self.cb_cpufreq.addItem(customTr)
  1495. self.m_availGovList.append(customTr)
  1496. self.cb_cpufreq.setCurrentIndex(len(self.m_availGovList)-1)
  1497. self.cb_cpufreq.blockSignals(False)
  1498. @pyqtSlot()
  1499. def slot_tweaksApply(self):
  1500. if "plugins" in self.settings_changed_types:
  1501. EXTRA_LADSPA_DIRS = []
  1502. EXTRA_DSSI_DIRS = []
  1503. EXTRA_LV2_DIRS = []
  1504. EXTRA_VST_DIRS = []
  1505. for i in range(self.list_LADSPA.count()):
  1506. iPath = self.list_LADSPA.item(i).text()
  1507. if iPath not in DEFAULT_LADSPA_PATH and iPath not in EXTRA_LADSPA_DIRS:
  1508. EXTRA_LADSPA_DIRS.append(iPath)
  1509. for i in range(self.list_DSSI.count()):
  1510. iPath = self.list_DSSI.item(i).text()
  1511. if iPath not in DEFAULT_DSSI_PATH and iPath not in EXTRA_DSSI_DIRS:
  1512. EXTRA_DSSI_DIRS.append(iPath)
  1513. for i in range(self.list_LV2.count()):
  1514. iPath = self.list_LV2.item(i).text()
  1515. if iPath not in DEFAULT_LV2_PATH and iPath not in EXTRA_LV2_DIRS:
  1516. EXTRA_LV2_DIRS.append(iPath)
  1517. for i in range(self.list_VST.count()):
  1518. iPath = self.list_VST.item(i).text()
  1519. if iPath not in DEFAULT_VST_PATH and iPath not in EXTRA_VST_DIRS:
  1520. EXTRA_VST_DIRS.append(iPath)
  1521. GlobalSettings.setValue("AudioPlugins/EXTRA_LADSPA_PATH", ":".join(EXTRA_LADSPA_DIRS))
  1522. GlobalSettings.setValue("AudioPlugins/EXTRA_DSSI_PATH", ":".join(EXTRA_DSSI_DIRS))
  1523. GlobalSettings.setValue("AudioPlugins/EXTRA_LV2_PATH", ":".join(EXTRA_LV2_DIRS))
  1524. GlobalSettings.setValue("AudioPlugins/EXTRA_VST_PATH", ":".join(EXTRA_VST_DIRS))
  1525. if "apps" in self.settings_changed_types:
  1526. mimeFileContent = ""
  1527. # Fix common mime errors
  1528. mimeFileContent += "application/x-designer=designer-qt4.desktop;\n"
  1529. mimeFileContent += "application/x-ms-dos-executable=wine.desktop;\n"
  1530. mimeFileContent += "audio/x-minipsf=audacious.desktop;\n"
  1531. mimeFileContent += "audio/x-psf=audacious.desktop;\n"
  1532. if self.ch_app_image.isChecked():
  1533. imageApp = self.cb_app_image.currentText().replace("/","-")
  1534. mimeFileContent += "image/bmp=%s;\n" % imageApp
  1535. mimeFileContent += "image/gif=%s;\n" % imageApp
  1536. mimeFileContent += "image/jp2=%s;\n" % imageApp
  1537. mimeFileContent += "image/jpeg=%s;\n" % imageApp
  1538. mimeFileContent += "image/png=%s;\n" % imageApp
  1539. mimeFileContent += "image/svg+xml=%s;\n" % imageApp
  1540. mimeFileContent += "image/svg+xml-compressed=%s;\n" % imageApp
  1541. mimeFileContent += "image/tiff=%s;\n" % imageApp
  1542. mimeFileContent += "image/x-canon-cr2=%s;\n" % imageApp
  1543. mimeFileContent += "image/x-canon-crw=%s;\n" % imageApp
  1544. mimeFileContent += "image/x-eps=%s;\n" % imageApp
  1545. mimeFileContent += "image/x-kodak-dcr=%s;\n" % imageApp
  1546. mimeFileContent += "image/x-kodak-k25=%s;\n" % imageApp
  1547. mimeFileContent += "image/x-kodak-kdc=%s;\n" % imageApp
  1548. mimeFileContent += "image/x-nikon-nef=%s;\n" % imageApp
  1549. mimeFileContent += "image/x-olympus-orf=%s;\n" % imageApp
  1550. mimeFileContent += "image/x-panasonic-raw=%s;\n" % imageApp
  1551. mimeFileContent += "image/x-pcx=%s;\n" % imageApp
  1552. mimeFileContent += "image/x-pentax-pef=%s;\n" % imageApp
  1553. mimeFileContent += "image/x-portable-anymap=%s;\n" % imageApp
  1554. mimeFileContent += "image/x-portable-bitmap=%s;\n" % imageApp
  1555. mimeFileContent += "image/x-portable-graymap=%s;\n" % imageApp
  1556. mimeFileContent += "image/x-portable-pixmap=%s;\n" % imageApp
  1557. mimeFileContent += "image/x-sony-arw=%s;\n" % imageApp
  1558. mimeFileContent += "image/x-sony-sr2=%s;\n" % imageApp
  1559. mimeFileContent += "image/x-sony-srf=%s;\n" % imageApp
  1560. mimeFileContent += "image/x-tga=%s;\n" % imageApp
  1561. mimeFileContent += "image/x-xbitmap=%s;\n" % imageApp
  1562. mimeFileContent += "image/x-xpixmap=%s;\n" % imageApp
  1563. if self.ch_app_music.isChecked():
  1564. musicApp = self.cb_app_music.currentText().replace("/","-")
  1565. mimeFileContent += "application/vnd.apple.mpegurl=%s;\n" % musicApp
  1566. mimeFileContent += "application/xspf+xml=%s;\n" % musicApp
  1567. mimeFileContent += "application/x-smaf=%s;\n" % musicApp
  1568. mimeFileContent += "audio/AMR=%s;\n" % musicApp
  1569. mimeFileContent += "audio/AMR-WB=%s;\n" % musicApp
  1570. mimeFileContent += "audio/aac=%s;\n" % musicApp
  1571. mimeFileContent += "audio/ac3=%s;\n" % musicApp
  1572. mimeFileContent += "audio/basic=%s;\n" % musicApp
  1573. mimeFileContent += "audio/flac=%s;\n" % musicApp
  1574. mimeFileContent += "audio/m3u=%s;\n" % musicApp
  1575. mimeFileContent += "audio/mp2=%s;\n" % musicApp
  1576. mimeFileContent += "audio/mp4=%s;\n" % musicApp
  1577. mimeFileContent += "audio/mpeg=%s;\n" % musicApp
  1578. mimeFileContent += "audio/ogg=%s;\n" % musicApp
  1579. mimeFileContent += "audio/vnd.rn-realaudio=%s;\n" % musicApp
  1580. mimeFileContent += "audio/vorbis=%s;\n" % musicApp
  1581. mimeFileContent += "audio/webm=%s;\n" % musicApp
  1582. mimeFileContent += "audio/wav=%s;\n" % musicApp
  1583. mimeFileContent += "audio/x-adpcm=%s;\n" % musicApp
  1584. mimeFileContent += "audio/x-aifc=%s;\n" % musicApp
  1585. mimeFileContent += "audio/x-aiff=%s;\n" % musicApp
  1586. mimeFileContent += "audio/x-aiffc=%s;\n" % musicApp
  1587. mimeFileContent += "audio/x-ape=%s;\n" % musicApp
  1588. mimeFileContent += "audio/x-cda=%s;\n" % musicApp
  1589. mimeFileContent += "audio/x-flac=%s;\n" % musicApp
  1590. mimeFileContent += "audio/x-flac+ogg=%s;\n" % musicApp
  1591. mimeFileContent += "audio/x-gsm=%s;\n" % musicApp
  1592. mimeFileContent += "audio/x-m4b=%s;\n" % musicApp
  1593. mimeFileContent += "audio/x-matroska=%s;\n" % musicApp
  1594. mimeFileContent += "audio/x-mp2=%s;\n" % musicApp
  1595. mimeFileContent += "audio/x-mpegurl=%s;\n" % musicApp
  1596. mimeFileContent += "audio/x-ms-asx=%s;\n" % musicApp
  1597. mimeFileContent += "audio/x-ms-wma=%s;\n" % musicApp
  1598. mimeFileContent += "audio/x-musepack=%s;\n" % musicApp
  1599. mimeFileContent += "audio/x-ogg=%s;\n" % musicApp
  1600. mimeFileContent += "audio/x-oggflac=%s;\n" % musicApp
  1601. mimeFileContent += "audio/x-pn-realaudio-plugin=%s;\n" % musicApp
  1602. mimeFileContent += "audio/x-riff=%s;\n" % musicApp
  1603. mimeFileContent += "audio/x-scpls=%s;\n" % musicApp
  1604. mimeFileContent += "audio/x-speex=%s;\n" % musicApp
  1605. mimeFileContent += "audio/x-speex+ogg=%s;\n" % musicApp
  1606. mimeFileContent += "audio/x-tta=%s;\n" % musicApp
  1607. mimeFileContent += "audio/x-vorbis+ogg=%s;\n" % musicApp
  1608. mimeFileContent += "audio/x-wav=%s;\n" % musicApp
  1609. mimeFileContent += "audio/x-wavpack=%s;\n" % musicApp
  1610. if self.ch_app_video.isChecked():
  1611. videoApp = self.cb_app_video.currentText().replace("/","-")
  1612. mimeFileContent +="application/mxf=%s;\n" % videoApp
  1613. mimeFileContent +="application/ogg=%s;\n" % videoApp
  1614. mimeFileContent +="application/ram=%s;\n" % videoApp
  1615. mimeFileContent +="application/vnd.ms-asf=%s;\n" % videoApp
  1616. mimeFileContent +="application/vnd.ms-wpl=%s;\n" % videoApp
  1617. mimeFileContent +="application/vnd.rn-realmedia=%s;\n" % videoApp
  1618. mimeFileContent +="application/x-ms-wmp=%s;\n" % videoApp
  1619. mimeFileContent +="application/x-ms-wms=%s;\n" % videoApp
  1620. mimeFileContent +="application/x-netshow-channel=%s;\n" % videoApp
  1621. mimeFileContent +="application/x-ogg=%s;\n" % videoApp
  1622. mimeFileContent +="application/x-quicktime-media-link=%s;\n" % videoApp
  1623. mimeFileContent +="video/3gpp=%s;\n" % videoApp
  1624. mimeFileContent +="video/3gpp2=%s;\n" % videoApp
  1625. mimeFileContent +="video/divx=%s;\n" % videoApp
  1626. mimeFileContent +="video/dv=%s;\n" % videoApp
  1627. mimeFileContent +="video/flv=%s;\n" % videoApp
  1628. mimeFileContent +="video/mp2t=%s;\n" % videoApp
  1629. mimeFileContent +="video/mp4=%s;\n" % videoApp
  1630. mimeFileContent +="video/mpeg=%s;\n" % videoApp
  1631. mimeFileContent +="video/ogg=%s;\n" % videoApp
  1632. mimeFileContent +="video/quicktime=%s;\n" % videoApp
  1633. mimeFileContent +="video/vivo=%s;\n" % videoApp
  1634. mimeFileContent +="video/vnd.rn-realvideo=%s;\n" % videoApp
  1635. mimeFileContent +="video/webm=%s;\n" % videoApp
  1636. mimeFileContent +="video/x-anim=%s;\n" % videoApp
  1637. mimeFileContent +="video/x-flic=%s;\n" % videoApp
  1638. mimeFileContent +="video/x-flv=%s;\n" % videoApp
  1639. mimeFileContent +="video/x-m4v=%s;\n" % videoApp
  1640. mimeFileContent +="video/x-matroska=%s;\n" % videoApp
  1641. mimeFileContent +="video/x-ms-asf=%s;\n" % videoApp
  1642. mimeFileContent +="video/x-ms-wm=%s;\n" % videoApp
  1643. mimeFileContent +="video/x-ms-wmp=%s;\n" % videoApp
  1644. mimeFileContent +="video/x-ms-wmv=%s;\n" % videoApp
  1645. mimeFileContent +="video/x-ms-wvx=%s;\n" % videoApp
  1646. mimeFileContent +="video/x-msvideo=%s;\n" % videoApp
  1647. mimeFileContent +="video/x-nsv=%s;\n" % videoApp
  1648. mimeFileContent +="video/x-ogg=%s;\n" % videoApp
  1649. mimeFileContent +="video/x-ogm=%s;\n" % videoApp
  1650. mimeFileContent +="video/x-ogm+ogg=%s;\n" % videoApp
  1651. mimeFileContent +="video/x-theora=%s;\n" % videoApp
  1652. mimeFileContent +="video/x-theora+ogg=%s;\n" % videoApp
  1653. mimeFileContent +="video/x-wmv=%s;\n" % videoApp
  1654. if self.ch_app_text.isChecked():
  1655. # TODO - more mimetypes
  1656. textApp = self.cb_app_text.currentText().replace("/","-")
  1657. mimeFileContent +="application/rdf+xml=%s;\n" % textApp
  1658. mimeFileContent +="application/xml=%s;\n" % textApp
  1659. mimeFileContent +="application/xml-dtd=%s;\n" % textApp
  1660. mimeFileContent +="application/xml-external-parsed-entity=%s;\n" % textApp
  1661. mimeFileContent +="application/xsd=%s;\n" % textApp
  1662. mimeFileContent +="application/xslt+xml=%s;\n" % textApp
  1663. mimeFileContent +="application/x-trash=%s;\n" % textApp
  1664. mimeFileContent +="application/x-wine-extension-inf=%s;\n" % textApp
  1665. mimeFileContent +="application/x-wine-extension-ini=%s;\n" % textApp
  1666. mimeFileContent +="application/x-zerosize=%s;\n" % textApp
  1667. mimeFileContent +="text/css=%s;\n" % textApp
  1668. mimeFileContent +="text/plain=%s;\n" % textApp
  1669. mimeFileContent +="text/x-authors=%s;\n" % textApp
  1670. mimeFileContent +="text/x-c++-hdr=%s;\n" % textApp
  1671. mimeFileContent +="text/x-c++-src=%s;\n" % textApp
  1672. mimeFileContent +="text/x-changelog=%s;\n" % textApp
  1673. mimeFileContent +="text/x-chdr=%s;\n" % textApp
  1674. mimeFileContent +="text/x-cmake=%s;\n" % textApp
  1675. mimeFileContent +="text/x-copying=%s;\n" % textApp
  1676. mimeFileContent +="text/x-credits=%s;\n" % textApp
  1677. mimeFileContent +="text/x-csharp=%s;\n" % textApp
  1678. mimeFileContent +="text/x-csrc=%s;\n" % textApp
  1679. mimeFileContent +="text/x-install=%s;\n" % textApp
  1680. mimeFileContent +="text/x-log=%s;\n" % textApp
  1681. mimeFileContent +="text/x-lua=%s;\n" % textApp
  1682. mimeFileContent +="text/x-makefile=%s;\n" % textApp
  1683. mimeFileContent +="text/x-ms-regedit=%s;\n" % textApp
  1684. mimeFileContent +="text/x-nfo=%s;\n" % textApp
  1685. mimeFileContent +="text/x-objchdr=%s;\n" % textApp
  1686. mimeFileContent +="text/x-objcsrc=%s;\n" % textApp
  1687. mimeFileContent +="text/x-pascal=%s;\n" % textApp
  1688. mimeFileContent +="text/x-patch=%s;\n" % textApp
  1689. mimeFileContent +="text/x-python=%s;\n" % textApp
  1690. mimeFileContent +="text/x-readme=%s;\n" % textApp
  1691. mimeFileContent +="text/x-vhdl=%s;\n" % textApp
  1692. if self.ch_app_browser.isChecked():
  1693. # TODO - needs something else for default browser
  1694. browserApp = self.cb_app_browser.currentText().replace("/","-")
  1695. mimeFileContent +="application/atom+xml=%s;\n" % browserApp
  1696. mimeFileContent +="application/rss+xml=%s;\n" % browserApp
  1697. mimeFileContent +="application/vnd.mozilla.xul+xml=%s;\n" % browserApp
  1698. mimeFileContent +="application/x-mozilla-bookmarks=%s;\n" % browserApp
  1699. mimeFileContent +="application/x-mswinurl=%s;\n" % browserApp
  1700. mimeFileContent +="application/x-xbel=%s;\n" % browserApp
  1701. mimeFileContent +="application/xhtml+xml=%s;\n" % browserApp
  1702. mimeFileContent +="text/html=%s;\n" % browserApp
  1703. mimeFileContent +="text/opml+xml=%s;\n" % browserApp
  1704. realMimeFileContent ="[Default Applications]\n"
  1705. realMimeFileContent += mimeFileContent
  1706. realMimeFileContent +="\n"
  1707. realMimeFileContent +="[Added Associations]\n"
  1708. realMimeFileContent += mimeFileContent
  1709. realMimeFileContent +="\n"
  1710. local_xdg_defaults = os.path.join(HOME, ".local", "share", "applications", "defaults.list")
  1711. local_xdg_mimeapps = os.path.join(HOME, ".local", "share", "applications", "mimeapps.list")
  1712. writeFile = open(local_xdg_defaults, "w")
  1713. writeFile.write(realMimeFileContent)
  1714. writeFile.close()
  1715. writeFile = open(local_xdg_mimeapps, "w")
  1716. writeFile.write(realMimeFileContent)
  1717. writeFile.close()
  1718. if "wineasio" in self.settings_changed_types:
  1719. REGFILE = 'REGEDIT4\n'
  1720. REGFILE += '\n'
  1721. REGFILE += '[HKEY_CURRENT_USER\Software\Wine\WineASIO]\n'
  1722. REGFILE += '"Autostart server"=dword:0000000%i\n' % int(1 if self.cb_wineasio_autostart.isChecked() else 0)
  1723. REGFILE += '"Connect to hardware"=dword:0000000%i\n' % int(1 if self.cb_wineasio_hw.isChecked() else 0)
  1724. REGFILE += '"Fixed buffersize"=dword:0000000%i\n' % int(1 if self.cb_wineasio_fixed_bsize.isChecked() else 0)
  1725. REGFILE += '"Number of inputs"=dword:000000%s\n' % smartHex(self.sb_wineasio_ins.value(), 2)
  1726. REGFILE += '"Number of outputs"=dword:000000%s\n' % smartHex(self.sb_wineasio_outs.value(), 2)
  1727. REGFILE += '"Preferred buffersize"=dword:0000%s\n' % smartHex(int(self.cb_wineasio_bsizes.currentText()), 4)
  1728. writeFile = open("/tmp/cadence-wineasio.reg", "w")
  1729. writeFile.write(REGFILE)
  1730. writeFile.close()
  1731. os.system("regedit /tmp/cadence-wineasio.reg")
  1732. self.settings_changed_types = []
  1733. self.frame_tweaks_settings.setVisible(False)
  1734. @pyqtSlot()
  1735. def slot_tweaksSettingsChanged_apps(self):
  1736. self.func_settings_changed("apps")
  1737. @pyqtSlot()
  1738. def slot_tweaksSettingsChanged_wineasio(self):
  1739. self.func_settings_changed("wineasio")
  1740. @pyqtSlot(int)
  1741. def slot_tweakAppImageHighlighted(self, index):
  1742. self.setAppDetails(self.cb_app_image.itemText(index))
  1743. @pyqtSlot(int)
  1744. def slot_tweakAppImageChanged(self, ignored):
  1745. self.setAppDetails(self.cb_app_image.currentText())
  1746. self.func_settings_changed("apps")
  1747. @pyqtSlot(int)
  1748. def slot_tweakAppMusicHighlighted(self, index):
  1749. self.setAppDetails(self.cb_app_music.itemText(index))
  1750. @pyqtSlot(int)
  1751. def slot_tweakAppMusicChanged(self, ignored):
  1752. self.setAppDetails(self.cb_app_music.currentText())
  1753. self.func_settings_changed("apps")
  1754. @pyqtSlot(int)
  1755. def slot_tweakAppVideoHighlighted(self, index):
  1756. self.setAppDetails(self.cb_app_video.itemText(index))
  1757. @pyqtSlot(int)
  1758. def slot_tweakAppVideoChanged(self, ignored):
  1759. self.setAppDetails(self.cb_app_video.currentText())
  1760. self.func_settings_changed("apps")
  1761. @pyqtSlot(int)
  1762. def slot_tweakAppTextHighlighted(self, index):
  1763. self.setAppDetails(self.cb_app_text.itemText(index))
  1764. @pyqtSlot(int)
  1765. def slot_tweakAppTextChanged(self, ignored):
  1766. self.setAppDetails(self.cb_app_text.currentText())
  1767. self.func_settings_changed("apps")
  1768. @pyqtSlot(int)
  1769. def slot_tweakAppBrowserHighlighted(self, index):
  1770. self.setAppDetails(self.cb_app_browser.itemText(index))
  1771. @pyqtSlot(int)
  1772. def slot_tweakAppBrowserChanged(self, ignored):
  1773. self.setAppDetails(self.cb_app_browser.currentText())
  1774. self.func_settings_changed("apps")
  1775. @pyqtSlot()
  1776. def slot_tweakPluginAdd(self):
  1777. newPath = QFileDialog.getExistingDirectory(self, self.tr("Add Path"), "", QFileDialog.ShowDirsOnly)
  1778. if not newPath:
  1779. return
  1780. if self.tb_tweak_plugins.currentIndex() == 0:
  1781. self.list_LADSPA.addItem(newPath)
  1782. elif self.tb_tweak_plugins.currentIndex() == 1:
  1783. self.list_DSSI.addItem(newPath)
  1784. elif self.tb_tweak_plugins.currentIndex() == 2:
  1785. self.list_LV2.addItem(newPath)
  1786. elif self.tb_tweak_plugins.currentIndex() == 3:
  1787. self.list_VST.addItem(newPath)
  1788. self.func_settings_changed("plugins")
  1789. @pyqtSlot()
  1790. def slot_tweakPluginChange(self):
  1791. if self.tb_tweak_plugins.currentIndex() == 0:
  1792. curPath = self.list_LADSPA.item(self.list_LADSPA.currentRow()).text()
  1793. elif self.tb_tweak_plugins.currentIndex() == 1:
  1794. curPath = self.list_DSSI.item(self.list_DSSI.currentRow()).text()
  1795. elif self.tb_tweak_plugins.currentIndex() == 2:
  1796. curPath = self.list_LV2.item(self.list_LV2.currentRow()).text()
  1797. elif self.tb_tweak_plugins.currentIndex() == 3:
  1798. curPath = self.list_VST.item(self.list_VST.currentRow()).text()
  1799. else:
  1800. curPath = ""
  1801. newPath = QFileDialog.getExistingDirectory(self, self.tr("Change Path"), curPath, QFileDialog.ShowDirsOnly)
  1802. if not newPath:
  1803. return
  1804. if self.tb_tweak_plugins.currentIndex() == 0:
  1805. self.list_LADSPA.item(self.list_LADSPA.currentRow()).setText(newPath)
  1806. elif self.tb_tweak_plugins.currentIndex() == 1:
  1807. self.list_DSSI.item(self.list_DSSI.currentRow()).setText(newPath)
  1808. elif self.tb_tweak_plugins.currentIndex() == 2:
  1809. self.list_LV2.item(self.list_LV2.currentRow()).setText(newPath)
  1810. elif self.tb_tweak_plugins.currentIndex() == 3:
  1811. self.list_VST.item(self.list_VST.currentRow()).setText(newPath)
  1812. self.func_settings_changed("plugins")
  1813. @pyqtSlot()
  1814. def slot_tweakPluginRemove(self):
  1815. if self.tb_tweak_plugins.currentIndex() == 0:
  1816. self.list_LADSPA.takeItem(self.list_LADSPA.currentRow())
  1817. elif self.tb_tweak_plugins.currentIndex() == 1:
  1818. self.list_DSSI.takeItem(self.list_DSSI.currentRow())
  1819. elif self.tb_tweak_plugins.currentIndex() == 2:
  1820. self.list_LV2.takeItem(self.list_LV2.currentRow())
  1821. elif self.tb_tweak_plugins.currentIndex() == 3:
  1822. self.list_VST.takeItem(self.list_VST.currentRow())
  1823. self.func_settings_changed("plugins")
  1824. @pyqtSlot()
  1825. def slot_tweakPluginReset(self):
  1826. if self.tb_tweak_plugins.currentIndex() == 0:
  1827. self.list_LADSPA.clear()
  1828. for iPath in DEFAULT_LADSPA_PATH:
  1829. self.list_LADSPA.addItem(iPath)
  1830. elif self.tb_tweak_plugins.currentIndex() == 1:
  1831. self.list_DSSI.clear()
  1832. for iPath in DEFAULT_DSSI_PATH:
  1833. self.list_DSSI.addItem(iPath)
  1834. elif self.tb_tweak_plugins.currentIndex() == 2:
  1835. self.list_LV2.clear()
  1836. for iPath in DEFAULT_LV2_PATH:
  1837. self.list_LV2.addItem(iPath)
  1838. elif self.tb_tweak_plugins.currentIndex() == 3:
  1839. self.list_VST.clear()
  1840. for iPath in DEFAULT_VST_PATH:
  1841. self.list_VST.addItem(iPath)
  1842. self.func_settings_changed("plugins")
  1843. @pyqtSlot(int)
  1844. def slot_tweakPluginTypeChanged(self, index):
  1845. # Force row change
  1846. if index == 0:
  1847. self.list_LADSPA.setCurrentRow(-1)
  1848. self.list_LADSPA.setCurrentRow(0)
  1849. elif index == 1:
  1850. self.list_DSSI.setCurrentRow(-1)
  1851. self.list_DSSI.setCurrentRow(0)
  1852. elif index == 2:
  1853. self.list_LV2.setCurrentRow(-1)
  1854. self.list_LV2.setCurrentRow(0)
  1855. elif index == 3:
  1856. self.list_VST.setCurrentRow(-1)
  1857. self.list_VST.setCurrentRow(0)
  1858. @pyqtSlot(int)
  1859. def slot_tweakPluginsLadspaRowChanged(self, index):
  1860. nonRemovable = (index >= 0 and self.list_LADSPA.item(index).text() not in DEFAULT_LADSPA_PATH)
  1861. self.b_tweak_plugins_change.setEnabled(nonRemovable)
  1862. self.b_tweak_plugins_remove.setEnabled(nonRemovable)
  1863. @pyqtSlot(int)
  1864. def slot_tweakPluginsDssiRowChanged(self, index):
  1865. nonRemovable = (index >= 0 and self.list_DSSI.item(index).text() not in DEFAULT_DSSI_PATH)
  1866. self.b_tweak_plugins_change.setEnabled(nonRemovable)
  1867. self.b_tweak_plugins_remove.setEnabled(nonRemovable)
  1868. @pyqtSlot(int)
  1869. def slot_tweakPluginsLv2RowChanged(self, index):
  1870. nonRemovable = (index >= 0 and self.list_LV2.item(index).text() not in DEFAULT_LV2_PATH)
  1871. self.b_tweak_plugins_change.setEnabled(nonRemovable)
  1872. self.b_tweak_plugins_remove.setEnabled(nonRemovable)
  1873. @pyqtSlot(int)
  1874. def slot_tweakPluginsVstRowChanged(self, index):
  1875. nonRemovable = (index >= 0 and self.list_VST.item(index).text() not in DEFAULT_VST_PATH)
  1876. self.b_tweak_plugins_change.setEnabled(nonRemovable)
  1877. self.b_tweak_plugins_remove.setEnabled(nonRemovable)
  1878. def saveSettings(self):
  1879. self.settings.setValue("Geometry", self.saveGeometry())
  1880. GlobalSettings.setValue("JACK/AutoStart", self.cb_jack_autostart.isChecked())
  1881. GlobalSettings.setValue("ALSA-Audio/BridgeIndexType", self.cb_alsa_type.currentIndex())
  1882. GlobalSettings.setValue("A2J/AutoStart", self.cb_a2j_autostart.isChecked())
  1883. GlobalSettings.setValue("Pulse2JACK/AutoStart", (havePulseAudio and self.cb_pulse_autostart.isChecked()))
  1884. def loadSettings(self, geometry):
  1885. if geometry:
  1886. self.restoreGeometry(self.settings.value("Geometry", b""))
  1887. usingAlsaLoop = bool(GlobalSettings.value("ALSA-Audio/BridgeIndexType", iAlsaFileNone, type=int) == iAlsaFileLoop)
  1888. self.cb_jack_autostart.setChecked(GlobalSettings.value("JACK/AutoStart", wantJackStart, type=bool))
  1889. self.cb_a2j_autostart.setChecked(GlobalSettings.value("A2J/AutoStart", True, type=bool))
  1890. self.cb_pulse_autostart.setChecked(GlobalSettings.value("Pulse2JACK/AutoStart", havePulseAudio and not usingAlsaLoop, type=bool))
  1891. def timerEvent(self, event):
  1892. if event.timerId() == self.m_timer500:
  1893. if gDBus.jack and self.m_last_dsp_load != None:
  1894. next_dsp_load = gDBus.jack.GetLoad()
  1895. next_xruns = gDBus.jack.GetXruns()
  1896. needUpdateTip = False
  1897. if self.m_last_dsp_load != next_dsp_load:
  1898. self.m_last_dsp_load = next_dsp_load
  1899. self.label_jack_dsp.setText("%.2f%%" % self.m_last_dsp_load)
  1900. needUpdateTip = True
  1901. if self.m_last_xruns != next_xruns:
  1902. self.m_last_xruns = next_xruns
  1903. self.label_jack_xruns.setText(str(self.m_last_xruns))
  1904. needUpdateTip = True
  1905. if needUpdateTip:
  1906. self.updateSystrayTooltip()
  1907. elif event.timerId() == self.m_timer2000:
  1908. if gDBus.jack and self.m_last_buffer_size != None:
  1909. next_buffer_size = gDBus.jack.GetBufferSize()
  1910. if self.m_last_buffer_size != next_buffer_size:
  1911. self.m_last_buffer_size = next_buffer_size
  1912. self.label_jack_bfsize.setText("%i samples" % self.m_last_buffer_size)
  1913. self.label_jack_latency.setText("%.1f ms" % gDBus.jack.GetLatency())
  1914. else:
  1915. self.update()
  1916. QMainWindow.timerEvent(self, event)
  1917. def closeEvent(self, event):
  1918. self.saveSettings()
  1919. self.systray.handleQtCloseEvent(event)
  1920. # ------------------------------------------------------------------------------------------------------------
  1921. def runFunctionInMainThread(task):
  1922. waiter = QSemaphore(1)
  1923. def taskInMainThread():
  1924. task()
  1925. waiter.release()
  1926. QTimer.singleShot(0, taskInMainThread)
  1927. waiter.tryAcquire()
  1928. #--------------- main ------------------
  1929. if __name__ == '__main__':
  1930. # App initialization
  1931. app = QApplication(sys.argv)
  1932. app.setApplicationName("Cadence")
  1933. app.setApplicationVersion(VERSION)
  1934. app.setOrganizationName("Cadence")
  1935. app.setWindowIcon(QIcon(":/scalable/cadence.svg"))
  1936. if haveDBus:
  1937. gDBus.loop = DBusQtMainLoop(set_as_default=True)
  1938. gDBus.bus = dbus.SessionBus(mainloop=gDBus.loop)
  1939. initSystemChecks()
  1940. # Show GUI
  1941. gui = CadenceMainW()
  1942. # Set-up custom signal handling
  1943. setUpSignals(gui)
  1944. if "--minimized" in app.arguments():
  1945. gui.hide()
  1946. gui.systray.setActionText("show", gui.tr("Restore"))
  1947. app.setQuitOnLastWindowClosed(False)
  1948. else:
  1949. gui.show()
  1950. # Exit properly
  1951. sys.exit(gui.systray.exec_(app))