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.

264 lines
8.5KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Script to start carla plugin bridges
  4. # Copyright (C) 2015-2018 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. # --------------------------------------------------------------------------------------------------------
  22. # Setup
  23. INSTALL_PREFIX = "X-PREFIX-X"
  24. CARLA_LIBDIR = os.path.join(INSTALL_PREFIX, "lib", "carla")
  25. CARLA_RESDIR = os.path.join(INSTALL_PREFIX, "share", "carla", "resources")
  26. # --------------------------------------------------------------------------------------------------------
  27. # Check for enough arguments
  28. usageMsg = """\
  29. usage: %s [arch (optional)] [format] [filename/uri] [label (optional)] [uniqueId (optional)]
  30. Possible archs:
  31. - native (default)
  32. - linux32
  33. - linux64
  34. - win32
  35. - win64
  36. Possible formats:
  37. - internal
  38. - ladspa
  39. - dssi
  40. - lv2
  41. - vst|vst2
  42. - vst3
  43. - clap
  44. - jsfx
  45. - sf2
  46. - sfz
  47. Examples:
  48. $ %s internal midisplit
  49. $ %s dssi /usr/lib/dssi/whysynth.so
  50. $ %s lv2 http://calf.sourceforge.net/plugins/Compressor
  51. $ %s native vst /usr/lib/vst/TAL-NoiseMaker.so
  52. $ %s win32 vst \"~/.wine/drive_c/Program Files (x86)/VstPlugins/Kontakt 5.dll\"
  53. $ CARLA_BRIDGE_PLUGIN_BINARY_TYPE=win64 %s vst \"~/.wine/drive_c/Program Files/Common Files/VST2/Sytrus VSTi.dll\"
  54. Format can be skipped for internal and lv2 plugins (auto-detected), like this:
  55. $ %s midipattern
  56. $ %s http://synthv1.sourceforge.net/lv2""" % ((sys.argv[0],)*9)
  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 = os.getenv("CARLA_BRIDGE_PLUGIN_BINARY_TYPE", "native")
  65. TESTING = os.getenv("CARLA_BRIDGE_TESTING", None)
  66. FORMAT = "none"
  67. FILENAME = ""
  68. LABEL = ""
  69. UNIQUEID = 0
  70. # --------------------------------------------------------------------------------------------------------
  71. # Set arch
  72. arg = 1
  73. if sys.argv[arg] in ("native", "posix32", "posix64", "linux32", "linux64", "mac32", "mac64", "win32", "win64"):
  74. ARCH = sys.argv[arg].replace("linux", "posix").replace("mac", "posix")
  75. arg += 1
  76. if len(sys.argv) == arg:
  77. printUsageAndQuit()
  78. # --------------------------------------------------------------------------------------------------------
  79. # Set format
  80. if sys.argv[arg] in ("internal", "ladspa", "dssi", "lv2", "vst", "vst2", "vst3", "au", "clap", "jsfx", "sf2", "sfz"):
  81. FORMAT = sys.argv[arg]
  82. arg += 1
  83. if FORMAT == "vst":
  84. FORMAT = "vst2"
  85. elif len(sys.argv) == arg+1:
  86. FORMAT = "lv2" if ":" in sys.argv[arg] else "internal"
  87. else:
  88. print("Invalid format")
  89. sys.exit(1)
  90. if len(sys.argv) == arg:
  91. printUsageAndQuit()
  92. # --------------------------------------------------------------------------------------------------------
  93. # Set filename/uri
  94. if FORMAT in ("internal", "lv2"):
  95. LABEL = sys.argv[arg]
  96. arg += 1
  97. else:
  98. FILENAME = os.path.expanduser(sys.argv[arg])
  99. arg += 1
  100. # --------------------------------------------------------------------------------------------------------
  101. # Set label (optional)
  102. if len(sys.argv) > arg:
  103. if FORMAT == "internal":
  104. print("label/uri already set, ignoring 2nd label")
  105. elif FORMAT == "lv2":
  106. newpwd = sys.argv[arg]
  107. if os.path.exists(newpwd):
  108. print("using path hack for lv2 plugin")
  109. os.chdir(newpwd)
  110. else:
  111. LABEL = sys.argv[arg]
  112. arg += 1
  113. # --------------------------------------------------------------------------------------------------------
  114. # Set uniqueId (optional)
  115. if len(sys.argv) > arg:
  116. if FORMAT in ("internal", "dssi", "lv2", "au", "sf2", "sfz"):
  117. print("uniqueId is not used in this format, ignored")
  118. else:
  119. try:
  120. UNIQUEID = int(sys.argv[arg])
  121. except:
  122. print("uniqueId must be a number")
  123. sys.exit(1)
  124. arg += 1
  125. # --------------------------------------------------------------------------------------------------------
  126. # Others?
  127. if len(sys.argv) > arg:
  128. print("Got too many arguments, ignoring past uniqueId")
  129. # --------------------------------------------------------------------------------------------------------
  130. # Set bridge binary
  131. BRIDGE = os.path.join(CARLA_LIBDIR, "carla-bridge-" + ARCH)
  132. if ARCH in ("win32", "win64") or TESTING in ("win32", "win64"):
  133. BRIDGE = BRIDGE + ".exe"
  134. # --------------------------------------------------------------------------------------------------------
  135. # Check for existing carla folder
  136. if not os.path.exists(CARLA_LIBDIR):
  137. print("Carla library folder does not exist, is Carla installed?")
  138. sys.exit(2)
  139. if not os.path.exists(CARLA_RESDIR):
  140. print("Carla resource folder does not exist, is Carla installed?")
  141. sys.exit(2)
  142. # --------------------------------------------------------------------------------------------------------
  143. # Check for existing arch binary
  144. if not os.path.exists(BRIDGE):
  145. print("Carla plugin bridge (%s) for the requested arch (%s) does not exist" % (os.path.basename(BRIDGE), ARCH,))
  146. sys.exit(2)
  147. # --------------------------------------------------------------------------------------------------------
  148. # Final checks
  149. if ARCH not in ("native", "posix32", "posix64", "win32", "win64"):
  150. print("Invalid arch")
  151. sys.exit(1)
  152. if FORMAT not in ("internal", "ladspa", "dssi", "lv2", "vst2", "vst3", "au", "clap", "jsfx", "sf2", "sfz"):
  153. print("Invalid format")
  154. sys.exit(1)
  155. if FILENAME and not os.path.exists(FILENAME):
  156. print("Requested filename does not exist")
  157. sys.exit(1)
  158. # --------------------------------------------------------------------------------------------------------
  159. # Setup environment
  160. LADSPA_PATH = os.getenv("LADSPA_PATH")
  161. DSSI_PATH = os.getenv("DSSI_PATH")
  162. LV2_PATH = os.getenv("LV2_PATH")
  163. VST2_PATH = os.getenv("VST_PATH")
  164. VST3_PATH = os.getenv("VST3_PATH")
  165. CLAP_PATH = os.getenv("CLAP_PATH")
  166. SF2_PATH = os.getenv("SF2_PATH")
  167. SFZ_PATH = os.getenv("SFZ_PATH")
  168. if LADSPA_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_LADSPA"] = LADSPA_PATH
  169. if DSSI_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_DSSI"] = DSSI_PATH
  170. if LV2_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_LV2"] = LV2_PATH
  171. if VST2_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_VST2"] = VST2_PATH
  172. if VST3_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_VST3"] = VST3_PATH
  173. if CLAP_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_CLAP"] = CLAP_PATH
  174. if SF2_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_SF2"] = SF2_PATH
  175. if SFZ_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_SFZ"] = SFZ_PATH
  176. os.environ["ENGINE_OPTION_PATH_BINARIES"] = CARLA_LIBDIR
  177. os.environ["ENGINE_OPTION_PATH_RESOURCES"] = CARLA_RESDIR
  178. # --------------------------------------------------------------------------------------------------------
  179. CARLA_CLIENT_NAME = os.getenv("CARLA_CLIENT_NAME")
  180. LADISH_APP_NAME = os.getenv("LADISH_APP_NAME")
  181. if CARLA_CLIENT_NAME is not None:
  182. os.environ["CARLA_CLIENT_NAME"] = CARLA_CLIENT_NAME
  183. elif LADISH_APP_NAME is not None:
  184. os.environ["CARLA_CLIENT_NAME"] = LADISH_APP_NAME
  185. else:
  186. os.environ["CARLA_CLIENT_NAME"] = "(none)"
  187. # --------------------------------------------------------------------------------------------------------
  188. # Exec
  189. command = []
  190. if os.getenv("CARLA_BRIDGE_PLUGIN_BINARY_TYPE") is not None:
  191. BRIDGE = os.path.join(CARLA_LIBDIR, "carla-bridge-native")
  192. elif ARCH == "win32" or TESTING == "win32":
  193. command.append("wine")
  194. elif ARCH == "win64" or TESTING == "win64":
  195. command.append("wine64")
  196. command.append(BRIDGE)
  197. command.append(FORMAT)
  198. command.append(FILENAME or "(none)")
  199. command.append(LABEL or "(none)")
  200. command.append(str(UNIQUEID))
  201. print(command)
  202. os.execvp(command[0], command)
  203. # --------------------------------------------------------------------------------------------------------