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.

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