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.

344 lines
12KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Carla plugin host
  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 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 QEvent
  24. from PyQt5.QtWidgets import QLabel, QTabWidget
  25. else:
  26. from PyQt4.QtCore import QEvent
  27. from PyQt4.QtGui import QLabel, QTabWidget
  28. # ------------------------------------------------------------------------------------------------------------
  29. # Imports (Custom Stuff)
  30. from carla_host import *
  31. from carla_patchbay import CarlaPatchbayW
  32. from carla_rack import CarlaRackW
  33. # ------------------------------------------------------------------------------------------------------------
  34. # Tab widget (rack + patchbay)
  35. class CarlaMultiW(QTabWidget):
  36. def __init__(self, parent, host):
  37. QTabWidget.__init__(self, parent)
  38. if False:
  39. # kdevelop likes this :)
  40. host = CarlaHostMeta()
  41. self.host = host
  42. # -------------------------------------------------------------
  43. self.fRack = CarlaRackW(parent, host, False)
  44. self.fPatchbay = CarlaPatchbayW(parent, host, False, False)
  45. self.fParent = parent
  46. self.fUseCustomPaint = parent.getSavedSettings()[CARLA_KEY_CUSTOM_PAINTING]
  47. self.addTab(self.fRack, "Plugins")
  48. self.addTab(self.fPatchbay, "Patchbay")
  49. #self.fPatchbay.hide()
  50. #self.removeTab(1)
  51. #self.fPatchbay.setParent(None)
  52. #self.fPatchbay.setWindowTitle(parent.windowTitle())
  53. #self.fPatchbay.show()
  54. #self.scene = self.fPatchbay.scene
  55. parent.ui.act_plugins_enable.triggered.connect(self.fRack.slot_pluginsEnable)
  56. parent.ui.act_plugins_disable.triggered.connect(self.fRack.slot_pluginsDisable)
  57. parent.ui.act_plugins_volume100.triggered.connect(self.fRack.slot_pluginsVolume100)
  58. parent.ui.act_plugins_mute.triggered.connect(self.fRack.slot_pluginsMute)
  59. parent.ui.act_plugins_wet100.triggered.connect(self.fRack.slot_pluginsWet100)
  60. parent.ui.act_plugins_bypass.triggered.connect(self.fRack.slot_pluginsBypass)
  61. parent.ui.act_plugins_center.triggered.connect(self.fRack.slot_pluginsCenter)
  62. parent.ui.act_plugins_panic.triggered.connect(self.fRack.slot_pluginsDisable)
  63. parent.ui.act_canvas_show_internal.triggered.connect(self.fPatchbay.slot_canvasShowInternal)
  64. parent.ui.act_canvas_show_external.triggered.connect(self.fPatchbay.slot_canvasShowExternal)
  65. parent.ui.act_canvas_arrange.triggered.connect(self.fPatchbay.slot_canvasArrange)
  66. parent.ui.act_canvas_refresh.triggered.connect(self.fPatchbay.slot_canvasRefresh)
  67. parent.ui.act_canvas_zoom_fit.triggered.connect(self.fPatchbay.slot_canvasZoomFit)
  68. parent.ui.act_canvas_zoom_in.triggered.connect(self.fPatchbay.slot_canvasZoomIn)
  69. parent.ui.act_canvas_zoom_out.triggered.connect(self.fPatchbay.slot_canvasZoomOut)
  70. parent.ui.act_canvas_zoom_100.triggered.connect(self.fPatchbay.slot_canvasZoomReset)
  71. parent.ui.act_canvas_print.triggered.connect(self.fPatchbay.slot_canvasPrint)
  72. parent.ui.act_canvas_save_image.triggered.connect(self.fPatchbay.slot_canvasSaveImage)
  73. # TODO, later
  74. parent.ui.act_canvas_arrange.setEnabled(False)
  75. parent.ui.act_settings_configure.triggered.connect(self.fPatchbay.slot_configureCarla)
  76. # -----------------------------------------------------------------
  77. # HostWidgetMeta methods
  78. def removeAllPlugins(self):
  79. self.fRack.removeAllPlugins()
  80. self.fPatchbay.removeAllPlugins()
  81. def engineStarted(self):
  82. self.fRack.engineStarted()
  83. self.fPatchbay.engineStarted()
  84. self.fParent.engineStarted()
  85. def engineStopped(self):
  86. self.fRack.engineStopped()
  87. self.fPatchbay.engineStopped()
  88. self.fParent.engineStopped()
  89. def idleFast(self):
  90. self.fRack.idleFast()
  91. self.fPatchbay.idleFast()
  92. def idleSlow(self):
  93. self.fRack.idleSlow()
  94. self.fPatchbay.idleSlow()
  95. def projectLoadingStarted(self):
  96. self.fRack.projectLoadingStarted()
  97. self.fPatchbay.projectLoadingStarted()
  98. def projectLoadingFinished(self):
  99. self.fRack.projectLoadingFinished()
  100. self.fPatchbay.projectLoadingFinished()
  101. def saveSettings(self, settings):
  102. self.fRack.saveSettings(settings)
  103. self.fPatchbay.saveSettings(settings)
  104. def showEditDialog(self, pluginId):
  105. self.fRack.showEditDialog(pluginId)
  106. # -----------------------------------------------------------------
  107. # -----------------------------------------------------------------
  108. def paintEvent(self, event):
  109. QTabWidget.paintEvent(self, event)
  110. if MACOS or not self.fUseCustomPaint:
  111. return
  112. painter = QPainter(self)
  113. painter.setBrush(QColor(36, 36, 36))
  114. painter.setPen(QColor(62, 62, 62))
  115. painter.drawRect(1, self.height()/2, self.width()-3, self.height()-self.height()/2-1)
  116. def resizeEvent(self, event):
  117. QTabWidget.resizeEvent(self, event)
  118. if self.currentIndex() == 0:
  119. self.fixCanvasPreviewSize()
  120. # ------------------------------------------------------------------------------------------------------------
  121. # Main Window
  122. class CarlaHostW(HostWindow):
  123. def __init__(self, host):
  124. HostWindow.__init__(self, host)
  125. # -------------------------------------------------------------
  126. # Set-up container
  127. #self.fContainer = CarlaMultiW(self, host)
  128. #self.setupContainer(False)
  129. # -------------------------------------------------------------
  130. # Set-up GUI stuff
  131. #self.fInfoText = ""
  132. #self.fInfoLabel = QLabel(self)
  133. #self.fInfoLabel.setAlignment(Qt.AlignRight|Qt.AlignVCenter)
  134. #self.fInfoLabel.setText("Engine stopped")
  135. #self.fDockLocation = Qt.LeftDockWidgetArea
  136. #self.fDockFloating = 0
  137. #if MACOS and False: # TODO: check if NOT using pro theme
  138. #self.fInfoLabel.hide()
  139. #self.setUnifiedTitleAndToolBarOnMac(True)
  140. # -------------------------------------------------------------
  141. #self.ui.act_settings_show_toolbar.triggered.connect(self.slot_toolbarShown)
  142. #self.ui.dockWidget.dockLocationChanged.connect(self.slot_dockLocationChanged)
  143. #self.ui.dockWidget.topLevelChanged.connect(self.slot_dockTopLevelChanged)
  144. #self.ui.dockWidget.installEventFilter(self)
  145. #QTimer.singleShot(0, self.slot_initWidgets)
  146. # -----------------------------------------------------------------
  147. #def engineChanged(self):
  148. #self.fInfoText = "Engine running | SampleRate: %g | BufferSize: %i" % (self.host.get_sample_rate(), self.host.get_buffer_size())
  149. #self.fInfoLabel.setText("%s | %s" % (self.fInfoText, self.fTransportText))
  150. #def engineStarted(self):
  151. #self.engineChanged()
  152. #def engineStopped(self):
  153. #self.fInfoText = ""
  154. #self.fInfoLabel.setText("Engine stopped")
  155. # -----------------------------------------------------------------
  156. #def updateInfoLabelXandSize(self):
  157. #tabBar = self.fContainer.tabBar()
  158. #x = tabBar.width() + 20
  159. #width = self.fContainer.width() - tabBar.width() - 20
  160. #if self.fDockLocation == Qt.LeftDockWidgetArea and self.fDockFloating <= 1:
  161. #x += self.ui.dockWidget.width()
  162. #self.fInfoLabel.move(x, self.fInfoLabel.y())
  163. #self.fInfoLabel.resize(width, self.fInfoLabel.height())
  164. #if self.fDockFloating == 1:
  165. #self.fDockFloating = 2
  166. #def updateInfoLabelY(self):
  167. #tabBar = self.fContainer.tabBar()
  168. #y = tabBar.mapFromParent(self.ui.centralwidget.pos()).y()
  169. #if not self.ui.toolBar.isVisible():
  170. #y -= self.ui.toolBar.height()
  171. #self.fInfoLabel.move(self.fInfoLabel.x(), y)
  172. # -----------------------------------------------------------------
  173. #@pyqtSlot()
  174. #def slot_initWidgets(self):
  175. #tabBar = self.fContainer.tabBar()
  176. #x = tabBar.width() + 20
  177. #y = tabBar.mapFromParent(self.ui.centralwidget.pos()).y()
  178. #if self.fDockLocation == Qt.LeftDockWidgetArea and self.fDockFloating <= 1:
  179. #x += self.ui.tabUtils.width()
  180. #self.fInfoLabel.move(x, y)
  181. #self.fInfoLabel.resize(self.fContainer.width()-tabBar.width()-20, tabBar.height())
  182. #@pyqtSlot(bool)
  183. #def slot_dockTopLevelChanged(self, top):
  184. #self.fDockFloating = 1 if top else 0
  185. #self.updateInfoLabelXandSize()
  186. #@pyqtSlot(Qt.DockWidgetArea)
  187. #def slot_dockLocationChanged(self, area):
  188. #self.fDockLocation = area
  189. #self.updateInfoLabelXandSize()
  190. #@pyqtSlot()
  191. #def slot_toolbarShown(self):
  192. #self.updateInfoLabelY()
  193. # -----------------------------------------------------------------
  194. #def eventFilter(self, obj, event):
  195. #if obj == self.ui.dockWidget and event.type() == QEvent.Resize:
  196. #self.updateInfoLabelXandSize()
  197. #return HostWindow.eventFilter(self, obj, event)
  198. #def closeEvent(self, event):
  199. #HostWindow.closeEvent(self, event)
  200. ## needed if using separate patchbay window
  201. #QApplication.instance().quit()
  202. #def resizeEvent(self, event):
  203. #HostWindow.resizeEvent(self, event)
  204. #self.updateInfoLabelXandSize()
  205. #def timerEvent(self, event):
  206. #HostWindow.timerEvent(self, event)
  207. #if event.timerId() == self.fIdleTimerFast:
  208. #self.fInfoLabel.setText("%s | %s" % (self.fInfoText, self.fTransportText))
  209. # ------------------------------------------------------------------------------------------------------------
  210. # Main
  211. if __name__ == '__main__':
  212. # -------------------------------------------------------------
  213. # Read CLI args
  214. initName = os.path.basename(__file__) if ("__file__" in dir() and os.path.dirname(__file__) in PATH) else sys.argv[0]
  215. libPrefix = None
  216. for arg in sys.argv:
  217. if arg.startswith("--with-appname="):
  218. initName = os.path.basename(arg.replace("--with-initname=", ""))
  219. elif arg.startswith("--with-libprefix="):
  220. libPrefix = arg.replace("--with-libprefix=", "")
  221. # -------------------------------------------------------------
  222. # App initialization
  223. app = CarlaApplication("Carla2", libPrefix)
  224. # -------------------------------------------------------------
  225. # Set-up custom signal handling
  226. setUpSignals()
  227. # -------------------------------------------------------------
  228. # Init host backend
  229. host = initHost(initName, libPrefix, False, False, True)
  230. loadHostSettings(host)
  231. # -------------------------------------------------------------
  232. # Create GUI
  233. gui = CarlaHostW(host)
  234. # -------------------------------------------------------------
  235. # Load project file if set
  236. args = app.arguments()
  237. if len(args) > 1:
  238. arg = args[-1]
  239. if arg.startswith("--with-appname=") or arg.startswith("--with-libprefix="):
  240. pass
  241. elif os.path.exists(arg):
  242. gui.loadProjectLater(arg)
  243. # -------------------------------------------------------------
  244. # Show GUI
  245. gui.show()
  246. # -------------------------------------------------------------
  247. # App-Loop
  248. app.exit_exec()