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.

184 lines
5.1KB

  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. def close(self):
  40. self.fWidget.ui.edit_dialog.close()
  41. def getWidget(self):
  42. return self.fWidget
  43. def setId(self, idx):
  44. self.fWidget.setId(idx)
  45. # ------------------------------------------------------------------------------------------------------------
  46. # Rack widget
  47. class CarlaRackW(QListWidget):
  48. def __init__(self, parent):
  49. QListWidget.__init__(self, parent)
  50. # -------------------------------------------------------------
  51. # Internal stuff
  52. self.fPluginCount = 0
  53. self.fPluginList = []
  54. # -------------------------------------------------------------
  55. # Set-up GUI stuff
  56. self.setFixedWidth(800)
  57. self.setSortingEnabled(False)
  58. app = QApplication.instance()
  59. pal1 = app.palette().base().color()
  60. pal2 = app.palette().button().color()
  61. col1 = "stop:0 rgb(%i, %i, %i)" % (pal1.red(), pal1.green(), pal1.blue())
  62. col2 = "stop:1 rgb(%i, %i, %i)" % (pal2.red(), pal2.green(), pal2.blue())
  63. self.setStyleSheet("""
  64. QListWidget {
  65. background-color: qlineargradient(spread:pad,
  66. x1:0.0, y1:0.0,
  67. x2:0.2, y2:1.0,
  68. %s,
  69. %s
  70. );
  71. }
  72. """ % (col1, col2))
  73. # -------------------------------------------------------------
  74. # TESTING
  75. #self.addPlugin(0)
  76. #self.addPlugin(1)
  77. #self.addPlugin(2)
  78. #self.addPlugin(3)
  79. #self.addPlugin(4)
  80. #self.removePlugin(3)
  81. #QTimer.singleShot(3000, self.testRemove)
  82. #QTimer.singleShot(5000, self.removeAllPlugins)
  83. def testRemove(self):
  84. self.removePlugin(0)
  85. def idleFast(self):
  86. for i in range(self.fPluginCount):
  87. pitem = self.fPluginList[i]
  88. if pitem is None:
  89. break
  90. pitem.fWidget.idleFast()
  91. def idleSlow(self):
  92. for i in range(self.fPluginCount):
  93. pitem = self.fPluginList[i]
  94. if pitem is None:
  95. break
  96. pitem.fWidget.idleSlow()
  97. def addPlugin(self, pluginId):
  98. pitem = CarlaRackItem(self, pluginId)
  99. self.fPluginList.append(pitem)
  100. self.fPluginCount += 1
  101. #if not self.fProjectLoading:
  102. #pwidget.setActive(True, True, True)
  103. def removePlugin(self, pluginId):
  104. if pluginId >= self.fPluginCount:
  105. return
  106. pitem = self.fPluginList[pluginId]
  107. if pitem is None:
  108. return
  109. self.fPluginCount -= 1
  110. self.fPluginList.pop(pluginId)
  111. self.takeItem(pluginId)
  112. pitem.close()
  113. del pitem
  114. # push all plugins 1 slot back
  115. for i in range(pluginId, self.fPluginCount):
  116. self.fPluginList[i].setId(i)
  117. def removeAllPlugins(self):
  118. while (self.takeItem(0)):
  119. pass
  120. for i in range(self.fPluginCount):
  121. pitem = self.fPluginList[i]
  122. if pitem is None:
  123. break
  124. pitem.close()
  125. del pitem
  126. self.fPluginCount = 0
  127. self.fPluginList = []
  128. # ------------------------------------------------------------------------------------------------------------
  129. # TESTING
  130. #from PyQt5.QtWidgets import QApplication
  131. #app = QApplication(sys.argv)
  132. #gui = CarlaRackW(None)
  133. #gui.show()
  134. #app.exec_()