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

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