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.

206 lines
7.2KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Carla Backend utils
  4. # Copyright (C) 2011-2014 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 (Global)
  19. from sys import argv
  20. # ------------------------------------------------------------------------------------------------------------
  21. # Imports (Custom)
  22. from carla_backend import *
  23. # ------------------------------------------------------------------------------------------------------------
  24. def getPluginTypeAsString(ptype):
  25. if ptype == PLUGIN_NONE:
  26. return "NONE"
  27. if ptype == PLUGIN_INTERNAL:
  28. return "Internal"
  29. if ptype == PLUGIN_LADSPA:
  30. return "LADSPA"
  31. if ptype == PLUGIN_DSSI:
  32. return "DSSI"
  33. if ptype == PLUGIN_LV2:
  34. return "LV2"
  35. if ptype == PLUGIN_VST2:
  36. return "VST2"
  37. if ptype == PLUGIN_VST3:
  38. return "VST3"
  39. if ptype == PLUGIN_AU:
  40. return "AU"
  41. if ptype == PLUGIN_GIG:
  42. return "GIG"
  43. if ptype == PLUGIN_SF2:
  44. return "SF2"
  45. if ptype == PLUGIN_SFZ:
  46. return "SFZ"
  47. print("getPluginTypeAsString(%i) - invalid type" % ptype);
  48. return "Unknown"
  49. def getPluginTypeFromString(stype):
  50. if not stype:
  51. return PLUGIN_NONE
  52. stype = stype.lower()
  53. if stype == "none":
  54. return PLUGIN_NONE
  55. if stype in ("internal", "native"):
  56. return PLUGIN_INTERNAL
  57. if stype == "ladspa":
  58. return PLUGIN_LADSPA
  59. if stype == "dssi":
  60. return PLUGIN_DSSI
  61. if stype == "lv2":
  62. return PLUGIN_LV2
  63. if stype in ("vst2", "vst"):
  64. return PLUGIN_VST2
  65. if stype == "vst3":
  66. return PLUGIN_VST3
  67. if stype in ("au", "audiounit"):
  68. return PLUGIN_AU
  69. if stype == "gig":
  70. return PLUGIN_GIG
  71. if stype == "sf2":
  72. return PLUGIN_SF2
  73. if stype == "sfz":
  74. return PLUGIN_SFZ
  75. print("getPluginTypeFromString(\"%s\") - invalid string type" % stype)
  76. return PLUGIN_NONE
  77. # ------------------------------------------------------------------------------------------------------------
  78. # Carla Pipe stuff
  79. CarlaPipeClientHandle = c_void_p
  80. CarlaPipeCallbackFunc = CFUNCTYPE(None, c_void_p, c_char_p)
  81. # ------------------------------------------------------------------------------------------------------------
  82. # Carla Utils object using a DLL
  83. class CarlaUtils(object):
  84. def __init__(self, filename):
  85. object.__init__(self)
  86. self.lib = cdll.LoadLibrary(filename)
  87. self.lib.carla_get_library_filename.argtypes = None
  88. self.lib.carla_get_library_filename.restype = c_char_p
  89. self.lib.carla_get_library_folder.argtypes = None
  90. self.lib.carla_get_library_folder.restype = c_char_p
  91. self.lib.carla_set_locale_C.argtypes = None
  92. self.lib.carla_set_locale_C.restype = None
  93. self.lib.carla_set_process_name.argtypes = [c_char_p]
  94. self.lib.carla_set_process_name.restype = None
  95. self.lib.carla_pipe_client_new.argtypes = [POINTER(c_char_p), CarlaPipeCallbackFunc, c_void_p]
  96. self.lib.carla_pipe_client_new.restype = CarlaPipeClientHandle
  97. self.lib.carla_pipe_client_idle.argtypes = [CarlaPipeClientHandle]
  98. self.lib.carla_pipe_client_idle.restype = None
  99. self.lib.carla_pipe_client_is_running.argtypes = [CarlaPipeClientHandle]
  100. self.lib.carla_pipe_client_is_running.restype = c_bool
  101. self.lib.carla_pipe_client_lock.argtypes = [CarlaPipeClientHandle]
  102. self.lib.carla_pipe_client_lock.restype = None
  103. self.lib.carla_pipe_client_unlock.argtypes = [CarlaPipeClientHandle]
  104. self.lib.carla_pipe_client_unlock.restype = None
  105. self.lib.carla_pipe_client_readlineblock.argtypes = [CarlaPipeClientHandle, c_uint]
  106. self.lib.carla_pipe_client_readlineblock.restype = c_char_p
  107. self.lib.carla_pipe_client_write_msg.argtypes = [CarlaPipeClientHandle, c_char_p]
  108. self.lib.carla_pipe_client_write_msg.restype = c_bool
  109. self.lib.carla_pipe_client_write_and_fix_msg.argtypes = [CarlaPipeClientHandle, c_char_p]
  110. self.lib.carla_pipe_client_write_and_fix_msg.restype = c_bool
  111. self.lib.carla_pipe_client_flush.argtypes = [CarlaPipeClientHandle]
  112. self.lib.carla_pipe_client_flush.restype = c_bool
  113. self.lib.carla_pipe_client_flush_and_unlock.argtypes = [CarlaPipeClientHandle]
  114. self.lib.carla_pipe_client_flush_and_unlock.restype = c_bool
  115. self.lib.carla_pipe_client_destroy.argtypes = [CarlaPipeClientHandle]
  116. self.lib.carla_pipe_client_destroy.restype = None
  117. # --------------------------------------------------------------------------------------------------------
  118. def get_library_filename(self):
  119. return charPtrToString(self.lib.carla_get_library_filename())
  120. def get_library_folder(self):
  121. return charPtrToString(self.lib.carla_get_library_folder())
  122. def set_locale_C(self):
  123. self.lib.carla_set_locale_C()
  124. def set_process_name(self, name):
  125. self.lib.carla_set_process_name(name.encode("utf-8"))
  126. def pipe_client_new(self, func):
  127. argc = len(argv)
  128. cagrvtype = c_char_p * argc
  129. cargv = cagrvtype()
  130. for i in range(argc):
  131. cargv[i] = c_char_p(argv[i].encode("utf-8"))
  132. self._pipeClientCallback = CarlaPipeCallbackFunc(func)
  133. return self.lib.carla_pipe_client_new(cargv, self._pipeClientCallback, None)
  134. def pipe_client_idle(self, handle):
  135. self.lib.carla_pipe_client_idle(handle)
  136. def pipe_client_is_running(self, handle):
  137. return bool(self.lib.carla_pipe_client_is_running(handle))
  138. def pipe_client_lock(self, handle):
  139. self.lib.carla_pipe_client_lock(handle)
  140. def pipe_client_unlock(self, handle):
  141. self.lib.carla_pipe_client_unlock(handle)
  142. def pipe_client_readlineblock(self, handle, timeout):
  143. return charPtrToString(self.lib.carla_pipe_client_readlineblock(handle, timeout))
  144. def pipe_client_write_msg(self, handle, msg):
  145. return bool(self.lib.carla_pipe_client_write_msg(handle, msg.encode("utf-8")))
  146. def pipe_client_write_and_fix_msg(self, handle, msg):
  147. return bool(self.lib.carla_pipe_client_write_and_fix_msg(handle, msg.encode("utf-8")))
  148. def pipe_client_flush(self, handle):
  149. return bool(self.lib.carla_pipe_client_flush(handle))
  150. def pipe_client_flush_and_unlock(self, handle):
  151. return bool(self.lib.carla_pipe_client_flush_and_unlock(handle))
  152. def pipe_client_destroy(self, handle):
  153. self.lib.carla_pipe_client_destroy(handle)
  154. # ------------------------------------------------------------------------------------------------------------