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

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