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

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
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
Rack enhancements 2 (#770) Squashed commit of the following: commit 0449cd63f7c356684903f784be434191df9c4392 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Fri Oct 5 02:19:23 2018 +0500 carla skin: fancy item selection commit 84a7b527a7eb79de1da215d6350ba5c639a46477 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Fri Oct 5 02:10:49 2018 +0500 carla skin: drawOutline: fixed positioning and optimization commit 30681d1523d088a728ba702c3af42ef97da2ddd2 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Fri Oct 5 01:20:53 2018 +0500 carla skin: drawOutline: set brush only once commit 63d2ab2e2189efdfa1c5e57b1519706184aa14bc Author: Nikita Zlobin <nick87720z@gmail.com> Date: Thu Oct 4 00:10:39 2018 +0500 carla skin: more neat QColor to tuple conversion commit 2137b781093177891d43bcf84cbcca9f7a398ba6 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Wed Oct 3 16:35:48 2018 +0500 rack item: Skin-independent colorization support Color menu item tints background color, preserving all visible relief. No need to lock it for some skins. commit 13fa4f2c34f789c43fa54c6657bb3dd018fcac80 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Wed Oct 10 15:00:58 2018 +0500 rack list: Colorized padding commit 9964af199453ce45ae8a8c10828a79d11870e011 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Fri Sep 28 17:48:17 2018 +0500 rack list: Colorized rails commit d212577057c5a914f52fd38a9d35645517e09d46 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Wed Oct 10 14:12:36 2018 +0500 rack list: Set frame in ui form commit 9a7e06098899ea5ac7e510b4374e3f88aeae8282 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Fri Sep 28 18:44:49 2018 +0500 rack list: Set common frame
6 years ago
10 years ago
10 years ago
11 years ago
11 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
10 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
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
Minimap enhancements (#768) * minimap: Update on any selection change For now minimap is already updated when box (not port) is selected. Also it will update if port is selected by Ctrl+C while box is already selected. This commit just makes this behavior more stable and predictable, * minimap: Align frame bottom with canvas frame * minimap: Fixed & unified cursor pos expressions Another approach, yet working in both places without rewriting. Don't add xp or yp, as it displaces right/bottom limit by 1px * minimap: Better custom frame New implementation has outer 1px shadow above parent background and internal enlight border above background. All is pixel-aligned. * minimap: Fix cursor position on lowest scale When scale is close to 0.2, view area may become bigger than working area. After such "fix" viewRect position is broken. * minimap: Brightness-aware shading on side gaps * mininap: Set viewRect lineHinting from proper pen * minimap: Cliped rendering for rounded corners * minimap: Frame width awareness Draw content only inside frame when external qt theme is used. * minimap: Implement full resize with any ratio * minimap: Better cursor positioning * minimap: Minimal corner rounding Make rounding to look good with rounded frames, still not ugly with square themes. * minimap: Reworked frame Mimic tab frame by placing existing frame as line child to QTabWidget. Frame derivation still handy to create inner sunken frame, just like in two other frames around. * minimap-framewidth: Follow system style change * minimap: Special blending modes for view cursor Adding for dark color schemes and subtracting for light preserve more contrast, compared to default blending. Difference is calculated from background and rubberband colors. * Better buttons look in sidebar fileview * minimap: Hold cursor inside map in view move mode * minimap: Natural move Would be more natural to have centered position in canvas view, when pointed in minimap.
6 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
Minimap enhancements (#768) * minimap: Update on any selection change For now minimap is already updated when box (not port) is selected. Also it will update if port is selected by Ctrl+C while box is already selected. This commit just makes this behavior more stable and predictable, * minimap: Align frame bottom with canvas frame * minimap: Fixed & unified cursor pos expressions Another approach, yet working in both places without rewriting. Don't add xp or yp, as it displaces right/bottom limit by 1px * minimap: Better custom frame New implementation has outer 1px shadow above parent background and internal enlight border above background. All is pixel-aligned. * minimap: Fix cursor position on lowest scale When scale is close to 0.2, view area may become bigger than working area. After such "fix" viewRect position is broken. * minimap: Brightness-aware shading on side gaps * mininap: Set viewRect lineHinting from proper pen * minimap: Cliped rendering for rounded corners * minimap: Frame width awareness Draw content only inside frame when external qt theme is used. * minimap: Implement full resize with any ratio * minimap: Better cursor positioning * minimap: Minimal corner rounding Make rounding to look good with rounded frames, still not ugly with square themes. * minimap: Reworked frame Mimic tab frame by placing existing frame as line child to QTabWidget. Frame derivation still handy to create inner sunken frame, just like in two other frames around. * minimap-framewidth: Follow system style change * minimap: Special blending modes for view cursor Adding for dark color schemes and subtracting for light preserve more contrast, compared to default blending. Difference is calculated from background and rubberband colors. * Better buttons look in sidebar fileview * minimap: Hold cursor inside map in view move mode * minimap: Natural move Would be more natural to have centered position in canvas view, when pointed in minimap.
6 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
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
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
Rack enhancements 2 (#770) Squashed commit of the following: commit 0449cd63f7c356684903f784be434191df9c4392 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Fri Oct 5 02:19:23 2018 +0500 carla skin: fancy item selection commit 84a7b527a7eb79de1da215d6350ba5c639a46477 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Fri Oct 5 02:10:49 2018 +0500 carla skin: drawOutline: fixed positioning and optimization commit 30681d1523d088a728ba702c3af42ef97da2ddd2 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Fri Oct 5 01:20:53 2018 +0500 carla skin: drawOutline: set brush only once commit 63d2ab2e2189efdfa1c5e57b1519706184aa14bc Author: Nikita Zlobin <nick87720z@gmail.com> Date: Thu Oct 4 00:10:39 2018 +0500 carla skin: more neat QColor to tuple conversion commit 2137b781093177891d43bcf84cbcca9f7a398ba6 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Wed Oct 3 16:35:48 2018 +0500 rack item: Skin-independent colorization support Color menu item tints background color, preserving all visible relief. No need to lock it for some skins. commit 13fa4f2c34f789c43fa54c6657bb3dd018fcac80 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Wed Oct 10 15:00:58 2018 +0500 rack list: Colorized padding commit 9964af199453ce45ae8a8c10828a79d11870e011 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Fri Sep 28 17:48:17 2018 +0500 rack list: Colorized rails commit d212577057c5a914f52fd38a9d35645517e09d46 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Wed Oct 10 14:12:36 2018 +0500 rack list: Set frame in ui form commit 9a7e06098899ea5ac7e510b4374e3f88aeae8282 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Fri Sep 28 18:44:49 2018 +0500 rack list: Set common frame
6 years ago
Rack enhancements 2 (#770) Squashed commit of the following: commit 0449cd63f7c356684903f784be434191df9c4392 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Fri Oct 5 02:19:23 2018 +0500 carla skin: fancy item selection commit 84a7b527a7eb79de1da215d6350ba5c639a46477 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Fri Oct 5 02:10:49 2018 +0500 carla skin: drawOutline: fixed positioning and optimization commit 30681d1523d088a728ba702c3af42ef97da2ddd2 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Fri Oct 5 01:20:53 2018 +0500 carla skin: drawOutline: set brush only once commit 63d2ab2e2189efdfa1c5e57b1519706184aa14bc Author: Nikita Zlobin <nick87720z@gmail.com> Date: Thu Oct 4 00:10:39 2018 +0500 carla skin: more neat QColor to tuple conversion commit 2137b781093177891d43bcf84cbcca9f7a398ba6 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Wed Oct 3 16:35:48 2018 +0500 rack item: Skin-independent colorization support Color menu item tints background color, preserving all visible relief. No need to lock it for some skins. commit 13fa4f2c34f789c43fa54c6657bb3dd018fcac80 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Wed Oct 10 15:00:58 2018 +0500 rack list: Colorized padding commit 9964af199453ce45ae8a8c10828a79d11870e011 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Fri Sep 28 17:48:17 2018 +0500 rack list: Colorized rails commit d212577057c5a914f52fd38a9d35645517e09d46 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Wed Oct 10 14:12:36 2018 +0500 rack list: Set frame in ui form commit 9a7e06098899ea5ac7e510b4374e3f88aeae8282 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Fri Sep 28 18:44:49 2018 +0500 rack list: Set common frame
6 years ago
Rack enhancements 2 (#770) Squashed commit of the following: commit 0449cd63f7c356684903f784be434191df9c4392 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Fri Oct 5 02:19:23 2018 +0500 carla skin: fancy item selection commit 84a7b527a7eb79de1da215d6350ba5c639a46477 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Fri Oct 5 02:10:49 2018 +0500 carla skin: drawOutline: fixed positioning and optimization commit 30681d1523d088a728ba702c3af42ef97da2ddd2 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Fri Oct 5 01:20:53 2018 +0500 carla skin: drawOutline: set brush only once commit 63d2ab2e2189efdfa1c5e57b1519706184aa14bc Author: Nikita Zlobin <nick87720z@gmail.com> Date: Thu Oct 4 00:10:39 2018 +0500 carla skin: more neat QColor to tuple conversion commit 2137b781093177891d43bcf84cbcca9f7a398ba6 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Wed Oct 3 16:35:48 2018 +0500 rack item: Skin-independent colorization support Color menu item tints background color, preserving all visible relief. No need to lock it for some skins. commit 13fa4f2c34f789c43fa54c6657bb3dd018fcac80 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Wed Oct 10 15:00:58 2018 +0500 rack list: Colorized padding commit 9964af199453ce45ae8a8c10828a79d11870e011 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Fri Sep 28 17:48:17 2018 +0500 rack list: Colorized rails commit d212577057c5a914f52fd38a9d35645517e09d46 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Wed Oct 10 14:12:36 2018 +0500 rack list: Set frame in ui form commit 9a7e06098899ea5ac7e510b4374e3f88aeae8282 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Fri Sep 28 18:44:49 2018 +0500 rack list: Set common frame
6 years ago
Rack enhancements 2 (#770) Squashed commit of the following: commit 0449cd63f7c356684903f784be434191df9c4392 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Fri Oct 5 02:19:23 2018 +0500 carla skin: fancy item selection commit 84a7b527a7eb79de1da215d6350ba5c639a46477 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Fri Oct 5 02:10:49 2018 +0500 carla skin: drawOutline: fixed positioning and optimization commit 30681d1523d088a728ba702c3af42ef97da2ddd2 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Fri Oct 5 01:20:53 2018 +0500 carla skin: drawOutline: set brush only once commit 63d2ab2e2189efdfa1c5e57b1519706184aa14bc Author: Nikita Zlobin <nick87720z@gmail.com> Date: Thu Oct 4 00:10:39 2018 +0500 carla skin: more neat QColor to tuple conversion commit 2137b781093177891d43bcf84cbcca9f7a398ba6 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Wed Oct 3 16:35:48 2018 +0500 rack item: Skin-independent colorization support Color menu item tints background color, preserving all visible relief. No need to lock it for some skins. commit 13fa4f2c34f789c43fa54c6657bb3dd018fcac80 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Wed Oct 10 15:00:58 2018 +0500 rack list: Colorized padding commit 9964af199453ce45ae8a8c10828a79d11870e011 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Fri Sep 28 17:48:17 2018 +0500 rack list: Colorized rails commit d212577057c5a914f52fd38a9d35645517e09d46 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Wed Oct 10 14:12:36 2018 +0500 rack list: Set frame in ui form commit 9a7e06098899ea5ac7e510b4374e3f88aeae8282 Author: Nikita Zlobin <nick87720z@gmail.com> Date: Fri Sep 28 18:44:49 2018 +0500 rack list: Set common frame
6 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
10 years ago
9 years ago
6 years ago
6 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Carla host code
  4. # Copyright (C) 2011-2021 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 (Global)
  19. import json
  20. # ------------------------------------------------------------------------------------------------------------
  21. # Imports (ctypes)
  22. from ctypes import (
  23. byref, pointer
  24. )
  25. # ------------------------------------------------------------------------------------------------------------
  26. # Imports (PyQt5)
  27. # This fails in some configurations, assume >= 5.6.0 in that case
  28. try:
  29. from PyQt5.Qt import PYQT_VERSION
  30. except ImportError:
  31. PYQT_VERSION = 0x50600
  32. from PyQt5.QtCore import (
  33. QT_VERSION, qCritical, QBuffer, QEventLoop, QFileInfo, QIODevice, QMimeData, QModelIndex, QPointF, QTimer, QEvent
  34. )
  35. from PyQt5.QtGui import (
  36. QImage, QImageWriter, QPainter, QPalette, QBrush
  37. )
  38. from PyQt5.QtWidgets import (
  39. QAction, QApplication, QInputDialog, QFileSystemModel, QListWidgetItem, QGraphicsView, QMainWindow
  40. )
  41. # ------------------------------------------------------------------------------------------------------------
  42. # Imports (Custom)
  43. import ui_carla_host
  44. from carla_app import *
  45. from carla_backend_qt import CarlaHostQtDLL, CarlaHostQtNull
  46. from carla_database import *
  47. from carla_settings import *
  48. from carla_utils import *
  49. from carla_widgets import *
  50. from patchcanvas import patchcanvas
  51. from widgets.digitalpeakmeter import DigitalPeakMeter
  52. from widgets.pixmapkeyboard import PixmapKeyboardHArea
  53. # ------------------------------------------------------------------------------------------------------------
  54. # Try Import OpenGL
  55. try:
  56. from PyQt5.QtOpenGL import QGLWidget
  57. hasGL = True
  58. except:
  59. hasGL = False
  60. # ------------------------------------------------------------------------------------------------------------
  61. # Safe exception hook, needed for PyQt5
  62. def sys_excepthook(typ, value, tback):
  63. return sys.__excepthook__(typ, value, tback)
  64. # ------------------------------------------------------------------------------------------------------------
  65. # Session Management support
  66. CARLA_CLIENT_NAME = os.getenv("CARLA_CLIENT_NAME")
  67. LADISH_APP_NAME = os.getenv("LADISH_APP_NAME")
  68. NSM_URL = os.getenv("NSM_URL")
  69. # ------------------------------------------------------------------------------------------------------------
  70. # Small print helper
  71. def processMode2Str(processMode):
  72. if processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT:
  73. return "Single client"
  74. if processMode == ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS:
  75. return "Multi client"
  76. if processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK:
  77. return "Continuous Rack"
  78. if processMode == ENGINE_PROCESS_MODE_PATCHBAY:
  79. return "Patchbay"
  80. if processMode == ENGINE_PROCESS_MODE_BRIDGE:
  81. return "Bridge"
  82. return "Unknown"
  83. # ------------------------------------------------------------------------------------------------------------
  84. # Carla Print class
  85. class CarlaPrint:
  86. def __init__(self, err):
  87. self.err = err
  88. def flush(self):
  89. gCarla.utils.fflush(self.err)
  90. def write(self, string):
  91. gCarla.utils.fputs(self.err, string)
  92. # ------------------------------------------------------------------------------------------------------------
  93. # Host Window
  94. class HostWindow(QMainWindow):
  95. #class HostWindow(QMainWindow, PluginEditParentMeta, metaclass=PyQtMetaClass):
  96. # signals
  97. SIGTERM = pyqtSignal()
  98. SIGUSR1 = pyqtSignal()
  99. # CustomActions
  100. CUSTOM_ACTION_NONE = 0
  101. CUSTOM_ACTION_APP_CLOSE = 1
  102. CUSTOM_ACTION_PROJECT_LOAD = 2
  103. # --------------------------------------------------------------------------------------------------------
  104. def __init__(self, host, withCanvas, parent=None):
  105. QMainWindow.__init__(self, parent)
  106. self.host = host
  107. self.ui = ui_carla_host.Ui_CarlaHostW()
  108. self.ui.setupUi(self)
  109. gCarla.gui = self
  110. if False:
  111. # kdevelop likes this :)
  112. host = CarlaHostNull()
  113. self.host = host
  114. self._true = c_char_p("true".encode("utf-8"))
  115. self.fParentOrSelf = parent or self
  116. # ----------------------------------------------------------------------------------------------------
  117. # Internal stuff
  118. self.fIdleTimerNull = self.startTimer(1000) # keep application signals alive
  119. self.fIdleTimerFast = 0
  120. self.fIdleTimerSlow = 0
  121. self.fLadspaRdfNeedsUpdate = True
  122. self.fLadspaRdfList = []
  123. self.fPluginCount = 0
  124. self.fPluginList = []
  125. self.fPluginDatabaseDialog = None
  126. self.fFavoritePlugins = []
  127. self.fProjectFilename = ""
  128. self.fIsProjectLoading = False
  129. self.fCurrentlyRemovingAllPlugins = False
  130. self.fLastTransportBPM = 0.0
  131. self.fLastTransportFrame = 0
  132. self.fLastTransportState = False
  133. self.fBufferSize = 0
  134. self.fSampleRate = 0.0
  135. self.fOscAddressTCP = ""
  136. self.fOscAddressUDP = ""
  137. if MACOS:
  138. self.fMacClosingHelper = True
  139. # CancelableActionCallback Box
  140. self.fCancelableActionBox = None
  141. # run a custom action after engine is properly closed
  142. self.fCustomStopAction = self.CUSTOM_ACTION_NONE
  143. # first attempt of auto-start engine doesn't show an error
  144. self.fFirstEngineInit = True
  145. # to be filled with key-value pairs of current settings
  146. self.fSavedSettings = {}
  147. # true if NSM server handles our window management
  148. self.fWindowCloseHideGui = False
  149. if host.isControl:
  150. self.fClientName = "Carla-Control"
  151. self.fSessionManagerName = "Control"
  152. elif host.isPlugin:
  153. self.fClientName = "Carla-Plugin"
  154. self.fSessionManagerName = "Plugin"
  155. elif LADISH_APP_NAME:
  156. self.fClientName = LADISH_APP_NAME
  157. self.fSessionManagerName = "LADISH"
  158. elif NSM_URL and host.nsmOK:
  159. self.fClientName = "Carla.tmp"
  160. self.fSessionManagerName = "Non Session Manager TMP"
  161. self.fWindowCloseHideGui = True
  162. else:
  163. self.fClientName = CARLA_CLIENT_NAME or "Carla"
  164. self.fSessionManagerName = ""
  165. # ----------------------------------------------------------------------------------------------------
  166. # Internal stuff (patchbay)
  167. self.fPeaksCleared = True
  168. self.fExternalPatchbay = False
  169. self.fSelectedPlugins = []
  170. self.fCanvasWidth = 0
  171. self.fCanvasHeight = 0
  172. self.fMiniCanvasUpdateTimeout = 0
  173. self.fWithCanvas = withCanvas
  174. # ----------------------------------------------------------------------------------------------------
  175. # Internal stuff (logs)
  176. self.autoscrollOnNewLog = True
  177. self.lastLogSliderPos = 0
  178. # ----------------------------------------------------------------------------------------------------
  179. # Set up GUI (engine stopped)
  180. if self.host.isPlugin or self.host.isControl:
  181. self.ui.act_file_save.setVisible(False)
  182. self.ui.act_engine_start.setEnabled(False)
  183. self.ui.act_engine_start.setVisible(False)
  184. self.ui.act_engine_stop.setEnabled(False)
  185. self.ui.act_engine_stop.setVisible(False)
  186. self.ui.menu_Engine.setEnabled(False)
  187. self.ui.menu_Engine.setVisible(False)
  188. self.ui.menu_Engine.menuAction().setVisible(False)
  189. self.ui.tabWidget.removeTab(2)
  190. if self.host.isControl:
  191. self.ui.act_file_new.setVisible(False)
  192. self.ui.act_file_open.setVisible(False)
  193. self.ui.act_file_save_as.setVisible(False)
  194. self.ui.tabUtils.removeTab(0)
  195. else:
  196. self.ui.act_file_save_as.setText(self.tr("Export as..."))
  197. if not withCanvas:
  198. self.ui.tabWidget.tabBar().hide()
  199. else:
  200. self.ui.act_engine_start.setEnabled(True)
  201. if WINDOWS:
  202. self.ui.tabWidget.removeTab(2)
  203. if self.host.isControl:
  204. self.ui.act_file_refresh.setEnabled(False)
  205. else:
  206. self.ui.act_file_connect.setEnabled(False)
  207. self.ui.act_file_connect.setVisible(False)
  208. self.ui.act_file_refresh.setEnabled(False)
  209. self.ui.act_file_refresh.setVisible(False)
  210. if self.fSessionManagerName and not self.host.isPlugin:
  211. self.ui.act_file_new.setEnabled(False)
  212. self.ui.act_file_open.setEnabled(False)
  213. self.ui.act_file_save.setEnabled(False)
  214. self.ui.act_file_save_as.setEnabled(False)
  215. self.ui.act_engine_stop.setEnabled(False)
  216. self.ui.act_plugin_remove_all.setEnabled(False)
  217. self.ui.act_canvas_show_internal.setChecked(False)
  218. self.ui.act_canvas_show_internal.setVisible(False)
  219. self.ui.act_canvas_show_external.setChecked(False)
  220. self.ui.act_canvas_show_external.setVisible(False)
  221. self.ui.menu_PluginMacros.setEnabled(False)
  222. self.ui.menu_Canvas.setEnabled(False)
  223. self.ui.dockWidgetTitleBar = QWidget(self)
  224. self.ui.dockWidget.setTitleBarWidget(self.ui.dockWidgetTitleBar)
  225. if not withCanvas:
  226. self.ui.act_canvas_show_internal.setVisible(False)
  227. self.ui.act_canvas_show_external.setVisible(False)
  228. self.ui.act_canvas_arrange.setVisible(False)
  229. self.ui.act_canvas_refresh.setVisible(False)
  230. self.ui.act_canvas_save_image.setVisible(False)
  231. self.ui.act_canvas_zoom_100.setVisible(False)
  232. self.ui.act_canvas_zoom_fit.setVisible(False)
  233. self.ui.act_canvas_zoom_in.setVisible(False)
  234. self.ui.act_canvas_zoom_out.setVisible(False)
  235. self.ui.act_settings_show_meters.setVisible(False)
  236. self.ui.act_settings_show_keyboard.setVisible(False)
  237. self.ui.menu_Canvas_Zoom.setEnabled(False)
  238. self.ui.menu_Canvas_Zoom.setVisible(False)
  239. self.ui.menu_Canvas_Zoom.menuAction().setVisible(False)
  240. self.ui.menu_Canvas.setEnabled(False)
  241. self.ui.menu_Canvas.setVisible(False)
  242. self.ui.menu_Canvas.menuAction().setVisible(False)
  243. self.ui.tw_miniCanvas.hide()
  244. self.ui.tabWidget.removeTab(1)
  245. if WINDOWS:
  246. self.ui.tabWidget.tabBar().hide()
  247. # ----------------------------------------------------------------------------------------------------
  248. # Set up GUI (disk)
  249. exts = gCarla.utils.get_supported_file_extensions()
  250. self.fDirModel = QFileSystemModel(self)
  251. self.fDirModel.setRootPath(HOME)
  252. self.fDirModel.setNameFilters(tuple(("*." + i) for i in exts))
  253. self.ui.fileTreeView.setModel(self.fDirModel)
  254. self.ui.fileTreeView.setRootIndex(self.fDirModel.index(HOME))
  255. self.ui.fileTreeView.setColumnHidden(1, True)
  256. self.ui.fileTreeView.setColumnHidden(2, True)
  257. self.ui.fileTreeView.setColumnHidden(3, True)
  258. self.ui.fileTreeView.setHeaderHidden(True)
  259. # ----------------------------------------------------------------------------------------------------
  260. # Set up GUI (transport)
  261. fontMetrics = self.ui.l_transport_bbt.fontMetrics()
  262. minValueWidth = fontMetricsHorizontalAdvance(fontMetrics, "000|00|0000")
  263. minLabelWidth = fontMetricsHorizontalAdvance(fontMetrics, self.ui.label_transport_frame.text())
  264. labelTimeWidth = fontMetricsHorizontalAdvance(fontMetrics, self.ui.label_transport_time.text())
  265. labelBBTWidth = fontMetricsHorizontalAdvance(fontMetrics, self.ui.label_transport_bbt.text())
  266. if minLabelWidth < labelTimeWidth:
  267. minLabelWidth = labelTimeWidth
  268. if minLabelWidth < labelBBTWidth:
  269. minLabelWidth = labelBBTWidth
  270. self.ui.label_transport_frame.setMinimumWidth(minLabelWidth + 3)
  271. self.ui.label_transport_time.setMinimumWidth(minLabelWidth + 3)
  272. self.ui.label_transport_bbt.setMinimumWidth(minLabelWidth + 3)
  273. self.ui.l_transport_bbt.setMinimumWidth(minValueWidth + 3)
  274. self.ui.l_transport_frame.setMinimumWidth(minValueWidth + 3)
  275. self.ui.l_transport_time.setMinimumWidth(minValueWidth + 3)
  276. if host.isPlugin:
  277. self.ui.b_transport_play.setEnabled(False)
  278. self.ui.b_transport_stop.setEnabled(False)
  279. self.ui.b_transport_backwards.setEnabled(False)
  280. self.ui.b_transport_forwards.setEnabled(False)
  281. self.ui.group_transport_controls.setEnabled(False)
  282. self.ui.group_transport_controls.setVisible(False)
  283. self.ui.cb_transport_link.setEnabled(False)
  284. self.ui.cb_transport_link.setVisible(False)
  285. self.ui.cb_transport_jack.setEnabled(False)
  286. self.ui.cb_transport_jack.setVisible(False)
  287. self.ui.dsb_transport_bpm.setEnabled(False)
  288. self.ui.dsb_transport_bpm.setReadOnly(True)
  289. self.ui.w_transport.setEnabled(False)
  290. # ----------------------------------------------------------------------------------------------------
  291. # Set up GUI (rack)
  292. self.ui.listWidget.setHostAndParent(self.host, self)
  293. sb = self.ui.listWidget.verticalScrollBar()
  294. self.ui.rackScrollBar.setMinimum(sb.minimum())
  295. self.ui.rackScrollBar.setMaximum(sb.maximum())
  296. self.ui.rackScrollBar.setValue(sb.value())
  297. sb.rangeChanged.connect(self.ui.rackScrollBar.setRange)
  298. sb.valueChanged.connect(self.ui.rackScrollBar.setValue)
  299. self.ui.rackScrollBar.rangeChanged.connect(sb.setRange)
  300. self.ui.rackScrollBar.valueChanged.connect(sb.setValue)
  301. self.updateStyle()
  302. self.ui.rack.setStyleSheet("""
  303. CarlaRackList#CarlaRackList {
  304. background-color: black;
  305. }
  306. """)
  307. # ----------------------------------------------------------------------------------------------------
  308. # Set up GUI (patchbay)
  309. self.ui.peak_in.setChannelCount(2)
  310. self.ui.peak_in.setMeterColor(DigitalPeakMeter.COLOR_BLUE)
  311. self.ui.peak_in.setMeterOrientation(DigitalPeakMeter.VERTICAL)
  312. self.ui.peak_in.setFixedWidth(25)
  313. self.ui.peak_out.setChannelCount(2)
  314. self.ui.peak_out.setMeterColor(DigitalPeakMeter.COLOR_GREEN)
  315. self.ui.peak_out.setMeterOrientation(DigitalPeakMeter.VERTICAL)
  316. self.ui.peak_out.setFixedWidth(25)
  317. self.ui.scrollArea = PixmapKeyboardHArea(self.ui.patchbay)
  318. self.ui.keyboard = self.ui.scrollArea.keyboard
  319. self.ui.patchbay.layout().addWidget(self.ui.scrollArea, 1, 0, 1, 0)
  320. self.ui.scrollArea.setEnabled(False)
  321. self.ui.miniCanvasPreview.setRealParent(self)
  322. self.ui.tw_miniCanvas.tabBar().hide()
  323. # ----------------------------------------------------------------------------------------------------
  324. # Set up GUI (logs)
  325. self.ui.text_logs.textChanged.connect(self.slot_logButtonsState)
  326. self.ui.logs_clear.clicked.connect(self.slot_logClear)
  327. self.ui.logs_save.clicked.connect(self.slot_logSave)
  328. self.ui.logs_autoscroll.stateChanged.connect(self.slot_toggleLogAutoscroll)
  329. self.ui.text_logs.verticalScrollBar().valueChanged.connect(self.slot_logSliderMoved)
  330. # ----------------------------------------------------------------------------------------------------
  331. # Set up GUI (special stuff for Mac OS)
  332. if MACOS:
  333. self.ui.act_file_quit.setMenuRole(QAction.QuitRole)
  334. self.ui.act_settings_configure.setMenuRole(QAction.PreferencesRole)
  335. self.ui.act_help_about.setMenuRole(QAction.AboutRole)
  336. self.ui.act_help_about_juce.setMenuRole(QAction.ApplicationSpecificRole)
  337. self.ui.act_help_about_qt.setMenuRole(QAction.AboutQtRole)
  338. self.ui.menu_Settings.setTitle("Panels")
  339. # ----------------------------------------------------------------------------------------------------
  340. # Load Settings
  341. self.loadSettings(True)
  342. # ----------------------------------------------------------------------------------------------------
  343. # Set-up Canvas
  344. if withCanvas:
  345. self.scene = patchcanvas.PatchScene(self, self.ui.graphicsView)
  346. self.ui.graphicsView.setScene(self.scene)
  347. if self.fSavedSettings[CARLA_KEY_CANVAS_USE_OPENGL] and hasGL:
  348. self.ui.glView = QGLWidget(self)
  349. self.ui.graphicsView.setViewport(self.ui.glView)
  350. self.setupCanvas()
  351. # ----------------------------------------------------------------------------------------------------
  352. # Set-up Icons
  353. if self.fSavedSettings[CARLA_KEY_MAIN_SYSTEM_ICONS]:
  354. self.ui.act_file_connect.setIcon(getIcon('network-connect', 16, 'svgz'))
  355. self.ui.act_file_refresh.setIcon(getIcon('view-refresh', 16, 'svgz'))
  356. self.ui.act_file_new.setIcon(getIcon('document-new', 16, 'svgz'))
  357. self.ui.act_file_open.setIcon(getIcon('document-open', 16, 'svgz'))
  358. self.ui.act_file_save.setIcon(getIcon('document-save', 16, 'svgz'))
  359. self.ui.act_file_save_as.setIcon(getIcon('document-save-as', 16, 'svgz'))
  360. self.ui.act_file_quit.setIcon(getIcon('application-exit', 16, 'svgz'))
  361. self.ui.act_engine_start.setIcon(getIcon('media-playback-start', 16, 'svgz'))
  362. self.ui.act_engine_stop.setIcon(getIcon('media-playback-stop', 16, 'svgz'))
  363. self.ui.act_engine_panic.setIcon(getIcon('dialog-warning', 16, 'svgz'))
  364. self.ui.act_engine_config.setIcon(getIcon('configure', 16, 'svgz'))
  365. self.ui.act_plugin_add.setIcon(getIcon('list-add', 16, 'svgz'))
  366. self.ui.act_plugin_add_jack.setIcon(getIcon('list-add', 16, 'svgz'))
  367. self.ui.act_plugin_remove_all.setIcon(getIcon('edit-delete', 16, 'svgz'))
  368. self.ui.act_canvas_arrange.setIcon(getIcon('view-sort-ascending', 16, 'svgz'))
  369. self.ui.act_canvas_refresh.setIcon(getIcon('view-refresh', 16, 'svgz'))
  370. self.ui.act_canvas_zoom_fit.setIcon(getIcon('zoom-fit-best', 16, 'svgz'))
  371. self.ui.act_canvas_zoom_in.setIcon(getIcon('zoom-in', 16, 'svgz'))
  372. self.ui.act_canvas_zoom_out.setIcon(getIcon('zoom-out', 16, 'svgz'))
  373. self.ui.act_canvas_zoom_100.setIcon(getIcon('zoom-original', 16, 'svgz'))
  374. self.ui.act_settings_configure.setIcon(getIcon('configure', 16, 'svgz'))
  375. self.ui.b_disk_add.setIcon(getIcon('list-add', 16, 'svgz'))
  376. self.ui.b_disk_remove.setIcon(getIcon('list-remove', 16, 'svgz'))
  377. self.ui.b_transport_play.setIcon(getIcon('media-playback-start', 16, 'svgz'))
  378. self.ui.b_transport_stop.setIcon(getIcon('media-playback-stop', 16, 'svgz'))
  379. self.ui.b_transport_backwards.setIcon(getIcon('media-seek-backward', 16, 'svgz'))
  380. self.ui.b_transport_forwards.setIcon(getIcon('media-seek-forward', 16, 'svgz'))
  381. self.ui.logs_clear.setIcon(getIcon('edit-clear', 16, 'svgz'))
  382. self.ui.logs_save.setIcon(getIcon('document-save', 16, 'svgz'))
  383. # ----------------------------------------------------------------------------------------------------
  384. # Connect actions to functions
  385. self.ui.act_file_new.triggered.connect(self.slot_fileNew)
  386. self.ui.act_file_open.triggered.connect(self.slot_fileOpen)
  387. self.ui.act_file_save.triggered.connect(self.slot_fileSave)
  388. self.ui.act_file_save_as.triggered.connect(self.slot_fileSaveAs)
  389. self.ui.act_engine_start.triggered.connect(self.slot_engineStart)
  390. self.ui.act_engine_stop.triggered.connect(self.slot_engineStop)
  391. self.ui.act_engine_panic.triggered.connect(self.slot_pluginsDisable)
  392. self.ui.act_engine_config.triggered.connect(self.slot_engineConfig)
  393. self.ui.act_plugin_add.triggered.connect(self.slot_pluginAdd)
  394. self.ui.act_plugin_add_jack.triggered.connect(self.slot_jackAppAdd)
  395. self.ui.act_plugin_remove_all.triggered.connect(self.slot_confirmRemoveAll)
  396. self.ui.act_plugins_enable.triggered.connect(self.slot_pluginsEnable)
  397. self.ui.act_plugins_disable.triggered.connect(self.slot_pluginsDisable)
  398. self.ui.act_plugins_volume100.triggered.connect(self.slot_pluginsVolume100)
  399. self.ui.act_plugins_mute.triggered.connect(self.slot_pluginsMute)
  400. self.ui.act_plugins_wet100.triggered.connect(self.slot_pluginsWet100)
  401. self.ui.act_plugins_bypass.triggered.connect(self.slot_pluginsBypass)
  402. self.ui.act_plugins_center.triggered.connect(self.slot_pluginsCenter)
  403. self.ui.act_plugins_compact.triggered.connect(self.slot_pluginsCompact)
  404. self.ui.act_plugins_expand.triggered.connect(self.slot_pluginsExpand)
  405. self.ui.act_settings_show_toolbar.toggled.connect(self.slot_showToolbar)
  406. self.ui.act_settings_show_meters.toggled.connect(self.slot_showCanvasMeters)
  407. self.ui.act_settings_show_keyboard.toggled.connect(self.slot_showCanvasKeyboard)
  408. self.ui.act_settings_show_side_panel.toggled.connect(self.slot_showSidePanel)
  409. self.ui.act_settings_configure.triggered.connect(self.slot_configureCarla)
  410. self.ui.act_help_about.triggered.connect(self.slot_aboutCarla)
  411. self.ui.act_help_about_juce.triggered.connect(self.slot_aboutJuce)
  412. self.ui.act_help_about_qt.triggered.connect(self.slot_aboutQt)
  413. self.ui.cb_disk.currentIndexChanged.connect(self.slot_diskFolderChanged)
  414. self.ui.b_disk_add.clicked.connect(self.slot_diskFolderAdd)
  415. self.ui.b_disk_remove.clicked.connect(self.slot_diskFolderRemove)
  416. self.ui.fileTreeView.doubleClicked.connect(self.slot_fileTreeDoubleClicked)
  417. self.ui.b_transport_play.clicked.connect(self.slot_transportPlayPause)
  418. self.ui.b_transport_stop.clicked.connect(self.slot_transportStop)
  419. self.ui.b_transport_backwards.clicked.connect(self.slot_transportBackwards)
  420. self.ui.b_transport_forwards.clicked.connect(self.slot_transportForwards)
  421. self.ui.dsb_transport_bpm.valueChanged.connect(self.slot_transportBpmChanged)
  422. self.ui.cb_transport_jack.clicked.connect(self.slot_transportJackEnabled)
  423. self.ui.cb_transport_link.clicked.connect(self.slot_transportLinkEnabled)
  424. self.ui.b_xruns.clicked.connect(self.slot_xrunClear)
  425. self.ui.listWidget.customContextMenuRequested.connect(self.slot_showPluginActionsMenu)
  426. self.ui.keyboard.noteOn.connect(self.slot_noteOn)
  427. self.ui.keyboard.noteOff.connect(self.slot_noteOff)
  428. self.ui.tabWidget.currentChanged.connect(self.slot_tabChanged)
  429. if withCanvas:
  430. self.ui.act_canvas_show_internal.triggered.connect(self.slot_canvasShowInternal)
  431. self.ui.act_canvas_show_external.triggered.connect(self.slot_canvasShowExternal)
  432. self.ui.act_canvas_arrange.triggered.connect(self.slot_canvasArrange)
  433. self.ui.act_canvas_refresh.triggered.connect(self.slot_canvasRefresh)
  434. self.ui.act_canvas_zoom_fit.triggered.connect(self.slot_canvasZoomFit)
  435. self.ui.act_canvas_zoom_in.triggered.connect(self.slot_canvasZoomIn)
  436. self.ui.act_canvas_zoom_out.triggered.connect(self.slot_canvasZoomOut)
  437. self.ui.act_canvas_zoom_100.triggered.connect(self.slot_canvasZoomReset)
  438. self.ui.act_canvas_save_image.triggered.connect(self.slot_canvasSaveImage)
  439. self.ui.act_canvas_save_image_2x.triggered.connect(self.slot_canvasSaveImage)
  440. self.ui.act_canvas_save_image_4x.triggered.connect(self.slot_canvasSaveImage)
  441. self.ui.act_canvas_copy_clipboard.triggered.connect(self.slot_canvasCopyToClipboard)
  442. self.ui.act_canvas_arrange.setEnabled(False) # TODO, later
  443. self.ui.graphicsView.horizontalScrollBar().valueChanged.connect(self.slot_horizontalScrollBarChanged)
  444. self.ui.graphicsView.verticalScrollBar().valueChanged.connect(self.slot_verticalScrollBarChanged)
  445. self.ui.miniCanvasPreview.miniCanvasMoved.connect(self.slot_miniCanvasMoved)
  446. self.scene.scaleChanged.connect(self.slot_canvasScaleChanged)
  447. self.scene.pluginSelected.connect(self.slot_canvasPluginSelected)
  448. self.scene.selectionChanged.connect(self.slot_canvasSelectionChanged)
  449. self.SIGUSR1.connect(self.slot_handleSIGUSR1)
  450. self.SIGTERM.connect(self.slot_handleSIGTERM)
  451. host.EngineStartedCallback.connect(self.slot_handleEngineStartedCallback)
  452. host.EngineStoppedCallback.connect(self.slot_handleEngineStoppedCallback)
  453. host.TransportModeChangedCallback.connect(self.slot_handleTransportModeChangedCallback)
  454. host.BufferSizeChangedCallback.connect(self.slot_handleBufferSizeChangedCallback)
  455. host.SampleRateChangedCallback.connect(self.slot_handleSampleRateChangedCallback)
  456. host.CancelableActionCallback.connect(self.slot_handleCancelableActionCallback)
  457. host.ProjectLoadFinishedCallback.connect(self.slot_handleProjectLoadFinishedCallback)
  458. host.PluginAddedCallback.connect(self.slot_handlePluginAddedCallback)
  459. host.PluginRemovedCallback.connect(self.slot_handlePluginRemovedCallback)
  460. host.ReloadAllCallback.connect(self.slot_handleReloadAllCallback)
  461. host.NoteOnCallback.connect(self.slot_handleNoteOnCallback)
  462. host.NoteOffCallback.connect(self.slot_handleNoteOffCallback)
  463. host.UpdateCallback.connect(self.slot_handleUpdateCallback)
  464. if withCanvas:
  465. host.PatchbayClientAddedCallback.connect(self.slot_handlePatchbayClientAddedCallback)
  466. host.PatchbayClientRemovedCallback.connect(self.slot_handlePatchbayClientRemovedCallback)
  467. host.PatchbayClientRenamedCallback.connect(self.slot_handlePatchbayClientRenamedCallback)
  468. host.PatchbayClientDataChangedCallback.connect(self.slot_handlePatchbayClientDataChangedCallback)
  469. host.PatchbayClientPositionChangedCallback.connect(self.slot_handlePatchbayClientPositionChangedCallback)
  470. host.PatchbayPortAddedCallback.connect(self.slot_handlePatchbayPortAddedCallback)
  471. host.PatchbayPortRemovedCallback.connect(self.slot_handlePatchbayPortRemovedCallback)
  472. host.PatchbayPortChangedCallback.connect(self.slot_handlePatchbayPortChangedCallback)
  473. host.PatchbayPortGroupAddedCallback.connect(self.slot_handlePatchbayPortGroupAddedCallback)
  474. host.PatchbayPortGroupRemovedCallback.connect(self.slot_handlePatchbayPortGroupRemovedCallback)
  475. host.PatchbayPortGroupChangedCallback.connect(self.slot_handlePatchbayPortGroupChangedCallback)
  476. host.PatchbayConnectionAddedCallback.connect(self.slot_handlePatchbayConnectionAddedCallback)
  477. host.PatchbayConnectionRemovedCallback.connect(self.slot_handlePatchbayConnectionRemovedCallback)
  478. host.NSMCallback.connect(self.slot_handleNSMCallback)
  479. host.DebugCallback.connect(self.slot_handleDebugCallback)
  480. host.InfoCallback.connect(self.slot_handleInfoCallback)
  481. host.ErrorCallback.connect(self.slot_handleErrorCallback)
  482. host.QuitCallback.connect(self.slot_handleQuitCallback)
  483. host.InlineDisplayRedrawCallback.connect(self.slot_handleInlineDisplayRedrawCallback)
  484. # ----------------------------------------------------------------------------------------------------
  485. # Final setup
  486. self.ui.text_logs.clear()
  487. self.slot_logButtonsState(False)
  488. self.setProperWindowTitle()
  489. # Disable non-supported features
  490. features = gCarla.utils.get_supported_features()
  491. if "link" not in features:
  492. self.ui.cb_transport_link.setEnabled(False)
  493. self.ui.cb_transport_link.setVisible(False)
  494. if "juce" not in features:
  495. self.ui.act_help_about_juce.setEnabled(False)
  496. self.ui.act_help_about_juce.setVisible(False)
  497. # Plugin needs to have timers always running so it receives messages
  498. if self.host.isPlugin or self.host.isRemote:
  499. self.startTimers()
  500. # Qt needs this so it properly creates & resizes the canvas
  501. self.ui.tabWidget.blockSignals(True)
  502. self.ui.tabWidget.setCurrentIndex(1)
  503. self.ui.tabWidget.setCurrentIndex(0)
  504. self.ui.tabWidget.blockSignals(False)
  505. # Start in patchbay tab if using forced patchbay mode
  506. if host.processModeForced and host.processMode == ENGINE_PROCESS_MODE_PATCHBAY:
  507. self.ui.tabWidget.setCurrentIndex(1)
  508. # Load initial project file if set
  509. if not (self.host.isControl or self.host.isPlugin):
  510. projectFile = getInitialProjectFile(QApplication.instance())
  511. if projectFile:
  512. self.loadProjectLater(projectFile)
  513. # For NSM we wait for the open message
  514. if NSM_URL and host.nsmOK:
  515. host.nsm_ready(NSM_CALLBACK_INIT)
  516. return
  517. if not host.isControl:
  518. QTimer.singleShot(0, self.slot_engineStart)
  519. # --------------------------------------------------------------------------------------------------------
  520. # Manage visibility state, needed for NSM
  521. def hideForNSM(self):
  522. for pitem in reversed(self.fPluginList):
  523. if pitem is None:
  524. continue
  525. pitem.getWidget().hideCustomUI()
  526. self.hide()
  527. def showIfNeeded(self):
  528. if self.host.nsmOK:
  529. self.ui.act_file_quit.setText(self.tr("Hide"))
  530. QApplication.instance().setQuitOnLastWindowClosed(False)
  531. else:
  532. self.show()
  533. # --------------------------------------------------------------------------------------------------------
  534. # Setup
  535. def compactPlugin(self, pluginId):
  536. if pluginId > self.fPluginCount:
  537. return
  538. pitem = self.fPluginList[pluginId]
  539. if pitem is None:
  540. return
  541. pitem.recreateWidget(True)
  542. def changePluginColor(self, pluginId, color, colorStr):
  543. if pluginId > self.fPluginCount:
  544. return
  545. pitem = self.fPluginList[pluginId]
  546. if pitem is None:
  547. return
  548. self.host.set_custom_data(pluginId, CUSTOM_DATA_TYPE_PROPERTY, "CarlaColor", colorStr)
  549. pitem.recreateWidget(newColor = color)
  550. def changePluginSkin(self, pluginId, skin):
  551. if pluginId > self.fPluginCount:
  552. return
  553. pitem = self.fPluginList[pluginId]
  554. if pitem is None:
  555. return
  556. self.host.set_custom_data(pluginId, CUSTOM_DATA_TYPE_PROPERTY, "CarlaSkin", skin)
  557. if skin not in ("default","rncbc","presets","mpresets"):
  558. pitem.recreateWidget(newSkin = skin, newColor = (255,255,255))
  559. else:
  560. pitem.recreateWidget(newSkin = skin)
  561. def findPluginInPatchbay(self, pluginId):
  562. if pluginId > self.fPluginCount:
  563. return
  564. if self.fExternalPatchbay:
  565. self.slot_canvasShowInternal()
  566. if not patchcanvas.focusGroupUsingPluginId(pluginId):
  567. name = self.host.get_plugin_info(pluginId)['name']
  568. if not patchcanvas.focusGroupUsingGroupName(name):
  569. return
  570. self.ui.tabWidget.setCurrentIndex(1)
  571. def switchPlugins(self, pluginIdA, pluginIdB):
  572. if pluginIdA == pluginIdB:
  573. return
  574. if pluginIdA < 0 or pluginIdB < 0:
  575. return
  576. if pluginIdA >= self.fPluginCount or pluginIdB >= self.fPluginCount:
  577. return
  578. self.host.switch_plugins(pluginIdA, pluginIdB)
  579. itemA = self.fPluginList[pluginIdA]
  580. compactA = itemA.isCompacted()
  581. guiShownA = itemA.isGuiShown()
  582. itemB = self.fPluginList[pluginIdB]
  583. compactB = itemB.isCompacted()
  584. guiShownB = itemB.isGuiShown()
  585. itemA.setPluginId(pluginIdA)
  586. itemA.recreateWidget2(compactB, guiShownB)
  587. itemB.setPluginId(pluginIdB)
  588. itemB.recreateWidget2(compactA, guiShownA)
  589. if self.fWithCanvas:
  590. self.slot_canvasRefresh()
  591. def setLoadRDFsNeeded(self):
  592. self.fLadspaRdfNeedsUpdate = True
  593. def setProperWindowTitle(self):
  594. title = self.fClientName
  595. if self.fProjectFilename and not self.host.nsmOK:
  596. title += " - %s" % os.path.basename(self.fProjectFilename)
  597. if self.fSessionManagerName:
  598. title += " (%s)" % self.fSessionManagerName
  599. self.setWindowTitle(title)
  600. def updateBufferSize(self, newBufferSize):
  601. if self.fBufferSize == newBufferSize:
  602. return
  603. self.fBufferSize = newBufferSize
  604. self.ui.cb_buffer_size.clear()
  605. self.ui.cb_buffer_size.addItem(str(newBufferSize))
  606. self.ui.cb_buffer_size.setCurrentIndex(0)
  607. def updateSampleRate(self, newSampleRate):
  608. if self.fSampleRate == newSampleRate:
  609. return
  610. self.fSampleRate = newSampleRate
  611. self.ui.cb_sample_rate.clear()
  612. self.ui.cb_sample_rate.addItem(str(newSampleRate))
  613. self.ui.cb_sample_rate.setCurrentIndex(0)
  614. self.refreshTransport(True)
  615. # --------------------------------------------------------------------------------------------------------
  616. # Files
  617. def loadProjectNow(self):
  618. if not self.fProjectFilename:
  619. return qCritical("ERROR: loading project without filename set")
  620. if self.host.nsmOK and not os.path.exists(self.fProjectFilename):
  621. return
  622. self.projectLoadingStarted()
  623. self.fIsProjectLoading = True
  624. if not self.host.load_project(self.fProjectFilename):
  625. self.fIsProjectLoading = False
  626. self.projectLoadingFinished(True)
  627. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Failed to load project"),
  628. self.host.get_last_error(),
  629. QMessageBox.Ok, QMessageBox.Ok)
  630. def loadProjectLater(self, filename):
  631. self.fProjectFilename = QFileInfo(filename).absoluteFilePath()
  632. self.setProperWindowTitle()
  633. QTimer.singleShot(1, self.slot_loadProjectNow)
  634. def saveProjectNow(self):
  635. if not self.fProjectFilename:
  636. return qCritical("ERROR: saving project without filename set")
  637. if not self.host.save_project(self.fProjectFilename):
  638. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Failed to save project"),
  639. self.host.get_last_error(),
  640. QMessageBox.Ok, QMessageBox.Ok)
  641. return
  642. def projectLoadingStarted(self):
  643. self.ui.rack.setEnabled(False)
  644. self.ui.graphicsView.setEnabled(False)
  645. def projectLoadingFinished(self, refreshCanvas):
  646. self.ui.rack.setEnabled(True)
  647. self.ui.graphicsView.setEnabled(True)
  648. if self.fCustomStopAction == self.CUSTOM_ACTION_APP_CLOSE or not self.fWithCanvas:
  649. return
  650. if refreshCanvas and not self.loadExternalCanvasGroupPositionsIfNeeded(self.fProjectFilename):
  651. QTimer.singleShot(1, self.slot_canvasRefresh)
  652. def loadExternalCanvasGroupPositionsIfNeeded(self, filename):
  653. extrafile = filename.rsplit(".",1)[0]+".json"
  654. if not os.path.exists(extrafile):
  655. return False
  656. with open(filename, "r") as fh:
  657. if "".join(fh.readlines(90)).find("<CARLA-PROJECT VERSION='2.0'>") < 0:
  658. return False
  659. with open(extrafile, "r") as fh:
  660. try:
  661. canvasdata = json.load(fh)['canvas']
  662. except:
  663. return False
  664. print("NOTICE: loading old-style canvas group positions via legacy json file")
  665. patchcanvas.restoreGroupPositions(canvasdata)
  666. QTimer.singleShot(1, self.slot_canvasRefresh)
  667. return True
  668. # --------------------------------------------------------------------------------------------------------
  669. # Files (menu actions)
  670. @pyqtSlot()
  671. def slot_fileNew(self):
  672. if self.fPluginCount > 0 and QMessageBox.question(self, self.tr("New File"),
  673. self.tr("Plugins that are currently loaded will be removed. Are you sure?"),
  674. QMessageBox.Yes|QMessageBox.No) == QMessageBox.No:
  675. return
  676. self.pluginRemoveAll()
  677. self.fProjectFilename = ""
  678. self.setProperWindowTitle()
  679. self.host.clear_project_filename()
  680. @pyqtSlot()
  681. def slot_fileOpen(self):
  682. fileFilter = self.tr("Carla Project File (*.carxp);;Carla Preset File (*.carxs)")
  683. filename, ok = QFileDialog.getOpenFileName(self, self.tr("Open Carla Project File"), self.fSavedSettings[CARLA_KEY_MAIN_PROJECT_FOLDER], filter=fileFilter)
  684. # FIXME use ok value, test if it works as expected
  685. if not filename:
  686. return
  687. newFile = True
  688. if self.fPluginCount > 0:
  689. ask = QMessageBox.question(self, self.tr("Question"), self.tr("There are some plugins loaded, do you want to remove them now?"),
  690. QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
  691. newFile = (ask == QMessageBox.Yes)
  692. if newFile:
  693. self.pluginRemoveAll()
  694. self.fProjectFilename = filename
  695. self.setProperWindowTitle()
  696. self.loadProjectNow()
  697. else:
  698. filenameOld = self.fProjectFilename
  699. self.fProjectFilename = filename
  700. self.loadProjectNow()
  701. self.fProjectFilename = filenameOld
  702. @pyqtSlot()
  703. def slot_fileSave(self, saveAs=False):
  704. if self.fProjectFilename and not saveAs:
  705. return self.saveProjectNow()
  706. fileFilter = self.tr("Carla Project File (*.carxp)")
  707. filename, ok = QFileDialog.getSaveFileName(self, self.tr("Save Carla Project File"), self.fSavedSettings[CARLA_KEY_MAIN_PROJECT_FOLDER], filter=fileFilter)
  708. # FIXME use ok value, test if it works as expected
  709. if not filename:
  710. return
  711. if not filename.lower().endswith(".carxp"):
  712. filename += ".carxp"
  713. if self.fProjectFilename != filename:
  714. self.fProjectFilename = filename
  715. self.setProperWindowTitle()
  716. self.saveProjectNow()
  717. @pyqtSlot()
  718. def slot_fileSaveAs(self):
  719. self.slot_fileSave(True)
  720. @pyqtSlot()
  721. def slot_loadProjectNow(self):
  722. self.loadProjectNow()
  723. # --------------------------------------------------------------------------------------------------------
  724. # Engine (menu actions)
  725. @pyqtSlot()
  726. def slot_engineStart(self):
  727. audioDriver = setEngineSettings(self.host)
  728. firstInit = self.fFirstEngineInit
  729. self.fFirstEngineInit = False
  730. self.ui.text_logs.appendPlainText("======= Starting engine =======")
  731. if self.host.engine_init(audioDriver, self.fClientName):
  732. if firstInit and not (self.host.isControl or self.host.isPlugin):
  733. settings = QSafeSettings()
  734. lastBpm = settings.value("LastBPM", 120.0, float)
  735. del settings
  736. if lastBpm >= 20.0:
  737. self.host.transport_bpm(lastBpm)
  738. return
  739. elif firstInit:
  740. self.ui.text_logs.appendPlainText("Failed to start engine on first try, ignored")
  741. return
  742. audioError = self.host.get_last_error()
  743. if audioError:
  744. QMessageBox.critical(self, self.tr("Error"), self.tr("Could not connect to Audio backend '%s', possible reasons:\n%s" % (audioDriver, audioError)))
  745. else:
  746. QMessageBox.critical(self, self.tr("Error"), self.tr("Could not connect to Audio backend '%s'" % audioDriver))
  747. @pyqtSlot()
  748. def slot_engineStop(self, forced = False):
  749. self.ui.text_logs.appendPlainText("======= Stopping engine =======")
  750. if self.fPluginCount == 0 or not self.host.is_engine_running():
  751. self.engineStopFinal()
  752. return True
  753. if not forced:
  754. 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"
  755. "Do you want to do this now?"),
  756. QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
  757. if ask != QMessageBox.Yes:
  758. return False
  759. return self.slot_engineStopTryAgain()
  760. @pyqtSlot()
  761. def slot_engineConfig(self):
  762. dialog = RuntimeDriverSettingsW(self.fParentOrSelf, self.host)
  763. if not dialog.exec_():
  764. return
  765. audioDevice, bufferSize, sampleRate = dialog.getValues()
  766. if self.host.is_engine_running():
  767. self.host.set_engine_buffer_size_and_sample_rate(bufferSize, sampleRate)
  768. else:
  769. self.host.set_engine_option(ENGINE_OPTION_AUDIO_DEVICE, 0, audioDevice)
  770. self.host.set_engine_option(ENGINE_OPTION_AUDIO_BUFFER_SIZE, bufferSize, "")
  771. self.host.set_engine_option(ENGINE_OPTION_AUDIO_SAMPLE_RATE, sampleRate, "")
  772. @pyqtSlot()
  773. def slot_engineStopTryAgain(self):
  774. if self.host.is_engine_running() and not self.host.set_engine_about_to_close():
  775. QTimer.singleShot(0, self.slot_engineStopTryAgain)
  776. return False
  777. self.engineStopFinal()
  778. return True
  779. def engineStopFinal(self):
  780. patchcanvas.handleAllPluginsRemoved()
  781. self.killTimers()
  782. if self.fCustomStopAction == self.CUSTOM_ACTION_PROJECT_LOAD:
  783. self.removeAllPlugins()
  784. else:
  785. self.fProjectFilename = ""
  786. self.setProperWindowTitle()
  787. if self.fPluginCount != 0:
  788. self.fCurrentlyRemovingAllPlugins = True
  789. self.projectLoadingStarted()
  790. if self.host.is_engine_running() and not self.host.remove_all_plugins():
  791. self.ui.text_logs.appendPlainText("Failed to remove all plugins, error was:")
  792. self.ui.text_logs.appendPlainText(self.host.get_last_error())
  793. if not self.host.engine_close():
  794. self.ui.text_logs.appendPlainText("Failed to stop engine, error was:")
  795. self.ui.text_logs.appendPlainText(self.host.get_last_error())
  796. if self.fCustomStopAction == self.CUSTOM_ACTION_APP_CLOSE:
  797. self.close()
  798. elif self.fCustomStopAction == self.CUSTOM_ACTION_PROJECT_LOAD:
  799. self.slot_engineStart()
  800. self.loadProjectNow()
  801. self.host.nsm_ready(NSM_CALLBACK_OPEN)
  802. self.fCustomStopAction = self.CUSTOM_ACTION_NONE
  803. # --------------------------------------------------------------------------------------------------------
  804. # Engine (host callbacks)
  805. @pyqtSlot(int, int, int, int, float, str)
  806. def slot_handleEngineStartedCallback(self, pluginCount, processMode, transportMode, bufferSize, sampleRate, driverName):
  807. self.ui.menu_PluginMacros.setEnabled(True)
  808. self.ui.menu_Canvas.setEnabled(True)
  809. self.ui.w_transport.setEnabled(True)
  810. self.ui.act_canvas_show_internal.blockSignals(True)
  811. self.ui.act_canvas_show_external.blockSignals(True)
  812. if processMode == ENGINE_PROCESS_MODE_PATCHBAY and not self.host.isPlugin:
  813. self.ui.act_canvas_show_internal.setChecked(True)
  814. self.ui.act_canvas_show_internal.setVisible(True)
  815. self.ui.act_canvas_show_external.setChecked(False)
  816. self.ui.act_canvas_show_external.setVisible(True)
  817. self.fExternalPatchbay = False
  818. else:
  819. self.ui.act_canvas_show_internal.setChecked(False)
  820. self.ui.act_canvas_show_internal.setVisible(False)
  821. self.ui.act_canvas_show_external.setChecked(True)
  822. self.ui.act_canvas_show_external.setVisible(False)
  823. self.fExternalPatchbay = not self.host.isPlugin
  824. self.ui.act_canvas_show_internal.blockSignals(False)
  825. self.ui.act_canvas_show_external.blockSignals(False)
  826. if not (self.host.isControl or self.host.isPlugin):
  827. canSave = (self.fProjectFilename and os.path.exists(self.fProjectFilename)) or not self.fSessionManagerName
  828. self.ui.act_file_save.setEnabled(canSave)
  829. self.ui.act_engine_start.setEnabled(False)
  830. self.ui.act_engine_stop.setEnabled(True)
  831. if not self.host.isPlugin:
  832. self.enableTransport(transportMode != ENGINE_TRANSPORT_MODE_DISABLED)
  833. if self.host.isPlugin or not self.fSessionManagerName:
  834. self.ui.act_file_open.setEnabled(True)
  835. self.ui.act_file_save_as.setEnabled(True)
  836. self.ui.cb_transport_jack.setChecked(transportMode == ENGINE_TRANSPORT_MODE_JACK)
  837. self.ui.cb_transport_jack.setEnabled(driverName == "JACK" and processMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS)
  838. if self.ui.cb_transport_link.isEnabled():
  839. self.ui.cb_transport_link.setChecked(":link:" in self.host.transportExtra)
  840. self.updateBufferSize(bufferSize)
  841. self.updateSampleRate(int(sampleRate))
  842. self.refreshRuntimeInfo(0.0, 0)
  843. self.startTimers()
  844. self.ui.text_logs.appendPlainText("======= Engine started ========")
  845. self.ui.text_logs.appendPlainText("Carla engine started, details:")
  846. self.ui.text_logs.appendPlainText(" Driver name: %s" % driverName)
  847. self.ui.text_logs.appendPlainText(" Sample rate: %i" % int(sampleRate))
  848. self.ui.text_logs.appendPlainText(" Process mode: %s" % processMode2Str(processMode))
  849. @pyqtSlot()
  850. def slot_handleEngineStoppedCallback(self):
  851. self.ui.text_logs.appendPlainText("======= Engine stopped ========")
  852. if self.fWithCanvas:
  853. patchcanvas.clear()
  854. self.killTimers()
  855. # just in case
  856. self.removeAllPlugins()
  857. self.refreshRuntimeInfo(0.0, 0)
  858. self.ui.menu_PluginMacros.setEnabled(False)
  859. self.ui.menu_Canvas.setEnabled(False)
  860. self.ui.w_transport.setEnabled(False)
  861. if not (self.host.isControl or self.host.isPlugin):
  862. self.ui.act_file_save.setEnabled(False)
  863. self.ui.act_engine_start.setEnabled(True)
  864. self.ui.act_engine_stop.setEnabled(False)
  865. if self.host.isPlugin or not self.fSessionManagerName:
  866. self.ui.act_file_open.setEnabled(False)
  867. self.ui.act_file_save_as.setEnabled(False)
  868. @pyqtSlot(int, str)
  869. def slot_handleTransportModeChangedCallback(self, transportMode, transportExtra):
  870. self.enableTransport(transportMode != ENGINE_TRANSPORT_MODE_DISABLED)
  871. self.ui.cb_transport_jack.setChecked(transportMode == ENGINE_TRANSPORT_MODE_JACK)
  872. self.ui.cb_transport_link.setChecked(":link:" in transportExtra)
  873. @pyqtSlot(int)
  874. def slot_handleBufferSizeChangedCallback(self, newBufferSize):
  875. self.updateBufferSize(newBufferSize)
  876. @pyqtSlot(float)
  877. def slot_handleSampleRateChangedCallback(self, newSampleRate):
  878. self.updateSampleRate(int(newSampleRate))
  879. @pyqtSlot(int, bool, str)
  880. def slot_handleCancelableActionCallback(self, pluginId, started, action):
  881. if self.fCancelableActionBox is not None:
  882. self.fCancelableActionBox.close()
  883. if started:
  884. self.fCancelableActionBox = QMessageBox(self)
  885. self.fCancelableActionBox.setIcon(QMessageBox.Information)
  886. self.fCancelableActionBox.setWindowTitle(self.tr("Action in progress"))
  887. self.fCancelableActionBox.setText(action)
  888. self.fCancelableActionBox.setInformativeText(self.tr("An action is in progress, please wait..."))
  889. self.fCancelableActionBox.setStandardButtons(QMessageBox.Cancel)
  890. self.fCancelableActionBox.setDefaultButton(QMessageBox.Cancel)
  891. self.fCancelableActionBox.buttonClicked.connect(self.slot_canlableActionBoxClicked)
  892. self.fCancelableActionBox.show()
  893. else:
  894. self.fCancelableActionBox = None
  895. @pyqtSlot()
  896. def slot_canlableActionBoxClicked(self):
  897. self.host.cancel_engine_action()
  898. @pyqtSlot()
  899. def slot_handleProjectLoadFinishedCallback(self):
  900. self.fIsProjectLoading = False
  901. self.projectLoadingFinished(False)
  902. # --------------------------------------------------------------------------------------------------------
  903. # Plugins
  904. def removeAllPlugins(self):
  905. self.ui.act_plugin_remove_all.setEnabled(False)
  906. patchcanvas.handleAllPluginsRemoved()
  907. while self.ui.listWidget.takeItem(0):
  908. pass
  909. self.clearSideStuff()
  910. for pitem in self.fPluginList:
  911. if pitem is None:
  912. continue
  913. pitem.close()
  914. del pitem
  915. self.fPluginCount = 0
  916. self.fPluginList = []
  917. # --------------------------------------------------------------------------------------------------------
  918. # Plugins (menu actions)
  919. def showAddPluginDialog(self):
  920. if self.fPluginDatabaseDialog is None:
  921. self.fPluginDatabaseDialog = PluginDatabaseW(self.fParentOrSelf, self.host,
  922. self.fSavedSettings[CARLA_KEY_MAIN_SYSTEM_ICONS])
  923. dialog = self.fPluginDatabaseDialog
  924. ret = dialog.exec_()
  925. if dialog.fFavoritePluginsChanged:
  926. self.fFavoritePlugins = dialog.fFavoritePlugins
  927. if not ret:
  928. return
  929. if not self.host.is_engine_running():
  930. QMessageBox.warning(self, self.tr("Warning"), self.tr("Cannot add new plugins while engine is stopped"))
  931. return
  932. btype = dialog.fRetPlugin['build']
  933. ptype = dialog.fRetPlugin['type']
  934. filename = dialog.fRetPlugin['filename']
  935. label = dialog.fRetPlugin['label']
  936. uniqueId = dialog.fRetPlugin['uniqueId']
  937. extraPtr = self.getExtraPtr(dialog.fRetPlugin)
  938. return (btype, ptype, filename, label, uniqueId, extraPtr)
  939. def showAddJackAppDialog(self):
  940. dialog = JackApplicationW(self.fParentOrSelf, self.fProjectFilename)
  941. if not dialog.exec_():
  942. return
  943. if not self.host.is_engine_running():
  944. QMessageBox.warning(self, self.tr("Warning"), self.tr("Cannot add new plugins while engine is stopped"))
  945. return
  946. return dialog.getCommandAndFlags()
  947. @pyqtSlot()
  948. def slot_favoritePluginAdd(self):
  949. plugin = self.sender().data()
  950. if plugin is None:
  951. return
  952. if not self.host.add_plugin(plugin['build'], plugin['type'], plugin['filename'], None,
  953. plugin['label'], plugin['uniqueId'], None, PLUGIN_OPTIONS_NULL):
  954. # remove plugin from favorites
  955. try:
  956. self.fFavoritePlugins.remove(plugin)
  957. except ValueError:
  958. pass
  959. else:
  960. settingsDBf = QSafeSettings("falkTX", "CarlaDatabase2")
  961. settingsDBf.setValue("PluginDatabase/Favorites", self.fFavoritePlugins)
  962. settingsDBf.sync()
  963. del settingsDBf
  964. CustomMessageBox(self,
  965. QMessageBox.Critical,
  966. self.tr("Error"),
  967. self.tr("Failed to load plugin"),
  968. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  969. @pyqtSlot()
  970. def slot_showPluginActionsMenu(self):
  971. menu = QMenu(self)
  972. menu.addSection("Plugins")
  973. menu.addAction(self.ui.act_plugin_add)
  974. if len(self.fFavoritePlugins) != 0:
  975. fmenu = QMenu("Add from favorites", self)
  976. for p in self.fFavoritePlugins:
  977. act = fmenu.addAction(p['name'])
  978. act.setData(p)
  979. act.triggered.connect(self.slot_favoritePluginAdd)
  980. menu.addMenu(fmenu)
  981. menu.addAction(self.ui.act_plugin_remove_all)
  982. menu.addSection("All plugins (macros)")
  983. menu.addAction(self.ui.act_plugins_enable)
  984. menu.addAction(self.ui.act_plugins_disable)
  985. menu.addSeparator()
  986. menu.addAction(self.ui.act_plugins_volume100)
  987. menu.addAction(self.ui.act_plugins_mute)
  988. menu.addSeparator()
  989. menu.addAction(self.ui.act_plugins_wet100)
  990. menu.addAction(self.ui.act_plugins_bypass)
  991. menu.addSeparator()
  992. menu.addAction(self.ui.act_plugins_center)
  993. menu.addSeparator()
  994. menu.addAction(self.ui.act_plugins_compact)
  995. menu.addAction(self.ui.act_plugins_expand)
  996. menu.exec_(QCursor.pos())
  997. @pyqtSlot()
  998. def slot_pluginAdd(self):
  999. data = self.showAddPluginDialog()
  1000. if data is None:
  1001. return
  1002. btype, ptype, filename, label, uniqueId, extraPtr = data
  1003. if not self.host.add_plugin(btype, ptype, filename, None, label, uniqueId, extraPtr, PLUGIN_OPTIONS_NULL):
  1004. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Failed to load plugin"),
  1005. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1006. @pyqtSlot()
  1007. def slot_confirmRemoveAll(self):
  1008. if self.fPluginCount == 0:
  1009. return
  1010. if QMessageBox.question(self, self.tr("Remove All"),
  1011. self.tr("Are you sure you want to remove all plugins?"),
  1012. QMessageBox.Yes|QMessageBox.No) == QMessageBox.No:
  1013. return
  1014. self.pluginRemoveAll()
  1015. def pluginRemoveAll(self):
  1016. if self.fPluginCount == 0:
  1017. return
  1018. self.fCurrentlyRemovingAllPlugins = True
  1019. self.projectLoadingStarted()
  1020. if not self.host.remove_all_plugins():
  1021. self.projectLoadingFinished(True)
  1022. self.fCurrentlyRemovingAllPlugins = False
  1023. CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"),
  1024. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1025. @pyqtSlot()
  1026. def slot_jackAppAdd(self):
  1027. data = self.showAddJackAppDialog()
  1028. if data is None:
  1029. return
  1030. filename, name, label = data
  1031. if not filename:
  1032. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Cannot add jack application"),
  1033. self.tr("command is empty"), QMessageBox.Ok, QMessageBox.Ok)
  1034. return
  1035. if not self.host.add_plugin(BINARY_NATIVE, PLUGIN_JACK, filename, name, label, 0, None, PLUGIN_OPTIONS_NULL):
  1036. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"), self.tr("Failed to load plugin"),
  1037. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1038. # --------------------------------------------------------------------------------------------------------
  1039. # Plugins (macros)
  1040. @pyqtSlot()
  1041. def slot_pluginsEnable(self):
  1042. if not self.host.is_engine_running():
  1043. return
  1044. for pitem in self.fPluginList:
  1045. if pitem is None:
  1046. break
  1047. pitem.getWidget().setActive(True, True, True)
  1048. @pyqtSlot()
  1049. def slot_pluginsDisable(self):
  1050. if not self.host.is_engine_running():
  1051. return
  1052. for pitem in self.fPluginList:
  1053. if pitem is None:
  1054. break
  1055. pitem.getWidget().setActive(False, True, True)
  1056. @pyqtSlot()
  1057. def slot_pluginsVolume100(self):
  1058. if not self.host.is_engine_running():
  1059. return
  1060. for pitem in self.fPluginList:
  1061. if pitem is None:
  1062. break
  1063. pitem.getWidget().setInternalParameter(PLUGIN_CAN_VOLUME, 1.0)
  1064. @pyqtSlot()
  1065. def slot_pluginsMute(self):
  1066. if not self.host.is_engine_running():
  1067. return
  1068. for pitem in self.fPluginList:
  1069. if pitem is None:
  1070. break
  1071. pitem.getWidget().setInternalParameter(PLUGIN_CAN_VOLUME, 0.0)
  1072. @pyqtSlot()
  1073. def slot_pluginsWet100(self):
  1074. if not self.host.is_engine_running():
  1075. return
  1076. for pitem in self.fPluginList:
  1077. if pitem is None:
  1078. break
  1079. pitem.getWidget().setInternalParameter(PLUGIN_CAN_DRYWET, 1.0)
  1080. @pyqtSlot()
  1081. def slot_pluginsBypass(self):
  1082. if not self.host.is_engine_running():
  1083. return
  1084. for pitem in self.fPluginList:
  1085. if pitem is None:
  1086. break
  1087. pitem.getWidget().setInternalParameter(PLUGIN_CAN_DRYWET, 0.0)
  1088. @pyqtSlot()
  1089. def slot_pluginsCenter(self):
  1090. if not self.host.is_engine_running():
  1091. return
  1092. for pitem in self.fPluginList:
  1093. if pitem is None:
  1094. break
  1095. pitem.getWidget().setInternalParameter(PARAMETER_BALANCE_LEFT, -1.0)
  1096. pitem.getWidget().setInternalParameter(PARAMETER_BALANCE_RIGHT, 1.0)
  1097. pitem.getWidget().setInternalParameter(PARAMETER_PANNING, 0.0)
  1098. @pyqtSlot()
  1099. def slot_pluginsCompact(self):
  1100. for pitem in self.fPluginList:
  1101. if pitem is None:
  1102. break
  1103. pitem.compact()
  1104. @pyqtSlot()
  1105. def slot_pluginsExpand(self):
  1106. for pitem in self.fPluginList:
  1107. if pitem is None:
  1108. break
  1109. pitem.expand()
  1110. # --------------------------------------------------------------------------------------------------------
  1111. # Plugins (host callbacks)
  1112. @pyqtSlot(int, str)
  1113. def slot_handlePluginAddedCallback(self, pluginId, pluginName):
  1114. if pluginId != self.fPluginCount:
  1115. print("ERROR: pluginAdded mismatch Id:", pluginId, self.fPluginCount)
  1116. pitem = self.getPluginItem(pluginId)
  1117. pitem.recreateWidget()
  1118. return
  1119. pitem = self.ui.listWidget.createItem(pluginId, self.fSavedSettings[CARLA_KEY_MAIN_CLASSIC_SKIN])
  1120. self.fPluginList.append(pitem)
  1121. self.fPluginCount += 1
  1122. self.ui.act_plugin_remove_all.setEnabled(self.fPluginCount > 0)
  1123. @pyqtSlot(int)
  1124. def slot_handlePluginRemovedCallback(self, pluginId):
  1125. if self.fWithCanvas:
  1126. patchcanvas.handlePluginRemoved(pluginId)
  1127. if pluginId in self.fSelectedPlugins:
  1128. self.clearSideStuff()
  1129. if self.fPluginCount == 0:
  1130. return
  1131. pitem = self.getPluginItem(pluginId)
  1132. self.fPluginCount -= 1
  1133. self.fPluginList.pop(pluginId)
  1134. self.ui.listWidget.takeItem(pluginId)
  1135. if pitem is not None:
  1136. pitem.close()
  1137. del pitem
  1138. if self.fPluginCount == 0:
  1139. self.ui.act_plugin_remove_all.setEnabled(False)
  1140. if self.fCurrentlyRemovingAllPlugins:
  1141. self.fCurrentlyRemovingAllPlugins = False
  1142. self.projectLoadingFinished(False)
  1143. return
  1144. # push all plugins 1 slot back
  1145. for i in range(pluginId, self.fPluginCount):
  1146. pitem = self.fPluginList[i]
  1147. pitem.setPluginId(i)
  1148. self.ui.act_plugin_remove_all.setEnabled(True)
  1149. # --------------------------------------------------------------------------------------------------------
  1150. # Canvas
  1151. def clearSideStuff(self):
  1152. if self.fWithCanvas:
  1153. self.scene.clearSelection()
  1154. self.fSelectedPlugins = []
  1155. self.ui.keyboard.allNotesOff(False)
  1156. self.ui.scrollArea.setEnabled(False)
  1157. self.fPeaksCleared = True
  1158. self.ui.peak_in.displayMeter(1, 0.0, True)
  1159. self.ui.peak_in.displayMeter(2, 0.0, True)
  1160. self.ui.peak_out.displayMeter(1, 0.0, True)
  1161. self.ui.peak_out.displayMeter(2, 0.0, True)
  1162. def setupCanvas(self):
  1163. pOptions = patchcanvas.options_t()
  1164. pOptions.theme_name = self.fSavedSettings[CARLA_KEY_CANVAS_THEME]
  1165. pOptions.auto_hide_groups = self.fSavedSettings[CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS]
  1166. pOptions.auto_select_items = self.fSavedSettings[CARLA_KEY_CANVAS_AUTO_SELECT_ITEMS]
  1167. pOptions.use_bezier_lines = self.fSavedSettings[CARLA_KEY_CANVAS_USE_BEZIER_LINES]
  1168. pOptions.antialiasing = self.fSavedSettings[CARLA_KEY_CANVAS_ANTIALIASING]
  1169. pOptions.inline_displays = self.fSavedSettings[CARLA_KEY_CANVAS_INLINE_DISPLAYS]
  1170. if self.fSavedSettings[CARLA_KEY_CANVAS_FANCY_EYE_CANDY]:
  1171. pOptions.eyecandy = patchcanvas.EYECANDY_FULL
  1172. elif self.fSavedSettings[CARLA_KEY_CANVAS_EYE_CANDY]:
  1173. pOptions.eyecandy = patchcanvas.EYECANDY_SMALL
  1174. else:
  1175. pOptions.eyecandy = patchcanvas.EYECANDY_NONE
  1176. pFeatures = patchcanvas.features_t()
  1177. pFeatures.group_info = False
  1178. pFeatures.group_rename = False
  1179. pFeatures.port_info = False
  1180. pFeatures.port_rename = False
  1181. pFeatures.handle_group_pos = False
  1182. patchcanvas.setOptions(pOptions)
  1183. patchcanvas.setFeatures(pFeatures)
  1184. patchcanvas.init("Carla2", self.scene, canvasCallback, False)
  1185. tryCanvasSize = self.fSavedSettings[CARLA_KEY_CANVAS_SIZE].split("x")
  1186. if len(tryCanvasSize) == 2 and tryCanvasSize[0].isdigit() and tryCanvasSize[1].isdigit():
  1187. self.fCanvasWidth = int(tryCanvasSize[0])
  1188. self.fCanvasHeight = int(tryCanvasSize[1])
  1189. else:
  1190. self.fCanvasWidth = CARLA_DEFAULT_CANVAS_SIZE_WIDTH
  1191. self.fCanvasHeight = CARLA_DEFAULT_CANVAS_SIZE_HEIGHT
  1192. patchcanvas.setCanvasSize(0, 0, self.fCanvasWidth, self.fCanvasHeight)
  1193. patchcanvas.setInitialPos(self.fCanvasWidth / 2, self.fCanvasHeight / 2)
  1194. self.ui.graphicsView.setSceneRect(0, 0, self.fCanvasWidth, self.fCanvasHeight)
  1195. self.ui.miniCanvasPreview.setViewTheme(patchcanvas.canvas.theme.canvas_bg, patchcanvas.canvas.theme.rubberband_brush, patchcanvas.canvas.theme.rubberband_pen.color())
  1196. self.ui.miniCanvasPreview.init(self.scene, self.fCanvasWidth, self.fCanvasHeight, self.fSavedSettings[CARLA_KEY_CUSTOM_PAINTING])
  1197. if self.fSavedSettings[CARLA_KEY_CANVAS_ANTIALIASING] != patchcanvas.ANTIALIASING_NONE:
  1198. self.ui.graphicsView.setRenderHint(QPainter.Antialiasing, True)
  1199. fullAA = self.fSavedSettings[CARLA_KEY_CANVAS_ANTIALIASING] == patchcanvas.ANTIALIASING_FULL
  1200. self.ui.graphicsView.setRenderHint(QPainter.SmoothPixmapTransform, fullAA)
  1201. self.ui.graphicsView.setRenderHint(QPainter.TextAntialiasing, fullAA)
  1202. if self.fSavedSettings[CARLA_KEY_CANVAS_USE_OPENGL] and hasGL:
  1203. self.ui.graphicsView.setRenderHint(QPainter.HighQualityAntialiasing, self.fSavedSettings[CARLA_KEY_CANVAS_HQ_ANTIALIASING])
  1204. else:
  1205. self.ui.graphicsView.setRenderHint(QPainter.Antialiasing, False)
  1206. if self.fSavedSettings[CARLA_KEY_CANVAS_FULL_REPAINTS]:
  1207. self.ui.graphicsView.setViewportUpdateMode(QGraphicsView.FullViewportUpdate)
  1208. else:
  1209. self.ui.graphicsView.setViewportUpdateMode(QGraphicsView.MinimalViewportUpdate)
  1210. def updateCanvasInitialPos(self):
  1211. x = self.ui.graphicsView.horizontalScrollBar().value() + self.width()/4
  1212. y = self.ui.graphicsView.verticalScrollBar().value() + self.height()/4
  1213. patchcanvas.setInitialPos(x, y)
  1214. def updateMiniCanvasLater(self):
  1215. QTimer.singleShot(self.fMiniCanvasUpdateTimeout, self.ui.miniCanvasPreview.update)
  1216. # --------------------------------------------------------------------------------------------------------
  1217. # Canvas (menu actions)
  1218. @pyqtSlot()
  1219. def slot_canvasShowInternal(self):
  1220. self.fExternalPatchbay = False
  1221. self.ui.act_canvas_show_internal.blockSignals(True)
  1222. self.ui.act_canvas_show_external.blockSignals(True)
  1223. self.ui.act_canvas_show_internal.setChecked(True)
  1224. self.ui.act_canvas_show_external.setChecked(False)
  1225. self.ui.act_canvas_show_internal.blockSignals(False)
  1226. self.ui.act_canvas_show_external.blockSignals(False)
  1227. self.slot_canvasRefresh()
  1228. @pyqtSlot()
  1229. def slot_canvasShowExternal(self):
  1230. self.fExternalPatchbay = True
  1231. self.ui.act_canvas_show_internal.blockSignals(True)
  1232. self.ui.act_canvas_show_external.blockSignals(True)
  1233. self.ui.act_canvas_show_internal.setChecked(False)
  1234. self.ui.act_canvas_show_external.setChecked(True)
  1235. self.ui.act_canvas_show_internal.blockSignals(False)
  1236. self.ui.act_canvas_show_external.blockSignals(False)
  1237. self.slot_canvasRefresh()
  1238. @pyqtSlot()
  1239. def slot_canvasArrange(self):
  1240. patchcanvas.arrange()
  1241. @pyqtSlot()
  1242. def slot_canvasRefresh(self):
  1243. patchcanvas.clear()
  1244. if self.host.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK and self.host.isPlugin:
  1245. return
  1246. if self.host.is_engine_running():
  1247. self.host.patchbay_refresh(self.fExternalPatchbay)
  1248. self.updateMiniCanvasLater()
  1249. @pyqtSlot()
  1250. def slot_canvasZoomFit(self):
  1251. self.scene.zoom_fit()
  1252. @pyqtSlot()
  1253. def slot_canvasZoomIn(self):
  1254. self.scene.zoom_in()
  1255. @pyqtSlot()
  1256. def slot_canvasZoomOut(self):
  1257. self.scene.zoom_out()
  1258. @pyqtSlot()
  1259. def slot_canvasZoomReset(self):
  1260. self.scene.zoom_reset()
  1261. def _canvasImageRender(self, zoom = 1.0):
  1262. image = QImage(self.scene.width()*zoom, self.scene.height()*zoom, QImage.Format_RGB32)
  1263. painter = QPainter(image)
  1264. painter.save()
  1265. painter.setRenderHints(painter.renderHints() | QPainter.Antialiasing | QPainter.TextAntialiasing)
  1266. self.scene.clearSelection()
  1267. self.scene.render(painter)
  1268. painter.restore()
  1269. del painter
  1270. return image
  1271. def _canvasImageWrite(self, iw: QImageWriter, imgFormat: bytes, image: QImage):
  1272. iw.setFormat(imgFormat)
  1273. iw.setCompression(-1)
  1274. if QT_VERSION >= 0x50500:
  1275. iw.setOptimizedWrite(True)
  1276. iw.write(image)
  1277. @pyqtSlot()
  1278. def slot_canvasSaveImage(self):
  1279. if self.fProjectFilename:
  1280. dir = QFileInfo(self.fProjectFilename).absoluteDir().absolutePath()
  1281. else:
  1282. dir = self.fSavedSettings[CARLA_KEY_MAIN_PROJECT_FOLDER]
  1283. fileDialog = QFileDialog(self)
  1284. fileDialog.setAcceptMode(QFileDialog.AcceptSave)
  1285. fileDialog.setDirectory(dir)
  1286. fileDialog.setFileMode(QFileDialog.AnyFile)
  1287. fileDialog.setMimeTypeFilters(("image/png", "image/jpeg"))
  1288. fileDialog.setNameFilter(self.tr("Images (*.png *.jpg)"))
  1289. fileDialog.setOptions(QFileDialog.DontUseCustomDirectoryIcons)
  1290. fileDialog.setWindowTitle(self.tr("Save Image"))
  1291. ok = fileDialog.exec_()
  1292. if not ok:
  1293. return
  1294. newPath = fileDialog.selectedFiles()
  1295. if len(newPath) != 1:
  1296. return
  1297. newPath = newPath[0]
  1298. if QT_VERSION >= 0x50900:
  1299. if fileDialog.selectedMimeTypeFilter() == "image/jpeg":
  1300. imgFormat = b"JPG"
  1301. else:
  1302. imgFormat = b"PNG"
  1303. else:
  1304. if newPath.lower().endswith((".jpg", ".jpeg")):
  1305. imgFormat = b"JPG"
  1306. else:
  1307. imgFormat = b"PNG"
  1308. sender = self.sender()
  1309. if sender == self.ui.act_canvas_save_image_2x:
  1310. zoom = 2.0
  1311. elif sender == self.ui.act_canvas_save_image_4x:
  1312. zoom = 4.0
  1313. else:
  1314. zoom = 1.0
  1315. image = self._canvasImageRender(zoom)
  1316. iw = QImageWriter(newPath)
  1317. self._canvasImageWrite(iw, imgFormat, image)
  1318. @pyqtSlot()
  1319. def slot_canvasCopyToClipboard(self):
  1320. buffer = QBuffer()
  1321. buffer.open(QIODevice.WriteOnly)
  1322. image = self._canvasImageRender()
  1323. iw = QImageWriter(buffer, b"PNG")
  1324. self._canvasImageWrite(iw, b"PNG", image)
  1325. buffer.close()
  1326. mimeData = QMimeData()
  1327. mimeData.setData("image/png", buffer.buffer());
  1328. QApplication.clipboard().setMimeData(mimeData)
  1329. # --------------------------------------------------------------------------------------------------------
  1330. # Canvas (canvas callbacks)
  1331. @pyqtSlot()
  1332. def slot_canvasSelectionChanged(self):
  1333. self.updateMiniCanvasLater()
  1334. @pyqtSlot(float)
  1335. def slot_canvasScaleChanged(self, scale):
  1336. self.ui.miniCanvasPreview.setViewScale(scale)
  1337. @pyqtSlot(list)
  1338. def slot_canvasPluginSelected(self, pluginList):
  1339. self.ui.keyboard.allNotesOff(False)
  1340. self.ui.scrollArea.setEnabled(len(pluginList) != 0) # and self.fPluginCount > 0
  1341. self.fSelectedPlugins = pluginList
  1342. # --------------------------------------------------------------------------------------------------------
  1343. # Canvas (host callbacks)
  1344. @pyqtSlot(int, int, int, str)
  1345. def slot_handlePatchbayClientAddedCallback(self, clientId, clientIcon, pluginId, clientName):
  1346. pcSplit = patchcanvas.SPLIT_UNDEF
  1347. pcIcon = patchcanvas.ICON_APPLICATION
  1348. if clientIcon == PATCHBAY_ICON_PLUGIN:
  1349. pcIcon = patchcanvas.ICON_PLUGIN
  1350. if clientIcon == PATCHBAY_ICON_HARDWARE:
  1351. pcIcon = patchcanvas.ICON_HARDWARE
  1352. elif clientIcon == PATCHBAY_ICON_CARLA:
  1353. pass
  1354. elif clientIcon == PATCHBAY_ICON_DISTRHO:
  1355. pcIcon = patchcanvas.ICON_DISTRHO
  1356. elif clientIcon == PATCHBAY_ICON_FILE:
  1357. pcIcon = patchcanvas.ICON_FILE
  1358. patchcanvas.addGroup(clientId, clientName, pcSplit, pcIcon)
  1359. self.updateMiniCanvasLater()
  1360. if pluginId < 0:
  1361. return
  1362. if pluginId >= self.fPluginCount and pluginId != MAIN_CARLA_PLUGIN_ID:
  1363. print("Error mapping plugin to canvas client:", clientName)
  1364. return
  1365. if pluginId == MAIN_CARLA_PLUGIN_ID:
  1366. hasCustomUI = False
  1367. hasInlineDisplay = False
  1368. else:
  1369. hints = self.host.get_plugin_info(pluginId)['hints']
  1370. hasCustomUI = bool(hints & PLUGIN_HAS_CUSTOM_UI)
  1371. hasInlineDisplay = bool(hints & PLUGIN_HAS_INLINE_DISPLAY)
  1372. patchcanvas.setGroupAsPlugin(clientId, pluginId, hasCustomUI, hasInlineDisplay)
  1373. @pyqtSlot(int)
  1374. def slot_handlePatchbayClientRemovedCallback(self, clientId):
  1375. patchcanvas.removeGroup(clientId)
  1376. self.updateMiniCanvasLater()
  1377. @pyqtSlot(int, str)
  1378. def slot_handlePatchbayClientRenamedCallback(self, clientId, newClientName):
  1379. patchcanvas.renameGroup(clientId, newClientName)
  1380. self.updateMiniCanvasLater()
  1381. @pyqtSlot(int, int, int)
  1382. def slot_handlePatchbayClientDataChangedCallback(self, clientId, clientIcon, pluginId):
  1383. pcIcon = patchcanvas.ICON_APPLICATION
  1384. if clientIcon == PATCHBAY_ICON_PLUGIN:
  1385. pcIcon = patchcanvas.ICON_PLUGIN
  1386. if clientIcon == PATCHBAY_ICON_HARDWARE:
  1387. pcIcon = patchcanvas.ICON_HARDWARE
  1388. elif clientIcon == PATCHBAY_ICON_CARLA:
  1389. pass
  1390. elif clientIcon == PATCHBAY_ICON_DISTRHO:
  1391. pcIcon = patchcanvas.ICON_DISTRHO
  1392. elif clientIcon == PATCHBAY_ICON_FILE:
  1393. pcIcon = patchcanvas.ICON_FILE
  1394. patchcanvas.setGroupIcon(clientId, pcIcon)
  1395. self.updateMiniCanvasLater()
  1396. if pluginId < 0:
  1397. return
  1398. if pluginId >= self.fPluginCount and pluginId != MAIN_CARLA_PLUGIN_ID:
  1399. print("sorry, can't map this plugin to canvas client", pluginId, self.fPluginCount)
  1400. return
  1401. if pluginId == MAIN_CARLA_PLUGIN_ID:
  1402. hasCustomUI = False
  1403. hasInlineDisplay = False
  1404. else:
  1405. hints = self.host.get_plugin_info(pluginId)['hints']
  1406. hasCustomUI = bool(hints & PLUGIN_HAS_CUSTOM_UI)
  1407. hasInlineDisplay = bool(hints & PLUGIN_HAS_INLINE_DISPLAY)
  1408. patchcanvas.setGroupAsPlugin(clientId, pluginId, hasCustomUI, hasInlineDisplay)
  1409. @pyqtSlot(int, int, int, int, int)
  1410. def slot_handlePatchbayClientPositionChangedCallback(self, clientId, x1, y1, x2, y2):
  1411. if (x1 != 0 and x2 != 0) or (y1 != 0 and y2 != 0):
  1412. patchcanvas.splitGroup(clientId)
  1413. else:
  1414. patchcanvas.joinGroup(clientId)
  1415. patchcanvas.setGroupPosFull(clientId, x1, y1, x2, y2)
  1416. self.updateMiniCanvasLater()
  1417. @pyqtSlot(int, int, int, int, str)
  1418. def slot_handlePatchbayPortAddedCallback(self, clientId, portId, portFlags, portGroupId, portName):
  1419. if portFlags & PATCHBAY_PORT_IS_INPUT:
  1420. portMode = patchcanvas.PORT_MODE_INPUT
  1421. else:
  1422. portMode = patchcanvas.PORT_MODE_OUTPUT
  1423. if portFlags & PATCHBAY_PORT_TYPE_AUDIO:
  1424. portType = patchcanvas.PORT_TYPE_AUDIO_JACK
  1425. isAlternate = False
  1426. elif portFlags & PATCHBAY_PORT_TYPE_CV:
  1427. portType = patchcanvas.PORT_TYPE_PARAMETER
  1428. isAlternate = False
  1429. elif portFlags & PATCHBAY_PORT_TYPE_MIDI:
  1430. portType = patchcanvas.PORT_TYPE_MIDI_JACK
  1431. isAlternate = False
  1432. else:
  1433. portType = patchcanvas.PORT_TYPE_NULL
  1434. isAlternate = False
  1435. patchcanvas.addPort(clientId, portId, portName, portMode, portType, isAlternate)
  1436. self.updateMiniCanvasLater()
  1437. @pyqtSlot(int, int)
  1438. def slot_handlePatchbayPortRemovedCallback(self, groupId, portId):
  1439. patchcanvas.removePort(groupId, portId)
  1440. self.updateMiniCanvasLater()
  1441. @pyqtSlot(int, int, int, int, str)
  1442. def slot_handlePatchbayPortChangedCallback(self, groupId, portId, portFlags, portGroupId, newPortName):
  1443. patchcanvas.renamePort(groupId, portId, newPortName)
  1444. self.updateMiniCanvasLater()
  1445. @pyqtSlot(int, int, int, str)
  1446. def slot_handlePatchbayPortGroupAddedCallback(self, groupId, portId, portGroupId, newPortName):
  1447. # TODO
  1448. pass
  1449. @pyqtSlot(int, int)
  1450. def slot_handlePatchbayPortGroupRemovedCallback(self, groupId, portId):
  1451. # TODO
  1452. pass
  1453. @pyqtSlot(int, int, int, str)
  1454. def slot_handlePatchbayPortGroupChangedCallback(self, groupId, portId, portGroupId, newPortName):
  1455. # TODO
  1456. pass
  1457. @pyqtSlot(int, int, int, int, int)
  1458. def slot_handlePatchbayConnectionAddedCallback(self, connectionId, groupOutId, portOutId, groupInId, portInId):
  1459. patchcanvas.connectPorts(connectionId, groupOutId, portOutId, groupInId, portInId)
  1460. self.updateMiniCanvasLater()
  1461. @pyqtSlot(int, int, int)
  1462. def slot_handlePatchbayConnectionRemovedCallback(self, connectionId, portOutId, portInId):
  1463. patchcanvas.disconnectPorts(connectionId)
  1464. self.updateMiniCanvasLater()
  1465. # --------------------------------------------------------------------------------------------------------
  1466. # Settings
  1467. def saveSettings(self):
  1468. settings = QSafeSettings()
  1469. settings.setValue("Geometry", self.saveGeometry())
  1470. settings.setValue("ShowToolbar", self.ui.toolBar.isEnabled())
  1471. settings.setValue("ShowSidePanel", self.ui.dockWidget.isEnabled())
  1472. diskFolders = []
  1473. for i in range(self.ui.cb_disk.count()):
  1474. diskFolders.append(self.ui.cb_disk.itemData(i))
  1475. settings.setValue("DiskFolders", diskFolders)
  1476. settings.setValue("LastBPM", self.fLastTransportBPM)
  1477. settings.setValue("ShowMeters", self.ui.act_settings_show_meters.isChecked())
  1478. settings.setValue("ShowKeyboard", self.ui.act_settings_show_keyboard.isChecked())
  1479. settings.setValue("HorizontalScrollBarValue", self.ui.graphicsView.horizontalScrollBar().value())
  1480. settings.setValue("VerticalScrollBarValue", self.ui.graphicsView.verticalScrollBar().value())
  1481. settings.setValue(CARLA_KEY_ENGINE_TRANSPORT_MODE, self.host.transportMode)
  1482. settings.setValue(CARLA_KEY_ENGINE_TRANSPORT_EXTRA, self.host.transportExtra)
  1483. return settings
  1484. def loadSettings(self, firstTime):
  1485. settings = QSafeSettings()
  1486. if firstTime:
  1487. geometry = settings.value("Geometry", QByteArray(), QByteArray)
  1488. if not geometry.isNull():
  1489. self.restoreGeometry(geometry)
  1490. showToolbar = settings.value("ShowToolbar", True, bool)
  1491. self.ui.act_settings_show_toolbar.setChecked(showToolbar)
  1492. self.ui.toolBar.setEnabled(showToolbar)
  1493. self.ui.toolBar.setVisible(showToolbar)
  1494. #if settings.contains("SplitterState"):
  1495. #self.ui.splitter.restoreState(settings.value("SplitterState", b""))
  1496. #else:
  1497. #self.ui.splitter.setSizes([210, 99999])
  1498. showSidePanel = settings.value("ShowSidePanel", True, bool)
  1499. self.ui.act_settings_show_side_panel.setChecked(showSidePanel)
  1500. self.slot_showSidePanel(showSidePanel)
  1501. diskFolders = settings.value("DiskFolders", [HOME], list)
  1502. self.ui.cb_disk.setItemData(0, HOME)
  1503. for i in range(len(diskFolders)):
  1504. if i == 0: continue
  1505. folder = diskFolders[i]
  1506. self.ui.cb_disk.addItem(os.path.basename(folder), folder)
  1507. #if MACOS and not settings.value(CARLA_KEY_MAIN_USE_PRO_THEME, True, bool):
  1508. # self.setUnifiedTitleAndToolBarOnMac(True)
  1509. showMeters = settings.value("ShowMeters", True, bool)
  1510. self.ui.act_settings_show_meters.setChecked(showMeters)
  1511. self.ui.peak_in.setVisible(showMeters)
  1512. self.ui.peak_out.setVisible(showMeters)
  1513. showKeyboard = settings.value("ShowKeyboard", True, bool)
  1514. self.ui.act_settings_show_keyboard.setChecked(showKeyboard)
  1515. self.ui.scrollArea.setVisible(showKeyboard)
  1516. settingsDBf = QSafeSettings("falkTX", "CarlaDatabase2")
  1517. self.fFavoritePlugins = settingsDBf.value("PluginDatabase/Favorites", [], list)
  1518. QTimer.singleShot(100, self.slot_restoreCanvasScrollbarValues)
  1519. # TODO - complete this
  1520. oldSettings = self.fSavedSettings
  1521. self.fSavedSettings = {
  1522. CARLA_KEY_MAIN_PROJECT_FOLDER: settings.value(CARLA_KEY_MAIN_PROJECT_FOLDER, CARLA_DEFAULT_MAIN_PROJECT_FOLDER, str),
  1523. CARLA_KEY_MAIN_CONFIRM_EXIT: settings.value(CARLA_KEY_MAIN_CONFIRM_EXIT, CARLA_DEFAULT_MAIN_CONFIRM_EXIT, bool),
  1524. CARLA_KEY_MAIN_CLASSIC_SKIN: settings.value(CARLA_KEY_MAIN_CLASSIC_SKIN, CARLA_DEFAULT_MAIN_CLASSIC_SKIN, bool),
  1525. CARLA_KEY_MAIN_REFRESH_INTERVAL: settings.value(CARLA_KEY_MAIN_REFRESH_INTERVAL, CARLA_DEFAULT_MAIN_REFRESH_INTERVAL, int),
  1526. CARLA_KEY_MAIN_SYSTEM_ICONS: settings.value(CARLA_KEY_MAIN_SYSTEM_ICONS, CARLA_DEFAULT_MAIN_SYSTEM_ICONS, bool),
  1527. CARLA_KEY_MAIN_EXPERIMENTAL: settings.value(CARLA_KEY_MAIN_EXPERIMENTAL, CARLA_DEFAULT_MAIN_EXPERIMENTAL, bool),
  1528. CARLA_KEY_CANVAS_THEME: settings.value(CARLA_KEY_CANVAS_THEME, CARLA_DEFAULT_CANVAS_THEME, str),
  1529. CARLA_KEY_CANVAS_SIZE: settings.value(CARLA_KEY_CANVAS_SIZE, CARLA_DEFAULT_CANVAS_SIZE, str),
  1530. CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS: settings.value(CARLA_KEY_CANVAS_AUTO_HIDE_GROUPS, CARLA_DEFAULT_CANVAS_AUTO_HIDE_GROUPS, bool),
  1531. CARLA_KEY_CANVAS_AUTO_SELECT_ITEMS: settings.value(CARLA_KEY_CANVAS_AUTO_SELECT_ITEMS, CARLA_DEFAULT_CANVAS_AUTO_SELECT_ITEMS, bool),
  1532. CARLA_KEY_CANVAS_USE_BEZIER_LINES: settings.value(CARLA_KEY_CANVAS_USE_BEZIER_LINES, CARLA_DEFAULT_CANVAS_USE_BEZIER_LINES, bool),
  1533. CARLA_KEY_CANVAS_EYE_CANDY: settings.value(CARLA_KEY_CANVAS_EYE_CANDY, CARLA_DEFAULT_CANVAS_EYE_CANDY, bool),
  1534. CARLA_KEY_CANVAS_FANCY_EYE_CANDY: settings.value(CARLA_KEY_CANVAS_FANCY_EYE_CANDY, CARLA_DEFAULT_CANVAS_FANCY_EYE_CANDY, bool),
  1535. CARLA_KEY_CANVAS_USE_OPENGL: settings.value(CARLA_KEY_CANVAS_USE_OPENGL, CARLA_DEFAULT_CANVAS_USE_OPENGL, bool),
  1536. CARLA_KEY_CANVAS_ANTIALIASING: settings.value(CARLA_KEY_CANVAS_ANTIALIASING, CARLA_DEFAULT_CANVAS_ANTIALIASING, int),
  1537. CARLA_KEY_CANVAS_HQ_ANTIALIASING: settings.value(CARLA_KEY_CANVAS_HQ_ANTIALIASING, CARLA_DEFAULT_CANVAS_HQ_ANTIALIASING, bool),
  1538. CARLA_KEY_CANVAS_FULL_REPAINTS: settings.value(CARLA_KEY_CANVAS_FULL_REPAINTS, CARLA_DEFAULT_CANVAS_FULL_REPAINTS, bool),
  1539. CARLA_KEY_CUSTOM_PAINTING: (settings.value(CARLA_KEY_MAIN_USE_PRO_THEME, True, bool) and
  1540. settings.value(CARLA_KEY_MAIN_PRO_THEME_COLOR, "Black", str).lower() == "black"),
  1541. }
  1542. if not self.host.isControl:
  1543. self.fSavedSettings[CARLA_KEY_CANVAS_INLINE_DISPLAYS] = settings.value(CARLA_KEY_CANVAS_INLINE_DISPLAYS, CARLA_DEFAULT_CANVAS_INLINE_DISPLAYS, bool)
  1544. else:
  1545. self.fSavedSettings[CARLA_KEY_CANVAS_INLINE_DISPLAYS] = False
  1546. settings2 = QSafeSettings("falkTX", "Carla2")
  1547. if self.host.experimental:
  1548. visible = settings2.value(CARLA_KEY_EXPERIMENTAL_JACK_APPS, CARLA_DEFAULT_EXPERIMENTAL_JACK_APPS, bool)
  1549. self.ui.act_plugin_add_jack.setVisible(visible)
  1550. else:
  1551. self.ui.act_plugin_add_jack.setVisible(False)
  1552. self.fMiniCanvasUpdateTimeout = 1000 if self.fSavedSettings[CARLA_KEY_CANVAS_FANCY_EYE_CANDY] else 0
  1553. setEngineSettings(self.host)
  1554. self.restartTimersIfNeeded()
  1555. if oldSettings.get(CARLA_KEY_MAIN_CLASSIC_SKIN, None) not in (self.fSavedSettings[CARLA_KEY_MAIN_CLASSIC_SKIN], None):
  1556. newSkin = "classic" if self.fSavedSettings[CARLA_KEY_MAIN_CLASSIC_SKIN] else None
  1557. for pitem in self.fPluginList:
  1558. if pitem is None:
  1559. continue
  1560. pitem.recreateWidget(newSkin = newSkin)
  1561. return settings
  1562. # --------------------------------------------------------------------------------------------------------
  1563. # Settings (helpers)
  1564. def enableTransport(self, enabled):
  1565. self.ui.group_transport_controls.setEnabled(enabled)
  1566. self.ui.group_transport_settings.setEnabled(enabled)
  1567. @pyqtSlot()
  1568. def slot_restoreCanvasScrollbarValues(self):
  1569. settings = QSafeSettings()
  1570. horiz = settings.value("HorizontalScrollBarValue", int(self.ui.graphicsView.horizontalScrollBar().maximum()/2), int)
  1571. vertc = settings.value("VerticalScrollBarValue", int(self.ui.graphicsView.verticalScrollBar().maximum()/2), int)
  1572. self.ui.graphicsView.horizontalScrollBar().setValue(horiz)
  1573. self.ui.graphicsView.verticalScrollBar().setValue(vertc)
  1574. # --------------------------------------------------------------------------------------------------------
  1575. # Settings (menu actions)
  1576. @pyqtSlot(bool)
  1577. def slot_showSidePanel(self, yesNo):
  1578. self.ui.dockWidget.setEnabled(yesNo)
  1579. self.ui.dockWidget.setVisible(yesNo)
  1580. @pyqtSlot(bool)
  1581. def slot_showToolbar(self, yesNo):
  1582. self.ui.toolBar.setEnabled(yesNo)
  1583. self.ui.toolBar.setVisible(yesNo)
  1584. @pyqtSlot(bool)
  1585. def slot_showCanvasMeters(self, yesNo):
  1586. self.ui.peak_in.setVisible(yesNo)
  1587. self.ui.peak_out.setVisible(yesNo)
  1588. QTimer.singleShot(0, self.slot_miniCanvasCheckAll)
  1589. @pyqtSlot(bool)
  1590. def slot_showCanvasKeyboard(self, yesNo):
  1591. self.ui.scrollArea.setVisible(yesNo)
  1592. QTimer.singleShot(0, self.slot_miniCanvasCheckAll)
  1593. @pyqtSlot()
  1594. def slot_configureCarla(self):
  1595. dialog = CarlaSettingsW(self.fParentOrSelf, self.host, True, hasGL)
  1596. if not dialog.exec_():
  1597. return
  1598. self.loadSettings(False)
  1599. if self.fWithCanvas:
  1600. patchcanvas.clear()
  1601. self.setupCanvas()
  1602. self.slot_miniCanvasCheckAll()
  1603. if self.host.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK and self.host.isPlugin:
  1604. pass
  1605. elif self.host.is_engine_running():
  1606. self.host.patchbay_refresh(self.fExternalPatchbay)
  1607. # --------------------------------------------------------------------------------------------------------
  1608. # About (menu actions)
  1609. @pyqtSlot()
  1610. def slot_aboutCarla(self):
  1611. CarlaAboutW(self.fParentOrSelf, self.host).exec_()
  1612. @pyqtSlot()
  1613. def slot_aboutJuce(self):
  1614. JuceAboutW(self.fParentOrSelf).exec_()
  1615. @pyqtSlot()
  1616. def slot_aboutQt(self):
  1617. QApplication.instance().aboutQt()
  1618. # --------------------------------------------------------------------------------------------------------
  1619. # Disk (menu actions)
  1620. @pyqtSlot(int)
  1621. def slot_diskFolderChanged(self, index):
  1622. if index < 0:
  1623. return
  1624. elif index == 0:
  1625. filename = HOME
  1626. self.ui.b_disk_remove.setEnabled(False)
  1627. else:
  1628. filename = self.ui.cb_disk.itemData(index)
  1629. self.ui.b_disk_remove.setEnabled(True)
  1630. self.fDirModel.setRootPath(filename)
  1631. self.ui.fileTreeView.setRootIndex(self.fDirModel.index(filename))
  1632. @pyqtSlot()
  1633. def slot_diskFolderAdd(self):
  1634. newPath = QFileDialog.getExistingDirectory(self, self.tr("New Folder"), "", QFileDialog.ShowDirsOnly)
  1635. if newPath:
  1636. if newPath[-1] == os.sep:
  1637. newPath = newPath[:-1]
  1638. self.ui.cb_disk.addItem(os.path.basename(newPath), newPath)
  1639. self.ui.cb_disk.setCurrentIndex(self.ui.cb_disk.count()-1)
  1640. self.ui.b_disk_remove.setEnabled(True)
  1641. @pyqtSlot()
  1642. def slot_diskFolderRemove(self):
  1643. index = self.ui.cb_disk.currentIndex()
  1644. if index <= 0:
  1645. return
  1646. self.ui.cb_disk.removeItem(index)
  1647. if self.ui.cb_disk.currentIndex() == 0:
  1648. self.ui.b_disk_remove.setEnabled(False)
  1649. @pyqtSlot(QModelIndex)
  1650. def slot_fileTreeDoubleClicked(self, modelIndex):
  1651. filename = self.fDirModel.filePath(modelIndex)
  1652. if not self.ui.listWidget.isDragUrlValid(filename):
  1653. return
  1654. if not self.host.load_file(filename):
  1655. CustomMessageBox(self, QMessageBox.Critical, self.tr("Error"),
  1656. self.tr("Failed to load file"),
  1657. self.host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  1658. return
  1659. if filename.endswith(".carxp"):
  1660. self.loadExternalCanvasGroupPositionsIfNeeded(filename)
  1661. # --------------------------------------------------------------------------------------------------------
  1662. # Transport
  1663. def refreshTransport(self, forced = False):
  1664. if not self.ui.l_transport_time.isVisible():
  1665. return
  1666. if self.fSampleRate == 0.0 or not self.host.is_engine_running():
  1667. return
  1668. timeInfo = self.host.get_transport_info()
  1669. playing = timeInfo['playing']
  1670. frame = timeInfo['frame']
  1671. bpm = timeInfo['bpm']
  1672. if playing != self.fLastTransportState or forced:
  1673. if playing:
  1674. if self.fSavedSettings[CARLA_KEY_MAIN_SYSTEM_ICONS]:
  1675. icon = getIcon('media-playback-pause', 16, 'svgz')
  1676. else:
  1677. icon = QIcon(":/16x16/media-playback-pause.svgz")
  1678. self.ui.b_transport_play.setChecked(True)
  1679. self.ui.b_transport_play.setIcon(icon)
  1680. #self.ui.b_transport_play.setText(self.tr("&Pause"))
  1681. else:
  1682. if self.fSavedSettings[CARLA_KEY_MAIN_SYSTEM_ICONS]:
  1683. icon = getIcon('media-playback-start', 16, 'svgz')
  1684. else:
  1685. icon = QIcon(":/16x16/media-playback-start.svgz")
  1686. self.ui.b_transport_play.setChecked(False)
  1687. self.ui.b_transport_play.setIcon(icon)
  1688. #self.ui.b_play.setText(self.tr("&Play"))
  1689. self.fLastTransportState = playing
  1690. if frame != self.fLastTransportFrame or forced:
  1691. self.fLastTransportFrame = frame
  1692. time = frame / self.fSampleRate
  1693. secs = time % 60
  1694. mins = (time / 60) % 60
  1695. hrs = (time / 3600) % 60
  1696. self.ui.l_transport_time.setText("%02i:%02i:%02i" % (hrs, mins, secs))
  1697. frame1 = frame % 1000
  1698. frame2 = (frame / 1000) % 1000
  1699. frame3 = (frame / 1000000) % 1000
  1700. self.ui.l_transport_frame.setText("%03i'%03i'%03i" % (frame3, frame2, frame1))
  1701. bar = timeInfo['bar']
  1702. beat = timeInfo['beat']
  1703. tick = timeInfo['tick']
  1704. self.ui.l_transport_bbt.setText("%03i|%02i|%04i" % (bar, beat, tick))
  1705. if bpm != self.fLastTransportBPM or forced:
  1706. self.fLastTransportBPM = bpm
  1707. if bpm > 0.0:
  1708. self.ui.dsb_transport_bpm.blockSignals(True)
  1709. self.ui.dsb_transport_bpm.setValue(bpm)
  1710. self.ui.dsb_transport_bpm.blockSignals(False)
  1711. self.ui.dsb_transport_bpm.setStyleSheet("")
  1712. else:
  1713. self.ui.dsb_transport_bpm.setStyleSheet("QDoubleSpinBox { color: palette(mid); }")
  1714. # --------------------------------------------------------------------------------------------------------
  1715. # Transport (menu actions)
  1716. @pyqtSlot(bool)
  1717. def slot_transportPlayPause(self, toggled):
  1718. if self.host.isPlugin or not self.host.is_engine_running():
  1719. return
  1720. if toggled:
  1721. self.host.transport_play()
  1722. else:
  1723. self.host.transport_pause()
  1724. self.refreshTransport()
  1725. @pyqtSlot()
  1726. def slot_transportStop(self):
  1727. if self.host.isPlugin or not self.host.is_engine_running():
  1728. return
  1729. self.host.transport_pause()
  1730. self.host.transport_relocate(0)
  1731. self.refreshTransport()
  1732. @pyqtSlot()
  1733. def slot_transportBackwards(self):
  1734. if self.host.isPlugin or not self.host.is_engine_running():
  1735. return
  1736. newFrame = self.host.get_current_transport_frame() - 100000
  1737. if newFrame < 0:
  1738. newFrame = 0
  1739. self.host.transport_relocate(newFrame)
  1740. @pyqtSlot(float)
  1741. def slot_transportBpmChanged(self, newValue):
  1742. self.host.transport_bpm(newValue)
  1743. @pyqtSlot()
  1744. def slot_transportForwards(self):
  1745. if self.fSampleRate == 0.0 or self.host.isPlugin or not self.host.is_engine_running():
  1746. return
  1747. newFrame = self.host.get_current_transport_frame() + int(self.fSampleRate*2.5)
  1748. self.host.transport_relocate(newFrame)
  1749. @pyqtSlot(bool)
  1750. def slot_transportJackEnabled(self, clicked):
  1751. if not self.host.is_engine_running():
  1752. return
  1753. self.host.transportMode = ENGINE_TRANSPORT_MODE_JACK if clicked else ENGINE_TRANSPORT_MODE_INTERNAL
  1754. self.host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE,
  1755. self.host.transportMode,
  1756. self.host.transportExtra)
  1757. @pyqtSlot(bool)
  1758. def slot_transportLinkEnabled(self, clicked):
  1759. if not self.host.is_engine_running():
  1760. return
  1761. extra = ":link:" if clicked else ""
  1762. self.host.transportExtra = extra
  1763. self.host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE,
  1764. self.host.transportMode,
  1765. self.host.transportExtra)
  1766. # --------------------------------------------------------------------------------------------------------
  1767. # Other
  1768. @pyqtSlot(bool)
  1769. def slot_xrunClear(self):
  1770. self.host.clear_engine_xruns()
  1771. # --------------------------------------------------------------------------------------------------------
  1772. # Canvas scrollbars
  1773. @pyqtSlot(int)
  1774. def slot_horizontalScrollBarChanged(self, value):
  1775. maximum = self.ui.graphicsView.horizontalScrollBar().maximum()
  1776. if maximum == 0:
  1777. xp = 0
  1778. else:
  1779. xp = float(value) / maximum
  1780. self.ui.miniCanvasPreview.setViewPosX(xp)
  1781. self.updateCanvasInitialPos()
  1782. @pyqtSlot(int)
  1783. def slot_verticalScrollBarChanged(self, value):
  1784. maximum = self.ui.graphicsView.verticalScrollBar().maximum()
  1785. if maximum == 0:
  1786. yp = 0
  1787. else:
  1788. yp = float(value) / maximum
  1789. self.ui.miniCanvasPreview.setViewPosY(yp)
  1790. self.updateCanvasInitialPos()
  1791. # --------------------------------------------------------------------------------------------------------
  1792. # Canvas keyboard
  1793. @pyqtSlot(int)
  1794. def slot_noteOn(self, note):
  1795. if self.fPluginCount == 0:
  1796. return
  1797. for pluginId in self.fSelectedPlugins:
  1798. self.host.send_midi_note(pluginId, 0, note, 100)
  1799. pedit = self.getPluginEditDialog(pluginId)
  1800. pedit.noteOn(0, note, 100)
  1801. @pyqtSlot(int)
  1802. def slot_noteOff(self, note):
  1803. if self.fPluginCount == 0:
  1804. return
  1805. for pluginId in self.fSelectedPlugins:
  1806. self.host.send_midi_note(pluginId, 0, note, 0)
  1807. pedit = self.getPluginEditDialog(pluginId)
  1808. pedit.noteOff(0, note)
  1809. # --------------------------------------------------------------------------------------------------------
  1810. # Canvas keyboard (host callbacks)
  1811. @pyqtSlot(int, int, int, int)
  1812. def slot_handleNoteOnCallback(self, pluginId, channel, note, velocity):
  1813. if pluginId in self.fSelectedPlugins:
  1814. self.ui.keyboard.sendNoteOn(note, False)
  1815. @pyqtSlot(int, int, int)
  1816. def slot_handleNoteOffCallback(self, pluginId, channel, note):
  1817. if pluginId in self.fSelectedPlugins:
  1818. self.ui.keyboard.sendNoteOff(note, False)
  1819. # --------------------------------------------------------------------------------------------------------
  1820. @pyqtSlot(int)
  1821. def slot_handleUpdateCallback(self, pluginId):
  1822. pitem = self.getPluginItem(pluginId)
  1823. if pitem is None:
  1824. return
  1825. wasCompacted = pitem.isCompacted()
  1826. isCompacted = wasCompacted
  1827. check = self.host.get_custom_data_value(pluginId, CUSTOM_DATA_TYPE_PROPERTY, "CarlaSkinIsCompacted")
  1828. if not check:
  1829. return
  1830. isCompacted = bool(check == "true")
  1831. if wasCompacted == isCompacted:
  1832. return
  1833. pitem.recreateWidget(True)
  1834. # --------------------------------------------------------------------------------------------------------
  1835. # MiniCanvas stuff
  1836. @pyqtSlot()
  1837. def slot_miniCanvasCheckAll(self):
  1838. self.slot_miniCanvasCheckSize()
  1839. self.slot_horizontalScrollBarChanged(self.ui.graphicsView.horizontalScrollBar().value())
  1840. self.slot_verticalScrollBarChanged(self.ui.graphicsView.verticalScrollBar().value())
  1841. @pyqtSlot()
  1842. def slot_miniCanvasCheckSize(self):
  1843. if self.fCanvasWidth == 0 or self.fCanvasHeight == 0:
  1844. return
  1845. currentIndex = self.ui.tabWidget.currentIndex()
  1846. if currentIndex == 1:
  1847. width = self.ui.graphicsView.width()
  1848. height = self.ui.graphicsView.height()
  1849. else:
  1850. self.ui.tabWidget.blockSignals(True)
  1851. self.ui.tabWidget.setCurrentIndex(1)
  1852. width = self.ui.graphicsView.width()
  1853. height = self.ui.graphicsView.height()
  1854. self.ui.tabWidget.setCurrentIndex(currentIndex)
  1855. self.ui.tabWidget.blockSignals(False)
  1856. self.scene.updateLimits()
  1857. self.ui.miniCanvasPreview.setViewSize(float(width)/self.fCanvasWidth, float(height)/self.fCanvasHeight)
  1858. @pyqtSlot(float, float)
  1859. def slot_miniCanvasMoved(self, xp, yp):
  1860. hsb = self.ui.graphicsView.horizontalScrollBar()
  1861. vsb = self.ui.graphicsView.verticalScrollBar()
  1862. hsb.setValue(xp * hsb.maximum())
  1863. vsb.setValue(yp * vsb.maximum())
  1864. self.updateCanvasInitialPos()
  1865. # --------------------------------------------------------------------------------------------------------
  1866. # Logs autoscroll, save and clear
  1867. @pyqtSlot(int)
  1868. def slot_toggleLogAutoscroll(self, checkState):
  1869. self.autoscrollOnNewLog = checkState == Qt.Checked
  1870. if self.autoscrollOnNewLog:
  1871. self.ui.text_logs.verticalScrollBar().setValue(self.ui.text_logs.verticalScrollBar().maximum())
  1872. @pyqtSlot(int)
  1873. def slot_logSliderMoved(self, slider_pos):
  1874. if self.ui.text_logs.verticalScrollBar().hasTracking() or self.autoscrollOnNewLog:
  1875. self.lastLogSliderPos = slider_pos
  1876. else:
  1877. self.ui.text_logs.verticalScrollBar().setValue(self.lastLogSliderPos)
  1878. @pyqtSlot()
  1879. def slot_logButtonsState(self, enabled=True):
  1880. self.ui.logs_clear.setEnabled(enabled)
  1881. self.ui.logs_save.setEnabled(enabled)
  1882. @pyqtSlot()
  1883. def slot_logSave(self):
  1884. filename = os.path.join(self.fSavedSettings[CARLA_KEY_MAIN_PROJECT_FOLDER], 'carla_log.txt')
  1885. filename, _ = QFileDialog.getSaveFileName(self, self.tr("Save Logs"), filename)
  1886. if not filename:
  1887. return
  1888. try:
  1889. with open(filename, "w") as logfile:
  1890. logfile.write(self.ui.text_logs.toPlainText())
  1891. logfile.close()
  1892. except:
  1893. return
  1894. @pyqtSlot()
  1895. def slot_logClear(self):
  1896. self.ui.text_logs.clear()
  1897. self.ui.text_logs.appendPlainText("======= Logs cleared ========")
  1898. self.slot_logButtonsState(False)
  1899. # --------------------------------------------------------------------------------------------------------
  1900. # Timers
  1901. def startTimers(self):
  1902. if self.fIdleTimerFast == 0:
  1903. self.fIdleTimerFast = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL])
  1904. if self.fIdleTimerSlow == 0:
  1905. self.fIdleTimerSlow = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL]*4)
  1906. def restartTimersIfNeeded(self):
  1907. if self.fIdleTimerFast != 0:
  1908. self.killTimer(self.fIdleTimerFast)
  1909. self.fIdleTimerFast = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL])
  1910. if self.fIdleTimerSlow != 0:
  1911. self.killTimer(self.fIdleTimerSlow)
  1912. self.fIdleTimerSlow = self.startTimer(self.fSavedSettings[CARLA_KEY_MAIN_REFRESH_INTERVAL]*4)
  1913. def killTimers(self):
  1914. if self.fIdleTimerFast != 0:
  1915. self.killTimer(self.fIdleTimerFast)
  1916. self.fIdleTimerFast = 0
  1917. if self.fIdleTimerSlow != 0:
  1918. self.killTimer(self.fIdleTimerSlow)
  1919. self.fIdleTimerSlow = 0
  1920. # --------------------------------------------------------------------------------------------------------
  1921. # Misc
  1922. @pyqtSlot(int)
  1923. def slot_tabChanged(self, index):
  1924. if index != 1:
  1925. return
  1926. self.ui.graphicsView.setFocus()
  1927. @pyqtSlot(int)
  1928. def slot_handleReloadAllCallback(self, pluginId):
  1929. if pluginId >= self.fPluginCount:
  1930. return
  1931. pitem = self.fPluginList[pluginId]
  1932. if pitem is None:
  1933. return
  1934. pitem.recreateWidget()
  1935. # --------------------------------------------------------------------------------------------------------
  1936. @pyqtSlot(int, int, str)
  1937. def slot_handleNSMCallback(self, opcode, valueInt, valueStr):
  1938. if opcode == NSM_CALLBACK_INIT:
  1939. return
  1940. # Error
  1941. elif opcode == NSM_CALLBACK_ERROR:
  1942. pass
  1943. # Reply
  1944. elif opcode == NSM_CALLBACK_ANNOUNCE:
  1945. self.fFirstEngineInit = False
  1946. self.fSessionManagerName = valueStr
  1947. self.setProperWindowTitle()
  1948. # If NSM server does not support optional-gui, revert our initial assumptions that it does
  1949. if (valueInt & (1 << 1)) == 0x0:
  1950. self.fWindowCloseHideGui = False
  1951. self.ui.act_file_quit.setText(self.tr("&Quit"))
  1952. QApplication.instance().setQuitOnLastWindowClosed(True)
  1953. self.show()
  1954. # Open
  1955. elif opcode == NSM_CALLBACK_OPEN:
  1956. self.fProjectFilename = QFileInfo(valueStr+".carxp").absoluteFilePath()
  1957. self.setProperWindowTitle()
  1958. self.fCustomStopAction = self.CUSTOM_ACTION_PROJECT_LOAD
  1959. self.slot_engineStop(True)
  1960. return
  1961. # Save
  1962. elif opcode == NSM_CALLBACK_SAVE:
  1963. self.saveProjectNow()
  1964. # Session is Loaded
  1965. elif opcode == NSM_CALLBACK_SESSION_IS_LOADED:
  1966. pass
  1967. # Show Optional Gui
  1968. elif opcode == NSM_CALLBACK_SHOW_OPTIONAL_GUI:
  1969. self.show()
  1970. # Hide Optional Gui
  1971. elif opcode == NSM_CALLBACK_HIDE_OPTIONAL_GUI:
  1972. self.hideForNSM()
  1973. # Set client name
  1974. elif opcode == NSM_CALLBACK_SET_CLIENT_NAME_ID:
  1975. self.fClientName = valueStr
  1976. return
  1977. self.host.nsm_ready(opcode)
  1978. # --------------------------------------------------------------------------------------------------------
  1979. def fixLogText(self, text):
  1980. return text.replace("\x1b[30;1m", "").replace("\x1b[31m", "").replace("\x1b[0m", "")
  1981. @pyqtSlot(int, int, int, int, float, str)
  1982. def slot_handleDebugCallback(self, pluginId, value1, value2, value3, valuef, valueStr):
  1983. self.ui.text_logs.appendPlainText(self.fixLogText(valueStr))
  1984. @pyqtSlot(str)
  1985. def slot_handleInfoCallback(self, info):
  1986. QMessageBox.information(self, "Information", info)
  1987. @pyqtSlot(str)
  1988. def slot_handleErrorCallback(self, error):
  1989. QMessageBox.critical(self, "Error", error)
  1990. @pyqtSlot()
  1991. def slot_handleQuitCallback(self):
  1992. self.fIsProjectLoading = False
  1993. self.killTimers()
  1994. self.removeAllPlugins()
  1995. self.projectLoadingFinished(False)
  1996. @pyqtSlot(int)
  1997. def slot_handleInlineDisplayRedrawCallback(self, pluginId):
  1998. # FIXME
  1999. if self.fIdleTimerSlow != 0 and self.fIdleTimerFast != 0 and pluginId < self.fPluginCount and not self.fIsProjectLoading:
  2000. patchcanvas.redrawPluginGroup(pluginId)
  2001. # --------------------------------------------------------------------------------------------------------
  2002. @pyqtSlot()
  2003. def slot_handleSIGUSR1(self):
  2004. print("Got SIGUSR1 -> Saving project now")
  2005. self.slot_fileSave()
  2006. @pyqtSlot()
  2007. def slot_handleSIGTERM(self):
  2008. print("Got SIGTERM -> Closing now")
  2009. self.fCustomStopAction = self.CUSTOM_ACTION_APP_CLOSE
  2010. self.close()
  2011. # --------------------------------------------------------------------------------------------------------
  2012. # Internal stuff
  2013. def getExtraPtr(self, plugin):
  2014. ptype = plugin['type']
  2015. if ptype == PLUGIN_LADSPA:
  2016. uniqueId = plugin['uniqueId']
  2017. self.maybeLoadRDFs()
  2018. for rdfItem in self.fLadspaRdfList:
  2019. if rdfItem.UniqueID == uniqueId:
  2020. return pointer(rdfItem)
  2021. elif ptype == PLUGIN_SF2:
  2022. if plugin['name'].lower().endswith(" (16 outputs)"):
  2023. return self._true
  2024. return None
  2025. def maybeLoadRDFs(self):
  2026. if not self.fLadspaRdfNeedsUpdate:
  2027. return
  2028. self.fLadspaRdfNeedsUpdate = False
  2029. self.fLadspaRdfList = []
  2030. if not haveLRDF:
  2031. return
  2032. settingsDir = os.path.join(HOME, ".config", "falkTX")
  2033. frLadspaFile = os.path.join(settingsDir, "ladspa_rdf.db")
  2034. if os.path.exists(frLadspaFile):
  2035. frLadspa = open(frLadspaFile, 'r')
  2036. try:
  2037. self.fLadspaRdfList = ladspa_rdf.get_c_ladspa_rdfs(json.load(frLadspa))
  2038. except:
  2039. pass
  2040. frLadspa.close()
  2041. # --------------------------------------------------------------------------------------------------------
  2042. def getPluginCount(self):
  2043. return self.fPluginCount
  2044. def getPluginItem(self, pluginId):
  2045. if pluginId >= self.fPluginCount:
  2046. return None
  2047. pitem = self.fPluginList[pluginId]
  2048. if pitem is None:
  2049. return None
  2050. #if False:
  2051. #return CarlaRackItem(self, 0, False)
  2052. return pitem
  2053. def getPluginEditDialog(self, pluginId):
  2054. if pluginId >= self.fPluginCount:
  2055. return None
  2056. pitem = self.fPluginList[pluginId]
  2057. if pitem is None:
  2058. return None
  2059. if False:
  2060. return PluginEdit(self, self.host, 0)
  2061. return pitem.getEditDialog()
  2062. def getPluginSlotWidget(self, pluginId):
  2063. if pluginId >= self.fPluginCount:
  2064. return None
  2065. pitem = self.fPluginList[pluginId]
  2066. if pitem is None:
  2067. return None
  2068. #if False:
  2069. #return AbstractPluginSlot()
  2070. return pitem.getWidget()
  2071. # --------------------------------------------------------------------------------------------------------
  2072. def waitForPendingEvents(self):
  2073. pass
  2074. # --------------------------------------------------------------------------------------------------------
  2075. # show/hide event
  2076. def showEvent(self, event):
  2077. self.getAndRefreshRuntimeInfo()
  2078. self.refreshTransport(True)
  2079. QMainWindow.showEvent(self, event)
  2080. if QT_VERSION >= 0x50600:
  2081. self.host.set_engine_option(ENGINE_OPTION_FRONTEND_UI_SCALE, int(self.devicePixelRatioF() * 1000), "")
  2082. print("Frontend pixel ratio is", self.devicePixelRatioF())
  2083. # set our gui as parent for all plugins UIs
  2084. if self.host.manageUIs and not self.host.isControl:
  2085. if MACOS:
  2086. nsViewPtr = int(self.winId())
  2087. winIdStr = "%x" % gCarla.utils.cocoa_get_window(nsViewPtr)
  2088. else:
  2089. winIdStr = "%x" % int(self.winId())
  2090. self.host.set_engine_option(ENGINE_OPTION_FRONTEND_WIN_ID, 0, winIdStr)
  2091. def hideEvent(self, event):
  2092. # disable parent
  2093. if not self.host.isControl:
  2094. self.host.set_engine_option(ENGINE_OPTION_FRONTEND_WIN_ID, 0, "0")
  2095. QMainWindow.hideEvent(self, event)
  2096. # --------------------------------------------------------------------------------------------------------
  2097. # resize event
  2098. def resizeEvent(self, event):
  2099. QMainWindow.resizeEvent(self, event)
  2100. if self.fWithCanvas:
  2101. self.slot_miniCanvasCheckSize()
  2102. # --------------------------------------------------------------------------------------------------------
  2103. # timer event
  2104. def refreshRuntimeInfo(self, load, xruns):
  2105. txt1 = str(xruns) if (xruns >= 0) else "--"
  2106. txt2 = "" if (xruns == 1) else "s"
  2107. self.ui.b_xruns.setText("%s Xrun%s" % (txt1, txt2))
  2108. self.ui.pb_dsp_load.setValue(int(load))
  2109. def getAndRefreshRuntimeInfo(self):
  2110. if not self.ui.pb_dsp_load.isVisible():
  2111. return
  2112. if not self.host.is_engine_running():
  2113. return
  2114. info = self.host.get_runtime_engine_info()
  2115. self.refreshRuntimeInfo(info['load'], info['xruns'])
  2116. def idleFast(self):
  2117. self.host.engine_idle()
  2118. self.refreshTransport()
  2119. if self.fPluginCount == 0 or self.fCurrentlyRemovingAllPlugins:
  2120. return
  2121. for pitem in self.fPluginList:
  2122. if pitem is None:
  2123. break
  2124. pitem.getWidget().idleFast()
  2125. for pluginId in self.fSelectedPlugins:
  2126. self.fPeaksCleared = False
  2127. if self.ui.peak_in.isVisible():
  2128. self.ui.peak_in.displayMeter(1, self.host.get_input_peak_value(pluginId, True))
  2129. self.ui.peak_in.displayMeter(2, self.host.get_input_peak_value(pluginId, False))
  2130. if self.ui.peak_out.isVisible():
  2131. self.ui.peak_out.displayMeter(1, self.host.get_output_peak_value(pluginId, True))
  2132. self.ui.peak_out.displayMeter(2, self.host.get_output_peak_value(pluginId, False))
  2133. return
  2134. if self.fPeaksCleared:
  2135. return
  2136. self.fPeaksCleared = True
  2137. self.ui.peak_in.displayMeter(1, 0.0, True)
  2138. self.ui.peak_in.displayMeter(2, 0.0, True)
  2139. self.ui.peak_out.displayMeter(1, 0.0, True)
  2140. self.ui.peak_out.displayMeter(2, 0.0, True)
  2141. def idleSlow(self):
  2142. self.getAndRefreshRuntimeInfo()
  2143. if self.fPluginCount == 0 or self.fCurrentlyRemovingAllPlugins:
  2144. return
  2145. for pitem in self.fPluginList:
  2146. if pitem is None:
  2147. break
  2148. pitem.getWidget().idleSlow()
  2149. def timerEvent(self, event):
  2150. if event.timerId() == self.fIdleTimerFast:
  2151. self.idleFast()
  2152. elif event.timerId() == self.fIdleTimerSlow:
  2153. self.idleSlow()
  2154. QMainWindow.timerEvent(self, event)
  2155. # --------------------------------------------------------------------------------------------------------
  2156. # color/style change event
  2157. def changeEvent(self, event):
  2158. if event.type() in (QEvent.PaletteChange, QEvent.StyleChange):
  2159. self.updateStyle()
  2160. QMainWindow.changeEvent(self, event)
  2161. def updateStyle(self):
  2162. # Rack padding images setup
  2163. rack_imgL = QImage(":/bitmaps/rack_padding_left.png")
  2164. rack_imgR = QImage(":/bitmaps/rack_padding_right.png")
  2165. min_value = 0.07
  2166. if PYQT_VERSION >= 0x50600:
  2167. value_fix = 1.0/(1.0-rack_imgL.scaled(1, 1, Qt.IgnoreAspectRatio, Qt.SmoothTransformation).pixelColor(0,0).blackF())
  2168. else:
  2169. value_fix = 1.5
  2170. rack_pal = self.ui.rack.palette()
  2171. bg_color = rack_pal.window().color()
  2172. fg_color = rack_pal.text().color()
  2173. bg_value = 1.0 - bg_color.blackF()
  2174. if bg_value != 0.0 and bg_value < min_value:
  2175. pad_color = bg_color.lighter(int(100*min_value/bg_value*value_fix))
  2176. else:
  2177. pad_color = QColor.fromHsvF(0.0, 0.0, min_value*value_fix)
  2178. painter = QPainter()
  2179. fillRect = rack_imgL.rect().adjusted(-1,-1,1,1)
  2180. painter.begin(rack_imgL)
  2181. painter.setCompositionMode(QPainter.CompositionMode_Multiply)
  2182. painter.setBrush(pad_color)
  2183. painter.drawRect(fillRect)
  2184. painter.end()
  2185. rack_pixmapL = QPixmap(rack_imgL)
  2186. self.imgL_palette = QPalette()
  2187. self.imgL_palette.setBrush(QPalette.Window, QBrush(rack_pixmapL))
  2188. self.ui.pad_left.setPalette(self.imgL_palette)
  2189. self.ui.pad_left.setAutoFillBackground(True)
  2190. painter.begin(rack_imgR)
  2191. painter.setCompositionMode(QPainter.CompositionMode_Multiply)
  2192. painter.setBrush(pad_color)
  2193. painter.drawRect(fillRect)
  2194. painter.end()
  2195. rack_pixmapR = QPixmap(rack_imgR)
  2196. self.imgR_palette = QPalette()
  2197. self.imgR_palette.setBrush(QPalette.Window, QBrush(rack_pixmapR))
  2198. self.ui.pad_right.setPalette(self.imgR_palette)
  2199. self.ui.pad_right.setAutoFillBackground(True)
  2200. # qt's rgba is actually argb, so convert that
  2201. bg_color_value = bg_color.rgba()
  2202. bg_color_value = ((bg_color_value & 0xffffff) << 8) | (bg_color_value >> 24)
  2203. fg_color_value = fg_color.rgba()
  2204. fg_color_value = ((fg_color_value & 0xffffff) << 8) | (fg_color_value >> 24)
  2205. self.host.set_engine_option(ENGINE_OPTION_FRONTEND_BACKGROUND_COLOR, bg_color_value, "")
  2206. self.host.set_engine_option(ENGINE_OPTION_FRONTEND_FOREGROUND_COLOR, fg_color_value, "")
  2207. # --------------------------------------------------------------------------------------------------------
  2208. # paint event
  2209. #def paintEvent(self, event):
  2210. #QMainWindow.paintEvent(self, event)
  2211. #if MACOS or not self.fSavedSettings[CARLA_KEY_CUSTOM_PAINTING]:
  2212. #return
  2213. #painter = QPainter(self)
  2214. #painter.setBrush(QColor(36, 36, 36))
  2215. #painter.setPen(QColor(62, 62, 62))
  2216. #painter.drawRect(1, self.height()/2, self.width()-3, self.height()-self.height()/2-1)
  2217. # --------------------------------------------------------------------------------------------------------
  2218. # close event
  2219. def shouldIgnoreClose(self):
  2220. if self.host.isControl or self.host.isPlugin:
  2221. return False
  2222. if self.fCustomStopAction == self.CUSTOM_ACTION_APP_CLOSE:
  2223. return False
  2224. if self.fWindowCloseHideGui:
  2225. return False
  2226. if self.fSavedSettings[CARLA_KEY_MAIN_CONFIRM_EXIT]:
  2227. return QMessageBox.question(self, self.tr("Quit"),
  2228. self.tr("Are you sure you want to quit Carla?"),
  2229. QMessageBox.Yes|QMessageBox.No) == QMessageBox.No
  2230. return False
  2231. def closeEvent(self, event):
  2232. if self.shouldIgnoreClose():
  2233. event.ignore()
  2234. return
  2235. if self.fWindowCloseHideGui and self.fCustomStopAction != self.CUSTOM_ACTION_APP_CLOSE:
  2236. self.hideForNSM()
  2237. self.host.nsm_ready(NSM_CALLBACK_HIDE_OPTIONAL_GUI)
  2238. return
  2239. patchcanvas.handleAllPluginsRemoved()
  2240. if MACOS and self.fMacClosingHelper and not (self.host.isControl or self.host.isPlugin):
  2241. self.fCustomStopAction = self.CUSTOM_ACTION_APP_CLOSE
  2242. self.fMacClosingHelper = False
  2243. event.ignore()
  2244. for i in reversed(range(self.fPluginCount)):
  2245. self.host.show_custom_ui(i, False)
  2246. QTimer.singleShot(100, self.close)
  2247. return
  2248. self.killTimers()
  2249. self.saveSettings()
  2250. if self.host.is_engine_running() and not (self.host.isControl or self.host.isPlugin):
  2251. if not self.slot_engineStop(True):
  2252. self.fCustomStopAction = self.CUSTOM_ACTION_APP_CLOSE
  2253. event.ignore()
  2254. return
  2255. QMainWindow.closeEvent(self, event)
  2256. # if we reach this point, fully close ourselves
  2257. gCarla.gui = None
  2258. QApplication.instance().quit()
  2259. # ------------------------------------------------------------------------------------------------
  2260. # Canvas callback
  2261. def canvasCallback(action, value1, value2, valueStr):
  2262. host = gCarla.gui.host
  2263. if gCarla.gui.fCustomStopAction == HostWindow.CUSTOM_ACTION_APP_CLOSE:
  2264. return
  2265. if action == patchcanvas.ACTION_GROUP_INFO:
  2266. pass
  2267. elif action == patchcanvas.ACTION_GROUP_RENAME:
  2268. pass
  2269. elif action == patchcanvas.ACTION_GROUP_SPLIT:
  2270. groupId = value1
  2271. patchcanvas.splitGroup(groupId)
  2272. gCarla.gui.updateMiniCanvasLater()
  2273. elif action == patchcanvas.ACTION_GROUP_JOIN:
  2274. groupId = value1
  2275. patchcanvas.joinGroup(groupId)
  2276. gCarla.gui.updateMiniCanvasLater()
  2277. elif action == patchcanvas.ACTION_GROUP_POSITION:
  2278. if gCarla.gui.fIsProjectLoading:
  2279. return
  2280. if not host.is_engine_running():
  2281. return
  2282. groupId = value1
  2283. x1, y1, x2, y2 = tuple(int(i) for i in valueStr.split(":"))
  2284. host.patchbay_set_group_pos(gCarla.gui.fExternalPatchbay, groupId, x1, y1, x2, y2)
  2285. gCarla.gui.updateMiniCanvasLater()
  2286. elif action == patchcanvas.ACTION_PORT_INFO:
  2287. pass
  2288. elif action == patchcanvas.ACTION_PORT_RENAME:
  2289. pass
  2290. elif action == patchcanvas.ACTION_PORTS_CONNECT:
  2291. gOut, pOut, gIn, pIn = tuple(int(i) for i in valueStr.split(":"))
  2292. if not host.patchbay_connect(gCarla.gui.fExternalPatchbay, gOut, pOut, gIn, pIn):
  2293. print("Connection failed:", host.get_last_error())
  2294. elif action == patchcanvas.ACTION_PORTS_DISCONNECT:
  2295. connectionId = value1
  2296. if not host.patchbay_disconnect(gCarla.gui.fExternalPatchbay, connectionId):
  2297. print("Disconnect failed:", host.get_last_error())
  2298. elif action == patchcanvas.ACTION_PLUGIN_CLONE:
  2299. pluginId = value1
  2300. if not host.clone_plugin(pluginId):
  2301. CustomMessageBox(gCarla.gui, QMessageBox.Warning, gCarla.gui.tr("Error"), gCarla.gui.tr("Operation failed"),
  2302. host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  2303. elif action == patchcanvas.ACTION_PLUGIN_EDIT:
  2304. pluginId = value1
  2305. pwidget = gCarla.gui.getPluginSlotWidget(pluginId)
  2306. if pwidget is not None:
  2307. pwidget.showEditDialog()
  2308. elif action == patchcanvas.ACTION_PLUGIN_RENAME:
  2309. pluginId = value1
  2310. pwidget = gCarla.gui.getPluginSlotWidget(pluginId)
  2311. if pwidget is not None:
  2312. pwidget.showRenameDialog()
  2313. elif action == patchcanvas.ACTION_PLUGIN_REPLACE:
  2314. pluginId = value1
  2315. pwidget = gCarla.gui.getPluginSlotWidget(pluginId)
  2316. if pwidget is not None:
  2317. pwidget.showReplaceDialog()
  2318. elif action == patchcanvas.ACTION_PLUGIN_REMOVE:
  2319. pluginId = value1
  2320. if not host.remove_plugin(pluginId):
  2321. CustomMessageBox(gCarla.gui, QMessageBox.Warning, gCarla.gui.tr("Error"), gCarla.gui.tr("Operation failed"),
  2322. host.get_last_error(), QMessageBox.Ok, QMessageBox.Ok)
  2323. elif action == patchcanvas.ACTION_PLUGIN_SHOW_UI:
  2324. pluginId = value1
  2325. pwidget = gCarla.gui.getPluginSlotWidget(pluginId)
  2326. if pwidget is not None:
  2327. pwidget.showCustomUI()
  2328. elif action == patchcanvas.ACTION_BG_RIGHT_CLICK:
  2329. gCarla.gui.slot_showPluginActionsMenu()
  2330. elif action == patchcanvas.ACTION_INLINE_DISPLAY:
  2331. if gCarla.gui.fIsProjectLoading:
  2332. return
  2333. if not host.is_engine_running():
  2334. return
  2335. pluginId = value1
  2336. width, height = [int(v) for v in valueStr.split(":")]
  2337. return host.render_inline_display(pluginId, width, height)
  2338. # ------------------------------------------------------------------------------------------------------------
  2339. # Engine callback
  2340. def engineCallback(host, action, pluginId, value1, value2, value3, valuef, valueStr):
  2341. # kdevelop likes this :)
  2342. if False: host = CarlaHostNull()
  2343. valueStr = charPtrToString(valueStr)
  2344. if action == ENGINE_CALLBACK_ENGINE_STARTED:
  2345. host.processMode = value1
  2346. host.transportMode = value2
  2347. elif action == ENGINE_CALLBACK_PROCESS_MODE_CHANGED:
  2348. host.processMode = value1
  2349. elif action == ENGINE_CALLBACK_TRANSPORT_MODE_CHANGED:
  2350. host.transportMode = value1
  2351. host.transportExtra = valueStr
  2352. if action == ENGINE_CALLBACK_DEBUG:
  2353. host.DebugCallback.emit(pluginId, value1, value2, value3, valuef, valueStr)
  2354. elif action == ENGINE_CALLBACK_PLUGIN_ADDED:
  2355. host.PluginAddedCallback.emit(pluginId, valueStr)
  2356. elif action == ENGINE_CALLBACK_PLUGIN_REMOVED:
  2357. host.PluginRemovedCallback.emit(pluginId)
  2358. elif action == ENGINE_CALLBACK_PLUGIN_RENAMED:
  2359. host.PluginRenamedCallback.emit(pluginId, valueStr)
  2360. elif action == ENGINE_CALLBACK_PLUGIN_UNAVAILABLE:
  2361. host.PluginUnavailableCallback.emit(pluginId, valueStr)
  2362. elif action == ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED:
  2363. host.ParameterValueChangedCallback.emit(pluginId, value1, valuef)
  2364. elif action == ENGINE_CALLBACK_PARAMETER_DEFAULT_CHANGED:
  2365. host.ParameterDefaultChangedCallback.emit(pluginId, value1, valuef)
  2366. elif action == ENGINE_CALLBACK_PARAMETER_MAPPED_CONTROL_INDEX_CHANGED:
  2367. host.ParameterMappedControlIndexChangedCallback.emit(pluginId, value1, value2)
  2368. elif action == ENGINE_CALLBACK_PARAMETER_MAPPED_RANGE_CHANGED:
  2369. minimum, maximum = (float(v) for v in valueStr.split(":", 2))
  2370. host.ParameterMappedRangeChangedCallback.emit(pluginId, value1, minimum, maximum)
  2371. elif action == ENGINE_CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED:
  2372. host.ParameterMidiChannelChangedCallback.emit(pluginId, value1, value2)
  2373. elif action == ENGINE_CALLBACK_PROGRAM_CHANGED:
  2374. host.ProgramChangedCallback.emit(pluginId, value1)
  2375. elif action == ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED:
  2376. host.MidiProgramChangedCallback.emit(pluginId, value1)
  2377. elif action == ENGINE_CALLBACK_OPTION_CHANGED:
  2378. host.OptionChangedCallback.emit(pluginId, value1, bool(value2))
  2379. elif action == ENGINE_CALLBACK_UI_STATE_CHANGED:
  2380. host.UiStateChangedCallback.emit(pluginId, value1)
  2381. elif action == ENGINE_CALLBACK_NOTE_ON:
  2382. host.NoteOnCallback.emit(pluginId, value1, value2, value3)
  2383. elif action == ENGINE_CALLBACK_NOTE_OFF:
  2384. host.NoteOffCallback.emit(pluginId, value1, value2)
  2385. elif action == ENGINE_CALLBACK_UPDATE:
  2386. host.UpdateCallback.emit(pluginId)
  2387. elif action == ENGINE_CALLBACK_RELOAD_INFO:
  2388. host.ReloadInfoCallback.emit(pluginId)
  2389. elif action == ENGINE_CALLBACK_RELOAD_PARAMETERS:
  2390. host.ReloadParametersCallback.emit(pluginId)
  2391. elif action == ENGINE_CALLBACK_RELOAD_PROGRAMS:
  2392. host.ReloadProgramsCallback.emit(pluginId)
  2393. elif action == ENGINE_CALLBACK_RELOAD_ALL:
  2394. host.ReloadAllCallback.emit(pluginId)
  2395. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED:
  2396. host.PatchbayClientAddedCallback.emit(pluginId, value1, value2, valueStr)
  2397. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_REMOVED:
  2398. host.PatchbayClientRemovedCallback.emit(pluginId)
  2399. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_RENAMED:
  2400. host.PatchbayClientRenamedCallback.emit(pluginId, valueStr)
  2401. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_DATA_CHANGED:
  2402. host.PatchbayClientDataChangedCallback.emit(pluginId, value1, value2)
  2403. elif action == ENGINE_CALLBACK_PATCHBAY_CLIENT_POSITION_CHANGED:
  2404. host.PatchbayClientPositionChangedCallback.emit(pluginId, value1, value2, value3, int(round(valuef)))
  2405. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_ADDED:
  2406. host.PatchbayPortAddedCallback.emit(pluginId, value1, value2, value3, valueStr)
  2407. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_REMOVED:
  2408. host.PatchbayPortRemovedCallback.emit(pluginId, value1)
  2409. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_CHANGED:
  2410. host.PatchbayPortChangedCallback.emit(pluginId, value1, value2, value3, valueStr)
  2411. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_GROUP_ADDED:
  2412. host.PatchbayPortGroupAddedCallback.emit(pluginId, value1, value2, valueStr)
  2413. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_GROUP_REMOVED:
  2414. host.PatchbayPortGroupRemovedCallback.emit(pluginId, value1)
  2415. elif action == ENGINE_CALLBACK_PATCHBAY_PORT_GROUP_CHANGED:
  2416. host.PatchbayPortGroupChangedCallback.emit(pluginId, value1, value2, valueStr)
  2417. elif action == ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED:
  2418. gOut, pOut, gIn, pIn = [int(i) for i in valueStr.split(":")] # FIXME
  2419. host.PatchbayConnectionAddedCallback.emit(pluginId, gOut, pOut, gIn, pIn)
  2420. elif action == ENGINE_CALLBACK_PATCHBAY_CONNECTION_REMOVED:
  2421. host.PatchbayConnectionRemovedCallback.emit(pluginId, value1, value2)
  2422. elif action == ENGINE_CALLBACK_ENGINE_STARTED:
  2423. host.EngineStartedCallback.emit(pluginId, value1, value2, value3, valuef, valueStr)
  2424. elif action == ENGINE_CALLBACK_ENGINE_STOPPED:
  2425. host.EngineStoppedCallback.emit()
  2426. elif action == ENGINE_CALLBACK_PROCESS_MODE_CHANGED:
  2427. host.ProcessModeChangedCallback.emit(value1)
  2428. elif action == ENGINE_CALLBACK_TRANSPORT_MODE_CHANGED:
  2429. host.TransportModeChangedCallback.emit(value1, valueStr)
  2430. elif action == ENGINE_CALLBACK_BUFFER_SIZE_CHANGED:
  2431. host.BufferSizeChangedCallback.emit(value1)
  2432. elif action == ENGINE_CALLBACK_SAMPLE_RATE_CHANGED:
  2433. host.SampleRateChangedCallback.emit(valuef)
  2434. elif action == ENGINE_CALLBACK_CANCELABLE_ACTION:
  2435. host.CancelableActionCallback.emit(pluginId, bool(value1 != 0), valueStr)
  2436. elif action == ENGINE_CALLBACK_PROJECT_LOAD_FINISHED:
  2437. host.ProjectLoadFinishedCallback.emit()
  2438. elif action == ENGINE_CALLBACK_NSM:
  2439. host.NSMCallback.emit(value1, value2, valueStr)
  2440. elif action == ENGINE_CALLBACK_IDLE:
  2441. QApplication.processEvents()
  2442. elif action == ENGINE_CALLBACK_INFO:
  2443. host.InfoCallback.emit(valueStr)
  2444. elif action == ENGINE_CALLBACK_ERROR:
  2445. host.ErrorCallback.emit(valueStr)
  2446. elif action == ENGINE_CALLBACK_QUIT:
  2447. host.QuitCallback.emit()
  2448. elif action == ENGINE_CALLBACK_INLINE_DISPLAY_REDRAW:
  2449. host.InlineDisplayRedrawCallback.emit(pluginId)
  2450. else:
  2451. print("unhandled action", action)
  2452. # ------------------------------------------------------------------------------------------------------------
  2453. # File callback
  2454. def fileCallback(ptr, action, isDir, title, filter):
  2455. title = charPtrToString(title)
  2456. filter = charPtrToString(filter)
  2457. if action == FILE_CALLBACK_OPEN:
  2458. ret, ok = QFileDialog.getOpenFileName(gCarla.gui, title, "", filter) #, QFileDialog.ShowDirsOnly if isDir else 0x0)
  2459. elif action == FILE_CALLBACK_SAVE:
  2460. ret, ok = QFileDialog.getSaveFileName(gCarla.gui, title, "", filter, QFileDialog.ShowDirsOnly if isDir else 0x0)
  2461. else:
  2462. ret, ok = ("", "")
  2463. # FIXME use ok value, test if it works as expected
  2464. if not ret:
  2465. return None
  2466. # FIXME
  2467. global fileRet
  2468. fileRet = c_char_p(ret.encode("utf-8"))
  2469. retval = cast(byref(fileRet), POINTER(c_uintptr))
  2470. return retval.contents.value
  2471. # ------------------------------------------------------------------------------------------------------------
  2472. # Init host
  2473. def initHost(initName, libPrefix, isControl, isPlugin, failError, HostClass = None):
  2474. pathBinaries, pathResources = getPaths(libPrefix)
  2475. # --------------------------------------------------------------------------------------------------------
  2476. # Fail if binary dir is not found
  2477. if not os.path.exists(pathBinaries):
  2478. if failError:
  2479. QMessageBox.critical(None, "Error", "Failed to find the carla binaries, cannot continue")
  2480. sys.exit(1)
  2481. return
  2482. # --------------------------------------------------------------------------------------------------------
  2483. # Check if we should open main lib as local or global
  2484. settings = QSafeSettings("falkTX", "Carla2")
  2485. loadGlobal = settings.value(CARLA_KEY_EXPERIMENTAL_LOAD_LIB_GLOBAL, CARLA_DEFAULT_EXPERIMENTAL_LOAD_LIB_GLOBAL, bool)
  2486. # --------------------------------------------------------------------------------------------------------
  2487. # Set Carla library name
  2488. libname = "libcarla_%s2.%s" % ("control" if isControl else "standalone", DLL_EXTENSION)
  2489. libname = os.path.join(pathBinaries, libname)
  2490. utilsname = os.path.join(pathBinaries, "libcarla_utils.%s" % (DLL_EXTENSION))
  2491. # --------------------------------------------------------------------------------------------------------
  2492. # Print info
  2493. if not (gCarla.nogui and isinstance(gCarla.nogui, int)):
  2494. print("Carla %s started, status:" % VERSION)
  2495. print(" Python version: %s" % sys.version.split(" ",1)[0])
  2496. print(" Qt version: %s" % QT_VERSION_STR)
  2497. print(" PyQt version: %s" % PYQT_VERSION_STR)
  2498. print(" Binary dir: %s" % pathBinaries)
  2499. print(" Resources dir: %s" % pathResources)
  2500. # --------------------------------------------------------------------------------------------------------
  2501. # Init host
  2502. if failError:
  2503. # no try
  2504. host = HostClass() if HostClass is not None else CarlaHostQtDLL(libname, loadGlobal)
  2505. else:
  2506. try:
  2507. host = HostClass() if HostClass is not None else CarlaHostQtDLL(libname, loadGlobal)
  2508. except:
  2509. host = CarlaHostQtNull()
  2510. host.isControl = isControl
  2511. host.isPlugin = isPlugin
  2512. host.set_engine_callback(lambda h,a,p,v1,v2,v3,vf,vs: engineCallback(host,a,p,v1,v2,v3,vf,vs))
  2513. host.set_file_callback(fileCallback)
  2514. # If it's a plugin the paths are already set
  2515. if not isPlugin:
  2516. host.pathBinaries = pathBinaries
  2517. host.pathResources = pathResources
  2518. host.set_engine_option(ENGINE_OPTION_PATH_BINARIES, 0, pathBinaries)
  2519. host.set_engine_option(ENGINE_OPTION_PATH_RESOURCES, 0, pathResources)
  2520. if not isControl:
  2521. host.nsmOK = host.nsm_init(os.getpid(), initName)
  2522. # --------------------------------------------------------------------------------------------------------
  2523. # Init utils
  2524. gCarla.utils = CarlaUtils(utilsname)
  2525. gCarla.utils.set_process_name(os.path.basename(initName))
  2526. try:
  2527. sys.stdout.flush()
  2528. except:
  2529. pass
  2530. sys.stdout = CarlaPrint(False)
  2531. sys.stderr = CarlaPrint(True)
  2532. sys.excepthook = sys_excepthook
  2533. # --------------------------------------------------------------------------------------------------------
  2534. # Done
  2535. return host
  2536. # ------------------------------------------------------------------------------------------------------------
  2537. # Load host settings
  2538. def loadHostSettings(host):
  2539. # kdevelop likes this :)
  2540. if False: host = CarlaHostNull()
  2541. settings = QSafeSettings("falkTX", "Carla2")
  2542. host.experimental = settings.value(CARLA_KEY_MAIN_EXPERIMENTAL, CARLA_DEFAULT_MAIN_EXPERIMENTAL, bool)
  2543. host.exportLV2 = settings.value(CARLA_KEY_EXPERIMENTAL_EXPORT_LV2, CARLA_DEFAULT_EXPERIMENTAL_LV2_EXPORT, bool)
  2544. host.manageUIs = settings.value(CARLA_KEY_ENGINE_MANAGE_UIS, CARLA_DEFAULT_MANAGE_UIS, bool)
  2545. host.maxParameters = settings.value(CARLA_KEY_ENGINE_MAX_PARAMETERS, CARLA_DEFAULT_MAX_PARAMETERS, int)
  2546. host.resetXruns = settings.value(CARLA_KEY_ENGINE_RESET_XRUNS, CARLA_DEFAULT_RESET_XRUNS, bool)
  2547. host.forceStereo = settings.value(CARLA_KEY_ENGINE_FORCE_STEREO, CARLA_DEFAULT_FORCE_STEREO, bool)
  2548. host.preferPluginBridges = settings.value(CARLA_KEY_ENGINE_PREFER_PLUGIN_BRIDGES, CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES, bool)
  2549. host.preferUIBridges = settings.value(CARLA_KEY_ENGINE_PREFER_UI_BRIDGES, CARLA_DEFAULT_PREFER_UI_BRIDGES, bool)
  2550. host.preventBadBehaviour = settings.value(CARLA_KEY_EXPERIMENTAL_PREVENT_BAD_BEHAVIOUR, CARLA_DEFAULT_EXPERIMENTAL_PREVENT_BAD_BEHAVIOUR, bool)
  2551. host.showLogs = settings.value(CARLA_KEY_MAIN_SHOW_LOGS, CARLA_DEFAULT_MAIN_SHOW_LOGS, bool) and not WINDOWS
  2552. host.showPluginBridges = settings.value(CARLA_KEY_EXPERIMENTAL_PLUGIN_BRIDGES, CARLA_DEFAULT_EXPERIMENTAL_PLUGIN_BRIDGES, bool)
  2553. host.showWineBridges = settings.value(CARLA_KEY_EXPERIMENTAL_WINE_BRIDGES, CARLA_DEFAULT_EXPERIMENTAL_WINE_BRIDGES, bool)
  2554. host.uiBridgesTimeout = settings.value(CARLA_KEY_ENGINE_UI_BRIDGES_TIMEOUT, CARLA_DEFAULT_UI_BRIDGES_TIMEOUT, int)
  2555. host.uisAlwaysOnTop = settings.value(CARLA_KEY_ENGINE_UIS_ALWAYS_ON_TOP, CARLA_DEFAULT_UIS_ALWAYS_ON_TOP, bool)
  2556. if host.isPlugin:
  2557. return
  2558. host.transportExtra = settings.value(CARLA_KEY_ENGINE_TRANSPORT_EXTRA, "", str)
  2559. # enums
  2560. if host.audioDriverForced is None:
  2561. host.transportMode = settings.value(CARLA_KEY_ENGINE_TRANSPORT_MODE, CARLA_DEFAULT_TRANSPORT_MODE, int)
  2562. if not host.processModeForced:
  2563. host.processMode = settings.value(CARLA_KEY_ENGINE_PROCESS_MODE, CARLA_DEFAULT_PROCESS_MODE, int)
  2564. host.nextProcessMode = host.processMode
  2565. # --------------------------------------------------------------------------------------------------------
  2566. # fix things if needed
  2567. if host.processMode == ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS:
  2568. if LADISH_APP_NAME:
  2569. print("LADISH detected but using multiple clients (not allowed), forcing single client now")
  2570. host.nextProcessMode = host.processMode = ENGINE_PROCESS_MODE_SINGLE_CLIENT
  2571. else:
  2572. host.transportMode = ENGINE_TRANSPORT_MODE_JACK
  2573. if gCarla.nogui:
  2574. host.showLogs = False
  2575. # --------------------------------------------------------------------------------------------------------
  2576. # run headless host now if nogui option enabled
  2577. if gCarla.nogui:
  2578. runHostWithoutUI(host)
  2579. # ------------------------------------------------------------------------------------------------------------
  2580. # Set host settings
  2581. def setHostSettings(host):
  2582. # kdevelop likes this :)
  2583. if False: host = CarlaHostNull()
  2584. host.set_engine_option(ENGINE_OPTION_FORCE_STEREO, host.forceStereo, "")
  2585. host.set_engine_option(ENGINE_OPTION_MAX_PARAMETERS, host.maxParameters, "")
  2586. host.set_engine_option(ENGINE_OPTION_RESET_XRUNS, host.resetXruns, "")
  2587. host.set_engine_option(ENGINE_OPTION_PREFER_PLUGIN_BRIDGES, host.preferPluginBridges, "")
  2588. host.set_engine_option(ENGINE_OPTION_PREFER_UI_BRIDGES, host.preferUIBridges, "")
  2589. host.set_engine_option(ENGINE_OPTION_PREVENT_BAD_BEHAVIOUR, host.preventBadBehaviour, "")
  2590. host.set_engine_option(ENGINE_OPTION_UI_BRIDGES_TIMEOUT, host.uiBridgesTimeout, "")
  2591. host.set_engine_option(ENGINE_OPTION_UIS_ALWAYS_ON_TOP, host.uisAlwaysOnTop, "")
  2592. if host.isPlugin or host.isRemote or host.is_engine_running():
  2593. return
  2594. host.set_engine_option(ENGINE_OPTION_PROCESS_MODE, host.nextProcessMode, "")
  2595. host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE, host.transportMode, host.transportExtra)
  2596. host.set_engine_option(ENGINE_OPTION_DEBUG_CONSOLE_OUTPUT, host.showLogs, "")
  2597. if not (NSM_URL and host.nsmOK):
  2598. host.set_engine_option(ENGINE_OPTION_CLIENT_NAME_PREFIX, 0, gCarla.cnprefix)
  2599. # ------------------------------------------------------------------------------------------------------------
  2600. # Set Engine settings according to carla preferences. Returns selected audio driver.
  2601. def setEngineSettings(host, oscPort = None):
  2602. # kdevelop likes this :)
  2603. if False: host = CarlaHostNull()
  2604. # --------------------------------------------------------------------------------------------------------
  2605. # do nothing if control
  2606. if host.isControl:
  2607. return "Control"
  2608. # --------------------------------------------------------------------------------------------------------
  2609. settings = QSafeSettings("falkTX", "Carla2")
  2610. # --------------------------------------------------------------------------------------------------------
  2611. # main settings
  2612. setHostSettings(host)
  2613. # --------------------------------------------------------------------------------------------------------
  2614. # file paths
  2615. FILE_PATH_AUDIO = settings.value(CARLA_KEY_PATHS_AUDIO, CARLA_DEFAULT_FILE_PATH_AUDIO, list)
  2616. FILE_PATH_MIDI = settings.value(CARLA_KEY_PATHS_MIDI, CARLA_DEFAULT_FILE_PATH_MIDI, list)
  2617. host.set_engine_option(ENGINE_OPTION_FILE_PATH, FILE_AUDIO, splitter.join(FILE_PATH_AUDIO))
  2618. host.set_engine_option(ENGINE_OPTION_FILE_PATH, FILE_MIDI, splitter.join(FILE_PATH_MIDI))
  2619. # --------------------------------------------------------------------------------------------------------
  2620. # plugin paths
  2621. LADSPA_PATH = settings.value(CARLA_KEY_PATHS_LADSPA, CARLA_DEFAULT_LADSPA_PATH, list)
  2622. DSSI_PATH = settings.value(CARLA_KEY_PATHS_DSSI, CARLA_DEFAULT_DSSI_PATH, list)
  2623. LV2_PATH = settings.value(CARLA_KEY_PATHS_LV2, CARLA_DEFAULT_LV2_PATH, list)
  2624. VST2_PATH = settings.value(CARLA_KEY_PATHS_VST2, CARLA_DEFAULT_VST2_PATH, list)
  2625. VST3_PATH = settings.value(CARLA_KEY_PATHS_VST3, CARLA_DEFAULT_VST3_PATH, list)
  2626. SF2_PATH = settings.value(CARLA_KEY_PATHS_SF2, CARLA_DEFAULT_SF2_PATH, list)
  2627. SFZ_PATH = settings.value(CARLA_KEY_PATHS_SFZ, CARLA_DEFAULT_SFZ_PATH, list)
  2628. JSFX_PATH = settings.value(CARLA_KEY_PATHS_JSFX, CARLA_DEFAULT_JSFX_PATH, list)
  2629. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_LADSPA, splitter.join(LADSPA_PATH))
  2630. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_DSSI, splitter.join(DSSI_PATH))
  2631. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_LV2, splitter.join(LV2_PATH))
  2632. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_VST2, splitter.join(VST2_PATH))
  2633. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_VST3, splitter.join(VST3_PATH))
  2634. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_SF2, splitter.join(SF2_PATH))
  2635. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_SFZ, splitter.join(SFZ_PATH))
  2636. host.set_engine_option(ENGINE_OPTION_PLUGIN_PATH, PLUGIN_JSFX, splitter.join(JSFX_PATH))
  2637. # --------------------------------------------------------------------------------------------------------
  2638. # don't continue if plugin
  2639. if host.isPlugin:
  2640. return "Plugin"
  2641. # --------------------------------------------------------------------------------------------------------
  2642. # osc settings
  2643. if oscPort is not None and isinstance(oscPort, int):
  2644. oscEnabled = True
  2645. portNumTCP = portNumUDP = oscPort
  2646. else:
  2647. oscEnabled = settings.value(CARLA_KEY_OSC_ENABLED, CARLA_DEFAULT_OSC_ENABLED, bool)
  2648. if not settings.value(CARLA_KEY_OSC_TCP_PORT_ENABLED, CARLA_DEFAULT_OSC_TCP_PORT_ENABLED, bool):
  2649. portNumTCP = -1
  2650. elif settings.value(CARLA_KEY_OSC_TCP_PORT_RANDOM, CARLA_DEFAULT_OSC_TCP_PORT_RANDOM, bool):
  2651. portNumTCP = 0
  2652. else:
  2653. portNumTCP = settings.value(CARLA_KEY_OSC_TCP_PORT_NUMBER, CARLA_DEFAULT_OSC_TCP_PORT_NUMBER, int)
  2654. if not settings.value(CARLA_KEY_OSC_UDP_PORT_ENABLED, CARLA_DEFAULT_OSC_UDP_PORT_ENABLED, bool):
  2655. portNumUDP = -1
  2656. elif settings.value(CARLA_KEY_OSC_UDP_PORT_RANDOM, CARLA_DEFAULT_OSC_UDP_PORT_RANDOM, bool):
  2657. portNumUDP = 0
  2658. else:
  2659. portNumUDP = settings.value(CARLA_KEY_OSC_UDP_PORT_NUMBER, CARLA_DEFAULT_OSC_UDP_PORT_NUMBER, int)
  2660. host.set_engine_option(ENGINE_OPTION_OSC_ENABLED, 1 if oscEnabled else 0, "")
  2661. host.set_engine_option(ENGINE_OPTION_OSC_PORT_TCP, portNumTCP, "")
  2662. host.set_engine_option(ENGINE_OPTION_OSC_PORT_UDP, portNumUDP, "")
  2663. # --------------------------------------------------------------------------------------------------------
  2664. # wine settings
  2665. optWineExecutable = settings.value(CARLA_KEY_WINE_EXECUTABLE, CARLA_DEFAULT_WINE_EXECUTABLE, str)
  2666. optWineAutoPrefix = settings.value(CARLA_KEY_WINE_AUTO_PREFIX, CARLA_DEFAULT_WINE_AUTO_PREFIX, bool)
  2667. optWineFallbackPrefix = settings.value(CARLA_KEY_WINE_FALLBACK_PREFIX, CARLA_DEFAULT_WINE_FALLBACK_PREFIX, str)
  2668. optWineRtPrioEnabled = settings.value(CARLA_KEY_WINE_RT_PRIO_ENABLED, CARLA_DEFAULT_WINE_RT_PRIO_ENABLED, bool)
  2669. optWineBaseRtPrio = settings.value(CARLA_KEY_WINE_BASE_RT_PRIO, CARLA_DEFAULT_WINE_BASE_RT_PRIO, int)
  2670. optWineServerRtPrio = settings.value(CARLA_KEY_WINE_SERVER_RT_PRIO, CARLA_DEFAULT_WINE_SERVER_RT_PRIO, int)
  2671. host.set_engine_option(ENGINE_OPTION_WINE_EXECUTABLE, 0, optWineExecutable)
  2672. host.set_engine_option(ENGINE_OPTION_WINE_AUTO_PREFIX, 1 if optWineAutoPrefix else 0, "")
  2673. host.set_engine_option(ENGINE_OPTION_WINE_FALLBACK_PREFIX, 0, os.path.expanduser(optWineFallbackPrefix))
  2674. host.set_engine_option(ENGINE_OPTION_WINE_RT_PRIO_ENABLED, 1 if optWineRtPrioEnabled else 0, "")
  2675. host.set_engine_option(ENGINE_OPTION_WINE_BASE_RT_PRIO, optWineBaseRtPrio, "")
  2676. host.set_engine_option(ENGINE_OPTION_WINE_SERVER_RT_PRIO, optWineServerRtPrio, "")
  2677. # --------------------------------------------------------------------------------------------------------
  2678. # driver and device settings
  2679. # driver name
  2680. if host.audioDriverForced is not None:
  2681. audioDriver = host.audioDriverForced
  2682. else:
  2683. try:
  2684. audioDriver = settings.value(CARLA_KEY_ENGINE_AUDIO_DRIVER, CARLA_DEFAULT_AUDIO_DRIVER, str)
  2685. except:
  2686. audioDriver = CARLA_DEFAULT_AUDIO_DRIVER
  2687. # driver options
  2688. audioDevice = settings.value("%s%s/Device" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), "", str)
  2689. audioBufferSize = settings.value("%s%s/BufferSize" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_BUFFER_SIZE, int)
  2690. audioSampleRate = settings.value("%s%s/SampleRate" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_SAMPLE_RATE, int)
  2691. audioTripleBuffer = settings.value("%s%s/TripleBuffer" % (CARLA_KEY_ENGINE_DRIVER_PREFIX, audioDriver), CARLA_DEFAULT_AUDIO_TRIPLE_BUFFER, bool)
  2692. # Only setup audio things if engine is not running
  2693. if not host.is_engine_running():
  2694. host.set_engine_option(ENGINE_OPTION_AUDIO_DRIVER, 0, audioDriver)
  2695. host.set_engine_option(ENGINE_OPTION_AUDIO_DEVICE, 0, audioDevice)
  2696. if not audioDriver.startswith("JACK"):
  2697. host.set_engine_option(ENGINE_OPTION_AUDIO_BUFFER_SIZE, audioBufferSize, "")
  2698. host.set_engine_option(ENGINE_OPTION_AUDIO_SAMPLE_RATE, audioSampleRate, "")
  2699. host.set_engine_option(ENGINE_OPTION_AUDIO_TRIPLE_BUFFER, 1 if audioTripleBuffer else 0, "")
  2700. # --------------------------------------------------------------------------------------------------------
  2701. # fix things if needed
  2702. if audioDriver != "JACK" and host.transportMode == ENGINE_TRANSPORT_MODE_JACK:
  2703. host.transportMode = ENGINE_TRANSPORT_MODE_INTERNAL
  2704. host.set_engine_option(ENGINE_OPTION_TRANSPORT_MODE, ENGINE_TRANSPORT_MODE_INTERNAL, host.transportExtra)
  2705. # --------------------------------------------------------------------------------------------------------
  2706. # return selected driver name
  2707. return audioDriver
  2708. # ------------------------------------------------------------------------------------------------------------
  2709. # Run Carla without showing UI
  2710. def runHostWithoutUI(host):
  2711. # kdevelop likes this :)
  2712. if False: host = CarlaHostNull()
  2713. # --------------------------------------------------------------------------------------------------------
  2714. # Some initial checks
  2715. if not gCarla.nogui:
  2716. return
  2717. projectFile = getInitialProjectFile(True)
  2718. if not isinstance(gCarla.nogui, int):
  2719. oscPort = None
  2720. if not projectFile:
  2721. print("Carla no-gui mode can only be used together with a project file.")
  2722. sys.exit(1)
  2723. else:
  2724. oscPort = gCarla.nogui
  2725. # --------------------------------------------------------------------------------------------------------
  2726. # Additional imports
  2727. from time import sleep
  2728. # --------------------------------------------------------------------------------------------------------
  2729. # Init engine
  2730. audioDriver = setEngineSettings(host, oscPort)
  2731. if not host.engine_init(audioDriver, "Carla"):
  2732. print("Engine failed to initialize, possible reasons:\n%s" % host.get_last_error())
  2733. sys.exit(1)
  2734. if projectFile and not host.load_project(projectFile):
  2735. print("Failed to load selected project file, possible reasons:\n%s" % host.get_last_error())
  2736. host.engine_close()
  2737. sys.exit(1)
  2738. # --------------------------------------------------------------------------------------------------------
  2739. # Idle
  2740. print("Carla ready!")
  2741. while host.is_engine_running() and not gCarla.term:
  2742. host.engine_idle()
  2743. sleep(0.0333) # 30 Hz
  2744. # --------------------------------------------------------------------------------------------------------
  2745. # Stop
  2746. host.engine_close()
  2747. sys.exit(0)
  2748. # ------------------------------------------------------------------------------------------------------------