Audio plugin host https://kx.studio/carla
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.

273 lines
8.2KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Script to start carla plugin bridges
  4. # Copyright (C) 2015 Filipe Coelho <falktx@falktx.com>
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License as
  8. # published by the Free Software Foundation; either version 2 of
  9. # the License, or 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 doc/GPL.txt file.
  17. # --------------------------------------------------------------------------------------------------------
  18. # Imports
  19. import os
  20. import sys
  21. from signal import signal, SIGINT, SIGTERM
  22. from subprocess import Popen
  23. # --------------------------------------------------------------------------------------------------------
  24. # Setup
  25. INSTALL_PREFIX = "X-PREFIX-X"
  26. CARLA_LIBDIR = os.path.join(INSTALL_PREFIX, "lib", "carla")
  27. CARLA_RESDIR = os.path.join(INSTALL_PREFIX, "share", "carla", "resources")
  28. # --------------------------------------------------------------------------------------------------------
  29. # Check for enough arguments
  30. usageMsg = """\
  31. usage: %s [arch (optional)] [format] [filename/uri] [label (optional)] [uniqueId (optional)]
  32. Possible archs:
  33. - native (default)
  34. - linux32
  35. - linux64
  36. - win32
  37. - win64
  38. Possible formats:
  39. - internal
  40. - ladspa
  41. - dssi
  42. - lv2
  43. - vst|vst2
  44. - vst3
  45. - gig
  46. - sf2
  47. - sfz
  48. Examples:
  49. $ %s internal midisplit
  50. $ %s dssi /usr/lib/dssi/hexter.so hexter
  51. $ %s lv2 http://calf.sourceforge.net/plugins/Compressor
  52. $ %s native vst /usr/lib/vst/TAL-NoiseMaker.so
  53. $ %s win32 vst \"~/.wine/drive_c/Program Files (x86)/VstPlugins/Kontakt 5.dll\"
  54. Format can be skipped for internal and lv2 plugins (auto-detected), like this:
  55. $ %s nekofilter
  56. $ %s http://synthv1.sourceforge.net/lv2""" % ((sys.argv[0],)*8)
  57. def printUsageAndQuit():
  58. print(usageMsg)
  59. sys.exit(0)
  60. if len(sys.argv) < 2:
  61. printUsageAndQuit()
  62. # --------------------------------------------------------------------------------------------------------
  63. # Initialize variables to null
  64. ARCH = "native"
  65. FORMAT = "none"
  66. FILENAME = ""
  67. LABEL = ""
  68. UNIQUEID = 0
  69. # --------------------------------------------------------------------------------------------------------
  70. # Set arch
  71. arg = 1
  72. if sys.argv[arg] in ("native", "posix32", "posix64", "linux32", "linux64", "mac32", "mac64", "win32", "win64"):
  73. ARCH = sys.argv[arg].replace("linux", "posix").replace("mac", "posix")
  74. arg += 1
  75. if len(sys.argv) == arg:
  76. printUsageAndQuit()
  77. # --------------------------------------------------------------------------------------------------------
  78. # Set format
  79. if sys.argv[arg] in ("internal", "ladspa", "dssi", "lv2", "vst", "vst2", "vst3", "au", "audiounit", "gig", "sf2", "sfz"):
  80. FORMAT = sys.argv[arg]
  81. arg += 1
  82. if FORMAT == "vst":
  83. FORMAT = "vst2"
  84. elif FORMAT == "audiounit":
  85. FORMAT = "au"
  86. elif len(sys.argv) == arg+1:
  87. FORMAT = "lv2" if ":" in sys.argv[arg] else "internal"
  88. else:
  89. print("Invalid format")
  90. sys.exit(1)
  91. if len(sys.argv) == arg:
  92. printUsageAndQuit()
  93. # --------------------------------------------------------------------------------------------------------
  94. # Set filename/uri
  95. if FORMAT in ("internal", "lv2"):
  96. LABEL = sys.argv[arg]
  97. arg += 1
  98. else:
  99. FILENAME = os.path.expanduser(sys.argv[arg])
  100. arg += 1
  101. # --------------------------------------------------------------------------------------------------------
  102. # Set label (optional)
  103. if len(sys.argv) > arg:
  104. if FORMAT in ("internal", "lv2"):
  105. print("label/uri already set, ignoring 2nd label")
  106. else:
  107. LABEL = sys.argv[arg]
  108. arg += 1
  109. # --------------------------------------------------------------------------------------------------------
  110. # Set uniqueId (optional)
  111. if len(sys.argv) > arg:
  112. if FORMAT in ("internal", "dssi", "lv2", "au", "gig", "sf2", "sfz"):
  113. print("uniqueId is not used in this format, ignored")
  114. else:
  115. try:
  116. UNIQUEID = int(sys.argv[arg])
  117. except:
  118. print("uniqueId must be a number")
  119. sys.exit(1)
  120. arg += 1
  121. # --------------------------------------------------------------------------------------------------------
  122. # Others?
  123. if len(sys.argv) > arg:
  124. print("Got too many arguments, ignoring past uniqueId")
  125. # --------------------------------------------------------------------------------------------------------
  126. # Set bridge binary
  127. BRIDGE = os.path.join(CARLA_LIBDIR, "carla-bridge-" + ARCH)
  128. if ARCH in ("win32", "win64"):
  129. BRIDGE = BRIDGE + ".exe"
  130. # --------------------------------------------------------------------------------------------------------
  131. # Check for existing carla folder
  132. if not os.path.exists(CARLA_LIBDIR):
  133. print("Carla library folder does not exist, is it installed?")
  134. sys.exit(2)
  135. if not os.path.exists(CARLA_RESDIR):
  136. print("Carla resource folder does not exist, is it installed?")
  137. sys.exit(2)
  138. # --------------------------------------------------------------------------------------------------------
  139. # Check for existing arch binary
  140. if not os.path.exists(BRIDGE):
  141. print("Carla plugin bridge for the requested arch (%s) does not exist" % (ARCH,))
  142. sys.exit(2)
  143. # --------------------------------------------------------------------------------------------------------
  144. # Final checks
  145. if ARCH not in ("native", "posix32", "posix64", "win32", "win64"):
  146. print("Invalid arch")
  147. sys.exit(1)
  148. if FORMAT not in ("internal", "ladspa", "dssi", "lv2", "vst2", "vst3", "gig", "sf2", "sfz"):
  149. print("Invalid format")
  150. sys.exit(1)
  151. if FILENAME and not os.path.exists(FILENAME):
  152. print("Requested filename does not exist")
  153. sys.exit(1)
  154. # ------------------------------------------------------------------------------------------------------------
  155. # Signal handler
  156. global gProc
  157. gProc = None
  158. def signalHandler(sig, frame):
  159. global gProc
  160. if gProc is None:
  161. return
  162. if sig in (SIGINT, SIGTERM):
  163. gProc.kill()
  164. gProc = None
  165. signal(SIGINT, signalHandler)
  166. signal(SIGTERM, signalHandler)
  167. # --------------------------------------------------------------------------------------------------------
  168. # Setup environment
  169. #CARLA_CLIENT_NAME = os.getenv("CARLA_CLIENT_NAME", "(none)")
  170. #os.environ["ENGINE_OPTION_UIS_ALWAYS_ON_TOP"] = "false"
  171. #os.environ["ENGINE_OPTION_MAX_PARAMETERS"] = "200"
  172. #os.environ["ENGINE_OPTION_UI_BRIDGES_TIMEOUT"] = "3000"
  173. LADSPA_PATH = os.getenv("LADSPA_PATH")
  174. DSSI_PATH = os.getenv("DSSI_PATH")
  175. LV2_PATH = os.getenv("LV2_PATH")
  176. VST2_PATH = os.getenv("VST_PATH")
  177. VST3_PATH = os.getenv("VST3_PATH")
  178. AU_PATH = os.getenv("AU_PATH")
  179. GIG_PATH = os.getenv("GIG_PATH")
  180. SF2_PATH = os.getenv("SF2_PATH")
  181. SFZ_PATH = os.getenv("SFZ_PATH")
  182. if LADSPA_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_LADSPA"] = LADSPA_PATH
  183. if DSSI_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_DSSI"] = DSSI_PATH
  184. if LV2_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_LV2"] = LV2_PATH
  185. if VST2_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_VST2"] = VST2_PATH
  186. if VST3_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_VST3"] = VST3_PATH
  187. if AU_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_AU"] = AU_PATH
  188. if GIG_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_GIG"] = GIG_PATH
  189. if SF2_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_SF2"] = SF2_PATH
  190. if SFZ_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_SFZ"] = SFZ_PATH
  191. os.environ["ENGINE_OPTION_PATH_BINARIES"] = CARLA_LIBDIR
  192. os.environ["ENGINE_OPTION_PATH_RESOURCES"] = CARLA_RESDIR
  193. # --------------------------------------------------------------------------------------------------------
  194. # Exec
  195. command = []
  196. if ARCH in ("win32", "win64"):
  197. command.append("wine")
  198. command.append(BRIDGE)
  199. command.append(FORMAT)
  200. command.append(FILENAME or "(none)")
  201. command.append(LABEL or "(none)")
  202. command.append(str(UNIQUEID))
  203. print(command)
  204. gProc = Popen(command)
  205. gProc.wait()
  206. # --------------------------------------------------------------------------------------------------------