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

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