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.

258 lines
8.1KB

  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. # --------------------------------------------------------------------------------------------------------
  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. - gig
  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. Format can be skipped for internal and lv2 plugins (auto-detected), like this:
  53. $ %s midipattern
  54. $ %s http://synthv1.sourceforge.net/lv2""" % ((sys.argv[0],)*8)
  55. def printUsageAndQuit():
  56. print(usageMsg)
  57. sys.exit(0)
  58. if len(sys.argv) < 2:
  59. printUsageAndQuit()
  60. # --------------------------------------------------------------------------------------------------------
  61. # Initialize variables to null
  62. ARCH = "native"
  63. FORMAT = "none"
  64. FILENAME = ""
  65. LABEL = ""
  66. UNIQUEID = 0
  67. # --------------------------------------------------------------------------------------------------------
  68. # Set arch
  69. arg = 1
  70. if sys.argv[arg] in ("native", "posix32", "posix64", "linux32", "linux64", "mac32", "mac64", "win32", "win64"):
  71. ARCH = sys.argv[arg].replace("linux", "posix").replace("mac", "posix")
  72. arg += 1
  73. if len(sys.argv) == arg:
  74. printUsageAndQuit()
  75. # --------------------------------------------------------------------------------------------------------
  76. # Set format
  77. if sys.argv[arg] in ("internal", "ladspa", "dssi", "lv2", "vst", "vst2", "vst3", "au", "audiounit", "gig", "sf2", "sfz"):
  78. FORMAT = sys.argv[arg]
  79. arg += 1
  80. if FORMAT == "vst":
  81. FORMAT = "vst2"
  82. elif FORMAT == "audiounit":
  83. FORMAT = "au"
  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 in ("internal", "lv2"):
  103. print("label/uri already set, ignoring 2nd label")
  104. else:
  105. LABEL = sys.argv[arg]
  106. arg += 1
  107. # --------------------------------------------------------------------------------------------------------
  108. # Set uniqueId (optional)
  109. if len(sys.argv) > arg:
  110. if FORMAT in ("internal", "dssi", "lv2", "au", "gig", "sf2", "sfz"):
  111. print("uniqueId is not used in this format, ignored")
  112. else:
  113. try:
  114. UNIQUEID = int(sys.argv[arg])
  115. except:
  116. print("uniqueId must be a number")
  117. sys.exit(1)
  118. arg += 1
  119. # --------------------------------------------------------------------------------------------------------
  120. # Others?
  121. if len(sys.argv) > arg:
  122. print("Got too many arguments, ignoring past uniqueId")
  123. # --------------------------------------------------------------------------------------------------------
  124. # Set bridge binary
  125. BRIDGE = os.path.join(CARLA_LIBDIR, "carla-bridge-" + ARCH)
  126. if ARCH in ("win32", "win64"):
  127. BRIDGE = BRIDGE + ".exe"
  128. # --------------------------------------------------------------------------------------------------------
  129. # Check for existing carla folder
  130. if not os.path.exists(CARLA_LIBDIR):
  131. print("Carla library folder does not exist, is Carla installed?")
  132. sys.exit(2)
  133. # --------------------------------------------------------------------------------------------------------
  134. # Check for existing arch binary
  135. if not os.path.exists(BRIDGE):
  136. print("Carla plugin bridge for the requested arch (%s) does not exist" % (ARCH,))
  137. sys.exit(2)
  138. # --------------------------------------------------------------------------------------------------------
  139. # Final checks
  140. if ARCH not in ("native", "posix32", "posix64", "win32", "win64"):
  141. print("Invalid arch")
  142. sys.exit(1)
  143. if FORMAT not in ("internal", "ladspa", "dssi", "lv2", "vst2", "vst3", "gig", "sf2", "sfz"):
  144. print("Invalid format")
  145. sys.exit(1)
  146. if FILENAME and not os.path.exists(FILENAME):
  147. print("Requested filename does not exist")
  148. sys.exit(1)
  149. # --------------------------------------------------------------------------------------------------------
  150. # Setup environment
  151. #os.environ["ENGINE_OPTION_UIS_ALWAYS_ON_TOP"] = "false"
  152. #os.environ["ENGINE_OPTION_MAX_PARAMETERS"] = "200"
  153. #os.environ["ENGINE_OPTION_UI_BRIDGES_TIMEOUT"] = "3000"
  154. LADSPA_PATH = os.getenv("LADSPA_PATH")
  155. DSSI_PATH = os.getenv("DSSI_PATH")
  156. LV2_PATH = os.getenv("LV2_PATH")
  157. VST2_PATH = os.getenv("VST_PATH")
  158. VST3_PATH = os.getenv("VST3_PATH")
  159. AU_PATH = os.getenv("AU_PATH")
  160. GIG_PATH = os.getenv("GIG_PATH")
  161. SF2_PATH = os.getenv("SF2_PATH")
  162. SFZ_PATH = os.getenv("SFZ_PATH")
  163. if LADSPA_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_LADSPA"] = LADSPA_PATH
  164. if DSSI_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_DSSI"] = DSSI_PATH
  165. if LV2_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_LV2"] = LV2_PATH
  166. if VST2_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_VST2"] = VST2_PATH
  167. if VST3_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_VST3"] = VST3_PATH
  168. if AU_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_AU"] = AU_PATH
  169. if GIG_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_GIG"] = GIG_PATH
  170. if SF2_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_SF2"] = SF2_PATH
  171. if SFZ_PATH is not None: os.environ["ENGINE_OPTION_PLUGIN_PATH_SFZ"] = SFZ_PATH
  172. os.environ["ENGINE_OPTION_PATH_BINARIES"] = CARLA_LIBDIR
  173. os.environ["ENGINE_OPTION_PATH_RESOURCES"] = CARLA_RESDIR
  174. # --------------------------------------------------------------------------------------------------------
  175. CARLA_CLIENT_NAME = os.getenv("CARLA_CLIENT_NAME")
  176. LADISH_APP_NAME = os.getenv("LADISH_APP_NAME")
  177. if CARLA_CLIENT_NAME is not None:
  178. os.environ["CARLA_CLIENT_NAME"] = CARLA_CLIENT_NAME
  179. elif CARLA_CLIENT_NAME is not None:
  180. os.environ["CARLA_CLIENT_NAME"] = LADISH_APP_NAME
  181. else:
  182. os.environ["CARLA_CLIENT_NAME"] = "(none)"
  183. # --------------------------------------------------------------------------------------------------------
  184. # Exec
  185. command = []
  186. if ARCH == "win32":
  187. command.append("wine")
  188. elif ARCH == "win64":
  189. command.append("wine64")
  190. command.append(BRIDGE)
  191. command.append(FORMAT)
  192. command.append(FILENAME or "(none)")
  193. command.append(LABEL or "(none)")
  194. command.append(str(UNIQUEID))
  195. print(command)
  196. os.execvp(command[0], command)
  197. # --------------------------------------------------------------------------------------------------------