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.

carla 12KB

11 years ago
11 years ago
11 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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 resizeEvent(self, event):
  117. QTabWidget.resizeEvent(self, event)
  118. if self.currentIndex() == 0:
  119. self.fixCanvasPreviewSize()
  120. # ------------------------------------------------------------------------------------------------------------
  121. # Main Window
  122. class CarlaHostW(HostWindow):
  123. def __init__(self, parent=None):
  124. HostWindow.__init__(self, parent)
  125. # -------------------------------------------------------------
  126. # Set-up container
  127. self.fContainer = CarlaMultiW(self)
  128. self.setupContainer(True, self.fContainer.fPatchbay.themeData)
  129. # -------------------------------------------------------------
  130. # Set-up GUI stuff
  131. self.fInfoText = ""
  132. self.fInfoLabel = QLabel(self)
  133. self.fInfoLabel.setAlignment(Qt.AlignRight|Qt.AlignVCenter)
  134. self.fInfoLabel.setText("Engine stopped")
  135. if MACOS and False: # TODO: check if NOT using pro theme
  136. self.fInfoLabel.hide()
  137. self.setUnifiedTitleAndToolBarOnMac(True)
  138. # -------------------------------------------------------------
  139. self.ui.act_settings_show_toolbar.triggered.connect(self.slot_toolbarShown)
  140. self.ui.splitter.splitterMoved.connect(self.slot_splitterMoved)
  141. QTimer.singleShot(0, self.slot_initWidgets)
  142. # -----------------------------------------------------------------
  143. def engineStopped(self):
  144. self.fInfoText = ""
  145. self.fInfoLabel.setText("Engine stopped")
  146. def engineChanged(self):
  147. self.fInfoText = "Engine running | SampleRate: %g | BufferSize: %i" % (Carla.sampleRate, Carla.bufferSize)
  148. self.fInfoLabel.setText("%s | %s" % (self.fInfoText, self.fTextTransport))
  149. # -----------------------------------------------------------------
  150. def updateInfoLabelXandSize(self):
  151. tabBar = self.fContainer.tabBar()
  152. x = tabBar.width() + self.ui.tabUtils.width() + 20
  153. self.fInfoLabel.move(x, self.fInfoLabel.y())
  154. self.fInfoLabel.resize(self.fContainer.width()-tabBar.width()-20, self.fInfoLabel.height())
  155. def updateInfoLabelY(self):
  156. tabBar = self.fContainer.tabBar()
  157. y = tabBar.mapFromParent(self.ui.centralwidget.pos()).y()
  158. if not self.ui.toolBar.isVisible():
  159. y -= self.ui.toolBar.height()
  160. self.fInfoLabel.move(self.fInfoLabel.x(), y)
  161. # -----------------------------------------------------------------
  162. @pyqtSlot()
  163. def slot_initWidgets(self):
  164. tabBar = self.fContainer.tabBar()
  165. x = tabBar.width() + self.ui.tabUtils.width() + 20
  166. y = tabBar.mapFromParent(self.ui.centralwidget.pos()).y()
  167. self.fInfoLabel.move(x, y)
  168. self.fInfoLabel.resize(self.fContainer.width()-tabBar.width()-20, tabBar.height())
  169. # FIXME: Qt4 needs this so it properly creates & resizes the canvas
  170. self.fContainer.setCurrentIndex(1)
  171. self.fContainer.setCurrentIndex(0)
  172. self.fContainer.fixCanvasPreviewSize()
  173. @pyqtSlot()
  174. def slot_splitterMoved(self):
  175. self.updateInfoLabelXandSize()
  176. @pyqtSlot()
  177. def slot_toolbarShown(self):
  178. self.updateInfoLabelY()
  179. # -----------------------------------------------------------------
  180. def resizeEvent(self, event):
  181. HostWindow.resizeEvent(self, event)
  182. self.updateInfoLabelXandSize()
  183. def timerEvent(self, event):
  184. HostWindow.timerEvent(self, event)
  185. if event.timerId() == self.fIdleTimerFast:
  186. self.fInfoLabel.setText("%s | %s" % (self.fInfoText, self.fTextTransport))
  187. # ------------------------------------------------------------------------------------------------------------
  188. # Main
  189. if __name__ == '__main__':
  190. # -------------------------------------------------------------
  191. # App initialization
  192. app = CarlaApplication()
  193. # -------------------------------------------------------------
  194. # Set-up custom signal handling
  195. setUpSignals()
  196. # -------------------------------------------------------------
  197. # Read CLI args
  198. appName = os.path.basename(__file__) if ("__file__" in dir() and os.path.dirname(__file__) in PATH) else sys.argv[0]
  199. libPrefix = None
  200. projectFilename = None
  201. argv = app.arguments()
  202. argc = len(argv)
  203. for i in range(argc):
  204. if i == 0: continue
  205. argument = argv[i]
  206. if argument.startswith("--with-appname="):
  207. appName = os.path.basename(argument.replace("--with-appname=", ""))
  208. elif argument.startswith("--with-libprefix="):
  209. libPrefix = argument.replace("--with-libprefix=", "")
  210. elif os.path.exists(argument):
  211. projectFilename = argument
  212. if libPrefix is not None:
  213. app.addLibraryPath(os.path.join(libPrefix, "lib", "carla"))
  214. # -------------------------------------------------------------
  215. # Init host backend
  216. Carla.isControl = False
  217. Carla.isLocal = True
  218. Carla.isPlugin = False
  219. initHost(appName, libPrefix)
  220. # -------------------------------------------------------------
  221. # Create GUI
  222. Carla.gui = CarlaHostW()
  223. # -------------------------------------------------------------
  224. # Load project file if set
  225. if projectFilename is not None:
  226. Carla.gui.loadProjectLater(projectFilename)
  227. # -------------------------------------------------------------
  228. # Show GUI
  229. Carla.gui.show()
  230. # -------------------------------------------------------------
  231. # App-Loop
  232. sys.exit(app.exec_())