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.

144 lines
4.7KB

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