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

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