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.

176 lines
5.8KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Carla rack widget code
  4. # Copyright (C) 2011-2014 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 (Config)
  19. from carla_config import *
  20. # ------------------------------------------------------------------------------------------------------------
  21. # Imports (Global)
  22. if config_UseQt5:
  23. from PyQt5.QtCore import Qt, QSize, QTimer
  24. from PyQt5.QtGui import QPixmap
  25. from PyQt5.QtWidgets import QAbstractItemView, QApplication, QHBoxLayout, QLabel, QListWidget, QListWidgetItem
  26. else:
  27. from PyQt4.QtCore import Qt, QSize, QTimer
  28. from PyQt4.QtGui import QAbstractItemView, QApplication, QHBoxLayout, QLabel, QListWidget, QListWidgetItem, QPixmap
  29. # ------------------------------------------------------------------------------------------------------------
  30. # Imports (Custom Stuff)
  31. from carla_host import *
  32. from carla_skin import *
  33. # ------------------------------------------------------------------------------------------------------------
  34. # Rack widget list
  35. class CarlaRackList(QListWidget):
  36. def __init__(self, parent, host):
  37. QListWidget.__init__(self, parent)
  38. self.host = host
  39. if False:
  40. # kdevelop likes this :)
  41. host = CarlaHostMeta()
  42. self.host = host
  43. # -------------------------------------------------------------
  44. exts = host.get_supported_file_extensions().split(";")
  45. # plugin files
  46. exts.append("dll")
  47. if MACOS:
  48. exts.append("dylib")
  49. if not WINDOWS:
  50. exts.append("so")
  51. self.fSupportedExtensions = tuple(i.replace("*.","") for i in exts)
  52. self.fWasLastDragValid = False
  53. self.setMinimumWidth(640+20) # required by zita, 591 was old value
  54. self.setSelectionMode(QAbstractItemView.SingleSelection)
  55. self.setSortingEnabled(False)
  56. #self.setSortingEnabled(True)
  57. self.setDragEnabled(True)
  58. self.setDragDropMode(QAbstractItemView.DropOnly)
  59. self.setDropIndicatorShown(True)
  60. self.viewport().setAcceptDrops(True)
  61. self.setFrameShape(QFrame.NoFrame)
  62. self.setFrameShadow(QFrame.Plain)
  63. self.fPixmapL = QPixmap(":/bitmaps/rack_interior_left.png")
  64. self.fPixmapR = QPixmap(":/bitmaps/rack_interior_right.png")
  65. self.fPixmapWidth = self.fPixmapL.width()
  66. def isDragEventValid(self, urls):
  67. for url in urls:
  68. filename = url.toLocalFile()
  69. if os.path.isdir(filename):
  70. if os.path.exists(os.path.join(filename, "manifest.ttl")):
  71. return True
  72. elif os.path.isfile(filename):
  73. if filename.lower().endswith(self.fSupportedExtensions):
  74. return True
  75. return False
  76. def dragEnterEvent(self, event):
  77. if self.isDragEventValid(event.mimeData().urls()):
  78. self.fWasLastDragValid = True
  79. event.acceptProposedAction()
  80. return
  81. self.fWasLastDragValid = False
  82. QListWidget.dragEnterEvent(self, event)
  83. def dragMoveEvent(self, event):
  84. if self.fWasLastDragValid:
  85. event.acceptProposedAction()
  86. tryItem = self.itemAt(event.pos())
  87. if tryItem is not None:
  88. self.setCurrentRow(tryItem.widget.getPluginId())
  89. else:
  90. self.setCurrentRow(-1)
  91. return
  92. QListWidget.dragMoveEvent(self, event)
  93. #def dragLeaveEvent(self, event):
  94. #self.fWasLastDragValid = False
  95. #QListWidget.dragLeaveEvent(self, event)
  96. def dropEvent(self, event):
  97. event.acceptProposedAction()
  98. urls = event.mimeData().urls()
  99. if len(urls) == 0:
  100. return
  101. tryItem = self.itemAt(event.pos())
  102. if tryItem is not None:
  103. pluginId = tryItem.widget.getPluginId()
  104. self.host.replace_plugin(pluginId)
  105. for url in urls:
  106. filename = url.toLocalFile()
  107. if not self.host.load_file(filename):
  108. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"),
  109. self.tr("Failed to load file"),
  110. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  111. if tryItem is not None:
  112. self.host.replace_plugin(self.parent().fPluginCount)
  113. #tryItem.widget.setActive(True, True, True)
  114. def mousePressEvent(self, event):
  115. if self.itemAt(event.pos()) is None:
  116. event.accept()
  117. self.setCurrentRow(-1)
  118. return
  119. QListWidget.mousePressEvent(self, event)
  120. def paintEvent(self, event):
  121. painter = QPainter(self.viewport())
  122. painter.drawTiledPixmap(0, 0, self.fPixmapWidth, self.height(), self.fPixmapL)
  123. painter.drawTiledPixmap(self.width()-self.fPixmapWidth-2, 0, self.fPixmapWidth, self.height(), self.fPixmapR)
  124. QListWidget.paintEvent(self, event)
  125. # ------------------------------------------------------------------------------------------------------------
  126. # Rack widget
  127. class CarlaRackW(QFrame):
  128. #class CarlaRackW(QFrame, HostWidgetMeta, metaclass=PyQtMetaClass):
  129. def __init__(self, parent, host, doSetup = True):
  130. QFrame.__init__(self, parent)
  131. self.host = host