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

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