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

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