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_host.py 84KB

10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
10 years ago
11 years ago
10 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
10 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
10 years ago
10 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Carla host code
  4. # Copyright (C) 2011-2014 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 doc/GPL.txt file.
  17. # ------------------------------------------------------------------------------------------------------------
  18. # Imports (Config)
  19. from carla_config import *
  20. # ------------------------------------------------------------------------------------------------------------
  21. # Imports (Global)
  22. if config_UseQt5:
  23. from PyQt5.QtCore import qCritical, QFileInfo, QModelIndex, QPointF, QTimer
  24. from PyQt5.QtGui import QImage, QPalette
  25. from PyQt5.QtPrintSupport import QPrinter, QPrintDialog
  26. from PyQt5.QtWidgets import QAction, QApplication, QFileSystemModel, QListWidgetItem, QMainWindow
  27. else:
  28. from PyQt4.QtCore import qCritical, QFileInfo, QModelIndex, QPointF, QTimer
  29. from PyQt4.QtGui import QAction, QApplication, QFileSystemModel, QImage, QListWidgetItem, QMainWindow, QPalette, QPrinter, QPrintDialog
  30. # ------------------------------------------------------------------------------------------------------------
  31. # Imports (Custom)
  32. import patchcanvas
  33. import ui_carla_host
  34. from carla_app import *
  35. from carla_database import *
  36. from carla_panels import *
  37. from carla_settings import *
  38. from carla_utils import *
  39. from carla_widgets import *
  40. from digitalpeakmeter import DigitalPeakMeter
  41. from pixmapkeyboard import PixmapKeyboardHArea
  42. # ------------------------------------------------------------------------------------------------------------
  43. # Try Import OpenGL
  44. try:
  45. if config_UseQt5:
  46. from PyQt5.QtOpenGL import QGLWidget
  47. else:
  48. from PyQt4.QtOpenGL import QGLWidget
  49. hasGL = True
  50. except:
  51. hasGL = False
  52. # ------------------------------------------------------------------------------------------------------------
  53. # Session Management support
  54. CARLA_CLIENT_NAME = os.getenv("CARLA_CLIENT_NAME")
  55. LADISH_APP_NAME = os.getenv("LADISH_APP_NAME")
  56. NSM_URL = os.getenv("NSM_URL")
  57. # ------------------------------------------------------------------------------------------------------------
  58. # Host Window
  59. class HostWindow(QMainWindow):
  60. #class HostWindow(QMainWindow, PluginEditParentMeta, metaclass=PyQtMetaClass):
  61. # signals
  62. SIGTERM = pyqtSignal()
  63. SIGUSR1 = pyqtSignal()
  64. # --------------------------------------------------------------------------------------------------------
  65. def __init__(self, host, withCanvas, parent=None):
  66. QMainWindow.__init__(self, parent)
  67. self.host = host
  68. self.ui = ui_carla_host.Ui_CarlaHostW()
  69. self.ui.setupUi(self)
  70. gCarla.gui = self
  71. if False:
  72. # kdevelop likes this :)
  73. host = CarlaHostMeta()
  74. self.host = host
  75. self._true = c_char_p("true".encode("utf-8"))
  76. # ----------------------------------------------------------------------------------------------------
  77. # Internal stuff
  78. self.fIdleTimerFast = 0
  79. self.fIdleTimerSlow = 0
  80. self.fLadspaRdfNeedsUpdate = True
  81. self.fLadspaRdfList = []
  82. self.fPluginCount = 0
  83. self.fPluginList = []
  84. self.fProjectFilename = ""
  85. self.fIsProjectLoading = False
  86. self.fCurrentlyRemovingAllPlugins = False
  87. # first attempt of auto-start engine doesn't show an error
  88. self.fFirstEngineInit = True
  89. # to be filled with key-value pairs of current settings
  90. self.fSavedSettings = {}
  91. if host.isPlugin:
  92. self.fClientName = "Carla-Plugin"
  93. self.fSessionManagerName = "Plugin"
  94. elif LADISH_APP_NAME:
  95. self.fClientName = LADISH_APP_NAME
  96. self.fSessionManagerName = "LADISH"
  97. elif NSM_URL:
  98. self.fClientName = "Carla" # "Carla.tmp"
  99. self.fSessionManagerName = "Non Session Manager"
  100. else:
  101. self.fClientName = CARLA_CLIENT_NAME or "Carla"
  102. self.fSessionManagerName = ""
  103. # ----------------------------------------------------------------------------------------------------
  104. # Internal stuff (rack)
  105. self.fCurrentRow = -1
  106. self.fLastSelectedItem = None
  107. # ----------------------------------------------------------------------------------------------------
  108. # Internal stuff (patchbay)
  109. self.fExportImage = QImage()
  110. self.fExportPrinter = QPrinter()
  111. self.fPeaksCleared = True
  112. self.fExternalPatchbay = False
  113. self.fSelectedPlugins = []
  114. self.fCanvasWidth = 0
  115. self.fCanvasHeight = 0
  116. self.fMiniCanvasUpdateTimeout = 0
  117. self.fWithCanvas = withCanvas
  118. # ----------------------------------------------------------------------------------------------------
  119. # Set up GUI (engine stopped)
  120. if self.host.isPlugin:
  121. self.ui.act_engine_start.setEnabled(False)
  122. self.ui.menu_Engine.setEnabled(False)
  123. else:
  124. self.ui.act_engine_start.setEnabled(True)
  125. if self.fSessionManagerName:
  126. self.ui.act_file_new.setEnabled(False)
  127. self.ui.act_file_open.setEnabled(False)
  128. self.ui.act_file_save.setEnabled(False)
  129. self.ui.act_file_save_as.setEnabled(False)
  130. self.ui.act_engine_stop.setEnabled(False)
  131. self.ui.act_plugin_remove_all.setEnabled(False)
  132. self.ui.act_canvas_show_internal.setChecked(False)
  133. self.ui.act_canvas_show_internal.setVisible(False)
  134. self.ui.act_canvas_show_external.setChecked(False)
  135. self.ui.act_canvas_show_external.setVisible(False)
  136. self.ui.menu_PluginMacros.setEnabled(False)
  137. self.ui.menu_Canvas.setEnabled(False)
  138. self.ui.dockWidgetTitleBar = QWidget(self)
  139. self.ui.dockWidget.setTitleBarWidget(self.ui.dockWidgetTitleBar)
  140. if not withCanvas:
  141. self.ui.act_canvas_show_internal.setVisible(False)
  142. self.ui.act_canvas_show_external.setVisible(False)
  143. self.ui.act_canvas_arrange.setVisible(False)
  144. self.ui.act_canvas_print.setVisible(False)
  145. self.ui.act_canvas_refresh.setVisible(False)
  146. self.ui.act_canvas_save_image.setVisible(False)
  147. self.ui.act_canvas_zoom_100.setVisible(False)
  148. self.ui.act_canvas_zoom_fit.setVisible(False)
  149. self.ui.act_canvas_zoom_in.setVisible(False)
  150. self.ui.act_canvas_zoom_out.setVisible(False)
  151. self.ui.act_settings_show_meters.setVisible(False)
  152. self.ui.act_settings_show_keyboard.setVisible(False)
  153. self.ui.menu_Canvas_Zoom.setEnabled(False)
  154. self.ui.menu_Canvas_Zoom.setVisible(False)
  155. self.ui.menu_Canvas_Zoom.menuAction().setVisible(False)
  156. self.ui.menu_Canvas.setEnabled(False)
  157. self.ui.menu_Canvas.setVisible(False)
  158. self.ui.menu_Canvas.menuAction().setVisible(False)
  159. self.ui.miniCanvasPreview.hide()
  160. self.ui.tabWidget.removeTab(1)
  161. self.ui.tabWidget.tabBar().hide()
  162. # ----------------------------------------------------------------------------------------------------
  163. # Set up GUI (disk)
  164. self.fDirModel = QFileSystemModel(self)
  165. self.fDirModel.setRootPath(HOME)
  166. self.fDirModel.setNameFilters(gCarla.utils.get_supported_file_extensions().split(";"))
  167. self.ui.fileTreeView.setModel(self.fDirModel)
  168. self.ui.fileTreeView.setRootIndex(self.fDirModel.index(HOME))
  169. self.ui.fileTreeView.setColumnHidden(1, True)
  170. self.ui.fileTreeView.setColumnHidden(2, True)
  171. self.ui.fileTreeView.setColumnHidden(3, True)
  172. self.ui.fileTreeView.setHeaderHidden(True)
  173. # ----------------------------------------------------------------------------------------------------
  174. # Set up GUI (panels)
  175. self.fPanelTime = CarlaPanelTime(host, self)
  176. self.fPanelTime.setEnabled(False)
  177. if not host.isPlugin:
  178. QTimer.singleShot(0, self.fPanelTime.show)
  179. # ----------------------------------------------------------------------------------------------------
  180. # Set up GUI (rack)
  181. self.ui.listWidget.setHost(self.host)
  182. sb = self.ui.listWidget.verticalScrollBar()
  183. self.ui.rackScrollBar.setMinimum(sb.minimum())
  184. self.ui.rackScrollBar.setMaximum(sb.maximum())
  185. self.ui.rackScrollBar.setValue(sb.value())
  186. sb.rangeChanged.connect(self.ui.rackScrollBar.setRange)
  187. sb.valueChanged.connect(self.ui.rackScrollBar.setValue)
  188. self.ui.rackScrollBar.rangeChanged.connect(sb.setRange)
  189. self.ui.rackScrollBar.valueChanged.connect(sb.setValue)
  190. self.ui.listWidget.currentRowChanged.connect(self.slot_currentRowChanged)
  191. self.ui.rack.setStyleSheet("""
  192. QLabel#pad_left {
  193. background-image: url(:/bitmaps/rack_padding_left.png);
  194. background-repeat: repeat-y;
  195. }
  196. QLabel#pad_right {
  197. background-image: url(:/bitmaps/rack_padding_right.png);
  198. background-repeat: repeat-y;
  199. }
  200. CarlaRackList#CarlaRackList {
  201. background-color: black;
  202. }
  203. """)
  204. # ----------------------------------------------------------------------------------------------------
  205. # Set up GUI (patchbay)
  206. self.ui.peak_in.setChannelCount(2)
  207. self.ui.peak_in.setMeterColor(DigitalPeakMeter.COLOR_BLUE)
  208. self.ui.peak_in.setMeterOrientation(DigitalPeakMeter.VERTICAL)
  209. self.ui.peak_in.setFixedWidth(25)
  210. self.ui.peak_out.setChannelCount(2)
  211. self.ui.peak_out.setMeterColor(DigitalPeakMeter.COLOR_GREEN)
  212. self.ui.peak_out.setMeterOrientation(DigitalPeakMeter.VERTICAL)
  213. self.ui.peak_out.setFixedWidth(25)
  214. self.ui.scrollArea = PixmapKeyboardHArea(self.ui.patchbay)
  215. self.ui.keyboard = self.ui.scrollArea.keyboard
  216. self.ui.patchbay.layout().addWidget(self.ui.scrollArea, 1, 0, 1, 0)
  217. self.ui.scrollArea.setEnabled(False)
  218. self.ui.miniCanvasPreview.setRealParent(self)
  219. # ----------------------------------------------------------------------------------------------------
  220. # Set up GUI (special stuff for Mac OS)
  221. if MACOS:
  222. self.ui.act_file_quit.setMenuRole(QAction.QuitRole)
  223. self.ui.act_settings_configure.setMenuRole(QAction.PreferencesRole)
  224. self.ui.act_help_about.setMenuRole(QAction.AboutRole)
  225. self.ui.act_help_about_juce.setMenuRole(QAction.AboutQtRole)
  226. self.ui.act_help_about_qt.setMenuRole(QAction.AboutQtRole)
  227. self.ui.menu_Settings.setTitle("Panels")
  228. #self.ui.menu_Help.hide()
  229. # ----------------------------------------------------------------------------------------------------
  230. # Load Settings
  231. self.loadSettings(True)
  232. # ----------------------------------------------------------------------------------------------------
  233. # Set-up Canvas
  234. self.scene = patchcanvas.PatchScene(self, self.ui.graphicsView)
  235. self.ui.graphicsView.setScene(self.scene)
  236. self.ui.graphicsView.setRenderHint(QPainter.Antialiasing, bool(self.fSavedSettings[CARLA_KEY_CANVAS_ANTIALIASING] == patchcanvas.ANTIALIASING_FULL))
  237. if self.fSavedSettings[CARLA_KEY_CANVAS_USE_OPENGL] and hasGL:
  238. self.ui.glView = QGLWidget(self)
  239. self.ui.graphicsView.setViewport(self.ui.glView)
  240. self.ui.graphicsView.setRenderHint(QPainter.HighQualityAntialiasing, self.fSavedSettings[CARLA_KEY_CANVAS_HQ_ANTIALIASING])
  241. self.setupCanvas()
  242. # ----------------------------------------------------------------------------------------------------
  243. # Connect actions to functions
  244. self.ui.act_file_new.triggered.connect(self.slot_fileNew)
  245. self.ui.act_file_open.triggered.connect(self.slot_fileOpen)
  246. self.ui.act_file_save.triggered.connect(self.slot_fileSave)
  247. self.ui.act_file_save_as.triggered.connect(self.slot_fileSaveAs)
  248. self.ui.act_engine_start.triggered.connect(self.slot_engineStart)
  249. self.ui.act_engine_stop.triggered.connect(self.slot_engineStop)
  250. self.ui.act_plugin_add.triggered.connect(self.slot_pluginAdd)
  251. self.ui.act_plugin_add2.triggered.connect(self.slot_pluginAdd)
  252. self.ui.act_plugin_remove_all.triggered.connect(self.slot_pluginRemoveAll)
  253. self.ui.act_plugins_enable.triggered.connect(self.slot_pluginsEnable)
  254. self.ui.act_plugins_disable.triggered.connect(self.slot_pluginsDisable)
  255. self.ui.act_plugins_volume100.triggered.connect(self.slot_pluginsVolume100)
  256. self.ui.act_plugins_mute.triggered.connect(self.slot_pluginsMute)
  257. self.ui.act_plugins_wet100.triggered.connect(self.slot_pluginsWet100)
  258. self.ui.act_plugins_bypass.triggered.connect(self.slot_pluginsBypass)
  259. self.ui.act_plugins_center.triggered.connect(self.slot_pluginsCenter)
  260. self.ui.act_plugins_panic.triggered.connect(self.slot_pluginsDisable)
  261. self.ui.act_canvas_show_internal.triggered.connect(self.slot_canvasShowInternal)
  262. self.ui.act_canvas_show_external.triggered.connect(self.slot_canvasShowExternal)
  263. self.ui.act_canvas_arrange.triggered.connect(self.slot_canvasArrange)
  264. self.ui.act_canvas_refresh.triggered.connect(self.slot_canvasRefresh)
  265. self.ui.act_canvas_zoom_fit.triggered.connect(self.slot_canvasZoomFit)
  266. self.ui.act_canvas_zoom_in.triggered.connect(self.slot_canvasZoomIn)
  267. self.ui.act_canvas_zoom_out.triggered.connect(self.slot_canvasZoomOut)
  268. self.ui.act_canvas_zoom_100.triggered.connect(self.slot_canvasZoomReset)
  269. self.ui.act_canvas_print.triggered.connect(self.slot_canvasPrint)
  270. self.ui.act_canvas_save_image.triggered.connect(self.slot_canvasSaveImage)
  271. self.ui.act_canvas_arrange.setEnabled(False) # TODO, later
  272. self.ui.act_settings_show_meters.toggled.connect(self.slot_showCanvasMeters)
  273. self.ui.act_settings_show_keyboard.toggled.connect(self.slot_showCanvasKeyboard)
  274. self.ui.act_settings_configure.triggered.connect(self.slot_configureCarla)
  275. self.ui.act_help_about.triggered.connect(self.slot_aboutCarla)
  276. self.ui.act_help_about_juce.triggered.connect(self.slot_aboutJuce)
  277. self.ui.act_help_about_qt.triggered.connect(self.slot_aboutQt)
  278. self.ui.cb_disk.currentIndexChanged.connect(self.slot_diskFolderChanged)
  279. self.ui.b_disk_add.clicked.connect(self.slot_diskFolderAdd)
  280. self.ui.b_disk_remove.clicked.connect(self.slot_diskFolderRemove)
  281. self.ui.fileTreeView.doubleClicked.connect(self.slot_fileTreeDoubleClicked)
  282. self.ui.graphicsView.horizontalScrollBar().valueChanged.connect(self.slot_horizontalScrollBarChanged)
  283. self.ui.graphicsView.verticalScrollBar().valueChanged.connect(self.slot_verticalScrollBarChanged)
  284. self.ui.keyboard.noteOn.connect(self.slot_noteOn)
  285. self.ui.keyboard.noteOff.connect(self.slot_noteOff)
  286. self.ui.miniCanvasPreview.miniCanvasMoved.connect(self.slot_miniCanvasMoved)
  287. self.ui.tabWidget.currentChanged.connect(self.slot_tabChanged)
  288. self.scene.scaleChanged.connect(self.slot_canvasScaleChanged)
  289. self.scene.sceneGroupMoved.connect(self.slot_canvasItemMoved)
  290. self.scene.pluginSelected.connect(self.slot_canvasPluginSelected)
  291. self.SIGUSR1.connect(self.slot_handleSIGUSR1)
  292. self.SIGTERM.connect(self.slot_handleSIGTERM)
  293. host.EngineStartedCallback.connect(self.slot_handleEngineStartedCallback)
  294. host.EngineStoppedCallback.connect(self.slot_handleEngineStoppedCallback)
  295. host.PluginAddedCallback.connect(self.slot_handlePluginAddedCallback)
  296. host.PluginRemovedCallback.connect(self.slot_handlePluginRemovedCallback)
  297. host.ReloadAllCallback.connect(self.slot_handleReloadAllCallback)
  298. host.NoteOnCallback.connect(self.slot_handleNoteOnCallback)
  299. host.NoteOffCallback.connect(self.slot_handleNoteOffCallback)
  300. host.PatchbayClientAddedCallback.connect(self.slot_handlePatchbayClientAddedCallback)
  301. host.PatchbayClientRemovedCallback.connect(self.slot_handlePatchbayClientRemovedCallback)
  302. host.PatchbayClientRenamedCallback.connect(self.slot_handlePatchbayClientRenamedCallback)
  303. host.PatchbayClientDataChangedCallback.connect(self.slot_handlePatchbayClientDataChangedCallback)
  304. host.PatchbayPortAddedCallback.connect(self.slot_handlePatchbayPortAddedCallback)
  305. host.PatchbayPortRemovedCallback.connect(self.slot_handlePatchbayPortRemovedCallback)
  306. host.PatchbayPortRenamedCallback.connect(self.slot_handlePatchbayPortRenamedCallback)
  307. host.PatchbayConnectionAddedCallback.connect(self.slot_handlePatchbayConnectionAddedCallback)
  308. host.PatchbayConnectionRemovedCallback.connect(self.slot_handlePatchbayConnectionRemovedCallback)
  309. host.DebugCallback.connect(self.slot_handleDebugCallback)
  310. host.InfoCallback.connect(self.slot_handleInfoCallback)
  311. host.ErrorCallback.connect(self.slot_handleErrorCallback)
  312. host.QuitCallback.connect(self.slot_handleQuitCallback)
  313. # ----------------------------------------------------------------------------------------------------
  314. # Final setup
  315. self.setProperWindowTitle()
  316. # Qt needs this so it properly creates & resizes the canvas
  317. self.ui.tabWidget.blockSignals(True)
  318. self.ui.tabWidget.setCurrentIndex(1)
  319. self.ui.tabWidget.setCurrentIndex(0)
  320. self.ui.tabWidget.blockSignals(False)
  321. # Plugin needs to have timers always running so it receives messages
  322. if self.host.isPlugin:
  323. self.startTimers()
  324. QTimer.singleShot(0, self.slot_engineStart)
  325. # --------------------------------------------------------------------------------------------------------
  326. # Setup
  327. def setLoadRDFsNeeded(self):
  328. self.fLadspaRdfNeedsUpdate = True
  329. def setProperWindowTitle(self):
  330. title = self.fClientName
  331. if self.fProjectFilename:
  332. title += " - %s" % os.path.basename(self.fProjectFilename)
  333. if self.fSessionManagerName:
  334. title += " (%s)" % self.fSessionManagerName
  335. self.setWindowTitle(title)
  336. # --------------------------------------------------------------------------------------------------------
  337. # Files
  338. def loadProjectNow(self):
  339. if not self.fProjectFilename:
  340. return qCritical("ERROR: loading project without filename set")
  341. self.projectLoadingStarted()
  342. self.fIsProjectLoading = True
  343. self.host.load_project(self.fProjectFilename)
  344. self.fIsProjectLoading = False
  345. self.projectLoadingFinished()
  346. def loadProjectLater(self, filename):
  347. self.fProjectFilename = QFileInfo(filename).absoluteFilePath()
  348. self.setProperWindowTitle()
  349. QTimer.singleShot(0, self.slot_loadProjectNow)
  350. def saveProjectNow(self):
  351. if not self.fProjectFilename:
  352. return qCritical("ERROR: saving project without filename set")
  353. self.host.save_project(self.fProjectFilename)
  354. def projectLoadingStarted(self):
  355. self.ui.rack.setEnabled(False)
  356. self.ui.graphicsView.setEnabled(False)
  357. def projectLoadingFinished(self):
  358. self.ui.rack.setEnabled(True)
  359. self.ui.graphicsView.setEnabled(True)
  360. QTimer.singleShot(1000, self.slot_canvasRefresh)
  361. # --------------------------------------------------------------------------------------------------------
  362. # Files (menu actions)
  363. @pyqtSlot()
  364. def slot_fileNew(self):
  365. self.slot_pluginRemoveAll()
  366. self.fProjectFilename = ""
  367. self.setProperWindowTitle()
  368. @pyqtSlot()
  369. def slot_fileOpen(self):
  370. fileFilter = self.tr("Carla Project File (*.carxp)")
  371. filename = QFileDialog.getOpenFileName(self, self.tr("Open Carla Project File"), self.fSavedSettings[CARLA_KEY_MAIN_PROJECT_FOLDER], filter=fileFilter)
  372. if config_UseQt5:
  373. filename = filename[0]
  374. if not filename:
  375. return
  376. newFile = True
  377. if self.fPluginCount > 0:
  378. ask = QMessageBox.question(self, self.tr("Question"), self.tr("There are some plugins loaded, do you want to remove them now?"),
  379. QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
  380. newFile = (ask == QMessageBox.Yes)
  381. if newFile:
  382. self.slot_pluginRemoveAll()
  383. self.fProjectFilename = filename
  384. self.setProperWindowTitle()
  385. self.loadProjectNow()
  386. else:
  387. filenameOld = self.fProjectFilename
  388. self.fProjectFilename = filename
  389. self.loadProjectNow()
  390. self.fProjectFilename = filenameOld
  391. @pyqtSlot()
  392. def slot_fileSave(self, saveAs=False):
  393. if self.fProjectFilename and not saveAs:
  394. return self.saveProjectNow()
  395. fileFilter = self.tr("Carla Project File (*.carxp)")
  396. filename = QFileDialog.getSaveFileName(self, self.tr("Save Carla Project File"), self.fSavedSettings[CARLA_KEY_MAIN_PROJECT_FOLDER], filter=fileFilter)
  397. if config_UseQt5:
  398. filename = filename[0]
  399. if not filename:
  400. return
  401. if not filename.lower().endswith(".carxp"):
  402. filename += ".carxp"
  403. if self.fProjectFilename != filename:
  404. self.fProjectFilename = filename
  405. self.setProperWindowTitle()
  406. self.saveProjectNow()
  407. @pyqtSlot()
  408. def slot_fileSaveAs(self):
  409. self.slot_fileSave(True)
  410. @pyqtSlot()
  411. def slot_loadProjectNow(self):
  412. self.loadProjectNow()
  413. # --------------------------------------------------------------------------------------------------------
  414. # Engine (menu actions)
  415. @pyqtSlot()
  416. def slot_engineStart(self):
  417. audioDriver = self.setEngineSettings()
  418. firstInit = self.fFirstEngineInit
  419. self.fFirstEngineInit = False
  420. if self.host.engine_init(audioDriver, self.fClientName) or firstInit:
  421. return
  422. audioError = self.host.get_last_error()
  423. if audioError:
  424. QMessageBox.critical(self, self.tr("Error"), self.tr("Could not connect to Audio backend '%s', possible reasons:\n%s" % (audioDriver, audioError)))
  425. else:
  426. QMessageBox.critical(self, self.tr("Error"), self.tr("Could not connect to Audio backend '%s'" % audioDriver))
  427. @pyqtSlot()
  428. def slot_engineStop(self, forced = False):
  429. if self.fPluginCount > 0:
  430. if not forced:
  431. ask = QMessageBox.question(self, self.tr("Warning"), self.tr("There are still some plugins loaded, you need to remove them to stop the engine.\n"
  432. "Do you want to do this now?"),
  433. QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
  434. if ask != QMessageBox.Yes:
  435. return
  436. self.removeAllPlugins()
  437. self.host.set_engine_about_to_close()
  438. self.host.remove_all_plugins()
  439. if self.host.is_engine_running() and not self.host.engine_close():
  440. print(self.host.get_last_error())
  441. # --------------------------------------------------------------------------------------------------------
  442. # Engine (host callbacks)
  443. @pyqtSlot(str)
  444. def slot_handleEngineStartedCallback(self, processMode, transportMode, driverName):
  445. self.ui.menu_PluginMacros.setEnabled(True)
  446. self.ui.menu_Canvas.setEnabled(True)
  447. self.ui.act_canvas_show_internal.blockSignals(True)
  448. self.ui.act_canvas_show_external.blockSignals(True)
  449. if processMode == ENGINE_PROCESS_MODE_PATCHBAY and driverName == "JACK":
  450. self.ui.act_canvas_show_internal.setChecked(True)
  451. self.ui.act_canvas_show_internal.setVisible(True)
  452. self.ui.act_canvas_show_external.setChecked(False)
  453. self.ui.act_canvas_show_external.setVisible(True)
  454. else:
  455. self.ui.act_canvas_show_internal.setChecked(False)
  456. self.ui.act_canvas_show_internal.setVisible(False)
  457. self.ui.act_canvas_show_external.setChecked(False)
  458. self.ui.act_canvas_show_external.setVisible(False)
  459. self.ui.act_canvas_show_internal.blockSignals(False)
  460. self.ui.act_canvas_show_external.blockSignals(False)
  461. if not self.host.isPlugin:
  462. self.ui.act_engine_start.setEnabled(False)
  463. self.ui.act_engine_stop.setEnabled(True)
  464. if not self.fSessionManagerName:
  465. self.ui.act_file_open.setEnabled(True)
  466. self.ui.act_file_save.setEnabled(True)
  467. self.ui.act_file_save_as.setEnabled(True)
  468. self.fPanelTime.setEnabled(True)
  469. self.startTimers()
  470. @pyqtSlot()
  471. def slot_handleEngineStoppedCallback(self):
  472. patchcanvas.clear()
  473. self.killTimers()
  474. # just in case
  475. self.removeAllPlugins()
  476. self.ui.menu_PluginMacros.setEnabled(False)
  477. self.ui.menu_Canvas.setEnabled(False)
  478. if not self.host.isPlugin:
  479. self.ui.act_engine_start.setEnabled(True)
  480. self.ui.act_engine_stop.setEnabled(False)
  481. if not self.fSessionManagerName:
  482. self.ui.act_file_open.setEnabled(False)
  483. self.ui.act_file_save.setEnabled(False)
  484. self.ui.act_file_save_as.setEnabled(False)
  485. self.fPanelTime.setEnabled(False)
  486. # --------------------------------------------------------------------------------------------------------
  487. # Plugins
  488. def removeAllPlugins(self):
  489. self.ui.act_plugin_remove_all.setEnabled(False)
  490. patchcanvas.handleAllPluginsRemoved()
  491. while self.ui.listWidget.takeItem(0):
  492. pass
  493. self.clearSideStuff()
  494. for pitem in self.fPluginList:
  495. if pitem is None:
  496. continue
  497. pitem.close()
  498. del pitem
  499. self.fPluginCount = 0
  500. self.fPluginList = []
  501. # --------------------------------------------------------------------------------------------------------
  502. # Plugins (menu actions)
  503. @pyqtSlot()
  504. def slot_pluginAdd(self, pluginToReplace = -1):
  505. dialog = PluginDatabaseW(self, self.host)
  506. if not dialog.exec_():
  507. return
  508. if not self.host.is_engine_running():
  509. QMessageBox.warning(self, self.tr("Warning"), self.tr("Cannot add new plugins while engine is stopped"))
  510. return
  511. btype = dialog.fRetPlugin['build']
  512. ptype = dialog.fRetPlugin['type']
  513. filename = dialog.fRetPlugin['filename']
  514. label = dialog.fRetPlugin['label']
  515. uniqueId = dialog.fRetPlugin['uniqueId']
  516. extraPtr = self.getExtraPtr(dialog.fRetPlugin)
  517. if pluginToReplace >= 0:
  518. if not self.host.replace_plugin(pluginToReplace):
  519. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Failed to replace plugin"), self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  520. return
  521. ok = self.host.add_plugin(btype, ptype, filename, None, label, uniqueId, extraPtr)
  522. if pluginToReplace >= 0:
  523. self.host.replace_plugin(self.host.get_max_plugin_number())
  524. if not ok:
  525. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Failed to load plugin"), self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  526. @pyqtSlot()
  527. def slot_pluginRemoveAll(self):
  528. if self.fPluginCount == 0:
  529. return
  530. # FIXME - this is not working
  531. # removing a plugin causes flicker, the rack-list becomes empty for some time
  532. # this breaks the remove-all animation, so don't bother using it
  533. if False and not self.host.isPlugin:
  534. self.projectLoadingStarted()
  535. app = QApplication.instance()
  536. app.processEvents()
  537. for i in reversed(range(self.fPluginCount)):
  538. self.host.remove_plugin(i)
  539. app.processEvents()
  540. self.projectLoadingFinished()
  541. self.fCurrentlyRemovingAllPlugins = True
  542. ok = self.host.remove_all_plugins()
  543. self.fCurrentlyRemovingAllPlugins = False
  544. if ok:
  545. self.removeAllPlugins()
  546. else:
  547. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  548. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  549. self.fCurrentlyRemovingAllPlugins = False
  550. # --------------------------------------------------------------------------------------------------------
  551. # Plugins (macros)
  552. @pyqtSlot()
  553. def slot_pluginsEnable(self):
  554. if not self.host.is_engine_running():
  555. return
  556. for pitem in self.fPluginList:
  557. if pitem is None:
  558. break
  559. pitem.getWidget().setActive(True, True, True)
  560. @pyqtSlot()
  561. def slot_pluginsDisable(self):
  562. if not self.host.is_engine_running():
  563. return
  564. for pitem in self.fPluginList:
  565. if pitem is None:
  566. break
  567. pitem.getWidget().setActive(False, True, True)
  568. @pyqtSlot()
  569. def slot_pluginsVolume100(self):
  570. if not self.host.is_engine_running():
  571. return
  572. for pitem in self.fPluginList:
  573. if pitem is None:
  574. break
  575. pitem.getWidget().setInternalParameter(PLUGIN_CAN_VOLUME, 1.0)
  576. @pyqtSlot()
  577. def slot_pluginsMute(self):
  578. if not self.host.is_engine_running():
  579. return
  580. for pitem in self.fPluginList:
  581. if pitem is None:
  582. break
  583. pitem.getWidget().setInternalParameter(PLUGIN_CAN_VOLUME, 0.0)
  584. @pyqtSlot()
  585. def slot_pluginsWet100(self):
  586. if not self.host.is_engine_running():
  587. return
  588. for pitem in self.fPluginList:
  589. if pitem is None:
  590. break
  591. pitem.getWidget().setInternalParameter(PLUGIN_CAN_DRYWET, 1.0)
  592. @pyqtSlot()
  593. def slot_pluginsBypass(self):
  594. if not self.host.is_engine_running():
  595. return
  596. for pitem in self.fPluginList:
  597. if pitem is None:
  598. break
  599. pitem.getWidget().setInternalParameter(PLUGIN_CAN_DRYWET, 0.0)
  600. @pyqtSlot()
  601. def slot_pluginsCenter(self):
  602. if not self.host.is_engine_running():
  603. return
  604. for pitem in self.fPluginList:
  605. if pitem is None:
  606. break
  607. pitem.getWidget().setInternalParameter(PARAMETER_BALANCE_LEFT, -1.0)
  608. pitem.getWidget().setInternalParameter(PARAMETER_BALANCE_RIGHT, 1.0)
  609. pitem.getWidget().setInternalParameter(PARAMETER_PANNING, 0.0)
  610. # --------------------------------------------------------------------------------------------------------
  611. # Plugins (host callbacks)
  612. @pyqtSlot(int, str)
  613. def slot_handlePluginAddedCallback(self, pluginId, pluginName):
  614. pitem = self.ui.listWidget.createItem(pluginId, self.fSavedSettings[CARLA_KEY_MAIN_USE_CUSTOM_SKINS])
  615. self.fPluginList.append(pitem)
  616. self.fPluginCount += 1
  617. if not self.fIsProjectLoading:
  618. pitem.getWidget().setActive(True, True, True)
  619. self.ui.act_plugin_remove_all.setEnabled(self.fPluginCount > 0)
  620. @pyqtSlot(int)
  621. def slot_handlePluginRemovedCallback(self, pluginId):
  622. patchcanvas.handlePluginRemoved(pluginId)
  623. if pluginId in self.fSelectedPlugins:
  624. self.clearSideStuff()
  625. pitem = self.getPluginItem(pluginId)
  626. self.fPluginCount -= 1
  627. self.fPluginList.pop(pluginId)
  628. self.ui.listWidget.takeItem(pluginId)
  629. if pitem is not None:
  630. pitem.close()
  631. del pitem
  632. # push all plugins 1 slot back
  633. for i in range(pluginId, self.fPluginCount):
  634. pitem = self.fPluginList[i]
  635. pitem.setPluginId(i)
  636. self.ui.act_plugin_remove_all.setEnabled(self.fPluginCount > 0)
  637. # --------------------------------------------------------------------------------------------------------
  638. # Canvas
  639. def clearSideStuff(self):
  640. self.scene.clearSelection()
  641. self.fSelectedPlugins = []
  642. self.ui.keyboard.allNotesOff(False)
  643. self.ui.scrollArea.setEnabled(False)
  644. self.fPeaksCleared = True
  645. self.ui.peak_in.displayMeter(1, 0.0, True)
  646. self.ui.peak_in.displayMeter(2, 0.0, True)
  647. self.ui.peak_out.displayMeter(1, 0.0, True)
  648. self.ui.peak_out.displayMeter(2, 0.0, True)
  649. def setupCanvas(self):
  650. pOptions = patchcanvas.options_t()
  651. pOptions.theme_name = self.fSavedSettings[CARLA_KEY_CANVAS_THEME]
  652. pOptions.auto_hide_groups = self.fSavedSettings[CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS]
  653. pOptions.use_bezier_lines = self.fSavedSettings[CARLA_KEY_CANVAS_USE_BEZIER_LINES]
  654. pOptions.antialiasing = self.fSavedSettings[CARLA_KEY_CANVAS_ANTIALIASING]
  655. pOptions.eyecandy = self.fSavedSettings[CARLA_KEY_CANVAS_EYE_CANDY]
  656. pFeatures = patchcanvas.features_t()
  657. pFeatures.group_info = False
  658. pFeatures.group_rename = False
  659. pFeatures.port_info = False
  660. pFeatures.port_rename = False
  661. pFeatures.handle_group_pos = True
  662. patchcanvas.setOptions(pOptions)
  663. patchcanvas.setFeatures(pFeatures)
  664. patchcanvas.init("Carla2", self.scene, canvasCallback, False)
  665. tryCanvasSize = self.fSavedSettings[CARLA_KEY_CANVAS_SIZE].split("x")
  666. if len(tryCanvasSize) == 2 and tryCanvasSize[0].isdigit() and tryCanvasSize[1].isdigit():
  667. self.fCanvasWidth = int(tryCanvasSize[0])
  668. self.fCanvasHeight = int(tryCanvasSize[1])
  669. else:
  670. self.fCanvasWidth = CARLA_DEFAULT_CANVAS_SIZE_WIDTH
  671. self.fCanvasHeight = CARLA_DEFAULT_CANVAS_SIZE_HEIGHT
  672. patchcanvas.setCanvasSize(0, 0, self.fCanvasWidth, self.fCanvasHeight)
  673. patchcanvas.setInitialPos(self.fCanvasWidth / 2, self.fCanvasHeight / 2)
  674. self.ui.graphicsView.setSceneRect(0, 0, self.fCanvasWidth, self.fCanvasHeight)
  675. self.ui.miniCanvasPreview.setViewTheme(patchcanvas.canvas.theme.canvas_bg, patchcanvas.canvas.theme.rubberband_brush, patchcanvas.canvas.theme.rubberband_pen.color())
  676. self.ui.miniCanvasPreview.init(self.scene, self.fCanvasWidth, self.fCanvasHeight, self.fSavedSettings[CARLA_KEY_CUSTOM_PAINTING])
  677. def updateCanvasInitialPos(self):
  678. x = self.ui.graphicsView.horizontalScrollBar().value() + self.width()/4
  679. y = self.ui.graphicsView.verticalScrollBar().value() + self.height()/4
  680. patchcanvas.setInitialPos(x, y)
  681. # --------------------------------------------------------------------------------------------------------
  682. # Canvas (menu actions)
  683. @pyqtSlot()
  684. def slot_canvasShowInternal(self):
  685. self.fExternalPatchbay = False
  686. self.ui.act_canvas_show_internal.blockSignals(True)
  687. self.ui.act_canvas_show_external.blockSignals(True)
  688. self.ui.act_canvas_show_internal.setChecked(True)
  689. self.ui.act_canvas_show_external.setChecked(False)
  690. self.ui.act_canvas_show_internal.blockSignals(False)
  691. self.ui.act_canvas_show_external.blockSignals(False)
  692. self.slot_canvasRefresh()
  693. @pyqtSlot()
  694. def slot_canvasShowExternal(self):
  695. self.fExternalPatchbay = True
  696. self.ui.act_canvas_show_internal.blockSignals(True)
  697. self.ui.act_canvas_show_external.blockSignals(True)
  698. self.ui.act_canvas_show_internal.setChecked(False)
  699. self.ui.act_canvas_show_external.setChecked(True)
  700. self.ui.act_canvas_show_internal.blockSignals(False)
  701. self.ui.act_canvas_show_external.blockSignals(False)
  702. self.slot_canvasRefresh()
  703. @pyqtSlot()
  704. def slot_canvasArrange(self):
  705. patchcanvas.arrange()
  706. @pyqtSlot()
  707. def slot_canvasRefresh(self):
  708. patchcanvas.clear()
  709. if self.host.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK and self.host.isPlugin:
  710. return
  711. if self.host.is_engine_running():
  712. self.host.patchbay_refresh(self.fExternalPatchbay)
  713. QTimer.singleShot(self.fMiniCanvasUpdateTimeout, self.ui.miniCanvasPreview.update)
  714. @pyqtSlot()
  715. def slot_canvasZoomFit(self):
  716. self.scene.zoom_fit()
  717. @pyqtSlot()
  718. def slot_canvasZoomIn(self):
  719. self.scene.zoom_in()
  720. @pyqtSlot()
  721. def slot_canvasZoomOut(self):
  722. self.scene.zoom_out()
  723. @pyqtSlot()
  724. def slot_canvasZoomReset(self):
  725. self.scene.zoom_reset()
  726. @pyqtSlot()
  727. def slot_canvasPrint(self):
  728. self.scene.clearSelection()
  729. dialog = QPrintDialog(self.fExportPrinter, self)
  730. if dialog.exec_():
  731. painter = QPainter(self.fExportPrinter)
  732. painter.save()
  733. painter.setRenderHint(QPainter.Antialiasing)
  734. painter.setRenderHint(QPainter.TextAntialiasing)
  735. self.scene.render(painter)
  736. painter.restore()
  737. @pyqtSlot()
  738. def slot_canvasSaveImage(self):
  739. newPath = QFileDialog.getSaveFileName(self, self.tr("Save Image"), filter=self.tr("PNG Image (*.png);;JPEG Image (*.jpg)"))
  740. if config_UseQt5:
  741. newPath = newPath[0]
  742. if not newPath:
  743. return
  744. self.scene.clearSelection()
  745. if newPath.lower().endswith((".jpg", ".jpeg")):
  746. imgFormat = "JPG"
  747. elif newPath.lower().endswith((".png",)):
  748. imgFormat = "PNG"
  749. else:
  750. # File-dialog may not auto-add the extension
  751. imgFormat = "PNG"
  752. newPath += ".png"
  753. self.fExportImage = QImage(self.scene.sceneRect().width(), self.scene.sceneRect().height(), QImage.Format_RGB32)
  754. painter = QPainter(self.fExportImage)
  755. painter.save()
  756. painter.setRenderHint(QPainter.Antialiasing) # TODO - set true, cleanup this
  757. painter.setRenderHint(QPainter.TextAntialiasing)
  758. self.scene.render(painter)
  759. self.fExportImage.save(newPath, imgFormat, 100)
  760. painter.restore()
  761. # --------------------------------------------------------------------------------------------------------
  762. # Canvas (canvas callbacks)
  763. @pyqtSlot(int, int, QPointF)
  764. def slot_canvasItemMoved(self, group_id, split_mode, pos):
  765. self.ui.miniCanvasPreview.update()
  766. @pyqtSlot(float)
  767. def slot_canvasScaleChanged(self, scale):
  768. self.ui.miniCanvasPreview.setViewScale(scale)
  769. @pyqtSlot(list)
  770. def slot_canvasPluginSelected(self, pluginList):
  771. self.ui.keyboard.allNotesOff(False)
  772. self.ui.scrollArea.setEnabled(len(pluginList) != 0) # and self.fPluginCount > 0
  773. self.fSelectedPlugins = pluginList
  774. # --------------------------------------------------------------------------------------------------------
  775. # Canvas (host callbacks)
  776. @pyqtSlot(int, int, int, str)
  777. def slot_handlePatchbayClientAddedCallback(self, clientId, clientIcon, pluginId, clientName):
  778. pcSplit = patchcanvas.SPLIT_UNDEF
  779. pcIcon = patchcanvas.ICON_APPLICATION
  780. if clientIcon == PATCHBAY_ICON_PLUGIN:
  781. pcIcon = patchcanvas.ICON_PLUGIN
  782. if clientIcon == PATCHBAY_ICON_HARDWARE:
  783. pcIcon = patchcanvas.ICON_HARDWARE
  784. elif clientIcon == PATCHBAY_ICON_CARLA:
  785. pass
  786. elif clientIcon == PATCHBAY_ICON_DISTRHO:
  787. pcIcon = patchcanvas.ICON_DISTRHO
  788. elif clientIcon == PATCHBAY_ICON_FILE:
  789. pcIcon = patchcanvas.ICON_FILE
  790. patchcanvas.addGroup(clientId, clientName, pcSplit, pcIcon)
  791. QTimer.singleShot(self.fMiniCanvasUpdateTimeout, self.ui.miniCanvasPreview.update)
  792. if pluginId < 0:
  793. return
  794. if pluginId >= self.fPluginCount:
  795. print("sorry, can't map this plugin to canvas client", pluginId, self.fPluginCount)
  796. return
  797. patchcanvas.setGroupAsPlugin(clientId, pluginId, bool(self.host.get_plugin_info(pluginId)['hints'] & PLUGIN_HAS_CUSTOM_UI))
  798. @pyqtSlot(int)
  799. def slot_handlePatchbayClientRemovedCallback(self, clientId):
  800. patchcanvas.removeGroup(clientId)
  801. QTimer.singleShot(self.fMiniCanvasUpdateTimeout, self.ui.miniCanvasPreview.update)
  802. @pyqtSlot(int, str)
  803. def slot_handlePatchbayClientRenamedCallback(self, clientId, newClientName):
  804. patchcanvas.renameGroup(clientId, newClientName)
  805. QTimer.singleShot(self.fMiniCanvasUpdateTimeout, self.ui.miniCanvasPreview.update)
  806. @pyqtSlot(int, int, int)
  807. def slot_handlePatchbayClientDataChangedCallback(self, clientId, clientIcon, pluginId):
  808. pcIcon = patchcanvas.ICON_APPLICATION
  809. if clientIcon == PATCHBAY_ICON_PLUGIN:
  810. pcIcon = patchcanvas.ICON_PLUGIN
  811. if clientIcon == PATCHBAY_ICON_HARDWARE:
  812. pcIcon = patchcanvas.ICON_HARDWARE
  813. elif clientIcon == PATCHBAY_ICON_CARLA:
  814. pass
  815. elif clientIcon == PATCHBAY_ICON_DISTRHO:
  816. pcIcon = patchcanvas.ICON_DISTRHO
  817. elif clientIcon == PATCHBAY_ICON_FILE:
  818. pcIcon = patchcanvas.ICON_FILE
  819. patchcanvas.setGroupIcon(clientId, pcIcon)
  820. QTimer.singleShot(self.fMiniCanvasUpdateTimeout, self.ui.miniCanvasPreview.update)
  821. if pluginId < 0:
  822. return
  823. if pluginId >= self.fPluginCount:
  824. print("sorry, can't map this plugin to canvas client", pluginId, self.fPluginCount)
  825. return
  826. patchcanvas.setGroupAsPlugin(clientId, pluginId, bool(self.host.get_plugin_info(pluginId)['hints'] & PLUGIN_HAS_CUSTOM_UI))
  827. @pyqtSlot(int, int, int, str)
  828. def slot_handlePatchbayPortAddedCallback(self, clientId, portId, portFlags, portName):
  829. if portFlags & PATCHBAY_PORT_IS_INPUT:
  830. portMode = patchcanvas.PORT_MODE_INPUT
  831. else:
  832. portMode = patchcanvas.PORT_MODE_OUTPUT
  833. if portFlags & PATCHBAY_PORT_TYPE_AUDIO:
  834. portType = patchcanvas.PORT_TYPE_AUDIO_JACK
  835. isAlternate = False
  836. elif portFlags & PATCHBAY_PORT_TYPE_CV:
  837. portType = patchcanvas.PORT_TYPE_AUDIO_JACK
  838. isAlternate = True
  839. elif portFlags & PATCHBAY_PORT_TYPE_MIDI:
  840. portType = patchcanvas.PORT_TYPE_MIDI_JACK
  841. isAlternate = False
  842. else:
  843. portType = patchcanvas.PORT_TYPE_NULL
  844. isAlternate = False
  845. patchcanvas.addPort(clientId, portId, portName, portMode, portType, isAlternate)
  846. QTimer.singleShot(self.fMiniCanvasUpdateTimeout, self.ui.miniCanvasPreview.update)
  847. @pyqtSlot(int, int)
  848. def slot_handlePatchbayPortRemovedCallback(self, groupId, portId):
  849. patchcanvas.removePort(groupId, portId)
  850. QTimer.singleShot(self.fMiniCanvasUpdateTimeout, self.ui.miniCanvasPreview.update)
  851. @pyqtSlot(int, int, str)
  852. def slot_handlePatchbayPortRenamedCallback(self, groupId, portId, newPortName):
  853. patchcanvas.renamePort(groupId, portId, newPortName)
  854. QTimer.singleShot(self.fMiniCanvasUpdateTimeout, self.ui.miniCanvasPreview.update)
  855. @pyqtSlot(int, int, int, int, int)
  856. def slot_handlePatchbayConnectionAddedCallback(self, connectionId, groupOutId, portOutId, groupInId, portInId):
  857. patchcanvas.connectPorts(connectionId, groupOutId, portOutId, groupInId, portInId)
  858. QTimer.singleShot(self.fMiniCanvasUpdateTimeout, self.ui.miniCanvasPreview.update)
  859. @pyqtSlot(int, int, int)
  860. def slot_handlePatchbayConnectionRemovedCallback(self, connectionId, portOutId, portInId):
  861. patchcanvas.disconnectPorts(connectionId)
  862. QTimer.singleShot(self.fMiniCanvasUpdateTimeout, self.ui.miniCanvasPreview.update)
  863. # --------------------------------------------------------------------------------------------------------
  864. # Settings
  865. def setEngineSettings(self):
  866. settings = QSettings("falkTX", "Carla2")
  867. # ----------------------------------------------------------------------------------------------------
  868. # main settings
  869. setHostSettings(self.host)
  870. # ----------------------------------------------------------------------------------------------------
  871. # plugin paths
  872. LADSPA_PATH = toList(settings.value(CARLA_KEY_PATHS_LADSPA, CARLA_DEFAULT_LADSPA_PATH))
  873. DSSI_PATH = toList(settings.value(CARLA_KEY_PATHS_DSSI, CARLA_DEFAULT_DSSI_PATH))
  874. LV2_PATH = toList(settings.value(CARLA_KEY_PATHS_LV2, CARLA_DEFAULT_LV2_PATH))
  875. VST2_PATH = toList(settings.value(CARLA_KEY_PATHS_VST2, CARLA_DEFAULT_VST2_PATH))
  876. VST3_PATH = toList(settings.value(CARLA_KEY_PATHS_VST3, CARLA_DEFAULT_VST3_PATH))
  877. AU_PATH = toList(settings.value(CARLA_KEY_PATHS_AU, CARLA_DEFAULT_AU_PATH))
  878. GIG_PATH = toList(settings.value(CARLA_KEY_PATHS_GIG, CARLA_DEFAULT_GIG_PATH))
  879. SF2_PATH = toList(settings.value(CARLA_KEY_PATHS_SF2, CARLA_DEFAULT_SF2_PATH))
  880. SFZ_PATH = toList(settings.value(CARLA_KEY_PATHS_SFZ, CARLA_DEFAULT_SFZ_PATH))
  881. self.host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_LADSPA, splitter.join(LADSPA_PATH))
  882. self.host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_DSSI, splitter.join(DSSI_PATH))
  883. self.host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_LV2, splitter.join(LV2_PATH))
  884. self.host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_VST2, splitter.join(VST2_PATH))
  885. self.host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_VST3, splitter.join(VST3_PATH))
  886. self.host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_AU, splitter.join(AU_PATH))
  887. self.host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_GIG, splitter.join(GIG_PATH))
  888. self.host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_SF2, splitter.join(SF2_PATH))
  889. self.host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_SFZ, splitter.join(SFZ_PATH))
  890. # ----------------------------------------------------------------------------------------------------
  891. # don't continue if plugin
  892. if self.host.isPlugin:
  893. return "Plugin"
  894. # ----------------------------------------------------------------------------------------------------
  895. # driver and device settings
  896. # driver name
  897. try:
  898. audioDriver = settings.value(CARLA_KEY_ENGINE_AUDIO_DRIVER, CARLA_DEFAULT_AUDIO_DRIVER, type=str)
  899. except:
  900. audioDriver = CARLA_DEFAULT_AUDIO_DRIVER
  901. # driver options
  902. try:
  903. audioDevice = settings.value("%s%s/Device" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), "", type=str)
  904. except:
  905. audioDevice = ""
  906. try:
  907. audioNumPeriods = settings.value("%s%s/NumPeriods" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_NUM_PERIODS, type=int)
  908. except:
  909. audioNumPeriods = CARLA_DEFAULT_AUDIO_NUM_PERIODS
  910. try:
  911. audioBufferSize = settings.value("%s%s/BufferSize" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_BUFFER_SIZE, type=int)
  912. except:
  913. audioBufferSize = CARLA_DEFAULT_AUDIO_BUFFER_SIZE
  914. try:
  915. audioSampleRate = settings.value("%s%s/SampleRate" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_SAMPLE_RATE, type=int)
  916. except:
  917. audioSampleRate = CARLA_DEFAULT_AUDIO_SAMPLE_RATE
  918. self.host.set_engine_option(ENGINE_OPTION_AUDIO_DEVICE, 0, audioDevice)
  919. self.host.set_engine_option(ENGINE_OPTION_AUDIO_NUM_PERIODS, audioNumPeriods, "")
  920. self.host.set_engine_option(ENGINE_OPTION_AUDIO_BUFFER_SIZE, audioBufferSize, "")
  921. self.host.set_engine_option(ENGINE_OPTION_AUDIO_SAMPLE_RATE, audioSampleRate, "")
  922. # ----------------------------------------------------------------------------------------------------
  923. # fix things if needed
  924. if audioDriver != "JACK" and self.host.transportMode == ENGINE_TRANSPORT_MODE_JACK:
  925. self.host.transportMode = ENGINE_TRANSPORT_MODE_INTERNAL
  926. self.host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE, ENGINE_TRANSPORT_MODE_INTERNAL, "")
  927. # ----------------------------------------------------------------------------------------------------
  928. # return selected driver name
  929. return audioDriver
  930. def saveSettings(self):
  931. settings = QSettings()
  932. settings.setValue("Geometry", self.saveGeometry())
  933. #settings.setValue("SplitterState", self.ui.splitter.saveState())
  934. settings.setValue("ShowToolbar", self.ui.toolBar.isVisible())
  935. diskFolders = []
  936. for i in range(self.ui.cb_disk.count()):
  937. diskFolders.append(self.ui.cb_disk.itemData(i))
  938. settings.setValue("DiskFolders", diskFolders)
  939. settings.setValue("ShowMeters", self.ui.act_settings_show_meters.isChecked())
  940. settings.setValue("ShowKeyboard", self.ui.act_settings_show_keyboard.isChecked())
  941. settings.setValue("HorizontalScrollBarValue", self.ui.graphicsView.horizontalScrollBar().value())
  942. settings.setValue("VerticalScrollBarValue", self.ui.graphicsView.verticalScrollBar().value())
  943. def loadSettings(self, firstTime):
  944. settings = QSettings()
  945. if firstTime:
  946. self.restoreGeometry(settings.value("Geometry", ""))
  947. showToolbar = settings.value("ShowToolbar", True, type=bool)
  948. self.ui.act_settings_show_toolbar.setChecked(showToolbar)
  949. self.ui.toolBar.setVisible(showToolbar)
  950. #if settings.contains("SplitterState"):
  951. #self.ui.splitter.restoreState(settings.value("SplitterState", ""))
  952. #else:
  953. #self.ui.splitter.setSizes([210, 99999])
  954. diskFolders = toList(settings.value("DiskFolders", [HOME]))
  955. self.ui.cb_disk.setItemData(0, HOME)
  956. for i in range(len(diskFolders)):
  957. if i == 0: continue
  958. folder = diskFolders[i]
  959. self.ui.cb_disk.addItem(os.path.basename(folder), folder)
  960. #if MACOS and not settings.value(CARLA_KEY_MAIN_USE_PRO_THEME, True, type=bool):
  961. # self.setUnifiedTitleAndToolBarOnMac(True)
  962. showMeters = settings.value("ShowMeters", False, type=bool)
  963. self.ui.act_settings_show_meters.setChecked(showMeters)
  964. self.ui.peak_in.setVisible(showMeters)
  965. self.ui.peak_out.setVisible(showMeters)
  966. showKeyboard = settings.value("ShowKeyboard", not(MACOS or WINDOWS), type=bool)
  967. self.ui.act_settings_show_keyboard.setChecked(showKeyboard)
  968. self.ui.scrollArea.setVisible(showKeyboard)
  969. QTimer.singleShot(100, self.slot_restoreCanvasScrollbarValues)
  970. # TODO - complete this
  971. self.fSavedSettings = {
  972. CARLA_KEY_MAIN_PROJECT_FOLDER: settings.value(CARLA_KEY_MAIN_PROJECT_FOLDER, CARLA_DEFAULT_MAIN_PROJECT_FOLDER, type=str),
  973. CARLA_KEY_MAIN_REFRESH_INTERVAL: settings.value(CARLA_KEY_MAIN_REFRESH_INTERVAL, CARLA_DEFAULT_MAIN_REFRESH_INTERVAL, type=int),
  974. CARLA_KEY_MAIN_USE_CUSTOM_SKINS: settings.value(CARLA_KEY_MAIN_USE_CUSTOM_SKINS, CARLA_DEFAULT_MAIN_USE_CUSTOM_SKINS, type=bool),
  975. CARLA_KEY_CANVAS_THEME: settings.value(CARLA_KEY_CANVAS_THEME, CARLA_DEFAULT_CANVAS_THEME, type=str),
  976. CARLA_KEY_CANVAS_SIZE: settings.value(CARLA_KEY_CANVAS_SIZE, CARLA_DEFAULT_CANVAS_SIZE, type=str),
  977. CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS: settings.value(CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS, CARLA_DEFAULT_CANVAS_AUTO_HIDE_GROUPS, type=bool),
  978. CARLA_KEY_CANVAS_USE_BEZIER_LINES: settings.value(CARLA_KEY_CANVAS_USE_BEZIER_LINES, CARLA_DEFAULT_CANVAS_USE_BEZIER_LINES, type=bool),
  979. CARLA_KEY_CANVAS_EYE_CANDY: settings.value(CARLA_KEY_CANVAS_EYE_CANDY, CARLA_DEFAULT_CANVAS_EYE_CANDY, type=int),
  980. CARLA_KEY_CANVAS_USE_OPENGL: settings.value(CARLA_KEY_CANVAS_USE_OPENGL, CARLA_DEFAULT_CANVAS_USE_OPENGL, type=bool),
  981. CARLA_KEY_CANVAS_ANTIALIASING: settings.value(CARLA_KEY_CANVAS_ANTIALIASING, CARLA_DEFAULT_CANVAS_ANTIALIASING, type=int),
  982. CARLA_KEY_CANVAS_HQ_ANTIALIASING: settings.value(CARLA_KEY_CANVAS_HQ_ANTIALIASING, CARLA_DEFAULT_CANVAS_HQ_ANTIALIASING, type=bool),
  983. CARLA_KEY_CUSTOM_PAINTING: (settings.value(CARLA_KEY_MAIN_USE_PRO_THEME, True, type=bool) and
  984. settings.value(CARLA_KEY_MAIN_PRO_THEME_COLOR, "Black", type=str).lower() == "black")
  985. }
  986. self.fMiniCanvasUpdateTimeout = 1000 if self.fSavedSettings[CARLA_KEY_CANVAS_EYE_CANDY] == patchcanvas.EYECANDY_FULL else 0
  987. self.setEngineSettings()
  988. self.restartTimersIfNeeded()
  989. # --------------------------------------------------------------------------------------------------------
  990. # Settings (helpers)
  991. @pyqtSlot()
  992. def slot_restoreCanvasScrollbarValues(self):
  993. settings = QSettings()
  994. self.ui.graphicsView.horizontalScrollBar().setValue(settings.value("HorizontalScrollBarValue", self.ui.graphicsView.horizontalScrollBar().maximum()/2, type=int))
  995. self.ui.graphicsView.verticalScrollBar().setValue(settings.value("VerticalScrollBarValue", self.ui.graphicsView.verticalScrollBar().maximum()/2, type=int))
  996. # --------------------------------------------------------------------------------------------------------
  997. # Settings (menu actions)
  998. @pyqtSlot(bool)
  999. def slot_showCanvasMeters(self, yesNo):
  1000. self.ui.peak_in.setVisible(yesNo)
  1001. self.ui.peak_out.setVisible(yesNo)
  1002. QTimer.singleShot(0, self.slot_miniCanvasCheckAll)
  1003. @pyqtSlot(bool)
  1004. def slot_showCanvasKeyboard(self, yesNo):
  1005. self.ui.scrollArea.setVisible(yesNo)
  1006. QTimer.singleShot(0, self.slot_miniCanvasCheckAll)
  1007. @pyqtSlot()
  1008. def slot_configureCarla(self):
  1009. dialog = CarlaSettingsW(self, self.host, True, hasGL)
  1010. if not dialog.exec_():
  1011. return
  1012. self.loadSettings(False)
  1013. patchcanvas.clear()
  1014. self.setupCanvas()
  1015. self.slot_miniCanvasCheckAll()
  1016. if self.host.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK and self.host.isPlugin:
  1017. pass
  1018. elif self.host.is_engine_running():
  1019. self.host.patchbay_refresh(self.fExternalPatchbay)
  1020. # --------------------------------------------------------------------------------------------------------
  1021. # About (menu actions)
  1022. @pyqtSlot()
  1023. def slot_aboutCarla(self):
  1024. CarlaAboutW(self, self.host).exec_()
  1025. @pyqtSlot()
  1026. def slot_aboutJuce(self):
  1027. JuceAboutW(self).exec_()
  1028. @pyqtSlot()
  1029. def slot_aboutQt(self):
  1030. QApplication.instance().aboutQt()
  1031. # --------------------------------------------------------------------------------------------------------
  1032. # Disk (menu actions)
  1033. @pyqtSlot(int)
  1034. def slot_diskFolderChanged(self, index):
  1035. if index < 0:
  1036. return
  1037. elif index == 0:
  1038. filename = HOME
  1039. self.ui.b_disk_remove.setEnabled(False)
  1040. else:
  1041. filename = self.ui.cb_disk.itemData(index)
  1042. self.ui.b_disk_remove.setEnabled(True)
  1043. self.fDirModel.setRootPath(filename)
  1044. self.ui.fileTreeView.setRootIndex(self.fDirModel.index(filename))
  1045. @pyqtSlot()
  1046. def slot_diskFolderAdd(self):
  1047. newPath = QFileDialog.getExistingDirectory(self, self.tr("New Folder"), "", QFileDialog.ShowDirsOnly)
  1048. if newPath:
  1049. if newPath[-1] == os.sep:
  1050. newPath = newPath[:-1]
  1051. self.ui.cb_disk.addItem(os.path.basename(newPath), newPath)
  1052. self.ui.cb_disk.setCurrentIndex(self.ui.cb_disk.count()-1)
  1053. self.ui.b_disk_remove.setEnabled(True)
  1054. @pyqtSlot()
  1055. def slot_diskFolderRemove(self):
  1056. index = self.ui.cb_disk.currentIndex()
  1057. if index <= 0:
  1058. return
  1059. self.ui.cb_disk.removeItem(index)
  1060. if self.ui.cb_disk.currentIndex() == 0:
  1061. self.ui.b_disk_remove.setEnabled(False)
  1062. @pyqtSlot(QModelIndex)
  1063. def slot_fileTreeDoubleClicked(self, modelIndex):
  1064. filename = self.fDirModel.filePath(modelIndex)
  1065. if not self.host.load_file(filename):
  1066. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"),
  1067. self.tr("Failed to load file"),
  1068. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1069. # --------------------------------------------------------------------------------------------------------
  1070. # Canvas scrollbars
  1071. @pyqtSlot(int)
  1072. def slot_horizontalScrollBarChanged(self, value):
  1073. maximum = self.ui.graphicsView.horizontalScrollBar().maximum()
  1074. if maximum == 0:
  1075. xp = 0
  1076. else:
  1077. xp = float(value) / maximum
  1078. self.ui.miniCanvasPreview.setViewPosX(xp)
  1079. self.updateCanvasInitialPos()
  1080. @pyqtSlot(int)
  1081. def slot_verticalScrollBarChanged(self, value):
  1082. maximum = self.ui.graphicsView.verticalScrollBar().maximum()
  1083. if maximum == 0:
  1084. yp = 0
  1085. else:
  1086. yp = float(value) / maximum
  1087. self.ui.miniCanvasPreview.setViewPosY(yp)
  1088. self.updateCanvasInitialPos()
  1089. # --------------------------------------------------------------------------------------------------------
  1090. # Canvas keyboard
  1091. @pyqtSlot(int)
  1092. def slot_noteOn(self, note):
  1093. for pluginId in self.fSelectedPlugins:
  1094. self.host.send_midi_note(pluginId, 0, note, 100)
  1095. pedit = self.getPluginEditDialog(pluginId)
  1096. pedit.noteOn(0, note, 100)
  1097. @pyqtSlot(int)
  1098. def slot_noteOff(self, note):
  1099. for pluginId in self.fSelectedPlugins:
  1100. self.host.send_midi_note(pluginId, 0, note, 0)
  1101. pedit = self.getPluginEditDialog(pluginId)
  1102. pedit.noteOff(0, note)
  1103. # --------------------------------------------------------------------------------------------------------
  1104. # Canvas keyboard (host callbacks)
  1105. @pyqtSlot(int, int, int, int)
  1106. def slot_handleNoteOnCallback(self, pluginId, channel, note, velocity):
  1107. if pluginId in self.fSelectedPlugins:
  1108. self.ui.keyboard.sendNoteOn(note, False)
  1109. @pyqtSlot(int, int, int)
  1110. def slot_handleNoteOffCallback(self, pluginId, channel, note):
  1111. if pluginId in self.fSelectedPlugins:
  1112. self.ui.keyboard.sendNoteOff(note, False)
  1113. # --------------------------------------------------------------------------------------------------------
  1114. # MiniCanvas stuff
  1115. @pyqtSlot()
  1116. def slot_miniCanvasCheckAll(self):
  1117. self.slot_miniCanvasCheckSize()
  1118. self.slot_horizontalScrollBarChanged(self.ui.graphicsView.horizontalScrollBar().value())
  1119. self.slot_verticalScrollBarChanged(self.ui.graphicsView.verticalScrollBar().value())
  1120. @pyqtSlot()
  1121. def slot_miniCanvasCheckSize(self):
  1122. if self.fCanvasWidth == 0 or self.fCanvasHeight == 0:
  1123. return
  1124. if self.ui.tabWidget.currentIndex() == 1:
  1125. width = self.ui.graphicsView.width()
  1126. height = self.ui.graphicsView.height()
  1127. else:
  1128. self.ui.tabWidget.blockSignals(True)
  1129. self.ui.tabWidget.setCurrentIndex(1)
  1130. width = self.ui.graphicsView.width()
  1131. height = self.ui.graphicsView.height()
  1132. self.ui.tabWidget.setCurrentIndex(0)
  1133. self.ui.tabWidget.blockSignals(False)
  1134. self.ui.miniCanvasPreview.setViewSize(float(width)/self.fCanvasWidth, float(height)/self.fCanvasHeight)
  1135. @pyqtSlot(float, float)
  1136. def slot_miniCanvasMoved(self, xp, yp):
  1137. hsb = self.ui.graphicsView.horizontalScrollBar()
  1138. vsb = self.ui.graphicsView.verticalScrollBar()
  1139. hsb.setValue(xp * hsb.maximum())
  1140. vsb.setValue(yp * vsb.maximum())
  1141. self.updateCanvasInitialPos()
  1142. # --------------------------------------------------------------------------------------------------------
  1143. # Rack stuff
  1144. @pyqtSlot(int)
  1145. def slot_currentRowChanged(self, row):
  1146. self.fCurrentRow = row
  1147. if self.fLastSelectedItem is not None:
  1148. self.fLastSelectedItem.setSelected(False)
  1149. if row < 0 or row >= self.fPluginCount or self.fPluginList[row] is None:
  1150. self.fLastSelectedItem = None
  1151. return
  1152. pitem = self.fPluginList[row]
  1153. pitem.getWidget().setSelected(True)
  1154. self.fLastSelectedItem = pitem.getWidget()
  1155. # --------------------------------------------------------------------------------------------------------
  1156. # Timers
  1157. def startTimers(self):
  1158. if self.fIdleTimerFast == 0:
  1159. self.fIdleTimerFast = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL])
  1160. if self.fIdleTimerSlow == 0:
  1161. self.fIdleTimerSlow = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL]*4)
  1162. def restartTimersIfNeeded(self):
  1163. if self.fIdleTimerFast != 0:
  1164. self.killTimer(self.fIdleTimerFast)
  1165. self.fIdleTimerFast = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL])
  1166. if self.fIdleTimerSlow != 0:
  1167. self.killTimer(self.fIdleTimerSlow)
  1168. self.fIdleTimerSlow = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL]*4)
  1169. def killTimers(self):
  1170. if self.fIdleTimerFast != 0:
  1171. self.killTimer(self.fIdleTimerFast)
  1172. self.fIdleTimerFast = 0
  1173. if self.fIdleTimerSlow != 0:
  1174. self.killTimer(self.fIdleTimerSlow)
  1175. self.fIdleTimerSlow = 0
  1176. # --------------------------------------------------------------------------------------------------------
  1177. # Misc
  1178. @pyqtSlot(int)
  1179. def slot_tabChanged(self, index):
  1180. if index != 1:
  1181. return
  1182. self.ui.graphicsView.setFocus()
  1183. @pyqtSlot(int)
  1184. def slot_handleReloadAllCallback(self, pluginId):
  1185. if pluginId >= self.fPluginCount:
  1186. return
  1187. pitem = self.fPluginList[pluginId]
  1188. if pitem is None:
  1189. return
  1190. self.ui.listWidget.setCurrentRow(-1)
  1191. self.fCurrentRow = -1
  1192. self.fLastSelectedItem = None
  1193. pitem.recreateWidget()
  1194. # --------------------------------------------------------------------------------------------------------
  1195. @pyqtSlot(int, int, int, float, str)
  1196. def slot_handleDebugCallback(self, pluginId, value1, value2, value3, valueStr):
  1197. print("DEBUG:", pluginId, value1, value2, value3, valueStr)
  1198. @pyqtSlot(str)
  1199. def slot_handleInfoCallback(self, info):
  1200. QMessageBox.information(self, "Information", info)
  1201. @pyqtSlot(str)
  1202. def slot_handleErrorCallback(self, error):
  1203. QMessageBox.critical(self, "Error", error)
  1204. @pyqtSlot()
  1205. def slot_handleQuitCallback(self):
  1206. pass # TODO
  1207. # --------------------------------------------------------------------------------------------------------
  1208. @pyqtSlot()
  1209. def slot_handleSIGUSR1(self):
  1210. print("Got SIGUSR1 -> Saving project now")
  1211. self.slot_fileSave()
  1212. @pyqtSlot()
  1213. def slot_handleSIGTERM(self):
  1214. print("Got SIGTERM -> Closing now")
  1215. self.close()
  1216. # --------------------------------------------------------------------------------------------------------
  1217. # Internal stuff
  1218. def getExtraPtr(self, plugin):
  1219. ptype = plugin['type']
  1220. if ptype == PLUGIN_LADSPA:
  1221. uniqueId = plugin['uniqueId']
  1222. self.maybeLoadRDFs()
  1223. for rdfItem in self.fLadspaRdfList:
  1224. if rdfItem.UniqueID == uniqueId:
  1225. return pointer(rdfItem)
  1226. elif ptype in (PLUGIN_GIG, PLUGIN_SF2):
  1227. if plugin['name'].lower().endswith(" (16 outputs)"):
  1228. return self._true
  1229. return None
  1230. def maybeLoadRDFs(self):
  1231. if not self.fLadspaRdfNeedsUpdate:
  1232. return
  1233. self.fLadspaRdfNeedsUpdate = False
  1234. self.fLadspaRdfList = []
  1235. if not haveLRDF:
  1236. return
  1237. settingsDir = os.path.join(HOME, ".config", "falkTX")
  1238. frLadspaFile = os.path.join(settingsDir, "ladspa_rdf.db")
  1239. if os.path.exists(frLadspaFile):
  1240. frLadspa = open(frLadspaFile, 'r')
  1241. try:
  1242. self.fLadspaRdfList = ladspa_rdf.get_c_ladspa_rdfs(json.load(frLadspa))
  1243. except:
  1244. pass
  1245. frLadspa.close()
  1246. # --------------------------------------------------------------------------------------------------------
  1247. def getPluginItem(self, pluginId):
  1248. if pluginId >= self.fPluginCount:
  1249. return None
  1250. pitem = self.fPluginList[pluginId]
  1251. if pitem is None:
  1252. return None
  1253. #if False:
  1254. #return CarlaRackItem(self, 0, False)
  1255. return pitem
  1256. def getPluginEditDialog(self, pluginId):
  1257. if pluginId >= self.fPluginCount:
  1258. return None
  1259. pitem = self.fPluginList[pluginId]
  1260. if pitem is None:
  1261. return None
  1262. if False:
  1263. return PluginEdit(self, self.host, 0)
  1264. return pitem.getEditDialog()
  1265. def getPluginSlotWidget(self, pluginId):
  1266. if pluginId >= self.fPluginCount:
  1267. return None
  1268. pitem = self.fPluginList[pluginId]
  1269. if pitem is None:
  1270. return None
  1271. #if False:
  1272. #return AbstractPluginSlot()
  1273. return pitem.getWidget()
  1274. # --------------------------------------------------------------------------------------------------------
  1275. # show/hide event
  1276. def showEvent(self, event):
  1277. QMainWindow.showEvent(self, event)
  1278. # set our gui as parent for all plugins UIs
  1279. winIdStr = "%x" % self.winId()
  1280. self.host.set_engine_option(ENGINE_OPTION_FRONTEND_WIN_ID, 0, winIdStr)
  1281. def hideEvent(self, event):
  1282. # disable parent
  1283. self.host.set_engine_option(ENGINE_OPTION_FRONTEND_WIN_ID, 0, "0")
  1284. QMainWindow.hideEvent(self, event)
  1285. # --------------------------------------------------------------------------------------------------------
  1286. # resize event
  1287. def fixCanvasPreviewSize(self):
  1288. self.ui.patchbay.resize(self.ui.rack.size())
  1289. self.slot_miniCanvasCheckSize()
  1290. def resizeEvent(self, event):
  1291. QMainWindow.resizeEvent(self, event)
  1292. if self.ui.tabWidget.currentIndex() != 1:
  1293. size = self.ui.rack.size()
  1294. self.ui.patchbay.resize(size)
  1295. self.slot_miniCanvasCheckSize()
  1296. # --------------------------------------------------------------------------------------------------------
  1297. # timer event
  1298. def idleFast(self):
  1299. self.host.engine_idle()
  1300. self.fPanelTime.refreshTransport()
  1301. if self.fPluginCount == 0 or self.fCurrentlyRemovingAllPlugins:
  1302. return
  1303. for pitem in self.fPluginList:
  1304. if pitem is None:
  1305. break
  1306. pitem.getWidget().idleFast()
  1307. for pluginId in self.fSelectedPlugins:
  1308. self.fPeaksCleared = False
  1309. if self.ui.peak_in.isVisible():
  1310. self.ui.peak_in.displayMeter(1, self.host.get_input_peak_value(pluginId, True))
  1311. self.ui.peak_in.displayMeter(2, self.host.get_input_peak_value(pluginId, False))
  1312. if self.ui.peak_out.isVisible():
  1313. self.ui.peak_out.displayMeter(1, self.host.get_output_peak_value(pluginId, True))
  1314. self.ui.peak_out.displayMeter(2, self.host.get_output_peak_value(pluginId, False))
  1315. return
  1316. if self.fPeaksCleared:
  1317. return
  1318. self.fPeaksCleared = True
  1319. self.ui.peak_in.displayMeter(1, 0.0, True)
  1320. self.ui.peak_in.displayMeter(2, 0.0, True)
  1321. self.ui.peak_out.displayMeter(1, 0.0, True)
  1322. self.ui.peak_out.displayMeter(2, 0.0, True)
  1323. def idleSlow(self):
  1324. if self.fPluginCount == 0 or self.fCurrentlyRemovingAllPlugins:
  1325. return
  1326. for pitem in self.fPluginList:
  1327. if pitem is None:
  1328. break
  1329. pitem.getWidget().idleSlow()
  1330. def timerEvent(self, event):
  1331. if event.timerId() == self.fIdleTimerFast:
  1332. self.idleFast()
  1333. elif event.timerId() == self.fIdleTimerSlow:
  1334. self.idleSlow()
  1335. QMainWindow.timerEvent(self, event)
  1336. # --------------------------------------------------------------------------------------------------------
  1337. # paint event
  1338. #def paintEvent(self, event):
  1339. #QMainWindow.paintEvent(self, event)
  1340. #if MACOS or not self.fSavedSettings[CARLA_KEY_CUSTOM_PAINTING]:
  1341. #return
  1342. #painter = QPainter(self)
  1343. #painter.setBrush(QColor(36, 36, 36))
  1344. #painter.setPen(QColor(62, 62, 62))
  1345. #painter.drawRect(1, self.height()/2, self.width()-3, self.height()-self.height()/2-1)
  1346. # --------------------------------------------------------------------------------------------------------
  1347. # close event
  1348. def closeEvent(self, event):
  1349. self.killTimers()
  1350. self.saveSettings()
  1351. if self.host.is_engine_running() and not self.host.isPlugin:
  1352. self.slot_engineStop(True)
  1353. QMainWindow.closeEvent(self, event)
  1354. # ------------------------------------------------------------------------------------------------
  1355. # Canvas callback
  1356. def canvasCallback(action, value1, value2, valueStr):
  1357. host = gCarla.gui.host
  1358. if action == patchcanvas.ACTION_GROUP_INFO:
  1359. pass
  1360. elif action == patchcanvas.ACTION_GROUP_RENAME:
  1361. pass
  1362. elif action == patchcanvas.ACTION_GROUP_SPLIT:
  1363. groupId = value1
  1364. patchcanvas.splitGroup(groupId)
  1365. gCarla.gui.ui.miniCanvasPreview.update()
  1366. elif action == patchcanvas.ACTION_GROUP_JOIN:
  1367. groupId = value1
  1368. patchcanvas.joinGroup(groupId)
  1369. gCarla.gui.ui.miniCanvasPreview.update()
  1370. elif action == patchcanvas.ACTION_PORT_INFO:
  1371. pass
  1372. elif action == patchcanvas.ACTION_PORT_RENAME:
  1373. pass
  1374. elif action == patchcanvas.ACTION_PORTS_CONNECT:
  1375. gOut, pOut, gIn, pIn = [int(i) for i in valueStr.split(":")]
  1376. if not host.patchbay_connect(gOut, pOut, gIn, pIn):
  1377. print("Connection failed:", host.get_last_error())
  1378. elif action == patchcanvas.ACTION_PORTS_DISCONNECT:
  1379. connectionId = value1
  1380. if not host.patchbay_disconnect(connectionId):
  1381. print("Disconnect failed:", host.get_last_error())
  1382. elif action == patchcanvas.ACTION_PLUGIN_CLONE:
  1383. pluginId = value1
  1384. if not host.clone_plugin(pluginId):
  1385. CustomMessageBox(gCarla.gui, QMessageBox.Warning, gCarla.gui.tr("Error"), gCarla.gui.tr("Operation failed"),
  1386. host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1387. elif action == patchcanvas.ACTION_PLUGIN_EDIT:
  1388. pluginId = value1
  1389. dialog = gCarla.gui.getPluginEditDialog(pluginId)
  1390. if dialog is None:
  1391. return
  1392. dialog.show()
  1393. elif action == patchcanvas.ACTION_PLUGIN_RENAME:
  1394. pluginId = value1
  1395. newName = valueStr
  1396. if not host.rename_plugin(pluginId, newName):
  1397. CustomMessageBox(gCarla.gui, QMessageBox.Warning, gCarla.gui.tr("Error"), gCarla.gui.tr("Operation failed"),
  1398. host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1399. elif action == patchcanvas.ACTION_PLUGIN_REMOVE:
  1400. pluginId = value1
  1401. if not host.remove_plugin(pluginId):
  1402. CustomMessageBox(gCarla.gui, QMessageBox.Warning, gCarla.gui.tr("Error"), gCarla.gui.tr("Operation failed"),
  1403. host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1404. elif action == patchcanvas.ACTION_PLUGIN_SHOW_UI:
  1405. pluginId = value1
  1406. host.show_custom_ui(pluginId, True)
  1407. # ------------------------------------------------------------------------------------------------------------
  1408. # Engine callback
  1409. def engineCallback(host, action, pluginId, value1, value2, value3, valueStr):
  1410. # kdevelop likes this :)
  1411. if False: host = CarlaHostMeta()
  1412. if action == ENGINE_CALLBACK_ENGINE_STARTED:
  1413. host.processMode = value1
  1414. host.transportMode = value2
  1415. elif action == ENGINE_CALLBACK_PROCESS_MODE_CHANGED:
  1416. host.processMode = value1
  1417. elif action == ENGINE_CALLBACK_TRANSPORT_MODE_CHANGED:
  1418. host.transportMode = value1
  1419. valueStr = charPtrToString(valueStr)
  1420. if action == ENGINE_CALLBACK_DEBUG:
  1421. host.DebugCallback.emit(pluginId, value1, value2, value3, valueStr)
  1422. elif action == ENGINE_CALLBACK_PLUGIN_ADDED:
  1423. host.PluginAddedCallback.emit(pluginId, valueStr)
  1424. elif action == ENGINE_CALLBACK_PLUGIN_REMOVED:
  1425. host.PluginRemovedCallback.emit(pluginId)
  1426. elif action == ENGINE_CALLBACK_PLUGIN_RENAMED:
  1427. host.PluginRenamedCallback.emit(pluginId, valueStr)
  1428. elif action == ENGINE_CALLBACK_PLUGIN_UNAVAILABLE:
  1429. host.PluginUnavailableCallback.emit(pluginId, valueStr)
  1430. elif action == ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED:
  1431. host.ParameterValueChangedCallback.emit(pluginId, value1, value3)
  1432. elif action == ENGINE_CALLBACK_PARAMETER_DEFAULT_CHANGED:
  1433. host.ParameterDefaultChangedCallback.emit(pluginId, value1, value3)
  1434. elif action == ENGINE_CALLBACK_PARAMETER_MIDI_CC_CHANGED:
  1435. host.ParameterMidiCcChangedCallback.emit(pluginId, value1, value2)
  1436. elif action == ENGINE_CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED:
  1437. host.ParameterMidiChannelChangedCallback.emit(pluginId, value1, value2)
  1438. elif action == ENGINE_CALLBACK_PROGRAM_CHANGED:
  1439. host.ProgramChangedCallback.emit(pluginId, value1)
  1440. elif action == ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED:
  1441. host.MidiProgramChangedCallback.emit(pluginId, value1)
  1442. elif action == ENGINE_CALLBACK_OPTION_CHANGED:
  1443. host.OptionChangedCallback.emit(pluginId, value1, bool(value2))
  1444. elif action == ENGINE_CALLBACK_UI_STATE_CHANGED:
  1445. host.UiStateChangedCallback.emit(pluginId, value1)
  1446. elif action == ENGINE_CALLBACK_NOTE_ON:
  1447. host.NoteOnCallback.emit(pluginId, value1, value2, int(value3))
  1448. elif action == ENGINE_CALLBACK_NOTE_OFF:
  1449. host.NoteOffCallback.emit(pluginId, value1, value2)
  1450. elif action == ENGINE_CALLBACK_UPDATE:
  1451. host.UpdateCallback.emit(pluginId)
  1452. elif action == ENGINE_CALLBACK_RELOAD_INFO:
  1453. host.ReloadInfoCallback.emit(pluginId)
  1454. elif action == ENGINE_CALLBACK_RELOAD_PARAMETERS:
  1455. host.ReloadParametersCallback.emit(pluginId)
  1456. elif action == ENGINE_CALLBACK_RELOAD_PROGRAMS:
  1457. host.ReloadProgramsCallback.emit(pluginId)
  1458. elif action == ENGINE_CALLBACK_RELOAD_ALL:
  1459. host.ReloadAllCallback.emit(pluginId)
  1460. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED:
  1461. host.PatchbayClientAddedCallback.emit(pluginId, value1, value2, valueStr)
  1462. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_REMOVED:
  1463. host.PatchbayClientRemovedCallback.emit(pluginId)
  1464. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_RENAMED:
  1465. host.PatchbayClientRenamedCallback.emit(pluginId, valueStr)
  1466. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_DATA_CHANGED:
  1467. host.PatchbayClientDataChangedCallback.emit(pluginId, value1, value2)
  1468. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_ADDED:
  1469. host.PatchbayPortAddedCallback.emit(pluginId, value1, value2, valueStr)
  1470. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_REMOVED:
  1471. host.PatchbayPortRemovedCallback.emit(pluginId, value1)
  1472. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_RENAMED:
  1473. host.PatchbayPortRenamedCallback.emit(pluginId, value1, valueStr)
  1474. elif action == ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED:
  1475. gOut, pOut, gIn, pIn = [int(i) for i in valueStr.split(":")] # FIXME
  1476. host.PatchbayConnectionAddedCallback.emit(pluginId, gOut, pOut, gIn, pIn)
  1477. elif action == ENGINE_CALLBACK_PATCHBAY_CONNECTION_REMOVED:
  1478. host.PatchbayConnectionRemovedCallback.emit(pluginId, value1, value2)
  1479. elif action == ENGINE_CALLBACK_ENGINE_STARTED:
  1480. host.EngineStartedCallback.emit(value1, value2, valueStr)
  1481. elif action == ENGINE_CALLBACK_ENGINE_STOPPED:
  1482. host.EngineStoppedCallback.emit()
  1483. elif action == ENGINE_CALLBACK_PROCESS_MODE_CHANGED:
  1484. host.ProcessModeChangedCallback.emit(value1)
  1485. elif action == ENGINE_CALLBACK_TRANSPORT_MODE_CHANGED:
  1486. host.TransportModeChangedCallback.emit(value1)
  1487. elif action == ENGINE_CALLBACK_BUFFER_SIZE_CHANGED:
  1488. host.BufferSizeChangedCallback.emit(value1)
  1489. elif action == ENGINE_CALLBACK_SAMPLE_RATE_CHANGED:
  1490. host.SampleRateChangedCallback.emit(value3)
  1491. elif action == ENGINE_CALLBACK_IDLE:
  1492. QApplication.instance().processEvents()
  1493. elif action == ENGINE_CALLBACK_INFO:
  1494. host.InfoCallback.emit(valueStr)
  1495. elif action == ENGINE_CALLBACK_ERROR:
  1496. host.ErrorCallback.emit(valueStr)
  1497. elif action == ENGINE_CALLBACK_QUIT:
  1498. host.QuitCallback.emit()
  1499. # ------------------------------------------------------------------------------------------------------------
  1500. # File callback
  1501. def fileCallback(ptr, action, isDir, title, filter):
  1502. ret = ("", "") if config_UseQt5 else ""
  1503. if action == FILE_CALLBACK_DEBUG:
  1504. pass
  1505. elif action == FILE_CALLBACK_OPEN:
  1506. ret = QFileDialog.getOpenFileName(gCarla.gui, charPtrToString(title), "", charPtrToString(filter) ) #, QFileDialog.ShowDirsOnly if isDir else 0x0)
  1507. elif action == FILE_CALLBACK_SAVE:
  1508. ret = QFileDialog.getSaveFileName(gCarla.gui, charPtrToString(title), "", charPtrToString(filter), QFileDialog.ShowDirsOnly if isDir else 0x0)
  1509. if config_UseQt5:
  1510. ret = ret[0]
  1511. if not ret:
  1512. return None
  1513. # FIXME
  1514. global fileRet
  1515. fileRet = c_char_p(ret.encode("utf-8"))
  1516. retval = cast(byref(fileRet), POINTER(c_uintptr))
  1517. return retval.contents.value
  1518. # ------------------------------------------------------------------------------------------------------------
  1519. # Init host
  1520. def initHost(initName, libPrefixOrPluginClass, isControl, isPlugin, failError):
  1521. if isPlugin:
  1522. PluginClass = libPrefixOrPluginClass
  1523. libPrefix = None
  1524. else:
  1525. PluginClass = None
  1526. libPrefix = libPrefixOrPluginClass
  1527. pathBinaries, pathResources = getPaths(libPrefix)
  1528. # --------------------------------------------------------------------------------------------------------
  1529. # Fail if binary dir is not found
  1530. if not os.path.exists(pathBinaries):
  1531. if failError:
  1532. QMessageBox.critical(None, "Error", "Failed to find the carla binaries, cannot continue")
  1533. sys.exit(1)
  1534. return
  1535. # --------------------------------------------------------------------------------------------------------
  1536. # Set Carla library name
  1537. libname = "libcarla_%s2.%s" % ("control" if isControl else "standalone", DLL_EXTENSION)
  1538. utilsname = "libcarla_utils.%s" % (DLL_EXTENSION)
  1539. # --------------------------------------------------------------------------------------------------------
  1540. # Print info
  1541. print("Carla %s started, status:" % VERSION)
  1542. print(" Python version: %s" % sys.version.split(" ",1)[0])
  1543. print(" Qt version: %s" % qVersion())
  1544. print(" PyQt version: %s" % PYQT_VERSION_STR)
  1545. print(" Binary dir: %s" % pathBinaries)
  1546. print(" Resources dir: %s" % pathResources)
  1547. # --------------------------------------------------------------------------------------------------------
  1548. # Init host
  1549. if failError:
  1550. # no try
  1551. host = PluginClass() if isPlugin else CarlaHostQtDLL(os.path.join(pathBinaries, libname))
  1552. else:
  1553. try:
  1554. host = PluginClass() if isPlugin else CarlaHostQtDLL(os.path.join(pathBinaries, libname))
  1555. except:
  1556. host = CarlaHostQtNull()
  1557. host.isControl = isControl
  1558. host.isPlugin = isPlugin
  1559. host.set_engine_callback(lambda h,a,p,v1,v2,v3,vs: engineCallback(host,a,p,v1,v2,v3,vs))
  1560. host.set_file_callback(fileCallback)
  1561. # If it's a plugin the paths are already set
  1562. if not isPlugin:
  1563. host.pathBinaries = pathBinaries
  1564. host.pathResources = pathResources
  1565. host.set_engine_option(ENGINE_OPTION_PATH_BINARIES, 0, pathBinaries)
  1566. host.set_engine_option(ENGINE_OPTION_PATH_RESOURCES, 0, pathResources)
  1567. if not isControl:
  1568. host.set_engine_option(ENGINE_OPTION_NSM_INIT, os.getpid(), initName)
  1569. # --------------------------------------------------------------------------------------------------------
  1570. # Init utils
  1571. gCarla.utils = CarlaUtils(os.path.join(pathBinaries, utilsname))
  1572. gCarla.utils.set_process_name(initName)
  1573. #gCarla.utils.set_locale_C()
  1574. # --------------------------------------------------------------------------------------------------------
  1575. # Done
  1576. return host
  1577. # ------------------------------------------------------------------------------------------------------------
  1578. # Load host settings
  1579. def loadHostSettings(host):
  1580. # kdevelop likes this :)
  1581. if False: host = CarlaHostMeta()
  1582. settings = QSettings("falkTX", "Carla2")
  1583. # bool values
  1584. try:
  1585. host.forceStereo = settings.value(CARLA_KEY_ENGINE_FORCE_STEREO, CARLA_DEFAULT_FORCE_STEREO, type=bool)
  1586. except:
  1587. host.forceStereo = CARLA_DEFAULT_FORCE_STEREO
  1588. try:
  1589. host.preferPluginBridges = settings.value(CARLA_KEY_ENGINE_PREFER_PLUGIN_BRIDGES, CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES, type=bool)
  1590. except:
  1591. host.preferPluginBridges = CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES
  1592. try:
  1593. host.preferUIBridges = settings.value(CARLA_KEY_ENGINE_PREFER_UI_BRIDGES, CARLA_DEFAULT_PREFER_UI_BRIDGES, type=bool)
  1594. except:
  1595. host.preferUIBridges = CARLA_DEFAULT_PREFER_UI_BRIDGES
  1596. try:
  1597. host.uisAlwaysOnTop = settings.value(CARLA_KEY_ENGINE_UIS_ALWAYS_ON_TOP, CARLA_DEFAULT_UIS_ALWAYS_ON_TOP, type=bool)
  1598. except:
  1599. host.uisAlwaysOnTop = CARLA_DEFAULT_UIS_ALWAYS_ON_TOP
  1600. # int values
  1601. try:
  1602. host.maxParameters = settings.value(CARLA_KEY_ENGINE_MAX_PARAMETERS, CARLA_DEFAULT_MAX_PARAMETERS, type=int)
  1603. except:
  1604. host.maxParameters = CARLA_DEFAULT_MAX_PARAMETERS
  1605. try:
  1606. host.uiBridgesTimeout = settings.value(CARLA_KEY_ENGINE_UI_BRIDGES_TIMEOUT, CARLA_DEFAULT_UI_BRIDGES_TIMEOUT, type=int)
  1607. except:
  1608. host.uiBridgesTimeout = CARLA_DEFAULT_UI_BRIDGES_TIMEOUT
  1609. if host.isPlugin:
  1610. return
  1611. # enums
  1612. try:
  1613. host.transportMode = settings.value(CARLA_KEY_ENGINE_TRANSPORT_MODE, CARLA_DEFAULT_TRANSPORT_MODE, type=int)
  1614. except:
  1615. host.transportMode = CARLA_DEFAULT_TRANSPORT_MODE
  1616. if not host.processModeForced:
  1617. try:
  1618. host.processMode = settings.value(CARLA_KEY_ENGINE_PROCESS_MODE, CARLA_DEFAULT_PROCESS_MODE, type=int)
  1619. except:
  1620. host.processMode = CARLA_DEFAULT_PROCESS_MODE
  1621. host.nextProcessMode = host.processMode
  1622. # --------------------------------------------------------------------------------------------------------
  1623. # fix things if needed
  1624. if host.processMode == ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS and LADISH_APP_NAME:
  1625. print("LADISH detected but using multiple clients (not allowed), forcing single client now")
  1626. host.nextProcessMode = host.processMode = ENGINE_PROCESS_MODE_SINGLE_CLIENT
  1627. # ------------------------------------------------------------------------------------------------------------
  1628. # Set host settings
  1629. def setHostSettings(host):
  1630. # kdevelop likes this :)
  1631. if False: host = CarlaHostMeta()
  1632. # TEST
  1633. #host.preventBadBehaviour = True
  1634. host.set_engine_option(ENGINE_OPTION_FORCE_STEREO, host.forceStereo, "")
  1635. host.set_engine_option(ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, host.preferPluginBridges, "")
  1636. host.set_engine_option(ENGINE_OPTION_PREFER_UI_BRIDGES, host.preferUIBridges, "")
  1637. host.set_engine_option(ENGINE_OPTION_UIS_ALWAYS_ON_TOP, host.uisAlwaysOnTop, "")
  1638. host.set_engine_option(ENGINE_OPTION_MAX_PARAMETERS, host.maxParameters, "")
  1639. host.set_engine_option(ENGINE_OPTION_UI_BRIDGES_TIMEOUT, host.uiBridgesTimeout, "")
  1640. host.set_engine_option(ENGINE_OPTION_PREVENT_BAD_BEHAVIOUR, host.preventBadBehaviour, "")
  1641. if host.isPlugin:
  1642. return
  1643. host.set_engine_option(ENGINE_OPTION_PROCESS_MODE, host.nextProcessMode, "")
  1644. host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE, host.transportMode, "")
  1645. # ------------------------------------------------------------------------------------------------------------