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.

405 lines
16KB

  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):
  37. QTabWidget.__init__(self, parent)
  38. self.fRack = CarlaRackW(parent, False)
  39. self.fPatchbay = CarlaPatchbayW(parent, False, False)
  40. self.fParent = parent
  41. self.fUseCustomPaint = False
  42. self.addTab(self.fRack, "Plugins")
  43. self.addTab(self.fPatchbay, "Patchbay")
  44. #self.fPatchbay.hide()
  45. #self.removeTab(1)
  46. #self.fPatchbay.setParent(None)
  47. #self.fPatchbay.show()
  48. self.scene = self.fPatchbay.scene
  49. parent.ui.act_plugins_enable.triggered.connect(self.fRack.slot_pluginsEnable)
  50. parent.ui.act_plugins_disable.triggered.connect(self.fRack.slot_pluginsDisable)
  51. parent.ui.act_plugins_volume100.triggered.connect(self.fRack.slot_pluginsVolume100)
  52. parent.ui.act_plugins_mute.triggered.connect(self.fRack.slot_pluginsMute)
  53. parent.ui.act_plugins_wet100.triggered.connect(self.fRack.slot_pluginsWet100)
  54. parent.ui.act_plugins_bypass.triggered.connect(self.fRack.slot_pluginsBypass)
  55. parent.ui.act_plugins_center.triggered.connect(self.fRack.slot_pluginsCenter)
  56. parent.ui.act_plugins_panic.triggered.connect(self.fRack.slot_pluginsDisable)
  57. parent.ui.act_canvas_show_internal.triggered.connect(self.fPatchbay.slot_canvasShowInternal)
  58. parent.ui.act_canvas_show_external.triggered.connect(self.fPatchbay.slot_canvasShowExternal)
  59. parent.ui.act_canvas_arrange.setEnabled(False) # TODO, later
  60. parent.ui.act_canvas_arrange.triggered.connect(self.fPatchbay.slot_canvasArrange)
  61. parent.ui.act_canvas_refresh.triggered.connect(self.fPatchbay.slot_canvasRefresh)
  62. parent.ui.act_canvas_zoom_fit.triggered.connect(self.fPatchbay.slot_canvasZoomFit)
  63. parent.ui.act_canvas_zoom_in.triggered.connect(self.fPatchbay.slot_canvasZoomIn)
  64. parent.ui.act_canvas_zoom_out.triggered.connect(self.fPatchbay.slot_canvasZoomOut)
  65. parent.ui.act_canvas_zoom_100.triggered.connect(self.fPatchbay.slot_canvasZoomReset)
  66. parent.ui.act_canvas_print.triggered.connect(self.fPatchbay.slot_canvasPrint)
  67. parent.ui.act_canvas_save_image.triggered.connect(self.fPatchbay.slot_canvasSaveImage)
  68. parent.ui.act_settings_configure.triggered.connect(self.fPatchbay.slot_configureCarla)
  69. parent.ParameterValueChangedCallback.connect(self.fRack.slot_handleParameterValueChangedCallback)
  70. parent.ParameterValueChangedCallback.connect(self.fPatchbay.slot_handleParameterValueChangedCallback)
  71. parent.ParameterDefaultChangedCallback.connect(self.fRack.slot_handleParameterDefaultChangedCallback)
  72. parent.ParameterMidiChannelChangedCallback.connect(self.fRack.slot_handleParameterMidiChannelChangedCallback)
  73. parent.ParameterMidiCcChangedCallback.connect(self.fRack.slot_handleParameterMidiCcChangedCallback)
  74. parent.ProgramChangedCallback.connect(self.fRack.slot_handleProgramChangedCallback)
  75. parent.MidiProgramChangedCallback.connect(self.fRack.slot_handleMidiProgramChangedCallback)
  76. parent.OptionChangedCallback.connect(self.fRack.slot_handleOptionChangedCallback)
  77. parent.UiStateChangedCallback.connect(self.fRack.slot_handleUiStateChangedCallback)
  78. parent.NoteOnCallback.connect(self.fRack.slot_handleNoteOnCallback)
  79. parent.NoteOnCallback.connect(self.fPatchbay.slot_handleNoteOnCallback)
  80. parent.NoteOffCallback.connect(self.fRack.slot_handleNoteOffCallback)
  81. parent.NoteOffCallback.connect(self.fPatchbay.slot_handleNoteOffCallback)
  82. parent.UpdateCallback.connect(self.fRack.slot_handleUpdateCallback)
  83. parent.ReloadInfoCallback.connect(self.fRack.slot_handleReloadInfoCallback)
  84. parent.ReloadParametersCallback.connect(self.fRack.slot_handleReloadParametersCallback)
  85. parent.ReloadParametersCallback.connect(self.fPatchbay.slot_handleReloadParametersCallback)
  86. parent.ReloadProgramsCallback.connect(self.fRack.slot_handleReloadProgramsCallback)
  87. parent.ReloadAllCallback.connect(self.fRack.slot_handleReloadAllCallback)
  88. parent.ReloadAllCallback.connect(self.fPatchbay.slot_handleReloadAllCallback)
  89. parent.PatchbayClientAddedCallback.connect(self.fPatchbay.slot_handlePatchbayClientAddedCallback)
  90. parent.PatchbayClientRemovedCallback.connect(self.fPatchbay.slot_handlePatchbayClientRemovedCallback)
  91. parent.PatchbayClientRenamedCallback.connect(self.fPatchbay.slot_handlePatchbayClientRenamedCallback)
  92. parent.PatchbayClientDataChangedCallback.connect(self.fPatchbay.slot_handlePatchbayClientDataChangedCallback)
  93. parent.PatchbayPortAddedCallback.connect(self.fPatchbay.slot_handlePatchbayPortAddedCallback)
  94. parent.PatchbayPortRemovedCallback.connect(self.fPatchbay.slot_handlePatchbayPortRemovedCallback)
  95. parent.PatchbayPortRenamedCallback.connect(self.fPatchbay.slot_handlePatchbayPortRenamedCallback)
  96. parent.PatchbayConnectionAddedCallback.connect(self.fPatchbay.slot_handlePatchbayConnectionAddedCallback)
  97. parent.PatchbayConnectionRemovedCallback.connect(self.fPatchbay.slot_handlePatchbayConnectionRemovedCallback)
  98. # -----------------------------------------------------------------
  99. def getPluginCount(self):
  100. return self.fRack.getPluginCount()
  101. # -----------------------------------------------------------------
  102. def addPlugin(self, pluginId, isProjectLoading):
  103. self.fRack.addPlugin(pluginId, isProjectLoading)
  104. self.fPatchbay.addPlugin(pluginId, isProjectLoading)
  105. def removePlugin(self, pluginId):
  106. self.fRack.removePlugin(pluginId)
  107. self.fPatchbay.removePlugin(pluginId)
  108. def renamePlugin(self, pluginId, newName):
  109. self.fRack.renamePlugin(pluginId, newName)
  110. def disablePlugin(self, pluginId, errorMsg):
  111. self.fRack.disablePlugin(pluginId, errorMsg)
  112. def removeAllPlugins(self):
  113. self.fRack.removeAllPlugins()
  114. self.fPatchbay.removeAllPlugins()
  115. # -----------------------------------------------------------------
  116. def engineStarted(self):
  117. #self.fRack.engineStarted()
  118. #self.fPatchbay.engineStarted()
  119. self.fParent.engineChanged()
  120. def engineStopped(self):
  121. #self.fRack.engineStopped()
  122. self.fPatchbay.engineStopped()
  123. self.fParent.engineStopped()
  124. def engineChanged(self):
  125. self.fParent.engineChanged()
  126. # -----------------------------------------------------------------
  127. def idleFast(self):
  128. self.fRack.idleFast()
  129. self.fPatchbay.idleFast()
  130. def idleSlow(self):
  131. self.fRack.idleSlow()
  132. self.fPatchbay.idleSlow()
  133. # -----------------------------------------------------------------
  134. def projectLoadingStarted(self):
  135. self.fRack.projectLoadingStarted()
  136. #self.fPatchbay.projectLoadingStarted()
  137. def projectLoadingFinished(self):
  138. self.fRack.projectLoadingFinished()
  139. self.fPatchbay.projectLoadingFinished()
  140. # -----------------------------------------------------------------
  141. def saveSettings(self, settings):
  142. self.fPatchbay.saveSettings(settings)
  143. def showEditDialog(self, pluginId):
  144. self.fRack.showEditDialog(pluginId)
  145. # -----------------------------------------------------------------
  146. def fixCanvasPreviewSize(self):
  147. self.fPatchbay.resize(self.fRack.size())
  148. self.fPatchbay.slot_miniCanvasCheckSize()
  149. def setUseCustomPaint(self, useCustomPaint):
  150. if self.fUseCustomPaint != useCustomPaint:
  151. self.fUseCustomPaint = useCustomPaint
  152. self.update()
  153. def paintEvent(self, event):
  154. QTabWidget.paintEvent(self, event)
  155. if MACOS or not self.fUseCustomPaint:
  156. return
  157. painter = QPainter(self)
  158. painter.setBrush(QColor(36, 36, 36))
  159. painter.setPen(QColor(62, 62, 62))
  160. painter.drawRect(1, self.height()/2, self.width()-3, self.height()-self.height()/2-1)
  161. def resizeEvent(self, event):
  162. QTabWidget.resizeEvent(self, event)
  163. if self.currentIndex() == 0:
  164. self.fixCanvasPreviewSize()
  165. # ------------------------------------------------------------------------------------------------------------
  166. # Main Window
  167. class CarlaHostW(HostWindow):
  168. def __init__(self, parent=None):
  169. HostWindow.__init__(self, parent)
  170. # -------------------------------------------------------------
  171. # Set-up container
  172. self.fContainer = CarlaMultiW(self)
  173. self.setupContainer(True, self.fContainer.fPatchbay.themeData)
  174. self.fContainer.setUseCustomPaint(self.fSavedSettings[CARLA_KEY_CUSTOM_PAINTING])
  175. # -------------------------------------------------------------
  176. # Set-up GUI stuff
  177. self.fInfoText = ""
  178. self.fInfoLabel = QLabel(self)
  179. self.fInfoLabel.setAlignment(Qt.AlignRight|Qt.AlignVCenter)
  180. self.fInfoLabel.setText("Engine stopped")
  181. self.fDockLocation = Qt.LeftDockWidgetArea
  182. self.fDockFloating = 0
  183. if MACOS and False: # TODO: check if NOT using pro theme
  184. self.fInfoLabel.hide()
  185. self.setUnifiedTitleAndToolBarOnMac(True)
  186. # -------------------------------------------------------------
  187. self.ui.act_settings_show_toolbar.triggered.connect(self.slot_toolbarShown)
  188. self.ui.dockWidget.dockLocationChanged.connect(self.slot_dockLocationChanged)
  189. self.ui.dockWidget.topLevelChanged.connect(self.slot_dockTopLevelChanged)
  190. self.ui.dockWidget.installEventFilter(self)
  191. self.ui.dockWidgetTitleBar = QWidget(self)
  192. self.ui.dockWidget.setTitleBarWidget(self.ui.dockWidgetTitleBar)
  193. QTimer.singleShot(0, self.slot_initWidgets)
  194. # -----------------------------------------------------------------
  195. def engineStopped(self):
  196. self.fInfoText = ""
  197. self.fInfoLabel.setText("Engine stopped")
  198. def engineChanged(self):
  199. self.fInfoText = "Engine running | SampleRate: %g | BufferSize: %i" % (gCarla.sampleRate, gCarla.bufferSize)
  200. self.fInfoLabel.setText("%s | %s" % (self.fInfoText, self.fTextTransport))
  201. # -----------------------------------------------------------------
  202. def updateInfoLabelXandSize(self):
  203. tabBar = self.fContainer.tabBar()
  204. x = tabBar.width() + 20
  205. width = self.fContainer.width() - tabBar.width() - 20
  206. if self.fDockLocation == Qt.LeftDockWidgetArea and self.fDockFloating <= 1:
  207. x += self.ui.dockWidget.width()
  208. self.fInfoLabel.move(x, self.fInfoLabel.y())
  209. self.fInfoLabel.resize(width, self.fInfoLabel.height())
  210. if self.fDockFloating == 1:
  211. self.fDockFloating = 2
  212. def updateInfoLabelY(self):
  213. tabBar = self.fContainer.tabBar()
  214. y = tabBar.mapFromParent(self.ui.centralwidget.pos()).y()
  215. if not self.ui.toolBar.isVisible():
  216. y -= self.ui.toolBar.height()
  217. self.fInfoLabel.move(self.fInfoLabel.x(), y)
  218. # -----------------------------------------------------------------
  219. @pyqtSlot()
  220. def slot_initWidgets(self):
  221. tabBar = self.fContainer.tabBar()
  222. x = tabBar.width() + 20
  223. y = tabBar.mapFromParent(self.ui.centralwidget.pos()).y()
  224. if self.fDockLocation == Qt.LeftDockWidgetArea and self.fDockFloating <= 1:
  225. x += self.ui.tabUtils.width()
  226. self.fInfoLabel.move(x, y)
  227. self.fInfoLabel.resize(self.fContainer.width()-tabBar.width()-20, tabBar.height())
  228. # FIXME: Qt4 needs this so it properly creates & resizes the canvas
  229. self.fContainer.setCurrentIndex(1)
  230. self.fContainer.setCurrentIndex(0)
  231. self.fContainer.fixCanvasPreviewSize()
  232. @pyqtSlot(bool)
  233. def slot_dockTopLevelChanged(self, top):
  234. self.fDockFloating = 1 if top else 0
  235. self.updateInfoLabelXandSize()
  236. @pyqtSlot(Qt.DockWidgetArea)
  237. def slot_dockLocationChanged(self, area):
  238. self.fDockLocation = area
  239. self.updateInfoLabelXandSize()
  240. @pyqtSlot()
  241. def slot_toolbarShown(self):
  242. self.updateInfoLabelY()
  243. # -----------------------------------------------------------------
  244. def eventFilter(self, obj, event):
  245. if obj == self.ui.dockWidget and event.type() == QEvent.Resize:
  246. self.updateInfoLabelXandSize()
  247. return HostWindow.eventFilter(self, obj, event)
  248. def resizeEvent(self, event):
  249. HostWindow.resizeEvent(self, event)
  250. self.updateInfoLabelXandSize()
  251. def timerEvent(self, event):
  252. HostWindow.timerEvent(self, event)
  253. if event.timerId() == self.fIdleTimerFast:
  254. self.fInfoLabel.setText("%s | %s" % (self.fInfoText, self.fTextTransport))
  255. # ------------------------------------------------------------------------------------------------------------
  256. # Main
  257. if __name__ == '__main__':
  258. # -------------------------------------------------------------
  259. # Read CLI args
  260. initName = os.path.basename(__file__) if ("__file__" in dir() and os.path.dirname(__file__) in PATH) else sys.argv[0]
  261. libPrefix = None
  262. for arg in sys.argv:
  263. if arg.startswith("--with-appname="):
  264. initName = os.path.basename(arg.replace("--with-initname=", ""))
  265. elif arg.startswith("--with-libprefix="):
  266. libPrefix = arg.replace("--with-libprefix=", "")
  267. # -------------------------------------------------------------
  268. # App initialization
  269. app = CarlaApplication("Carla2", libPrefix)
  270. # -------------------------------------------------------------
  271. # Set-up custom signal handling
  272. setUpSignals()
  273. # -------------------------------------------------------------
  274. # Init host backend
  275. gCarla.isControl = False
  276. gCarla.isLocal = True
  277. gCarla.isPlugin = False
  278. initHost(initName, libPrefix)
  279. # -------------------------------------------------------------
  280. # Create GUI
  281. gCarla.gui = CarlaHostW()
  282. # -------------------------------------------------------------
  283. # Load project file if set
  284. args = app.arguments()
  285. if len(args) > 1:
  286. arg = args[-1]
  287. if arg.startswith("--with-appname=") or arg.startswith("--with-libprefix="):
  288. pass
  289. elif os.path.exists(arg):
  290. gCarla.gui.loadProjectLater(arg)
  291. # -------------------------------------------------------------
  292. # Show GUI
  293. gCarla.gui.show()
  294. # -------------------------------------------------------------
  295. # App-Loop
  296. app.exit_exec()