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.

2333 lines
93KB

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