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.

352 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)
  94. def removeAllPlugins(self):
  95. self.fRack.removeAllPlugins()
  96. # -----------------------------------------------------------------
  97. def engineStarted(self):
  98. #self.fRack.engineStarted()
  99. #self.fPatchbay.engineStarted()
  100. self.fParent.engineChanged()
  101. def engineStopped(self):
  102. #self.fRack.engineStopped()
  103. self.fPatchbay.engineStopped()
  104. self.fParent.engineStopped()
  105. def engineChanged(self):
  106. self.fParent.engineChanged()
  107. # -----------------------------------------------------------------
  108. def idleFast(self):
  109. self.fRack.idleFast()
  110. self.fPatchbay.idleFast()
  111. def idleSlow(self):
  112. self.fRack.idleSlow()
  113. # -----------------------------------------------------------------
  114. def projectLoaded(self):
  115. self.fPatchbay.projectLoaded()
  116. def saveSettings(self, settings):
  117. self.fPatchbay.saveSettings(settings)
  118. def showEditDialog(self, pluginId):
  119. self.fRack.showEditDialog(pluginId)
  120. # -----------------------------------------------------------------
  121. def fixCanvasPreviewSize(self):
  122. self.fPatchbay.resize(self.fRack.size())
  123. self.fPatchbay.slot_miniCanvasCheckSize()
  124. def setUseCustomPaint(self, useCustomPaint):
  125. if self.fUseCustomPaint != useCustomPaint:
  126. self.fUseCustomPaint = useCustomPaint
  127. self.update()
  128. def paintEvent(self, event):
  129. QTabWidget.paintEvent(self, event)
  130. if not self.fUseCustomPaint:
  131. return
  132. painter = QPainter(self)
  133. painter.setBrush(QColor(36, 36, 36))
  134. painter.setPen(QColor(62, 62, 62))
  135. painter.drawRect(1, self.height()/2, self.width()-3, self.height()-self.height()/2-1)
  136. def resizeEvent(self, event):
  137. QTabWidget.resizeEvent(self, event)
  138. if self.currentIndex() == 0:
  139. self.fixCanvasPreviewSize()
  140. # ------------------------------------------------------------------------------------------------------------
  141. # Main Window
  142. class CarlaHostW(HostWindow):
  143. def __init__(self, parent=None):
  144. HostWindow.__init__(self, parent)
  145. # -------------------------------------------------------------
  146. # Set-up container
  147. self.fContainer = CarlaMultiW(self)
  148. self.setupContainer(True, self.fContainer.fPatchbay.themeData)
  149. self.fContainer.setUseCustomPaint(self.fSavedSettings[CARLA_KEY_CUSTOM_PAINTING])
  150. # -------------------------------------------------------------
  151. # Set-up GUI stuff
  152. self.fInfoText = ""
  153. self.fInfoLabel = QLabel(self)
  154. self.fInfoLabel.setAlignment(Qt.AlignRight|Qt.AlignVCenter)
  155. self.fInfoLabel.setText("Engine stopped")
  156. if MACOS and False: # TODO: check if NOT using pro theme
  157. self.fInfoLabel.hide()
  158. self.setUnifiedTitleAndToolBarOnMac(True)
  159. # -------------------------------------------------------------
  160. self.ui.act_settings_show_toolbar.triggered.connect(self.slot_toolbarShown)
  161. self.ui.splitter.splitterMoved.connect(self.slot_splitterMoved)
  162. QTimer.singleShot(0, self.slot_initWidgets)
  163. # -----------------------------------------------------------------
  164. def engineStopped(self):
  165. self.fInfoText = ""
  166. self.fInfoLabel.setText("Engine stopped")
  167. def engineChanged(self):
  168. self.fInfoText = "Engine running | SampleRate: %g | BufferSize: %i" % (Carla.sampleRate, Carla.bufferSize)
  169. self.fInfoLabel.setText("%s | %s" % (self.fInfoText, self.fTextTransport))
  170. # -----------------------------------------------------------------
  171. def updateInfoLabelXandSize(self):
  172. tabBar = self.fContainer.tabBar()
  173. x = tabBar.width() + self.ui.tabUtils.width() + 20
  174. self.fInfoLabel.move(x, self.fInfoLabel.y())
  175. self.fInfoLabel.resize(self.fContainer.width()-tabBar.width()-20, self.fInfoLabel.height())
  176. def updateInfoLabelY(self):
  177. tabBar = self.fContainer.tabBar()
  178. y = tabBar.mapFromParent(self.ui.centralwidget.pos()).y()
  179. if not self.ui.toolBar.isVisible():
  180. y -= self.ui.toolBar.height()
  181. self.fInfoLabel.move(self.fInfoLabel.x(), y)
  182. # -----------------------------------------------------------------
  183. @pyqtSlot()
  184. def slot_initWidgets(self):
  185. tabBar = self.fContainer.tabBar()
  186. x = tabBar.width() + self.ui.tabUtils.width() + 20
  187. y = tabBar.mapFromParent(self.ui.centralwidget.pos()).y()
  188. self.fInfoLabel.move(x, y)
  189. self.fInfoLabel.resize(self.fContainer.width()-tabBar.width()-20, tabBar.height())
  190. # FIXME: Qt4 needs this so it properly creates & resizes the canvas
  191. self.fContainer.setCurrentIndex(1)
  192. self.fContainer.setCurrentIndex(0)
  193. self.fContainer.fixCanvasPreviewSize()
  194. @pyqtSlot()
  195. def slot_splitterMoved(self):
  196. self.updateInfoLabelXandSize()
  197. @pyqtSlot()
  198. def slot_toolbarShown(self):
  199. self.updateInfoLabelY()
  200. # -----------------------------------------------------------------
  201. def resizeEvent(self, event):
  202. HostWindow.resizeEvent(self, event)
  203. self.updateInfoLabelXandSize()
  204. def timerEvent(self, event):
  205. HostWindow.timerEvent(self, event)
  206. if event.timerId() == self.fIdleTimerFast:
  207. self.fInfoLabel.setText("%s | %s" % (self.fInfoText, self.fTextTransport))
  208. # ------------------------------------------------------------------------------------------------------------
  209. # Main
  210. if __name__ == '__main__':
  211. # -------------------------------------------------------------
  212. # App initialization
  213. app = CarlaApplication()
  214. # -------------------------------------------------------------
  215. # Set-up custom signal handling
  216. setUpSignals()
  217. # -------------------------------------------------------------
  218. # Read CLI args
  219. appName = os.path.basename(__file__) if ("__file__" in dir() and os.path.dirname(__file__) in PATH) else sys.argv[0]
  220. libPrefix = None
  221. projectFilename = None
  222. argv = app.arguments()
  223. argc = len(argv)
  224. for i in range(argc):
  225. if i == 0: continue
  226. argument = argv[i]
  227. if argument.startswith("--with-appname="):
  228. appName = os.path.basename(argument.replace("--with-appname=", ""))
  229. elif argument.startswith("--with-libprefix="):
  230. libPrefix = argument.replace("--with-libprefix=", "")
  231. elif os.path.exists(argument):
  232. projectFilename = argument
  233. if libPrefix is not None:
  234. app.addLibraryPath(os.path.join(libPrefix, "lib", "carla"))
  235. # -------------------------------------------------------------
  236. # Init host backend
  237. Carla.isControl = False
  238. Carla.isLocal = True
  239. Carla.isPlugin = False
  240. initHost(appName, libPrefix)
  241. # -------------------------------------------------------------
  242. # Create GUI
  243. Carla.gui = CarlaHostW()
  244. # set our gui as parent for all plugins UIs
  245. Carla.host.set_engine_option(ENGINE_OPTION_FRONTEND_WIN_ID, 0, str(Carla.gui.winId()))
  246. # -------------------------------------------------------------
  247. # Load project file if set
  248. if projectFilename is not None:
  249. Carla.gui.loadProjectLater(projectFilename)
  250. # -------------------------------------------------------------
  251. # Show GUI
  252. Carla.gui.show()
  253. # -------------------------------------------------------------
  254. # App-Loop
  255. sys.exit(app.exec_())