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.

372 lines
15KB

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