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.

364 lines
12KB

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