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

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