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.

497 lines
15KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Carla rack widget code
  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 doc/GPL.txt file.
  17. # ------------------------------------------------------------------------------------------------------------
  18. # Imports (Global)
  19. from PyQt4.QtCore import QSize, QTimer
  20. from PyQt4.QtGui import QApplication, QListWidget, QListWidgetItem
  21. # ------------------------------------------------------------------------------------------------------------
  22. # Imports (Custom Stuff)
  23. from carla_skin import *
  24. # ------------------------------------------------------------------------------------------------------------
  25. # Rack widget item
  26. class CarlaRackItem(QListWidgetItem):
  27. kRackItemType = QListWidgetItem.UserType + 1
  28. def __init__(self, parent, pluginId):
  29. QListWidgetItem.__init__(self, parent, self.kRackItemType)
  30. self.widget = createPluginSlot(parent, pluginId)
  31. self.widget.setFixedHeight(self.widget.getFixedHeight())
  32. self.setSizeHint(QSize(300, self.widget.getFixedHeight()))
  33. parent.setItemWidget(self, self.widget)
  34. # -----------------------------------------------------------------
  35. def close(self):
  36. self.widget.fEditDialog.close()
  37. #def setId(self, idx):
  38. #self.widget.setId(idx)
  39. #def setName(self, newName):
  40. #self.widget.ui.label_name.setText(newName)
  41. #self.widget.ui.edit_dialog.setName(newName)
  42. # ------------------------------------------------------------------------------------------------------------
  43. # Rack widget
  44. class CarlaRackW(QListWidget):
  45. def __init__(self, parent, doSetup = True):
  46. QListWidget.__init__(self, parent)
  47. # -------------------------------------------------------------
  48. # Internal stuff
  49. self.fParent = parent
  50. self.fPluginCount = 0
  51. self.fPluginList = []
  52. # -------------------------------------------------------------
  53. # Set-up GUI stuff
  54. self.setMinimumWidth(591)
  55. self.setSortingEnabled(False)
  56. app = QApplication.instance()
  57. pal1 = app.palette().base().color()
  58. pal2 = app.palette().button().color()
  59. col1 = "stop:0 rgb(%i, %i, %i)" % (pal1.red(), pal1.green(), pal1.blue())
  60. col2 = "stop:1 rgb(%i, %i, %i)" % (pal2.red(), pal2.green(), pal2.blue())
  61. self.setStyleSheet("""
  62. QListWidget {
  63. background-color: qlineargradient(spread:pad,
  64. x1:0.0, y1:0.0,
  65. x2:0.2, y2:1.0,
  66. %s,
  67. %s
  68. );
  69. }
  70. """ % (col1, col2))
  71. # -------------------------------------------------------------
  72. # Connect actions to functions
  73. if not doSetup: return
  74. parent.ui.menu_Canvas.hide()
  75. parent.ui.act_plugins_enable.triggered.connect(self.slot_pluginsEnable)
  76. parent.ui.act_plugins_disable.triggered.connect(self.slot_pluginsDisable)
  77. parent.ui.act_plugins_volume100.triggered.connect(self.slot_pluginsVolume100)
  78. parent.ui.act_plugins_mute.triggered.connect(self.slot_pluginsMute)
  79. parent.ui.act_plugins_wet100.triggered.connect(self.slot_pluginsWet100)
  80. parent.ui.act_plugins_bypass.triggered.connect(self.slot_pluginsBypass)
  81. parent.ui.act_plugins_center.triggered.connect(self.slot_pluginsCenter)
  82. parent.ui.act_plugins_panic.triggered.connect(self.slot_pluginsDisable)
  83. parent.ui.act_settings_configure.triggered.connect(self.slot_configureCarla)
  84. parent.ParameterValueChangedCallback.connect(self.slot_handleParameterValueChangedCallback)
  85. parent.ParameterDefaultChangedCallback.connect(self.slot_handleParameterDefaultChangedCallback)
  86. parent.ParameterMidiChannelChangedCallback.connect(self.slot_handleParameterMidiChannelChangedCallback)
  87. parent.ParameterMidiCcChangedCallback.connect(self.slot_handleParameterMidiCcChangedCallback)
  88. parent.ProgramChangedCallback.connect(self.slot_handleProgramChangedCallback)
  89. parent.MidiProgramChangedCallback.connect(self.slot_handleMidiProgramChangedCallback)
  90. parent.UiStateChangedCallback.connect(self.slot_handleUiStateChangedCallback)
  91. parent.NoteOnCallback.connect(self.slot_handleNoteOnCallback)
  92. parent.NoteOffCallback.connect(self.slot_handleNoteOffCallback)
  93. parent.UpdateCallback.connect(self.slot_handleUpdateCallback)
  94. parent.ReloadInfoCallback.connect(self.slot_handleReloadInfoCallback)
  95. parent.ReloadParametersCallback.connect(self.slot_handleReloadParametersCallback)
  96. parent.ReloadProgramsCallback.connect(self.slot_handleReloadProgramsCallback)
  97. parent.ReloadAllCallback.connect(self.slot_handleReloadAllCallback)
  98. # -----------------------------------------------------------------
  99. def getPluginCount(self):
  100. return self.fPluginCount
  101. # -----------------------------------------------------------------
  102. def addPlugin(self, pluginId, isProjectLoading):
  103. pitem = CarlaRackItem(self, pluginId)
  104. self.fPluginList.append(pitem)
  105. self.fPluginCount += 1
  106. if not isProjectLoading:
  107. pitem.widget.setActive(True, True, True)
  108. def removePlugin(self, pluginId):
  109. if pluginId >= self.fPluginCount:
  110. return
  111. pitem = self.fPluginList[pluginId]
  112. if pitem is None:
  113. return
  114. self.fPluginCount -= 1
  115. self.fPluginList.pop(pluginId)
  116. self.takeItem(pluginId)
  117. pitem.close()
  118. del pitem
  119. # push all plugins 1 slot back
  120. for i in range(pluginId, self.fPluginCount):
  121. pitem = self.fPluginList[i]
  122. pitem.widget.setId(i)
  123. def renamePlugin(self, pluginId, newName):
  124. if pluginId >= self.fPluginCount:
  125. return
  126. pitem = self.fPluginList[pluginId]
  127. if pitem is None:
  128. return
  129. pitem.widget.setName(newName)
  130. def disablePlugin(self, pluginId, errorMsg):
  131. if pluginId >= self.fPluginCount:
  132. return
  133. pitem = self.fPluginList[pluginId]
  134. if pitem is None:
  135. return
  136. def removeAllPlugins(self):
  137. while (self.takeItem(0)):
  138. pass
  139. for i in range(self.fPluginCount):
  140. pitem = self.fPluginList[i]
  141. if pitem is None:
  142. break
  143. pitem.close()
  144. del pitem
  145. self.fPluginCount = 0
  146. self.fPluginList = []
  147. # -----------------------------------------------------------------
  148. def engineStarted(self):
  149. pass
  150. def engineStopped(self):
  151. pass
  152. def engineChanged(self):
  153. pass
  154. # -----------------------------------------------------------------
  155. def idleFast(self):
  156. for i in range(self.fPluginCount):
  157. pitem = self.fPluginList[i]
  158. if pitem is None:
  159. break
  160. pitem.widget.idleFast()
  161. def idleSlow(self):
  162. for i in range(self.fPluginCount):
  163. pitem = self.fPluginList[i]
  164. if pitem is None:
  165. break
  166. pitem.widget.idleSlow()
  167. # -----------------------------------------------------------------
  168. def saveSettings(self, settings):
  169. pass
  170. # -----------------------------------------------------------------
  171. @pyqtSlot()
  172. def slot_pluginsEnable(self):
  173. if not Carla.host.is_engine_running():
  174. return
  175. for i in range(self.fPluginCount):
  176. pitem = self.fPluginList[i]
  177. if pitem is None:
  178. break
  179. pitem.widget.setActive(True, True, True)
  180. @pyqtSlot()
  181. def slot_pluginsDisable(self):
  182. if not Carla.host.is_engine_running():
  183. return
  184. for i in range(self.fPluginCount):
  185. pitem = self.fPluginList[i]
  186. if pitem is None:
  187. break
  188. pitem.widget.setActive(False, True, True)
  189. @pyqtSlot()
  190. def slot_pluginsVolume100(self):
  191. if not Carla.host.is_engine_running():
  192. return
  193. for i in range(self.fPluginCount):
  194. pitem = self.fPluginList[i]
  195. if pitem is None:
  196. break
  197. pitem.widget.setInternalParameter(PLUGIN_CAN_VOLUME, 1.0)
  198. @pyqtSlot()
  199. def slot_pluginsMute(self):
  200. if not Carla.host.is_engine_running():
  201. return
  202. for i in range(self.fPluginCount):
  203. pitem = self.fPluginList[i]
  204. if pitem is None:
  205. break
  206. pitem.widget.setInternalParameter(PLUGIN_CAN_VOLUME, 0.0)
  207. @pyqtSlot()
  208. def slot_pluginsWet100(self):
  209. if not Carla.host.is_engine_running():
  210. return
  211. for i in range(self.fPluginCount):
  212. pitem = self.fPluginList[i]
  213. if pitem is None:
  214. break
  215. pitem.widget.setInternalParameter(PLUGIN_CAN_DRYWET, 1.0)
  216. @pyqtSlot()
  217. def slot_pluginsBypass(self):
  218. if not Carla.host.is_engine_running():
  219. return
  220. for i in range(self.fPluginCount):
  221. pitem = self.fPluginList[i]
  222. if pitem is None:
  223. break
  224. pitem.widget.setInternalParameter(PLUGIN_CAN_DRYWET, 0.0)
  225. @pyqtSlot()
  226. def slot_pluginsCenter(self):
  227. if not Carla.host.is_engine_running():
  228. return
  229. for i in range(self.fPluginCount):
  230. pitem = self.fPluginList[i]
  231. if pitem is None:
  232. break
  233. pitem.widget.setInternalParameter(PARAMETER_BALANCE_LEFT, -1.0)
  234. pitem.widget.setInternalParameter(PARAMETER_BALANCE_RIGHT, 1.0)
  235. pitem.widget.setInternalParameter(PARAMETER_PANNING, 0.0)
  236. # -----------------------------------------------------------------
  237. @pyqtSlot()
  238. def slot_configureCarla(self):
  239. if self.fParent is None or not self.fParent.openSettingsWindow(False, False):
  240. return
  241. self.fParent.loadSettings(False)
  242. # -----------------------------------------------------------------
  243. @pyqtSlot(int, int, float)
  244. def slot_handleParameterValueChangedCallback(self, pluginId, index, value):
  245. if pluginId >= self.fPluginCount:
  246. return
  247. pitem = self.fPluginList[pluginId]
  248. if pitem is None:
  249. return
  250. pitem.widget.setParameterValue(index, value)
  251. @pyqtSlot(int, int, float)
  252. def slot_handleParameterDefaultChangedCallback(self, pluginId, index, value):
  253. if pluginId >= self.fPluginCount:
  254. return
  255. pitem = self.fPluginList[pluginId]
  256. if pitem is None:
  257. return
  258. pitem.widget.setParameterDefault(index, value)
  259. @pyqtSlot(int, int, int)
  260. def slot_handleParameterMidiCcChangedCallback(self, pluginId, index, cc):
  261. if pluginId >= self.fPluginCount:
  262. return
  263. pitem = self.fPluginList[pluginId]
  264. if pitem is None:
  265. return
  266. pitem.widget.setParameterMidiControl(index, cc)
  267. @pyqtSlot(int, int, int)
  268. def slot_handleParameterMidiChannelChangedCallback(self, pluginId, index, channel):
  269. if pluginId >= self.fPluginCount:
  270. return
  271. pitem = self.fPluginList[pluginId]
  272. if pitem is None:
  273. return
  274. pitem.widget.setParameterMidiChannel(index, channel)
  275. # -----------------------------------------------------------------
  276. @pyqtSlot(int, int)
  277. def slot_handleProgramChangedCallback(self, pluginId, index):
  278. if pluginId >= self.fPluginCount:
  279. return
  280. pitem = self.fPluginList[pluginId]
  281. if pitem is None:
  282. return
  283. pitem.widget.setProgram(index)
  284. @pyqtSlot(int, int)
  285. def slot_handleMidiProgramChangedCallback(self, pluginId, index):
  286. if pluginId >= self.fPluginCount:
  287. return
  288. pitem = self.fPluginList[pluginId]
  289. if pitem is None:
  290. return
  291. pitem.widget.setMidiProgram(index)
  292. # -----------------------------------------------------------------
  293. @pyqtSlot(int, int)
  294. def slot_handleUiStateChangedCallback(self, pluginId, state):
  295. if pluginId >= self.fPluginCount:
  296. return
  297. pitem = self.fPluginList[pluginId]
  298. if pitem is None:
  299. return
  300. pitem.widget.customUiStateChanged(state)
  301. # -----------------------------------------------------------------
  302. @pyqtSlot(int, int, int, int)
  303. def slot_handleNoteOnCallback(self, pluginId, channel, note, velo):
  304. if pluginId >= self.fPluginCount:
  305. return
  306. pitem = self.fPluginList[pluginId]
  307. if pitem is None:
  308. return
  309. pitem.widget.sendNoteOn(channel, note)
  310. @pyqtSlot(int, int, int)
  311. def slot_handleNoteOffCallback(self, pluginId, channel, note):
  312. if pluginId >= self.fPluginCount:
  313. return
  314. pitem = self.fPluginList[pluginId]
  315. if pitem is None:
  316. return
  317. pitem.widget.sendNoteOff(channel, note)
  318. # -----------------------------------------------------------------
  319. @pyqtSlot(int)
  320. def slot_handleUpdateCallback(self, pluginId):
  321. if pluginId >= self.fPluginCount:
  322. return
  323. pitem = self.fPluginList[pluginId]
  324. if pitem is None:
  325. return
  326. pitem.widget.fEditDialog.updateInfo()
  327. @pyqtSlot(int)
  328. def slot_handleReloadInfoCallback(self, pluginId):
  329. if pluginId >= self.fPluginCount:
  330. return
  331. pitem = self.fPluginList[pluginId]
  332. if pitem is None:
  333. return
  334. pitem.widget.fEditDialog.reloadInfo()
  335. @pyqtSlot(int)
  336. def slot_handleReloadParametersCallback(self, pluginId):
  337. if pluginId >= self.fPluginCount:
  338. return
  339. pitem = self.fPluginList[pluginId]
  340. if pitem is None:
  341. return
  342. pitem.widget.fEditDialog.reloadParameters()
  343. @pyqtSlot(int)
  344. def slot_handleReloadProgramsCallback(self, pluginId):
  345. if pluginId >= self.fPluginCount:
  346. return
  347. pitem = self.fPluginList[pluginId]
  348. if pitem is None:
  349. return
  350. pitem.widget.fEditDialog.reloadPrograms()
  351. @pyqtSlot(int)
  352. def slot_handleReloadAllCallback(self, pluginId):
  353. if pluginId >= self.fPluginCount:
  354. return
  355. pitem = self.fPluginList[pluginId]
  356. if pitem is None:
  357. return
  358. pitem.widget.fEditDialog.reloadAll()
  359. # -----------------------------------------------------------------