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

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