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.

carla 12KB

10 years ago
10 years ago
10 years ago
11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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. def fixCanvasPreviewSize(self):
  108. self.fPatchbay.resize(self.fRack.size())
  109. self.fPatchbay.slot_miniCanvasCheckSize()
  110. # -----------------------------------------------------------------
  111. def paintEvent(self, event):
  112. QTabWidget.paintEvent(self, event)
  113. if MACOS or not self.fUseCustomPaint:
  114. return
  115. painter = QPainter(self)
  116. painter.setBrush(QColor(36, 36, 36))
  117. painter.setPen(QColor(62, 62, 62))
  118. painter.drawRect(1, self.height()/2, self.width()-3, self.height()-self.height()/2-1)
  119. def resizeEvent(self, event):
  120. QTabWidget.resizeEvent(self, event)
  121. if self.currentIndex() == 0:
  122. self.fixCanvasPreviewSize()
  123. # ------------------------------------------------------------------------------------------------------------
  124. # Main Window
  125. class CarlaHostW(HostWindow):
  126. def __init__(self, host):
  127. HostWindow.__init__(self, host)
  128. # -------------------------------------------------------------
  129. # Set-up container
  130. self.fContainer = CarlaMultiW(self, host)
  131. self.setupContainer(True, self.fContainer.fPatchbay.themeData)
  132. # -------------------------------------------------------------
  133. # Set-up GUI stuff
  134. self.fInfoText = ""
  135. self.fInfoLabel = QLabel(self)
  136. self.fInfoLabel.setAlignment(Qt.AlignRight|Qt.AlignVCenter)
  137. self.fInfoLabel.setText("Engine stopped")
  138. self.fDockLocation = Qt.LeftDockWidgetArea
  139. self.fDockFloating = 0
  140. if MACOS and False: # TODO: check if NOT using pro theme
  141. self.fInfoLabel.hide()
  142. self.setUnifiedTitleAndToolBarOnMac(True)
  143. # -------------------------------------------------------------
  144. self.ui.act_settings_show_toolbar.triggered.connect(self.slot_toolbarShown)
  145. self.ui.dockWidget.dockLocationChanged.connect(self.slot_dockLocationChanged)
  146. self.ui.dockWidget.topLevelChanged.connect(self.slot_dockTopLevelChanged)
  147. self.ui.dockWidget.installEventFilter(self)
  148. QTimer.singleShot(0, self.slot_initWidgets)
  149. # -----------------------------------------------------------------
  150. def engineChanged(self):
  151. self.fInfoText = "Engine running | SampleRate: %g | BufferSize: %i" % (self.host.get_sample_rate(), self.host.get_buffer_size())
  152. self.fInfoLabel.setText("%s | %s" % (self.fInfoText, self.fTextTransport))
  153. def engineStarted(self):
  154. self.engineChanged()
  155. def engineStopped(self):
  156. self.fInfoText = ""
  157. self.fInfoLabel.setText("Engine stopped")
  158. # -----------------------------------------------------------------
  159. def updateInfoLabelXandSize(self):
  160. tabBar = self.fContainer.tabBar()
  161. x = tabBar.width() + 20
  162. width = self.fContainer.width() - tabBar.width() - 20
  163. if self.fDockLocation == Qt.LeftDockWidgetArea and self.fDockFloating <= 1:
  164. x += self.ui.dockWidget.width()
  165. self.fInfoLabel.move(x, self.fInfoLabel.y())
  166. self.fInfoLabel.resize(width, self.fInfoLabel.height())
  167. if self.fDockFloating == 1:
  168. self.fDockFloating = 2
  169. def updateInfoLabelY(self):
  170. tabBar = self.fContainer.tabBar()
  171. y = tabBar.mapFromParent(self.ui.centralwidget.pos()).y()
  172. if not self.ui.toolBar.isVisible():
  173. y -= self.ui.toolBar.height()
  174. self.fInfoLabel.move(self.fInfoLabel.x(), y)
  175. # -----------------------------------------------------------------
  176. @pyqtSlot()
  177. def slot_initWidgets(self):
  178. tabBar = self.fContainer.tabBar()
  179. x = tabBar.width() + 20
  180. y = tabBar.mapFromParent(self.ui.centralwidget.pos()).y()
  181. if self.fDockLocation == Qt.LeftDockWidgetArea and self.fDockFloating <= 1:
  182. x += self.ui.tabUtils.width()
  183. self.fInfoLabel.move(x, y)
  184. self.fInfoLabel.resize(self.fContainer.width()-tabBar.width()-20, tabBar.height())
  185. # FIXME: Qt4 needs this so it properly creates & resizes the canvas
  186. self.fContainer.setCurrentIndex(1)
  187. self.fContainer.setCurrentIndex(0)
  188. self.fContainer.fixCanvasPreviewSize()
  189. @pyqtSlot(bool)
  190. def slot_dockTopLevelChanged(self, top):
  191. self.fDockFloating = 1 if top else 0
  192. self.updateInfoLabelXandSize()
  193. @pyqtSlot(Qt.DockWidgetArea)
  194. def slot_dockLocationChanged(self, area):
  195. self.fDockLocation = area
  196. self.updateInfoLabelXandSize()
  197. @pyqtSlot()
  198. def slot_toolbarShown(self):
  199. self.updateInfoLabelY()
  200. # -----------------------------------------------------------------
  201. def eventFilter(self, obj, event):
  202. if obj == self.ui.dockWidget and event.type() == QEvent.Resize:
  203. self.updateInfoLabelXandSize()
  204. return HostWindow.eventFilter(self, obj, event)
  205. #def closeEvent(self, event):
  206. #HostWindow.closeEvent(self, event)
  207. ## needed if using separate patchbay window
  208. #QApplication.instance().quit()
  209. def resizeEvent(self, event):
  210. HostWindow.resizeEvent(self, event)
  211. self.updateInfoLabelXandSize()
  212. def timerEvent(self, event):
  213. HostWindow.timerEvent(self, event)
  214. if event.timerId() == self.fIdleTimerFast:
  215. self.fInfoLabel.setText("%s | %s" % (self.fInfoText, self.fTextTransport))
  216. # ------------------------------------------------------------------------------------------------------------
  217. # Main
  218. if __name__ == '__main__':
  219. # -------------------------------------------------------------
  220. # Read CLI args
  221. initName = os.path.basename(__file__) if ("__file__" in dir() and os.path.dirname(__file__) in PATH) else sys.argv[0]
  222. libPrefix = None
  223. for arg in sys.argv:
  224. if arg.startswith("--with-appname="):
  225. initName = os.path.basename(arg.replace("--with-initname=", ""))
  226. elif arg.startswith("--with-libprefix="):
  227. libPrefix = arg.replace("--with-libprefix=", "")
  228. # -------------------------------------------------------------
  229. # App initialization
  230. app = CarlaApplication("Carla2", libPrefix)
  231. # -------------------------------------------------------------
  232. # Set-up custom signal handling
  233. setUpSignals()
  234. # -------------------------------------------------------------
  235. # Init host backend
  236. host = initHost(initName, libPrefix, False, False, True)
  237. loadHostSettings(host)
  238. # -------------------------------------------------------------
  239. # Create GUI
  240. gui = CarlaHostW(host)
  241. # -------------------------------------------------------------
  242. # Load project file if set
  243. args = app.arguments()
  244. if len(args) > 1:
  245. arg = args[-1]
  246. if arg.startswith("--with-appname=") or arg.startswith("--with-libprefix="):
  247. pass
  248. elif os.path.exists(arg):
  249. gui.loadProjectLater(arg)
  250. # -------------------------------------------------------------
  251. # Show GUI
  252. gui.show()
  253. # -------------------------------------------------------------
  254. # App-Loop
  255. app.exit_exec()