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.

293 lines
11KB

  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. try:
  20. from PyQt5.QtWidgets import QLabel, QTabWidget
  21. except:
  22. from PyQt4.QtGui import QLabel, QTabWidget
  23. # ------------------------------------------------------------------------------------------------------------
  24. # Imports (Custom Stuff)
  25. from carla_host import *
  26. from carla_patchbay import CarlaPatchbayW
  27. from carla_rack import CarlaRackW
  28. # ------------------------------------------------------------------------------------------------------------
  29. # Tab widget (rack + patchbay)
  30. class CarlaMultiW(QTabWidget):
  31. def __init__(self, parent):
  32. QTabWidget.__init__(self, parent)
  33. self.fRack = CarlaRackW(parent, False)
  34. self.fPatchbay = CarlaPatchbayW(parent, False)
  35. self.fParent = parent
  36. self.addTab(self.fRack, "Plugins")
  37. self.addTab(self.fPatchbay, "Patchbay")
  38. self.scene = self.fPatchbay.scene
  39. parent.ui.act_plugins_enable.triggered.connect(self.fRack.slot_pluginsEnable)
  40. parent.ui.act_plugins_disable.triggered.connect(self.fRack.slot_pluginsDisable)
  41. parent.ui.act_plugins_volume100.triggered.connect(self.fRack.slot_pluginsVolume100)
  42. parent.ui.act_plugins_mute.triggered.connect(self.fRack.slot_pluginsMute)
  43. parent.ui.act_plugins_wet100.triggered.connect(self.fRack.slot_pluginsWet100)
  44. parent.ui.act_plugins_bypass.triggered.connect(self.fRack.slot_pluginsBypass)
  45. parent.ui.act_plugins_center.triggered.connect(self.fRack.slot_pluginsCenter)
  46. parent.ui.act_plugins_panic.triggered.connect(self.fRack.slot_pluginsDisable)
  47. parent.ui.act_canvas_arrange.setEnabled(False) # TODO, later
  48. parent.ui.act_canvas_arrange.triggered.connect(self.fPatchbay.slot_canvasArrange)
  49. parent.ui.act_canvas_refresh.triggered.connect(self.fPatchbay.slot_canvasRefresh)
  50. parent.ui.act_canvas_zoom_fit.triggered.connect(self.fPatchbay.slot_canvasZoomFit)
  51. parent.ui.act_canvas_zoom_in.triggered.connect(self.fPatchbay.slot_canvasZoomIn)
  52. parent.ui.act_canvas_zoom_out.triggered.connect(self.fPatchbay.slot_canvasZoomOut)
  53. parent.ui.act_canvas_zoom_100.triggered.connect(self.fPatchbay.slot_canvasZoomReset)
  54. parent.ui.act_canvas_print.triggered.connect(self.fPatchbay.slot_canvasPrint)
  55. parent.ui.act_canvas_save_image.triggered.connect(self.fPatchbay.slot_canvasSaveImage)
  56. parent.ui.act_settings_configure.triggered.connect(self.fPatchbay.slot_configureCarla)
  57. parent.ParameterValueChangedCallback.connect(self.fRack.slot_handleParameterValueChangedCallback)
  58. parent.ParameterDefaultChangedCallback.connect(self.fRack.slot_handleParameterDefaultChangedCallback)
  59. parent.ParameterMidiChannelChangedCallback.connect(self.fRack.slot_handleParameterMidiChannelChangedCallback)
  60. parent.ParameterMidiCcChangedCallback.connect(self.fRack.slot_handleParameterMidiCcChangedCallback)
  61. parent.ProgramChangedCallback.connect(self.fRack.slot_handleProgramChangedCallback)
  62. parent.MidiProgramChangedCallback.connect(self.fRack.slot_handleMidiProgramChangedCallback)
  63. parent.NoteOnCallback.connect(self.fRack.slot_handleNoteOnCallback)
  64. parent.NoteOffCallback.connect(self.fRack.slot_handleNoteOffCallback)
  65. parent.ShowGuiCallback.connect(self.fRack.slot_handleShowGuiCallback)
  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.PatchbayPortAddedCallback.connect(self.fPatchbay.slot_handlePatchbayPortAddedCallback)
  75. parent.PatchbayPortRemovedCallback.connect(self.fPatchbay.slot_handlePatchbayPortRemovedCallback)
  76. parent.PatchbayPortRenamedCallback.connect(self.fPatchbay.slot_handlePatchbayPortRenamedCallback)
  77. parent.PatchbayConnectionAddedCallback.connect(self.fPatchbay.slot_handlePatchbayConnectionAddedCallback)
  78. parent.PatchbayConnectionRemovedCallback.connect(self.fPatchbay.slot_handlePatchbayConnectionRemovedCallback)
  79. parent.PatchbayIconChangedCallback.connect(self.fPatchbay.slot_handlePatchbayIconChangedCallback)
  80. # -----------------------------------------------------------------
  81. def getPluginCount(self):
  82. return self.fRack.getPluginCount()
  83. # -----------------------------------------------------------------
  84. def addPlugin(self, pluginId, isProjectLoading):
  85. self.fRack.addPlugin(pluginId, isProjectLoading)
  86. def removePlugin(self, pluginId):
  87. self.fRack.removePlugin(pluginId)
  88. def renamePlugin(self, pluginId, newName):
  89. self.fRack.renamePlugin(pluginId, newName)
  90. self.fPatchbay.renamePlugin(pluginId, newName)
  91. def removeAllPlugins(self):
  92. self.fRack.removeAllPlugins()
  93. # -----------------------------------------------------------------
  94. def engineStarted(self):
  95. #self.fRack.engineStarted()
  96. #self.fPatchbay.engineStarted()
  97. self.fParent.engineChanged()
  98. def engineStopped(self):
  99. #self.fRack.engineStopped()
  100. self.fPatchbay.engineStopped()
  101. self.fParent.engineStopped()
  102. def engineChanged(self):
  103. self.fParent.engineChanged()
  104. # -----------------------------------------------------------------
  105. def idleFast(self):
  106. self.fRack.idleFast()
  107. def idleSlow(self):
  108. self.fRack.idleSlow()
  109. # -----------------------------------------------------------------
  110. def saveSettings(self, settings):
  111. pass
  112. #self.fRack.saveSettings(settings)
  113. #self.fPatchbay.saveSettings(settings)
  114. # ------------------------------------------------------------------------------------------------------------
  115. # Main Window
  116. class CarlaHostW(HostWindow):
  117. def __init__(self, parent=None):
  118. HostWindow.__init__(self, parent)
  119. # -------------------------------------------------------------
  120. # Set-up container
  121. self.fContainer = CarlaMultiW(self)
  122. self.setupContainer(True)
  123. # -------------------------------------------------------------
  124. # Set-up GUI stuff
  125. self.fInfoText = ""
  126. self.fInfoLabel = QLabel(self)
  127. self.fInfoLabel.setText("Engine stopped")
  128. # -------------------------------------------------------------
  129. self.ui.act_settings_show_toolbar.triggered.connect(self.slot_toolbarShown)
  130. self.ui.splitter.splitterMoved.connect(self.slot_splitterMoved)
  131. QTimer.singleShot(0, self.slot_infoLabelInit)
  132. # -----------------------------------------------------------------
  133. def engineStopped(self):
  134. self.fInfoText = ""
  135. self.fInfoLabel.setText("Engine stopped")
  136. def engineChanged(self):
  137. self.fInfoText = "Engine running | SampleRate: %g | BufferSize: %i" % (self.fSampleRate, self.fBufferSize)
  138. self.fInfoLabel.setText("%s | %s" % (self.fInfoText, self.fTextTransport))
  139. # -----------------------------------------------------------------
  140. def updateInfoLabelPos(self):
  141. tabBar = self.fContainer.tabBar()
  142. y = tabBar.mapFromParent(self.ui.centralwidget.pos()).y() #+tabBar.height()/4
  143. if not self.ui.toolBar.isVisible():
  144. y -= self.ui.toolBar.height()
  145. self.fInfoLabel.move(self.fInfoLabel.x(), y)
  146. def updateInfoLabelSize(self):
  147. tabBar = self.fContainer.tabBar()
  148. self.fInfoLabel.resize(self.fContainer.width()-tabBar.width()-20, self.fInfoLabel.height())
  149. # -----------------------------------------------------------------
  150. @pyqtSlot()
  151. def slot_splitterMoved(self):
  152. self.updateInfoLabelSize()
  153. @pyqtSlot()
  154. def slot_toolbarShown(self):
  155. self.updateInfoLabelPos()
  156. @pyqtSlot()
  157. def slot_infoLabelInit(self):
  158. tabBar = self.fContainer.tabBar()
  159. x = tabBar.width()+20
  160. y = tabBar.mapFromParent(self.ui.centralwidget.pos()).y() #+ tabBar.height()/4
  161. self.fInfoLabel.move(x, y)
  162. self.fInfoLabel.resize(self.fContainer.width()-x, tabBar.height())
  163. # -----------------------------------------------------------------
  164. def resizeEvent(self, event):
  165. self.updateInfoLabelSize()
  166. HostWindow.resizeEvent(self, event)
  167. def timerEvent(self, event):
  168. HostWindow.timerEvent(self, event)
  169. if event.timerId() == self.fIdleTimerFast:
  170. self.fInfoLabel.setText("%s | %s" % (self.fInfoText, self.fTextTransport))
  171. # ------------------------------------------------------------------------------------------------------------
  172. # Main
  173. if __name__ == '__main__':
  174. # -------------------------------------------------------------
  175. # App initialization
  176. app = CarlaApplication()
  177. # -------------------------------------------------------------
  178. # Set-up custom signal handling
  179. setUpSignals()
  180. # -------------------------------------------------------------
  181. # Read CLI args
  182. appName = os.path.basename(__file__) if ("__file__" in dir() and os.path.dirname(__file__) in PATH) else sys.argv[0]
  183. libPrefix = None
  184. projectFilename = None
  185. argv = app.arguments()
  186. argc = len(argv)
  187. for i in range(argc):
  188. if i == 0: continue
  189. argument = argv[i]
  190. if argument.startswith("--with-appname="):
  191. appName = os.path.basename(argument.replace("--with-appname=", ""))
  192. elif argument.startswith("--with-libprefix="):
  193. libPrefix = argument.replace("--with-libprefix=", "")
  194. elif os.path.exists(argument):
  195. projectFilename = argument
  196. # -------------------------------------------------------------
  197. # Init host backend
  198. Carla.isControl = False
  199. Carla.isLocal = True
  200. Carla.isPlugin = False
  201. initHost(appName, libPrefix)
  202. # -------------------------------------------------------------
  203. # Create GUI
  204. Carla.gui = CarlaHostW()
  205. # -------------------------------------------------------------
  206. # Load project file if set
  207. if projectFilename is not None:
  208. Carla.gui.loadProjectLater(projectFilename)
  209. # -------------------------------------------------------------
  210. # Show GUI
  211. Carla.gui.show()
  212. # -------------------------------------------------------------
  213. # App-Loop
  214. sys.exit(app.exec_())