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.

231 lines
6.8KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Imports (Global)
  4. import dbus, sys
  5. from PyQt4.QtCore import QCoreApplication
  6. # Imports (Custom Stuff)
  7. from shared_cadence import *
  8. # Cadence Global Settings
  9. GlobalSettings = QSettings("Cadence", "GlobalSettings")
  10. # DBus
  11. class DBus(object):
  12. __slots__ = [
  13. 'bus',
  14. 'a2j',
  15. 'jack'
  16. ]
  17. DBus = DBus()
  18. def forceReset():
  19. # Kill all audio processes
  20. stopAllAudioProcesses()
  21. # Remove configs
  22. configFiles = (
  23. # Cadence GlobalSettings
  24. os.path.join(HOME, ".asoundrc"),
  25. # ALSA settings
  26. os.path.join(HOME, ".config", "Cadence", "GlobalSettings.conf"),
  27. # JACK2 settings
  28. os.path.join(HOME, ".config", "jack", "conf.xml"),
  29. # JACK1 settings
  30. os.path.join(HOME, ".config", "jack", "conf-jack1.xml")
  31. )
  32. for config in configFiles:
  33. if os.path.exists(config):
  34. os.remove(config)
  35. # Start JACK, A2J and Pulse, according to user settings
  36. def startSession():
  37. # Check if JACK is set to auto-start
  38. if not GlobalSettings.value("JACK/AutoStart", False, type=bool):
  39. print("JACK is set to NOT auto-start on login")
  40. return True
  41. # Kill all audio processes first
  42. stopAllAudioProcesses()
  43. # Connect to DBus
  44. DBus.bus = dbus.SessionBus()
  45. DBus.jack = DBus.bus.get_object("org.jackaudio.service", "/org/jackaudio/Controller")
  46. try:
  47. DBus.a2j = dbus.Interface(DBus.bus.get_object("org.gna.home.a2jmidid", "/"), "org.gna.home.a2jmidid.control")
  48. except:
  49. DBus.a2j = None
  50. if GlobalSettings.value("JACK/AutoLoadLadishStudio", False, type=bool):
  51. try:
  52. ladish_control = DBus.bus.get_object("org.ladish", "/org/ladish/Control")
  53. except:
  54. startJack()
  55. return False
  56. try:
  57. ladish_conf = DBus.bus.get_object("org.ladish.conf", "/org/ladish/conf")
  58. except:
  59. ladish_conf = None
  60. ladishStudioName = dbus.String(GlobalSettings.value("JACK/LadishStudioName", "", type=str))
  61. ladishStudioListDump = ladish_control.GetStudioList()
  62. for thisStudioName, thisStudioDict in ladishStudioListDump:
  63. if ladishStudioName == thisStudioName:
  64. if ladish_conf and ladish_conf.get('/org/ladish/daemon/notify')[0] == "true":
  65. ladish_conf.set('/org/ladish/daemon/notify', "false")
  66. ladishNotifyHack = True
  67. else:
  68. ladishNotifyHack = False
  69. ladish_control.LoadStudio(thisStudioName)
  70. ladish_studio = DBus.bus.get_object("org.ladish", "/org/ladish/Studio")
  71. if not bool(ladish_studio.IsStarted()):
  72. ladish_studio.Start()
  73. if ladishNotifyHack:
  74. ladish_conf.set('/org/ladish/daemon/notify', "true")
  75. break
  76. else:
  77. startJack()
  78. else:
  79. startJack()
  80. if not bool(DBus.jack.IsStarted()):
  81. print("JACK Failed to Start")
  82. return False
  83. # Start bridges according to user settings
  84. # ALSA-Audio
  85. if GlobalSettings.value("ALSA-Audio/BridgeIndexType", iAlsaFileNone, type=int) == iAlsaFileLoop:
  86. os.system("cadence-aloop-daemon &")
  87. sleep(0.5)
  88. # ALSA-MIDI
  89. if GlobalSettings.value("A2J/AutoStart", True, type=bool) and DBus.a2j and not bool(DBus.a2j.is_started()):
  90. a2jExportHW = GlobalSettings.value("A2J/ExportHW", True, type=bool)
  91. DBus.a2j.set_hw_export(a2jExportHW)
  92. DBus.a2j.start()
  93. # PulseAudio
  94. if GlobalSettings.value("Pulse2JACK/AutoStart", True, type=bool):
  95. if GlobalSettings.value("Pulse2JACK/PlaybackModeOnly", False, type=bool):
  96. os.system("cadence-pulse2jack -p")
  97. else:
  98. os.system("cadence-pulse2jack")
  99. print("JACK Started Successfully")
  100. return True
  101. def startJack():
  102. if not bool(DBus.jack.IsStarted()):
  103. DBus.jack.StartServer()
  104. def printLADSPA_PATH():
  105. EXTRA_LADSPA_DIRS = GlobalSettings.value("AudioPlugins/EXTRA_LADSPA_PATH", "", type=str).split(":")
  106. LADSPA_PATH_str = ":".join(DEFAULT_LADSPA_PATH)
  107. for i in range(len(EXTRA_LADSPA_DIRS)):
  108. if EXTRA_LADSPA_DIRS[i]:
  109. LADSPA_PATH_str += ":"+EXTRA_LADSPA_DIRS[i]
  110. print(LADSPA_PATH_str)
  111. def printDSSI_PATH():
  112. EXTRA_DSSI_DIRS = GlobalSettings.value("AudioPlugins/EXTRA_DSSI_PATH", "", type=str).split(":")
  113. DSSI_PATH_str = ":".join(DEFAULT_DSSI_PATH)
  114. for i in range(len(EXTRA_DSSI_DIRS)):
  115. if EXTRA_DSSI_DIRS[i]:
  116. DSSI_PATH_str += ":"+EXTRA_DSSI_DIRS[i]
  117. print(DSSI_PATH_str)
  118. def printLV2_PATH():
  119. EXTRA_LV2_DIRS = GlobalSettings.value("AudioPlugins/EXTRA_LV2_PATH", "", type=str).split(":")
  120. LV2_PATH_str = ":".join(DEFAULT_LV2_PATH)
  121. for i in range(len(EXTRA_LV2_DIRS)):
  122. if EXTRA_LV2_DIRS[i]:
  123. LV2_PATH_str += ":"+EXTRA_LV2_DIRS[i]
  124. print(LV2_PATH_str)
  125. def printVST_PATH():
  126. EXTRA_VST_DIRS = GlobalSettings.value("AudioPlugins/EXTRA_VST_PATH", "", type=str).split(":")
  127. VST_PATH_str = ":".join(DEFAULT_VST_PATH)
  128. for i in range(len(EXTRA_VST_DIRS)):
  129. if EXTRA_VST_DIRS[i]:
  130. VST_PATH_str += ":"+EXTRA_VST_DIRS[i]
  131. print(VST_PATH_str)
  132. def printArguments():
  133. print("\t-s|--start \tStart session")
  134. print("\t --reset \tForce-reset all JACK daemons and settings (disables auto-start at login)")
  135. print("")
  136. print("\t-h|--help \tShow this help message")
  137. print("\t-v|--version\tShow version")
  138. def printError(cmd):
  139. print("Invalid arguments")
  140. print("Run '%s -h' for help" % (cmd))
  141. def printHelp(cmd):
  142. print("Usage: %s [cmd]" % (cmd))
  143. printArguments()
  144. def printVersion():
  145. print("Cadence version %s" % (VERSION))
  146. print("Developed by falkTX and the rest of the KXStudio Team")
  147. #--------------- main ------------------
  148. if __name__ == '__main__':
  149. # App initialization
  150. app = QCoreApplication(sys.argv)
  151. app.setApplicationName("Cadence")
  152. app.setApplicationVersion(VERSION)
  153. app.setOrganizationName("Cadence")
  154. # Check arguments
  155. cmd = sys.argv[0]
  156. if len(app.arguments()) == 1:
  157. printHelp(cmd)
  158. elif len(app.arguments()) == 2:
  159. arg = app.arguments()[1]
  160. if arg == "--printLADSPA_PATH":
  161. printLADSPA_PATH()
  162. elif arg == "--printDSSI_PATH":
  163. printDSSI_PATH()
  164. elif arg == "--printLV2_PATH":
  165. printLV2_PATH()
  166. elif arg == "--printVST_PATH":
  167. printVST_PATH()
  168. elif arg == "--reset":
  169. forceReset()
  170. elif arg in ["-s", "--s", "-start", "--start"]:
  171. sys.exit(startSession())
  172. elif arg in ["-h", "--h", "-help", "--help"]:
  173. printHelp(cmd)
  174. elif arg in ["-v", "--v", "-version", "--version"]:
  175. printVersion()
  176. else:
  177. printError(cmd)
  178. else:
  179. printError(cmd)
  180. # Exit
  181. sys.exit(0)