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-plugin 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Carla plugin host (plugin UI)
  4. # Copyright (C) 2013 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 GPL.txt file
  17. # ------------------------------------------------------------------------------------------------------------
  18. # Imports (Custom Stuff)
  19. from carla_host import *
  20. from externalui import ExternalUI
  21. # ------------------------------------------------------------------------------------------------------------
  22. # Host Plugin object
  23. class PluginHost(object):
  24. def __init__(self):
  25. object.__init__(self)
  26. self.fParent = None
  27. self.fBufferSize = 0
  28. self.fSampleRate = 0.0
  29. self.fLastError = ""
  30. self.fSupportedFileTypes = ""
  31. # -------------------------------------------------------------------
  32. def get_engine_driver_count(self):
  33. return 0
  34. def get_supported_file_types(self):
  35. return self.fSupportedFileTypes
  36. def engine_init(self, driverName, clientName):
  37. return True
  38. def engine_close(self):
  39. return True
  40. def is_engine_running(self):
  41. return True
  42. def set_engine_about_to_close(self):
  43. pass
  44. def set_engine_callback(self, func):
  45. pass
  46. def load_filename(self, filename):
  47. self.fParent.send(["load_filename", filename])
  48. return True
  49. def load_project(self, filename):
  50. self.fParent.send(["load_project", filename])
  51. return True
  52. def save_project(self, filename):
  53. self.fParent.send(["save_project", filename])
  54. return True
  55. def patchbay_connect(self, portIdA, portIdB):
  56. self.fParent.send(["patchbay_connect", portIdA, portIdB])
  57. return True
  58. def patchbay_disconnect(self, connectionId):
  59. self.fParent.send(["patchbay_disconnect", connectionId])
  60. return True
  61. def patchbay_refresh(self):
  62. self.fParent.send(["patchbay_refresh"])
  63. return True
  64. def add_plugin(self, btype, ptype, filename, name, label, extraStuff):
  65. self.fParent.send(["add_plugin", btype, ptype, filename, name, label])
  66. return True
  67. def remove_plugin(self, pluginId):
  68. self.fParent.send(["remove_plugin", pluginId])
  69. return True
  70. def remove_all_plugins(self):
  71. self.fParent.send(["remove_all_plugins"])
  72. return True
  73. def rename_plugin(self, pluginId, newName):
  74. self.fParent.send(["rename_plugin", pluginId, newName])
  75. return True
  76. def clone_plugin(self, pluginId):
  77. self.fParent.send(["clone_plugin", pluginId])
  78. return True
  79. def replace_plugin(self, pluginId):
  80. self.fParent.send(["replace_plugin", pluginId])
  81. return True
  82. def switch_plugins(self, pluginIdA, pluginIdB):
  83. self.fParent.send(["switch_plugins", pluginIdA, pluginIdB])
  84. return True
  85. def load_plugin_state(self, pluginId, filename):
  86. self.fParent.send(["load_plugin_state", pluginId, filename])
  87. return True
  88. def save_plugin_state(self, pluginId, filename):
  89. self.fParent.send(["save_plugin_state", pluginId, filename])
  90. return True
  91. #def get_plugin_info(self, pluginId):
  92. #return structToDict(self.lib.carla_get_plugin_info(pluginId).contents)
  93. #def get_audio_port_count_info(self, pluginId):
  94. #return structToDict(self.lib.carla_get_audio_port_count_info(pluginId).contents)
  95. #def get_midi_port_count_info(self, pluginId):
  96. #return structToDict(self.lib.carla_get_midi_port_count_info(pluginId).contents)
  97. #def get_parameter_count_info(self, pluginId):
  98. #return structToDict(self.lib.carla_get_parameter_count_info(pluginId).contents)
  99. #def get_parameter_info(self, pluginId, parameterId):
  100. #return structToDict(self.lib.carla_get_parameter_info(pluginId, parameterId).contents)
  101. #def get_parameter_scalepoint_info(self, pluginId, parameterId, scalePointId):
  102. #return structToDict(self.lib.carla_get_parameter_scalepoint_info(pluginId, parameterId, scalePointId).contents)
  103. #def get_parameter_data(self, pluginId, parameterId):
  104. #return structToDict(self.lib.carla_get_parameter_data(pluginId, parameterId).contents)
  105. #def get_parameter_ranges(self, pluginId, parameterId):
  106. #return structToDict(self.lib.carla_get_parameter_ranges(pluginId, parameterId).contents)
  107. #def get_midi_program_data(self, pluginId, midiProgramId):
  108. #return structToDict(self.lib.carla_get_midi_program_data(pluginId, midiProgramId).contents)
  109. #def get_custom_data(self, pluginId, customDataId):
  110. #return structToDict(self.lib.carla_get_custom_data(pluginId, customDataId).contents)
  111. #def get_chunk_data(self, pluginId):
  112. #return self.lib.carla_get_chunk_data(pluginId)
  113. #def get_parameter_count(self, pluginId):
  114. #return self.lib.carla_get_parameter_count(pluginId)
  115. #def get_program_count(self, pluginId):
  116. #return self.lib.carla_get_program_count(pluginId)
  117. #def get_midi_program_count(self, pluginId):
  118. #return self.lib.carla_get_midi_program_count(pluginId)
  119. #def get_custom_data_count(self, pluginId):
  120. #return self.lib.carla_get_custom_data_count(pluginId)
  121. #def get_parameter_text(self, pluginId, parameterId):
  122. #return self.lib.carla_get_parameter_text(pluginId, parameterId)
  123. #def get_program_name(self, pluginId, programId):
  124. #return self.lib.carla_get_program_name(pluginId, programId)
  125. #def get_midi_program_name(self, pluginId, midiProgramId):
  126. #return self.lib.carla_get_midi_program_name(pluginId, midiProgramId)
  127. #def get_real_plugin_name(self, pluginId):
  128. #return self.lib.carla_get_real_plugin_name(pluginId)
  129. #def get_current_program_index(self, pluginId):
  130. #return self.lib.carla_get_current_program_index(pluginId)
  131. #def get_current_midi_program_index(self, pluginId):
  132. #return self.lib.carla_get_current_midi_program_index(pluginId)
  133. #def get_default_parameter_value(self, pluginId, parameterId):
  134. #return self.lib.carla_get_default_parameter_value(pluginId, parameterId)
  135. #def get_current_parameter_value(self, pluginId, parameterId):
  136. #return self.lib.carla_get_current_parameter_value(pluginId, parameterId)
  137. #def get_input_peak_value(self, pluginId, portId):
  138. #return self.lib.carla_get_input_peak_value(pluginId, portId)
  139. #def get_output_peak_value(self, pluginId, portId):
  140. #return self.lib.carla_get_output_peak_value(pluginId, portId)
  141. def set_option(self, pluginId, option, yesNo):
  142. self.fParent.send(["set_option", pluginId, option, yesNo])
  143. def set_active(self, pluginId, onOff):
  144. self.fParent.send(["set_active", pluginId, onOff])
  145. def set_drywet(self, pluginId, value):
  146. self.fParent.send(["set_drywet", pluginId, value])
  147. def set_volume(self, pluginId, value):
  148. self.fParent.send(["set_volume", pluginId, value])
  149. def set_balance_left(self, pluginId, value):
  150. self.fParent.send(["set_balance_left", pluginId, value])
  151. def set_balance_right(self, pluginId, value):
  152. self.fParent.send(["set_balance_right", pluginId, value])
  153. def set_panning(self, pluginId, value):
  154. self.fParent.send(["set_panning", pluginId, value])
  155. def set_ctrl_channel(self, pluginId, channel):
  156. self.fParent.send(["set_ctrl_channel", pluginId, channel])
  157. def set_parameter_value(self, pluginId, parameterId, value):
  158. self.fParent.send(["set_parameter_value", pluginId, parameterId, value])
  159. def set_parameter_midi_cc(self, pluginId, parameterId, cc):
  160. self.fParent.send(["set_parameter_midi_cc", pluginId, parameterId, cc])
  161. def set_parameter_midi_channel(self, pluginId, parameterId, channel):
  162. self.fParent.send(["set_parameter_midi_channel", pluginId, parameterId, channel])
  163. def set_program(self, pluginId, programId):
  164. self.fParent.send(["set_program", pluginId, programId])
  165. def set_midi_program(self, pluginId, midiProgramId):
  166. self.fParent.send(["set_midi_program", pluginId, midiProgramId])
  167. def set_custom_data(self, pluginId, type_, key, value):
  168. self.fParent.send(["set_custom_data", pluginId, type_, key, value])
  169. def set_chunk_data(self, pluginId, chunkData):
  170. self.fParent.send(["set_chunk_data", pluginId, chunkData])
  171. def prepare_for_save(self, pluginId):
  172. self.fParent.send(["prepare_for_save", pluginId])
  173. def send_midi_note(self, pluginId, channel, note, velocity):
  174. self.fParent.send(["send_midi_note", pluginId, channel, note, velocity])
  175. def show_gui(self, pluginId, yesNo):
  176. self.fParent.send(["show_gui", pluginId, yesNo])
  177. def get_last_error(self):
  178. return self.fLastError
  179. def get_buffer_size(self):
  180. return self.fBufferSize
  181. def get_sample_rate(self):
  182. return self.fSampleRate
  183. # ------------------------------------------------------------------------------------------------------------
  184. # Init plugin
  185. def initPlugin():
  186. Carla.host = PluginHost()
  187. # ------------------------------------------------------------------------------------------------------------
  188. # Main Window
  189. class CarlaMiniW(HostWindow, ExternalUI):
  190. def __init__(self):
  191. HostWindow.__init__(self, None)
  192. ExternalUI.__init__(self)
  193. if Carla.host is not None:
  194. Carla.host.fParent = None
  195. Carla.host.fSampleRate = self.d_getSampleRate()
  196. if False:
  197. from carla_patchbay import CarlaPatchbayW
  198. self.fContainer = CarlaPatchbayW(self)
  199. else:
  200. from carla_rack import CarlaRackW
  201. self.fContainer = CarlaRackW(self)
  202. self.setCentralWidget(self.fContainer)
  203. self.setWindowTitle(self.fUiName)
  204. self.fIdleTimer = self.startTimer(50)
  205. self.showUiIfTesting()
  206. # -------------------------------------------------------------------
  207. # ExternalUI Callbacks
  208. def d_uiShow(self):
  209. self.show()
  210. def d_uiHide(self):
  211. self.hide()
  212. def d_uiQuit(self):
  213. self.close()
  214. app.quit()
  215. def d_uiTitleChanged(self, uiTitle):
  216. self.setWindowTitle(uiTitle)
  217. # -------------------------------------------------------------------
  218. # Qt events
  219. def timerEvent(self, event):
  220. if event.timerId() == self.fIdleTimer:
  221. if not self.idleExternalUI():
  222. self.d_uiQuit()
  223. QWidget.timerEvent(self, event)
  224. def closeEvent(self, event):
  225. self.closeExternalUI()
  226. HostWindow.closeEvent(self, event)
  227. # ------------------------------------------------------------------------------------------------------------
  228. # Main
  229. if __name__ == '__main__':
  230. # -------------------------------------------------------------
  231. # App initialization
  232. app = CarlaApplication()
  233. # -------------------------------------------------------------
  234. # Set-up custom signal handling
  235. setUpSignals()
  236. # -------------------------------------------------------------
  237. # Setup
  238. Carla.isControl = False
  239. Carla.isLocal = False
  240. Carla.isPlugin = True
  241. # -------------------------------------------------------------
  242. # Read CLI args
  243. argv = app.arguments()
  244. argc = len(argv)
  245. if argc > 1:
  246. pass
  247. # -------------------------------------------------------------
  248. # Init plugin backend
  249. initPlugin()
  250. # -------------------------------------------------------------
  251. # Create GUI
  252. Carla.gui = CarlaMiniW()
  253. # -------------------------------------------------------------
  254. # App-Loop
  255. sys.exit(app.exec_())