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.

1074 lines
38KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Carla OSC controller
  4. # Copyright (C) 2011-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 (Global)
  19. from PyQt4.QtCore import QLibrary
  20. from PyQt4.QtGui import QApplication, QInputDialog, QMainWindow
  21. from liblo import make_method, Address, ServerError, ServerThread
  22. from liblo import send as lo_send
  23. from liblo import TCP as LO_TCP
  24. # ------------------------------------------------------------------------------------------------------------
  25. # Imports (Custom)
  26. import ui_carla_control
  27. from carla_shared import *
  28. global lo_target, lo_targetName
  29. lo_target = None
  30. lo_targetName = ""
  31. Carla.isControl = True
  32. Carla.isLocal = False
  33. # ------------------------------------------------------------------------------------------------------------
  34. # Python Object dicts compatible to carla-backend struct ctypes
  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. MidiProgramData = {
  52. 'bank': 0,
  53. 'program': 0,
  54. 'name': None
  55. }
  56. CustomData = {
  57. 'type': CUSTOM_DATA_INVALID,
  58. 'key': None,
  59. 'value': None
  60. }
  61. # ------------------------------------------------------------------------------------------------------------
  62. CarlaPluginInfo = {
  63. 'type': PLUGIN_NONE,
  64. 'category': PLUGIN_CATEGORY_NONE,
  65. 'hints': 0x0,
  66. 'optionsAvailable': 0x0,
  67. 'optionsEnabled': 0x0,
  68. 'binary': None,
  69. 'name': None,
  70. 'label': None,
  71. 'maker': None,
  72. 'copyright': None,
  73. 'uniqueId': 0,
  74. 'latency': 0
  75. }
  76. CarlaNativePluginInfo = {
  77. 'category': PLUGIN_CATEGORY_NONE,
  78. 'hints': 0x0,
  79. 'audioIns': 0,
  80. 'audioOuts': 0,
  81. 'midiIns': 0,
  82. 'midiOuts': 0,
  83. 'parameterIns': 0,
  84. 'parameterOuts': 0,
  85. 'name': None,
  86. 'label': None,
  87. 'maker': None,
  88. 'copyright': None
  89. }
  90. CarlaPortCountInfo = {
  91. 'ins': 0,
  92. 'outs': 0,
  93. 'total': 0
  94. }
  95. CarlaParameterInfo = {
  96. 'name': None,
  97. 'symbol': None,
  98. 'unit': None,
  99. 'scalePointCount': 0,
  100. }
  101. CarlaScalePointInfo = {
  102. 'value': 0.0,
  103. 'label': None
  104. }
  105. CarlaTransportInfo = {
  106. 'playing': False,
  107. 'frame': 0,
  108. 'bar': 0,
  109. 'beat': 0,
  110. 'tick': 0,
  111. 'bpm': 0.0
  112. }
  113. # ------------------------------------------------------------------------------------------------------------
  114. # Helper class
  115. class ControlPluginInfo(object):
  116. __slots__ = [
  117. 'pluginInfo',
  118. 'pluginRealName',
  119. 'audioCountInfo',
  120. 'midiCountInfo',
  121. 'parameterCountInfo',
  122. 'parameterInfoS',
  123. 'parameterDataS',
  124. 'parameterRangeS',
  125. 'parameterValueS',
  126. 'programCount',
  127. 'programCurrent',
  128. 'programNameS',
  129. 'midiProgramCount',
  130. 'midiProgramCurrent',
  131. 'midiProgramDataS',
  132. 'inPeak',
  133. 'outPeak'
  134. ]
  135. # ------------------------------------------------------------------------------------------------------------
  136. # Python Object class compatible to 'Host' on the Carla Backend code
  137. class Host(object):
  138. def __init__(self):
  139. object.__init__(self)
  140. self.fPluginsInfo = []
  141. def _add(self, pluginId):
  142. if len(self.fPluginsInfo) != pluginId:
  143. return
  144. info = deepcopy(ControlPluginInfo)
  145. info.pluginInfo = CarlaPluginInfo
  146. info.pluginRealName = None
  147. info.audioCountInfo = CarlaPortCountInfo
  148. info.midiCountInfo = CarlaPortCountInfo
  149. info.parameterCountInfo = CarlaPortCountInfo
  150. info.parameterInfoS = []
  151. info.parameterDataS = []
  152. info.parameterRangeS = []
  153. info.parameterValueS = []
  154. info.programCount = 0
  155. info.programCurrent = -1
  156. info.programNameS = []
  157. info.midiProgramCount = 0
  158. info.midiProgramCurrent = -1
  159. info.midiProgramDataS = []
  160. info.peaks = [0.0, 0.0, 0.0, 0.0]
  161. self.fPluginsInfo.append(info)
  162. def _set_pluginInfo(self, index, info):
  163. self.fPluginsInfo[index].pluginInfo = info
  164. def _set_pluginRealName(self, index, realName):
  165. self.fPluginsInfo[index].pluginRealName = realName
  166. def _set_audioCountInfo(self, index, info):
  167. self.fPluginsInfo[index].audioCountInfo = info
  168. def _set_midiCountInfo(self, index, info):
  169. self.fPluginsInfo[index].midiCountInfo = info
  170. def _set_parameterCountInfo(self, index, info):
  171. self.fPluginsInfo[index].parameterCountInfo = info
  172. # clear
  173. self.fPluginsInfo[index].parameterInfoS = []
  174. self.fPluginsInfo[index].parameterDataS = []
  175. self.fPluginsInfo[index].parameterRangeS = []
  176. self.fPluginsInfo[index].parameterValueS = []
  177. # add placeholders
  178. for x in range(info['total']):
  179. self.fPluginsInfo[index].parameterInfoS.append(CarlaParameterInfo)
  180. self.fPluginsInfo[index].parameterDataS.append(ParameterData)
  181. self.fPluginsInfo[index].parameterRangeS.append(ParameterRanges)
  182. self.fPluginsInfo[index].parameterValueS.append(0.0)
  183. def _set_programCount(self, index, count):
  184. self.fPluginsInfo[index].programCount = count
  185. # clear
  186. self.fPluginsInfo[index].programNameS = []
  187. # add placeholders
  188. for x in range(count):
  189. self.fPluginsInfo[index].programNameS.append(None)
  190. def _set_midiProgramCount(self, index, count):
  191. self.fPluginsInfo[index].midiProgramCount = count
  192. # clear
  193. self.fPluginsInfo[index].midiProgramDataS = []
  194. # add placeholders
  195. for x in range(count):
  196. self.fPluginsInfo[index].midiProgramDataS.append(MidiProgramData)
  197. def _set_parameterInfoS(self, index, paramIndex, data):
  198. if paramIndex < self.fPluginsInfo[index].parameterCountInfo['total']:
  199. self.fPluginsInfo[index].parameterInfoS[paramIndex] = data
  200. def _set_parameterDataS(self, index, paramIndex, data):
  201. if paramIndex < self.fPluginsInfo[index].parameterCountInfo['total']:
  202. self.fPluginsInfo[index].parameterDataS[paramIndex] = data
  203. def _set_parameterRangeS(self, index, paramIndex, data):
  204. if paramIndex < self.fPluginsInfo[index].parameterCountInfo['total']:
  205. self.fPluginsInfo[index].parameterRangeS[paramIndex] = data
  206. def _set_parameterValueS(self, index, paramIndex, value):
  207. if paramIndex < self.fPluginsInfo[index].parameterCountInfo['total']:
  208. self.fPluginsInfo[index].parameterValueS[paramIndex] = value
  209. def _set_parameterDefaultValue(self, index, paramIndex, value):
  210. if paramIndex < self.fPluginsInfo[index].parameterCountInfo['total']:
  211. self.fPluginsInfo[index].parameterRangeS[paramIndex]['def'] = value
  212. def _set_parameterMidiCC(self, index, paramIndex, cc):
  213. if paramIndex < self.fPluginsInfo[index].parameterCountInfo['total']:
  214. self.fPluginsInfo[index].parameterDataS[paramIndex]['midiCC'] = cc
  215. def _set_parameterMidiChannel(self, index, paramIndex, channel):
  216. if paramIndex < self.fPluginsInfo[index].parameterCountInfo['total']:
  217. self.fPluginsInfo[index].parameterDataS[paramIndex]['midiChannel'] = channel
  218. def _set_currentProgram(self, index, pIndex):
  219. self.fPluginsInfo[index].programCurrent = pIndex
  220. def _set_currentMidiProgram(self, index, mpIndex):
  221. self.fPluginsInfo[index].midiProgramCurrent = mpIndex
  222. def _set_programNameS(self, index, pIndex, data):
  223. if pIndex < self.fPluginsInfo[index].programCount:
  224. self.fPluginsInfo[index].programNameS[pIndex] = data
  225. def _set_midiProgramDataS(self, index, mpIndex, data):
  226. if mpIndex < self.fPluginsInfo[index].midiProgramCount:
  227. self.fPluginsInfo[index].midiProgramDataS[mpIndex] = data
  228. def _set_peaks(self, index, in1, in2, out1, out2):
  229. self.fPluginsInfo[index].peaks = [in1, in2, out1, out2]
  230. # get_extended_license_text
  231. # get_supported_file_types
  232. # get_engine_driver_count
  233. # get_engine_driver_name
  234. # get_engine_driver_device_names
  235. # get_internal_plugin_count
  236. # get_internal_plugin_info
  237. # engine_init
  238. # engine_close
  239. # engine_idle
  240. # is_engine_running
  241. # set_engine_about_to_close
  242. # set_engine_callback
  243. # set_engine_option
  244. # load_filename
  245. # load_project
  246. # save_project
  247. # patchbay_connect
  248. # patchbay_disconnect
  249. # patchbay_refresh
  250. # transport_play
  251. # transport_pause
  252. # transport_relocate
  253. # get_current_transport_frame
  254. # get_transport_info
  255. # add_plugin
  256. # remove_plugin
  257. # remove_all_plugins
  258. # rename_plugin
  259. # clone_plugin
  260. # replace_plugin
  261. # switch_plugins
  262. # load_plugin_state
  263. # save_plugin_state
  264. def get_plugin_info(self, pluginId):
  265. return self.fPluginsInfo[pluginId].pluginInfo
  266. def get_audio_port_count_info(self, pluginId):
  267. return self.fPluginsInfo[pluginId].audioCountInfo
  268. def get_midi_port_count_info(self, pluginId):
  269. return self.fPluginsInfo[pluginId].midiCountInfo
  270. def get_parameter_count_info(self, pluginId):
  271. return self.fPluginsInfo[pluginId].parameterCountInfo
  272. def get_parameter_info(self, pluginId, parameterId):
  273. return self.fPluginsInfo[pluginId].parameterInfoS[parameterId]
  274. def get_parameter_scalepoint_info(self, pluginId, parameterId, scalepoint_id):
  275. return CarlaScalePointInfo
  276. def get_parameter_data(self, pluginId, parameterId):
  277. return self.fPluginsInfo[pluginId].parameterDataS[parameterId]
  278. def get_parameter_ranges(self, pluginId, parameterId):
  279. return self.fPluginsInfo[pluginId].parameterRangeS[parameterId]
  280. def get_midi_program_data(self, pluginId, midiProgramId):
  281. return self.fPluginsInfo[pluginId].midiProgramDataS[midiProgramId]
  282. def get_custom_data(self, pluginId, custom_data_id):
  283. return CustomData
  284. def get_chunk_data(self, pluginId):
  285. return None
  286. def get_parameter_count(self, pluginId):
  287. return self.fPluginsInfo[pluginId].parameterCountInfo['total']
  288. def get_program_count(self, pluginId):
  289. return self.fPluginsInfo[pluginId].programCount
  290. def get_midi_program_count(self, pluginId):
  291. return self.fPluginsInfo[pluginId].midiProgramCount
  292. def get_custom_data_count(self, pluginId):
  293. return 0
  294. def get_parameter_text(self, pluginId, parameterId):
  295. return None
  296. def get_program_name(self, pluginId, programId):
  297. return self.fPluginsInfo[pluginId].programNameS[programId]
  298. def get_midi_program_name(self, pluginId, midiProgramId):
  299. return self.fPluginsInfo[pluginId].midiProgramDataS[midiProgramId]['label']
  300. def get_real_plugin_name(self, pluginId):
  301. return self.fPluginsInfo[pluginId].pluginRealName
  302. def get_current_program_index(self, pluginId):
  303. return self.fPluginsInfo[pluginId].programCurrent
  304. def get_current_midi_program_index(self, pluginId):
  305. return self.fPluginsInfo[pluginId].midiProgramCurrent
  306. def get_default_parameter_value(self, pluginId, parameterId):
  307. return self.fPluginsInfo[pluginId].parameterRangeS[parameterId]['def']
  308. def get_current_parameter_value(self, pluginId, parameterId):
  309. return self.fPluginsInfo[pluginId].parameterValueS[parameterId]
  310. def get_input_peak_value(self, pluginId, portId):
  311. return self.fPluginsInfo[pluginId].peaks[portId-1]
  312. def get_output_peak_value(self, pluginId, portId):
  313. return self.fPluginsInfo[pluginId].peaks[2+portId-1]
  314. def set_option(self, pluginId, option, yesNo):
  315. global to_target, lo_targetName
  316. lo_path = "/%s/%i/set_option" % (lo_targetName, pluginId)
  317. lo_send(lo_target, lo_path, option, yesNo)
  318. def set_active(self, pluginId, onoff):
  319. global to_target, lo_targetName
  320. lo_path = "/%s/%i/set_active" % (lo_targetName, pluginId)
  321. lo_send(lo_target, lo_path, 1 if onoff else 0)
  322. def set_drywet(self, pluginId, value):
  323. global to_target, lo_targetName
  324. lo_path = "/%s/%i/set_drywet" % (lo_targetName, pluginId)
  325. lo_send(lo_target, lo_path, value)
  326. def set_volume(self, pluginId, value):
  327. global to_target, lo_targetName
  328. lo_path = "/%s/%i/set_volume" % (lo_targetName, pluginId)
  329. lo_send(lo_target, lo_path, value)
  330. def set_balance_left(self, pluginId, value):
  331. global to_target, lo_targetName
  332. lo_path = "/%s/%i/set_balance_left" % (lo_targetName, pluginId)
  333. lo_send(lo_target, lo_path, value)
  334. def set_balance_right(self, pluginId, value):
  335. global to_target, lo_targetName
  336. lo_path = "/%s/%i/set_balance_right" % (lo_targetName, pluginId)
  337. lo_send(lo_target, lo_path, value)
  338. def set_panning(self, pluginId, value):
  339. global to_target, lo_targetName
  340. lo_path = "/%s/%i/set_panning" % (lo_targetName, pluginId)
  341. lo_send(lo_target, lo_path, value)
  342. def set_ctrl_channel(self, pluginId, channel):
  343. global to_target, lo_targetName
  344. lo_path = "/%s/%i/set_ctrl_channel" % (lo_targetName, pluginId)
  345. lo_send(lo_target, lo_path, channel)
  346. def set_parameter_value(self, pluginId, parameterId, value):
  347. global to_target, lo_targetName
  348. lo_path = "/%s/%i/set_parameter_value" % (lo_targetName, pluginId)
  349. lo_send(lo_target, lo_path, parameterId, value)
  350. def set_parameter_midi_cc(self, pluginId, parameterId, midi_cc):
  351. global to_target, lo_targetName
  352. lo_path = "/%s/%i/set_parameter_midi_cc" % (lo_targetName, pluginId)
  353. lo_send(lo_target, lo_path, parameterId, midi_cc)
  354. def set_parameter_midi_channel(self, pluginId, parameterId, channel):
  355. global to_target, lo_targetName
  356. lo_path = "/%s/%i/set_parameter_midi_channel" % (lo_targetName, pluginId)
  357. lo_send(lo_target, lo_path, parameterId, channel)
  358. def set_program(self, pluginId, programId):
  359. global to_target, lo_targetName
  360. lo_path = "/%s/%i/set_program" % (lo_targetName, pluginId)
  361. lo_send(lo_target, lo_path, programId)
  362. def set_midi_program(self, pluginId, midiProgramId):
  363. global to_target, lo_targetName
  364. lo_path = "/%s/%i/set_midi_program" % (lo_targetName, pluginId)
  365. lo_send(lo_target, lo_path, midiProgramId)
  366. # set_custom_data
  367. # set_chunk_data
  368. # prepare_for_save
  369. def send_midi_note(self, pluginId, channel, note, velocity):
  370. global to_target, lo_targetName
  371. if velocity:
  372. lo_path = "/%s/%i/note_on" % (lo_targetName, pluginId)
  373. lo_send(lo_target, lo_path, channel, note, velocity)
  374. else:
  375. lo_path = "/%s/%i/note_off" % (lo_targetName, pluginId)
  376. lo_send(lo_target, lo_path, channel, note)
  377. # show_gui
  378. # get_buffer_size
  379. # get_sample_rate
  380. # get_last_error
  381. # get_host_osc_url
  382. # nsm_announce
  383. # nsm_reply_open
  384. # nsm_reply_save
  385. # ------------------------------------------------------------------------------------------------------------
  386. # OSC Control server
  387. class ControlServer(ServerThread):
  388. def __init__(self, parent):
  389. ServerThread.__init__(self, 8087, LO_TCP)
  390. self.fParent = parent
  391. def getFullURL(self):
  392. return "%scarla-control" % self.get_url()
  393. @make_method('/carla-control/add_plugin_start', 'is')
  394. def add_plugin_start_callback(self, path, args):
  395. pluginId, pluginName = args
  396. self.fParent.emit(SIGNAL("AddPluginStart(int, QString)"), pluginId, pluginName)
  397. @make_method('/carla-control/add_plugin_end', 'i')
  398. def add_plugin_end_callback(self, path, args):
  399. pluginId, = args
  400. self.fParent.emit(SIGNAL("AddPluginEnd(int)"), pluginId)
  401. @make_method('/carla-control/remove_plugin', 'i')
  402. def remove_plugin_callback(self, path, args):
  403. pluginId, = args
  404. self.fParent.emit(SIGNAL("RemovePlugin(int)"), pluginId)
  405. @make_method('/carla-control/set_plugin_data', 'iiiissssh')
  406. def set_plugin_data_callback(self, path, args):
  407. pluginId, ptype, category, hints, realName, label, maker, copyright_, uniqueId = args
  408. self.fParent.emit(SIGNAL("SetPluginData(int, int, int, int, QString, QString, QString, QString, int)"), pluginId, ptype, category, hints, realName, label, maker, copyright_, uniqueId)
  409. @make_method('/carla-control/set_plugin_ports', 'iiiiiiii')
  410. def set_plugin_ports_callback(self, path, args):
  411. pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals = args
  412. self.fParent.emit(SIGNAL("SetPluginPorts(int, int, int, int, int, int, int, int)"), pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals)
  413. @make_method('/carla-control/set_parameter_data', 'iiiissf')
  414. def set_parameter_data_callback(self, path, args):
  415. pluginId, index, type_, hints, name, label, current = args
  416. self.fParent.emit(SIGNAL("SetParameterData(int, int, int, int, QString, QString, double)"), pluginId, index, type_, hints, name, label, current)
  417. @make_method('/carla-control/set_parameter_ranges', 'iiffffff')
  418. def set_parameter_ranges_callback(self, path, args):
  419. pluginId, index, min_, max_, def_, step, stepSmall, stepLarge = args
  420. self.fParent.emit(SIGNAL("SetParameterRanges(int, int, double, double, double, double, double, double)"), pluginId, index, min_, max_, def_, step, stepSmall, stepLarge)
  421. @make_method('/carla-control/set_parameter_midi_cc', 'iii')
  422. def set_parameter_midi_cc_callback(self, path, args):
  423. pluginId, index, cc = args
  424. self.fParent.emit(SIGNAL("SetParameterMidiCC(int, int, int)"), pluginId, index, cc)
  425. @make_method('/carla-control/set_parameter_midi_channel', 'iii')
  426. def set_parameter_midi_channel_callback(self, path, args):
  427. pluginId, index, channel = args
  428. self.fParent.emit(SIGNAL("SetParameterMidiChannel(int, int, int)"), pluginId, index, channel)
  429. @make_method('/carla-control/set_parameter_value', 'iif')
  430. def set_parameter_value_callback(self, path, args):
  431. pluginId, index, value = args
  432. self.fParent.emit(SIGNAL("SetParameterValue(int, int, double)"), pluginId, index, value)
  433. @make_method('/carla-control/set_default_value', 'iif')
  434. def set_default_value_callback(self, path, args):
  435. pluginId, index, value = args
  436. self.fParent.emit(SIGNAL("SetDefaultValue(int, int, double)"), pluginId, index, value)
  437. @make_method('/carla-control/set_program', 'ii')
  438. def set_program_callback(self, path, args):
  439. pluginId, index = args
  440. self.fParent.emit(SIGNAL("SetProgram(int, int)"), pluginId, index)
  441. @make_method('/carla-control/set_program_count', 'ii')
  442. def set_program_count_callback(self, path, args):
  443. pluginId, count = args
  444. self.fParent.emit(SIGNAL("SetProgramCount(int, int)"), pluginId, count)
  445. @make_method('/carla-control/set_program_name', 'iis')
  446. def set_program_name_callback(self, path, args):
  447. pluginId, index, name = args
  448. self.fParent.emit(SIGNAL("SetProgramName(int, int, QString)"), pluginId, index, name)
  449. @make_method('/carla-control/set_midi_program', 'ii')
  450. def set_midi_program_callback(self, path, args):
  451. pluginId, index = args
  452. self.fParent.emit(SIGNAL("SetMidiProgram(int, int)"), pluginId, index)
  453. @make_method('/carla-control/set_midi_program_count', 'ii')
  454. def set_midi_program_count_callback(self, path, args):
  455. pluginId, count = args
  456. self.fParent.emit(SIGNAL("SetMidiProgramCount(int, int)"), pluginId, count)
  457. @make_method('/carla-control/set_midi_program_data', 'iiiis')
  458. def set_midi_program_data_callback(self, path, args):
  459. pluginId, index, bank, program, name = args
  460. self.fParent.emit(SIGNAL("SetMidiProgramData(int, int, int, int, QString)"), pluginId, index, bank, program, name)
  461. @make_method('/carla-control/note_on', 'iiii')
  462. def note_on_callback(self, path, args):
  463. pluginId, channel, note, velo = args
  464. self.fParent.emit(SIGNAL("NoteOn(int, int, int, int)"), pluginId, channel, note, velo)
  465. @make_method('/carla-control/note_off', 'iii')
  466. def note_off_callback(self, path, args):
  467. pluginId, channel, note = args
  468. self.fParent.emit(SIGNAL("NoteOff(int, int, int)"), pluginId, channel, note)
  469. @make_method('/carla-control/set_peaks', 'iffff')
  470. def set_output_peak_value_callback(self, path, args):
  471. pluginId, in1, in2, out1, out2 = args
  472. self.fParent.emit(SIGNAL("SetPeaks(int, double, double, double, double)"), pluginId, in1, in2, out1, out2)
  473. @make_method('/carla-control/exit', '')
  474. def exit_callback(self, path, args):
  475. self.fParent.emit(SIGNAL("Exit()"))
  476. @make_method(None, None)
  477. def fallback(self, path, args):
  478. print("ControlServer::fallback(\"%s\") - unknown message, args =" % path, args)
  479. # ------------------------------------------------------------------------------------------------------------
  480. # Main Window
  481. class CarlaControlW(QMainWindow):
  482. def __init__(self, parent=None):
  483. QMainWindow.__init__(self, parent)
  484. self.ui = ui_carla_control.Ui_CarlaControlW()
  485. self.ui.setupUi(self)
  486. # -------------------------------------------------------------
  487. # Load Settings
  488. self.loadSettings()
  489. self.setStyleSheet("""
  490. QWidget#centralwidget {
  491. background-color: qlineargradient(spread:pad,
  492. x1:0.0, y1:0.0,
  493. x2:0.2, y2:1.0,
  494. stop:0 rgb( 7, 7, 7),
  495. stop:1 rgb(28, 28, 28)
  496. );
  497. }
  498. """)
  499. # -------------------------------------------------------------
  500. # Internal stuff
  501. self.lo_address = ""
  502. self.lo_server = None
  503. self.fLastPluginName = ""
  504. self.fPluginCount = 0
  505. self.fPluginList = []
  506. self.fIdleTimerFast = 0
  507. self.fIdleTimerSlow = 0
  508. # -------------------------------------------------------------
  509. # Set-up GUI stuff
  510. self.ui.act_file_refresh.setEnabled(False)
  511. self.resize(self.width(), 0)
  512. # -------------------------------------------------------------
  513. # Connect actions to functions
  514. self.connect(self.ui.act_file_connect, SIGNAL("triggered()"), SLOT("slot_fileConnect()"))
  515. self.connect(self.ui.act_file_refresh, SIGNAL("triggered()"), SLOT("slot_fileRefresh()"))
  516. self.connect(self.ui.act_help_about, SIGNAL("triggered()"), SLOT("slot_aboutCarlaControl()"))
  517. self.connect(self.ui.act_help_about_qt, SIGNAL("triggered()"), app, SLOT("aboutQt()"))
  518. self.connect(self, SIGNAL("AddPluginStart(int, QString)"), SLOT("slot_handleAddPluginStart(int, QString)"))
  519. self.connect(self, SIGNAL("AddPluginEnd(int)"), SLOT("slot_handleAddPluginEnd(int)"))
  520. self.connect(self, SIGNAL("RemovePlugin(int)"), SLOT("slot_handleRemovePlugin(int)"))
  521. 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)"))
  522. self.connect(self, SIGNAL("SetPluginPorts(int, int, int, int, int, int, int, int)"), SLOT("slot_handleSetPluginPorts(int, int, int, int, int, int, int, int)"))
  523. self.connect(self, SIGNAL("SetParameterData(int, int, int, int, QString, QString, double)"), SLOT("slot_handleSetParameterData(int, int, int, int, QString, QString, double)"))
  524. self.connect(self, SIGNAL("SetParameterRanges(int, int, double, double, double, double, double, double)"), SLOT("slot_handleSetParameterRanges(int, int, double, double, double, double, double, double)"))
  525. self.connect(self, SIGNAL("SetParameterMidiCC(int, int, int)"), SLOT("slot_handleSetParameterMidiCC(int, int, int)"))
  526. self.connect(self, SIGNAL("SetParameterMidiChannel(int, int, int)"), SLOT("slot_handleSetParameterMidiChannel(int, int, int)"))
  527. self.connect(self, SIGNAL("SetParameterValue(int, int, double)"), SLOT("slot_handleSetParameterValue(int, int, double)"))
  528. self.connect(self, SIGNAL("SetDefaultValue(int, int, double)"), SLOT("slot_handleSetDefaultValue(int, int, double)"))
  529. self.connect(self, SIGNAL("SetProgram(int, int)"), SLOT("slot_handleSetProgram(int, int)"))
  530. self.connect(self, SIGNAL("SetProgramCount(int, int)"), SLOT("slot_handleSetProgramCount(int, int)"))
  531. self.connect(self, SIGNAL("SetProgramName(int, int, QString)"), SLOT("slot_handleSetProgramName(int, int, QString)"))
  532. self.connect(self, SIGNAL("SetMidiProgram(int, int)"), SLOT("slot_handleSetMidiProgram(int, int)"))
  533. self.connect(self, SIGNAL("SetMidiProgramCount(int, int)"), SLOT("slot_handleSetMidiProgramCount(int, int)"))
  534. self.connect(self, SIGNAL("SetMidiProgramData(int, int, int, int, QString)"), SLOT("slot_handleSetMidiProgramData(int, int, int, int, QString)"))
  535. self.connect(self, SIGNAL("NoteOn(int, int, int, int)"), SLOT("slot_handleNoteOn(int, int, int, int)"))
  536. self.connect(self, SIGNAL("NoteOff(int, int, int)"), SLOT("slot_handleNoteOff(int, int, int)"))
  537. self.connect(self, SIGNAL("SetPeaks(int, double, double, double, double)"), SLOT("slot_handleSetPeaks(int, double, double, double, double)"))
  538. self.connect(self, SIGNAL("Exit()"), SLOT("slot_handleExit()"))
  539. # Peaks
  540. self.fIdleTimerFast = self.startTimer(60)
  541. # LEDs and edit dialog parameters
  542. self.fIdleTimerSlow = self.startTimer(60*2)
  543. def removeAll(self):
  544. self.killTimer(self.fIdleTimerFast)
  545. self.killTimer(self.fIdleTimerSlow)
  546. self.fIdleTimerFast = 0
  547. self.fIdleTimerSlow = 0
  548. for i in range(self.fPluginCount):
  549. pwidget = self.fPluginList[i]
  550. if pwidget is None:
  551. break
  552. pwidget.ui.edit_dialog.close()
  553. pwidget.close()
  554. pwidget.deleteLater()
  555. del pwidget
  556. self.fPluginCount = 0
  557. self.fPluginList = []
  558. Carla.host.fPluginsInfo = []
  559. self.fIdleTimerFast = self.startTimer(60)
  560. self.fIdleTimerSlow = self.startTimer(60*2)
  561. @pyqtSlot()
  562. def slot_fileConnect(self):
  563. global lo_target, lo_targetName
  564. if lo_target and self.lo_server:
  565. urlText = self.lo_address
  566. else:
  567. urlText = "osc.tcp://127.0.0.1:19000/Carla"
  568. askValue = QInputDialog.getText(self, self.tr("Carla Control - Connect"), self.tr("Address"), text=urlText)
  569. if not askValue[1]:
  570. return
  571. self.slot_handleExit()
  572. self.lo_address = askValue[0]
  573. lo_target = Address(self.lo_address)
  574. lo_targetName = self.lo_address.rsplit("/", 1)[-1]
  575. print("Connecting to \"%s\" as '%s'..." % (self.lo_address, lo_targetName))
  576. try:
  577. self.lo_server = ControlServer(self)
  578. except: # ServerError, err:
  579. print("Connecting error!")
  580. #print str(err)
  581. QMessageBox.critical(self, self.tr("Error"), self.tr("Failed to connect, operation failed."))
  582. if self.lo_server:
  583. self.lo_server.start()
  584. self.ui.act_file_refresh.setEnabled(True)
  585. lo_send(lo_target, "/register", self.lo_server.getFullURL())
  586. @pyqtSlot()
  587. def slot_fileRefresh(self):
  588. global lo_target
  589. if lo_target and self.lo_server:
  590. self.removeAll()
  591. lo_send(lo_target, "/unregister")
  592. lo_send(lo_target, "/register", self.lo_server.getFullURL())
  593. @pyqtSlot()
  594. def slot_aboutCarlaControl(self):
  595. CarlaAboutW(self).exec_()
  596. @pyqtSlot(int, str)
  597. def slot_handleAddPluginStart(self, pluginId, pluginName):
  598. self.fLastPluginName = pluginName
  599. Carla.host._add(pluginId)
  600. @pyqtSlot(int)
  601. def slot_handleAddPluginEnd(self, pluginId):
  602. pwidget = PluginWidget(self, pluginId)
  603. pwidget.setRefreshRate(60)
  604. self.ui.w_plugins.layout().addWidget(pwidget)
  605. self.fPluginCount += 1
  606. self.fPluginList.append(pwidget)
  607. @pyqtSlot(int)
  608. def slot_handleRemovePlugin(self, pluginId):
  609. if pluginId >= self.fPluginCount:
  610. print("handleRemovePlugin(%i) - invalid plugin id" % pluginId)
  611. return
  612. pwidget = self.fPluginList[pluginId]
  613. if pwidget is None:
  614. print("handleRemovePlugin(%i) - invalid plugin" % pluginId)
  615. return
  616. self.fPluginList.pop(pluginId)
  617. self.fPluginCount -= 1
  618. self.ui.w_plugins.layout().removeWidget(pwidget)
  619. pwidget.ui.edit_dialog.close()
  620. pwidget.close()
  621. pwidget.deleteLater()
  622. del pwidget
  623. # push all plugins 1 slot back
  624. for i in range(pluginId, self.fPluginCount):
  625. self.fPluginList[i].setId(i)
  626. Carla.host.fPluginsInfo.pop(pluginId)
  627. @pyqtSlot(int, int, int, int, str, str, str, str, int)
  628. def slot_handleSetPluginData(self, pluginId, type_, category, hints, realName, label, maker, copyright, uniqueId):
  629. info = deepcopy(CarlaPluginInfo)
  630. info['type'] = type_
  631. info['category'] = category
  632. info['hints'] = hints
  633. info['name'] = self.fLastPluginName
  634. info['label'] = label
  635. info['maker'] = maker
  636. info['copyright'] = copyright
  637. info['uniqueId'] = uniqueId
  638. Carla.host._set_pluginInfo(pluginId, info)
  639. Carla.host._set_pluginRealName(pluginId, realName)
  640. @pyqtSlot(int, int, int, int, int, int, int, int)
  641. def slot_handleSetPluginPorts(self, pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals):
  642. audioInfo = deepcopy(CarlaPortCountInfo)
  643. midiInfo = deepcopy(CarlaPortCountInfo)
  644. paramInfo = deepcopy(CarlaPortCountInfo)
  645. audioInfo['ins'] = audioIns
  646. audioInfo['outs'] = audioOuts
  647. audioInfo['total'] = audioIns + audioOuts
  648. midiInfo['ins'] = midiIns
  649. midiInfo['outs'] = midiOuts
  650. midiInfo['total'] = midiIns + midiOuts
  651. paramInfo['ins'] = cIns
  652. paramInfo['outs'] = cOuts
  653. paramInfo['total'] = cTotals
  654. Carla.host._set_audioCountInfo(pluginId, audioInfo)
  655. Carla.host._set_midiCountInfo(pluginId, midiInfo)
  656. Carla.host._set_parameterCountInfo(pluginId, paramInfo)
  657. @pyqtSlot(int, int, int, int, str, str, float)
  658. def slot_handleSetParameterData(self, pluginId, index, type_, hints, name, label, current):
  659. # remove hints not possible in bridge mode
  660. hints &= ~(PARAMETER_USES_SCALEPOINTS | PARAMETER_USES_CUSTOM_TEXT)
  661. data = deepcopy(ParameterData)
  662. data['type'] = type_
  663. data['index'] = index
  664. data['rindex'] = index
  665. data['hints'] = hints
  666. info = deepcopy(CarlaParameterInfo)
  667. info['name'] = name
  668. info['label'] = label
  669. Carla.host._set_parameterDataS(pluginId, index, data)
  670. Carla.host._set_parameterInfoS(pluginId, index, info)
  671. Carla.host._set_parameterValueS(pluginId, index, current)
  672. @pyqtSlot(int, int, float, float, float, float, float, float)
  673. def slot_handleSetParameterRanges(self, pluginId, index, min_, max_, def_, step, stepSmall, stepLarge):
  674. ranges = deepcopy(ParameterRanges)
  675. ranges['min'] = min_
  676. ranges['max'] = max_
  677. ranges['def'] = def_
  678. ranges['step'] = step
  679. ranges['stepSmall'] = stepSmall
  680. ranges['stepLarge'] = stepLarge
  681. Carla.host._set_parameterRangeS(pluginId, index, ranges)
  682. @pyqtSlot(int, int, float)
  683. def slot_handleSetParameterValue(self, pluginId, parameterId, value):
  684. if parameterId >= 0:
  685. Carla.host._set_parameterValueS(pluginId, parameterId, value)
  686. pwidget = self.fPluginList[pluginId]
  687. if pwidget is None:
  688. return
  689. pwidget.setParameterValue(parameterId, value)
  690. @pyqtSlot(int, int, float)
  691. def slot_handleSetDefaultValue(self, pluginId, parameterId, value):
  692. Carla.host._set_parameterDefaultValue(pluginId, parameterId, value)
  693. pwidget = self.fPluginList[pluginId]
  694. if pwidget is None:
  695. return
  696. pwidget.setParameterDefault(parameterId, value)
  697. @pyqtSlot(int, int, int)
  698. def slot_handleSetParameterMidiCC(self, pluginId, index, cc):
  699. Carla.host._set_parameterMidiCC(pluginId, index, cc)
  700. pwidget = self.fPluginList[pluginId]
  701. if pwidget is None:
  702. return
  703. pwidget.setParameterMidiControl(index, cc)
  704. @pyqtSlot(int, int, int)
  705. def slot_handleSetParameterMidiChannel(self, pluginId, index, channel):
  706. Carla.host._set_parameterMidiChannel(pluginId, index, channel)
  707. pwidget = self.fPluginList[pluginId]
  708. if pwidget is None:
  709. return
  710. pwidget.setParameterMidiChannel(index, channel)
  711. @pyqtSlot(int, int)
  712. def slot_handleSetProgram(self, pluginId, index):
  713. Carla.host._set_currentProgram(pluginId, index)
  714. pwidget = self.fPluginList[pluginId]
  715. if pwidget is None:
  716. return
  717. pwidget.setProgram(index)
  718. @pyqtSlot(int, int)
  719. def slot_handleSetProgramCount(self, pluginId, count):
  720. Carla.host._set_programCount(pluginId, count)
  721. @pyqtSlot(int, int, str)
  722. def slot_handleSetProgramName(self, pluginId, index, name):
  723. Carla.host._set_programNameS(pluginId, index, name)
  724. @pyqtSlot(int, int)
  725. def slot_handleSetMidiProgram(self, pluginId, index):
  726. Carla.host._set_currentMidiProgram(pluginId, index)
  727. pwidget = self.fPluginList[pluginId]
  728. if pwidget is None:
  729. return
  730. pwidget.setMidiProgram(index)
  731. @pyqtSlot(int, int)
  732. def slot_handleSetMidiProgramCount(self, pluginId, count):
  733. Carla.host._set_midiProgramCount(pluginId, count)
  734. @pyqtSlot(int, int, int, int, str)
  735. def slot_handleSetMidiProgramData(self, pluginId, index, bank, program, name):
  736. data = deepcopy(MidiProgramData)
  737. data['bank'] = bank
  738. data['program'] = program
  739. data['label'] = name
  740. Carla.host._set_midiProgramDataS(pluginId, index, data)
  741. @pyqtSlot(int, int, float)
  742. def slot_handleSetInputPeakValue(self, pluginId, portId, value):
  743. Carla.host._set_inPeak(pluginId, portId-1, value)
  744. @pyqtSlot(int, int, float)
  745. def slot_handleSetOutputPeakValue(self, pluginId, portId, value):
  746. Carla.host._set_outPeak(pluginId, portId-1, value)
  747. @pyqtSlot(int, int, int, int)
  748. def slot_handleNoteOn(self, pluginId, channel, note, velo):
  749. pwidget = self.fPluginList[pluginId]
  750. if pwidget is None:
  751. return
  752. pwidget.sendNoteOn(note)
  753. @pyqtSlot(int, int, int)
  754. def slot_handleNoteOff(self, pluginId, channel, note):
  755. pwidget = self.fPluginList[pluginId]
  756. if pwidget is None:
  757. return
  758. pwidget.sendNoteOff(note)
  759. @pyqtSlot(int, float, float, float, float)
  760. def slot_handleSetPeaks(self, pluginId, in1, in2, out1, out2):
  761. Carla.host._set_peaks(pluginId, in1, in2, out1, out2)
  762. @pyqtSlot()
  763. def slot_handleExit(self):
  764. self.removeAll()
  765. if self.lo_server:
  766. self.lo_server.stop()
  767. self.lo_server = None
  768. self.ui.act_file_refresh.setEnabled(False)
  769. global lo_target, lo_targetName
  770. lo_target = None
  771. lo_targetName = ""
  772. self.lo_address = ""
  773. def saveSettings(self):
  774. settings = QSettings()
  775. settings.setValue("Geometry", self.saveGeometry())
  776. #settings.setValue("ShowToolbar", self.ui.toolBar.isVisible())
  777. def loadSettings(self):
  778. settings = QSettings()
  779. self.restoreGeometry(settings.value("Geometry", ""))
  780. #showToolbar = settings.value("ShowToolbar", True, type=bool)
  781. #self.ui.act_settings_show_toolbar.setChecked(showToolbar)
  782. #self.ui.toolBar.setVisible(showToolbar)
  783. def timerEvent(self, event):
  784. if event.timerId() == self.fIdleTimerFast:
  785. for pwidget in self.fPluginList:
  786. if pwidget is None:
  787. break
  788. pwidget.idleFast()
  789. elif event.timerId() == self.fIdleTimerSlow:
  790. for pwidget in self.fPluginList:
  791. if pwidget is None:
  792. break
  793. pwidget.idleSlow()
  794. QMainWindow.timerEvent(self, event)
  795. def closeEvent(self, event):
  796. self.saveSettings()
  797. global lo_target
  798. if lo_target and self.lo_server:
  799. lo_send(lo_target, "/unregister")
  800. QMainWindow.closeEvent(self, event)
  801. #--------------- main ------------------
  802. if __name__ == '__main__':
  803. # App initialization
  804. app = QApplication(sys.argv)
  805. app.setApplicationName("Carla-Control")
  806. app.setApplicationVersion(VERSION)
  807. app.setOrganizationName("Cadence")
  808. app.setWindowIcon(QIcon(":/scalable/carla-control.svg"))
  809. libPrefix = None
  810. for i in range(len(app.arguments())):
  811. if i == 0: continue
  812. argument = app.arguments()[i]
  813. if argument.startswith("--with-libprefix="):
  814. libPrefix = argument.replace("--with-libprefix=", "")
  815. if libPrefix is not None:
  816. libName = os.path.join(libPrefix, "lib", "carla", carla_libname)
  817. else:
  818. libName = carla_library_path
  819. # Load backend DLL, so it registers the theme
  820. libDLL = QLibrary()
  821. libDLL.setFileName(libName)
  822. try:
  823. libDLL.load()
  824. except:
  825. pass
  826. # Init backend (OSC bridge version)
  827. Carla.host = Host()
  828. # Create GUI
  829. Carla.gui = CarlaControlW()
  830. # Set-up custom signal handling
  831. setUpSignals()
  832. # Show GUI
  833. Carla.gui.show()
  834. # App-Loop
  835. ret = app.exec_()
  836. # Close backend DLL
  837. if libDLL.isLoaded():
  838. # Need to destroy app before theme
  839. del app
  840. libDLL.unload()
  841. sys.exit(ret)