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.

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