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.

167 lines
5.4KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Common/Shared code for Cadence
  4. # Copyright (C) 2012-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 time import sleep
  20. if True:
  21. from PyQt5.QtCore import QProcess, QSettings
  22. else:
  23. from PyQt4.QtCore import QProcess, QSettings
  24. # ------------------------------------------------------------------------------------------------------------
  25. # Imports (Custom Stuff)
  26. from shared import *
  27. # ------------------------------------------------------------------------------------------------------------
  28. # Default Plugin PATHs
  29. DEFAULT_LADSPA_PATH = [
  30. os.path.join(HOME, ".ladspa"),
  31. os.path.join("/", "usr", "lib", "ladspa"),
  32. os.path.join("/", "usr", "local", "lib", "ladspa")
  33. ]
  34. DEFAULT_DSSI_PATH = [
  35. os.path.join(HOME, ".dssi"),
  36. os.path.join("/", "usr", "lib", "dssi"),
  37. os.path.join("/", "usr", "local", "lib", "dssi")
  38. ]
  39. DEFAULT_LV2_PATH = [
  40. os.path.join(HOME, ".lv2"),
  41. os.path.join("/", "usr", "lib", "lv2"),
  42. os.path.join("/", "usr", "local", "lib", "lv2")
  43. ]
  44. DEFAULT_VST_PATH = [
  45. os.path.join(HOME, ".vst"),
  46. os.path.join("/", "usr", "lib", "vst"),
  47. os.path.join("/", "usr", "local", "lib", "vst")
  48. ]
  49. # ------------------------------------------------------------------------------------------------------------
  50. # ALSA file-type indexes
  51. iAlsaFileNone = 0
  52. iAlsaFileLoop = 1
  53. iAlsaFileJACK = 2
  54. iAlsaFilePulse = 3
  55. iAlsaFileMax = 4
  56. # ------------------------------------------------------------------------------------------------------------
  57. # Global Settings
  58. GlobalSettings = QSettings("Cadence", "GlobalSettings")
  59. # ------------------------------------------------------------------------------------------------------------
  60. # KXStudio Check
  61. wantJackStart = os.path.exists("/usr/share/kxstudio/config/config/Cadence/GlobalSettings.conf")
  62. # ------------------------------------------------------------------------------------------------------------
  63. # Get Process list
  64. def getProcList():
  65. retProcs = []
  66. if HAIKU or LINUX or MACOS:
  67. process = QProcess()
  68. process.start("ps", ["-u", str(os.getuid())])
  69. process.waitForFinished()
  70. processDump = process.readAllStandardOutput().split("\n")
  71. for i in range(len(processDump)):
  72. if (i == 0): continue
  73. dumpTest = str(processDump[i], encoding="utf-8").rsplit(":", 1)[-1].split(" ")
  74. if len(dumpTest) > 1 and dumpTest[1]:
  75. retProcs.append(dumpTest[1])
  76. else:
  77. print("getProcList() - Not supported in this system")
  78. return retProcs
  79. # ------------------------------------------------------------------------------------------------------------
  80. # Start ALSA-Audio Bridge, reading its settings
  81. def startAlsaAudioLoopBridge():
  82. channels = GlobalSettings.value("ALSA-Audio/BridgeChannels", 2, type=int)
  83. useZita = bool(GlobalSettings.value("ALSA-Audio/BridgeTool", "alsa_in", type=str) == "zita")
  84. os.system("cadence-aloop-daemon --channels=%i %s &" % (channels, "--zita" if useZita else ""))
  85. # ------------------------------------------------------------------------------------------------------------
  86. # Stop all audio processes, used for force-restart
  87. def waitProcsEnd(procs, tries):
  88. for x in range(tries):
  89. procsList = getProcList()
  90. for proc in procs:
  91. if proc in procsList:
  92. break
  93. else:
  94. sleep(0.1)
  95. else:
  96. break
  97. # ------------------------------------------------------------------------------------------------------------
  98. # Cleanly close the jack dbus service
  99. def tryCloseJackDBus():
  100. try:
  101. import dbus
  102. bus = dbus.SessionBus()
  103. jack = bus.get_object("org.jackaudio.service", "/org/jackaudio/Controller")
  104. jack.Exit()
  105. except:
  106. print("tryCloseJackDBus() failed")
  107. # ------------------------------------------------------------------------------------------------------------
  108. # Stop all audio processes, used for force-restart
  109. def stopAllAudioProcesses(tryCloseJack = True):
  110. if tryCloseJack:
  111. tryCloseJackDBus()
  112. if not (HAIKU or LINUX or MACOS):
  113. print("stopAllAudioProcesses() - Not supported in this system")
  114. return
  115. process = QProcess()
  116. # Tell pulse2jack script to create files, prevents pulseaudio respawn
  117. process.start("cadence-pulse2jack", ["--dummy"])
  118. process.waitForFinished()
  119. procsTerm = ["a2j", "a2jmidid", "artsd", "jackd", "jackdmp", "knotify4", "lash", "ladishd", "ladiappd", "ladiconfd", "jmcore"]
  120. procsKill = ["jackdbus", "pulseaudio"]
  121. tries = 20
  122. process.start("killall", procsTerm)
  123. process.waitForFinished()
  124. waitProcsEnd(procsTerm, tries)
  125. process.start("killall", ["-KILL"] + procsKill)
  126. process.waitForFinished()
  127. waitProcsEnd(procsKill, tries)