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.

138 lines
4.2KB

  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", ["-e"])
  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. # Stop all audio processes, used for force-restart
  75. def stopAllAudioProcesses():
  76. if not (HAIKU or LINUX or MACOS):
  77. print("stopAllAudioProcesses() - Not supported in this system")
  78. return
  79. process = QProcess()
  80. # Tell pulse2jack script to create files, prevents pulseaudio respawn
  81. process.start("cadence-pulse2jack", "--dummy")
  82. process.waitForFinished()
  83. procsTerm = ["a2j", "a2jmidid", "artsd", "jackd", "jackdmp", "knotify4", "lash", "ladishd", "ladiappd", "ladiconfd", "jmcore"]
  84. procsKill = ["jackdbus", "pulseaudio"]
  85. tries = 20
  86. process.start("killall", procsTerm)
  87. process.waitForFinished()
  88. for x in range(tries):
  89. procsList = getProcList()
  90. for term in range(len(procsTerm)):
  91. if term in procsList:
  92. break
  93. else:
  94. sleep(0.1)
  95. else:
  96. break
  97. process.start("killall", ["-KILL"] + procsKill)
  98. process.waitForFinished()
  99. for x in range(tries):
  100. procsList = getProcList()
  101. for kill in range(len(procsKill)):
  102. if kill in procsList:
  103. break
  104. else:
  105. sleep(0.1)
  106. else:
  107. break