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.

1076 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. if MACOS:
  487. self.setUnifiedTitleAndToolBarOnMac(True)
  488. # -------------------------------------------------------------
  489. # Load Settings
  490. self.loadSettings()
  491. # -------------------------------------------------------------
  492. # Internal stuff
  493. self.fProjectFilename = None
  494. self.fProjectLoading = False
  495. self.fPluginCount = 0
  496. self.fPluginList = []
  497. self.fIdleTimerFast = 0
  498. self.fIdleTimerSlow = 0
  499. self.fLastPluginName = ""
  500. self.lo_address = ""
  501. self.lo_server = None
  502. # -------------------------------------------------------------
  503. # Set-up GUI stuff
  504. self.ui.act_file_refresh.setEnabled(False)
  505. #self.ui.act_plugin_remove_all.setEnabled(False)
  506. self.resize(self.width(), 0)
  507. # -------------------------------------------------------------
  508. # Connect actions to functions
  509. self.connect(self.ui.act_file_connect, SIGNAL("triggered()"), SLOT("slot_fileConnect()"))
  510. self.connect(self.ui.act_file_refresh, SIGNAL("triggered()"), SLOT("slot_fileRefresh()"))
  511. #self.connect(self.ui.act_plugin_add, SIGNAL("triggered()"), SLOT("slot_pluginAdd()"))
  512. #self.connect(self.ui.act_plugin_add2, SIGNAL("triggered()"), SLOT("slot_pluginAdd()"))
  513. #self.connect(self.ui.act_plugin_refresh, SIGNAL("triggered()"), SLOT("slot_pluginRefresh()"))
  514. #self.connect(self.ui.act_plugin_remove_all, SIGNAL("triggered()"), SLOT("slot_pluginRemoveAll()"))
  515. #self.connect(self.ui.act_settings_show_toolbar, SIGNAL("triggered(bool)"), SLOT("slot_toolbarShown()"))
  516. #self.connect(self.ui.act_settings_configure, SIGNAL("triggered()"), SLOT("slot_configureCarla()"))
  517. self.connect(self.ui.act_help_about, SIGNAL("triggered()"), SLOT("slot_aboutCarlaControl()"))
  518. self.connect(self.ui.act_help_about_qt, SIGNAL("triggered()"), app, SLOT("aboutQt()"))
  519. self.connect(self, SIGNAL("SIGUSR1()"), SLOT("slot_handleSIGUSR1()"))
  520. self.connect(self, SIGNAL("SIGTERM()"), SLOT("slot_handleSIGTERM()"))
  521. self.connect(self, SIGNAL("AddPluginStart(int, QString)"), SLOT("slot_handleAddPluginStart(int, QString)"))
  522. self.connect(self, SIGNAL("AddPluginEnd(int)"), SLOT("slot_handleAddPluginEnd(int)"))
  523. self.connect(self, SIGNAL("RemovePlugin(int)"), SLOT("slot_handleRemovePlugin(int)"))
  524. 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)"))
  525. self.connect(self, SIGNAL("SetPluginPorts(int, int, int, int, int, int, int, int)"), SLOT("slot_handleSetPluginPorts(int, int, int, int, int, int, int, int)"))
  526. self.connect(self, SIGNAL("SetParameterData(int, int, int, int, QString, QString, double)"), SLOT("slot_handleSetParameterData(int, int, int, int, QString, QString, double)"))
  527. self.connect(self, SIGNAL("SetParameterRanges(int, int, double, double, double, double, double, double)"), SLOT("slot_handleSetParameterRanges(int, int, double, double, double, double, double, double)"))
  528. self.connect(self, SIGNAL("SetParameterMidiCC(int, int, int)"), SLOT("slot_handleSetParameterMidiCC(int, int, int)"))
  529. self.connect(self, SIGNAL("SetParameterMidiChannel(int, int, int)"), SLOT("slot_handleSetParameterMidiChannel(int, int, int)"))
  530. self.connect(self, SIGNAL("SetParameterValue(int, int, double)"), SLOT("slot_handleSetParameterValue(int, int, double)"))
  531. self.connect(self, SIGNAL("SetDefaultValue(int, int, double)"), SLOT("slot_handleSetDefaultValue(int, int, double)"))
  532. self.connect(self, SIGNAL("SetProgram(int, int)"), SLOT("slot_handleSetProgram(int, int)"))
  533. self.connect(self, SIGNAL("SetProgramCount(int, int)"), SLOT("slot_handleSetProgramCount(int, int)"))
  534. self.connect(self, SIGNAL("SetProgramName(int, int, QString)"), SLOT("slot_handleSetProgramName(int, int, QString)"))
  535. self.connect(self, SIGNAL("SetMidiProgram(int, int)"), SLOT("slot_handleSetMidiProgram(int, int)"))
  536. self.connect(self, SIGNAL("SetMidiProgramCount(int, int)"), SLOT("slot_handleSetMidiProgramCount(int, int)"))
  537. self.connect(self, SIGNAL("SetMidiProgramData(int, int, int, int, QString)"), SLOT("slot_handleSetMidiProgramData(int, int, int, int, QString)"))
  538. self.connect(self, SIGNAL("NoteOn(int, int, int, int)"), SLOT("slot_handleNoteOn(int, int, int, int)"))
  539. self.connect(self, SIGNAL("NoteOff(int, int, int)"), SLOT("slot_handleNoteOff(int, int, int)"))
  540. self.connect(self, SIGNAL("SetPeaks(int, double, double, double, double)"), SLOT("slot_handleSetPeaks(int, double, double, double, double)"))
  541. self.connect(self, SIGNAL("Exit()"), SLOT("slot_handleExit()"))
  542. def removeAll(self):
  543. self.killTimer(self.fIdleTimerFast)
  544. self.killTimer(self.fIdleTimerSlow)
  545. self.fIdleTimerFast = 0
  546. self.fIdleTimerSlow = 0
  547. for i in range(self.fPluginCount):
  548. pwidget = self.fPluginList[i]
  549. if pwidget is None:
  550. break
  551. pwidget.ui.edit_dialog.close()
  552. pwidget.close()
  553. pwidget.deleteLater()
  554. del pwidget
  555. self.fPluginCount = 0
  556. self.fPluginList = []
  557. Carla.host.fPluginsInfo = []
  558. self.fIdleTimerFast = self.startTimer(60)
  559. self.fIdleTimerSlow = self.startTimer(60*2)
  560. @pyqtSlot()
  561. def slot_fileConnect(self):
  562. global lo_target, lo_targetName
  563. if lo_target and self.lo_server:
  564. urlText = self.lo_address
  565. else:
  566. urlText = "osc.tcp://127.0.0.1:19000/Carla"
  567. askValue = QInputDialog.getText(self, self.tr("Carla Control - Connect"), self.tr("Address"), text=urlText)
  568. if not askValue[1]:
  569. return
  570. self.slot_handleExit()
  571. self.lo_address = askValue[0]
  572. lo_target = Address(self.lo_address)
  573. lo_targetName = self.lo_address.rsplit("/", 1)[-1]
  574. print("Connecting to \"%s\" as '%s'..." % (self.lo_address, lo_targetName))
  575. try:
  576. self.lo_server = ControlServer(self)
  577. except: # ServerError, err:
  578. print("Connecting error!")
  579. #print str(err)
  580. QMessageBox.critical(self, self.tr("Error"), self.tr("Failed to connect, operation failed."))
  581. if self.lo_server:
  582. self.lo_server.start()
  583. self.ui.act_file_refresh.setEnabled(True)
  584. lo_send(lo_target, "/register", self.lo_server.getFullURL())
  585. @pyqtSlot()
  586. def slot_fileRefresh(self):
  587. global lo_target
  588. if lo_target and self.lo_server:
  589. self.removeAll()
  590. lo_send(lo_target, "/unregister")
  591. lo_send(lo_target, "/register", self.lo_server.getFullURL())
  592. @pyqtSlot()
  593. def slot_aboutCarlaControl(self):
  594. CarlaAboutW(self).exec_()
  595. @pyqtSlot(int, str)
  596. def slot_handleAddPluginStart(self, pluginId, pluginName):
  597. self.fLastPluginName = pluginName
  598. Carla.host._add(pluginId)
  599. @pyqtSlot(int)
  600. def slot_handleAddPluginEnd(self, pluginId):
  601. pwidget = PluginWidget(self, pluginId)
  602. pwidget.setRefreshRate(60)
  603. self.ui.w_plugins.layout().addWidget(pwidget)
  604. self.fPluginCount += 1
  605. self.fPluginList.append(pwidget)
  606. @pyqtSlot(int)
  607. def slot_handleRemovePlugin(self, pluginId):
  608. if pluginId >= self.fPluginCount:
  609. print("handleRemovePlugin(%i) - invalid plugin id" % pluginId)
  610. return
  611. pwidget = self.fPluginList[pluginId]
  612. if pwidget is None:
  613. print("handleRemovePlugin(%i) - invalid plugin" % pluginId)
  614. return
  615. self.fPluginList.pop(pluginId)
  616. self.fPluginCount -= 1
  617. self.ui.w_plugins.layout().removeWidget(pwidget)
  618. pwidget.ui.edit_dialog.close()
  619. pwidget.close()
  620. pwidget.deleteLater()
  621. del pwidget
  622. # push all plugins 1 slot back
  623. for i in range(pluginId, self.fPluginCount):
  624. self.fPluginList[i].setId(i)
  625. Carla.host.fPluginsInfo.pop(pluginId)
  626. @pyqtSlot(int, int, int, int, str, str, str, str, int)
  627. def slot_handleSetPluginData(self, pluginId, type_, category, hints, realName, label, maker, copyright, uniqueId):
  628. info = deepcopy(CarlaPluginInfo)
  629. info['type'] = type_
  630. info['category'] = category
  631. info['hints'] = hints
  632. info['name'] = self.fLastPluginName
  633. info['label'] = label
  634. info['maker'] = maker
  635. info['copyright'] = copyright
  636. info['uniqueId'] = uniqueId
  637. Carla.host._set_pluginInfo(pluginId, info)
  638. Carla.host._set_pluginRealName(pluginId, realName)
  639. @pyqtSlot(int, int, int, int, int, int, int, int)
  640. def slot_handleSetPluginPorts(self, pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals):
  641. audioInfo = deepcopy(CarlaPortCountInfo)
  642. midiInfo = deepcopy(CarlaPortCountInfo)
  643. paramInfo = deepcopy(CarlaPortCountInfo)
  644. audioInfo['ins'] = audioIns
  645. audioInfo['outs'] = audioOuts
  646. audioInfo['total'] = audioIns + audioOuts
  647. midiInfo['ins'] = midiIns
  648. midiInfo['outs'] = midiOuts
  649. midiInfo['total'] = midiIns + midiOuts
  650. paramInfo['ins'] = cIns
  651. paramInfo['outs'] = cOuts
  652. paramInfo['total'] = cTotals
  653. Carla.host._set_audioCountInfo(pluginId, audioInfo)
  654. Carla.host._set_midiCountInfo(pluginId, midiInfo)
  655. Carla.host._set_parameterCountInfo(pluginId, paramInfo)
  656. @pyqtSlot(int, int, int, int, str, str, float)
  657. def slot_handleSetParameterData(self, pluginId, index, type_, hints, name, label, current):
  658. # remove hints not possible in bridge mode
  659. hints &= ~(PARAMETER_USES_SCALEPOINTS | PARAMETER_USES_CUSTOM_TEXT)
  660. data = deepcopy(ParameterData)
  661. data['type'] = type_
  662. data['index'] = index
  663. data['rindex'] = index
  664. data['hints'] = hints
  665. info = deepcopy(CarlaParameterInfo)
  666. info['name'] = name
  667. info['label'] = label
  668. Carla.host._set_parameterDataS(pluginId, index, data)
  669. Carla.host._set_parameterInfoS(pluginId, index, info)
  670. Carla.host._set_parameterValueS(pluginId, index, current)
  671. @pyqtSlot(int, int, float, float, float, float, float, float)
  672. def slot_handleSetParameterRanges(self, pluginId, index, min_, max_, def_, step, stepSmall, stepLarge):
  673. ranges = deepcopy(ParameterRanges)
  674. ranges['min'] = min_
  675. ranges['max'] = max_
  676. ranges['def'] = def_
  677. ranges['step'] = step
  678. ranges['stepSmall'] = stepSmall
  679. ranges['stepLarge'] = stepLarge
  680. Carla.host._set_parameterRangeS(pluginId, index, ranges)
  681. @pyqtSlot(int, int, float)
  682. def slot_handleSetParameterValue(self, pluginId, parameterId, value):
  683. if parameterId >= 0:
  684. Carla.host._set_parameterValueS(pluginId, parameterId, value)
  685. pwidget = self.fPluginList[pluginId]
  686. if pwidget is None:
  687. return
  688. pwidget.setParameterValue(parameterId, value)
  689. @pyqtSlot(int, int, float)
  690. def slot_handleSetDefaultValue(self, pluginId, parameterId, value):
  691. Carla.host._set_parameterDefaultValue(pluginId, parameterId, value)
  692. pwidget = self.fPluginList[pluginId]
  693. if pwidget is None:
  694. return
  695. pwidget.setParameterDefault(parameterId, value)
  696. @pyqtSlot(int, int, int)
  697. def slot_handleSetParameterMidiCC(self, pluginId, index, cc):
  698. Carla.host._set_parameterMidiCC(pluginId, index, cc)
  699. pwidget = self.fPluginList[pluginId]
  700. if pwidget is None:
  701. return
  702. pwidget.setParameterMidiControl(index, cc)
  703. @pyqtSlot(int, int, int)
  704. def slot_handleSetParameterMidiChannel(self, pluginId, index, channel):
  705. Carla.host._set_parameterMidiChannel(pluginId, index, channel)
  706. pwidget = self.fPluginList[pluginId]
  707. if pwidget is None:
  708. return
  709. pwidget.setParameterMidiChannel(index, channel)
  710. @pyqtSlot(int, int)
  711. def slot_handleSetProgram(self, pluginId, index):
  712. Carla.host._set_currentProgram(pluginId, index)
  713. pwidget = self.fPluginList[pluginId]
  714. if pwidget is None:
  715. return
  716. pwidget.setProgram(index)
  717. @pyqtSlot(int, int)
  718. def slot_handleSetProgramCount(self, pluginId, count):
  719. Carla.host._set_programCount(pluginId, count)
  720. @pyqtSlot(int, int, str)
  721. def slot_handleSetProgramName(self, pluginId, index, name):
  722. Carla.host._set_programNameS(pluginId, index, name)
  723. @pyqtSlot(int, int)
  724. def slot_handleSetMidiProgram(self, pluginId, index):
  725. Carla.host._set_currentMidiProgram(pluginId, index)
  726. pwidget = self.fPluginList[pluginId]
  727. if pwidget is None:
  728. return
  729. pwidget.setMidiProgram(index)
  730. @pyqtSlot(int, int)
  731. def slot_handleSetMidiProgramCount(self, pluginId, count):
  732. Carla.host._set_midiProgramCount(pluginId, count)
  733. @pyqtSlot(int, int, int, int, str)
  734. def slot_handleSetMidiProgramData(self, pluginId, index, bank, program, name):
  735. data = deepcopy(MidiProgramData)
  736. data['bank'] = bank
  737. data['program'] = program
  738. data['label'] = name
  739. Carla.host._set_midiProgramDataS(pluginId, index, data)
  740. @pyqtSlot(int, int, float)
  741. def slot_handleSetInputPeakValue(self, pluginId, portId, value):
  742. Carla.host._set_inPeak(pluginId, portId-1, value)
  743. @pyqtSlot(int, int, float)
  744. def slot_handleSetOutputPeakValue(self, pluginId, portId, value):
  745. Carla.host._set_outPeak(pluginId, portId-1, value)
  746. @pyqtSlot(int, int, int, int)
  747. def slot_handleNoteOn(self, pluginId, channel, note, velo):
  748. pwidget = self.fPluginList[pluginId]
  749. if pwidget is None:
  750. return
  751. pwidget.sendNoteOn(note)
  752. @pyqtSlot(int, int, int)
  753. def slot_handleNoteOff(self, pluginId, channel, note):
  754. pwidget = self.fPluginList[pluginId]
  755. if pwidget is None:
  756. return
  757. pwidget.sendNoteOff(note)
  758. @pyqtSlot(int, float, float, float, float)
  759. def slot_handleSetPeaks(self, pluginId, in1, in2, out1, out2):
  760. Carla.host._set_peaks(pluginId, in1, in2, out1, out2)
  761. @pyqtSlot()
  762. def slot_handleExit(self):
  763. self.removeAll()
  764. if self.lo_server:
  765. self.lo_server.stop()
  766. self.lo_server = None
  767. self.ui.act_file_refresh.setEnabled(False)
  768. global lo_target, lo_targetName
  769. lo_target = None
  770. lo_targetName = ""
  771. self.lo_address = ""
  772. def saveSettings(self):
  773. settings = QSettings()
  774. settings.setValue("Geometry", self.saveGeometry())
  775. #settings.setValue("ShowToolbar", self.ui.toolBar.isVisible())
  776. def loadSettings(self):
  777. settings = QSettings()
  778. self.restoreGeometry(settings.value("Geometry", ""))
  779. #showToolbar = settings.value("ShowToolbar", True, type=bool)
  780. #self.ui.act_settings_show_toolbar.setChecked(showToolbar)
  781. #self.ui.toolBar.setVisible(showToolbar)
  782. def timerEvent(self, event):
  783. if event.timerId() == self.fIdleTimerFast:
  784. for pwidget in self.fPluginList:
  785. if pwidget is None:
  786. break
  787. pwidget.idleFast()
  788. elif event.timerId() == self.fIdleTimerSlow:
  789. for pwidget in self.fPluginList:
  790. if pwidget is None:
  791. break
  792. pwidget.idleSlow()
  793. QMainWindow.timerEvent(self, event)
  794. def closeEvent(self, event):
  795. self.saveSettings()
  796. global lo_target
  797. if lo_target and self.lo_server:
  798. lo_send(lo_target, "/unregister")
  799. QMainWindow.closeEvent(self, event)
  800. #--------------- main ------------------
  801. if __name__ == '__main__':
  802. # App initialization
  803. app = QApplication(sys.argv)
  804. app.setApplicationName("Carla-Control")
  805. app.setApplicationVersion(VERSION)
  806. app.setOrganizationName("Cadence")
  807. app.setWindowIcon(QIcon(":/scalable/carla-control.svg"))
  808. libPrefix = None
  809. for i in range(len(app.arguments())):
  810. if i == 0: continue
  811. argument = app.arguments()[i]
  812. if argument.startswith("--with-libprefix="):
  813. libPrefix = argument.replace("--with-libprefix=", "")
  814. if libPrefix is not None:
  815. libName = os.path.join(libPrefix, "lib", "carla", carla_libname)
  816. else:
  817. libName = carla_library_path
  818. # Load backend DLL, so it registers the theme
  819. libDLL = QLibrary()
  820. libDLL.setFileName(libName)
  821. try:
  822. libDLL.load()
  823. except:
  824. pass
  825. # Init backend (OSC bridge version)
  826. Carla.host = Host()
  827. # Create GUI
  828. Carla.gui = CarlaControlW()
  829. # Set-up custom signal handling
  830. setUpSignals()
  831. # Show GUI
  832. Carla.gui.show()
  833. # App-Loop
  834. ret = app.exec_()
  835. # Close backend DLL
  836. if libDLL.isLoaded():
  837. # Need to destroy app before theme
  838. del app
  839. libDLL.unload()
  840. sys.exit(ret)