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.

383 lines
10KB

  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. try:
  20. from PyQt5.QtCore import QSize, QTimer
  21. from PyQt5.QtWidgets import QApplication, QListWidget, QListWidgetItem
  22. except:
  23. from PyQt4.QtCore import QSize, QTimer
  24. from PyQt4.QtGui import QApplication, QListWidget, QListWidgetItem
  25. # ------------------------------------------------------------------------------------------------------------
  26. # Imports (Custom Stuff)
  27. from carla_widgets import *
  28. # ------------------------------------------------------------------------------------------------------------
  29. # Rack widget item
  30. class CarlaRackItem(QListWidgetItem):
  31. RackItemType = QListWidgetItem.UserType + 1
  32. StaticHeight = 32
  33. def __init__(self, parent, pluginId):
  34. QListWidgetItem.__init__(self, parent, self.RackItemType)
  35. self.fWidget = PluginWidget(parent, pluginId)
  36. self.fWidget.setFixedHeight(self.StaticHeight)
  37. self.setSizeHint(QSize(300, self.StaticHeight))
  38. parent.setItemWidget(self, self.fWidget)
  39. # -----------------------------------------------------------------
  40. def close(self):
  41. self.fWidget.ui.edit_dialog.close()
  42. def setId(self, idx):
  43. self.fWidget.setId(idx)
  44. # ------------------------------------------------------------------------------------------------------------
  45. # Rack widget
  46. class CarlaRackW(QListWidget):
  47. def __init__(self, parent):
  48. QListWidget.__init__(self, parent)
  49. # -------------------------------------------------------------
  50. # Internal stuff
  51. self.fPluginCount = 0
  52. self.fPluginList = []
  53. # -------------------------------------------------------------
  54. # Set-up GUI stuff
  55. #self.setMnimumWidth(800)
  56. self.setSortingEnabled(False)
  57. app = QApplication.instance()
  58. pal1 = app.palette().base().color()
  59. pal2 = app.palette().button().color()
  60. col1 = "stop:0 rgb(%i, %i, %i)" % (pal1.red(), pal1.green(), pal1.blue())
  61. col2 = "stop:1 rgb(%i, %i, %i)" % (pal2.red(), pal2.green(), pal2.blue())
  62. self.setStyleSheet("""
  63. QListWidget {
  64. background-color: qlineargradient(spread:pad,
  65. x1:0.0, y1:0.0,
  66. x2:0.2, y2:1.0,
  67. %s,
  68. %s
  69. );
  70. }
  71. """ % (col1, col2))
  72. # -----------------------------------------------------------------
  73. def getPluginCount(self):
  74. return self.fPluginCount
  75. def getPlugin(self, pluginId):
  76. if pluginId >= self.fPluginCount:
  77. return None
  78. pitem = self.fPluginList[pluginId]
  79. if pitem is None:
  80. return None
  81. return pitem
  82. # -----------------------------------------------------------------
  83. def addPlugin(self, pluginId, isProjectLoading):
  84. pitem = CarlaRackItem(self, pluginId)
  85. self.fPluginList.append(pitem)
  86. self.fPluginCount += 1
  87. if not isProjectLoading:
  88. pitem.fWidget.setActive(True, True, True)
  89. def removePlugin(self, pluginId):
  90. if pluginId >= self.fPluginCount:
  91. return
  92. pitem = self.fPluginList[pluginId]
  93. if pitem is None:
  94. return
  95. self.fPluginCount -= 1
  96. self.fPluginList.pop(pluginId)
  97. self.takeItem(pluginId)
  98. pitem.close()
  99. del pitem
  100. # push all plugins 1 slot back
  101. for i in range(pluginId, self.fPluginCount):
  102. self.fPluginList[i].setId(i)
  103. def renamePlugin(self, pluginId, newName):
  104. if pluginId >= self.fPluginCount:
  105. return
  106. pitem = self.fPluginList[pluginId]
  107. if pitem is None:
  108. return
  109. pitem.fWidget.ui.label_name.setText(name)
  110. pitem.fWidget.ui.edit_dialog.setName(name)
  111. def removeAllPlugins(self):
  112. while (self.takeItem(0)):
  113. pass
  114. for i in range(self.fPluginCount):
  115. pitem = self.fPluginList[i]
  116. if pitem is None:
  117. break
  118. pitem.close()
  119. del pitem
  120. self.fPluginCount = 0
  121. self.fPluginList = []
  122. # -----------------------------------------------------------------
  123. def setParameterValue(self, pluginId, index, value):
  124. if pluginId >= self.fPluginCount:
  125. return
  126. pitem = self.fPluginList[pluginId]
  127. if pitem is None:
  128. return
  129. pitem.fWidget.setParameterValue(index, value)
  130. def setParameterDefault(self, pluginId, index, value):
  131. if pluginId >= self.fPluginCount:
  132. return
  133. pitem = self.fPluginList[pluginId]
  134. if pitem is None:
  135. return
  136. pitem.fWidget.setParameterDefault(index, value)
  137. def setParameterMidiChannel(self, pluginId, index, channel):
  138. if pluginId >= self.fPluginCount:
  139. return
  140. pitem = self.fPluginList[pluginId]
  141. if pitem is None:
  142. return
  143. pitem.fWidget.setParameterMidiChannel(index, channel)
  144. def setParameterMidiCC(self, pluginId, index, cc):
  145. if pluginId >= self.fPluginCount:
  146. return
  147. pitem = self.fPluginList[pluginId]
  148. if pitem is None:
  149. return
  150. pitem.fWidget.setParameterMidiControl(index, cc)
  151. # -----------------------------------------------------------------
  152. def setProgram(self, pluginId, index):
  153. if pluginId >= self.fPluginCount:
  154. return
  155. pitem = self.fPluginList[pluginId]
  156. if pitem is None:
  157. return
  158. pitem.fWidget.setProgram(index)
  159. def setMidiProgram(self, pluginId, index):
  160. if pluginId >= self.fPluginCount:
  161. return
  162. pitem = self.fPluginList[pluginId]
  163. if pitem is None:
  164. return
  165. pitem.fWidget.setMidiProgram(index)
  166. # -----------------------------------------------------------------
  167. def noteOn(self, pluginId, channel, note, velocity):
  168. if pluginId >= self.fPluginCount:
  169. return
  170. pitem = self.fPluginList[pluginId]
  171. if pitem is None:
  172. return
  173. pitem.fWidget.sendNoteOn(channel, note)
  174. def noteOff(self, pluginId, channel, note):
  175. if pluginId >= self.fPluginCount:
  176. return
  177. pitem = self.fPluginList[pluginId]
  178. if pitem is None:
  179. return
  180. pitem.fWidget.sendNoteOff(channel, note)
  181. # -----------------------------------------------------------------
  182. def setGuiState(self, pluginId, state):
  183. if pluginId >= self.fPluginCount:
  184. return
  185. pitem = self.fPluginList[pluginId]
  186. if pitem is None:
  187. return
  188. if state == 0:
  189. pitem.fWidget.ui.b_gui.setChecked(False)
  190. pitem.fWidget.ui.b_gui.setEnabled(True)
  191. elif state == 1:
  192. pitem.fWidget.ui.b_gui.setChecked(True)
  193. pitem.fWidget.ui.b_gui.setEnabled(True)
  194. elif state == -1:
  195. pitem.fWidget.ui.b_gui.setChecked(False)
  196. pitem.fWidget.ui.b_gui.setEnabled(False)
  197. # -----------------------------------------------------------------
  198. def updateInfo(self, pluginId):
  199. if pluginId >= self.fPluginCount:
  200. return
  201. pitem = self.fPluginList[pluginId]
  202. if pitem is None:
  203. return
  204. pitem.ui.edit_dialog.updateInfo()
  205. def reloadInfo(self, pluginId):
  206. if pluginId >= self.fPluginCount:
  207. return
  208. pitem = self.fPluginList[pluginId]
  209. if pitem is None:
  210. return
  211. pitem.ui.edit_dialog.reloadInfo()
  212. def reloadParameters(self, pluginId):
  213. if pluginId >= self.fPluginCount:
  214. return
  215. pitem = self.fPluginList[pluginId]
  216. if pitem is None:
  217. return
  218. pitem.ui.edit_dialog.reloadParameters()
  219. def reloadPrograms(self, pluginId):
  220. if pluginId >= self.fPluginCount:
  221. return
  222. pitem = self.fPluginList[pluginId]
  223. if pitem is None:
  224. return
  225. pitem.ui.edit_dialog.reloadPrograms()
  226. def reloadAll(self, pluginId):
  227. if pluginId >= self.fPluginCount:
  228. return
  229. pitem = self.fPluginList[pluginId]
  230. if pitem is None:
  231. return
  232. pitem.ui.edit_dialog.reloadAll()
  233. # -----------------------------------------------------------------
  234. def patchbayClientAdded(self, clientId, clientIcon, clientName):
  235. pass
  236. def patchbayClientRemoved(self, clientId, clientName):
  237. pass
  238. def patchbayClientRenamed(self, clientId, newClientName):
  239. pass
  240. def patchbayPortAdded(self, clientId, portId, portFlags, portName):
  241. pass
  242. def patchbayPortRemoved(self, groupId, portId, fullPortName):
  243. pass
  244. def patchbayPortRenamed(self, groupId, portId, newPortName):
  245. pass
  246. def patchbayConnectionAdded(self, connectionId, portOutId, portInId):
  247. pass
  248. def patchbayConnectionRemoved(self, connectionId):
  249. pass
  250. def patchbayIconChanged(self, clientId, clientIcon):
  251. pass
  252. # -----------------------------------------------------------------
  253. def idleFast(self):
  254. for i in range(self.fPluginCount):
  255. pitem = self.fPluginList[i]
  256. if pitem is None:
  257. break
  258. pitem.fWidget.idleFast()
  259. def idleSlow(self):
  260. for i in range(self.fPluginCount):
  261. pitem = self.fPluginList[i]
  262. if pitem is None:
  263. break
  264. pitem.fWidget.idleSlow()
  265. # ------------------------------------------------------------------------------------------------------------
  266. # TESTING
  267. #from PyQt5.QtWidgets import QApplication
  268. #app = QApplication(sys.argv)
  269. #gui = CarlaRackW(None)
  270. #gui.show()
  271. #app.exec_()