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.

carla-single 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. - jsfx
  44. - sf2
  45. - sfz
  46. Examples:
  47. $ %s internal midisplit
  48. $ %s dssi /usr/lib/dssi/whysynth.so
  49. $ %s lv2 http://calf.sourceforge.net/plugins/Compressor
  50. $ %s native vst /usr/lib/vst/TAL-NoiseMaker.so
  51. $ %s win32 vst \"~/.wine/drive_c/Program Files (x86)/VstPlugins/Kontakt 5.dll\"
  52. $ CARLA_BRIDGE_PLUGIN_BINARY_TYPE=win64 %s vst \"~/.wine/drive_c/Program Files/Common Files/VST2/Sytrus VSTi.dll\"
  53. Format can be skipped for internal and lv2 plugins (auto-detected), like this:
  54. $ %s midipattern
  55. $ %s http://synthv1.sourceforge.net/lv2""" % ((sys.argv[0],)*9)
  56. def printUsageAndQuit():
  57. print(usageMsg)
  58. sys.exit(0)
  59. if len(sys.argv) < 2:
  60. printUsageAndQuit()
  61. # --------------------------------------------------------------------------------------------------------
  62. # Initialize variables to null
  63. ARCH = os.getenv("CARLA_BRIDGE_PLUGIN_BINARY_TYPE", "native")
  64. TESTING = os.getenv("CARLA_BRIDGE_TESTING", None)
  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", "jsfx", "sf2", "sfz"):
  80. FORMAT = sys.argv[arg]
  81. arg += 1
  82. if FORMAT == "vst":
  83. FORMAT = "vst2"
  84. elif len(sys.argv) == arg+1:
  85. FORMAT = "lv2" if ":" in sys.argv[arg] else "internal"
  86. else:
  87. print("Invalid format")
  88. sys.exit(1)
  89. if len(sys.argv) == arg:
  90. printUsageAndQuit()
  91. # --------------------------------------------------------------------------------------------------------
  92. # Set filename/uri
  93. if FORMAT in ("internal", "lv2"):
  94. LABEL = sys.argv[arg]
  95. arg += 1
  96. else:
  97. FILENAME = os.path.expanduser(sys.argv[arg])
  98. arg += 1
  99. # --------------------------------------------------------------------------------------------------------
  100. # Set label (optional)
  101. if len(sys.argv) > arg:
  102. if FORMAT == "internal":
  103. print("label/uri already set, ignoring 2nd label")
  104. elif FORMAT == "lv2":
  105. newpwd = sys.argv[arg]
  106. if os.path.exists(newpwd):
  107. print("using path hack for lv2 plugin")
  108. os.chdir(newpwd)
  109. else:
  110. LABEL = sys.argv[arg]
  111. arg += 1
  112. # --------------------------------------------------------------------------------------------------------
  113. # Set uniqueId (optional)
  114. if len(sys.argv) > arg:
  115. if FORMAT in ("internal", "dssi", "lv2", "au", "sf2", "sfz"):
  116. print("uniqueId is not used in this format, ignored")
  117. else:
  118. try:
  119. UNIQUEID = int(sys.argv[arg])
  120. except:
  121. print("uniqueId must be a number")
  122. sys.exit(1)
  123. arg += 1
  124. # --------------------------------------------------------------------------------------------------------
  125. # Others?
  126. if len(sys.argv) > arg:
  127. print("Got too many arguments, ignoring past uniqueId")
  128. # --------------------------------------------------------------------------------------------------------
  129. # Set bridge binary
  130. BRIDGE = os.path.join(CARLA_LIBDIR, "carla-bridge-" + ARCH)
  131. if ARCH in ("win32", "win64") or TESTING in ("win32", "win64"):
  132. BRIDGE = BRIDGE + ".exe"
  133. # --------------------------------------------------------------------------------------------------------
  134. # Check for existing carla folder
  135. if not os.path.exists(CARLA_LIBDIR):
  136. print("Carla library folder does not exist, is Carla installed?")
  137. sys.exit(2)
  138. if not os.path.exists(CARLA_RESDIR):
  139. print("Carla resource folder does not exist, is Carla installed?")
  140. sys.exit(2)
  141. # --------------------------------------------------------------------------------------------------------
  142. # Check for existing arch binary
  143. if not os.path.exists(BRIDGE):
  144. print("Carla plugin bridge (%s) for the requested arch (%s) does not exist" % (os.path.basename(BRIDGE), ARCH,))
  145. sys.exit(2)
  146. # --------------------------------------------------------------------------------------------------------
  147. # Final checks
  148. if ARCH not in ("native", "posix32", "posix64", "win32", "win64"):
  149. print("Invalid arch")
  150. sys.exit(1)
  151. if FORMAT not in ("internal", "ladspa", "dssi", "lv2", "vst2", "vst3", "au", "jsfx", "sf2", "sfz"):
  152. print("Invalid format")
  153. sys.exit(1)
  154. if FILENAME and not os.path.exists(FILENAME):
  155. print("Requested filename does not exist")
  156. sys.exit(1)
  157. # --------------------------------------------------------------------------------------------------------
  158. # Setup environment
  159. LADSPA_PATH = os.getenv("LADSPA_PATH")
  160. DSSI_PATH = os.getenv("DSSI_PATH")
  161. LV2_PATH = os.getenv("LV2_PATH")
  162. VST2_PATH = os.getenv("VST_PATH")
  163. VST3_PATH = os.getenv("VST3_PATH")
  164. SF2_PATH = os.getenv("SF2_PATH")
  165. SFZ_PATH = os.getenv("SFZ_PATH")
  166. if LADSPA_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_LADSPA"] = LADSPA_PATH
  167. if DSSI_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_DSSI"] = DSSI_PATH
  168. if LV2_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_LV2"] = LV2_PATH
  169. if VST2_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_VST2"] = VST2_PATH
  170. if VST3_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_VST3"] = VST3_PATH
  171. if SF2_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_SF2"] = SF2_PATH
  172. if SFZ_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_SFZ"] = SFZ_PATH
  173. os.environ["ENGINE_OPTION_PATH_BINARIES"] = CARLA_LIBDIR
  174. os.environ["ENGINE_OPTION_PATH_RESOURCES"] = CARLA_RESDIR
  175. # --------------------------------------------------------------------------------------------------------
  176. CARLA_CLIENT_NAME = os.getenv("CARLA_CLIENT_NAME")
  177. LADISH_APP_NAME = os.getenv("LADISH_APP_NAME")
  178. if CARLA_CLIENT_NAME is not None:
  179. os.environ["CARLA_CLIENT_NAME"] = CARLA_CLIENT_NAME
  180. elif LADISH_APP_NAME is not None:
  181. os.environ["CARLA_CLIENT_NAME"] = LADISH_APP_NAME
  182. else:
  183. os.environ["CARLA_CLIENT_NAME"] = "(none)"
  184. # --------------------------------------------------------------------------------------------------------
  185. # Exec
  186. command = []
  187. if os.getenv("CARLA_BRIDGE_PLUGIN_BINARY_TYPE") is not None:
  188. BRIDGE = os.path.join(CARLA_LIBDIR, "carla-bridge-native")
  189. elif ARCH == "win32" or TESTING == "win32":
  190. command.append("wine")
  191. elif ARCH == "win64" or TESTING == "win64":
  192. command.append("wine64")
  193. command.append(BRIDGE)
  194. command.append(FORMAT)
  195. command.append(FILENAME or "(none)")
  196. command.append(LABEL or "(none)")
  197. command.append(str(UNIQUEID))
  198. print(command)
  199. os.execvp(command[0], command)
  200. # --------------------------------------------------------------------------------------------------------