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.

360 lines
14KB

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