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

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