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

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
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
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
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
11 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
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
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
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
10 years ago
10 years ago
11 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
9 years ago
10 years ago
9 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
10 years ago
9 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Carla host code
  4. # Copyright (C) 2011-2016 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. import json
  23. if config_UseQt5:
  24. from PyQt5.QtCore import qCritical, QFileInfo, QModelIndex, QPointF, QTimer
  25. from PyQt5.QtGui import QImage, QPalette
  26. from PyQt5.QtWidgets import QAction, QApplication, QInputDialog, QFileSystemModel, QListWidgetItem, QMainWindow
  27. else:
  28. from PyQt4.QtCore import qCritical, QFileInfo, QModelIndex, QPointF, QTimer
  29. from PyQt4.QtGui import QImage, QPalette
  30. from PyQt4.QtGui import QAction, QApplication, QInputDialog, QFileSystemModel, QListWidgetItem, QMainWindow
  31. # ------------------------------------------------------------------------------------------------------------
  32. # Imports (Custom)
  33. import patchcanvas
  34. import ui_carla_host
  35. from carla_app import *
  36. from carla_database 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. # Safe exception hook, needed for PyQt5
  54. def sys_excepthook(type, value, tback):
  55. return sys.__excepthook__(type, value, tback)
  56. # ------------------------------------------------------------------------------------------------------------
  57. # Session Management support
  58. CARLA_CLIENT_NAME = os.getenv("CARLA_CLIENT_NAME")
  59. LADISH_APP_NAME = os.getenv("LADISH_APP_NAME")
  60. NSM_URL = os.getenv("NSM_URL")
  61. # ------------------------------------------------------------------------------------------------------------
  62. # Carla Print class
  63. class CarlaPrint:
  64. def __init__(self, err):
  65. self.err = err
  66. def flush(self):
  67. gCarla.utils.fflush(self.err)
  68. def write(self, string):
  69. gCarla.utils.fputs(self.err, string)
  70. # ------------------------------------------------------------------------------------------------------------
  71. # Host Window
  72. class HostWindow(QMainWindow):
  73. #class HostWindow(QMainWindow, PluginEditParentMeta, metaclass=PyQtMetaClass):
  74. # signals
  75. SIGTERM = pyqtSignal()
  76. SIGUSR1 = pyqtSignal()
  77. # --------------------------------------------------------------------------------------------------------
  78. def __init__(self, host, withCanvas, parent=None):
  79. QMainWindow.__init__(self, parent)
  80. self.host = host
  81. self.ui = ui_carla_host.Ui_CarlaHostW()
  82. self.ui.setupUi(self)
  83. gCarla.gui = self
  84. if False:
  85. # kdevelop likes this :)
  86. host = CarlaHostNull()
  87. self.host = host
  88. self._true = c_char_p("true".encode("utf-8"))
  89. self.fParentOrSelf = parent or self
  90. # ----------------------------------------------------------------------------------------------------
  91. # Internal stuff
  92. self.fIdleTimerFast = 0
  93. self.fIdleTimerSlow = 0
  94. self.fLadspaRdfNeedsUpdate = True
  95. self.fLadspaRdfList = []
  96. self.fPluginCount = 0
  97. self.fPluginList = []
  98. self.fProjectFilename = ""
  99. self.fIsProjectLoading = False
  100. self.fCurrentlyRemovingAllPlugins = False
  101. self.fLastTransportBPM = 0.0
  102. self.fLastTransportFrame = 0
  103. self.fLastTransportState = False
  104. self.fSampleRate = 0.0
  105. # run a custom action after engine is properly closed
  106. # 1 for close carla, 2 for load project
  107. self.fCustomStopAction = 0
  108. # first attempt of auto-start engine doesn't show an error
  109. self.fFirstEngineInit = True
  110. # to be filled with key-value pairs of current settings
  111. self.fSavedSettings = {}
  112. if host.isControl:
  113. self.fClientName = "Carla-Control"
  114. self.fSessionManagerName = "Control"
  115. elif host.isPlugin:
  116. self.fClientName = "Carla-Plugin"
  117. self.fSessionManagerName = "Plugin"
  118. elif LADISH_APP_NAME:
  119. self.fClientName = LADISH_APP_NAME
  120. self.fSessionManagerName = "LADISH"
  121. elif NSM_URL and host.nsmOK:
  122. self.fClientName = "Carla.tmp"
  123. self.fSessionManagerName = "Non Session Manager TMP"
  124. else:
  125. self.fClientName = CARLA_CLIENT_NAME or "Carla"
  126. self.fSessionManagerName = ""
  127. # ----------------------------------------------------------------------------------------------------
  128. # Internal stuff (patchbay)
  129. self.fExportImage = QImage()
  130. self.fPeaksCleared = True
  131. self.fExternalPatchbay = False
  132. self.fSelectedPlugins = []
  133. self.fCanvasWidth = 0
  134. self.fCanvasHeight = 0
  135. self.fMiniCanvasUpdateTimeout = 0
  136. self.fWithCanvas = withCanvas
  137. # ----------------------------------------------------------------------------------------------------
  138. # Set up GUI (engine stopped)
  139. if self.host.isPlugin or self.host.isControl:
  140. self.ui.act_file_save.setVisible(False)
  141. self.ui.act_engine_start.setEnabled(False)
  142. self.ui.act_engine_start.setVisible(False)
  143. self.ui.act_engine_stop.setEnabled(False)
  144. self.ui.act_engine_stop.setVisible(False)
  145. self.ui.menu_Engine.setEnabled(False)
  146. self.ui.menu_Engine.setVisible(False)
  147. self.ui.menu_Engine.menuAction().setVisible(False)
  148. self.ui.tabWidget.removeTab(2)
  149. if self.host.isControl:
  150. self.ui.act_file_new.setVisible(False)
  151. self.ui.act_file_open.setVisible(False)
  152. self.ui.act_file_save.setVisible(False)
  153. self.ui.act_file_save_as.setVisible(False)
  154. self.ui.act_plugin_add.setVisible(False)
  155. self.ui.act_plugin_add2.setVisible(False)
  156. self.ui.act_plugin_remove_all.setVisible(False)
  157. self.ui.menu_Plugin.setEnabled(False)
  158. self.ui.menu_Plugin.setVisible(False)
  159. self.ui.menu_Plugin.menuAction().setVisible(False)
  160. else:
  161. self.ui.act_file_save_as.setText(self.tr("Export as..."))
  162. else:
  163. self.ui.act_engine_start.setEnabled(True)
  164. if WINDOWS:
  165. self.ui.tabWidget.removeTab(2)
  166. if not self.host.isControl:
  167. self.ui.act_file_connect.setEnabled(False)
  168. self.ui.act_file_connect.setVisible(False)
  169. self.ui.act_file_refresh.setEnabled(False)
  170. self.ui.act_file_refresh.setVisible(False)
  171. if self.fSessionManagerName and not self.host.isPlugin:
  172. self.ui.act_file_new.setEnabled(False)
  173. self.ui.act_file_open.setEnabled(False)
  174. self.ui.act_file_save.setEnabled(False)
  175. self.ui.act_file_save_as.setEnabled(False)
  176. self.ui.act_engine_stop.setEnabled(False)
  177. self.ui.act_plugin_remove_all.setEnabled(False)
  178. self.ui.act_canvas_show_internal.setChecked(False)
  179. self.ui.act_canvas_show_internal.setVisible(False)
  180. self.ui.act_canvas_show_external.setChecked(False)
  181. self.ui.act_canvas_show_external.setVisible(False)
  182. self.ui.menu_PluginMacros.setEnabled(False)
  183. self.ui.menu_Canvas.setEnabled(False)
  184. self.ui.dockWidgetTitleBar = QWidget(self)
  185. self.ui.dockWidget.setTitleBarWidget(self.ui.dockWidgetTitleBar)
  186. if not withCanvas:
  187. self.ui.act_canvas_show_internal.setVisible(False)
  188. self.ui.act_canvas_show_external.setVisible(False)
  189. self.ui.act_canvas_arrange.setVisible(False)
  190. self.ui.act_canvas_refresh.setVisible(False)
  191. self.ui.act_canvas_save_image.setVisible(False)
  192. self.ui.act_canvas_zoom_100.setVisible(False)
  193. self.ui.act_canvas_zoom_fit.setVisible(False)
  194. self.ui.act_canvas_zoom_in.setVisible(False)
  195. self.ui.act_canvas_zoom_out.setVisible(False)
  196. self.ui.act_settings_show_meters.setVisible(False)
  197. self.ui.act_settings_show_keyboard.setVisible(False)
  198. self.ui.menu_Canvas_Zoom.setEnabled(False)
  199. self.ui.menu_Canvas_Zoom.setVisible(False)
  200. self.ui.menu_Canvas_Zoom.menuAction().setVisible(False)
  201. self.ui.menu_Canvas.setEnabled(False)
  202. self.ui.menu_Canvas.setVisible(False)
  203. self.ui.menu_Canvas.menuAction().setVisible(False)
  204. self.ui.miniCanvasPreview.hide()
  205. self.ui.tabWidget.removeTab(1)
  206. if WINDOWS:
  207. self.ui.tabWidget.tabBar().hide()
  208. if host.isControl:
  209. self.ui.dockWidget.hide()
  210. # ----------------------------------------------------------------------------------------------------
  211. # Set up GUI (disk)
  212. self.fDirModel = QFileSystemModel(self)
  213. self.fDirModel.setRootPath(HOME)
  214. self.fDirModel.setNameFilters(gCarla.utils.get_supported_file_extensions().split(";"))
  215. self.ui.fileTreeView.setModel(self.fDirModel)
  216. self.ui.fileTreeView.setRootIndex(self.fDirModel.index(HOME))
  217. self.ui.fileTreeView.setColumnHidden(1, True)
  218. self.ui.fileTreeView.setColumnHidden(2, True)
  219. self.ui.fileTreeView.setColumnHidden(3, True)
  220. self.ui.fileTreeView.setHeaderHidden(True)
  221. # ----------------------------------------------------------------------------------------------------
  222. # Set up GUI (transport)
  223. fontMetrics = QFontMetrics(self.ui.l_transport_bbt.font())
  224. minValueWidth = fontMetrics.width("000|00|0000")
  225. minLabelWidth = fontMetrics.width(self.ui.label_transport_frame.text())
  226. labelTimeWidth = fontMetrics.width(self.ui.label_transport_time.text())
  227. labelBBTWidth = fontMetrics.width(self.ui.label_transport_bbt.text())
  228. if minLabelWidth < labelTimeWidth:
  229. minLabelWidth = labelTimeWidth
  230. if minLabelWidth < labelBBTWidth:
  231. minLabelWidth = labelBBTWidth
  232. self.ui.label_transport_frame.setMinimumWidth(minLabelWidth + 3)
  233. self.ui.label_transport_time.setMinimumWidth(minLabelWidth + 3)
  234. self.ui.label_transport_bbt.setMinimumWidth(minLabelWidth + 3)
  235. self.ui.l_transport_bbt.setMinimumWidth(minValueWidth + 3)
  236. self.ui.l_transport_frame.setMinimumWidth(minValueWidth + 3)
  237. self.ui.l_transport_time.setMinimumWidth(minValueWidth + 3)
  238. if host.isControl or host.isPlugin:
  239. self.ui.b_transport_play.setEnabled(False)
  240. self.ui.b_transport_stop.setEnabled(False)
  241. self.ui.b_transport_backwards.setEnabled(False)
  242. self.ui.b_transport_forwards.setEnabled(False)
  243. self.ui.cb_transport_link.setEnabled(False)
  244. self.ui.dsb_transport_bpm.setEnabled(False)
  245. self.ui.w_transport.setEnabled(False)
  246. # ----------------------------------------------------------------------------------------------------
  247. # Set up GUI (rack)
  248. self.ui.listWidget.setHost(self.host)
  249. sb = self.ui.listWidget.verticalScrollBar()
  250. self.ui.rackScrollBar.setMinimum(sb.minimum())
  251. self.ui.rackScrollBar.setMaximum(sb.maximum())
  252. self.ui.rackScrollBar.setValue(sb.value())
  253. sb.rangeChanged.connect(self.ui.rackScrollBar.setRange)
  254. sb.valueChanged.connect(self.ui.rackScrollBar.setValue)
  255. self.ui.rackScrollBar.rangeChanged.connect(sb.setRange)
  256. self.ui.rackScrollBar.valueChanged.connect(sb.setValue)
  257. self.ui.rack.setStyleSheet("""
  258. QLabel#pad_left {
  259. background-image: url(:/bitmaps/rack_padding_left.png);
  260. background-repeat: repeat-y;
  261. }
  262. QLabel#pad_right {
  263. background-image: url(:/bitmaps/rack_padding_right.png);
  264. background-repeat: repeat-y;
  265. }
  266. CarlaRackList#CarlaRackList {
  267. background-color: black;
  268. }
  269. """)
  270. # ----------------------------------------------------------------------------------------------------
  271. # Set up GUI (patchbay)
  272. self.ui.peak_in.setChannelCount(2)
  273. self.ui.peak_in.setMeterColor(DigitalPeakMeter.COLOR_BLUE)
  274. self.ui.peak_in.setMeterOrientation(DigitalPeakMeter.VERTICAL)
  275. self.ui.peak_in.setFixedWidth(25)
  276. self.ui.peak_out.setChannelCount(2)
  277. self.ui.peak_out.setMeterColor(DigitalPeakMeter.COLOR_GREEN)
  278. self.ui.peak_out.setMeterOrientation(DigitalPeakMeter.VERTICAL)
  279. self.ui.peak_out.setFixedWidth(25)
  280. self.ui.scrollArea = PixmapKeyboardHArea(self.ui.patchbay)
  281. self.ui.keyboard = self.ui.scrollArea.keyboard
  282. self.ui.patchbay.layout().addWidget(self.ui.scrollArea, 1, 0, 1, 0)
  283. self.ui.scrollArea.setEnabled(False)
  284. self.ui.miniCanvasPreview.setRealParent(self)
  285. # ----------------------------------------------------------------------------------------------------
  286. # Set up GUI (special stuff for Mac OS)
  287. if MACOS:
  288. self.ui.act_file_quit.setMenuRole(QAction.QuitRole)
  289. self.ui.act_settings_configure.setMenuRole(QAction.PreferencesRole)
  290. self.ui.act_help_about.setMenuRole(QAction.AboutRole)
  291. self.ui.act_help_about_qt.setMenuRole(QAction.AboutQtRole)
  292. self.ui.menu_Settings.setTitle("Panels")
  293. self.ui.menu_Help.menuAction().setVisible(False)
  294. # ----------------------------------------------------------------------------------------------------
  295. # Load Settings
  296. self.loadSettings(True)
  297. # ----------------------------------------------------------------------------------------------------
  298. # Set-up Canvas
  299. self.scene = patchcanvas.PatchScene(self, self.ui.graphicsView)
  300. self.ui.graphicsView.setScene(self.scene)
  301. self.ui.graphicsView.setRenderHint(QPainter.Antialiasing, bool(self.fSavedSettings[CARLA_KEY_CANVAS_ANTIALIASING] == patchcanvas.ANTIALIASING_FULL))
  302. if self.fSavedSettings[CARLA_KEY_CANVAS_USE_OPENGL] and hasGL:
  303. self.ui.glView = QGLWidget(self)
  304. self.ui.graphicsView.setViewport(self.ui.glView)
  305. self.ui.graphicsView.setRenderHint(QPainter.HighQualityAntialiasing, self.fSavedSettings[CARLA_KEY_CANVAS_HQ_ANTIALIASING])
  306. self.setupCanvas()
  307. # ----------------------------------------------------------------------------------------------------
  308. # Connect actions to functions
  309. self.ui.act_file_new.triggered.connect(self.slot_fileNew)
  310. self.ui.act_file_open.triggered.connect(self.slot_fileOpen)
  311. self.ui.act_file_save.triggered.connect(self.slot_fileSave)
  312. self.ui.act_file_save_as.triggered.connect(self.slot_fileSaveAs)
  313. self.ui.act_engine_start.triggered.connect(self.slot_engineStart)
  314. self.ui.act_engine_stop.triggered.connect(self.slot_engineStop)
  315. self.ui.act_plugin_add.triggered.connect(self.slot_pluginAdd)
  316. self.ui.act_plugin_add2.triggered.connect(self.slot_pluginAdd)
  317. self.ui.act_plugin_remove_all.triggered.connect(self.slot_pluginRemoveAll)
  318. self.ui.act_add_jack.triggered.connect(self.slot_jackAppAdd)
  319. self.ui.act_plugins_enable.triggered.connect(self.slot_pluginsEnable)
  320. self.ui.act_plugins_disable.triggered.connect(self.slot_pluginsDisable)
  321. self.ui.act_plugins_volume100.triggered.connect(self.slot_pluginsVolume100)
  322. self.ui.act_plugins_mute.triggered.connect(self.slot_pluginsMute)
  323. self.ui.act_plugins_wet100.triggered.connect(self.slot_pluginsWet100)
  324. self.ui.act_plugins_bypass.triggered.connect(self.slot_pluginsBypass)
  325. self.ui.act_plugins_center.triggered.connect(self.slot_pluginsCenter)
  326. self.ui.act_plugins_compact.triggered.connect(self.slot_pluginsCompact)
  327. self.ui.act_plugins_expand.triggered.connect(self.slot_pluginsExpand)
  328. self.ui.act_plugins_panic.triggered.connect(self.slot_pluginsDisable)
  329. self.ui.act_canvas_show_internal.triggered.connect(self.slot_canvasShowInternal)
  330. self.ui.act_canvas_show_external.triggered.connect(self.slot_canvasShowExternal)
  331. self.ui.act_canvas_arrange.triggered.connect(self.slot_canvasArrange)
  332. self.ui.act_canvas_refresh.triggered.connect(self.slot_canvasRefresh)
  333. self.ui.act_canvas_zoom_fit.triggered.connect(self.slot_canvasZoomFit)
  334. self.ui.act_canvas_zoom_in.triggered.connect(self.slot_canvasZoomIn)
  335. self.ui.act_canvas_zoom_out.triggered.connect(self.slot_canvasZoomOut)
  336. self.ui.act_canvas_zoom_100.triggered.connect(self.slot_canvasZoomReset)
  337. self.ui.act_canvas_save_image.triggered.connect(self.slot_canvasSaveImage)
  338. self.ui.act_canvas_arrange.setEnabled(False) # TODO, later
  339. self.ui.act_settings_show_toolbar.toggled.connect(self.slot_showToolbar)
  340. self.ui.act_settings_show_meters.toggled.connect(self.slot_showCanvasMeters)
  341. self.ui.act_settings_show_keyboard.toggled.connect(self.slot_showCanvasKeyboard)
  342. self.ui.act_settings_show_side_panel.toggled.connect(self.slot_showSidePanel)
  343. self.ui.act_settings_configure.triggered.connect(self.slot_configureCarla)
  344. self.ui.act_help_about.triggered.connect(self.slot_aboutCarla)
  345. self.ui.act_help_about_qt.triggered.connect(self.slot_aboutQt)
  346. self.ui.cb_disk.currentIndexChanged.connect(self.slot_diskFolderChanged)
  347. self.ui.b_disk_add.clicked.connect(self.slot_diskFolderAdd)
  348. self.ui.b_disk_remove.clicked.connect(self.slot_diskFolderRemove)
  349. self.ui.fileTreeView.doubleClicked.connect(self.slot_fileTreeDoubleClicked)
  350. self.ui.b_transport_play.clicked.connect(self.slot_transportPlayPause)
  351. self.ui.b_transport_stop.clicked.connect(self.slot_transportStop)
  352. self.ui.b_transport_backwards.clicked.connect(self.slot_transportBackwards)
  353. self.ui.b_transport_forwards.clicked.connect(self.slot_transportForwards)
  354. self.ui.dsb_transport_bpm.valueChanged.connect(self.slot_transportBpmChanged)
  355. self.ui.cb_transport_jack.clicked.connect(self.slot_transportJackEnabled)
  356. self.ui.cb_transport_link.clicked.connect(self.slot_transportLinkEnabled)
  357. self.ui.listWidget.customContextMenuRequested.connect(self.showPluginActionsMenu)
  358. self.ui.graphicsView.horizontalScrollBar().valueChanged.connect(self.slot_horizontalScrollBarChanged)
  359. self.ui.graphicsView.verticalScrollBar().valueChanged.connect(self.slot_verticalScrollBarChanged)
  360. self.ui.keyboard.noteOn.connect(self.slot_noteOn)
  361. self.ui.keyboard.noteOff.connect(self.slot_noteOff)
  362. self.ui.miniCanvasPreview.miniCanvasMoved.connect(self.slot_miniCanvasMoved)
  363. self.ui.tabWidget.currentChanged.connect(self.slot_tabChanged)
  364. self.scene.scaleChanged.connect(self.slot_canvasScaleChanged)
  365. self.scene.sceneGroupMoved.connect(self.slot_canvasItemMoved)
  366. self.scene.pluginSelected.connect(self.slot_canvasPluginSelected)
  367. self.SIGUSR1.connect(self.slot_handleSIGUSR1)
  368. self.SIGTERM.connect(self.slot_handleSIGTERM)
  369. host.EngineStartedCallback.connect(self.slot_handleEngineStartedCallback)
  370. host.EngineStoppedCallback.connect(self.slot_handleEngineStoppedCallback)
  371. host.SampleRateChangedCallback.connect(self.slot_handleSampleRateChangedCallback)
  372. host.ProjectLoadFinishedCallback.connect(self.slot_handleProjectLoadFinishedCallback)
  373. host.PluginAddedCallback.connect(self.slot_handlePluginAddedCallback)
  374. host.PluginRemovedCallback.connect(self.slot_handlePluginRemovedCallback)
  375. host.ReloadAllCallback.connect(self.slot_handleReloadAllCallback)
  376. host.NoteOnCallback.connect(self.slot_handleNoteOnCallback)
  377. host.NoteOffCallback.connect(self.slot_handleNoteOffCallback)
  378. host.UpdateCallback.connect(self.slot_handleUpdateCallback)
  379. host.PatchbayClientAddedCallback.connect(self.slot_handlePatchbayClientAddedCallback)
  380. host.PatchbayClientRemovedCallback.connect(self.slot_handlePatchbayClientRemovedCallback)
  381. host.PatchbayClientRenamedCallback.connect(self.slot_handlePatchbayClientRenamedCallback)
  382. host.PatchbayClientDataChangedCallback.connect(self.slot_handlePatchbayClientDataChangedCallback)
  383. host.PatchbayPortAddedCallback.connect(self.slot_handlePatchbayPortAddedCallback)
  384. host.PatchbayPortRemovedCallback.connect(self.slot_handlePatchbayPortRemovedCallback)
  385. host.PatchbayPortRenamedCallback.connect(self.slot_handlePatchbayPortRenamedCallback)
  386. host.PatchbayConnectionAddedCallback.connect(self.slot_handlePatchbayConnectionAddedCallback)
  387. host.PatchbayConnectionRemovedCallback.connect(self.slot_handlePatchbayConnectionRemovedCallback)
  388. host.NSMCallback.connect(self.slot_handleNSMCallback)
  389. host.DebugCallback.connect(self.slot_handleDebugCallback)
  390. host.InfoCallback.connect(self.slot_handleInfoCallback)
  391. host.ErrorCallback.connect(self.slot_handleErrorCallback)
  392. host.QuitCallback.connect(self.slot_handleQuitCallback)
  393. # ----------------------------------------------------------------------------------------------------
  394. # Final setup
  395. self.ui.text_logs.clear()
  396. self.setProperWindowTitle()
  397. # Qt needs this so it properly creates & resizes the canvas
  398. self.ui.tabWidget.blockSignals(True)
  399. self.ui.tabWidget.setCurrentIndex(1)
  400. self.ui.tabWidget.setCurrentIndex(0)
  401. self.ui.tabWidget.blockSignals(False)
  402. # Plugin needs to have timers always running so it receives messages
  403. if self.host.isPlugin:
  404. self.startTimers()
  405. # Start in patchbay tab if using forced patchbay mode
  406. if host.processModeForced and host.processMode == ENGINE_PROCESS_MODE_PATCHBAY and not host.isControl:
  407. self.ui.tabWidget.setCurrentIndex(1)
  408. # Load initial project file if set
  409. if not (self.host.isControl or self.host.isPlugin):
  410. projectFile = getInitialProjectFile(QApplication.instance())
  411. if projectFile:
  412. self.loadProjectLater(projectFile)
  413. # For NSM we wait for the open message
  414. if NSM_URL and host.nsmOK:
  415. host.nsm_ready(-1)
  416. return
  417. QTimer.singleShot(0, self.slot_engineStart)
  418. # --------------------------------------------------------------------------------------------------------
  419. # Setup
  420. def compactPlugin(self, pluginId):
  421. if pluginId > self.fPluginCount:
  422. return
  423. pitem = self.fPluginList[pluginId]
  424. if pitem is None:
  425. return
  426. pitem.recreateWidget(True)
  427. def setLoadRDFsNeeded(self):
  428. self.fLadspaRdfNeedsUpdate = True
  429. def setProperWindowTitle(self):
  430. title = self.fClientName
  431. if self.fProjectFilename and not self.host.nsmOK:
  432. title += " - %s" % os.path.basename(self.fProjectFilename)
  433. if self.fSessionManagerName:
  434. title += " (%s)" % self.fSessionManagerName
  435. self.setWindowTitle(title)
  436. # --------------------------------------------------------------------------------------------------------
  437. # Files
  438. def makeExtraFilename(self):
  439. return self.fProjectFilename.rsplit(".",1)[0]+".json"
  440. def loadProjectNow(self):
  441. if not self.fProjectFilename:
  442. return qCritical("ERROR: loading project without filename set")
  443. if self.host.nsmOK and not os.path.exists(self.fProjectFilename):
  444. return
  445. self.projectLoadingStarted()
  446. self.fIsProjectLoading = True
  447. self.host.load_project(self.fProjectFilename)
  448. # Project finished loading is sent by engine
  449. def loadProjectLater(self, filename):
  450. self.fProjectFilename = QFileInfo(filename).absoluteFilePath()
  451. self.setProperWindowTitle()
  452. QTimer.singleShot(1, self.slot_loadProjectNow)
  453. def saveProjectNow(self):
  454. if not self.fProjectFilename:
  455. return qCritical("ERROR: saving project without filename set")
  456. self.host.save_project(self.fProjectFilename)
  457. with open(self.makeExtraFilename(), 'w') as fh:
  458. json.dump({
  459. 'canvas': patchcanvas.saveGroupPositions(),
  460. }, fh)
  461. def projectLoadingStarted(self):
  462. self.ui.rack.setEnabled(False)
  463. self.ui.graphicsView.setEnabled(False)
  464. def projectLoadingFinished(self):
  465. self.ui.rack.setEnabled(True)
  466. self.ui.graphicsView.setEnabled(True)
  467. QTimer.singleShot(1000, self.slot_canvasRefresh)
  468. extrafile = self.makeExtraFilename()
  469. if not os.path.exists(extrafile):
  470. return
  471. try:
  472. with open(extrafile, "r") as fh:
  473. canvasdata = json.load(fh)['canvas']
  474. except:
  475. return
  476. patchcanvas.restoreGroupPositions(canvasdata)
  477. # --------------------------------------------------------------------------------------------------------
  478. # Files (menu actions)
  479. @pyqtSlot()
  480. def slot_fileNew(self):
  481. self.slot_pluginRemoveAll()
  482. self.fProjectFilename = ""
  483. self.setProperWindowTitle()
  484. @pyqtSlot()
  485. def slot_fileOpen(self):
  486. fileFilter = self.tr("Carla Project File (*.carxp);;Carla Preset File (*.carxs)")
  487. filename = QFileDialog.getOpenFileName(self, self.tr("Open Carla Project File"), self.fSavedSettings[CARLA_KEY_MAIN_PROJECT_FOLDER], filter=fileFilter)
  488. if config_UseQt5:
  489. filename = filename[0]
  490. if not filename:
  491. return
  492. newFile = True
  493. if self.fPluginCount > 0:
  494. ask = QMessageBox.question(self, self.tr("Question"), self.tr("There are some plugins loaded, do you want to remove them now?"),
  495. QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
  496. newFile = (ask == QMessageBox.Yes)
  497. if newFile:
  498. self.slot_pluginRemoveAll()
  499. self.fProjectFilename = filename
  500. self.setProperWindowTitle()
  501. self.loadProjectNow()
  502. else:
  503. filenameOld = self.fProjectFilename
  504. self.fProjectFilename = filename
  505. self.loadProjectNow()
  506. self.fProjectFilename = filenameOld
  507. @pyqtSlot()
  508. def slot_fileSave(self, saveAs=False):
  509. if self.fProjectFilename and not saveAs:
  510. return self.saveProjectNow()
  511. fileFilter = self.tr("Carla Project File (*.carxp)")
  512. filename = QFileDialog.getSaveFileName(self, self.tr("Save Carla Project File"), self.fSavedSettings[CARLA_KEY_MAIN_PROJECT_FOLDER], filter=fileFilter)
  513. if config_UseQt5:
  514. filename = filename[0]
  515. if not filename:
  516. return
  517. if not filename.lower().endswith(".carxp"):
  518. filename += ".carxp"
  519. if self.fProjectFilename != filename:
  520. self.fProjectFilename = filename
  521. self.setProperWindowTitle()
  522. self.saveProjectNow()
  523. @pyqtSlot()
  524. def slot_fileSaveAs(self):
  525. self.slot_fileSave(True)
  526. @pyqtSlot()
  527. def slot_loadProjectNow(self):
  528. self.loadProjectNow()
  529. # --------------------------------------------------------------------------------------------------------
  530. # Engine (menu actions)
  531. @pyqtSlot()
  532. def slot_engineStart(self):
  533. audioDriver = setEngineSettings(self.host)
  534. firstInit = self.fFirstEngineInit
  535. self.fFirstEngineInit = False
  536. self.ui.text_logs.appendPlainText("======= Starting engine =======")
  537. if self.host.engine_init(audioDriver, self.fClientName):
  538. self.ui.text_logs.appendPlainText("======= Engine started ========")
  539. return
  540. elif firstInit:
  541. self.ui.text_logs.appendPlainText("Failed to start engine on first try, ignored")
  542. return
  543. audioError = self.host.get_last_error()
  544. if audioError:
  545. QMessageBox.critical(self, self.tr("Error"), self.tr("Could not connect to Audio backend '%s', possible reasons:\n%s" % (audioDriver, audioError)))
  546. else:
  547. QMessageBox.critical(self, self.tr("Error"), self.tr("Could not connect to Audio backend '%s'" % audioDriver))
  548. @pyqtSlot()
  549. def slot_engineStop(self, forced = False):
  550. self.ui.text_logs.appendPlainText("======= Stopping engine =======")
  551. if self.fPluginCount == 0:
  552. self.engineStopFinal()
  553. return True
  554. if not forced:
  555. 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"
  556. "Do you want to do this now?"),
  557. QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
  558. if ask != QMessageBox.Yes:
  559. return False
  560. return self.slot_engineStopTryAgain()
  561. @pyqtSlot()
  562. def slot_engineStopTryAgain(self):
  563. if self.host.is_engine_running() and not self.host.set_engine_about_to_close():
  564. QTimer.singleShot(0, self.slot_engineStopTryAgain)
  565. return False
  566. self.engineStopFinal()
  567. return True
  568. def engineStopFinal(self):
  569. self.killTimers()
  570. self.removeAllPlugins()
  571. if self.host.is_engine_running():
  572. self.host.remove_all_plugins()
  573. if self.host.engine_close():
  574. self.ui.text_logs.appendPlainText("======= Engine stopped ========")
  575. else:
  576. self.ui.text_logs.appendPlainText("Failed to stop engine, error was:")
  577. self.ui.text_logs.appendPlainText(self.host.get_last_error())
  578. if self.fCustomStopAction == 1:
  579. self.close()
  580. elif self.fCustomStopAction == 2:
  581. self.slot_engineStart()
  582. self.loadProjectNow()
  583. self.host.nsm_ready(2) # open
  584. self.fCustomStopAction = 0
  585. # --------------------------------------------------------------------------------------------------------
  586. # Engine (host callbacks)
  587. @pyqtSlot(int, int, str)
  588. def slot_handleEngineStartedCallback(self, processMode, transportMode, driverName):
  589. self.fSampleRate = self.host.get_sample_rate()
  590. self.ui.menu_PluginMacros.setEnabled(True)
  591. self.ui.menu_Canvas.setEnabled(True)
  592. self.ui.act_canvas_show_internal.blockSignals(True)
  593. self.ui.act_canvas_show_external.blockSignals(True)
  594. if processMode == ENGINE_PROCESS_MODE_PATCHBAY and not (self.host.isControl or self.host.isPlugin):
  595. self.ui.act_canvas_show_internal.setChecked(True)
  596. self.ui.act_canvas_show_internal.setVisible(True)
  597. self.ui.act_canvas_show_external.setChecked(False)
  598. self.ui.act_canvas_show_external.setVisible(True)
  599. else:
  600. self.ui.act_canvas_show_internal.setChecked(False)
  601. self.ui.act_canvas_show_internal.setVisible(False)
  602. self.ui.act_canvas_show_external.setChecked(False)
  603. self.ui.act_canvas_show_external.setVisible(False)
  604. self.ui.act_canvas_show_internal.blockSignals(False)
  605. self.ui.act_canvas_show_external.blockSignals(False)
  606. if not (self.host.isControl or self.host.isPlugin):
  607. canSave = (self.fProjectFilename and os.path.exists(self.fProjectFilename)) or not self.fSessionManagerName
  608. self.ui.act_file_save.setEnabled(canSave)
  609. self.ui.act_engine_start.setEnabled(False)
  610. self.ui.act_engine_stop.setEnabled(True)
  611. self.ui.w_transport.setEnabled(transportMode != ENGINE_TRANSPORT_MODE_DISABLED)
  612. if self.host.isPlugin or not self.fSessionManagerName:
  613. self.ui.act_file_open.setEnabled(True)
  614. self.ui.act_file_save_as.setEnabled(True)
  615. self.refreshTransport(True)
  616. self.ui.cb_transport_jack.setChecked(transportMode == ENGINE_TRANSPORT_MODE_JACK)
  617. self.ui.cb_transport_jack.setEnabled(driverName == "JACK")
  618. self.startTimers()
  619. @pyqtSlot()
  620. def slot_handleEngineStoppedCallback(self):
  621. patchcanvas.clear()
  622. self.killTimers()
  623. # just in case
  624. self.removeAllPlugins()
  625. self.ui.menu_PluginMacros.setEnabled(False)
  626. self.ui.menu_Canvas.setEnabled(False)
  627. if not (self.host.isControl or self.host.isPlugin):
  628. self.ui.act_file_save.setEnabled(False)
  629. self.ui.act_engine_start.setEnabled(True)
  630. self.ui.act_engine_stop.setEnabled(False)
  631. self.ui.w_transport.setEnabled(False)
  632. if self.host.isPlugin or not self.fSessionManagerName:
  633. self.ui.act_file_open.setEnabled(False)
  634. self.ui.act_file_save_as.setEnabled(False)
  635. @pyqtSlot(float)
  636. def slot_handleSampleRateChangedCallback(self, newSampleRate):
  637. self.fSampleRate = newSampleRate
  638. self.refreshTransport(True)
  639. @pyqtSlot()
  640. def slot_handleProjectLoadFinishedCallback(self):
  641. self.fIsProjectLoading = False
  642. self.projectLoadingFinished()
  643. # --------------------------------------------------------------------------------------------------------
  644. # Plugins
  645. def removeAllPlugins(self):
  646. self.ui.act_plugin_remove_all.setEnabled(False)
  647. patchcanvas.handleAllPluginsRemoved()
  648. while self.ui.listWidget.takeItem(0):
  649. pass
  650. self.clearSideStuff()
  651. for pitem in self.fPluginList:
  652. if pitem is None:
  653. continue
  654. pitem.close()
  655. del pitem
  656. self.fPluginCount = 0
  657. self.fPluginList = []
  658. # --------------------------------------------------------------------------------------------------------
  659. # Plugins (menu actions)
  660. def showAddPluginDialog(self):
  661. dialog = PluginDatabaseW(self.fParentOrSelf, self.host)
  662. if not dialog.exec_():
  663. return
  664. if not self.host.is_engine_running():
  665. QMessageBox.warning(self, self.tr("Warning"), self.tr("Cannot add new plugins while engine is stopped"))
  666. return
  667. btype = dialog.fRetPlugin['build']
  668. ptype = dialog.fRetPlugin['type']
  669. filename = dialog.fRetPlugin['filename']
  670. label = dialog.fRetPlugin['label']
  671. uniqueId = dialog.fRetPlugin['uniqueId']
  672. extraPtr = self.getExtraPtr(dialog.fRetPlugin)
  673. return (btype, ptype, filename, label, uniqueId, extraPtr)
  674. def showAddJackAppDialog(self):
  675. dialog = JackApplicationW(self.fParentOrSelf, self.host)
  676. if not dialog.exec_():
  677. return
  678. if not self.host.is_engine_running():
  679. QMessageBox.warning(self, self.tr("Warning"), self.tr("Cannot add new plugins while engine is stopped"))
  680. return
  681. return dialog.getCommandAndFlags()
  682. @pyqtSlot()
  683. def showPluginActionsMenu(self):
  684. menu = QMenu(self)
  685. if config_UseQt5:
  686. menu.addSection("Plugins")
  687. else:
  688. # fake section
  689. act = menu.addAction(" Plugins")
  690. font = act.font()
  691. font.setBold(True)
  692. act.setFont(font)
  693. act.setEnabled(False)
  694. menu.addSeparator()
  695. menu.addAction(self.ui.act_plugin_add)
  696. menu.addAction(self.ui.act_plugin_remove_all)
  697. if config_UseQt5:
  698. menu.addSection("All plugins (macros)")
  699. else:
  700. # fake space
  701. act = menu.addAction(" ")
  702. font = act.font()
  703. font.setBold(True)
  704. font.setPointSize(font.pointSize()/2)
  705. act.setEnabled(False)
  706. # fake section
  707. act = menu.addAction(" All plugins (macros)")
  708. font = act.font()
  709. font.setBold(True)
  710. act.setFont(font)
  711. act.setEnabled(False)
  712. menu.addSeparator()
  713. menu.addAction(self.ui.act_plugins_enable)
  714. menu.addAction(self.ui.act_plugins_disable)
  715. menu.addSeparator()
  716. menu.addAction(self.ui.act_plugins_volume100)
  717. menu.addAction(self.ui.act_plugins_mute)
  718. menu.addSeparator()
  719. menu.addAction(self.ui.act_plugins_wet100)
  720. menu.addAction(self.ui.act_plugins_bypass)
  721. menu.addSeparator()
  722. menu.addAction(self.ui.act_plugins_center)
  723. menu.addSeparator()
  724. menu.addAction(self.ui.act_plugins_compact)
  725. menu.addAction(self.ui.act_plugins_expand)
  726. menu.exec_(QCursor.pos())
  727. @pyqtSlot()
  728. def slot_pluginAdd(self):
  729. data = self.showAddPluginDialog()
  730. if data is None:
  731. return
  732. btype, ptype, filename, label, uniqueId, extraPtr = data
  733. if not self.host.add_plugin(btype, ptype, filename, None, label, uniqueId, extraPtr, 0x0):
  734. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Failed to load plugin"), self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  735. @pyqtSlot()
  736. def slot_pluginRemoveAll(self):
  737. if self.fPluginCount == 0:
  738. return
  739. # FIXME - this is not working
  740. # removing a plugin causes flicker, the rack-list becomes empty for some time
  741. # this breaks the remove-all animation, so don't bother using it
  742. if False and not self.host.isPlugin:
  743. self.projectLoadingStarted()
  744. app = QApplication.instance()
  745. app.processEvents()
  746. for i in reversed(range(self.fPluginCount)):
  747. self.host.remove_plugin(i)
  748. app.processEvents()
  749. self.projectLoadingFinished()
  750. self.fCurrentlyRemovingAllPlugins = True
  751. ok = self.host.remove_all_plugins()
  752. self.fCurrentlyRemovingAllPlugins = False
  753. if ok:
  754. self.removeAllPlugins()
  755. else:
  756. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  757. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  758. self.fCurrentlyRemovingAllPlugins = False
  759. @pyqtSlot()
  760. def slot_jackAppAdd(self):
  761. data = self.showAddJackAppDialog()
  762. if data is None:
  763. return
  764. filename, name, label = data
  765. if not filename:
  766. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Cannot add jack application"),
  767. self.tr("command is empty"), QMessageBox.Ok, QMessageBox.Ok)
  768. return
  769. if not self.host.add_plugin(BINARY_NATIVE, PLUGIN_JACK, filename, name, label, 0, None, 0x0):
  770. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Failed to load plugin"),
  771. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  772. # --------------------------------------------------------------------------------------------------------
  773. # Plugins (macros)
  774. @pyqtSlot()
  775. def slot_pluginsEnable(self):
  776. if not self.host.is_engine_running():
  777. return
  778. for pitem in self.fPluginList:
  779. if pitem is None:
  780. break
  781. pitem.getWidget().setActive(True, True, True)
  782. @pyqtSlot()
  783. def slot_pluginsDisable(self):
  784. if not self.host.is_engine_running():
  785. return
  786. for pitem in self.fPluginList:
  787. if pitem is None:
  788. break
  789. pitem.getWidget().setActive(False, True, True)
  790. @pyqtSlot()
  791. def slot_pluginsVolume100(self):
  792. if not self.host.is_engine_running():
  793. return
  794. for pitem in self.fPluginList:
  795. if pitem is None:
  796. break
  797. pitem.getWidget().setInternalParameter(PLUGIN_CAN_VOLUME, 1.0)
  798. @pyqtSlot()
  799. def slot_pluginsMute(self):
  800. if not self.host.is_engine_running():
  801. return
  802. for pitem in self.fPluginList:
  803. if pitem is None:
  804. break
  805. pitem.getWidget().setInternalParameter(PLUGIN_CAN_VOLUME, 0.0)
  806. @pyqtSlot()
  807. def slot_pluginsWet100(self):
  808. if not self.host.is_engine_running():
  809. return
  810. for pitem in self.fPluginList:
  811. if pitem is None:
  812. break
  813. pitem.getWidget().setInternalParameter(PLUGIN_CAN_DRYWET, 1.0)
  814. @pyqtSlot()
  815. def slot_pluginsBypass(self):
  816. if not self.host.is_engine_running():
  817. return
  818. for pitem in self.fPluginList:
  819. if pitem is None:
  820. break
  821. pitem.getWidget().setInternalParameter(PLUGIN_CAN_DRYWET, 0.0)
  822. @pyqtSlot()
  823. def slot_pluginsCenter(self):
  824. if not self.host.is_engine_running():
  825. return
  826. for pitem in self.fPluginList:
  827. if pitem is None:
  828. break
  829. pitem.getWidget().setInternalParameter(PARAMETER_BALANCE_LEFT, -1.0)
  830. pitem.getWidget().setInternalParameter(PARAMETER_BALANCE_RIGHT, 1.0)
  831. pitem.getWidget().setInternalParameter(PARAMETER_PANNING, 0.0)
  832. @pyqtSlot()
  833. def slot_pluginsCompact(self):
  834. for pitem in self.fPluginList:
  835. if pitem is None:
  836. break
  837. pitem.compact()
  838. @pyqtSlot()
  839. def slot_pluginsExpand(self):
  840. for pitem in self.fPluginList:
  841. if pitem is None:
  842. break
  843. pitem.expand()
  844. # --------------------------------------------------------------------------------------------------------
  845. # Plugins (host callbacks)
  846. @pyqtSlot(int, str)
  847. def slot_handlePluginAddedCallback(self, pluginId, pluginName):
  848. pitem = self.ui.listWidget.createItem(pluginId, self.fSavedSettings[CARLA_KEY_MAIN_USE_CUSTOM_SKINS])
  849. self.fPluginList.append(pitem)
  850. self.fPluginCount += 1
  851. self.ui.act_plugin_remove_all.setEnabled(self.fPluginCount > 0)
  852. @pyqtSlot(int)
  853. def slot_handlePluginRemovedCallback(self, pluginId):
  854. patchcanvas.handlePluginRemoved(pluginId)
  855. if pluginId in self.fSelectedPlugins:
  856. self.clearSideStuff()
  857. pitem = self.getPluginItem(pluginId)
  858. self.fPluginCount -= 1
  859. self.fPluginList.pop(pluginId)
  860. self.ui.listWidget.takeItem(pluginId)
  861. if pitem is not None:
  862. pitem.close()
  863. del pitem
  864. # push all plugins 1 slot back
  865. for i in range(pluginId, self.fPluginCount):
  866. pitem = self.fPluginList[i]
  867. pitem.setPluginId(i)
  868. self.ui.act_plugin_remove_all.setEnabled(self.fPluginCount > 0)
  869. # --------------------------------------------------------------------------------------------------------
  870. # Canvas
  871. def clearSideStuff(self):
  872. self.scene.clearSelection()
  873. self.fSelectedPlugins = []
  874. self.ui.keyboard.allNotesOff(False)
  875. self.ui.scrollArea.setEnabled(False)
  876. self.fPeaksCleared = True
  877. self.ui.peak_in.displayMeter(1, 0.0, True)
  878. self.ui.peak_in.displayMeter(2, 0.0, True)
  879. self.ui.peak_out.displayMeter(1, 0.0, True)
  880. self.ui.peak_out.displayMeter(2, 0.0, True)
  881. def setupCanvas(self):
  882. pOptions = patchcanvas.options_t()
  883. pOptions.theme_name = self.fSavedSettings[CARLA_KEY_CANVAS_THEME]
  884. pOptions.auto_hide_groups = self.fSavedSettings[CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS]
  885. pOptions.auto_select_items = self.fSavedSettings[CARLA_KEY_CANVAS_AUTO_SELECT_ITEMS]
  886. pOptions.use_bezier_lines = self.fSavedSettings[CARLA_KEY_CANVAS_USE_BEZIER_LINES]
  887. pOptions.antialiasing = self.fSavedSettings[CARLA_KEY_CANVAS_ANTIALIASING]
  888. if self.fSavedSettings[CARLA_KEY_CANVAS_FANCY_EYE_CANDY]:
  889. pOptions.eyecandy = patchcanvas.EYECANDY_FULL
  890. elif self.fSavedSettings[CARLA_KEY_CANVAS_EYE_CANDY]:
  891. pOptions.eyecandy = patchcanvas.EYECANDY_SMALL
  892. else:
  893. pOptions.eyecandy = patchcanvas.EYECANDY_NONE
  894. pFeatures = patchcanvas.features_t()
  895. pFeatures.group_info = False
  896. pFeatures.group_rename = False
  897. pFeatures.port_info = False
  898. pFeatures.port_rename = False
  899. pFeatures.handle_group_pos = True
  900. patchcanvas.setOptions(pOptions)
  901. patchcanvas.setFeatures(pFeatures)
  902. patchcanvas.init("Carla2", self.scene, canvasCallback, False)
  903. tryCanvasSize = self.fSavedSettings[CARLA_KEY_CANVAS_SIZE].split("x")
  904. if len(tryCanvasSize) == 2 and tryCanvasSize[0].isdigit() and tryCanvasSize[1].isdigit():
  905. self.fCanvasWidth = int(tryCanvasSize[0])
  906. self.fCanvasHeight = int(tryCanvasSize[1])
  907. else:
  908. self.fCanvasWidth = CARLA_DEFAULT_CANVAS_SIZE_WIDTH
  909. self.fCanvasHeight = CARLA_DEFAULT_CANVAS_SIZE_HEIGHT
  910. patchcanvas.setCanvasSize(0, 0, self.fCanvasWidth, self.fCanvasHeight)
  911. patchcanvas.setInitialPos(self.fCanvasWidth / 2, self.fCanvasHeight / 2)
  912. self.ui.graphicsView.setSceneRect(0, 0, self.fCanvasWidth, self.fCanvasHeight)
  913. self.ui.miniCanvasPreview.setViewTheme(patchcanvas.canvas.theme.canvas_bg, patchcanvas.canvas.theme.rubberband_brush, patchcanvas.canvas.theme.rubberband_pen.color())
  914. self.ui.miniCanvasPreview.init(self.scene, self.fCanvasWidth, self.fCanvasHeight, self.fSavedSettings[CARLA_KEY_CUSTOM_PAINTING])
  915. def updateCanvasInitialPos(self):
  916. x = self.ui.graphicsView.horizontalScrollBar().value() + self.width()/4
  917. y = self.ui.graphicsView.verticalScrollBar().value() + self.height()/4
  918. patchcanvas.setInitialPos(x, y)
  919. def updateMiniCanvasLater(self):
  920. QTimer.singleShot(self.fMiniCanvasUpdateTimeout, self.ui.miniCanvasPreview.update)
  921. # --------------------------------------------------------------------------------------------------------
  922. # Canvas (menu actions)
  923. @pyqtSlot()
  924. def slot_canvasShowInternal(self):
  925. self.fExternalPatchbay = False
  926. self.ui.act_canvas_show_internal.blockSignals(True)
  927. self.ui.act_canvas_show_external.blockSignals(True)
  928. self.ui.act_canvas_show_internal.setChecked(True)
  929. self.ui.act_canvas_show_external.setChecked(False)
  930. self.ui.act_canvas_show_internal.blockSignals(False)
  931. self.ui.act_canvas_show_external.blockSignals(False)
  932. self.slot_canvasRefresh()
  933. @pyqtSlot()
  934. def slot_canvasShowExternal(self):
  935. self.fExternalPatchbay = True
  936. self.ui.act_canvas_show_internal.blockSignals(True)
  937. self.ui.act_canvas_show_external.blockSignals(True)
  938. self.ui.act_canvas_show_internal.setChecked(False)
  939. self.ui.act_canvas_show_external.setChecked(True)
  940. self.ui.act_canvas_show_internal.blockSignals(False)
  941. self.ui.act_canvas_show_external.blockSignals(False)
  942. self.slot_canvasRefresh()
  943. @pyqtSlot()
  944. def slot_canvasArrange(self):
  945. patchcanvas.arrange()
  946. @pyqtSlot()
  947. def slot_canvasRefresh(self):
  948. patchcanvas.clear()
  949. if self.host.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK and (self.host.isControl or self.host.isPlugin):
  950. return
  951. if self.host.is_engine_running():
  952. self.host.patchbay_refresh(self.fExternalPatchbay)
  953. self.updateMiniCanvasLater()
  954. @pyqtSlot()
  955. def slot_canvasZoomFit(self):
  956. self.scene.zoom_fit()
  957. @pyqtSlot()
  958. def slot_canvasZoomIn(self):
  959. self.scene.zoom_in()
  960. @pyqtSlot()
  961. def slot_canvasZoomOut(self):
  962. self.scene.zoom_out()
  963. @pyqtSlot()
  964. def slot_canvasZoomReset(self):
  965. self.scene.zoom_reset()
  966. @pyqtSlot()
  967. def slot_canvasSaveImage(self):
  968. newPath = QFileDialog.getSaveFileName(self, self.tr("Save Image"), filter=self.tr("PNG Image (*.png);;JPEG Image (*.jpg)"))
  969. if config_UseQt5:
  970. newPath = newPath[0]
  971. if not newPath:
  972. return
  973. self.scene.clearSelection()
  974. if newPath.lower().endswith((".jpg", ".jpeg")):
  975. imgFormat = "JPG"
  976. elif newPath.lower().endswith((".png",)):
  977. imgFormat = "PNG"
  978. else:
  979. # File-dialog may not auto-add the extension
  980. imgFormat = "PNG"
  981. newPath += ".png"
  982. self.fExportImage = QImage(self.scene.sceneRect().width(), self.scene.sceneRect().height(), QImage.Format_RGB32)
  983. painter = QPainter(self.fExportImage)
  984. painter.save()
  985. painter.setRenderHint(QPainter.Antialiasing) # TODO - set true, cleanup this
  986. painter.setRenderHint(QPainter.TextAntialiasing)
  987. self.scene.render(painter)
  988. self.fExportImage.save(newPath, imgFormat, 100)
  989. painter.restore()
  990. # --------------------------------------------------------------------------------------------------------
  991. # Canvas (canvas callbacks)
  992. @pyqtSlot(int, int, QPointF)
  993. def slot_canvasItemMoved(self, group_id, split_mode, pos):
  994. self.updateMiniCanvasLater()
  995. @pyqtSlot(float)
  996. def slot_canvasScaleChanged(self, scale):
  997. self.ui.miniCanvasPreview.setViewScale(scale)
  998. @pyqtSlot(list)
  999. def slot_canvasPluginSelected(self, pluginList):
  1000. self.ui.keyboard.allNotesOff(False)
  1001. self.ui.scrollArea.setEnabled(len(pluginList) != 0) # and self.fPluginCount > 0
  1002. self.fSelectedPlugins = pluginList
  1003. # --------------------------------------------------------------------------------------------------------
  1004. # Canvas (host callbacks)
  1005. @pyqtSlot(int, int, int, str)
  1006. def slot_handlePatchbayClientAddedCallback(self, clientId, clientIcon, pluginId, clientName):
  1007. pcSplit = patchcanvas.SPLIT_UNDEF
  1008. pcIcon = patchcanvas.ICON_APPLICATION
  1009. if clientIcon == PATCHBAY_ICON_PLUGIN:
  1010. pcIcon = patchcanvas.ICON_PLUGIN
  1011. if clientIcon == PATCHBAY_ICON_HARDWARE:
  1012. pcIcon = patchcanvas.ICON_HARDWARE
  1013. elif clientIcon == PATCHBAY_ICON_CARLA:
  1014. pass
  1015. elif clientIcon == PATCHBAY_ICON_DISTRHO:
  1016. pcIcon = patchcanvas.ICON_DISTRHO
  1017. elif clientIcon == PATCHBAY_ICON_FILE:
  1018. pcIcon = patchcanvas.ICON_FILE
  1019. patchcanvas.addGroup(clientId, clientName, pcSplit, pcIcon)
  1020. self.updateMiniCanvasLater()
  1021. if pluginId < 0:
  1022. return
  1023. if pluginId >= self.fPluginCount and pluginId != MAIN_CARLA_PLUGIN_ID:
  1024. print("sorry, can't map this plugin to canvas client", pluginId, self.fPluginCount)
  1025. return
  1026. if pluginId == MAIN_CARLA_PLUGIN_ID:
  1027. hasCustomUI = False
  1028. else:
  1029. hasCustomUI = bool(self.host.get_plugin_info(pluginId)['hints'] & PLUGIN_HAS_CUSTOM_UI)
  1030. patchcanvas.setGroupAsPlugin(clientId, pluginId, hasCustomUI)
  1031. @pyqtSlot(int)
  1032. def slot_handlePatchbayClientRemovedCallback(self, clientId):
  1033. patchcanvas.removeGroup(clientId)
  1034. self.updateMiniCanvasLater()
  1035. @pyqtSlot(int, str)
  1036. def slot_handlePatchbayClientRenamedCallback(self, clientId, newClientName):
  1037. patchcanvas.renameGroup(clientId, newClientName)
  1038. self.updateMiniCanvasLater()
  1039. @pyqtSlot(int, int, int)
  1040. def slot_handlePatchbayClientDataChangedCallback(self, clientId, clientIcon, pluginId):
  1041. pcIcon = patchcanvas.ICON_APPLICATION
  1042. if clientIcon == PATCHBAY_ICON_PLUGIN:
  1043. pcIcon = patchcanvas.ICON_PLUGIN
  1044. if clientIcon == PATCHBAY_ICON_HARDWARE:
  1045. pcIcon = patchcanvas.ICON_HARDWARE
  1046. elif clientIcon == PATCHBAY_ICON_CARLA:
  1047. pass
  1048. elif clientIcon == PATCHBAY_ICON_DISTRHO:
  1049. pcIcon = patchcanvas.ICON_DISTRHO
  1050. elif clientIcon == PATCHBAY_ICON_FILE:
  1051. pcIcon = patchcanvas.ICON_FILE
  1052. patchcanvas.setGroupIcon(clientId, pcIcon)
  1053. self.updateMiniCanvasLater()
  1054. if pluginId < 0:
  1055. return
  1056. if pluginId >= self.fPluginCount and pluginId != MAIN_CARLA_PLUGIN_ID:
  1057. print("sorry, can't map this plugin to canvas client", pluginId, self.fPluginCount)
  1058. return
  1059. if pluginId == MAIN_CARLA_PLUGIN_ID:
  1060. hasCustomUI = False
  1061. else:
  1062. hasCustomUI = bool(self.host.get_plugin_info(pluginId)['hints'] & PLUGIN_HAS_CUSTOM_UI)
  1063. patchcanvas.setGroupAsPlugin(clientId, pluginId, hasCustomUI)
  1064. @pyqtSlot(int, int, int, str)
  1065. def slot_handlePatchbayPortAddedCallback(self, clientId, portId, portFlags, portName):
  1066. if portFlags & PATCHBAY_PORT_IS_INPUT:
  1067. portMode = patchcanvas.PORT_MODE_INPUT
  1068. else:
  1069. portMode = patchcanvas.PORT_MODE_OUTPUT
  1070. if portFlags & PATCHBAY_PORT_TYPE_AUDIO:
  1071. portType = patchcanvas.PORT_TYPE_AUDIO_JACK
  1072. isAlternate = False
  1073. elif portFlags & PATCHBAY_PORT_TYPE_CV:
  1074. portType = patchcanvas.PORT_TYPE_AUDIO_JACK
  1075. isAlternate = True
  1076. elif portFlags & PATCHBAY_PORT_TYPE_MIDI:
  1077. portType = patchcanvas.PORT_TYPE_MIDI_JACK
  1078. isAlternate = False
  1079. else:
  1080. portType = patchcanvas.PORT_TYPE_NULL
  1081. isAlternate = False
  1082. patchcanvas.addPort(clientId, portId, portName, portMode, portType, isAlternate)
  1083. self.updateMiniCanvasLater()
  1084. @pyqtSlot(int, int)
  1085. def slot_handlePatchbayPortRemovedCallback(self, groupId, portId):
  1086. patchcanvas.removePort(groupId, portId)
  1087. self.updateMiniCanvasLater()
  1088. @pyqtSlot(int, int, str)
  1089. def slot_handlePatchbayPortRenamedCallback(self, groupId, portId, newPortName):
  1090. patchcanvas.renamePort(groupId, portId, newPortName)
  1091. self.updateMiniCanvasLater()
  1092. @pyqtSlot(int, int, int, int, int)
  1093. def slot_handlePatchbayConnectionAddedCallback(self, connectionId, groupOutId, portOutId, groupInId, portInId):
  1094. patchcanvas.connectPorts(connectionId, groupOutId, portOutId, groupInId, portInId)
  1095. self.updateMiniCanvasLater()
  1096. @pyqtSlot(int, int, int)
  1097. def slot_handlePatchbayConnectionRemovedCallback(self, connectionId, portOutId, portInId):
  1098. patchcanvas.disconnectPorts(connectionId)
  1099. self.updateMiniCanvasLater()
  1100. # --------------------------------------------------------------------------------------------------------
  1101. # Settings
  1102. def saveSettings(self):
  1103. settings = QSettings()
  1104. settings.setValue("Geometry", self.saveGeometry())
  1105. #settings.setValue("SplitterState", self.ui.splitter.saveState())
  1106. settings.setValue("ShowToolbar", self.ui.toolBar.isEnabled())
  1107. settings.setValue("ShowSidePanel", self.ui.dockWidget.isEnabled())
  1108. diskFolders = []
  1109. for i in range(self.ui.cb_disk.count()):
  1110. diskFolders.append(self.ui.cb_disk.itemData(i))
  1111. settings.setValue("DiskFolders", diskFolders)
  1112. settings.setValue("ShowMeters", self.ui.act_settings_show_meters.isChecked())
  1113. settings.setValue("ShowKeyboard", self.ui.act_settings_show_keyboard.isChecked())
  1114. settings.setValue("HorizontalScrollBarValue", self.ui.graphicsView.horizontalScrollBar().value())
  1115. settings.setValue("VerticalScrollBarValue", self.ui.graphicsView.verticalScrollBar().value())
  1116. def loadSettings(self, firstTime):
  1117. settings = QSettings()
  1118. if firstTime:
  1119. self.restoreGeometry(settings.value("Geometry", b""))
  1120. showToolbar = settings.value("ShowToolbar", True, type=bool)
  1121. self.ui.act_settings_show_toolbar.setChecked(showToolbar)
  1122. self.ui.toolBar.setEnabled(showToolbar)
  1123. self.ui.toolBar.setVisible(showToolbar)
  1124. #if settings.contains("SplitterState"):
  1125. #self.ui.splitter.restoreState(settings.value("SplitterState", b""))
  1126. #else:
  1127. #self.ui.splitter.setSizes([210, 99999])
  1128. showSidePanel = settings.value("ShowSidePanel", True, type=bool)
  1129. self.ui.act_settings_show_side_panel.setChecked(showSidePanel)
  1130. self.ui.dockWidget.setEnabled(showSidePanel)
  1131. self.ui.dockWidget.setVisible(showSidePanel)
  1132. diskFolders = toList(settings.value("DiskFolders", [HOME]))
  1133. self.ui.cb_disk.setItemData(0, HOME)
  1134. for i in range(len(diskFolders)):
  1135. if i == 0: continue
  1136. folder = diskFolders[i]
  1137. self.ui.cb_disk.addItem(os.path.basename(folder), folder)
  1138. #if MACOS and not settings.value(CARLA_KEY_MAIN_USE_PRO_THEME, True, type=bool):
  1139. # self.setUnifiedTitleAndToolBarOnMac(True)
  1140. showMeters = settings.value("ShowMeters", False, type=bool)
  1141. self.ui.act_settings_show_meters.setChecked(showMeters)
  1142. self.ui.peak_in.setVisible(showMeters)
  1143. self.ui.peak_out.setVisible(showMeters)
  1144. showKeyboard = settings.value("ShowKeyboard", not(MACOS or WINDOWS), type=bool)
  1145. self.ui.act_settings_show_keyboard.setChecked(showKeyboard)
  1146. self.ui.scrollArea.setVisible(showKeyboard)
  1147. QTimer.singleShot(100, self.slot_restoreCanvasScrollbarValues)
  1148. # TODO - complete this
  1149. self.fSavedSettings = {
  1150. CARLA_KEY_MAIN_PROJECT_FOLDER: settings.value(CARLA_KEY_MAIN_PROJECT_FOLDER, CARLA_DEFAULT_MAIN_PROJECT_FOLDER, type=str),
  1151. CARLA_KEY_MAIN_REFRESH_INTERVAL: settings.value(CARLA_KEY_MAIN_REFRESH_INTERVAL, CARLA_DEFAULT_MAIN_REFRESH_INTERVAL, type=int),
  1152. CARLA_KEY_MAIN_USE_CUSTOM_SKINS: settings.value(CARLA_KEY_MAIN_USE_CUSTOM_SKINS, CARLA_DEFAULT_MAIN_USE_CUSTOM_SKINS, type=bool),
  1153. CARLA_KEY_MAIN_EXPERIMENTAL: settings.value(CARLA_KEY_MAIN_EXPERIMENTAL, CARLA_DEFAULT_MAIN_EXPERIMENTAL, type=bool),
  1154. CARLA_KEY_CANVAS_THEME: settings.value(CARLA_KEY_CANVAS_THEME, CARLA_DEFAULT_CANVAS_THEME, type=str),
  1155. CARLA_KEY_CANVAS_SIZE: settings.value(CARLA_KEY_CANVAS_SIZE, CARLA_DEFAULT_CANVAS_SIZE, type=str),
  1156. CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS: settings.value(CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS, CARLA_DEFAULT_CANVAS_AUTO_HIDE_GROUPS, type=bool),
  1157. CARLA_KEY_CANVAS_AUTO_SELECT_ITEMS: settings.value(CARLA_KEY_CANVAS_AUTO_SELECT_ITEMS, CARLA_DEFAULT_CANVAS_AUTO_SELECT_ITEMS, type=bool),
  1158. CARLA_KEY_CANVAS_USE_BEZIER_LINES: settings.value(CARLA_KEY_CANVAS_USE_BEZIER_LINES, CARLA_DEFAULT_CANVAS_USE_BEZIER_LINES, type=bool),
  1159. CARLA_KEY_CANVAS_EYE_CANDY: settings.value(CARLA_KEY_CANVAS_EYE_CANDY, CARLA_DEFAULT_CANVAS_EYE_CANDY, type=bool),
  1160. CARLA_KEY_CANVAS_FANCY_EYE_CANDY: settings.value(CARLA_KEY_CANVAS_FANCY_EYE_CANDY, CARLA_DEFAULT_CANVAS_FANCY_EYE_CANDY, type=bool),
  1161. CARLA_KEY_CANVAS_USE_OPENGL: settings.value(CARLA_KEY_CANVAS_USE_OPENGL, CARLA_DEFAULT_CANVAS_USE_OPENGL, type=bool),
  1162. CARLA_KEY_CANVAS_ANTIALIASING: settings.value(CARLA_KEY_CANVAS_ANTIALIASING, CARLA_DEFAULT_CANVAS_ANTIALIASING, type=int),
  1163. CARLA_KEY_CANVAS_HQ_ANTIALIASING: settings.value(CARLA_KEY_CANVAS_HQ_ANTIALIASING, CARLA_DEFAULT_CANVAS_HQ_ANTIALIASING, type=bool),
  1164. CARLA_KEY_CUSTOM_PAINTING: (settings.value(CARLA_KEY_MAIN_USE_PRO_THEME, True, type=bool) and
  1165. settings.value(CARLA_KEY_MAIN_PRO_THEME_COLOR, "Black", type=str).lower() == "black"),
  1166. }
  1167. self.ui.act_add_jack.setVisible(settings.value(CARLA_KEY_EXPERIMENTAL_JACK_APPS,
  1168. CARLA_DEFAULT_EXPERIMENTAL_JACK_APPS, type=bool))
  1169. if not (self.host.isControl or self.host.isPlugin):
  1170. if settings.value(CARLA_KEY_EXPERIMENTAL_TRANSPORT, CARLA_DEFAULT_EXPERIMENTAL_TRANSPORT, type=bool):
  1171. if self.ui.cb_transport_jack.isChecked():
  1172. transportMode = ENGINE_TRANSPORT_MODE_JACK
  1173. else:
  1174. transportMode = ENGINE_TRANSPORT_MODE_INTERNAL
  1175. transportExtra = ":link:" if self.ui.cb_transport_link.isChecked() else ""
  1176. else:
  1177. # Stop transport if becoming disabled
  1178. if self.ui.w_transport.isEnabled() and self.host.is_engine_running():
  1179. self.host.transport_pause()
  1180. self.host.transport_relocate(0)
  1181. self.host.transport_pause()
  1182. transportMode = ENGINE_TRANSPORT_MODE_DISABLED
  1183. transportExtra = ""
  1184. self.ui.w_transport.setEnabled(transportMode != ENGINE_TRANSPORT_MODE_DISABLED)
  1185. self.host.transportMode = transportMode
  1186. self.host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE, transportMode, transportExtra)
  1187. self.fMiniCanvasUpdateTimeout = 1000 if self.fSavedSettings[CARLA_KEY_CANVAS_FANCY_EYE_CANDY] else 0
  1188. setEngineSettings(self.host)
  1189. self.restartTimersIfNeeded()
  1190. # --------------------------------------------------------------------------------------------------------
  1191. # Settings (helpers)
  1192. @pyqtSlot()
  1193. def slot_restoreCanvasScrollbarValues(self):
  1194. settings = QSettings()
  1195. self.ui.graphicsView.horizontalScrollBar().setValue(settings.value("HorizontalScrollBarValue", self.ui.graphicsView.horizontalScrollBar().maximum()/2, type=int))
  1196. self.ui.graphicsView.verticalScrollBar().setValue(settings.value("VerticalScrollBarValue", self.ui.graphicsView.verticalScrollBar().maximum()/2, type=int))
  1197. # --------------------------------------------------------------------------------------------------------
  1198. # Settings (menu actions)
  1199. @pyqtSlot(bool)
  1200. def slot_showSidePanel(self, yesNo):
  1201. self.ui.dockWidget.setEnabled(yesNo)
  1202. self.ui.dockWidget.setVisible(yesNo)
  1203. @pyqtSlot(bool)
  1204. def slot_showToolbar(self, yesNo):
  1205. self.ui.toolBar.setEnabled(yesNo)
  1206. self.ui.toolBar.setVisible(yesNo)
  1207. @pyqtSlot(bool)
  1208. def slot_showCanvasMeters(self, yesNo):
  1209. self.ui.peak_in.setVisible(yesNo)
  1210. self.ui.peak_out.setVisible(yesNo)
  1211. QTimer.singleShot(0, self.slot_miniCanvasCheckAll)
  1212. @pyqtSlot(bool)
  1213. def slot_showCanvasKeyboard(self, yesNo):
  1214. self.ui.scrollArea.setVisible(yesNo)
  1215. QTimer.singleShot(0, self.slot_miniCanvasCheckAll)
  1216. @pyqtSlot()
  1217. def slot_configureCarla(self):
  1218. dialog = CarlaSettingsW(self.fParentOrSelf, self.host, True, hasGL)
  1219. if not dialog.exec_():
  1220. return
  1221. self.loadSettings(False)
  1222. patchcanvas.clear()
  1223. self.setupCanvas()
  1224. self.slot_miniCanvasCheckAll()
  1225. if self.host.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK and self.host.isPlugin:
  1226. pass
  1227. elif self.host.is_engine_running():
  1228. self.host.patchbay_refresh(self.fExternalPatchbay)
  1229. for pitem in self.fPluginList:
  1230. if pitem is None:
  1231. break
  1232. pitem.setUsingSkins(self.fSavedSettings[CARLA_KEY_MAIN_USE_CUSTOM_SKINS])
  1233. pitem.recreateWidget()
  1234. # --------------------------------------------------------------------------------------------------------
  1235. # About (menu actions)
  1236. @pyqtSlot()
  1237. def slot_aboutCarla(self):
  1238. CarlaAboutW(self.fParentOrSelf, self.host).exec_()
  1239. @pyqtSlot()
  1240. def slot_aboutQt(self):
  1241. QApplication.instance().aboutQt()
  1242. # --------------------------------------------------------------------------------------------------------
  1243. # Disk (menu actions)
  1244. @pyqtSlot(int)
  1245. def slot_diskFolderChanged(self, index):
  1246. if index < 0:
  1247. return
  1248. elif index == 0:
  1249. filename = HOME
  1250. self.ui.b_disk_remove.setEnabled(False)
  1251. else:
  1252. filename = self.ui.cb_disk.itemData(index)
  1253. self.ui.b_disk_remove.setEnabled(True)
  1254. self.fDirModel.setRootPath(filename)
  1255. self.ui.fileTreeView.setRootIndex(self.fDirModel.index(filename))
  1256. @pyqtSlot()
  1257. def slot_diskFolderAdd(self):
  1258. newPath = QFileDialog.getExistingDirectory(self, self.tr("New Folder"), "", QFileDialog.ShowDirsOnly)
  1259. if newPath:
  1260. if newPath[-1] == os.sep:
  1261. newPath = newPath[:-1]
  1262. self.ui.cb_disk.addItem(os.path.basename(newPath), newPath)
  1263. self.ui.cb_disk.setCurrentIndex(self.ui.cb_disk.count()-1)
  1264. self.ui.b_disk_remove.setEnabled(True)
  1265. @pyqtSlot()
  1266. def slot_diskFolderRemove(self):
  1267. index = self.ui.cb_disk.currentIndex()
  1268. if index <= 0:
  1269. return
  1270. self.ui.cb_disk.removeItem(index)
  1271. if self.ui.cb_disk.currentIndex() == 0:
  1272. self.ui.b_disk_remove.setEnabled(False)
  1273. @pyqtSlot(QModelIndex)
  1274. def slot_fileTreeDoubleClicked(self, modelIndex):
  1275. filename = self.fDirModel.filePath(modelIndex)
  1276. if not self.ui.listWidget.isDragUrlValid(filename):
  1277. return
  1278. if not self.host.load_file(filename):
  1279. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"),
  1280. self.tr("Failed to load file"),
  1281. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1282. # --------------------------------------------------------------------------------------------------------
  1283. # Transport
  1284. def refreshTransport(self, forced = False):
  1285. if not self.isVisible():
  1286. return
  1287. if self.fSampleRate == 0.0 or not self.host.is_engine_running():
  1288. return
  1289. timeInfo = self.host.get_transport_info()
  1290. playing = timeInfo['playing']
  1291. frame = timeInfo['frame']
  1292. bpm = timeInfo['bpm']
  1293. if playing != self.fLastTransportState or forced:
  1294. if playing:
  1295. icon = getIcon("media-playback-pause")
  1296. self.ui.b_transport_play.setChecked(True)
  1297. self.ui.b_transport_play.setIcon(icon)
  1298. #self.ui.b_transport_play.setText(self.tr("&Pause"))
  1299. else:
  1300. icon = getIcon("media-playback-start")
  1301. self.ui.b_transport_play.setChecked(False)
  1302. self.ui.b_transport_play.setIcon(icon)
  1303. #self.ui.b_play.setText(self.tr("&Play"))
  1304. self.fLastTransportState = playing
  1305. if frame != self.fLastTransportFrame or forced:
  1306. self.fLastTransportFrame = frame
  1307. time = frame / self.fSampleRate
  1308. secs = time % 60
  1309. mins = (time / 60) % 60
  1310. hrs = (time / 3600) % 60
  1311. self.ui.l_transport_time.setText("%02i:%02i:%02i" % (hrs, mins, secs))
  1312. frame1 = frame % 1000
  1313. frame2 = (frame / 1000) % 1000
  1314. frame3 = (frame / 1000000) % 1000
  1315. self.ui.l_transport_frame.setText("%03i'%03i'%03i" % (frame3, frame2, frame1))
  1316. bar = timeInfo['bar']
  1317. beat = timeInfo['beat']
  1318. tick = timeInfo['tick']
  1319. self.ui.l_transport_bbt.setText("%03i|%02i|%04i" % (bar, beat, tick))
  1320. if bpm != self.fLastTransportBPM or forced:
  1321. self.fLastTransportBPM = bpm
  1322. if bpm > 0.0:
  1323. self.ui.dsb_transport_bpm.blockSignals(True)
  1324. self.ui.dsb_transport_bpm.setValue(bpm)
  1325. self.ui.dsb_transport_bpm.blockSignals(False)
  1326. self.ui.dsb_transport_bpm.setStyleSheet("")
  1327. else:
  1328. self.ui.dsb_transport_bpm.setStyleSheet("QDoubleSpinBox { color: palette(mid); }")
  1329. # --------------------------------------------------------------------------------------------------------
  1330. # Transport (menu actions)
  1331. @pyqtSlot(bool)
  1332. def slot_transportPlayPause(self, toggled):
  1333. if self.host.isPlugin or not self.host.is_engine_running():
  1334. return
  1335. if toggled:
  1336. self.host.transport_play()
  1337. else:
  1338. self.host.transport_pause()
  1339. self.refreshTransport()
  1340. @pyqtSlot()
  1341. def slot_transportStop(self):
  1342. if self.host.isPlugin or not self.host.is_engine_running():
  1343. return
  1344. self.host.transport_pause()
  1345. self.host.transport_relocate(0)
  1346. self.refreshTransport()
  1347. @pyqtSlot()
  1348. def slot_transportBackwards(self):
  1349. if self.host.isPlugin or not self.host.is_engine_running():
  1350. return
  1351. newFrame = self.host.get_current_transport_frame() - 100000
  1352. if newFrame < 0:
  1353. newFrame = 0
  1354. self.host.transport_relocate(newFrame)
  1355. @pyqtSlot(float)
  1356. def slot_transportBpmChanged(self, newValue):
  1357. self.host.transport_bpm(newValue)
  1358. @pyqtSlot()
  1359. def slot_transportForwards(self):
  1360. if self.fSampleRate == 0.0 or self.host.isPlugin or not self.host.is_engine_running():
  1361. return
  1362. newFrame = self.host.get_current_transport_frame() + int(self.fSampleRate*2.5)
  1363. self.host.transport_relocate(newFrame)
  1364. @pyqtSlot(bool)
  1365. def slot_transportJackEnabled(self, clicked):
  1366. if not self.host.is_engine_running():
  1367. return
  1368. mode = ENGINE_TRANSPORT_MODE_JACK if clicked else ENGINE_TRANSPORT_MODE_INTERNAL
  1369. extra = ":link:" if self.ui.cb_transport_link.isChecked() else ""
  1370. self.host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE, mode, extra)
  1371. @pyqtSlot(bool)
  1372. def slot_transportLinkEnabled(self, clicked):
  1373. if not self.host.is_engine_running():
  1374. return
  1375. mode = ENGINE_TRANSPORT_MODE_JACK if self.ui.cb_transport_jack.isChecked() else ENGINE_TRANSPORT_MODE_INTERNAL
  1376. extra = ":link:" if clicked else ""
  1377. self.host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE, mode, extra)
  1378. # --------------------------------------------------------------------------------------------------------
  1379. # Canvas scrollbars
  1380. @pyqtSlot(int)
  1381. def slot_horizontalScrollBarChanged(self, value):
  1382. maximum = self.ui.graphicsView.horizontalScrollBar().maximum()
  1383. if maximum == 0:
  1384. xp = 0
  1385. else:
  1386. xp = float(value) / maximum
  1387. self.ui.miniCanvasPreview.setViewPosX(xp)
  1388. self.updateCanvasInitialPos()
  1389. @pyqtSlot(int)
  1390. def slot_verticalScrollBarChanged(self, value):
  1391. maximum = self.ui.graphicsView.verticalScrollBar().maximum()
  1392. if maximum == 0:
  1393. yp = 0
  1394. else:
  1395. yp = float(value) / maximum
  1396. self.ui.miniCanvasPreview.setViewPosY(yp)
  1397. self.updateCanvasInitialPos()
  1398. # --------------------------------------------------------------------------------------------------------
  1399. # Canvas keyboard
  1400. @pyqtSlot(int)
  1401. def slot_noteOn(self, note):
  1402. for pluginId in self.fSelectedPlugins:
  1403. self.host.send_midi_note(pluginId, 0, note, 100)
  1404. pedit = self.getPluginEditDialog(pluginId)
  1405. pedit.noteOn(0, note, 100)
  1406. @pyqtSlot(int)
  1407. def slot_noteOff(self, note):
  1408. for pluginId in self.fSelectedPlugins:
  1409. self.host.send_midi_note(pluginId, 0, note, 0)
  1410. pedit = self.getPluginEditDialog(pluginId)
  1411. pedit.noteOff(0, note)
  1412. # --------------------------------------------------------------------------------------------------------
  1413. # Canvas keyboard (host callbacks)
  1414. @pyqtSlot(int, int, int, int)
  1415. def slot_handleNoteOnCallback(self, pluginId, channel, note, velocity):
  1416. if pluginId in self.fSelectedPlugins:
  1417. self.ui.keyboard.sendNoteOn(note, False)
  1418. @pyqtSlot(int, int, int)
  1419. def slot_handleNoteOffCallback(self, pluginId, channel, note):
  1420. if pluginId in self.fSelectedPlugins:
  1421. self.ui.keyboard.sendNoteOff(note, False)
  1422. # --------------------------------------------------------------------------------------------------------
  1423. @pyqtSlot(int)
  1424. def slot_handleUpdateCallback(self, pluginId):
  1425. pitem = self.getPluginItem(pluginId)
  1426. if pitem is None:
  1427. return
  1428. wasCompacted = pitem.isCompacted()
  1429. isCompacted = wasCompacted
  1430. for i in range(self.host.get_custom_data_count(pluginId)):
  1431. cdata = self.host.get_custom_data(pluginId, i)
  1432. if cdata['type'] == CUSTOM_DATA_TYPE_PROPERTY and cdata['key'] == "CarlaSkinIsCompacted":
  1433. isCompacted = bool(cdata['value'] == "true")
  1434. break
  1435. else:
  1436. return
  1437. if wasCompacted == isCompacted:
  1438. return
  1439. pitem.recreateWidget(True)
  1440. # --------------------------------------------------------------------------------------------------------
  1441. # MiniCanvas stuff
  1442. @pyqtSlot()
  1443. def slot_miniCanvasCheckAll(self):
  1444. self.slot_miniCanvasCheckSize()
  1445. self.slot_horizontalScrollBarChanged(self.ui.graphicsView.horizontalScrollBar().value())
  1446. self.slot_verticalScrollBarChanged(self.ui.graphicsView.verticalScrollBar().value())
  1447. @pyqtSlot()
  1448. def slot_miniCanvasCheckSize(self):
  1449. if self.fCanvasWidth == 0 or self.fCanvasHeight == 0:
  1450. return
  1451. currentIndex = self.ui.tabWidget.currentIndex()
  1452. if currentIndex == 1:
  1453. width = self.ui.graphicsView.width()
  1454. height = self.ui.graphicsView.height()
  1455. else:
  1456. self.ui.tabWidget.blockSignals(True)
  1457. self.ui.tabWidget.setCurrentIndex(1)
  1458. width = self.ui.graphicsView.width()
  1459. height = self.ui.graphicsView.height()
  1460. self.ui.tabWidget.setCurrentIndex(currentIndex)
  1461. self.ui.tabWidget.blockSignals(False)
  1462. self.ui.miniCanvasPreview.setViewSize(float(width)/self.fCanvasWidth, float(height)/self.fCanvasHeight)
  1463. @pyqtSlot(float, float)
  1464. def slot_miniCanvasMoved(self, xp, yp):
  1465. hsb = self.ui.graphicsView.horizontalScrollBar()
  1466. vsb = self.ui.graphicsView.verticalScrollBar()
  1467. hsb.setValue(xp * hsb.maximum())
  1468. vsb.setValue(yp * vsb.maximum())
  1469. self.updateCanvasInitialPos()
  1470. # --------------------------------------------------------------------------------------------------------
  1471. # Timers
  1472. def startTimers(self):
  1473. if self.fIdleTimerFast == 0:
  1474. self.fIdleTimerFast = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL])
  1475. if self.fIdleTimerSlow == 0:
  1476. self.fIdleTimerSlow = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL]*4)
  1477. def restartTimersIfNeeded(self):
  1478. if self.fIdleTimerFast != 0:
  1479. self.killTimer(self.fIdleTimerFast)
  1480. self.fIdleTimerFast = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL])
  1481. if self.fIdleTimerSlow != 0:
  1482. self.killTimer(self.fIdleTimerSlow)
  1483. self.fIdleTimerSlow = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL]*4)
  1484. def killTimers(self):
  1485. if self.fIdleTimerFast != 0:
  1486. self.killTimer(self.fIdleTimerFast)
  1487. self.fIdleTimerFast = 0
  1488. if self.fIdleTimerSlow != 0:
  1489. self.killTimer(self.fIdleTimerSlow)
  1490. self.fIdleTimerSlow = 0
  1491. # --------------------------------------------------------------------------------------------------------
  1492. # Misc
  1493. @pyqtSlot(int)
  1494. def slot_tabChanged(self, index):
  1495. if index != 1:
  1496. return
  1497. self.ui.graphicsView.setFocus()
  1498. @pyqtSlot(int)
  1499. def slot_handleReloadAllCallback(self, pluginId):
  1500. if pluginId >= self.fPluginCount:
  1501. return
  1502. pitem = self.fPluginList[pluginId]
  1503. if pitem is None:
  1504. return
  1505. pitem.recreateWidget()
  1506. # --------------------------------------------------------------------------------------------------------
  1507. @pyqtSlot(int, int, str)
  1508. def slot_handleNSMCallback(self, value1, value2, valueStr):
  1509. # Error
  1510. if value1 == 0:
  1511. pass
  1512. # Reply
  1513. elif value1 == 1:
  1514. self.fFirstEngineInit = False
  1515. self.fSessionManagerName = valueStr
  1516. self.setProperWindowTitle()
  1517. # Open
  1518. elif value1 == 2:
  1519. self.fClientName = os.path.basename(valueStr)
  1520. self.fProjectFilename = QFileInfo(valueStr+".carxp").absoluteFilePath()
  1521. self.setProperWindowTitle()
  1522. self.fCustomStopAction = 2
  1523. self.slot_engineStop(True)
  1524. return
  1525. # Save
  1526. elif value1 == 3:
  1527. self.saveProjectNow()
  1528. # Session is Loaded
  1529. elif value1 == 4:
  1530. pass
  1531. # Show Optional Gui
  1532. elif value1 == 5:
  1533. self.show()
  1534. # Hide Optional Gui
  1535. elif value1 == 6:
  1536. self.hide()
  1537. self.host.nsm_ready(value1)
  1538. # --------------------------------------------------------------------------------------------------------
  1539. def fixLogText(self, text):
  1540. return text.replace("\x1b[30;1m", "").replace("\x1b[31m", "").replace("\x1b[0m", "")
  1541. @pyqtSlot(int, int, int, float, str)
  1542. def slot_handleDebugCallback(self, pluginId, value1, value2, value3, valueStr):
  1543. self.ui.text_logs.appendPlainText(self.fixLogText(valueStr))
  1544. @pyqtSlot(str)
  1545. def slot_handleInfoCallback(self, info):
  1546. QMessageBox.information(self, "Information", info)
  1547. @pyqtSlot(str)
  1548. def slot_handleErrorCallback(self, error):
  1549. QMessageBox.critical(self, "Error", error)
  1550. @pyqtSlot()
  1551. def slot_handleQuitCallback(self):
  1552. pass # TODO
  1553. # --------------------------------------------------------------------------------------------------------
  1554. @pyqtSlot()
  1555. def slot_handleSIGUSR1(self):
  1556. print("Got SIGUSR1 -> Saving project now")
  1557. self.slot_fileSave()
  1558. @pyqtSlot()
  1559. def slot_handleSIGTERM(self):
  1560. print("Got SIGTERM -> Closing now")
  1561. self.fCustomStopAction = 1
  1562. self.slot_engineStop(True)
  1563. # --------------------------------------------------------------------------------------------------------
  1564. # Internal stuff
  1565. def getExtraPtr(self, plugin):
  1566. ptype = plugin['type']
  1567. if ptype == PLUGIN_LADSPA:
  1568. uniqueId = plugin['uniqueId']
  1569. self.maybeLoadRDFs()
  1570. for rdfItem in self.fLadspaRdfList:
  1571. if rdfItem.UniqueID == uniqueId:
  1572. return pointer(rdfItem)
  1573. elif ptype in (PLUGIN_GIG, PLUGIN_SF2):
  1574. if plugin['name'].lower().endswith(" (16 outputs)"):
  1575. return self._true
  1576. return None
  1577. def maybeLoadRDFs(self):
  1578. if not self.fLadspaRdfNeedsUpdate:
  1579. return
  1580. self.fLadspaRdfNeedsUpdate = False
  1581. self.fLadspaRdfList = []
  1582. if not haveLRDF:
  1583. return
  1584. settingsDir = os.path.join(HOME, ".config", "falkTX")
  1585. frLadspaFile = os.path.join(settingsDir, "ladspa_rdf.db")
  1586. if os.path.exists(frLadspaFile):
  1587. frLadspa = open(frLadspaFile, 'r')
  1588. try:
  1589. self.fLadspaRdfList = ladspa_rdf.get_c_ladspa_rdfs(json.load(frLadspa))
  1590. except:
  1591. pass
  1592. frLadspa.close()
  1593. # --------------------------------------------------------------------------------------------------------
  1594. def getPluginItem(self, pluginId):
  1595. if pluginId >= self.fPluginCount:
  1596. return None
  1597. pitem = self.fPluginList[pluginId]
  1598. if pitem is None:
  1599. return None
  1600. #if False:
  1601. #return CarlaRackItem(self, 0, False)
  1602. return pitem
  1603. def getPluginEditDialog(self, pluginId):
  1604. if pluginId >= self.fPluginCount:
  1605. return None
  1606. pitem = self.fPluginList[pluginId]
  1607. if pitem is None:
  1608. return None
  1609. if False:
  1610. return PluginEdit(self, self.host, 0)
  1611. return pitem.getEditDialog()
  1612. def getPluginSlotWidget(self, pluginId):
  1613. if pluginId >= self.fPluginCount:
  1614. return None
  1615. pitem = self.fPluginList[pluginId]
  1616. if pitem is None:
  1617. return None
  1618. #if False:
  1619. #return AbstractPluginSlot()
  1620. return pitem.getWidget()
  1621. # --------------------------------------------------------------------------------------------------------
  1622. def waitForPendingEvents(self):
  1623. pass
  1624. # --------------------------------------------------------------------------------------------------------
  1625. # show/hide event
  1626. def showEvent(self, event):
  1627. self.refreshTransport(True)
  1628. QMainWindow.showEvent(self, event)
  1629. # set our gui as parent for all plugins UIs
  1630. if self.host.manageUIs and not (self.host.isControl or self.host.isPlugin):
  1631. if MACOS:
  1632. nsViewPtr = int(self.winId())
  1633. winIdStr = "%x" % gCarla.utils.cocoa_get_window(nsViewPtr)
  1634. else:
  1635. winIdStr = "%x" % int(self.winId())
  1636. self.host.set_engine_option(ENGINE_OPTION_FRONTEND_WIN_ID, 0, winIdStr)
  1637. def hideEvent(self, event):
  1638. # disable parent
  1639. if not (self.host.isControl or self.host.isPlugin):
  1640. self.host.set_engine_option(ENGINE_OPTION_FRONTEND_WIN_ID, 0, "0")
  1641. QMainWindow.hideEvent(self, event)
  1642. # --------------------------------------------------------------------------------------------------------
  1643. # resize event
  1644. def fixCanvasPreviewSize(self):
  1645. self.ui.patchbay.resize(self.ui.rack.size())
  1646. self.slot_miniCanvasCheckSize()
  1647. def resizeEvent(self, event):
  1648. QMainWindow.resizeEvent(self, event)
  1649. if self.ui.tabWidget.currentIndex() != 1:
  1650. size = self.ui.rack.size()
  1651. self.ui.patchbay.resize(size)
  1652. self.slot_miniCanvasCheckSize()
  1653. # --------------------------------------------------------------------------------------------------------
  1654. # timer event
  1655. def idleFast(self):
  1656. self.host.engine_idle()
  1657. self.refreshTransport()
  1658. if self.fPluginCount == 0 or self.fCurrentlyRemovingAllPlugins:
  1659. return
  1660. for pitem in self.fPluginList:
  1661. if pitem is None:
  1662. break
  1663. pitem.getWidget().idleFast()
  1664. for pluginId in self.fSelectedPlugins:
  1665. self.fPeaksCleared = False
  1666. if self.ui.peak_in.isVisible():
  1667. self.ui.peak_in.displayMeter(1, self.host.get_input_peak_value(pluginId, True))
  1668. self.ui.peak_in.displayMeter(2, self.host.get_input_peak_value(pluginId, False))
  1669. if self.ui.peak_out.isVisible():
  1670. self.ui.peak_out.displayMeter(1, self.host.get_output_peak_value(pluginId, True))
  1671. self.ui.peak_out.displayMeter(2, self.host.get_output_peak_value(pluginId, False))
  1672. return
  1673. if self.fPeaksCleared:
  1674. return
  1675. self.fPeaksCleared = True
  1676. self.ui.peak_in.displayMeter(1, 0.0, True)
  1677. self.ui.peak_in.displayMeter(2, 0.0, True)
  1678. self.ui.peak_out.displayMeter(1, 0.0, True)
  1679. self.ui.peak_out.displayMeter(2, 0.0, True)
  1680. def idleSlow(self):
  1681. if self.fPluginCount == 0 or self.fCurrentlyRemovingAllPlugins:
  1682. return
  1683. for pitem in self.fPluginList:
  1684. if pitem is None:
  1685. break
  1686. pitem.getWidget().idleSlow()
  1687. def timerEvent(self, event):
  1688. if event.timerId() == self.fIdleTimerFast:
  1689. self.idleFast()
  1690. elif event.timerId() == self.fIdleTimerSlow:
  1691. self.idleSlow()
  1692. QMainWindow.timerEvent(self, event)
  1693. # --------------------------------------------------------------------------------------------------------
  1694. # paint event
  1695. #def paintEvent(self, event):
  1696. #QMainWindow.paintEvent(self, event)
  1697. #if MACOS or not self.fSavedSettings[CARLA_KEY_CUSTOM_PAINTING]:
  1698. #return
  1699. #painter = QPainter(self)
  1700. #painter.setBrush(QColor(36, 36, 36))
  1701. #painter.setPen(QColor(62, 62, 62))
  1702. #painter.drawRect(1, self.height()/2, self.width()-3, self.height()-self.height()/2-1)
  1703. # --------------------------------------------------------------------------------------------------------
  1704. # close event
  1705. def closeEvent(self, event):
  1706. self.killTimers()
  1707. self.saveSettings()
  1708. if self.host.is_engine_running() and not (self.host.isControl or self.host.isPlugin):
  1709. if not self.slot_engineStop(True):
  1710. self.fCustomStopAction = 1
  1711. event.ignore()
  1712. return
  1713. QMainWindow.closeEvent(self, event)
  1714. # ------------------------------------------------------------------------------------------------
  1715. # Canvas callback
  1716. def canvasCallback(action, value1, value2, valueStr):
  1717. host = gCarla.gui.host
  1718. if action == patchcanvas.ACTION_GROUP_INFO:
  1719. pass
  1720. elif action == patchcanvas.ACTION_GROUP_RENAME:
  1721. pass
  1722. elif action == patchcanvas.ACTION_GROUP_SPLIT:
  1723. groupId = value1
  1724. patchcanvas.splitGroup(groupId)
  1725. gCarla.gui.updateMiniCanvasLater()
  1726. elif action == patchcanvas.ACTION_GROUP_JOIN:
  1727. groupId = value1
  1728. patchcanvas.joinGroup(groupId)
  1729. gCarla.gui.updateMiniCanvasLater()
  1730. elif action == patchcanvas.ACTION_PORT_INFO:
  1731. pass
  1732. elif action == patchcanvas.ACTION_PORT_RENAME:
  1733. pass
  1734. elif action == patchcanvas.ACTION_PORTS_CONNECT:
  1735. gOut, pOut, gIn, pIn = [int(i) for i in valueStr.split(":")]
  1736. if not host.patchbay_connect(gOut, pOut, gIn, pIn):
  1737. print("Connection failed:", host.get_last_error())
  1738. elif action == patchcanvas.ACTION_PORTS_DISCONNECT:
  1739. connectionId = value1
  1740. if not host.patchbay_disconnect(connectionId):
  1741. print("Disconnect failed:", host.get_last_error())
  1742. elif action == patchcanvas.ACTION_PLUGIN_CLONE:
  1743. pluginId = value1
  1744. if not host.clone_plugin(pluginId):
  1745. CustomMessageBox(gCarla.gui, QMessageBox.Warning, gCarla.gui.tr("Error"), gCarla.gui.tr("Operation failed"),
  1746. host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1747. elif action == patchcanvas.ACTION_PLUGIN_EDIT:
  1748. pluginId = value1
  1749. pwidget = gCarla.gui.getPluginSlotWidget(pluginId)
  1750. if pwidget is not None:
  1751. pwidget.showEditDialog()
  1752. elif action == patchcanvas.ACTION_PLUGIN_RENAME:
  1753. pluginId = value1
  1754. pwidget = gCarla.gui.getPluginSlotWidget(pluginId)
  1755. if pwidget is not None:
  1756. pwidget.showRenameDialog()
  1757. elif action == patchcanvas.ACTION_PLUGIN_REPLACE:
  1758. pluginId = value1
  1759. pwidget = gCarla.gui.getPluginSlotWidget(pluginId)
  1760. if pwidget is not None:
  1761. pwidget.showReplaceDialog()
  1762. elif action == patchcanvas.ACTION_PLUGIN_REMOVE:
  1763. pluginId = value1
  1764. if not host.remove_plugin(pluginId):
  1765. CustomMessageBox(gCarla.gui, QMessageBox.Warning, gCarla.gui.tr("Error"), gCarla.gui.tr("Operation failed"),
  1766. host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1767. elif action == patchcanvas.ACTION_PLUGIN_SHOW_UI:
  1768. pluginId = value1
  1769. pwidget = gCarla.gui.getPluginSlotWidget(pluginId)
  1770. if pwidget is not None:
  1771. pwidget.showCustomUI()
  1772. elif action == patchcanvas.ACTION_BG_RIGHT_CLICK:
  1773. gCarla.gui.showPluginActionsMenu()
  1774. # ------------------------------------------------------------------------------------------------------------
  1775. # Engine callback
  1776. def engineCallback(host, action, pluginId, value1, value2, value3, valueStr):
  1777. # kdevelop likes this :)
  1778. if False: host = CarlaHostNull()
  1779. if action == ENGINE_CALLBACK_ENGINE_STARTED:
  1780. host.processMode = value1
  1781. host.transportMode = value2
  1782. elif action == ENGINE_CALLBACK_PROCESS_MODE_CHANGED:
  1783. host.processMode = value1
  1784. elif action == ENGINE_CALLBACK_TRANSPORT_MODE_CHANGED:
  1785. host.transportMode = value1
  1786. valueStr = charPtrToString(valueStr)
  1787. if action == ENGINE_CALLBACK_DEBUG:
  1788. host.DebugCallback.emit(pluginId, value1, value2, value3, valueStr)
  1789. elif action == ENGINE_CALLBACK_PLUGIN_ADDED:
  1790. host.PluginAddedCallback.emit(pluginId, valueStr)
  1791. elif action == ENGINE_CALLBACK_PLUGIN_REMOVED:
  1792. host.PluginRemovedCallback.emit(pluginId)
  1793. elif action == ENGINE_CALLBACK_PLUGIN_RENAMED:
  1794. host.PluginRenamedCallback.emit(pluginId, valueStr)
  1795. elif action == ENGINE_CALLBACK_PLUGIN_UNAVAILABLE:
  1796. host.PluginUnavailableCallback.emit(pluginId, valueStr)
  1797. elif action == ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED:
  1798. host.ParameterValueChangedCallback.emit(pluginId, value1, value3)
  1799. elif action == ENGINE_CALLBACK_PARAMETER_DEFAULT_CHANGED:
  1800. host.ParameterDefaultChangedCallback.emit(pluginId, value1, value3)
  1801. elif action == ENGINE_CALLBACK_PARAMETER_MIDI_CC_CHANGED:
  1802. host.ParameterMidiCcChangedCallback.emit(pluginId, value1, value2)
  1803. elif action == ENGINE_CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED:
  1804. host.ParameterMidiChannelChangedCallback.emit(pluginId, value1, value2)
  1805. elif action == ENGINE_CALLBACK_PROGRAM_CHANGED:
  1806. host.ProgramChangedCallback.emit(pluginId, value1)
  1807. elif action == ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED:
  1808. host.MidiProgramChangedCallback.emit(pluginId, value1)
  1809. elif action == ENGINE_CALLBACK_OPTION_CHANGED:
  1810. host.OptionChangedCallback.emit(pluginId, value1, bool(value2))
  1811. elif action == ENGINE_CALLBACK_UI_STATE_CHANGED:
  1812. host.UiStateChangedCallback.emit(pluginId, value1)
  1813. elif action == ENGINE_CALLBACK_NOTE_ON:
  1814. host.NoteOnCallback.emit(pluginId, value1, value2, round(value3))
  1815. elif action == ENGINE_CALLBACK_NOTE_OFF:
  1816. host.NoteOffCallback.emit(pluginId, value1, value2)
  1817. elif action == ENGINE_CALLBACK_UPDATE:
  1818. host.UpdateCallback.emit(pluginId)
  1819. elif action == ENGINE_CALLBACK_RELOAD_INFO:
  1820. host.ReloadInfoCallback.emit(pluginId)
  1821. elif action == ENGINE_CALLBACK_RELOAD_PARAMETERS:
  1822. host.ReloadParametersCallback.emit(pluginId)
  1823. elif action == ENGINE_CALLBACK_RELOAD_PROGRAMS:
  1824. host.ReloadProgramsCallback.emit(pluginId)
  1825. elif action == ENGINE_CALLBACK_RELOAD_ALL:
  1826. host.ReloadAllCallback.emit(pluginId)
  1827. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED:
  1828. host.PatchbayClientAddedCallback.emit(pluginId, value1, value2, valueStr)
  1829. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_REMOVED:
  1830. host.PatchbayClientRemovedCallback.emit(pluginId)
  1831. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_RENAMED:
  1832. host.PatchbayClientRenamedCallback.emit(pluginId, valueStr)
  1833. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_DATA_CHANGED:
  1834. host.PatchbayClientDataChangedCallback.emit(pluginId, value1, value2)
  1835. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_ADDED:
  1836. host.PatchbayPortAddedCallback.emit(pluginId, value1, value2, valueStr)
  1837. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_REMOVED:
  1838. host.PatchbayPortRemovedCallback.emit(pluginId, value1)
  1839. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_RENAMED:
  1840. host.PatchbayPortRenamedCallback.emit(pluginId, value1, valueStr)
  1841. elif action == ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED:
  1842. gOut, pOut, gIn, pIn = [int(i) for i in valueStr.split(":")] # FIXME
  1843. host.PatchbayConnectionAddedCallback.emit(pluginId, gOut, pOut, gIn, pIn)
  1844. elif action == ENGINE_CALLBACK_PATCHBAY_CONNECTION_REMOVED:
  1845. host.PatchbayConnectionRemovedCallback.emit(pluginId, value1, value2)
  1846. elif action == ENGINE_CALLBACK_ENGINE_STARTED:
  1847. host.EngineStartedCallback.emit(value1, value2, valueStr)
  1848. elif action == ENGINE_CALLBACK_ENGINE_STOPPED:
  1849. host.EngineStoppedCallback.emit()
  1850. elif action == ENGINE_CALLBACK_PROCESS_MODE_CHANGED:
  1851. host.ProcessModeChangedCallback.emit(value1)
  1852. elif action == ENGINE_CALLBACK_TRANSPORT_MODE_CHANGED:
  1853. host.TransportModeChangedCallback.emit(value1)
  1854. elif action == ENGINE_CALLBACK_BUFFER_SIZE_CHANGED:
  1855. host.BufferSizeChangedCallback.emit(value1)
  1856. elif action == ENGINE_CALLBACK_SAMPLE_RATE_CHANGED:
  1857. host.SampleRateChangedCallback.emit(value3)
  1858. elif action == ENGINE_CALLBACK_PROJECT_LOAD_FINISHED:
  1859. host.ProjectLoadFinishedCallback.emit()
  1860. elif action == ENGINE_CALLBACK_NSM:
  1861. host.NSMCallback.emit(value1, value2, valueStr)
  1862. elif action == ENGINE_CALLBACK_IDLE:
  1863. QApplication.instance().processEvents()
  1864. elif action == ENGINE_CALLBACK_INFO:
  1865. host.InfoCallback.emit(valueStr)
  1866. elif action == ENGINE_CALLBACK_ERROR:
  1867. host.ErrorCallback.emit(valueStr)
  1868. elif action == ENGINE_CALLBACK_QUIT:
  1869. host.QuitCallback.emit()
  1870. # ------------------------------------------------------------------------------------------------------------
  1871. # File callback
  1872. def fileCallback(ptr, action, isDir, title, filter):
  1873. ret = ("", "") if config_UseQt5 else ""
  1874. if action == FILE_CALLBACK_DEBUG:
  1875. pass
  1876. elif action == FILE_CALLBACK_OPEN:
  1877. ret = QFileDialog.getOpenFileName(gCarla.gui, charPtrToString(title), "", charPtrToString(filter) ) #, QFileDialog.ShowDirsOnly if isDir else 0x0)
  1878. elif action == FILE_CALLBACK_SAVE:
  1879. ret = QFileDialog.getSaveFileName(gCarla.gui, charPtrToString(title), "", charPtrToString(filter), QFileDialog.ShowDirsOnly if isDir else 0x0)
  1880. if config_UseQt5:
  1881. ret = ret[0]
  1882. if not ret:
  1883. return None
  1884. # FIXME
  1885. global fileRet
  1886. fileRet = c_char_p(ret.encode("utf-8"))
  1887. retval = cast(byref(fileRet), POINTER(c_uintptr))
  1888. return retval.contents.value
  1889. # ------------------------------------------------------------------------------------------------------------
  1890. # Init host
  1891. def initHost(initName, libPrefix, isControl, isPlugin, failError, HostClass = None):
  1892. pathBinaries, pathResources = getPaths(libPrefix)
  1893. # --------------------------------------------------------------------------------------------------------
  1894. # Check if we should open main lib as local or global
  1895. settings = QSettings("falkTX", "Carla2")
  1896. try:
  1897. loadGlobal = settings.value(CARLA_KEY_EXPERIMENTAL_LOAD_LIB_GLOBAL, CARLA_DEFAULT_EXPERIMENTAL_LOAD_LIB_GLOBAL, type=bool)
  1898. except:
  1899. loadGlobal = CARLA_DEFAULT_EXPERIMENTAL_LOAD_LIB_GLOBAL
  1900. # --------------------------------------------------------------------------------------------------------
  1901. # Fail if binary dir is not found
  1902. if not os.path.exists(pathBinaries):
  1903. if failError:
  1904. QMessageBox.critical(None, "Error", "Failed to find the carla binaries, cannot continue")
  1905. sys.exit(1)
  1906. return
  1907. # --------------------------------------------------------------------------------------------------------
  1908. # Set Carla library name
  1909. libname = "libcarla_%s2.%s" % ("control" if isControl else "standalone", DLL_EXTENSION)
  1910. libname = os.path.join(pathBinaries, libname)
  1911. utilsname = os.path.join(pathBinaries, "libcarla_utils.%s" % (DLL_EXTENSION))
  1912. # --------------------------------------------------------------------------------------------------------
  1913. # Print info
  1914. print("Carla %s started, status:" % VERSION)
  1915. print(" Python version: %s" % sys.version.split(" ",1)[0])
  1916. print(" Qt version: %s" % qVersion())
  1917. print(" PyQt version: %s" % PYQT_VERSION_STR)
  1918. print(" Binary dir: %s" % pathBinaries)
  1919. print(" Resources dir: %s" % pathResources)
  1920. # --------------------------------------------------------------------------------------------------------
  1921. # Init host
  1922. if failError:
  1923. # no try
  1924. host = HostClass() if HostClass is not None else CarlaHostQtDLL(libname, loadGlobal)
  1925. else:
  1926. try:
  1927. host = HostClass() if HostClass is not None else CarlaHostQtDLL(libname, loadGlobal)
  1928. except:
  1929. host = CarlaHostQtNull()
  1930. host.isControl = isControl
  1931. host.isPlugin = isPlugin
  1932. host.set_engine_callback(lambda h,a,p,v1,v2,v3,vs: engineCallback(host,a,p,v1,v2,v3,vs))
  1933. host.set_file_callback(fileCallback)
  1934. # If it's a plugin the paths are already set
  1935. if not isPlugin:
  1936. host.pathBinaries = pathBinaries
  1937. host.pathResources = pathResources
  1938. host.set_engine_option(ENGINE_OPTION_PATH_BINARIES, 0, pathBinaries)
  1939. host.set_engine_option(ENGINE_OPTION_PATH_RESOURCES, 0, pathResources)
  1940. if not isControl:
  1941. host.nsmOK = host.nsm_init(os.getpid(), initName)
  1942. # --------------------------------------------------------------------------------------------------------
  1943. # Init utils
  1944. gCarla.utils = CarlaUtils(utilsname)
  1945. gCarla.utils.set_process_name(os.path.basename(initName))
  1946. try:
  1947. sys.stdout.flush()
  1948. except:
  1949. pass
  1950. sys.stdout = CarlaPrint(False)
  1951. sys.stderr = CarlaPrint(True)
  1952. if config_UseQt5:
  1953. sys.excepthook = sys_excepthook
  1954. # --------------------------------------------------------------------------------------------------------
  1955. # Done
  1956. return host
  1957. # ------------------------------------------------------------------------------------------------------------
  1958. # Load host settings
  1959. def loadHostSettings(host):
  1960. # kdevelop likes this :)
  1961. if False: host = CarlaHostNull()
  1962. settings = QSettings("falkTX", "Carla2")
  1963. try:
  1964. host.experimental = settings.value(CARLA_KEY_MAIN_EXPERIMENTAL, CARLA_DEFAULT_MAIN_EXPERIMENTAL, type=bool)
  1965. except:
  1966. host.experimental = CARLA_DEFAULT_MAIN_EXPERIMENTAL
  1967. try:
  1968. host.exportLV2 = settings.value(CARLA_KEY_EXPERIMENTAL_EXPORT_LV2, CARLA_DEFAULT_EXPERIMENTAL_LV2_EXPORT, type=bool)
  1969. except:
  1970. host.exportLV2 = CARLA_DEFAULT_EXPERIMENTAL_LV2_EXPORT
  1971. try:
  1972. host.manageUIs = settings.value(CARLA_KEY_ENGINE_MANAGE_UIS, CARLA_DEFAULT_MANAGE_UIS, type=bool)
  1973. except:
  1974. host.manageUIs = CARLA_DEFAULT_MANAGE_UIS
  1975. try:
  1976. host.maxParameters = settings.value(CARLA_KEY_ENGINE_MAX_PARAMETERS, CARLA_DEFAULT_MAX_PARAMETERS, type=int)
  1977. except:
  1978. host.maxParameters = CARLA_DEFAULT_MAX_PARAMETERS
  1979. try:
  1980. host.forceStereo = settings.value(CARLA_KEY_ENGINE_FORCE_STEREO, CARLA_DEFAULT_FORCE_STEREO, type=bool)
  1981. except:
  1982. host.forceStereo = CARLA_DEFAULT_FORCE_STEREO
  1983. try:
  1984. host.preferPluginBridges = settings.value(CARLA_KEY_ENGINE_PREFER_PLUGIN_BRIDGES, CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES, type=bool)
  1985. except:
  1986. host.preferPluginBridges = CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES
  1987. try:
  1988. host.preferUIBridges = settings.value(CARLA_KEY_ENGINE_PREFER_UI_BRIDGES, CARLA_DEFAULT_PREFER_UI_BRIDGES, type=bool)
  1989. except:
  1990. host.preferUIBridges = CARLA_DEFAULT_PREFER_UI_BRIDGES
  1991. try:
  1992. host.preventBadBehaviour = settings.value(CARLA_KEY_EXPERIMENTAL_PREVENT_BAD_BEHAVIOUR, CARLA_DEFAULT_EXPERIMENTAL_PREVENT_BAD_BEHAVIOUR, type=bool)
  1993. except:
  1994. host.preventBadBehaviour = CARLA_DEFAULT_EXPERIMENTAL_PREVENT_BAD_BEHAVIOUR
  1995. try:
  1996. host.showLogs = settings.value(CARLA_KEY_MAIN_SHOW_LOGS, CARLA_DEFAULT_MAIN_SHOW_LOGS, type=bool)
  1997. except:
  1998. host.showLogs = CARLA_DEFAULT_MAIN_SHOW_LOGS
  1999. try:
  2000. host.showPluginBridges = settings.value(CARLA_KEY_EXPERIMENTAL_PLUGIN_BRIDGES, CARLA_DEFAULT_EXPERIMENTAL_PLUGIN_BRIDGES, type=bool)
  2001. except:
  2002. host.showPluginBridges = CARLA_DEFAULT_EXPERIMENTAL_PLUGIN_BRIDGES
  2003. try:
  2004. host.showWineBridges = settings.value(CARLA_KEY_EXPERIMENTAL_WINE_BRIDGES, CARLA_DEFAULT_EXPERIMENTAL_WINE_BRIDGES, type=bool)
  2005. except:
  2006. host.showWineBridges = CARLA_DEFAULT_EXPERIMENTAL_WINE_BRIDGES
  2007. try:
  2008. host.uiBridgesTimeout = settings.value(CARLA_KEY_ENGINE_UI_BRIDGES_TIMEOUT, CARLA_DEFAULT_UI_BRIDGES_TIMEOUT, type=int)
  2009. except:
  2010. host.uiBridgesTimeout = CARLA_DEFAULT_UI_BRIDGES_TIMEOUT
  2011. try:
  2012. host.uisAlwaysOnTop = settings.value(CARLA_KEY_ENGINE_UIS_ALWAYS_ON_TOP, CARLA_DEFAULT_UIS_ALWAYS_ON_TOP, type=bool)
  2013. except:
  2014. host.uisAlwaysOnTop = CARLA_DEFAULT_UIS_ALWAYS_ON_TOP
  2015. if host.isPlugin:
  2016. return
  2017. # enums
  2018. if host.audioDriverForced is None:
  2019. try:
  2020. host.transportMode = settings.value(CARLA_KEY_ENGINE_TRANSPORT_MODE, CARLA_DEFAULT_TRANSPORT_MODE, type=int)
  2021. except:
  2022. host.transportMode = CARLA_DEFAULT_TRANSPORT_MODE
  2023. if not host.processModeForced:
  2024. try:
  2025. host.processMode = settings.value(CARLA_KEY_ENGINE_PROCESS_MODE, CARLA_DEFAULT_PROCESS_MODE, type=int)
  2026. except:
  2027. host.processMode = CARLA_DEFAULT_PROCESS_MODE
  2028. host.nextProcessMode = host.processMode
  2029. # --------------------------------------------------------------------------------------------------------
  2030. # fix things if needed
  2031. if host.processMode == ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS and LADISH_APP_NAME:
  2032. print("LADISH detected but using multiple clients (not allowed), forcing single client now")
  2033. host.nextProcessMode = host.processMode = ENGINE_PROCESS_MODE_SINGLE_CLIENT
  2034. # --------------------------------------------------------------------------------------------------------
  2035. # run headless host now if nogui option enabled
  2036. if gCarla.nogui:
  2037. runHostWithoutUI(host)
  2038. # ------------------------------------------------------------------------------------------------------------
  2039. # Set host settings
  2040. def setHostSettings(host):
  2041. # kdevelop likes this :)
  2042. if False: host = CarlaHostNull()
  2043. host.set_engine_option(ENGINE_OPTION_FORCE_STEREO, host.forceStereo, "")
  2044. host.set_engine_option(ENGINE_OPTION_MAX_PARAMETERS, host.maxParameters, "")
  2045. host.set_engine_option(ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, host.preferPluginBridges, "")
  2046. host.set_engine_option(ENGINE_OPTION_PREFER_UI_BRIDGES, host.preferUIBridges, "")
  2047. host.set_engine_option(ENGINE_OPTION_PREVENT_BAD_BEHAVIOUR, host.preventBadBehaviour, "")
  2048. host.set_engine_option(ENGINE_OPTION_DEBUG_CONSOLE_OUTPUT, host.showLogs, "")
  2049. host.set_engine_option(ENGINE_OPTION_UI_BRIDGES_TIMEOUT, host.uiBridgesTimeout, "")
  2050. host.set_engine_option(ENGINE_OPTION_UIS_ALWAYS_ON_TOP, host.uisAlwaysOnTop, "")
  2051. if host.isPlugin:
  2052. return
  2053. host.set_engine_option(ENGINE_OPTION_PROCESS_MODE, host.nextProcessMode, "")
  2054. host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE, host.transportMode, "")
  2055. # ------------------------------------------------------------------------------------------------------------
  2056. # Set Engine settings according to carla preferences. Returns selected audio driver.
  2057. def setEngineSettings(host):
  2058. # kdevelop likes this :)
  2059. if False: host = CarlaHostNull()
  2060. # --------------------------------------------------------------------------------------------------------
  2061. # do nothing if control
  2062. if host.isControl:
  2063. return "Control"
  2064. # --------------------------------------------------------------------------------------------------------
  2065. settings = QSettings("falkTX", "Carla2")
  2066. # --------------------------------------------------------------------------------------------------------
  2067. # main settings
  2068. setHostSettings(host)
  2069. # --------------------------------------------------------------------------------------------------------
  2070. # plugin paths
  2071. LADSPA_PATH = toList(settings.value(CARLA_KEY_PATHS_LADSPA, CARLA_DEFAULT_LADSPA_PATH))
  2072. DSSI_PATH = toList(settings.value(CARLA_KEY_PATHS_DSSI, CARLA_DEFAULT_DSSI_PATH))
  2073. LV2_PATH = toList(settings.value(CARLA_KEY_PATHS_LV2, CARLA_DEFAULT_LV2_PATH))
  2074. VST2_PATH = toList(settings.value(CARLA_KEY_PATHS_VST2, CARLA_DEFAULT_VST2_PATH))
  2075. GIG_PATH = toList(settings.value(CARLA_KEY_PATHS_GIG, CARLA_DEFAULT_GIG_PATH))
  2076. SF2_PATH = toList(settings.value(CARLA_KEY_PATHS_SF2, CARLA_DEFAULT_SF2_PATH))
  2077. SFZ_PATH = toList(settings.value(CARLA_KEY_PATHS_SFZ, CARLA_DEFAULT_SFZ_PATH))
  2078. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_LADSPA, splitter.join(LADSPA_PATH))
  2079. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_DSSI, splitter.join(DSSI_PATH))
  2080. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_LV2, splitter.join(LV2_PATH))
  2081. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_VST2, splitter.join(VST2_PATH))
  2082. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_GIG, splitter.join(GIG_PATH))
  2083. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_SF2, splitter.join(SF2_PATH))
  2084. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_SFZ, splitter.join(SFZ_PATH))
  2085. # --------------------------------------------------------------------------------------------------------
  2086. # don't continue if plugin
  2087. if host.isPlugin:
  2088. return "Plugin"
  2089. # --------------------------------------------------------------------------------------------------------
  2090. # driver and device settings
  2091. # driver name
  2092. if host.audioDriverForced is not None:
  2093. audioDriver = host.audioDriverForced
  2094. else:
  2095. try:
  2096. audioDriver = settings.value(CARLA_KEY_ENGINE_AUDIO_DRIVER, CARLA_DEFAULT_AUDIO_DRIVER, type=str)
  2097. except:
  2098. audioDriver = CARLA_DEFAULT_AUDIO_DRIVER
  2099. # driver options
  2100. try:
  2101. audioDevice = settings.value("%s%s/Device" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), "", type=str)
  2102. except:
  2103. audioDevice = ""
  2104. try:
  2105. audioNumPeriods = settings.value("%s%s/NumPeriods" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_NUM_PERIODS, type=int)
  2106. except:
  2107. audioNumPeriods = CARLA_DEFAULT_AUDIO_NUM_PERIODS
  2108. try:
  2109. audioBufferSize = settings.value("%s%s/BufferSize" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_BUFFER_SIZE, type=int)
  2110. except:
  2111. audioBufferSize = CARLA_DEFAULT_AUDIO_BUFFER_SIZE
  2112. try:
  2113. audioSampleRate = settings.value("%s%s/SampleRate" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_SAMPLE_RATE, type=int)
  2114. except:
  2115. audioSampleRate = CARLA_DEFAULT_AUDIO_SAMPLE_RATE
  2116. host.set_engine_option(ENGINE_OPTION_AUDIO_DEVICE, 0, audioDevice)
  2117. host.set_engine_option(ENGINE_OPTION_AUDIO_NUM_PERIODS, audioNumPeriods, "")
  2118. host.set_engine_option(ENGINE_OPTION_AUDIO_BUFFER_SIZE, audioBufferSize, "")
  2119. host.set_engine_option(ENGINE_OPTION_AUDIO_SAMPLE_RATE, audioSampleRate, "")
  2120. # --------------------------------------------------------------------------------------------------------
  2121. # fix things if needed
  2122. if audioDriver != "JACK" and host.transportMode == ENGINE_TRANSPORT_MODE_JACK:
  2123. host.transportMode = ENGINE_TRANSPORT_MODE_INTERNAL
  2124. host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE, ENGINE_TRANSPORT_MODE_INTERNAL, "")
  2125. # --------------------------------------------------------------------------------------------------------
  2126. # wine settings
  2127. optWineExecutable = settings.value(CARLA_KEY_WINE_EXECUTABLE, CARLA_DEFAULT_WINE_EXECUTABLE, type=str)
  2128. optWineAutoPrefix = settings.value(CARLA_KEY_WINE_AUTO_PREFIX, CARLA_DEFAULT_WINE_AUTO_PREFIX, type=bool)
  2129. optWineFallbackPrefix = settings.value(CARLA_KEY_WINE_FALLBACK_PREFIX, CARLA_DEFAULT_WINE_FALLBACK_PREFIX, type=str)
  2130. optWineRtPrioEnabled = settings.value(CARLA_KEY_WINE_RT_PRIO_ENABLED, CARLA_DEFAULT_WINE_RT_PRIO_ENABLED, type=bool)
  2131. optWineBaseRtPrio = settings.value(CARLA_KEY_WINE_BASE_RT_PRIO, CARLA_DEFAULT_WINE_BASE_RT_PRIO, type=int)
  2132. optWineServerRtPrio = settings.value(CARLA_KEY_WINE_SERVER_RT_PRIO, CARLA_DEFAULT_WINE_SERVER_RT_PRIO, type=int)
  2133. host.set_engine_option(ENGINE_OPTION_WINE_EXECUTABLE, 0, optWineExecutable)
  2134. host.set_engine_option(ENGINE_OPTION_WINE_AUTO_PREFIX, 1 if optWineAutoPrefix else 0, "")
  2135. host.set_engine_option(ENGINE_OPTION_WINE_FALLBACK_PREFIX, 0, os.path.expanduser(optWineFallbackPrefix))
  2136. host.set_engine_option(ENGINE_OPTION_WINE_RT_PRIO_ENABLED, 1 if optWineRtPrioEnabled else 0, "")
  2137. host.set_engine_option(ENGINE_OPTION_WINE_BASE_RT_PRIO, optWineBaseRtPrio, "")
  2138. host.set_engine_option(ENGINE_OPTION_WINE_SERVER_RT_PRIO, optWineServerRtPrio, "")
  2139. # --------------------------------------------------------------------------------------------------------
  2140. # return selected driver name
  2141. return audioDriver
  2142. # ------------------------------------------------------------------------------------------------------------
  2143. # Run Carla without showing UI
  2144. def runHostWithoutUI(host):
  2145. # kdevelop likes this :)
  2146. if False: host = CarlaHostNull()
  2147. # --------------------------------------------------------------------------------------------------------
  2148. # Some initial checks
  2149. if not gCarla.nogui:
  2150. return
  2151. projectFile = getInitialProjectFile(QCoreApplication.instance(), True)
  2152. if not projectFile:
  2153. print("Carla no-gui mode can only be used together with a project file.")
  2154. sys.exit(1)
  2155. # --------------------------------------------------------------------------------------------------------
  2156. # Additional imports
  2157. from time import sleep
  2158. # --------------------------------------------------------------------------------------------------------
  2159. # Init engine
  2160. audioDriver = setEngineSettings(host)
  2161. if not host.engine_init(audioDriver, "Carla"):
  2162. print("Engine failed to initialize, possible reasons:\n%s" % host.get_last_error())
  2163. sys.exit(1)
  2164. if not host.load_project(projectFile):
  2165. print("Failed to load selected project file, possible reasons:\n%s" % host.get_last_error())
  2166. host.engine_close()
  2167. sys.exit(1)
  2168. # --------------------------------------------------------------------------------------------------------
  2169. # Idle
  2170. while host.is_engine_running() and not gCarla.term:
  2171. host.engine_idle()
  2172. sleep(0.5)
  2173. # --------------------------------------------------------------------------------------------------------
  2174. # Stop
  2175. host.engine_close()
  2176. sys.exit(0)
  2177. # ------------------------------------------------------------------------------------------------------------