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.

365 lines
14KB

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