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

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