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 88KB

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