|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
-
- # Carla patchbay widget code
- # Copyright (C) 2011-2014 Filipe Coelho <falktx@falktx.com>
- #
- # This program is free software; you can redistribute it and/or
- # modify it under the terms of the GNU General Public License as
- # published by the Free Software Foundation; either version 2 of
- # the License, or any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # For a full copy of the GNU General Public License see the doc/GPL.txt file.
-
- # ------------------------------------------------------------------------------------------------------------
- # Imports (Config)
-
- from carla_config import *
-
- # ------------------------------------------------------------------------------------------------------------
- # Imports (Global)
-
- if config_UseQt5:
- from PyQt5.QtCore import QPointF, QTimer
- from PyQt5.QtGui import QImage
- from PyQt5.QtPrintSupport import QPrinter, QPrintDialog
- from PyQt5.QtWidgets import QFrame, QGraphicsView, QGridLayout
- else:
- from PyQt4.QtCore import QPointF, QTimer
- from PyQt4.QtGui import QFrame, QGraphicsView, QGridLayout, QImage, QPrinter, QPrintDialog
-
- # ------------------------------------------------------------------------------------------------------------
- # Imports (Custom Stuff)
-
- import patchcanvas
-
- from carla_widgets import *
- from digitalpeakmeter import DigitalPeakMeter
- from pixmapkeyboard import PixmapKeyboardHArea
-
- # ------------------------------------------------------------------------------------------------------------
- # Try Import OpenGL
-
- try:
- if config_UseQt5:
- from PyQt5.QtOpenGL import QGLWidget
- else:
- from PyQt4.QtOpenGL import QGLWidget
- hasGL = True
- except:
- hasGL = False
-
- # ------------------------------------------------------------------------------------------------------------
- # Carla Canvas defaults
-
- CARLA_DEFAULT_CANVAS_SIZE_WIDTH = 3100
- CARLA_DEFAULT_CANVAS_SIZE_HEIGHT = 2400
-
- # ------------------------------------------------------------------------------------------------
- # Patchbay info class, used in main carla as replacement for PluginEdit
-
- class PluginInfo(object):
- def __init__(self, parent, pluginId):
- object.__init__(self)
-
- self.fPluginId = pluginId
-
- #------------------------------------------------------------------
-
- def setId(self, idx):
- self.fPluginId = idx
-
- #------------------------------------------------------------------
-
- def close(self):
- pass
-
- def setName(self, name):
- pass
-
- def setParameterValue(self, parameterId, value):
- pass
-
- def reloadAll(self):
- pass
-
- def idleSlow(self):
- pass
-
- # ------------------------------------------------------------------------------------------------
- # Patchbay widget
-
- class CarlaPatchbayW(QFrame):
- def __init__(self, parent, doSetup = True, onlyPatchbay = True, is3D = False):
- QFrame.__init__(self, parent)
-
- self.fLayout = QGridLayout(self)
- self.fLayout.setContentsMargins(0, 0, 0, 0)
- self.fLayout.setSpacing(1)
- self.setLayout(self.fLayout)
-
- self.fView = QGraphicsView(self)
- self.fKeys = PixmapKeyboardHArea(self)
-
- self.fPeaksIn = DigitalPeakMeter(self)
- self.fPeaksOut = DigitalPeakMeter(self)
- self.fPeaksCleared = True
-
- self.fPeaksIn.setColor(DigitalPeakMeter.BLUE)
- self.fPeaksIn.setChannels(2)
- self.fPeaksIn.setOrientation(DigitalPeakMeter.VERTICAL)
- self.fPeaksIn.setFixedWidth(25)
-
- self.fPeaksOut.setColor(DigitalPeakMeter.GREEN)
- self.fPeaksOut.setChannels(2)
- self.fPeaksOut.setOrientation(DigitalPeakMeter.VERTICAL)
- self.fPeaksOut.setFixedWidth(25)
-
- self.fLayout.addWidget(self.fPeaksIn, 0, 0)
- self.fLayout.addWidget(self.fView, 0, 1) # self.fViewWidget if is3D else
- self.fLayout.addWidget(self.fPeaksOut, 0, 2)
- self.fLayout.addWidget(self.fKeys, 1, 0, 1, 0)
-
- # -------------------------------------------------------------
- # Internal stuff
-
- self.fParent = parent
- self.fPluginCount = 0
- self.fPluginList = []
-
- self.fIsOnlyPatchbay = onlyPatchbay
- self.fSelectedPlugins = []
-
- self.fCanvasWidth = 0
- self.fCanvasHeight = 0
-
- # -------------------------------------------------------------
- # Set-up Canvas Preview
-
- self.fMiniCanvasPreview = self.fParent.ui.miniCanvasPreview
- self.fMiniCanvasPreview.setRealParent(self)
- self.fMovingViaMiniCanvas = False
-
- # -------------------------------------------------------------
- # Set-up Canvas
-
- self.scene = patchcanvas.PatchScene(self, self.fView)
- self.fView.setScene(self.scene)
- self.fView.setRenderHint(QPainter.Antialiasing, bool(parent.fSavedSettings[CARLA_KEY_CANVAS_ANTIALIASING] == patchcanvas.ANTIALIASING_FULL))
-
- if parent.fSavedSettings[CARLA_KEY_CANVAS_USE_OPENGL] and hasGL: # and not is3D:
- self.fViewWidget = QGLWidget(self)
- self.fView.setViewport(self.fViewWidget)
- self.fView.setRenderHint(QPainter.HighQualityAntialiasing, parent.fSavedSettings[CARLA_KEY_CANVAS_HQ_ANTIALIASING])
-
- self.setupCanvas()
-
- QTimer.singleShot(100, self.slot_restoreScrollbarValues)
-
- # -------------------------------------------------------------
- # Connect actions to functions
-
- parent.ui.act_settings_show_meters.toggled.connect(self.slot_showCanvasMeters)
- parent.ui.act_settings_show_keyboard.toggled.connect(self.slot_showCanvasKeyboard)
-
- self.fView.horizontalScrollBar().valueChanged.connect(self.slot_horizontalScrollBarChanged)
- self.fView.verticalScrollBar().valueChanged.connect(self.slot_verticalScrollBarChanged)
-
- self.scene.scaleChanged.connect(self.slot_canvasScaleChanged)
- self.scene.sceneGroupMoved.connect(self.slot_canvasItemMoved)
- self.scene.pluginSelected.connect(self.slot_canvasPluginSelected)
-
- self.fMiniCanvasPreview.miniCanvasMoved.connect(self.slot_miniCanvasMoved)
-
- self.fKeys.keyboard.noteOn.connect(self.slot_noteOn)
- self.fKeys.keyboard.noteOff.connect(self.slot_noteOff)
-
- # -------------------------------------------------------------
- # Load Settings
-
- settings = QSettings()
-
- showMeters = settings.value("ShowMeters", False, type=bool)
- self.fParent.ui.act_settings_show_meters.setChecked(showMeters)
- self.fPeaksIn.setVisible(showMeters)
- self.fPeaksOut.setVisible(showMeters)
-
- showKeyboard = settings.value("ShowKeyboard", not(MACOS or WINDOWS), type=bool)
- self.fParent.ui.act_settings_show_keyboard.setChecked(showKeyboard)
- self.fKeys.setVisible(showKeyboard)
-
- # -------------------------------------------------------------
- # Connect actions to functions (part 2)
-
- if not doSetup: return
-
- parent.ui.act_plugins_enable.triggered.connect(self.slot_pluginsEnable)
- parent.ui.act_plugins_disable.triggered.connect(self.slot_pluginsDisable)
- parent.ui.act_plugins_volume100.triggered.connect(self.slot_pluginsVolume100)
- parent.ui.act_plugins_mute.triggered.connect(self.slot_pluginsMute)
- parent.ui.act_plugins_wet100.triggered.connect(self.slot_pluginsWet100)
- parent.ui.act_plugins_bypass.triggered.connect(self.slot_pluginsBypass)
- parent.ui.act_plugins_center.triggered.connect(self.slot_pluginsCenter)
- parent.ui.act_plugins_panic.triggered.connect(self.slot_pluginsDisable)
-
- parent.ui.act_canvas_arrange.setEnabled(False) # TODO, later
- parent.ui.act_canvas_arrange.triggered.connect(self.slot_canvasArrange)
- parent.ui.act_canvas_refresh.triggered.connect(self.slot_canvasRefresh)
- parent.ui.act_canvas_zoom_fit.triggered.connect(self.slot_canvasZoomFit)
- parent.ui.act_canvas_zoom_in.triggered.connect(self.slot_canvasZoomIn)
- parent.ui.act_canvas_zoom_out.triggered.connect(self.slot_canvasZoomOut)
- parent.ui.act_canvas_zoom_100.triggered.connect(self.slot_canvasZoomReset)
- parent.ui.act_canvas_print.triggered.connect(self.slot_canvasPrint)
- parent.ui.act_canvas_save_image.triggered.connect(self.slot_canvasSaveImage)
-
- parent.ui.act_settings_configure.triggered.connect(self.slot_configureCarla)
-
- parent.ParameterValueChangedCallback.connect(self.slot_handleParameterValueChangedCallback)
- parent.ParameterDefaultChangedCallback.connect(self.slot_handleParameterDefaultChangedCallback)
- parent.ParameterMidiChannelChangedCallback.connect(self.slot_handleParameterMidiChannelChangedCallback)
- parent.ParameterMidiCcChangedCallback.connect(self.slot_handleParameterMidiCcChangedCallback)
- parent.ProgramChangedCallback.connect(self.slot_handleProgramChangedCallback)
- parent.MidiProgramChangedCallback.connect(self.slot_handleMidiProgramChangedCallback)
- parent.OptionChangedCallback.connect(self.slot_handleOptionChangedCallback)
- parent.NoteOnCallback.connect(self.slot_handleNoteOnCallback)
- parent.NoteOffCallback.connect(self.slot_handleNoteOffCallback)
- parent.UpdateCallback.connect(self.slot_handleUpdateCallback)
- parent.ReloadInfoCallback.connect(self.slot_handleReloadInfoCallback)
- parent.ReloadParametersCallback.connect(self.slot_handleReloadParametersCallback)
- parent.ReloadProgramsCallback.connect(self.slot_handleReloadProgramsCallback)
- parent.ReloadAllCallback.connect(self.slot_handleReloadAllCallback)
- parent.PatchbayClientAddedCallback.connect(self.slot_handlePatchbayClientAddedCallback)
- parent.PatchbayClientRemovedCallback.connect(self.slot_handlePatchbayClientRemovedCallback)
- parent.PatchbayClientRenamedCallback.connect(self.slot_handlePatchbayClientRenamedCallback)
- parent.PatchbayClientDataChangedCallback.connect(self.slot_handlePatchbayClientDataChangedCallback)
- parent.PatchbayPortAddedCallback.connect(self.slot_handlePatchbayPortAddedCallback)
- parent.PatchbayPortRemovedCallback.connect(self.slot_handlePatchbayPortRemovedCallback)
- parent.PatchbayPortRenamedCallback.connect(self.slot_handlePatchbayPortRenamedCallback)
- parent.PatchbayConnectionAddedCallback.connect(self.slot_handlePatchbayConnectionAddedCallback)
- parent.PatchbayConnectionRemovedCallback.connect(self.slot_handlePatchbayConnectionRemovedCallback)
-
- # -----------------------------------------------------------------
-
- def getPluginCount(self):
- return self.fPluginCount
-
- # -----------------------------------------------------------------
-
- def addPlugin(self, pluginId, isProjectLoading):
- if self.fIsOnlyPatchbay:
- pitem = PluginEdit(self, pluginId)
- else:
- pitem = PluginInfo(self, pluginId)
-
- self.fPluginList.append(pitem)
- self.fPluginCount += 1
-
- if self.fIsOnlyPatchbay and not isProjectLoading:
- gCarla.host.set_active(pluginId, True)
-
- def removePlugin(self, pluginId):
- patchcanvas.handlePluginRemoved(pluginId)
-
- if pluginId in self.fSelectedPlugins:
- self.clearSideStuff()
-
- if pluginId >= self.fPluginCount:
- return
-
- pitem = self.fPluginList[pluginId]
- if pitem is None:
- return
-
- self.fPluginCount -= 1
- self.fPluginList.pop(pluginId)
-
- pitem.close()
- del pitem
-
- # push all plugins 1 slot back
- for i in range(pluginId, self.fPluginCount):
- pitem = self.fPluginList[i]
- pitem.setId(i)
-
- def renamePlugin(self, pluginId, newName):
- if pluginId >= self.fPluginCount:
- return
-
- pitem = self.fPluginList[pluginId]
- if pitem is None:
- return
-
- pitem.setName(newName)
-
- def disablePlugin(self, pluginId, errorMsg):
- if pluginId >= self.fPluginCount:
- return
-
- pitem = self.fPluginList[pluginId]
- if pitem is None:
- return
-
- def removeAllPlugins(self):
- for pitem in self.fPluginList:
- if pitem is None:
- break
- pitem.close()
- del pitem
-
- self.fPluginCount = 0
- self.fPluginList = []
-
- self.clearSideStuff()
-
- patchcanvas.handlePluginRemoved(0)
-
- # -----------------------------------------------------------------
-
- def engineStarted(self):
- pass
-
- def engineStopped(self):
- patchcanvas.clear()
-
- def engineChanged(self):
- pass
-
- # -----------------------------------------------------------------
-
- def idleFast(self):
- if self.fPluginCount == 0:
- return
-
- for pluginId in self.fSelectedPlugins:
- self.fPeaksCleared = False
- if self.fPeaksIn.isVisible():
- self.fPeaksIn.displayMeter(1, gCarla.host.get_input_peak_value(pluginId, True))
- self.fPeaksIn.displayMeter(2, gCarla.host.get_input_peak_value(pluginId, False))
- if self.fPeaksOut.isVisible():
- self.fPeaksOut.displayMeter(1, gCarla.host.get_output_peak_value(pluginId, True))
- self.fPeaksOut.displayMeter(2, gCarla.host.get_output_peak_value(pluginId, False))
- return
-
- if self.fPeaksCleared:
- return
-
- self.fPeaksCleared = True
- self.fPeaksIn.displayMeter(1, 0.0, True)
- self.fPeaksIn.displayMeter(2, 0.0, True)
- self.fPeaksOut.displayMeter(1, 0.0, True)
- self.fPeaksOut.displayMeter(2, 0.0, True)
-
- def idleSlow(self):
- for pitem in self.fPluginList:
- if pitem is None:
- break
- pitem.idleSlow()
-
- # -----------------------------------------------------------------
-
- def projectLoadingStarted(self):
- pass
-
- def projectLoadingFinished(self):
- QTimer.singleShot(1000, self.slot_canvasRefresh)
-
- # -----------------------------------------------------------------
-
- def saveSettings(self, settings):
- settings.setValue("ShowMeters", self.fParent.ui.act_settings_show_meters.isChecked())
- settings.setValue("ShowKeyboard", self.fParent.ui.act_settings_show_keyboard.isChecked())
- settings.setValue("HorizontalScrollBarValue", self.fView.horizontalScrollBar().value())
- settings.setValue("VerticalScrollBarValue", self.fView.verticalScrollBar().value())
-
- def showEditDialog(self, pluginId):
- if pluginId >= self.fPluginCount:
- return
-
- pitem = self.fPluginList[pluginId]
- if pitem is None:
- return
-
- pitem.show()
-
- # -----------------------------------------------------------------
- # called by PluginEdit to plugin skin parent, ignored here
-
- def editDialogChanged(self, visible):
- pass
-
- def recheckPluginHints(self, hints):
- pass
-
- def notePressed(self, note):
- pass
-
- def noteReleased(self, note):
- pass
-
- # -----------------------------------------------------------------
-
- def clearSideStuff(self):
- self.scene.clearSelection()
-
- self.fSelectedPlugins = []
-
- self.fKeys.keyboard.allNotesOff(False)
- self.fKeys.setEnabled(False)
-
- self.fPeaksCleared = True
- self.fPeaksIn.displayMeter(1, 0.0, True)
- self.fPeaksIn.displayMeter(2, 0.0, True)
- self.fPeaksOut.displayMeter(1, 0.0, True)
- self.fPeaksOut.displayMeter(2, 0.0, True)
-
- def setupCanvas(self):
- pOptions = patchcanvas.options_t()
- pOptions.theme_name = self.fParent.fSavedSettings[CARLA_KEY_CANVAS_THEME]
- pOptions.auto_hide_groups = self.fParent.fSavedSettings[CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS]
- pOptions.use_bezier_lines = self.fParent.fSavedSettings[CARLA_KEY_CANVAS_USE_BEZIER_LINES]
- pOptions.antialiasing = self.fParent.fSavedSettings[CARLA_KEY_CANVAS_ANTIALIASING]
- pOptions.eyecandy = self.fParent.fSavedSettings[CARLA_KEY_CANVAS_EYE_CANDY]
-
- pFeatures = patchcanvas.features_t()
- pFeatures.group_info = False
- pFeatures.group_rename = False
- pFeatures.port_info = False
- pFeatures.port_rename = False
- pFeatures.handle_group_pos = True
-
- patchcanvas.setOptions(pOptions)
- patchcanvas.setFeatures(pFeatures)
- patchcanvas.init("Carla2", self.scene, canvasCallback, False)
-
- tryCanvasSize = self.fParent.fSavedSettings[CARLA_KEY_CANVAS_SIZE].split("x")
-
- if len(tryCanvasSize) == 2 and tryCanvasSize[0].isdigit() and tryCanvasSize[1].isdigit():
- self.fCanvasWidth = int(tryCanvasSize[0])
- self.fCanvasHeight = int(tryCanvasSize[1])
- else:
- self.fCanvasWidth = CARLA_DEFAULT_CANVAS_SIZE_WIDTH
- self.fCanvasHeight = CARLA_DEFAULT_CANVAS_SIZE_HEIGHT
-
- patchcanvas.setCanvasSize(0, 0, self.fCanvasWidth, self.fCanvasHeight)
- patchcanvas.setInitialPos(self.fCanvasWidth / 2, self.fCanvasHeight / 2)
- self.fView.setSceneRect(0, 0, self.fCanvasWidth, self.fCanvasHeight)
-
- self.themeData = [self.fCanvasWidth, self.fCanvasHeight, patchcanvas.canvas.theme.canvas_bg, patchcanvas.canvas.theme.rubberband_brush, patchcanvas.canvas.theme.rubberband_pen.color()]
-
- def updateCanvasInitialPos(self):
- x = self.fView.horizontalScrollBar().value() + self.width()/4
- y = self.fView.verticalScrollBar().value() + self.height()/4
- patchcanvas.setInitialPos(x, y)
-
- # -----------------------------------------------------------------
-
- @pyqtSlot(bool)
- def slot_showCanvasMeters(self, yesNo):
- self.fPeaksIn.setVisible(yesNo)
- self.fPeaksOut.setVisible(yesNo)
-
- @pyqtSlot(bool)
- def slot_showCanvasKeyboard(self, yesNo):
- self.fKeys.setVisible(yesNo)
-
- # -----------------------------------------------------------------
-
- @pyqtSlot()
- def slot_miniCanvasCheckAll(self):
- self.slot_miniCanvasCheckSize()
- self.slot_horizontalScrollBarChanged(self.fView.horizontalScrollBar().value())
- self.slot_verticalScrollBarChanged(self.fView.verticalScrollBar().value())
-
- @pyqtSlot()
- def slot_miniCanvasCheckSize(self):
- self.fMiniCanvasPreview.setViewSize(float(self.width()) / self.fCanvasWidth, float(self.height()) / self.fCanvasHeight)
-
- @pyqtSlot(int)
- def slot_horizontalScrollBarChanged(self, value):
- if self.fMovingViaMiniCanvas: return
-
- maximum = self.fView.horizontalScrollBar().maximum()
- if maximum == 0:
- xp = 0
- else:
- xp = float(value) / maximum
- self.fMiniCanvasPreview.setViewPosX(xp)
- self.updateCanvasInitialPos()
-
- @pyqtSlot(int)
- def slot_verticalScrollBarChanged(self, value):
- if self.fMovingViaMiniCanvas: return
-
- maximum = self.fView.verticalScrollBar().maximum()
- if maximum == 0:
- yp = 0
- else:
- yp = float(value) / maximum
- self.fMiniCanvasPreview.setViewPosY(yp)
- self.updateCanvasInitialPos()
-
- @pyqtSlot()
- def slot_restoreScrollbarValues(self):
- settings = QSettings()
- self.fView.horizontalScrollBar().setValue(settings.value("HorizontalScrollBarValue", self.fView.horizontalScrollBar().maximum()/2, type=int))
- self.fView.verticalScrollBar().setValue(settings.value("VerticalScrollBarValue", self.fView.verticalScrollBar().maximum()/2, type=int))
-
- # -----------------------------------------------------------------
-
- @pyqtSlot(float)
- def slot_canvasScaleChanged(self, scale):
- self.fMiniCanvasPreview.setViewScale(scale)
-
- @pyqtSlot(int, int, QPointF)
- def slot_canvasItemMoved(self, group_id, split_mode, pos):
- self.fMiniCanvasPreview.update()
-
- @pyqtSlot(list)
- def slot_canvasPluginSelected(self, pluginList):
- self.fKeys.keyboard.allNotesOff(False)
- self.fKeys.setEnabled(len(pluginList) != 0) # and self.fPluginCount > 0
- self.fSelectedPlugins = pluginList
-
- @pyqtSlot(float, float)
- def slot_miniCanvasMoved(self, xp, yp):
- self.fMovingViaMiniCanvas = True
- self.fView.horizontalScrollBar().setValue(xp * self.fView.horizontalScrollBar().maximum())
- self.fView.verticalScrollBar().setValue(yp * self.fView.verticalScrollBar().maximum())
- self.fMovingViaMiniCanvas = False
- self.updateCanvasInitialPos()
-
- # -----------------------------------------------------------------
-
- @pyqtSlot(int)
- def slot_noteOn(self, note):
- for pluginId in self.fSelectedPlugins:
- gCarla.host.send_midi_note(pluginId, 0, note, 100)
-
- @pyqtSlot(int)
- def slot_noteOff(self, note):
- for pluginId in self.fSelectedPlugins:
- gCarla.host.send_midi_note(pluginId, 0, note, 0)
-
- # -----------------------------------------------------------------
-
- @pyqtSlot()
- def slot_pluginsEnable(self):
- if not gCarla.host.is_engine_running():
- return
-
- for i in range(self.fPluginCount):
- gCarla.host.set_active(i, True)
-
- @pyqtSlot()
- def slot_pluginsDisable(self):
- if not gCarla.host.is_engine_running():
- return
-
- for i in range(self.fPluginCount):
- gCarla.host.set_active(i, False)
-
- @pyqtSlot()
- def slot_pluginsVolume100(self):
- if not gCarla.host.is_engine_running():
- return
-
- for i in range(self.fPluginCount):
- pitem = self.fPluginList[i]
- if pitem is None:
- break
-
- if pitem.getHints() & PLUGIN_CAN_VOLUME:
- pitem.setParameterValue(PARAMETER_VOLUME, 1.0)
- gCarla.host.set_volume(i, 1.0)
-
- @pyqtSlot()
- def slot_pluginsMute(self):
- if not gCarla.host.is_engine_running():
- return
-
- for i in range(self.fPluginCount):
- pitem = self.fPluginList[i]
- if pitem is None:
- break
-
- if pitem.getHints() & PLUGIN_CAN_VOLUME:
- pitem.setParameterValue(PARAMETER_VOLUME, 0.0)
- gCarla.host.set_volume(i, 0.0)
-
- @pyqtSlot()
- def slot_pluginsWet100(self):
- if not gCarla.host.is_engine_running():
- return
-
- for i in range(self.fPluginCount):
- pitem = self.fPluginList[i]
- if pitem is None:
- break
-
- if pitem.getHints() & PLUGIN_CAN_DRYWET:
- pitem.setParameterValue(PARAMETER_DRYWET, 1.0)
- gCarla.host.set_drywet(i, 1.0)
-
- @pyqtSlot()
- def slot_pluginsBypass(self):
- if not gCarla.host.is_engine_running():
- return
-
- for i in range(self.fPluginCount):
- pitem = self.fPluginList[i]
- if pitem is None:
- break
-
- if pitem.getHints() & PLUGIN_CAN_DRYWET:
- pitem.setParameterValue(PARAMETER_DRYWET, 0.0)
- gCarla.host.set_drywet(i, 0.0)
-
- @pyqtSlot()
- def slot_pluginsCenter(self):
- if not gCarla.host.is_engine_running():
- return
-
- for i in range(self.fPluginCount):
- pitem = self.fPluginList[i]
- if pitem is None:
- break
-
- if pitem.getHints() & PLUGIN_CAN_BALANCE:
- pitem.setParameterValue(PARAMETER_BALANCE_LEFT, -1.0)
- pitem.setParameterValue(PARAMETER_BALANCE_RIGHT, 1.0)
- gCarla.host.set_balance_left(i, -1.0)
- gCarla.host.set_balance_right(i, 1.0)
-
- if pitem.getHints() & PLUGIN_CAN_PANNING:
- pitem.setParameterValue(PARAMETER_PANNING, 0.0)
- gCarla.host.set_panning(i, 0.0)
-
- # -----------------------------------------------------------------
-
- @pyqtSlot()
- def slot_configureCarla(self):
- if self.fParent is None or not self.fParent.openSettingsWindow(True, hasGL):
- return
-
- self.fParent.loadSettings(False)
-
- patchcanvas.clear()
-
- self.setupCanvas()
- self.fParent.updateContainer(self.themeData)
- self.slot_miniCanvasCheckAll()
-
- if gCarla.host.is_engine_running():
- gCarla.host.patchbay_refresh()
-
- # -----------------------------------------------------------------
-
- @pyqtSlot(int, int, float)
- def slot_handleParameterValueChangedCallback(self, pluginId, index, value):
- if pluginId >= self.fPluginCount:
- return
-
- pitem = self.fPluginList[pluginId]
- if pitem is None:
- return
-
- pitem.setParameterValue(index, value)
-
- @pyqtSlot(int, int, float)
- def slot_handleParameterDefaultChangedCallback(self, pluginId, index, value):
- if pluginId >= self.fPluginCount:
- return
-
- pitem = self.fPluginList[pluginId]
- if pitem is None:
- return
-
- pitem.setParameterDefault(index, value)
-
- @pyqtSlot(int, int, int)
- def slot_handleParameterMidiCcChangedCallback(self, pluginId, index, cc):
- if pluginId >= self.fPluginCount:
- return
-
- pitem = self.fPluginList[pluginId]
- if pitem is None:
- return
-
- pitem.setParameterMidiControl(index, cc)
-
- @pyqtSlot(int, int, int)
- def slot_handleParameterMidiChannelChangedCallback(self, pluginId, index, channel):
- if pluginId >= self.fPluginCount:
- return
-
- pitem = self.fPluginList[pluginId]
- if pitem is None:
- return
-
- pitem.setParameterMidiChannel(index, channel)
-
- # -----------------------------------------------------------------
-
- @pyqtSlot(int, int)
- def slot_handleProgramChangedCallback(self, pluginId, index):
- if pluginId >= self.fPluginCount:
- return
-
- pitem = self.fPluginList[pluginId]
- if pitem is None:
- return
-
- pitem.setProgram(index)
-
- @pyqtSlot(int, int)
- def slot_handleMidiProgramChangedCallback(self, pluginId, index):
- if pluginId >= self.fPluginCount:
- return
-
- pitem = self.fPluginList[pluginId]
- if pitem is None:
- return
-
- pitem.setMidiProgram(index)
-
- # -----------------------------------------------------------------
-
- @pyqtSlot(int, int, bool)
- def slot_handleOptionChangedCallback(self, pluginId, option, yesNo):
- if pluginId >= self.fPluginCount:
- return
-
- pitem = self.fPluginList[pluginId]
- if pitem is None:
- return
-
- pitem.setOption(option, yesNo)
-
- # -----------------------------------------------------------------
-
- @pyqtSlot(int, int, int, int)
- def slot_handleNoteOnCallback(self, pluginId, channel, note, velo):
- if pluginId in self.fSelectedPlugins:
- self.fKeys.keyboard.sendNoteOn(note, False)
-
- if not self.fIsOnlyPatchbay:
- return
- if pluginId >= self.fPluginCount:
- return
-
- pitem = self.fPluginList[pluginId]
- if pitem is None:
- return
-
- pitem.sendNoteOn(channel, note)
-
- @pyqtSlot(int, int, int)
- def slot_handleNoteOffCallback(self, pluginId, channel, note):
- if pluginId in self.fSelectedPlugins:
- self.fKeys.keyboard.sendNoteOff(note, False)
-
- if not self.fIsOnlyPatchbay:
- return
- if pluginId >= self.fPluginCount:
- return
-
- pitem = self.fPluginList[pluginId]
- if pitem is None:
- return
-
- pitem.sendNoteOff(channel, note)
-
- # -----------------------------------------------------------------
-
- @pyqtSlot(int)
- def slot_handleUpdateCallback(self, pluginId):
- if pluginId >= self.fPluginCount:
- return
-
- pitem = self.fPluginList[pluginId]
- if pitem is None:
- return
-
- pitem.updateInfo()
-
- @pyqtSlot(int)
- def slot_handleReloadInfoCallback(self, pluginId):
- if pluginId >= self.fPluginCount:
- return
-
- pitem = self.fPluginList[pluginId]
- if pitem is None:
- return
-
- pitem.reloadInfo()
-
- @pyqtSlot(int)
- def slot_handleReloadParametersCallback(self, pluginId):
- if pluginId >= self.fPluginCount:
- return
-
- pitem = self.fPluginList[pluginId]
- if pitem is None:
- return
-
- pitem.reloadParameters()
-
- @pyqtSlot(int)
- def slot_handleReloadProgramsCallback(self, pluginId):
- if pluginId >= self.fPluginCount:
- return
-
- pitem = self.fPluginList[pluginId]
- if pitem is None:
- return
-
- pitem.reloadPrograms()
-
- @pyqtSlot(int)
- def slot_handleReloadAllCallback(self, pluginId):
- if pluginId >= self.fPluginCount:
- return
-
- pitem = self.fPluginList[pluginId]
- if pitem is None:
- return
-
- pitem.reloadAll()
-
- # -----------------------------------------------------------------
-
- @pyqtSlot(int, int, int, str)
- def slot_handlePatchbayClientAddedCallback(self, clientId, clientIcon, pluginId, clientName):
- pcSplit = patchcanvas.SPLIT_UNDEF
- pcIcon = patchcanvas.ICON_APPLICATION
-
- if clientIcon == PATCHBAY_ICON_PLUGIN:
- pcIcon = patchcanvas.ICON_PLUGIN
- if clientIcon == PATCHBAY_ICON_HARDWARE:
- pcIcon = patchcanvas.ICON_HARDWARE
- elif clientIcon == PATCHBAY_ICON_CARLA:
- pass
- elif clientIcon == PATCHBAY_ICON_DISTRHO:
- pcIcon = patchcanvas.ICON_DISTRHO
- elif clientIcon == PATCHBAY_ICON_FILE:
- pcIcon = patchcanvas.ICON_FILE
-
- patchcanvas.addGroup(clientId, clientName, pcSplit, pcIcon)
-
- QTimer.singleShot(0, self.fMiniCanvasPreview.update)
-
- if pluginId < 0:
- return
- if pluginId >= self.fPluginCount:
- print("sorry, can't map this plugin to canvas client", pluginId, self.fPluginCount)
- return
-
- patchcanvas.setGroupAsPlugin(clientId, pluginId, bool(gCarla.host.get_plugin_info(pluginId)['hints'] & PLUGIN_HAS_CUSTOM_UI))
-
- @pyqtSlot(int)
- def slot_handlePatchbayClientRemovedCallback(self, clientId):
- #if not self.fEngineStarted: return
- patchcanvas.removeGroup(clientId)
- QTimer.singleShot(0, self.fMiniCanvasPreview.update)
-
- @pyqtSlot(int, str)
- def slot_handlePatchbayClientRenamedCallback(self, clientId, newClientName):
- patchcanvas.renameGroup(clientId, newClientName)
- QTimer.singleShot(0, self.fMiniCanvasPreview.update)
-
- @pyqtSlot(int, int, int)
- def slot_handlePatchbayClientDataChangedCallback(self, clientId, clientIcon, pluginId):
- pcIcon = patchcanvas.ICON_APPLICATION
-
- if clientIcon == PATCHBAY_ICON_PLUGIN:
- pcIcon = patchcanvas.ICON_PLUGIN
- if clientIcon == PATCHBAY_ICON_HARDWARE:
- pcIcon = patchcanvas.ICON_HARDWARE
- elif clientIcon == PATCHBAY_ICON_CARLA:
- pass
- elif clientIcon == PATCHBAY_ICON_DISTRHO:
- pcIcon = patchcanvas.ICON_DISTRHO
- elif clientIcon == PATCHBAY_ICON_FILE:
- pcIcon = patchcanvas.ICON_FILE
-
- patchcanvas.setGroupIcon(clientId, pcIcon)
- QTimer.singleShot(0, self.fMiniCanvasPreview.update)
-
- if pluginId < 0:
- return
- if pluginId >= self.fPluginCount:
- print("sorry, can't map this plugin to canvas client", pluginId, self.getPluginCount())
- return
-
- patchcanvas.setGroupAsPlugin(clientId, pluginId, bool(gCarla.host.get_plugin_info(pluginId)['hints'] & PLUGIN_HAS_CUSTOM_UI))
-
- @pyqtSlot(int, int, int, str)
- def slot_handlePatchbayPortAddedCallback(self, clientId, portId, portFlags, portName):
- isAlternate = False
-
- if (portFlags & PATCHBAY_PORT_IS_INPUT):
- portMode = patchcanvas.PORT_MODE_INPUT
- else:
- portMode = patchcanvas.PORT_MODE_OUTPUT
-
- if (portFlags & PATCHBAY_PORT_TYPE_AUDIO):
- portType = patchcanvas.PORT_TYPE_AUDIO_JACK
- elif (portFlags & PATCHBAY_PORT_TYPE_CV):
- isAlternate = True
- portType = patchcanvas.PORT_TYPE_AUDIO_JACK
- elif (portFlags & PATCHBAY_PORT_TYPE_MIDI):
- portType = patchcanvas.PORT_TYPE_MIDI_JACK
- else:
- portType = patchcanvas.PORT_TYPE_NULL
-
- patchcanvas.addPort(clientId, portId, portName, portMode, portType, isAlternate)
- QTimer.singleShot(0, self.fMiniCanvasPreview.update)
-
- @pyqtSlot(int, int)
- def slot_handlePatchbayPortRemovedCallback(self, groupId, portId):
- #if not self.fEngineStarted: return
- patchcanvas.removePort(groupId, portId)
- QTimer.singleShot(0, self.fMiniCanvasPreview.update)
-
- @pyqtSlot(int, int, str)
- def slot_handlePatchbayPortRenamedCallback(self, groupId, portId, newPortName):
- patchcanvas.renamePort(groupId, portId, newPortName)
- QTimer.singleShot(0, self.fMiniCanvasPreview.update)
-
- @pyqtSlot(int, int, int, int, int)
- def slot_handlePatchbayConnectionAddedCallback(self, connectionId, groupOutId, portOutId, groupInId, portInId):
- patchcanvas.connectPorts(connectionId, groupOutId, portOutId, groupInId, portInId)
- QTimer.singleShot(0, self.fMiniCanvasPreview.update)
-
- @pyqtSlot(int, int, int)
- def slot_handlePatchbayConnectionRemovedCallback(self, connectionId, portOutId, portInId):
- #if not self.fEngineStarted: return
- patchcanvas.disconnectPorts(connectionId)
- QTimer.singleShot(0, self.fMiniCanvasPreview.update)
-
- # -----------------------------------------------------------------
-
- @pyqtSlot()
- def slot_canvasArrange(self):
- patchcanvas.arrange()
-
- @pyqtSlot()
- def slot_canvasRefresh(self):
- patchcanvas.clear()
-
- if gCarla.host is not None and gCarla.host.is_engine_running():
- gCarla.host.patchbay_refresh()
-
- for pitem in self.fPluginList:
- if pitem is None:
- break
- pitem.reloadAll()
-
- QTimer.singleShot(1000 if self.fParent.fSavedSettings[CARLA_KEY_CANVAS_EYE_CANDY] else 0, self.fMiniCanvasPreview.update)
-
- @pyqtSlot()
- def slot_canvasZoomFit(self):
- self.scene.zoom_fit()
-
- @pyqtSlot()
- def slot_canvasZoomIn(self):
- self.scene.zoom_in()
-
- @pyqtSlot()
- def slot_canvasZoomOut(self):
- self.scene.zoom_out()
-
- @pyqtSlot()
- def slot_canvasZoomReset(self):
- self.scene.zoom_reset()
-
- @pyqtSlot()
- def slot_canvasPrint(self):
- self.scene.clearSelection()
- self.fExportPrinter = QPrinter()
- dialog = QPrintDialog(self.fExportPrinter, self)
-
- if dialog.exec_():
- painter = QPainter(self.fExportPrinter)
- painter.save()
- painter.setRenderHint(QPainter.Antialiasing)
- painter.setRenderHint(QPainter.TextAntialiasing)
- self.scene.render(painter)
- painter.restore()
-
- @pyqtSlot()
- def slot_canvasSaveImage(self):
- newPath = QFileDialog.getSaveFileName(self, self.tr("Save Image"), filter=self.tr("PNG Image (*.png);;JPEG Image (*.jpg)"))
-
- if config_UseQt5:
- newPath = newPath[0]
- if not newPath:
- return
-
- self.scene.clearSelection()
-
- if newPath.lower().endswith((".jpg",)):
- imgFormat = "JPG"
- elif newPath.lower().endswith((".png",)):
- imgFormat = "PNG"
- else:
- # File-dialog may not auto-add the extension
- imgFormat = "PNG"
- newPath += ".png"
-
- self.fExportImage = QImage(self.scene.sceneRect().width(), self.scene.sceneRect().height(), QImage.Format_RGB32)
- painter = QPainter(self.fExportImage)
- painter.save()
- painter.setRenderHint(QPainter.Antialiasing) # TODO - set true, cleanup this
- painter.setRenderHint(QPainter.TextAntialiasing)
- self.scene.render(painter)
- self.fExportImage.save(newPath, imgFormat, 100)
- painter.restore()
-
- # -----------------------------------------------------------------
-
- def resizeEvent(self, event):
- QFrame.resizeEvent(self, event)
- self.slot_miniCanvasCheckSize()
-
- # ------------------------------------------------------------------------------------------------
- # Canvas callback
-
- def canvasCallback(action, value1, value2, valueStr):
- if action == patchcanvas.ACTION_GROUP_INFO:
- pass
-
- elif action == patchcanvas.ACTION_GROUP_RENAME:
- pass
-
- elif action == patchcanvas.ACTION_GROUP_SPLIT:
- groupId = value1
- patchcanvas.splitGroup(groupId)
- gCarla.gui.ui.miniCanvasPreview.update()
-
- elif action == patchcanvas.ACTION_GROUP_JOIN:
- groupId = value1
- patchcanvas.joinGroup(groupId)
- gCarla.gui.ui.miniCanvasPreview.update()
-
- elif action == patchcanvas.ACTION_PORT_INFO:
- pass
-
- elif action == patchcanvas.ACTION_PORT_RENAME:
- pass
-
- elif action == patchcanvas.ACTION_PORTS_CONNECT:
- gOut, pOut, gIn, pIn = [int(i) for i in valueStr.split(":")]
-
- if not gCarla.host.patchbay_connect(gOut, pOut, gIn, pIn):
- print("Connection failed:", gCarla.host.get_last_error())
-
- elif action == patchcanvas.ACTION_PORTS_DISCONNECT:
- connectionId = value1
-
- if not gCarla.host.patchbay_disconnect(connectionId):
- print("Disconnect failed:", gCarla.host.get_last_error())
-
- elif action == patchcanvas.ACTION_PLUGIN_CLONE:
- pluginId = value1
-
- gCarla.host.clone_plugin(pluginId)
-
- elif action == patchcanvas.ACTION_PLUGIN_EDIT:
- pluginId = value1
-
- gCarla.gui.fContainer.showEditDialog(pluginId)
-
- elif action == patchcanvas.ACTION_PLUGIN_RENAME:
- pluginId = value1
- newName = valueStr
-
- gCarla.host.rename_plugin(pluginId, newName)
-
- elif action == patchcanvas.ACTION_PLUGIN_REMOVE:
- pluginId = value1
-
- gCarla.host.remove_plugin(pluginId)
-
- elif action == patchcanvas.ACTION_PLUGIN_SHOW_UI:
- pluginId = value1
-
- gCarla.host.show_custom_ui(pluginId, True)
|