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.

343 lines
13KB

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