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

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