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