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.

898 lines
35KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Carla Backend code
  4. # Copyright (C) 2011-2012 Filipe Coelho <falktx@falktx.com>
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # 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 COPYING file
  17. # Imports (Global)
  18. from PyQt4.QtGui import QApplication, QMainWindow
  19. from liblo import make_method, Address, ServerError, ServerThread
  20. from liblo import send as lo_send
  21. from liblo import TCP as LO_TCP
  22. # Imports (Custom)
  23. import ui_carla_control
  24. from shared_carla import *
  25. global lo_target, lo_targetName
  26. lo_target = None
  27. lo_targetName = ""
  28. Carla.isControl = True
  29. # Python Object dicts compatible to carla-backend struct ctypes
  30. MidiProgramData = {
  31. 'bank': 0,
  32. 'program': 0,
  33. 'label': None
  34. }
  35. ParameterData = {
  36. 'type': PARAMETER_NULL,
  37. 'index': 0,
  38. 'rindex': -1,
  39. 'hints': 0x0,
  40. 'midiChannel': 0,
  41. 'midiCC': -1
  42. }
  43. ParameterRanges = {
  44. 'def': 0.0,
  45. 'min': 0.0,
  46. 'max': 1.0,
  47. 'step': 0.0,
  48. 'stepSmall': 0.0,
  49. 'stepLarge': 0.0
  50. }
  51. CustomData = {
  52. 'type': CUSTOM_DATA_INVALID,
  53. 'key': None,
  54. 'value': None
  55. }
  56. PluginInfo = {
  57. 'type': PLUGIN_NONE,
  58. 'category': PLUGIN_CATEGORY_NONE,
  59. 'hints': 0x0,
  60. 'binary': None,
  61. 'name': None,
  62. 'label': None,
  63. 'maker': None,
  64. 'copyright': None,
  65. 'uniqueId': 0
  66. }
  67. PortCountInfo = {
  68. 'ins': 0,
  69. 'outs': 0,
  70. 'total': 0
  71. }
  72. ParameterInfo = {
  73. 'name': None,
  74. 'symbol': None,
  75. 'unit': None,
  76. 'scalePointCount': 0,
  77. }
  78. ScalePointInfo = {
  79. 'value': 0.0,
  80. 'label': None
  81. }
  82. GuiInfo = {
  83. 'type': GUI_NONE,
  84. 'resizable': False
  85. }
  86. class ControlPluginInfo(object):
  87. __slots__ = [
  88. 'pluginInfo',
  89. 'pluginRealName',
  90. 'audioCountInfo',
  91. 'midiCountInfo',
  92. 'parameterCountInfo',
  93. 'parameterInfoS',
  94. 'parameterDataS',
  95. 'parameterRangeS',
  96. 'parameterValueS',
  97. 'programCount',
  98. 'programCurrent',
  99. 'programNameS',
  100. 'midiProgramCount',
  101. 'midiProgramCurrent',
  102. 'midiProgramDataS',
  103. 'inPeak',
  104. 'outPeak'
  105. ]
  106. # Python Object class compatible to 'Host' on the Carla Backend code
  107. class Host(object):
  108. def __init__(self):
  109. object.__init__(self)
  110. self.pluginInfo = []
  111. for i in range(MAX_PLUGINS):
  112. self.pluginInfo.append(ControlPluginInfo())
  113. self._clear(i)
  114. def _clear(self, index):
  115. self.pluginInfo[index].pluginInfo = PluginInfo
  116. self.pluginInfo[index].pluginRealName = None
  117. self.pluginInfo[index].audioCountInfo = PortCountInfo
  118. self.pluginInfo[index].midiCountInfo = PortCountInfo
  119. self.pluginInfo[index].parameterCountInfo = PortCountInfo
  120. self.pluginInfo[index].parameterInfoS = []
  121. self.pluginInfo[index].parameterDataS = []
  122. self.pluginInfo[index].parameterRangeS = []
  123. self.pluginInfo[index].parameterValueS = []
  124. self.pluginInfo[index].programCount = 0
  125. self.pluginInfo[index].programCurrent = -1
  126. self.pluginInfo[index].programNameS = []
  127. self.pluginInfo[index].midiProgramCount = 0
  128. self.pluginInfo[index].midiProgramCurrent = -1
  129. self.pluginInfo[index].midiProgramDataS = []
  130. self.pluginInfo[index].inPeak = [0.0, 0.0]
  131. self.pluginInfo[index].outPeak = [0.0, 0.0]
  132. def _set_pluginInfo(self, index, info):
  133. self.pluginInfo[index].pluginInfo = info
  134. def _set_pluginRealName(self, index, realName):
  135. self.pluginInfo[index].pluginRealName = realName
  136. def _set_audioCountInfo(self, index, info):
  137. self.pluginInfo[index].audioCountInfo = info
  138. def _set_midiCountInfo(self, index, info):
  139. self.pluginInfo[index].midiCountInfo = info
  140. def _set_parameterCountInfo(self, index, info):
  141. self.pluginInfo[index].parameterCountInfo = info
  142. # clear
  143. self.pluginInfo[index].parameterInfoS = []
  144. self.pluginInfo[index].parameterDataS = []
  145. self.pluginInfo[index].parameterRangeS = []
  146. self.pluginInfo[index].parameterValueS = []
  147. # add placeholders
  148. for x in range(info['total']):
  149. self.pluginInfo[index].parameterInfoS.append(ParameterInfo)
  150. self.pluginInfo[index].parameterDataS.append(ParameterData)
  151. self.pluginInfo[index].parameterRangeS.append(ParameterRanges)
  152. self.pluginInfo[index].parameterValueS.append(0.0)
  153. def _set_programCount(self, index, count):
  154. self.pluginInfo[index].programCount = count
  155. # clear
  156. self.pluginInfo[index].programNameS = []
  157. # add placeholders
  158. for x in range(count):
  159. self.pluginInfo[index].programNameS.append(None)
  160. def _set_midiProgramCount(self, index, count):
  161. self.pluginInfo[index].midiProgramCount = count
  162. # clear
  163. self.pluginInfo[index].midiProgramDataS = []
  164. # add placeholders
  165. for x in range(count):
  166. self.pluginInfo[index].midiProgramDataS.append(MidiProgramData)
  167. def _set_parameterInfoS(self, index, paramIndex, data):
  168. if paramIndex < self.pluginInfo[index].parameterCountInfo['total']:
  169. self.pluginInfo[index].parameterInfoS[paramIndex] = data
  170. def _set_parameterDataS(self, index, paramIndex, data):
  171. if paramIndex < self.pluginInfo[index].parameterCountInfo['total']:
  172. self.pluginInfo[index].parameterDataS[paramIndex] = data
  173. def _set_parameterRangeS(self, index, paramIndex, data):
  174. if paramIndex < self.pluginInfo[index].parameterCountInfo['total']:
  175. self.pluginInfo[index].parameterRangeS[paramIndex] = data
  176. def _set_parameterValueS(self, index, paramIndex, value):
  177. if paramIndex < self.pluginInfo[index].parameterCountInfo['total']:
  178. self.pluginInfo[index].parameterValueS[paramIndex] = value
  179. def _set_parameterDefaultValue(self, index, paramIndex, value):
  180. if paramIndex < self.pluginInfo[index].parameterCountInfo['total']:
  181. self.pluginInfo[index].parameterRangeS[paramIndex]['def'] = value
  182. def _set_parameterMidiCC(self, index, paramIndex, cc):
  183. if paramIndex < self.pluginInfo[index].parameterCountInfo['total']:
  184. self.pluginInfo[index].parameterDataS[paramIndex]['midiCC'] = cc
  185. def _set_parameterMidiChannel(self, index, paramIndex, channel):
  186. if paramIndex < self.pluginInfo[index].parameterCountInfo['total']:
  187. self.pluginInfo[index].parameterDataS[paramIndex]['midiChannel'] = channel
  188. def _set_currentProgram(self, index, pIndex):
  189. self.pluginInfo[index].programCurrent = pIndex
  190. def _set_currentMidiProgram(self, index, mpIndex):
  191. self.pluginInfo[index].midiProgramCurrent = mpIndex
  192. def _set_programNameS(self, index, pIndex, data):
  193. if pIndex < self.pluginInfo[index].programCount:
  194. self.pluginInfo[index].programNameS[pIndex] = data
  195. def _set_midiProgramDataS(self, index, mpIndex, data):
  196. if mpIndex < self.pluginInfo[index].midiProgramCount:
  197. self.pluginInfo[index].midiProgramDataS[mpIndex] = data
  198. def _set_inPeak(self, index, port, value):
  199. self.pluginInfo[index].inPeak[port] = value
  200. def _set_outPeak(self, index, port, value):
  201. self.pluginInfo[index].outPeak[port] = value
  202. def get_plugin_info(self, plugin_id):
  203. return self.pluginInfo[plugin_id].pluginInfo
  204. def get_audio_port_count_info(self, plugin_id):
  205. return self.pluginInfo[plugin_id].audioCountInfo
  206. def get_midi_port_count_info(self, plugin_id):
  207. return self.pluginInfo[plugin_id].midiCountInfo
  208. def get_parameter_count_info(self, plugin_id):
  209. return self.pluginInfo[plugin_id].parameterCountInfo
  210. def get_parameter_info(self, plugin_id, parameter_id):
  211. return self.pluginInfo[plugin_id].parameterInfoS[parameter_id]
  212. def get_parameter_scalepoint_info(self, plugin_id, parameter_id, scalepoint_id):
  213. return ScalePointInfo
  214. def get_gui_info(self, plugin_id):
  215. return GuiInfo
  216. def get_parameter_data(self, plugin_id, parameter_id):
  217. return self.pluginInfo[plugin_id].parameterDataS[parameter_id]
  218. def get_parameter_ranges(self, plugin_id, parameter_id):
  219. return self.pluginInfo[plugin_id].parameterRangeS[parameter_id]
  220. def get_midi_program_data(self, plugin_id, midi_program_id):
  221. return self.pluginInfo[plugin_id].midiProgramDataS[midi_program_id]
  222. def get_custom_data(self, plugin_id, custom_data_id):
  223. return CustomData
  224. def get_chunk_data(self, plugin_id):
  225. return None
  226. def get_parameter_count(self, plugin_id):
  227. return self.pluginInfo[plugin_id].parameterCountInfo['total']
  228. def get_program_count(self, plugin_id):
  229. return self.pluginInfo[plugin_id].programCount
  230. def get_midi_program_count(self, plugin_id):
  231. return self.pluginInfo[plugin_id].midiProgramCount
  232. def get_custom_data_count(self, plugin_id):
  233. return 0
  234. def get_parameter_text(self, plugin_id, program_id):
  235. return None
  236. def get_program_name(self, plugin_id, program_id):
  237. return self.pluginInfo[plugin_id].programNameS[program_id]
  238. def get_midi_program_name(self, plugin_id, midi_program_id):
  239. return self.pluginInfo[plugin_id].midiProgramDataS[midi_program_id]['label']
  240. def get_real_plugin_name(self, plugin_id):
  241. return self.pluginInfo[plugin_id].pluginRealName
  242. def get_current_program_index(self, plugin_id):
  243. return self.pluginInfo[plugin_id].programCurrent
  244. def get_current_midi_program_index(self, plugin_id):
  245. return self.pluginInfo[plugin_id].midiProgramCurrent
  246. def get_default_parameter_value(self, plugin_id, parameter_id):
  247. return self.pluginInfo[plugin_id].parameterRangeS[parameter_id]['def']
  248. def get_current_parameter_value(self, plugin_id, parameter_id):
  249. return self.pluginInfo[plugin_id].parameterValueS[parameter_id]
  250. def get_input_peak_value(self, plugin_id, port_id):
  251. return self.pluginInfo[plugin_id].inPeak[port_id-1]
  252. def get_output_peak_value(self, plugin_id, port_id):
  253. return self.pluginInfo[plugin_id].outPeak[port_id-1]
  254. def set_active(self, plugin_id, onoff):
  255. global to_target, lo_targetName
  256. lo_path = "/%s/%i/set_active" % (lo_targetName, plugin_id)
  257. lo_send(lo_target, lo_path, 1 if onoff else 0)
  258. def set_drywet(self, plugin_id, value):
  259. global to_target, lo_targetName
  260. lo_path = "/%s/%i/set_drywet" % (lo_targetName, plugin_id)
  261. lo_send(lo_target, lo_path, value)
  262. def set_volume(self, plugin_id, value):
  263. global to_target, lo_targetName
  264. lo_path = "/%s/%i/set_volume" % (lo_targetName, plugin_id)
  265. lo_send(lo_target, lo_path, value)
  266. def set_balance_left(self, plugin_id, value):
  267. global to_target, lo_targetName
  268. lo_path = "/%s/%i/set_balance_left" % (lo_targetName, plugin_id)
  269. lo_send(lo_target, lo_path, value)
  270. def set_balance_right(self, plugin_id, value):
  271. global to_target, lo_targetName
  272. lo_path = "/%s/%i/set_balance_right" % (lo_targetName, plugin_id)
  273. lo_send(lo_target, lo_path, value)
  274. def set_parameter_value(self, plugin_id, parameter_id, value):
  275. global to_target, lo_targetName
  276. lo_path = "/%s/%i/set_parameter_value" % (lo_targetName, plugin_id)
  277. lo_send(lo_target, lo_path, parameter_id, value)
  278. def set_parameter_midi_channel(self, plugin_id, parameter_id, channel):
  279. global to_target, lo_targetName
  280. lo_path = "/%s/%i/set_parameter_midi_channel" % (lo_targetName, plugin_id)
  281. lo_send(lo_target, lo_path, parameter_id, channel)
  282. def set_parameter_midi_cc(self, plugin_id, parameter_id, midi_cc):
  283. global to_target, lo_targetName
  284. lo_path = "/%s/%i/set_parameter_midi_cc" % (lo_targetName, plugin_id)
  285. lo_send(lo_target, lo_path, parameter_id, midi_cc)
  286. def set_program(self, plugin_id, program_id):
  287. global to_target, lo_targetName
  288. lo_path = "/%s/%i/set_program" % (lo_targetName, plugin_id)
  289. lo_send(lo_target, lo_path, program_id)
  290. def set_midi_program(self, plugin_id, midi_program_id):
  291. global to_target, lo_targetName
  292. lo_path = "/%s/%i/set_midi_program" % (lo_targetName, plugin_id)
  293. lo_send(lo_target, lo_path, midi_program_id)
  294. def send_midi_note(self, plugin_id, channel, note, velocity):
  295. global to_target, lo_targetName
  296. if velocity:
  297. lo_path = "/%s/%i/note_on" % (lo_targetName, plugin_id)
  298. lo_send(lo_target, lo_path, channel, note, velocity)
  299. else:
  300. lo_path = "/%s/%i/note_off" % (lo_targetName, plugin_id)
  301. lo_send(lo_target, lo_path, channel, note)
  302. # OSC Control server
  303. class ControlServer(ServerThread):
  304. def __init__(self, parent):
  305. ServerThread.__init__(self, 8087, LO_TCP)
  306. self.parent = parent
  307. def getFullURL(self):
  308. return "%scarla-control" % self.get_url()
  309. @make_method('/carla-control/add_plugin_start', 'is')
  310. def add_plugin_start_callback(self, path, args):
  311. pluginId, pluginName = args
  312. self.parent.emit(SIGNAL("AddPluginStart(int, QString)"), pluginId, pluginName)
  313. @make_method('/carla-control/add_plugin_end', 'i')
  314. def add_plugin_end_callback(self, path, args):
  315. pluginId, = args
  316. self.parent.emit(SIGNAL("AddPluginEnd(int)"), pluginId)
  317. @make_method('/carla-control/remove_plugin', 'i')
  318. def remove_plugin_callback(self, path, args):
  319. pluginId, = args
  320. self.parent.emit(SIGNAL("RemovePlugin(int)"), pluginId)
  321. @make_method('/carla-control/set_plugin_data', 'iiiissssh')
  322. def set_plugin_data_callback(self, path, args):
  323. pluginId, ptype, category, hints, realName, label, maker, copyright_, uniqueId = args
  324. self.parent.emit(SIGNAL("SetPluginData(int, int, int, int, QString, QString, QString, QString, int)"), pluginId, ptype, category, hints, realName, label, maker, copyright_, uniqueId)
  325. @make_method('/carla-control/set_plugin_ports', 'iiiiiiii')
  326. def set_plugin_ports_callback(self, path, args):
  327. pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals = args
  328. self.parent.emit(SIGNAL("SetPluginPorts(int, int, int, int, int, int, int, int)"), pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals)
  329. @make_method('/carla-control/set_parameter_data', 'iiiissd')
  330. def set_parameter_data_callback(self, path, args):
  331. pluginId, index, type_, hints, name, label, current = args
  332. self.parent.emit(SIGNAL("SetParameterData(int, int, int, int, QString, QString, double)"), pluginId, index, type_, hints, name, label, current)
  333. @make_method('/carla-control/set_parameter_ranges', 'iidddddd')
  334. def set_parameter_ranges_callback(self, path, args):
  335. pluginId, index, min_, max_, def_, step, stepSmall, stepLarge = args
  336. self.parent.emit(SIGNAL("SetParameterRanges(int, int, double, double, double, double, double, double)"), pluginId, index, min_, max_, def_, step, stepSmall, stepLarge)
  337. @make_method('/carla-control/set_parameter_midi_cc', 'iii')
  338. def set_parameter_midi_cc_callback(self, path, args):
  339. pluginId, index, cc = args
  340. self.parent.emit(SIGNAL("SetParameterMidiCC(int, int, int)"), pluginId, index, cc)
  341. @make_method('/carla-control/set_parameter_midi_channel', 'iii')
  342. def set_parameter_midi_channel_callback(self, path, args):
  343. pluginId, index, channel = args
  344. self.parent.emit(SIGNAL("SetParameterMidiChannel(int, int, int)"), pluginId, index, channel)
  345. @make_method('/carla-control/set_parameter_value', 'iid')
  346. def set_parameter_value_callback(self, path, args):
  347. pluginId, index, value = args
  348. self.parent.emit(SIGNAL("SetParameterValue(int, int, double)"), pluginId, index, value)
  349. @make_method('/carla-control/set_default_value', 'iid')
  350. def set_default_value_callback(self, path, args):
  351. pluginId, index, value = args
  352. self.parent.emit(SIGNAL("SetDefaultValue(int, int, double)"), pluginId, index, value)
  353. @make_method('/carla-control/set_program', 'ii')
  354. def set_program_callback(self, path, args):
  355. pluginId, index = args
  356. self.parent.emit(SIGNAL("SetProgram(int, int)"), pluginId, index)
  357. @make_method('/carla-control/set_program_count', 'ii')
  358. def set_program_count_callback(self, path, args):
  359. pluginId, count = args
  360. self.parent.emit(SIGNAL("SetProgramCount(int, int)"), pluginId, count)
  361. @make_method('/carla-control/set_program_name', 'iis')
  362. def set_program_name_callback(self, path, args):
  363. pluginId, index, name = args
  364. self.parent.emit(SIGNAL("SetProgramName(int, int, QString)"), pluginId, index, name)
  365. @make_method('/carla-control/set_midi_program', 'ii')
  366. def set_midi_program_callback(self, path, args):
  367. pluginId, index = args
  368. self.parent.emit(SIGNAL("SetMidiProgram(int, int)"), pluginId, index)
  369. @make_method('/carla-control/set_midi_program_count', 'ii')
  370. def set_midi_program_count_callback(self, path, args):
  371. pluginId, count = args
  372. self.parent.emit(SIGNAL("SetMidiProgramCount(int, int)"), pluginId, count)
  373. @make_method('/carla-control/set_midi_program_data', 'iiiis')
  374. def set_midi_program_data_callback(self, path, args):
  375. pluginId, index, bank, program, name = args
  376. self.parent.emit(SIGNAL("SetMidiProgramData(int, int, int, int, QString)"), pluginId, index, bank, program, name)
  377. @make_method('/carla-control/set_input_peak_value', 'iid')
  378. def set_input_peak_value_callback(self, path, args):
  379. pluginId, portId, value = args
  380. self.parent.emit(SIGNAL("SetInputPeakValue(int, int, double)"), pluginId, portId, value)
  381. @make_method('/carla-control/set_output_peak_value', 'iid')
  382. def set_output_peak_value_callback(self, path, args):
  383. pluginId, portId, value = args
  384. self.parent.emit(SIGNAL("SetOutputPeakValue(int, int, double)"), pluginId, portId, value)
  385. @make_method('/carla-control/note_on', 'iiii')
  386. def note_on_callback(self, path, args):
  387. pluginId, channel, note, velo = args
  388. self.parent.emit(SIGNAL("NoteOn(int, int, int, int)"), pluginId, channel, note, velo)
  389. @make_method('/carla-control/note_off', 'iii')
  390. def note_off_callback(self, path, args):
  391. pluginId, channel, note = args
  392. self.parent.emit(SIGNAL("NoteOff(int, int, int)"), pluginId, channel, note)
  393. @make_method('/carla-control/exit', '')
  394. def exit_callback(self, path, args):
  395. self.parent.emit(SIGNAL("Exit()"))
  396. @make_method(None, None)
  397. def fallback(self, path, args):
  398. print("ControlServer::fallback(\"%s\") - unknown message, args =" % path, args)
  399. # Main Window
  400. class CarlaControlW(QMainWindow, ui_carla_control.Ui_CarlaControlW):
  401. def __init__(self, parent=None):
  402. QMainWindow.__init__(self, parent)
  403. self.setupUi(self)
  404. # -------------------------------------------------------------
  405. # Load Settings
  406. self.settings = QSettings("Cadence", "Carla-Control")
  407. self.loadSettings()
  408. self.setStyleSheet("""
  409. QWidget#centralwidget {
  410. background-color: qlineargradient(spread:pad,
  411. x1:0.0, y1:0.0,
  412. x2:0.2, y2:1.0,
  413. stop:0 rgb( 7, 7, 7),
  414. stop:1 rgb(28, 28, 28)
  415. );
  416. }
  417. """)
  418. # -------------------------------------------------------------
  419. # Internal stuff
  420. self.lo_address = ""
  421. self.lo_server = None
  422. self.m_lastPluginName = None
  423. self.m_plugin_list = []
  424. for x in range(MAX_PLUGINS):
  425. self.m_plugin_list.append(None)
  426. # -------------------------------------------------------------
  427. # Set-up GUI stuff
  428. self.act_file_refresh.setEnabled(False)
  429. self.resize(self.width(), 0)
  430. # -------------------------------------------------------------
  431. # Connect actions to functions
  432. self.connect(self.act_file_connect, SIGNAL("triggered()"), SLOT("slot_doConnect()"))
  433. self.connect(self.act_file_refresh, SIGNAL("triggered()"), SLOT("slot_doRefresh()"))
  434. self.connect(self.act_help_about, SIGNAL("triggered()"), SLOT("slot_aboutCarlaControl()"))
  435. self.connect(self.act_help_about_qt, SIGNAL("triggered()"), app, SLOT("aboutQt()"))
  436. self.connect(self, SIGNAL("AddPluginStart(int, QString)"), SLOT("slot_handleAddPluginStart(int, QString)"))
  437. self.connect(self, SIGNAL("AddPluginEnd(int)"), SLOT("slot_handleAddPluginEnd(int)"))
  438. self.connect(self, SIGNAL("RemovePlugin(int)"), SLOT("slot_handleRemovePlugin(int)"))
  439. self.connect(self, SIGNAL("SetPluginData(int, int, int, int, QString, QString, QString, QString, int)"), SLOT("slot_handleSetPluginData(int, int, int, int, QString, QString, QString, QString, int)"))
  440. self.connect(self, SIGNAL("SetPluginPorts(int, int, int, int, int, int, int, int)"), SLOT("slot_handleSetPluginPorts(int, int, int, int, int, int, int, int)"))
  441. self.connect(self, SIGNAL("SetParameterData(int, int, int, int, QString, QString, double)"), SLOT("slot_handleSetParameterData(int, int, int, int, QString, QString, double)"))
  442. self.connect(self, SIGNAL("SetParameterRanges(int, int, double, double, double, double, double, double)"), SLOT("slot_handleSetParameterRanges(int, int, double, double, double, double, double, double)"))
  443. self.connect(self, SIGNAL("SetParameterMidiCC(int, int, int)"), SLOT("slot_handleSetParameterMidiCC(int, int, int)"))
  444. self.connect(self, SIGNAL("SetParameterMidiChannel(int, int, int)"), SLOT("slot_handleSetParameterMidiChannel(int, int, int)"))
  445. self.connect(self, SIGNAL("SetParameterValue(int, int, double)"), SLOT("slot_handleSetParameterValue(int, int, double)"))
  446. self.connect(self, SIGNAL("SetDefaultValue(int, int, double)"), SLOT("slot_handleSetDefaultValue(int, int, double)"))
  447. self.connect(self, SIGNAL("SetProgram(int, int)"), SLOT("slot_handleSetProgram(int, int)"))
  448. self.connect(self, SIGNAL("SetProgramCount(int, int)"), SLOT("slot_handleSetProgramCount(int, int)"))
  449. self.connect(self, SIGNAL("SetProgramName(int, int, QString)"), SLOT("slot_handleSetProgramName(int, int, QString)"))
  450. self.connect(self, SIGNAL("SetMidiProgram(int, int)"), SLOT("slot_handleSetMidiProgram(int, int)"))
  451. self.connect(self, SIGNAL("SetMidiProgramCount(int, int)"), SLOT("slot_handleSetMidiProgramCount(int, int)"))
  452. self.connect(self, SIGNAL("SetMidiProgramData(int, int, int, int, QString)"), SLOT("slot_handleSetMidiProgramData(int, int, int, int, QString)"))
  453. self.connect(self, SIGNAL("SetInputPeakValue(int, int, double)"), SLOT("slot_handleSetInputPeakValue(int, int, double)"))
  454. self.connect(self, SIGNAL("SetOutputPeakValue(int, int, double)"), SLOT("slot_handleSetOutputPeakValue(int, int, double)"))
  455. self.connect(self, SIGNAL("NoteOn(int, int, int, int)"), SLOT("slot_handleNoteOn(int, int, int, int)"))
  456. self.connect(self, SIGNAL("NoteOff(int, int, int)"), SLOT("slot_handleNoteOff(int, int, int)"))
  457. self.connect(self, SIGNAL("Exit()"), SLOT("slot_handleExit()"))
  458. self.TIMER_GUI_STUFF = self.startTimer(50) # Peaks
  459. self.TIMER_GUI_STUFF2 = self.startTimer(50 * 2) # LEDs and edit dialog
  460. def remove_all(self):
  461. for i in range(MAX_PLUGINS):
  462. if self.m_plugin_list[i]:
  463. self.slot_handleRemovePlugin(i)
  464. @pyqtSlot()
  465. def slot_doConnect(self):
  466. global lo_target, lo_targetName
  467. if lo_target and self.lo_server:
  468. urlText = self.lo_address
  469. else:
  470. urlText = "osc.tcp://127.0.0.1:19000/Carla"
  471. askValue = QInputDialog.getText(self, self.tr("Carla Control - Connect"), self.tr("Address"), text=urlText)
  472. if not askValue[1]:
  473. return
  474. self.slot_handleExit()
  475. self.lo_address = askValue[0]
  476. lo_target = Address(self.lo_address)
  477. lo_targetName = self.lo_address.rsplit("/", 1)[-1]
  478. print("Connecting to \"%s\" as '%s'..." % (self.lo_address, lo_targetName))
  479. try:
  480. self.lo_server = ControlServer(self)
  481. except: # ServerError, err:
  482. print("Connecting error!")
  483. #print str(err)
  484. QMessageBox.critical(self, self.tr("Error"), self.tr("Failed to connect, operation failed."))
  485. if self.lo_server:
  486. self.lo_server.start()
  487. self.act_file_refresh.setEnabled(True)
  488. lo_send(lo_target, "/register", self.lo_server.getFullURL())
  489. @pyqtSlot()
  490. def slot_doRefresh(self):
  491. global lo_target
  492. if lo_target and self.lo_server:
  493. self.remove_all()
  494. lo_send(lo_target, "/unregister")
  495. lo_send(lo_target, "/register", self.lo_server.getFullURL())
  496. @pyqtSlot()
  497. def slot_aboutCarlaControl(self):
  498. CarlaAboutW(self).exec_()
  499. @pyqtSlot(int, str)
  500. def slot_handleAddPluginStart(self, pluginId, pluginName):
  501. self.m_lastPluginName = pluginName
  502. @pyqtSlot(int)
  503. def slot_handleAddPluginEnd(self, pluginId):
  504. pwidget = PluginWidget(self, pluginId)
  505. self.w_plugins.layout().addWidget(pwidget)
  506. self.m_plugin_list[pluginId] = pwidget
  507. @pyqtSlot(int)
  508. def slot_handleRemovePlugin(self, pluginId):
  509. pwidget = self.m_plugin_list[pluginId]
  510. if pwidget:
  511. pwidget.edit_dialog.close()
  512. pwidget.close()
  513. pwidget.deleteLater()
  514. self.w_plugins.layout().removeWidget(pwidget)
  515. self.m_plugin_list[pluginId] = None
  516. @pyqtSlot(int, int, int, int, str, str, str, str, int)
  517. def slot_handleSetPluginData(self, pluginId, type_, category, hints, realName, label, maker, copyright, uniqueId):
  518. info = deepcopy(PluginInfo)
  519. info['type'] = type_
  520. info['category'] = category
  521. info['hints'] = hints
  522. info['name'] = self.m_lastPluginName
  523. info['label'] = label
  524. info['maker'] = maker
  525. info['copyright'] = copyright
  526. info['uniqueId'] = uniqueId
  527. Carla.host._set_pluginInfo(pluginId, info)
  528. Carla.host._set_pluginRealName(pluginId, realName)
  529. @pyqtSlot(int, int, int, int, int, int, int, int)
  530. def slot_handleSetPluginPorts(self, pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals):
  531. audioInfo = deepcopy(PortCountInfo)
  532. midiInfo = deepcopy(PortCountInfo)
  533. paramInfo = deepcopy(PortCountInfo)
  534. audioInfo['ins'] = audioIns
  535. audioInfo['outs'] = audioOuts
  536. audioInfo['total'] = audioIns + audioOuts
  537. midiInfo['ins'] = midiIns
  538. midiInfo['outs'] = midiOuts
  539. midiInfo['total'] = midiIns + midiOuts
  540. paramInfo['ins'] = cIns
  541. paramInfo['outs'] = cOuts
  542. paramInfo['total'] = cTotals
  543. Carla.host._set_audioCountInfo(pluginId, audioInfo)
  544. Carla.host._set_midiCountInfo(pluginId, midiInfo)
  545. Carla.host._set_parameterCountInfo(pluginId, paramInfo)
  546. @pyqtSlot(int, int, int, int, str, str, float)
  547. def slot_handleSetParameterData(self, pluginId, index, type_, hints, name, label, current):
  548. # remove hints not possible in bridge mode
  549. hints &= ~(PARAMETER_USES_SCALEPOINTS | PARAMETER_USES_CUSTOM_TEXT)
  550. data = deepcopy(ParameterData)
  551. data['type'] = type_
  552. data['index'] = index
  553. data['rindex'] = index
  554. data['hints'] = hints
  555. info = deepcopy(ParameterInfo)
  556. info['name'] = name
  557. info['label'] = label
  558. Carla.host._set_parameterDataS(pluginId, index, data)
  559. Carla.host._set_parameterInfoS(pluginId, index, info)
  560. Carla.host._set_parameterValueS(pluginId, index, current)
  561. @pyqtSlot(int, int, float, float, float, float, float, float)
  562. def slot_handleSetParameterRanges(self, pluginId, index, min_, max_, def_, step, stepSmall, stepLarge):
  563. ranges = deepcopy(ParameterRanges)
  564. ranges['min'] = min_
  565. ranges['max'] = max_
  566. ranges['def'] = def_
  567. ranges['step'] = step
  568. ranges['stepSmall'] = stepSmall
  569. ranges['stepLarge'] = stepLarge
  570. Carla.host._set_parameterRangeS(pluginId, index, ranges)
  571. @pyqtSlot(int, int, int)
  572. def slot_handleSetParameterMidiCC(self, pluginId, index, cc):
  573. Carla.host._set_parameterMidiCC(pluginId, index, cc)
  574. pwidget = self.m_plugin_list[pluginId]
  575. if pwidget:
  576. pwidget.edit_dialog.set_parameter_midi_cc(index, cc, True)
  577. @pyqtSlot(int, int, int)
  578. def slot_handleSetParameterMidiChannel(self, pluginId, index, channel):
  579. Carla.host._set_parameterMidiChannel(pluginId, index, channel)
  580. pwidget = self.m_plugin_list[pluginId]
  581. if pwidget:
  582. pwidget.edit_dialog.set_parameter_midi_channel(index, channel, True)
  583. @pyqtSlot(int, int, float)
  584. def slot_handleSetParameterValue(self, pluginId, parameterId, value):
  585. if parameterId >= 0:
  586. Carla.host._set_parameterValueS(pluginId, parameterId, value)
  587. pwidget = self.m_plugin_list[pluginId]
  588. if pwidget:
  589. if parameterId < PARAMETER_NULL:
  590. pwidget.m_parameterIconTimer = ICON_STATE_ON
  591. else:
  592. for param in pwidget.edit_dialog.m_parameterList:
  593. if param[1] == parameterId:
  594. if param[0] == PARAMETER_INPUT:
  595. pwidget.m_parameterIconTimer = ICON_STATE_ON
  596. break
  597. if parameterId == PARAMETER_ACTIVE:
  598. pwidget.set_active((value > 0.0), True, False)
  599. elif parameterId == PARAMETER_DRYWET:
  600. pwidget.set_drywet(value * 1000, True, False)
  601. elif parameterId == PARAMETER_VOLUME:
  602. pwidget.set_volume(value * 1000, True, False)
  603. elif parameterId == PARAMETER_BALANCE_LEFT:
  604. pwidget.set_balance_left(value * 1000, True, False)
  605. elif parameterId == PARAMETER_BALANCE_RIGHT:
  606. pwidget.set_balance_right(value * 1000, True, False)
  607. elif parameterId >= 0:
  608. pwidget.edit_dialog.set_parameter_to_update(parameterId)
  609. @pyqtSlot(int, int, float)
  610. def slot_handleSetDefaultValue(self, pluginId, parameterId, value):
  611. Carla.host._set_parameterDefaultValue(pluginId, parameterId, value)
  612. #pwidget = self.m_plugin_list[pluginId]
  613. #if pwidget:
  614. #pwidget.edit_dialog.set_parameter_default_value(parameterId, value)
  615. @pyqtSlot(int, int)
  616. def slot_handleSetProgram(self, pluginId, index):
  617. Carla.host._set_currentProgram(pluginId, index)
  618. pwidget = self.m_plugin_list[pluginId]
  619. if pwidget:
  620. pwidget.edit_dialog.set_program(index)
  621. pwidget.m_parameterIconTimer = ICON_STATE_ON
  622. @pyqtSlot(int, int)
  623. def slot_handleSetProgramCount(self, pluginId, count):
  624. Carla.host._set_programCount(pluginId, count)
  625. @pyqtSlot(int, int, str)
  626. def slot_handleSetProgramName(self, pluginId, index, name):
  627. Carla.host._set_programNameS(pluginId, index, name)
  628. @pyqtSlot(int, int)
  629. def slot_handleSetMidiProgram(self, pluginId, index):
  630. Carla.host._set_currentMidiProgram(pluginId, index)
  631. pwidget = self.m_plugin_list[pluginId]
  632. if pwidget:
  633. pwidget.edit_dialog.set_midi_program(index)
  634. pwidget.m_parameterIconTimer = ICON_STATE_ON
  635. @pyqtSlot(int, int)
  636. def slot_handleSetMidiProgramCount(self, pluginId, count):
  637. Carla.host._set_midiProgramCount(pluginId, count)
  638. @pyqtSlot(int, int, int, int, str)
  639. def slot_handleSetMidiProgramData(self, pluginId, index, bank, program, name):
  640. data = deepcopy(MidiProgramData)
  641. data['bank'] = bank
  642. data['program'] = program
  643. data['label'] = name
  644. Carla.host._set_midiProgramDataS(pluginId, index, data)
  645. @pyqtSlot(int, int, float)
  646. def slot_handleSetInputPeakValue(self, pluginId, portId, value):
  647. Carla.host._set_inPeak(pluginId, portId-1, value)
  648. @pyqtSlot(int, int, float)
  649. def slot_handleSetOutputPeakValue(self, pluginId, portId, value):
  650. Carla.host._set_outPeak(pluginId, portId-1, value)
  651. @pyqtSlot(int, int, int, int)
  652. def slot_handleNoteOn(self, pluginId, channel, note, velo):
  653. pwidget = self.m_plugin_list[pluginId]
  654. if pwidget:
  655. pwidget.edit_dialog.keyboard.sendNoteOn(note, False)
  656. @pyqtSlot(int, int, int)
  657. def slot_handleNoteOff(self, pluginId, channel, note):
  658. pwidget = self.m_plugin_list[pluginId]
  659. if pwidget:
  660. pwidget.edit_dialog.keyboard.sendNoteOff(note, False)
  661. @pyqtSlot()
  662. def slot_handleExit(self):
  663. self.remove_all()
  664. if self.lo_server:
  665. self.lo_server.stop()
  666. self.lo_server = None
  667. self.act_file_refresh.setEnabled(False)
  668. global lo_target, lo_targetName
  669. lo_target = None
  670. lo_targetName = ""
  671. self.lo_address = ""
  672. def saveSettings(self):
  673. self.settings.setValue("Geometry", self.saveGeometry())
  674. #self.settings.setValue("ShowToolbar", self.toolBar.isVisible())
  675. def loadSettings(self):
  676. self.restoreGeometry(self.settings.value("Geometry", ""))
  677. #show_toolbar = self.settings.value("ShowToolbar", True, type=bool)
  678. #self.act_settings_show_toolbar.setChecked(show_toolbar)
  679. #self.toolBar.setVisible(show_toolbar)
  680. def timerEvent(self, event):
  681. if event.timerId() == self.TIMER_GUI_STUFF:
  682. for pwidget in self.m_plugin_list:
  683. if pwidget: pwidget.check_gui_stuff()
  684. elif event.timerId() == self.TIMER_GUI_STUFF2:
  685. for pwidget in self.m_plugin_list:
  686. if pwidget: pwidget.check_gui_stuff2()
  687. QMainWindow.timerEvent(self, event)
  688. def closeEvent(self, event):
  689. self.saveSettings()
  690. global lo_target
  691. if lo_target and self.lo_server:
  692. lo_send(lo_target, "/unregister")
  693. QMainWindow.closeEvent(self, event)
  694. #--------------- main ------------------
  695. if __name__ == '__main__':
  696. # App initialization
  697. app = QApplication(sys.argv)
  698. app.setApplicationName("Carla-Control")
  699. app.setApplicationVersion(VERSION)
  700. app.setOrganizationName("Cadence")
  701. app.setWindowIcon(QIcon(":/scalable/carla-control.svg"))
  702. Carla.host = Host()
  703. # Create GUI
  704. Carla.gui = CarlaControlW()
  705. # Set-up custom signal handling
  706. setUpSignals(Carla.gui)
  707. # Show GUI
  708. Carla.gui.show()
  709. # App-Loop
  710. sys.exit(app.exec_())