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