window-basic-main.cpp 157 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039
  1. /******************************************************************************
  2. Copyright (C) 2013-2015 by Hugh Bailey <[email protected]>
  3. Zachary Lund <[email protected]>
  4. Philippe Groarke <[email protected]>
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ******************************************************************************/
  16. #include <time.h>
  17. #include <obs.hpp>
  18. #include <QGuiApplication>
  19. #include <QMessageBox>
  20. #include <QShowEvent>
  21. #include <QDesktopServices>
  22. #include <QFileDialog>
  23. #include <QDesktopWidget>
  24. #include <QRect>
  25. #include <QScreen>
  26. #include <util/dstr.h>
  27. #include <util/util.hpp>
  28. #include <util/platform.h>
  29. #include <util/profiler.hpp>
  30. #include <util/dstr.hpp>
  31. #include <graphics/math-defs.h>
  32. #include "obs-app.hpp"
  33. #include "platform.hpp"
  34. #include "visibility-item-widget.hpp"
  35. #include "item-widget-helpers.hpp"
  36. #include "window-basic-settings.hpp"
  37. #include "window-namedialog.hpp"
  38. #include "window-basic-auto-config.hpp"
  39. #include "window-basic-source-select.hpp"
  40. #include "window-basic-main.hpp"
  41. #include "window-basic-stats.hpp"
  42. #include "window-basic-main-outputs.hpp"
  43. #include "window-basic-properties.hpp"
  44. #include "window-log-reply.hpp"
  45. #include "window-projector.hpp"
  46. #include "window-remux.hpp"
  47. #include "qt-wrappers.hpp"
  48. #include "display-helpers.hpp"
  49. #include "volume-control.hpp"
  50. #include "remote-text.hpp"
  51. #if defined(_WIN32) && defined(ENABLE_WIN_UPDATER)
  52. #include "win-update/win-update.hpp"
  53. #endif
  54. #include "ui_OBSBasic.h"
  55. #include <fstream>
  56. #include <sstream>
  57. #include <QScreen>
  58. #include <QWindow>
  59. using namespace std;
  60. namespace {
  61. template <typename OBSRef>
  62. struct SignalContainer {
  63. OBSRef ref;
  64. vector<shared_ptr<OBSSignal>> handlers;
  65. };
  66. }
  67. Q_DECLARE_METATYPE(OBSScene);
  68. Q_DECLARE_METATYPE(OBSSceneItem);
  69. Q_DECLARE_METATYPE(OBSSource);
  70. Q_DECLARE_METATYPE(obs_order_movement);
  71. Q_DECLARE_METATYPE(SignalContainer<OBSScene>);
  72. template <typename T>
  73. static T GetOBSRef(QListWidgetItem *item)
  74. {
  75. return item->data(static_cast<int>(QtDataRole::OBSRef)).value<T>();
  76. }
  77. template <typename T>
  78. static void SetOBSRef(QListWidgetItem *item, T &&val)
  79. {
  80. item->setData(static_cast<int>(QtDataRole::OBSRef),
  81. QVariant::fromValue(val));
  82. }
  83. static void AddExtraModulePaths()
  84. {
  85. char base_module_dir[512];
  86. #if defined(_WIN32) || defined(__APPLE__)
  87. int ret = GetProgramDataPath(base_module_dir, sizeof(base_module_dir),
  88. "obs-studio/plugins/%module%");
  89. #else
  90. int ret = GetConfigPath(base_module_dir, sizeof(base_module_dir),
  91. "obs-studio/plugins/%module%");
  92. #endif
  93. if (ret <= 0)
  94. return;
  95. string path = (char*)base_module_dir;
  96. #if defined(__APPLE__)
  97. obs_add_module_path((path + "/bin").c_str(), (path + "/data").c_str());
  98. BPtr<char> config_bin = os_get_config_path_ptr("obs-studio/plugins/%module%/bin");
  99. BPtr<char> config_data = os_get_config_path_ptr("obs-studio/plugins/%module%/data");
  100. obs_add_module_path(config_bin, config_data);
  101. #elif ARCH_BITS == 64
  102. obs_add_module_path((path + "/bin/64bit").c_str(),
  103. (path + "/data").c_str());
  104. #else
  105. obs_add_module_path((path + "/bin/32bit").c_str(),
  106. (path + "/data").c_str());
  107. #endif
  108. }
  109. static QList<QKeySequence> DeleteKeys;
  110. OBSBasic::OBSBasic(QWidget *parent)
  111. : OBSMainWindow (parent),
  112. ui (new Ui::OBSBasic)
  113. {
  114. setAttribute(Qt::WA_NativeWindow);
  115. projectorArray.resize(10, "");
  116. previewProjectorArray.resize(10, 0);
  117. studioProgramProjectorArray.resize(10, 0);
  118. setAcceptDrops(true);
  119. ui->setupUi(this);
  120. ui->previewDisabledLabel->setVisible(false);
  121. startingDockLayout = saveState();
  122. copyActionsDynamicProperties();
  123. ui->sources->setItemDelegate(new VisibilityItemDelegate(ui->sources));
  124. char styleSheetPath[512];
  125. int ret = GetProfilePath(styleSheetPath, sizeof(styleSheetPath),
  126. "stylesheet.qss");
  127. if (ret > 0) {
  128. if (QFile::exists(styleSheetPath)) {
  129. QString path = QString("file:///") +
  130. QT_UTF8(styleSheetPath);
  131. App()->setStyleSheet(path);
  132. }
  133. }
  134. qRegisterMetaType<OBSScene> ("OBSScene");
  135. qRegisterMetaType<OBSSceneItem>("OBSSceneItem");
  136. qRegisterMetaType<OBSSource> ("OBSSource");
  137. qRegisterMetaType<obs_hotkey_id>("obs_hotkey_id");
  138. qRegisterMetaTypeStreamOperators<
  139. std::vector<std::shared_ptr<OBSSignal>>>(
  140. "std::vector<std::shared_ptr<OBSSignal>>");
  141. qRegisterMetaTypeStreamOperators<OBSScene>("OBSScene");
  142. qRegisterMetaTypeStreamOperators<OBSSceneItem>("OBSSceneItem");
  143. ui->scenes->setAttribute(Qt::WA_MacShowFocusRect, false);
  144. ui->sources->setAttribute(Qt::WA_MacShowFocusRect, false);
  145. auto displayResize = [this]() {
  146. struct obs_video_info ovi;
  147. if (obs_get_video_info(&ovi))
  148. ResizePreview(ovi.base_width, ovi.base_height);
  149. };
  150. connect(windowHandle(), &QWindow::screenChanged, displayResize);
  151. connect(ui->preview, &OBSQTDisplay::DisplayResized, displayResize);
  152. installEventFilter(CreateShortcutFilter());
  153. stringstream name;
  154. name << "OBS " << App()->GetVersionString();
  155. blog(LOG_INFO, "%s", name.str().c_str());
  156. blog(LOG_INFO, "---------------------------------");
  157. UpdateTitleBar();
  158. connect(ui->scenes->itemDelegate(),
  159. SIGNAL(closeEditor(QWidget*,
  160. QAbstractItemDelegate::EndEditHint)),
  161. this,
  162. SLOT(SceneNameEdited(QWidget*,
  163. QAbstractItemDelegate::EndEditHint)));
  164. connect(ui->sources->itemDelegate(),
  165. SIGNAL(closeEditor(QWidget*,
  166. QAbstractItemDelegate::EndEditHint)),
  167. this,
  168. SLOT(SceneItemNameEdited(QWidget*,
  169. QAbstractItemDelegate::EndEditHint)));
  170. cpuUsageInfo = os_cpu_usage_info_start();
  171. cpuUsageTimer = new QTimer(this);
  172. connect(cpuUsageTimer, SIGNAL(timeout()),
  173. ui->statusbar, SLOT(UpdateCPUUsage()));
  174. cpuUsageTimer->start(3000);
  175. DeleteKeys =
  176. #ifdef __APPLE__
  177. QList<QKeySequence>{{Qt::Key_Backspace}} <<
  178. #endif
  179. QKeySequence::keyBindings(QKeySequence::Delete);
  180. #ifdef __APPLE__
  181. ui->actionRemoveSource->setShortcuts(DeleteKeys);
  182. ui->actionRemoveScene->setShortcuts(DeleteKeys);
  183. ui->action_Settings->setMenuRole(QAction::PreferencesRole);
  184. ui->actionE_xit->setMenuRole(QAction::QuitRole);
  185. #endif
  186. auto addNudge = [this](const QKeySequence &seq, const char *s)
  187. {
  188. QAction *nudge = new QAction(ui->preview);
  189. nudge->setShortcut(seq);
  190. nudge->setShortcutContext(Qt::WidgetShortcut);
  191. ui->preview->addAction(nudge);
  192. connect(nudge, SIGNAL(triggered()), this, s);
  193. };
  194. addNudge(Qt::Key_Up, SLOT(NudgeUp()));
  195. addNudge(Qt::Key_Down, SLOT(NudgeDown()));
  196. addNudge(Qt::Key_Left, SLOT(NudgeLeft()));
  197. addNudge(Qt::Key_Right, SLOT(NudgeRight()));
  198. auto assignDockToggle = [this](QDockWidget *dock, QAction *action)
  199. {
  200. auto handleWindowToggle = [action] (bool vis)
  201. {
  202. action->blockSignals(true);
  203. action->setChecked(vis);
  204. action->blockSignals(false);
  205. };
  206. auto handleMenuToggle = [dock] (bool check)
  207. {
  208. dock->blockSignals(true);
  209. dock->setVisible(check);
  210. dock->blockSignals(false);
  211. };
  212. dock->connect(dock->toggleViewAction(), &QAction::toggled,
  213. handleWindowToggle);
  214. dock->connect(action, &QAction::toggled,
  215. handleMenuToggle);
  216. };
  217. assignDockToggle(ui->scenesDock, ui->toggleScenes);
  218. assignDockToggle(ui->sourcesDock, ui->toggleSources);
  219. assignDockToggle(ui->mixerDock, ui->toggleMixer);
  220. assignDockToggle(ui->transitionsDock, ui->toggleTransitions);
  221. assignDockToggle(ui->controlsDock, ui->toggleControls);
  222. //hide all docking panes
  223. ui->toggleScenes->setChecked(false);
  224. ui->toggleSources->setChecked(false);
  225. ui->toggleMixer->setChecked(false);
  226. ui->toggleTransitions->setChecked(false);
  227. ui->toggleControls->setChecked(false);
  228. //restore parent window geometry
  229. const char *geometry = config_get_string(App()->GlobalConfig(),
  230. "BasicWindow", "geometry");
  231. if (geometry != NULL) {
  232. QByteArray byteArray = QByteArray::fromBase64(
  233. QByteArray(geometry));
  234. restoreGeometry(byteArray);
  235. QRect windowGeometry = normalGeometry();
  236. if (!WindowPositionValid(windowGeometry)) {
  237. QRect rect = App()->desktop()->geometry();
  238. setGeometry(QStyle::alignedRect(
  239. Qt::LeftToRight,
  240. Qt::AlignCenter,
  241. size(), rect));
  242. }
  243. }
  244. }
  245. static void SaveAudioDevice(const char *name, int channel, obs_data_t *parent,
  246. vector<OBSSource> &audioSources)
  247. {
  248. obs_source_t *source = obs_get_output_source(channel);
  249. if (!source)
  250. return;
  251. audioSources.push_back(source);
  252. obs_data_t *data = obs_save_source(source);
  253. obs_data_set_obj(parent, name, data);
  254. obs_data_release(data);
  255. obs_source_release(source);
  256. }
  257. static obs_data_t *GenerateSaveData(obs_data_array_t *sceneOrder,
  258. obs_data_array_t *quickTransitionData, int transitionDuration,
  259. obs_data_array_t *transitions,
  260. OBSScene &scene, OBSSource &curProgramScene,
  261. obs_data_array_t *savedProjectorList,
  262. obs_data_array_t *savedPreviewProjectorList,
  263. obs_data_array_t *savedStudioProgramProjectorList)
  264. {
  265. obs_data_t *saveData = obs_data_create();
  266. vector<OBSSource> audioSources;
  267. audioSources.reserve(5);
  268. SaveAudioDevice(DESKTOP_AUDIO_1, 1, saveData, audioSources);
  269. SaveAudioDevice(DESKTOP_AUDIO_2, 2, saveData, audioSources);
  270. SaveAudioDevice(AUX_AUDIO_1, 3, saveData, audioSources);
  271. SaveAudioDevice(AUX_AUDIO_2, 4, saveData, audioSources);
  272. SaveAudioDevice(AUX_AUDIO_3, 5, saveData, audioSources);
  273. auto FilterAudioSources = [&](obs_source_t *source)
  274. {
  275. return find(begin(audioSources), end(audioSources), source) ==
  276. end(audioSources);
  277. };
  278. using FilterAudioSources_t = decltype(FilterAudioSources);
  279. obs_data_array_t *sourcesArray = obs_save_sources_filtered(
  280. [](void *data, obs_source_t *source)
  281. {
  282. return (*static_cast<FilterAudioSources_t*>(data))(source);
  283. }, static_cast<void*>(&FilterAudioSources));
  284. obs_source_t *transition = obs_get_output_source(0);
  285. obs_source_t *currentScene = obs_scene_get_source(scene);
  286. const char *sceneName = obs_source_get_name(currentScene);
  287. const char *programName = obs_source_get_name(curProgramScene);
  288. const char *sceneCollection = config_get_string(App()->GlobalConfig(),
  289. "Basic", "SceneCollection");
  290. obs_data_set_string(saveData, "current_scene", sceneName);
  291. obs_data_set_string(saveData, "current_program_scene", programName);
  292. obs_data_set_array(saveData, "scene_order", sceneOrder);
  293. obs_data_set_string(saveData, "name", sceneCollection);
  294. obs_data_set_array(saveData, "sources", sourcesArray);
  295. obs_data_set_array(saveData, "quick_transitions", quickTransitionData);
  296. obs_data_set_array(saveData, "transitions", transitions);
  297. obs_data_set_array(saveData, "saved_projectors", savedProjectorList);
  298. obs_data_set_array(saveData, "saved_preview_projectors",
  299. savedPreviewProjectorList);
  300. obs_data_set_array(saveData, "saved_studio_preview_projectors",
  301. savedStudioProgramProjectorList);
  302. obs_data_array_release(sourcesArray);
  303. obs_data_set_string(saveData, "current_transition",
  304. obs_source_get_name(transition));
  305. obs_data_set_int(saveData, "transition_duration", transitionDuration);
  306. obs_source_release(transition);
  307. return saveData;
  308. }
  309. void OBSBasic::copyActionsDynamicProperties()
  310. {
  311. // Themes need the QAction dynamic properties
  312. for (QAction *x : ui->scenesToolbar->actions()) {
  313. QWidget* temp = ui->scenesToolbar->widgetForAction(x);
  314. for (QByteArray &y : x->dynamicPropertyNames()) {
  315. temp->setProperty(y, x->property(y));
  316. }
  317. }
  318. for (QAction *x : ui->sourcesToolbar->actions()) {
  319. QWidget* temp = ui->sourcesToolbar->widgetForAction(x);
  320. for (QByteArray &y : x->dynamicPropertyNames()) {
  321. temp->setProperty(y, x->property(y));
  322. }
  323. }
  324. }
  325. void OBSBasic::ClearVolumeControls()
  326. {
  327. VolControl *control;
  328. for (size_t i = 0; i < volumes.size(); i++) {
  329. control = volumes[i];
  330. delete control;
  331. }
  332. volumes.clear();
  333. }
  334. obs_data_array_t *OBSBasic::SaveSceneListOrder()
  335. {
  336. obs_data_array_t *sceneOrder = obs_data_array_create();
  337. for (int i = 0; i < ui->scenes->count(); i++) {
  338. obs_data_t *data = obs_data_create();
  339. obs_data_set_string(data, "name",
  340. QT_TO_UTF8(ui->scenes->item(i)->text()));
  341. obs_data_array_push_back(sceneOrder, data);
  342. obs_data_release(data);
  343. }
  344. return sceneOrder;
  345. }
  346. obs_data_array_t *OBSBasic::SaveProjectors()
  347. {
  348. obs_data_array_t *saveProjector = obs_data_array_create();
  349. for (size_t i = 0; i < projectorArray.size(); i++) {
  350. obs_data_t *data = obs_data_create();
  351. obs_data_set_string(data, "saved_projectors",
  352. projectorArray.at(i).c_str());
  353. obs_data_array_push_back(saveProjector, data);
  354. obs_data_release(data);
  355. }
  356. return saveProjector;
  357. }
  358. obs_data_array_t *OBSBasic::SavePreviewProjectors()
  359. {
  360. obs_data_array_t *saveProjector = obs_data_array_create();
  361. for (size_t i = 0; i < previewProjectorArray.size(); i++) {
  362. obs_data_t *data = obs_data_create();
  363. obs_data_set_int(data, "saved_preview_projectors",
  364. previewProjectorArray.at(i));
  365. obs_data_array_push_back(saveProjector, data);
  366. obs_data_release(data);
  367. }
  368. return saveProjector;
  369. }
  370. obs_data_array_t *OBSBasic::SaveStudioProgramProjectors()
  371. {
  372. obs_data_array_t *saveProjector = obs_data_array_create();
  373. for (size_t i = 0; i < studioProgramProjectorArray.size(); i++) {
  374. obs_data_t *data = obs_data_create();
  375. obs_data_set_int(data, "saved_studio_preview_projectors",
  376. studioProgramProjectorArray.at(i));
  377. obs_data_array_push_back(saveProjector, data);
  378. obs_data_release(data);
  379. }
  380. return saveProjector;
  381. }
  382. void OBSBasic::Save(const char *file)
  383. {
  384. OBSScene scene = GetCurrentScene();
  385. OBSSource curProgramScene = OBSGetStrongRef(programScene);
  386. if (!curProgramScene)
  387. curProgramScene = obs_scene_get_source(scene);
  388. obs_data_array_t *sceneOrder = SaveSceneListOrder();
  389. obs_data_array_t *transitions = SaveTransitions();
  390. obs_data_array_t *quickTrData = SaveQuickTransitions();
  391. obs_data_array_t *savedProjectorList = SaveProjectors();
  392. obs_data_array_t *savedPreviewProjectorList = SavePreviewProjectors();
  393. obs_data_array_t *savedStudioProgramProjectorList =
  394. SaveStudioProgramProjectors();
  395. obs_data_t *saveData = GenerateSaveData(sceneOrder, quickTrData,
  396. ui->transitionDuration->value(), transitions,
  397. scene, curProgramScene, savedProjectorList,
  398. savedPreviewProjectorList,
  399. savedStudioProgramProjectorList);
  400. obs_data_set_bool(saveData, "preview_locked", ui->preview->Locked());
  401. obs_data_set_bool(saveData, "scaling_enabled",
  402. ui->preview->IsFixedScaling());
  403. obs_data_set_int(saveData, "scaling_level",
  404. ui->preview->GetScalingLevel());
  405. obs_data_set_double(saveData, "scaling_off_x",
  406. ui->preview->GetScrollX());
  407. obs_data_set_double(saveData, "scaling_off_y",
  408. ui->preview->GetScrollY());
  409. if (api) {
  410. obs_data_t *moduleObj = obs_data_create();
  411. api->on_save(moduleObj);
  412. obs_data_set_obj(saveData, "modules", moduleObj);
  413. obs_data_release(moduleObj);
  414. }
  415. if (!obs_data_save_json_safe(saveData, file, "tmp", "bak"))
  416. blog(LOG_ERROR, "Could not save scene data to %s", file);
  417. obs_data_release(saveData);
  418. obs_data_array_release(sceneOrder);
  419. obs_data_array_release(quickTrData);
  420. obs_data_array_release(transitions);
  421. obs_data_array_release(savedProjectorList);
  422. obs_data_array_release(savedPreviewProjectorList);
  423. obs_data_array_release(savedStudioProgramProjectorList);
  424. }
  425. static void LoadAudioDevice(const char *name, int channel, obs_data_t *parent)
  426. {
  427. obs_data_t *data = obs_data_get_obj(parent, name);
  428. if (!data)
  429. return;
  430. obs_source_t *source = obs_load_source(data);
  431. if (source) {
  432. obs_set_output_source(channel, source);
  433. obs_source_release(source);
  434. }
  435. obs_data_release(data);
  436. }
  437. static inline bool HasAudioDevices(const char *source_id)
  438. {
  439. const char *output_id = source_id;
  440. obs_properties_t *props = obs_get_source_properties(output_id);
  441. size_t count = 0;
  442. if (!props)
  443. return false;
  444. obs_property_t *devices = obs_properties_get(props, "device_id");
  445. if (devices)
  446. count = obs_property_list_item_count(devices);
  447. obs_properties_destroy(props);
  448. return count != 0;
  449. }
  450. void OBSBasic::CreateFirstRunSources()
  451. {
  452. bool hasDesktopAudio = HasAudioDevices(App()->OutputAudioSource());
  453. bool hasInputAudio = HasAudioDevices(App()->InputAudioSource());
  454. if (hasDesktopAudio)
  455. ResetAudioDevice(App()->OutputAudioSource(), "default",
  456. Str("Basic.DesktopDevice1"), 1);
  457. if (hasInputAudio)
  458. ResetAudioDevice(App()->InputAudioSource(), "default",
  459. Str("Basic.AuxDevice1"), 3);
  460. }
  461. void OBSBasic::CreateDefaultScene(bool firstStart)
  462. {
  463. disableSaving++;
  464. ClearSceneData();
  465. InitDefaultTransitions();
  466. CreateDefaultQuickTransitions();
  467. ui->transitionDuration->setValue(300);
  468. SetTransition(fadeTransition);
  469. obs_scene_t *scene = obs_scene_create(Str("Basic.Scene"));
  470. if (firstStart)
  471. CreateFirstRunSources();
  472. AddScene(obs_scene_get_source(scene));
  473. SetCurrentScene(scene, true);
  474. obs_scene_release(scene);
  475. disableSaving--;
  476. }
  477. static void ReorderItemByName(QListWidget *lw, const char *name, int newIndex)
  478. {
  479. for (int i = 0; i < lw->count(); i++) {
  480. QListWidgetItem *item = lw->item(i);
  481. if (strcmp(name, QT_TO_UTF8(item->text())) == 0) {
  482. if (newIndex != i) {
  483. item = lw->takeItem(i);
  484. lw->insertItem(newIndex, item);
  485. }
  486. break;
  487. }
  488. }
  489. }
  490. void OBSBasic::LoadSceneListOrder(obs_data_array_t *array)
  491. {
  492. size_t num = obs_data_array_count(array);
  493. for (size_t i = 0; i < num; i++) {
  494. obs_data_t *data = obs_data_array_item(array, i);
  495. const char *name = obs_data_get_string(data, "name");
  496. ReorderItemByName(ui->scenes, name, (int)i);
  497. obs_data_release(data);
  498. }
  499. }
  500. void OBSBasic::LoadSavedProjectors(obs_data_array_t *array)
  501. {
  502. size_t num = obs_data_array_count(array);
  503. for (size_t i = 0; i < num; i++) {
  504. obs_data_t *data = obs_data_array_item(array, i);
  505. projectorArray.at(i) = obs_data_get_string(data,
  506. "saved_projectors");
  507. obs_data_release(data);
  508. }
  509. }
  510. void OBSBasic::LoadSavedPreviewProjectors(obs_data_array_t *array)
  511. {
  512. size_t num = obs_data_array_count(array);
  513. for (size_t i = 0; i < num; i++) {
  514. obs_data_t *data = obs_data_array_item(array, i);
  515. previewProjectorArray.at(i) = obs_data_get_int(data,
  516. "saved_preview_projectors");
  517. obs_data_release(data);
  518. }
  519. }
  520. void OBSBasic::LoadSavedStudioProgramProjectors(obs_data_array_t *array)
  521. {
  522. size_t num = obs_data_array_count(array);
  523. for (size_t i = 0; i < num; i++) {
  524. obs_data_t *data = obs_data_array_item(array, i);
  525. studioProgramProjectorArray.at(i) = obs_data_get_int(data,
  526. "saved_studio_preview_projectors");
  527. obs_data_release(data);
  528. }
  529. }
  530. static void LogFilter(obs_source_t*, obs_source_t *filter, void *v_val)
  531. {
  532. const char *name = obs_source_get_name(filter);
  533. const char *id = obs_source_get_id(filter);
  534. int val = (int)(intptr_t)v_val;
  535. string indent;
  536. for (int i = 0; i < val; i++)
  537. indent += " ";
  538. blog(LOG_INFO, "%s- filter: '%s' (%s)", indent.c_str(), name, id);
  539. }
  540. static bool LogSceneItem(obs_scene_t*, obs_sceneitem_t *item, void*)
  541. {
  542. obs_source_t *source = obs_sceneitem_get_source(item);
  543. const char *name = obs_source_get_name(source);
  544. const char *id = obs_source_get_id(source);
  545. blog(LOG_INFO, " - source: '%s' (%s)", name, id);
  546. obs_monitoring_type monitoring_type =
  547. obs_source_get_monitoring_type(source);
  548. if (monitoring_type != OBS_MONITORING_TYPE_NONE) {
  549. const char *type =
  550. (monitoring_type == OBS_MONITORING_TYPE_MONITOR_ONLY)
  551. ? "monitor only"
  552. : "monitor and output";
  553. blog(LOG_INFO, " - monitoring: %s", type);
  554. }
  555. obs_source_enum_filters(source, LogFilter, (void*)(intptr_t)2);
  556. return true;
  557. }
  558. void OBSBasic::LogScenes()
  559. {
  560. blog(LOG_INFO, "------------------------------------------------");
  561. blog(LOG_INFO, "Loaded scenes:");
  562. for (int i = 0; i < ui->scenes->count(); i++) {
  563. QListWidgetItem *item = ui->scenes->item(i);
  564. OBSScene scene = GetOBSRef<OBSScene>(item);
  565. obs_source_t *source = obs_scene_get_source(scene);
  566. const char *name = obs_source_get_name(source);
  567. blog(LOG_INFO, "- scene '%s':", name);
  568. obs_scene_enum_items(scene, LogSceneItem, nullptr);
  569. obs_source_enum_filters(source, LogFilter, (void*)(intptr_t)1);
  570. }
  571. blog(LOG_INFO, "------------------------------------------------");
  572. }
  573. void OBSBasic::Load(const char *file)
  574. {
  575. disableSaving++;
  576. obs_data_t *data = obs_data_create_from_json_file_safe(file, "bak");
  577. if (!data) {
  578. disableSaving--;
  579. blog(LOG_INFO, "No scene file found, creating default scene");
  580. CreateDefaultScene(true);
  581. SaveProject();
  582. return;
  583. }
  584. ClearSceneData();
  585. InitDefaultTransitions();
  586. obs_data_array_t *sceneOrder = obs_data_get_array(data, "scene_order");
  587. obs_data_array_t *sources = obs_data_get_array(data, "sources");
  588. obs_data_array_t *transitions= obs_data_get_array(data, "transitions");
  589. const char *sceneName = obs_data_get_string(data,
  590. "current_scene");
  591. const char *programSceneName = obs_data_get_string(data,
  592. "current_program_scene");
  593. const char *transitionName = obs_data_get_string(data,
  594. "current_transition");
  595. if (!opt_starting_scene.empty()) {
  596. programSceneName = opt_starting_scene.c_str();
  597. if (!IsPreviewProgramMode())
  598. sceneName = opt_starting_scene.c_str();
  599. }
  600. int newDuration = obs_data_get_int(data, "transition_duration");
  601. if (!newDuration)
  602. newDuration = 300;
  603. if (!transitionName)
  604. transitionName = obs_source_get_name(fadeTransition);
  605. const char *curSceneCollection = config_get_string(
  606. App()->GlobalConfig(), "Basic", "SceneCollection");
  607. obs_data_set_default_string(data, "name", curSceneCollection);
  608. const char *name = obs_data_get_string(data, "name");
  609. obs_source_t *curScene;
  610. obs_source_t *curProgramScene;
  611. obs_source_t *curTransition;
  612. if (!name || !*name)
  613. name = curSceneCollection;
  614. LoadAudioDevice(DESKTOP_AUDIO_1, 1, data);
  615. LoadAudioDevice(DESKTOP_AUDIO_2, 2, data);
  616. LoadAudioDevice(AUX_AUDIO_1, 3, data);
  617. LoadAudioDevice(AUX_AUDIO_2, 4, data);
  618. LoadAudioDevice(AUX_AUDIO_3, 5, data);
  619. obs_load_sources(sources, OBSBasic::SourceLoaded, this);
  620. if (transitions)
  621. LoadTransitions(transitions);
  622. if (sceneOrder)
  623. LoadSceneListOrder(sceneOrder);
  624. obs_data_array_release(transitions);
  625. curTransition = FindTransition(transitionName);
  626. if (!curTransition)
  627. curTransition = fadeTransition;
  628. ui->transitionDuration->setValue(newDuration);
  629. SetTransition(curTransition);
  630. obs_data_array_t *savedProjectors = obs_data_get_array(data,
  631. "saved_projectors");
  632. if (savedProjectors)
  633. LoadSavedProjectors(savedProjectors);
  634. obs_data_array_release(savedProjectors);
  635. obs_data_array_t *savedPreviewProjectors = obs_data_get_array(data,
  636. "saved_preview_projectors");
  637. if (savedPreviewProjectors)
  638. LoadSavedPreviewProjectors(savedPreviewProjectors);
  639. obs_data_array_release(savedPreviewProjectors);
  640. obs_data_array_t *savedStudioProgramProjectors = obs_data_get_array(data,
  641. "saved_studio_preview_projectors");
  642. if (savedStudioProgramProjectors)
  643. LoadSavedStudioProgramProjectors(savedStudioProgramProjectors);
  644. obs_data_array_release(savedStudioProgramProjectors);
  645. retryScene:
  646. curScene = obs_get_source_by_name(sceneName);
  647. curProgramScene = obs_get_source_by_name(programSceneName);
  648. /* if the starting scene command line parameter is bad at all,
  649. * fall back to original settings */
  650. if (!opt_starting_scene.empty() && (!curScene || !curProgramScene)) {
  651. sceneName = obs_data_get_string(data, "current_scene");
  652. programSceneName = obs_data_get_string(data,
  653. "current_program_scene");
  654. obs_source_release(curScene);
  655. obs_source_release(curProgramScene);
  656. opt_starting_scene.clear();
  657. goto retryScene;
  658. }
  659. if (!curProgramScene) {
  660. curProgramScene = curScene;
  661. obs_source_addref(curScene);
  662. }
  663. SetCurrentScene(curScene, true);
  664. if (IsPreviewProgramMode())
  665. TransitionToScene(curProgramScene, true);
  666. obs_source_release(curScene);
  667. obs_source_release(curProgramScene);
  668. obs_data_array_release(sources);
  669. obs_data_array_release(sceneOrder);
  670. std::string file_base = strrchr(file, '/') + 1;
  671. file_base.erase(file_base.size() - 5, 5);
  672. config_set_string(App()->GlobalConfig(), "Basic", "SceneCollection",
  673. name);
  674. config_set_string(App()->GlobalConfig(), "Basic", "SceneCollectionFile",
  675. file_base.c_str());
  676. obs_data_array_t *quickTransitionData = obs_data_get_array(data,
  677. "quick_transitions");
  678. LoadQuickTransitions(quickTransitionData);
  679. obs_data_array_release(quickTransitionData);
  680. RefreshQuickTransitions();
  681. bool previewLocked = obs_data_get_bool(data, "preview_locked");
  682. ui->preview->SetLocked(previewLocked);
  683. ui->actionLockPreview->setChecked(previewLocked);
  684. /* ---------------------- */
  685. bool fixedScaling = obs_data_get_bool(data, "scaling_enabled");
  686. int scalingLevel = (int)obs_data_get_int(data, "scaling_level");
  687. float scrollOffX = (float)obs_data_get_double(data, "scaling_off_x");
  688. float scrollOffY = (float)obs_data_get_double(data, "scaling_off_y");
  689. if (fixedScaling) {
  690. ui->preview->SetScalingLevel(scalingLevel);
  691. ui->preview->SetScrollingOffset(scrollOffX, scrollOffY);
  692. }
  693. ui->preview->SetFixedScaling(fixedScaling);
  694. /* ---------------------- */
  695. if (api) {
  696. obs_data_t *modulesObj = obs_data_get_obj(data, "modules");
  697. api->on_load(modulesObj);
  698. obs_data_release(modulesObj);
  699. }
  700. obs_data_release(data);
  701. if (!opt_starting_scene.empty())
  702. opt_starting_scene.clear();
  703. if (opt_start_streaming) {
  704. blog(LOG_INFO, "Starting stream due to command line parameter");
  705. QMetaObject::invokeMethod(this, "StartStreaming",
  706. Qt::QueuedConnection);
  707. opt_start_streaming = false;
  708. }
  709. if (opt_start_recording) {
  710. blog(LOG_INFO, "Starting recording due to command line parameter");
  711. QMetaObject::invokeMethod(this, "StartRecording",
  712. Qt::QueuedConnection);
  713. opt_start_recording = false;
  714. }
  715. if (opt_start_replaybuffer) {
  716. QMetaObject::invokeMethod(this, "StartReplayBuffer",
  717. Qt::QueuedConnection);
  718. opt_start_replaybuffer = false;
  719. }
  720. LogScenes();
  721. disableSaving--;
  722. }
  723. #define SERVICE_PATH "service.json"
  724. void OBSBasic::SaveService()
  725. {
  726. if (!service)
  727. return;
  728. char serviceJsonPath[512];
  729. int ret = GetProfilePath(serviceJsonPath, sizeof(serviceJsonPath),
  730. SERVICE_PATH);
  731. if (ret <= 0)
  732. return;
  733. obs_data_t *data = obs_data_create();
  734. obs_data_t *settings = obs_service_get_settings(service);
  735. obs_data_set_string(data, "type", obs_service_get_type(service));
  736. obs_data_set_obj(data, "settings", settings);
  737. if (!obs_data_save_json_safe(data, serviceJsonPath, "tmp", "bak"))
  738. blog(LOG_WARNING, "Failed to save service");
  739. obs_data_release(settings);
  740. obs_data_release(data);
  741. }
  742. bool OBSBasic::LoadService()
  743. {
  744. const char *type;
  745. char serviceJsonPath[512];
  746. int ret = GetProfilePath(serviceJsonPath, sizeof(serviceJsonPath),
  747. SERVICE_PATH);
  748. if (ret <= 0)
  749. return false;
  750. obs_data_t *data = obs_data_create_from_json_file_safe(serviceJsonPath,
  751. "bak");
  752. obs_data_set_default_string(data, "type", "rtmp_common");
  753. type = obs_data_get_string(data, "type");
  754. obs_data_t *settings = obs_data_get_obj(data, "settings");
  755. obs_data_t *hotkey_data = obs_data_get_obj(data, "hotkeys");
  756. service = obs_service_create(type, "default_service", settings,
  757. hotkey_data);
  758. obs_service_release(service);
  759. obs_data_release(hotkey_data);
  760. obs_data_release(settings);
  761. obs_data_release(data);
  762. return !!service;
  763. }
  764. bool OBSBasic::InitService()
  765. {
  766. ProfileScope("OBSBasic::InitService");
  767. if (LoadService())
  768. return true;
  769. service = obs_service_create("rtmp_common", "default_service", nullptr,
  770. nullptr);
  771. if (!service)
  772. return false;
  773. obs_service_release(service);
  774. return true;
  775. }
  776. static const double scaled_vals[] =
  777. {
  778. 1.0,
  779. 1.25,
  780. (1.0/0.75),
  781. 1.5,
  782. (1.0/0.6),
  783. 1.75,
  784. 2.0,
  785. 2.25,
  786. 2.5,
  787. 2.75,
  788. 3.0,
  789. 0.0
  790. };
  791. bool OBSBasic::InitBasicConfigDefaults()
  792. {
  793. QList<QScreen*> screens = QGuiApplication::screens();
  794. if (!screens.size()) {
  795. OBSErrorBox(NULL, "There appears to be no monitors. Er, this "
  796. "technically shouldn't be possible.");
  797. return false;
  798. }
  799. QScreen *primaryScreen = QGuiApplication::primaryScreen();
  800. uint32_t cx = primaryScreen->size().width();
  801. uint32_t cy = primaryScreen->size().height();
  802. bool oldResolutionDefaults = config_get_bool(App()->GlobalConfig(),
  803. "General", "Pre19Defaults");
  804. /* use 1920x1080 for new default base res if main monitor is above
  805. * 1920x1080, but don't apply for people from older builds -- only to
  806. * new users */
  807. if (!oldResolutionDefaults && (cx * cy) > (1920 * 1080)) {
  808. cx = 1920;
  809. cy = 1080;
  810. }
  811. /* ----------------------------------------------------- */
  812. /* move over mixer values in advanced if older config */
  813. if (config_has_user_value(basicConfig, "AdvOut", "RecTrackIndex") &&
  814. !config_has_user_value(basicConfig, "AdvOut", "RecTracks")) {
  815. uint64_t track = config_get_uint(basicConfig, "AdvOut",
  816. "RecTrackIndex");
  817. track = 1ULL << (track - 1);
  818. config_set_uint(basicConfig, "AdvOut", "RecTracks", track);
  819. config_remove_value(basicConfig, "AdvOut", "RecTrackIndex");
  820. config_save_safe(basicConfig, "tmp", nullptr);
  821. }
  822. /* ----------------------------------------------------- */
  823. config_set_default_string(basicConfig, "Output", "Mode", "Simple");
  824. config_set_default_string(basicConfig, "SimpleOutput", "FilePath",
  825. GetDefaultVideoSavePath().c_str());
  826. config_set_default_string(basicConfig, "SimpleOutput", "RecFormat",
  827. "flv");
  828. config_set_default_uint (basicConfig, "SimpleOutput", "VBitrate",
  829. 2500);
  830. config_set_default_string(basicConfig, "SimpleOutput", "StreamEncoder",
  831. SIMPLE_ENCODER_X264);
  832. config_set_default_uint (basicConfig, "SimpleOutput", "ABitrate", 160);
  833. config_set_default_bool (basicConfig, "SimpleOutput", "UseAdvanced",
  834. false);
  835. config_set_default_bool (basicConfig, "SimpleOutput", "EnforceBitrate",
  836. true);
  837. config_set_default_string(basicConfig, "SimpleOutput", "Preset",
  838. "veryfast");
  839. config_set_default_string(basicConfig, "SimpleOutput", "RecQuality",
  840. "Stream");
  841. config_set_default_string(basicConfig, "SimpleOutput", "RecEncoder",
  842. SIMPLE_ENCODER_X264);
  843. config_set_default_bool(basicConfig, "SimpleOutput", "RecRB", false);
  844. config_set_default_int(basicConfig, "SimpleOutput", "RecRBTime", 20);
  845. config_set_default_int(basicConfig, "SimpleOutput", "RecRBSize", 512);
  846. config_set_default_string(basicConfig, "SimpleOutput", "RecRBPrefix",
  847. "Replay");
  848. config_set_default_bool (basicConfig, "AdvOut", "ApplyServiceSettings",
  849. true);
  850. config_set_default_bool (basicConfig, "AdvOut", "UseRescale", false);
  851. config_set_default_uint (basicConfig, "AdvOut", "TrackIndex", 1);
  852. config_set_default_string(basicConfig, "AdvOut", "Encoder", "obs_x264");
  853. config_set_default_string(basicConfig, "AdvOut", "RecType", "Standard");
  854. config_set_default_string(basicConfig, "AdvOut", "RecFilePath",
  855. GetDefaultVideoSavePath().c_str());
  856. config_set_default_string(basicConfig, "AdvOut", "RecFormat", "flv");
  857. config_set_default_bool (basicConfig, "AdvOut", "RecUseRescale",
  858. false);
  859. config_set_default_uint (basicConfig, "AdvOut", "RecTracks", (1<<0));
  860. config_set_default_string(basicConfig, "AdvOut", "RecEncoder",
  861. "none");
  862. config_set_default_bool (basicConfig, "AdvOut", "FFOutputToFile",
  863. true);
  864. config_set_default_string(basicConfig, "AdvOut", "FFFilePath",
  865. GetDefaultVideoSavePath().c_str());
  866. config_set_default_string(basicConfig, "AdvOut", "FFExtension", "mp4");
  867. config_set_default_uint (basicConfig, "AdvOut", "FFVBitrate", 2500);
  868. config_set_default_uint (basicConfig, "AdvOut", "FFVGOPSize", 250);
  869. config_set_default_bool (basicConfig, "AdvOut", "FFUseRescale",
  870. false);
  871. config_set_default_bool (basicConfig, "AdvOut", "FFIgnoreCompat",
  872. false);
  873. config_set_default_uint (basicConfig, "AdvOut", "FFABitrate", 160);
  874. config_set_default_uint (basicConfig, "AdvOut", "FFAudioTrack", 1);
  875. config_set_default_uint (basicConfig, "AdvOut", "Track1Bitrate", 160);
  876. config_set_default_uint (basicConfig, "AdvOut", "Track2Bitrate", 160);
  877. config_set_default_uint (basicConfig, "AdvOut", "Track3Bitrate", 160);
  878. config_set_default_uint (basicConfig, "AdvOut", "Track4Bitrate", 160);
  879. config_set_default_uint (basicConfig, "AdvOut", "Track5Bitrate", 160);
  880. config_set_default_uint (basicConfig, "AdvOut", "Track6Bitrate", 160);
  881. config_set_default_bool (basicConfig, "AdvOut", "RecRB", false);
  882. config_set_default_uint (basicConfig, "AdvOut", "RecRBTime", 20);
  883. config_set_default_int (basicConfig, "AdvOut", "RecRBSize", 512);
  884. config_set_default_uint (basicConfig, "Video", "BaseCX", cx);
  885. config_set_default_uint (basicConfig, "Video", "BaseCY", cy);
  886. /* don't allow BaseCX/BaseCY to be susceptible to defaults changing */
  887. if (!config_has_user_value(basicConfig, "Video", "BaseCX") ||
  888. !config_has_user_value(basicConfig, "Video", "BaseCY")) {
  889. config_set_uint(basicConfig, "Video", "BaseCX", cx);
  890. config_set_uint(basicConfig, "Video", "BaseCY", cy);
  891. config_save_safe(basicConfig, "tmp", nullptr);
  892. }
  893. config_set_default_string(basicConfig, "Output", "FilenameFormatting",
  894. "%CCYY-%MM-%DD %hh-%mm-%ss");
  895. config_set_default_bool (basicConfig, "Output", "DelayEnable", false);
  896. config_set_default_uint (basicConfig, "Output", "DelaySec", 20);
  897. config_set_default_bool (basicConfig, "Output", "DelayPreserve", true);
  898. config_set_default_bool (basicConfig, "Output", "Reconnect", true);
  899. config_set_default_uint (basicConfig, "Output", "RetryDelay", 10);
  900. config_set_default_uint (basicConfig, "Output", "MaxRetries", 20);
  901. config_set_default_string(basicConfig, "Output", "BindIP", "default");
  902. config_set_default_bool (basicConfig, "Output", "NewSocketLoopEnable",
  903. false);
  904. config_set_default_bool (basicConfig, "Output", "LowLatencyEnable",
  905. false);
  906. int i = 0;
  907. uint32_t scale_cx = cx;
  908. uint32_t scale_cy = cy;
  909. /* use a default scaled resolution that has a pixel count no higher
  910. * than 1280x720 */
  911. while (((scale_cx * scale_cy) > (1280 * 720)) && scaled_vals[i] > 0.0) {
  912. double scale = scaled_vals[i++];
  913. scale_cx = uint32_t(double(cx) / scale);
  914. scale_cy = uint32_t(double(cy) / scale);
  915. }
  916. config_set_default_uint (basicConfig, "Video", "OutputCX", scale_cx);
  917. config_set_default_uint (basicConfig, "Video", "OutputCY", scale_cy);
  918. /* don't allow OutputCX/OutputCY to be susceptible to defaults
  919. * changing */
  920. if (!config_has_user_value(basicConfig, "Video", "OutputCX") ||
  921. !config_has_user_value(basicConfig, "Video", "OutputCY")) {
  922. config_set_uint(basicConfig, "Video", "OutputCX", scale_cx);
  923. config_set_uint(basicConfig, "Video", "OutputCY", scale_cy);
  924. config_save_safe(basicConfig, "tmp", nullptr);
  925. }
  926. config_set_default_uint (basicConfig, "Video", "FPSType", 0);
  927. config_set_default_string(basicConfig, "Video", "FPSCommon", "30");
  928. config_set_default_uint (basicConfig, "Video", "FPSInt", 30);
  929. config_set_default_uint (basicConfig, "Video", "FPSNum", 30);
  930. config_set_default_uint (basicConfig, "Video", "FPSDen", 1);
  931. config_set_default_string(basicConfig, "Video", "ScaleType", "bicubic");
  932. config_set_default_string(basicConfig, "Video", "ColorFormat", "NV12");
  933. config_set_default_string(basicConfig, "Video", "ColorSpace", "601");
  934. config_set_default_string(basicConfig, "Video", "ColorRange",
  935. "Partial");
  936. config_set_default_string(basicConfig, "Audio", "MonitoringDeviceId",
  937. "default");
  938. config_set_default_string(basicConfig, "Audio", "MonitoringDeviceName",
  939. Str("Basic.Settings.Advanced.Audio.MonitoringDevice"
  940. ".Default"));
  941. config_set_default_uint (basicConfig, "Audio", "SampleRate", 44100);
  942. config_set_default_string(basicConfig, "Audio", "ChannelSetup",
  943. "Stereo");
  944. return true;
  945. }
  946. bool OBSBasic::InitBasicConfig()
  947. {
  948. ProfileScope("OBSBasic::InitBasicConfig");
  949. char configPath[512];
  950. int ret = GetProfilePath(configPath, sizeof(configPath), "");
  951. if (ret <= 0) {
  952. OBSErrorBox(nullptr, "Failed to get profile path");
  953. return false;
  954. }
  955. if (os_mkdir(configPath) == MKDIR_ERROR) {
  956. OBSErrorBox(nullptr, "Failed to create profile path");
  957. return false;
  958. }
  959. ret = GetProfilePath(configPath, sizeof(configPath), "basic.ini");
  960. if (ret <= 0) {
  961. OBSErrorBox(nullptr, "Failed to get base.ini path");
  962. return false;
  963. }
  964. int code = basicConfig.Open(configPath, CONFIG_OPEN_ALWAYS);
  965. if (code != CONFIG_SUCCESS) {
  966. OBSErrorBox(NULL, "Failed to open basic.ini: %d", code);
  967. return false;
  968. }
  969. if (config_get_string(basicConfig, "General", "Name") == nullptr) {
  970. const char *curName = config_get_string(App()->GlobalConfig(),
  971. "Basic", "Profile");
  972. config_set_string(basicConfig, "General", "Name", curName);
  973. basicConfig.SaveSafe("tmp");
  974. }
  975. return InitBasicConfigDefaults();
  976. }
  977. void OBSBasic::InitOBSCallbacks()
  978. {
  979. ProfileScope("OBSBasic::InitOBSCallbacks");
  980. signalHandlers.reserve(signalHandlers.size() + 6);
  981. signalHandlers.emplace_back(obs_get_signal_handler(), "source_remove",
  982. OBSBasic::SourceRemoved, this);
  983. signalHandlers.emplace_back(obs_get_signal_handler(), "source_activate",
  984. OBSBasic::SourceActivated, this);
  985. signalHandlers.emplace_back(obs_get_signal_handler(), "source_deactivate",
  986. OBSBasic::SourceDeactivated, this);
  987. signalHandlers.emplace_back(obs_get_signal_handler(), "source_rename",
  988. OBSBasic::SourceRenamed, this);
  989. }
  990. void OBSBasic::InitPrimitives()
  991. {
  992. ProfileScope("OBSBasic::InitPrimitives");
  993. obs_enter_graphics();
  994. gs_render_start(true);
  995. gs_vertex2f(0.0f, 0.0f);
  996. gs_vertex2f(0.0f, 1.0f);
  997. gs_vertex2f(1.0f, 1.0f);
  998. gs_vertex2f(1.0f, 0.0f);
  999. gs_vertex2f(0.0f, 0.0f);
  1000. box = gs_render_save();
  1001. gs_render_start(true);
  1002. gs_vertex2f(0.0f, 0.0f);
  1003. gs_vertex2f(0.0f, 1.0f);
  1004. boxLeft = gs_render_save();
  1005. gs_render_start(true);
  1006. gs_vertex2f(0.0f, 0.0f);
  1007. gs_vertex2f(1.0f, 0.0f);
  1008. boxTop = gs_render_save();
  1009. gs_render_start(true);
  1010. gs_vertex2f(1.0f, 0.0f);
  1011. gs_vertex2f(1.0f, 1.0f);
  1012. boxRight = gs_render_save();
  1013. gs_render_start(true);
  1014. gs_vertex2f(0.0f, 1.0f);
  1015. gs_vertex2f(1.0f, 1.0f);
  1016. boxBottom = gs_render_save();
  1017. gs_render_start(true);
  1018. for (int i = 0; i <= 360; i += (360/20)) {
  1019. float pos = RAD(float(i));
  1020. gs_vertex2f(cosf(pos), sinf(pos));
  1021. }
  1022. circle = gs_render_save();
  1023. obs_leave_graphics();
  1024. }
  1025. void OBSBasic::ReplayBufferClicked()
  1026. {
  1027. if (outputHandler->ReplayBufferActive())
  1028. StopReplayBuffer();
  1029. else
  1030. StartReplayBuffer();
  1031. };
  1032. void OBSBasic::ResetOutputs()
  1033. {
  1034. ProfileScope("OBSBasic::ResetOutputs");
  1035. const char *mode = config_get_string(basicConfig, "Output", "Mode");
  1036. bool advOut = astrcmpi(mode, "Advanced") == 0;
  1037. if (!outputHandler || !outputHandler->Active()) {
  1038. outputHandler.reset();
  1039. outputHandler.reset(advOut ?
  1040. CreateAdvancedOutputHandler(this) :
  1041. CreateSimpleOutputHandler(this));
  1042. delete replayBufferButton;
  1043. if (outputHandler->replayBuffer) {
  1044. replayBufferButton = new QPushButton(
  1045. QTStr("Basic.Main.StartReplayBuffer"),
  1046. this);
  1047. connect(replayBufferButton.data(),
  1048. &QPushButton::clicked,
  1049. this,
  1050. &OBSBasic::ReplayBufferClicked);
  1051. replayBufferButton->setProperty("themeID", "replayBufferButton");
  1052. ui->buttonsVLayout->insertWidget(2, replayBufferButton);
  1053. }
  1054. if (sysTrayReplayBuffer)
  1055. sysTrayReplayBuffer->setEnabled(
  1056. !!outputHandler->replayBuffer);
  1057. } else {
  1058. outputHandler->Update();
  1059. }
  1060. }
  1061. #define STARTUP_SEPARATOR \
  1062. "==== Startup complete ==============================================="
  1063. #define SHUTDOWN_SEPARATOR \
  1064. "==== Shutting down =================================================="
  1065. extern obs_frontend_callbacks *InitializeAPIInterface(OBSBasic *main);
  1066. #define UNSUPPORTED_ERROR \
  1067. "Failed to initialize video:\n\nRequired graphics API functionality " \
  1068. "not found. Your GPU may not be supported."
  1069. #define UNKNOWN_ERROR \
  1070. "Failed to initialize video. Your GPU may not be supported, " \
  1071. "or your graphics drivers may need to be updated."
  1072. void OBSBasic::OBSInit()
  1073. {
  1074. ProfileScope("OBSBasic::OBSInit");
  1075. const char *sceneCollection = config_get_string(App()->GlobalConfig(),
  1076. "Basic", "SceneCollectionFile");
  1077. char savePath[512];
  1078. char fileName[512];
  1079. int ret;
  1080. if (!sceneCollection)
  1081. throw "Failed to get scene collection name";
  1082. ret = snprintf(fileName, 512, "obs-studio/basic/scenes/%s.json",
  1083. sceneCollection);
  1084. if (ret <= 0)
  1085. throw "Failed to create scene collection file name";
  1086. ret = GetConfigPath(savePath, sizeof(savePath), fileName);
  1087. if (ret <= 0)
  1088. throw "Failed to get scene collection json file path";
  1089. if (!InitBasicConfig())
  1090. throw "Failed to load basic.ini";
  1091. if (!ResetAudio())
  1092. throw "Failed to initialize audio";
  1093. ret = ResetVideo();
  1094. switch (ret) {
  1095. case OBS_VIDEO_MODULE_NOT_FOUND:
  1096. throw "Failed to initialize video: Graphics module not found";
  1097. case OBS_VIDEO_NOT_SUPPORTED:
  1098. throw UNSUPPORTED_ERROR;
  1099. case OBS_VIDEO_INVALID_PARAM:
  1100. throw "Failed to initialize video: Invalid parameters";
  1101. default:
  1102. if (ret != OBS_VIDEO_SUCCESS)
  1103. throw UNKNOWN_ERROR;
  1104. }
  1105. /* load audio monitoring */
  1106. #if defined(_WIN32) || defined(__APPLE__) || HAVE_PULSEAUDIO
  1107. const char *device_name = config_get_string(basicConfig, "Audio",
  1108. "MonitoringDeviceName");
  1109. const char *device_id = config_get_string(basicConfig, "Audio",
  1110. "MonitoringDeviceId");
  1111. obs_set_audio_monitoring_device(device_name, device_id);
  1112. blog(LOG_INFO, "Audio monitoring device:\n\tname: %s\n\tid: %s",
  1113. device_name, device_id);
  1114. #endif
  1115. InitOBSCallbacks();
  1116. InitHotkeys();
  1117. api = InitializeAPIInterface(this);
  1118. AddExtraModulePaths();
  1119. blog(LOG_INFO, "---------------------------------");
  1120. obs_load_all_modules();
  1121. blog(LOG_INFO, "---------------------------------");
  1122. obs_log_loaded_modules();
  1123. blog(LOG_INFO, "---------------------------------");
  1124. obs_post_load_modules();
  1125. blog(LOG_INFO, STARTUP_SEPARATOR);
  1126. ResetOutputs();
  1127. CreateHotkeys();
  1128. if (!InitService())
  1129. throw "Failed to initialize service";
  1130. InitPrimitives();
  1131. sceneDuplicationMode = config_get_bool(App()->GlobalConfig(),
  1132. "BasicWindow", "SceneDuplicationMode");
  1133. swapScenesMode = config_get_bool(App()->GlobalConfig(),
  1134. "BasicWindow", "SwapScenesMode");
  1135. editPropertiesMode = config_get_bool(App()->GlobalConfig(),
  1136. "BasicWindow", "EditPropertiesMode");
  1137. if (!opt_studio_mode) {
  1138. SetPreviewProgramMode(config_get_bool(App()->GlobalConfig(),
  1139. "BasicWindow", "PreviewProgramMode"));
  1140. } else {
  1141. SetPreviewProgramMode(true);
  1142. opt_studio_mode = false;
  1143. }
  1144. #define SET_VISIBILITY(name, control) \
  1145. do { \
  1146. if (config_has_user_value(App()->GlobalConfig(), \
  1147. "BasicWindow", name)) { \
  1148. bool visible = config_get_bool(App()->GlobalConfig(), \
  1149. "BasicWindow", name); \
  1150. ui->control->setChecked(visible); \
  1151. } \
  1152. } while (false)
  1153. SET_VISIBILITY("ShowListboxToolbars", toggleListboxToolbars);
  1154. SET_VISIBILITY("ShowStatusBar", toggleStatusBar);
  1155. #undef SET_VISIBILITY
  1156. {
  1157. ProfileScope("OBSBasic::Load");
  1158. disableSaving--;
  1159. Load(savePath);
  1160. disableSaving++;
  1161. }
  1162. TimedCheckForUpdates();
  1163. loaded = true;
  1164. previewEnabled = config_get_bool(App()->GlobalConfig(),
  1165. "BasicWindow", "PreviewEnabled");
  1166. if (!previewEnabled && !IsPreviewProgramMode())
  1167. QMetaObject::invokeMethod(this, "EnablePreviewDisplay",
  1168. Qt::QueuedConnection,
  1169. Q_ARG(bool, previewEnabled));
  1170. #ifdef _WIN32
  1171. uint32_t winVer = GetWindowsVersion();
  1172. if (winVer > 0 && winVer < 0x602) {
  1173. bool disableAero = config_get_bool(basicConfig, "Video",
  1174. "DisableAero");
  1175. SetAeroEnabled(!disableAero);
  1176. }
  1177. #endif
  1178. RefreshSceneCollections();
  1179. RefreshProfiles();
  1180. disableSaving--;
  1181. auto addDisplay = [this] (OBSQTDisplay *window)
  1182. {
  1183. obs_display_add_draw_callback(window->GetDisplay(),
  1184. OBSBasic::RenderMain, this);
  1185. struct obs_video_info ovi;
  1186. if (obs_get_video_info(&ovi))
  1187. ResizePreview(ovi.base_width, ovi.base_height);
  1188. };
  1189. connect(ui->preview, &OBSQTDisplay::DisplayCreated, addDisplay);
  1190. #ifdef _WIN32
  1191. SetWin32DropStyle(this);
  1192. show();
  1193. #endif
  1194. bool alwaysOnTop = config_get_bool(App()->GlobalConfig(), "BasicWindow",
  1195. "AlwaysOnTop");
  1196. if (alwaysOnTop || opt_always_on_top) {
  1197. SetAlwaysOnTop(this, true);
  1198. ui->actionAlwaysOnTop->setChecked(true);
  1199. }
  1200. #ifndef _WIN32
  1201. show();
  1202. #endif
  1203. const char *dockStateStr = config_get_string(App()->GlobalConfig(),
  1204. "BasicWindow", "DockState");
  1205. if (!dockStateStr) {
  1206. on_resetUI_triggered();
  1207. } else {
  1208. QByteArray dockState =
  1209. QByteArray::fromBase64(QByteArray(dockStateStr));
  1210. if (!restoreState(dockState))
  1211. on_resetUI_triggered();
  1212. }
  1213. config_set_default_bool(App()->GlobalConfig(), "BasicWindow",
  1214. "DocksLocked", true);
  1215. bool docksLocked = config_get_bool(App()->GlobalConfig(),
  1216. "BasicWindow", "DocksLocked");
  1217. on_lockUI_toggled(docksLocked);
  1218. ui->lockUI->blockSignals(true);
  1219. ui->lockUI->setChecked(docksLocked);
  1220. ui->lockUI->blockSignals(false);
  1221. SystemTray(true);
  1222. OpenSavedProjectors();
  1223. if (windowState().testFlag(Qt::WindowFullScreen))
  1224. fullscreenInterface = true;
  1225. bool has_last_version = config_has_user_value(App()->GlobalConfig(),
  1226. "General", "LastVersion");
  1227. bool first_run = config_get_bool(App()->GlobalConfig(), "General",
  1228. "FirstRun");
  1229. if (!first_run) {
  1230. config_set_bool(App()->GlobalConfig(), "General", "FirstRun",
  1231. true);
  1232. config_save_safe(App()->GlobalConfig(), "tmp", nullptr);
  1233. }
  1234. if (!first_run && !has_last_version && !Active()) {
  1235. QString msg;
  1236. msg = QTStr("Basic.FirstStartup.RunWizard");
  1237. msg += "\n\n";
  1238. msg += QTStr("Basic.FirstStartup.RunWizard.BetaWarning");
  1239. QMessageBox::StandardButton button =
  1240. OBSMessageBox::question(this, QTStr("Basic.AutoConfig"),
  1241. msg);
  1242. if (button == QMessageBox::Yes) {
  1243. on_autoConfigure_triggered();
  1244. } else {
  1245. msg = QTStr("Basic.FirstStartup.RunWizard.NoClicked");
  1246. OBSMessageBox::information(this,
  1247. QTStr("Basic.AutoConfig"), msg);
  1248. }
  1249. }
  1250. if (config_get_bool(basicConfig, "General", "OpenStatsOnStartup"))
  1251. on_stats_triggered();
  1252. OBSBasicStats::InitializeValues();
  1253. }
  1254. void OBSBasic::InitHotkeys()
  1255. {
  1256. ProfileScope("OBSBasic::InitHotkeys");
  1257. struct obs_hotkeys_translations t = {};
  1258. t.insert = Str("Hotkeys.Insert");
  1259. t.del = Str("Hotkeys.Delete");
  1260. t.home = Str("Hotkeys.Home");
  1261. t.end = Str("Hotkeys.End");
  1262. t.page_up = Str("Hotkeys.PageUp");
  1263. t.page_down = Str("Hotkeys.PageDown");
  1264. t.num_lock = Str("Hotkeys.NumLock");
  1265. t.scroll_lock = Str("Hotkeys.ScrollLock");
  1266. t.caps_lock = Str("Hotkeys.CapsLock");
  1267. t.backspace = Str("Hotkeys.Backspace");
  1268. t.tab = Str("Hotkeys.Tab");
  1269. t.print = Str("Hotkeys.Print");
  1270. t.pause = Str("Hotkeys.Pause");
  1271. t.left = Str("Hotkeys.Left");
  1272. t.right = Str("Hotkeys.Right");
  1273. t.up = Str("Hotkeys.Up");
  1274. t.down = Str("Hotkeys.Down");
  1275. #ifdef _WIN32
  1276. t.meta = Str("Hotkeys.Windows");
  1277. #else
  1278. t.meta = Str("Hotkeys.Super");
  1279. #endif
  1280. t.menu = Str("Hotkeys.Menu");
  1281. t.space = Str("Hotkeys.Space");
  1282. t.numpad_num = Str("Hotkeys.NumpadNum");
  1283. t.numpad_multiply = Str("Hotkeys.NumpadMultiply");
  1284. t.numpad_divide = Str("Hotkeys.NumpadDivide");
  1285. t.numpad_plus = Str("Hotkeys.NumpadAdd");
  1286. t.numpad_minus = Str("Hotkeys.NumpadSubtract");
  1287. t.numpad_decimal = Str("Hotkeys.NumpadDecimal");
  1288. t.apple_keypad_num = Str("Hotkeys.AppleKeypadNum");
  1289. t.apple_keypad_multiply = Str("Hotkeys.AppleKeypadMultiply");
  1290. t.apple_keypad_divide = Str("Hotkeys.AppleKeypadDivide");
  1291. t.apple_keypad_plus = Str("Hotkeys.AppleKeypadAdd");
  1292. t.apple_keypad_minus = Str("Hotkeys.AppleKeypadSubtract");
  1293. t.apple_keypad_decimal = Str("Hotkeys.AppleKeypadDecimal");
  1294. t.apple_keypad_equal = Str("Hotkeys.AppleKeypadEqual");
  1295. t.mouse_num = Str("Hotkeys.MouseButton");
  1296. obs_hotkeys_set_translations(&t);
  1297. obs_hotkeys_set_audio_hotkeys_translations(Str("Mute"), Str("Unmute"),
  1298. Str("Push-to-mute"), Str("Push-to-talk"));
  1299. obs_hotkeys_set_sceneitem_hotkeys_translations(
  1300. Str("SceneItemShow"), Str("SceneItemHide"));
  1301. obs_hotkey_enable_callback_rerouting(true);
  1302. obs_hotkey_set_callback_routing_func(OBSBasic::HotkeyTriggered, this);
  1303. }
  1304. void OBSBasic::ProcessHotkey(obs_hotkey_id id, bool pressed)
  1305. {
  1306. obs_hotkey_trigger_routed_callback(id, pressed);
  1307. }
  1308. void OBSBasic::HotkeyTriggered(void *data, obs_hotkey_id id, bool pressed)
  1309. {
  1310. OBSBasic &basic = *static_cast<OBSBasic*>(data);
  1311. QMetaObject::invokeMethod(&basic, "ProcessHotkey",
  1312. Q_ARG(obs_hotkey_id, id), Q_ARG(bool, pressed));
  1313. }
  1314. void OBSBasic::CreateHotkeys()
  1315. {
  1316. ProfileScope("OBSBasic::CreateHotkeys");
  1317. auto LoadHotkeyData = [&](const char *name) -> OBSData
  1318. {
  1319. const char *info = config_get_string(basicConfig,
  1320. "Hotkeys", name);
  1321. if (!info)
  1322. return {};
  1323. obs_data_t *data = obs_data_create_from_json(info);
  1324. if (!data)
  1325. return {};
  1326. OBSData res = data;
  1327. obs_data_release(data);
  1328. return res;
  1329. };
  1330. auto LoadHotkey = [&](obs_hotkey_id id, const char *name)
  1331. {
  1332. obs_data_array_t *array =
  1333. obs_data_get_array(LoadHotkeyData(name), "bindings");
  1334. obs_hotkey_load(id, array);
  1335. obs_data_array_release(array);
  1336. };
  1337. auto LoadHotkeyPair = [&](obs_hotkey_pair_id id, const char *name0,
  1338. const char *name1)
  1339. {
  1340. obs_data_array_t *array0 =
  1341. obs_data_get_array(LoadHotkeyData(name0), "bindings");
  1342. obs_data_array_t *array1 =
  1343. obs_data_get_array(LoadHotkeyData(name1), "bindings");
  1344. obs_hotkey_pair_load(id, array0, array1);
  1345. obs_data_array_release(array0);
  1346. obs_data_array_release(array1);
  1347. };
  1348. #define MAKE_CALLBACK(pred, method, log_action) \
  1349. [](void *data, obs_hotkey_pair_id, obs_hotkey_t*, bool pressed) \
  1350. { \
  1351. OBSBasic &basic = *static_cast<OBSBasic*>(data); \
  1352. if (pred && pressed) { \
  1353. blog(LOG_INFO, log_action " due to hotkey"); \
  1354. method(); \
  1355. return true; \
  1356. } \
  1357. return false; \
  1358. }
  1359. streamingHotkeys = obs_hotkey_pair_register_frontend(
  1360. "OBSBasic.StartStreaming",
  1361. Str("Basic.Main.StartStreaming"),
  1362. "OBSBasic.StopStreaming",
  1363. Str("Basic.Main.StopStreaming"),
  1364. MAKE_CALLBACK(!basic.outputHandler->StreamingActive(),
  1365. basic.StartStreaming, "Starting stream"),
  1366. MAKE_CALLBACK(basic.outputHandler->StreamingActive(),
  1367. basic.StopStreaming, "Stopping stream"),
  1368. this, this);
  1369. LoadHotkeyPair(streamingHotkeys,
  1370. "OBSBasic.StartStreaming", "OBSBasic.StopStreaming");
  1371. auto cb = [] (void *data, obs_hotkey_id, obs_hotkey_t*, bool pressed)
  1372. {
  1373. OBSBasic &basic = *static_cast<OBSBasic*>(data);
  1374. if (basic.outputHandler->StreamingActive() && pressed) {
  1375. basic.ForceStopStreaming();
  1376. }
  1377. };
  1378. forceStreamingStopHotkey = obs_hotkey_register_frontend(
  1379. "OBSBasic.ForceStopStreaming",
  1380. Str("Basic.Main.ForceStopStreaming"),
  1381. cb, this);
  1382. LoadHotkey(forceStreamingStopHotkey,
  1383. "OBSBasic.ForceStopStreaming");
  1384. recordingHotkeys = obs_hotkey_pair_register_frontend(
  1385. "OBSBasic.StartRecording",
  1386. Str("Basic.Main.StartRecording"),
  1387. "OBSBasic.StopRecording",
  1388. Str("Basic.Main.StopRecording"),
  1389. MAKE_CALLBACK(!basic.outputHandler->RecordingActive(),
  1390. basic.StartRecording, "Starting recording"),
  1391. MAKE_CALLBACK(basic.outputHandler->RecordingActive(),
  1392. basic.StopRecording, "Stopping recording"),
  1393. this, this);
  1394. LoadHotkeyPair(recordingHotkeys,
  1395. "OBSBasic.StartRecording", "OBSBasic.StopRecording");
  1396. replayBufHotkeys = obs_hotkey_pair_register_frontend(
  1397. "OBSBasic.StartReplayBuffer",
  1398. Str("Basic.Main.StartReplayBuffer"),
  1399. "OBSBasic.StopReplayBuffer",
  1400. Str("Basic.Main.StopReplayBuffer"),
  1401. MAKE_CALLBACK(!basic.outputHandler->ReplayBufferActive(),
  1402. basic.StartReplayBuffer, "Starting replay buffer"),
  1403. MAKE_CALLBACK(basic.outputHandler->ReplayBufferActive(),
  1404. basic.StopReplayBuffer, "Stopping replay buffer"),
  1405. this, this);
  1406. LoadHotkeyPair(replayBufHotkeys,
  1407. "OBSBasic.StartReplayBuffer", "OBSBasic.StopReplayBuffer");
  1408. #undef MAKE_CALLBACK
  1409. auto togglePreviewProgram = [] (void *data, obs_hotkey_id,
  1410. obs_hotkey_t*, bool pressed)
  1411. {
  1412. if (pressed)
  1413. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  1414. "on_modeSwitch_clicked",
  1415. Qt::QueuedConnection);
  1416. };
  1417. togglePreviewProgramHotkey = obs_hotkey_register_frontend(
  1418. "OBSBasic.TogglePreviewProgram",
  1419. Str("Basic.TogglePreviewProgramMode"),
  1420. togglePreviewProgram, this);
  1421. LoadHotkey(togglePreviewProgramHotkey, "OBSBasic.TogglePreviewProgram");
  1422. auto transition = [] (void *data, obs_hotkey_id, obs_hotkey_t*,
  1423. bool pressed)
  1424. {
  1425. if (pressed)
  1426. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  1427. "TransitionClicked",
  1428. Qt::QueuedConnection);
  1429. };
  1430. transitionHotkey = obs_hotkey_register_frontend(
  1431. "OBSBasic.Transition",
  1432. Str("Transition"), transition, this);
  1433. LoadHotkey(transitionHotkey, "OBSBasic.Transition");
  1434. }
  1435. void OBSBasic::ClearHotkeys()
  1436. {
  1437. obs_hotkey_pair_unregister(streamingHotkeys);
  1438. obs_hotkey_pair_unregister(recordingHotkeys);
  1439. obs_hotkey_pair_unregister(replayBufHotkeys);
  1440. obs_hotkey_unregister(forceStreamingStopHotkey);
  1441. obs_hotkey_unregister(togglePreviewProgramHotkey);
  1442. obs_hotkey_unregister(transitionHotkey);
  1443. }
  1444. OBSBasic::~OBSBasic()
  1445. {
  1446. if (updateCheckThread && updateCheckThread->isRunning())
  1447. updateCheckThread->wait();
  1448. delete programOptions;
  1449. delete program;
  1450. /* XXX: any obs data must be released before calling obs_shutdown.
  1451. * currently, we can't automate this with C++ RAII because of the
  1452. * delicate nature of obs_shutdown needing to be freed before the UI
  1453. * can be freed, and we have no control over the destruction order of
  1454. * the Qt UI stuff, so we have to manually clear any references to
  1455. * libobs. */
  1456. delete cpuUsageTimer;
  1457. os_cpu_usage_info_destroy(cpuUsageInfo);
  1458. obs_hotkey_set_callback_routing_func(nullptr, nullptr);
  1459. ClearHotkeys();
  1460. service = nullptr;
  1461. outputHandler.reset();
  1462. if (interaction)
  1463. delete interaction;
  1464. if (properties)
  1465. delete properties;
  1466. if (filters)
  1467. delete filters;
  1468. if (transformWindow)
  1469. delete transformWindow;
  1470. if (advAudioWindow)
  1471. delete advAudioWindow;
  1472. obs_display_remove_draw_callback(ui->preview->GetDisplay(),
  1473. OBSBasic::RenderMain, this);
  1474. obs_enter_graphics();
  1475. gs_vertexbuffer_destroy(box);
  1476. gs_vertexbuffer_destroy(boxLeft);
  1477. gs_vertexbuffer_destroy(boxTop);
  1478. gs_vertexbuffer_destroy(boxRight);
  1479. gs_vertexbuffer_destroy(boxBottom);
  1480. gs_vertexbuffer_destroy(circle);
  1481. obs_leave_graphics();
  1482. /* When shutting down, sometimes source references can get in to the
  1483. * event queue, and if we don't forcibly process those events they
  1484. * won't get processed until after obs_shutdown has been called. I
  1485. * really wish there were a more elegant way to deal with this via C++,
  1486. * but Qt doesn't use C++ in a normal way, so you can't really rely on
  1487. * normal C++ behavior for your data to be freed in the order that you
  1488. * expect or want it to. */
  1489. QApplication::sendPostedEvents(this);
  1490. config_set_int(App()->GlobalConfig(), "General", "LastVersion",
  1491. LIBOBS_API_VER);
  1492. bool alwaysOnTop = IsAlwaysOnTop(this);
  1493. config_set_bool(App()->GlobalConfig(), "BasicWindow", "PreviewEnabled",
  1494. previewEnabled);
  1495. config_set_bool(App()->GlobalConfig(), "BasicWindow", "AlwaysOnTop",
  1496. alwaysOnTop);
  1497. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  1498. "SceneDuplicationMode", sceneDuplicationMode);
  1499. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  1500. "SwapScenesMode", swapScenesMode);
  1501. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  1502. "EditPropertiesMode", editPropertiesMode);
  1503. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  1504. "PreviewProgramMode", IsPreviewProgramMode());
  1505. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  1506. "DocksLocked", ui->lockUI->isChecked());
  1507. config_save_safe(App()->GlobalConfig(), "tmp", nullptr);
  1508. #ifdef _WIN32
  1509. uint32_t winVer = GetWindowsVersion();
  1510. if (winVer > 0 && winVer < 0x602) {
  1511. bool disableAero = config_get_bool(basicConfig, "Video",
  1512. "DisableAero");
  1513. if (disableAero) {
  1514. SetAeroEnabled(true);
  1515. }
  1516. }
  1517. #endif
  1518. }
  1519. void OBSBasic::SaveProjectNow()
  1520. {
  1521. if (disableSaving)
  1522. return;
  1523. projectChanged = true;
  1524. SaveProjectDeferred();
  1525. }
  1526. void OBSBasic::SaveProject()
  1527. {
  1528. if (disableSaving)
  1529. return;
  1530. projectChanged = true;
  1531. QMetaObject::invokeMethod(this, "SaveProjectDeferred",
  1532. Qt::QueuedConnection);
  1533. }
  1534. void OBSBasic::SaveProjectDeferred()
  1535. {
  1536. if (disableSaving)
  1537. return;
  1538. if (!projectChanged)
  1539. return;
  1540. projectChanged = false;
  1541. const char *sceneCollection = config_get_string(App()->GlobalConfig(),
  1542. "Basic", "SceneCollectionFile");
  1543. char savePath[512];
  1544. char fileName[512];
  1545. int ret;
  1546. if (!sceneCollection)
  1547. return;
  1548. ret = snprintf(fileName, 512, "obs-studio/basic/scenes/%s.json",
  1549. sceneCollection);
  1550. if (ret <= 0)
  1551. return;
  1552. ret = GetConfigPath(savePath, sizeof(savePath), fileName);
  1553. if (ret <= 0)
  1554. return;
  1555. Save(savePath);
  1556. }
  1557. OBSScene OBSBasic::GetCurrentScene()
  1558. {
  1559. QListWidgetItem *item = ui->scenes->currentItem();
  1560. return item ? GetOBSRef<OBSScene>(item) : nullptr;
  1561. }
  1562. OBSSceneItem OBSBasic::GetSceneItem(QListWidgetItem *item)
  1563. {
  1564. return item ? GetOBSRef<OBSSceneItem>(item) : nullptr;
  1565. }
  1566. OBSSceneItem OBSBasic::GetCurrentSceneItem()
  1567. {
  1568. return GetSceneItem(GetTopSelectedSourceItem());
  1569. }
  1570. void OBSBasic::UpdatePreviewScalingMenu()
  1571. {
  1572. bool fixedScaling = ui->preview->IsFixedScaling();
  1573. float scalingAmount = ui->preview->GetScalingAmount();
  1574. if (!fixedScaling) {
  1575. ui->actionScaleWindow->setChecked(true);
  1576. ui->actionScaleCanvas->setChecked(false);
  1577. ui->actionScaleOutput->setChecked(false);
  1578. return;
  1579. }
  1580. obs_video_info ovi;
  1581. obs_get_video_info(&ovi);
  1582. ui->actionScaleWindow->setChecked(false);
  1583. ui->actionScaleCanvas->setChecked(scalingAmount == 1.0f);
  1584. ui->actionScaleOutput->setChecked(
  1585. scalingAmount == float(ovi.output_width) / float(ovi.base_width));
  1586. }
  1587. void OBSBasic::UpdateSources(OBSScene scene)
  1588. {
  1589. ClearListItems(ui->sources);
  1590. obs_scene_enum_items(scene,
  1591. [] (obs_scene_t *scene, obs_sceneitem_t *item, void *p)
  1592. {
  1593. OBSBasic *window = static_cast<OBSBasic*>(p);
  1594. window->InsertSceneItem(item);
  1595. UNUSED_PARAMETER(scene);
  1596. return true;
  1597. }, this);
  1598. }
  1599. void OBSBasic::InsertSceneItem(obs_sceneitem_t *item)
  1600. {
  1601. QListWidgetItem *listItem = new QListWidgetItem();
  1602. SetOBSRef(listItem, OBSSceneItem(item));
  1603. ui->sources->insertItem(0, listItem);
  1604. ui->sources->setCurrentRow(0, QItemSelectionModel::ClearAndSelect);
  1605. SetupVisibilityItem(ui->sources, listItem, item);
  1606. }
  1607. void OBSBasic::CreateInteractionWindow(obs_source_t *source)
  1608. {
  1609. if (interaction)
  1610. interaction->close();
  1611. interaction = new OBSBasicInteraction(this, source);
  1612. interaction->Init();
  1613. interaction->setAttribute(Qt::WA_DeleteOnClose, true);
  1614. }
  1615. void OBSBasic::CreatePropertiesWindow(obs_source_t *source)
  1616. {
  1617. if (properties)
  1618. properties->close();
  1619. properties = new OBSBasicProperties(this, source);
  1620. properties->Init();
  1621. properties->setAttribute(Qt::WA_DeleteOnClose, true);
  1622. }
  1623. void OBSBasic::CreateFiltersWindow(obs_source_t *source)
  1624. {
  1625. if (filters)
  1626. filters->close();
  1627. filters = new OBSBasicFilters(this, source);
  1628. filters->Init();
  1629. filters->setAttribute(Qt::WA_DeleteOnClose, true);
  1630. }
  1631. /* Qt callbacks for invokeMethod */
  1632. void OBSBasic::AddScene(OBSSource source)
  1633. {
  1634. const char *name = obs_source_get_name(source);
  1635. obs_scene_t *scene = obs_scene_from_source(source);
  1636. QListWidgetItem *item = new QListWidgetItem(QT_UTF8(name));
  1637. SetOBSRef(item, OBSScene(scene));
  1638. ui->scenes->addItem(item);
  1639. obs_hotkey_register_source(source, "OBSBasic.SelectScene",
  1640. Str("Basic.Hotkeys.SelectScene"),
  1641. [](void *data,
  1642. obs_hotkey_id, obs_hotkey_t*, bool pressed)
  1643. {
  1644. OBSBasic *main =
  1645. reinterpret_cast<OBSBasic*>(App()->GetMainWindow());
  1646. auto potential_source = static_cast<obs_source_t*>(data);
  1647. auto source = obs_source_get_ref(potential_source);
  1648. if (source && pressed)
  1649. main->SetCurrentScene(source);
  1650. obs_source_release(source);
  1651. }, static_cast<obs_source_t*>(source));
  1652. signal_handler_t *handler = obs_source_get_signal_handler(source);
  1653. SignalContainer<OBSScene> container;
  1654. container.ref = scene;
  1655. container.handlers.assign({
  1656. std::make_shared<OBSSignal>(handler, "item_add",
  1657. OBSBasic::SceneItemAdded, this),
  1658. std::make_shared<OBSSignal>(handler, "item_remove",
  1659. OBSBasic::SceneItemRemoved, this),
  1660. std::make_shared<OBSSignal>(handler, "item_select",
  1661. OBSBasic::SceneItemSelected, this),
  1662. std::make_shared<OBSSignal>(handler, "item_deselect",
  1663. OBSBasic::SceneItemDeselected, this),
  1664. std::make_shared<OBSSignal>(handler, "reorder",
  1665. OBSBasic::SceneReordered, this),
  1666. });
  1667. item->setData(static_cast<int>(QtDataRole::OBSSignals),
  1668. QVariant::fromValue(container));
  1669. /* if the scene already has items (a duplicated scene) add them */
  1670. auto addSceneItem = [this] (obs_sceneitem_t *item)
  1671. {
  1672. AddSceneItem(item);
  1673. };
  1674. using addSceneItem_t = decltype(addSceneItem);
  1675. obs_scene_enum_items(scene,
  1676. [] (obs_scene_t*, obs_sceneitem_t *item, void *param)
  1677. {
  1678. addSceneItem_t *func;
  1679. func = reinterpret_cast<addSceneItem_t*>(param);
  1680. (*func)(item);
  1681. return true;
  1682. }, &addSceneItem);
  1683. SaveProject();
  1684. if (!disableSaving) {
  1685. obs_source_t *source = obs_scene_get_source(scene);
  1686. blog(LOG_INFO, "User added scene '%s'",
  1687. obs_source_get_name(source));
  1688. }
  1689. if (api)
  1690. api->on_event(OBS_FRONTEND_EVENT_SCENE_LIST_CHANGED);
  1691. }
  1692. void OBSBasic::RemoveScene(OBSSource source)
  1693. {
  1694. obs_scene_t *scene = obs_scene_from_source(source);
  1695. QListWidgetItem *sel = nullptr;
  1696. int count = ui->scenes->count();
  1697. for (int i = 0; i < count; i++) {
  1698. auto item = ui->scenes->item(i);
  1699. auto cur_scene = GetOBSRef<OBSScene>(item);
  1700. if (cur_scene != scene)
  1701. continue;
  1702. sel = item;
  1703. break;
  1704. }
  1705. if (sel != nullptr) {
  1706. if (sel == ui->scenes->currentItem())
  1707. ClearListItems(ui->sources);
  1708. delete sel;
  1709. }
  1710. SaveProject();
  1711. if (!disableSaving) {
  1712. blog(LOG_INFO, "User Removed scene '%s'",
  1713. obs_source_get_name(source));
  1714. }
  1715. if (api)
  1716. api->on_event(OBS_FRONTEND_EVENT_SCENE_LIST_CHANGED);
  1717. }
  1718. void OBSBasic::AddSceneItem(OBSSceneItem item)
  1719. {
  1720. obs_scene_t *scene = obs_sceneitem_get_scene(item);
  1721. if (GetCurrentScene() == scene)
  1722. InsertSceneItem(item);
  1723. SaveProject();
  1724. if (!disableSaving) {
  1725. obs_source_t *sceneSource = obs_scene_get_source(scene);
  1726. obs_source_t *itemSource = obs_sceneitem_get_source(item);
  1727. blog(LOG_INFO, "User added source '%s' (%s) to scene '%s'",
  1728. obs_source_get_name(itemSource),
  1729. obs_source_get_id(itemSource),
  1730. obs_source_get_name(sceneSource));
  1731. }
  1732. }
  1733. void OBSBasic::RemoveSceneItem(OBSSceneItem item)
  1734. {
  1735. for (int i = 0; i < ui->sources->count(); i++) {
  1736. QListWidgetItem *listItem = ui->sources->item(i);
  1737. if (GetOBSRef<OBSSceneItem>(listItem) == item) {
  1738. DeleteListItem(ui->sources, listItem);
  1739. break;
  1740. }
  1741. }
  1742. SaveProject();
  1743. if (!disableSaving) {
  1744. obs_scene_t *scene = obs_sceneitem_get_scene(item);
  1745. obs_source_t *sceneSource = obs_scene_get_source(scene);
  1746. obs_source_t *itemSource = obs_sceneitem_get_source(item);
  1747. blog(LOG_INFO, "User Removed source '%s' (%s) from scene '%s'",
  1748. obs_source_get_name(itemSource),
  1749. obs_source_get_id(itemSource),
  1750. obs_source_get_name(sceneSource));
  1751. }
  1752. }
  1753. void OBSBasic::UpdateSceneSelection(OBSSource source)
  1754. {
  1755. if (source) {
  1756. obs_scene_t *scene = obs_scene_from_source(source);
  1757. const char *name = obs_source_get_name(source);
  1758. if (!scene)
  1759. return;
  1760. QList<QListWidgetItem*> items =
  1761. ui->scenes->findItems(QT_UTF8(name), Qt::MatchExactly);
  1762. if (items.count()) {
  1763. sceneChanging = true;
  1764. ui->scenes->setCurrentItem(items.first());
  1765. sceneChanging = false;
  1766. UpdateSources(scene);
  1767. }
  1768. }
  1769. }
  1770. static void RenameListValues(QListWidget *listWidget, const QString &newName,
  1771. const QString &prevName)
  1772. {
  1773. QList<QListWidgetItem*> items =
  1774. listWidget->findItems(prevName, Qt::MatchExactly);
  1775. for (int i = 0; i < items.count(); i++)
  1776. items[i]->setText(newName);
  1777. }
  1778. void OBSBasic::RenameSources(QString newName, QString prevName)
  1779. {
  1780. RenameListValues(ui->scenes, newName, prevName);
  1781. for (size_t i = 0; i < volumes.size(); i++) {
  1782. if (volumes[i]->GetName().compare(prevName) == 0)
  1783. volumes[i]->SetName(newName);
  1784. }
  1785. std::string newText = newName.toUtf8().constData();
  1786. std::string prevText = prevName.toUtf8().constData();
  1787. for (size_t j = 0; j < projectorArray.size(); j++) {
  1788. if (projectorArray.at(j) == prevText)
  1789. projectorArray.at(j) = newText;
  1790. }
  1791. SaveProject();
  1792. }
  1793. void OBSBasic::SelectSceneItem(OBSScene scene, OBSSceneItem item, bool select)
  1794. {
  1795. SignalBlocker sourcesSignalBlocker(ui->sources);
  1796. if (scene != GetCurrentScene() || ignoreSelectionUpdate)
  1797. return;
  1798. for (int i = 0; i < ui->sources->count(); i++) {
  1799. QListWidgetItem *witem = ui->sources->item(i);
  1800. QVariant data =
  1801. witem->data(static_cast<int>(QtDataRole::OBSRef));
  1802. if (!data.canConvert<OBSSceneItem>())
  1803. continue;
  1804. if (item != data.value<OBSSceneItem>())
  1805. continue;
  1806. witem->setSelected(select);
  1807. break;
  1808. }
  1809. }
  1810. static inline bool SourceMixerHidden(obs_source_t *source)
  1811. {
  1812. obs_data_t *priv_settings = obs_source_get_private_settings(source);
  1813. bool hidden = obs_data_get_bool(priv_settings, "mixer_hidden");
  1814. obs_data_release(priv_settings);
  1815. return hidden;
  1816. }
  1817. static inline void SetSourceMixerHidden(obs_source_t *source, bool hidden)
  1818. {
  1819. obs_data_t *priv_settings = obs_source_get_private_settings(source);
  1820. obs_data_set_bool(priv_settings, "mixer_hidden", hidden);
  1821. obs_data_release(priv_settings);
  1822. }
  1823. void OBSBasic::GetAudioSourceFilters()
  1824. {
  1825. QAction *action = reinterpret_cast<QAction*>(sender());
  1826. VolControl *vol = action->property("volControl").value<VolControl*>();
  1827. obs_source_t *source = vol->GetSource();
  1828. CreateFiltersWindow(source);
  1829. }
  1830. void OBSBasic::GetAudioSourceProperties()
  1831. {
  1832. QAction *action = reinterpret_cast<QAction*>(sender());
  1833. VolControl *vol = action->property("volControl").value<VolControl*>();
  1834. obs_source_t *source = vol->GetSource();
  1835. CreatePropertiesWindow(source);
  1836. }
  1837. void OBSBasic::HideAudioControl()
  1838. {
  1839. QAction *action = reinterpret_cast<QAction*>(sender());
  1840. VolControl *vol = action->property("volControl").value<VolControl*>();
  1841. obs_source_t *source = vol->GetSource();
  1842. if (!SourceMixerHidden(source)) {
  1843. SetSourceMixerHidden(source, true);
  1844. DeactivateAudioSource(source);
  1845. }
  1846. }
  1847. void OBSBasic::UnhideAllAudioControls()
  1848. {
  1849. auto UnhideAudioMixer = [this] (obs_source_t *source) /* -- */
  1850. {
  1851. if (!obs_source_active(source))
  1852. return true;
  1853. if (!SourceMixerHidden(source))
  1854. return true;
  1855. SetSourceMixerHidden(source, false);
  1856. ActivateAudioSource(source);
  1857. return true;
  1858. };
  1859. using UnhideAudioMixer_t = decltype(UnhideAudioMixer);
  1860. auto PreEnum = [] (void *data, obs_source_t *source) -> bool /* -- */
  1861. {
  1862. return (*reinterpret_cast<UnhideAudioMixer_t *>(data))(source);
  1863. };
  1864. obs_enum_sources(PreEnum, &UnhideAudioMixer);
  1865. }
  1866. void OBSBasic::ToggleHideMixer()
  1867. {
  1868. OBSSceneItem item = GetCurrentSceneItem();
  1869. OBSSource source = obs_sceneitem_get_source(item);
  1870. if (!SourceMixerHidden(source)) {
  1871. SetSourceMixerHidden(source, true);
  1872. DeactivateAudioSource(source);
  1873. } else {
  1874. SetSourceMixerHidden(source, false);
  1875. ActivateAudioSource(source);
  1876. }
  1877. }
  1878. void OBSBasic::MixerRenameSource()
  1879. {
  1880. QAction *action = reinterpret_cast<QAction*>(sender());
  1881. VolControl *vol = action->property("volControl").value<VolControl*>();
  1882. OBSSource source = vol->GetSource();
  1883. const char *prevName = obs_source_get_name(source);
  1884. for (;;) {
  1885. string name;
  1886. bool accepted = NameDialog::AskForName(this,
  1887. QTStr("Basic.Main.MixerRename.Title"),
  1888. QTStr("Basic.Main.MixerRename.Text"),
  1889. name,
  1890. QT_UTF8(prevName));
  1891. if (!accepted)
  1892. return;
  1893. if (name.empty()) {
  1894. OBSMessageBox::information(this,
  1895. QTStr("NoNameEntered.Title"),
  1896. QTStr("NoNameEntered.Text"));
  1897. continue;
  1898. }
  1899. OBSSource sourceTest = obs_get_source_by_name(name.c_str());
  1900. obs_source_release(sourceTest);
  1901. if (sourceTest) {
  1902. OBSMessageBox::information(this,
  1903. QTStr("NameExists.Title"),
  1904. QTStr("NameExists.Text"));
  1905. continue;
  1906. }
  1907. obs_source_set_name(source, name.c_str());
  1908. break;
  1909. }
  1910. }
  1911. void OBSBasic::VolControlContextMenu()
  1912. {
  1913. VolControl *vol = reinterpret_cast<VolControl*>(sender());
  1914. /* ------------------- */
  1915. QAction hideAction(QTStr("Hide"), this);
  1916. QAction unhideAllAction(QTStr("UnhideAll"), this);
  1917. QAction mixerRenameAction(QTStr("Rename"), this);
  1918. QAction filtersAction(QTStr("Filters"), this);
  1919. QAction propertiesAction(QTStr("Properties"), this);
  1920. QAction advPropAction(QTStr("Basic.MainMenu.Edit.AdvAudio"), this);
  1921. /* ------------------- */
  1922. connect(&hideAction, &QAction::triggered,
  1923. this, &OBSBasic::HideAudioControl,
  1924. Qt::DirectConnection);
  1925. connect(&unhideAllAction, &QAction::triggered,
  1926. this, &OBSBasic::UnhideAllAudioControls,
  1927. Qt::DirectConnection);
  1928. connect(&mixerRenameAction, &QAction::triggered,
  1929. this, &OBSBasic::MixerRenameSource,
  1930. Qt::DirectConnection);
  1931. connect(&filtersAction, &QAction::triggered,
  1932. this, &OBSBasic::GetAudioSourceFilters,
  1933. Qt::DirectConnection);
  1934. connect(&propertiesAction, &QAction::triggered,
  1935. this, &OBSBasic::GetAudioSourceProperties,
  1936. Qt::DirectConnection);
  1937. connect(&advPropAction, &QAction::triggered,
  1938. this, &OBSBasic::on_actionAdvAudioProperties_triggered,
  1939. Qt::DirectConnection);
  1940. /* ------------------- */
  1941. hideAction.setProperty("volControl",
  1942. QVariant::fromValue<VolControl*>(vol));
  1943. mixerRenameAction.setProperty("volControl",
  1944. QVariant::fromValue<VolControl*>(vol));
  1945. filtersAction.setProperty("volControl",
  1946. QVariant::fromValue<VolControl*>(vol));
  1947. propertiesAction.setProperty("volControl",
  1948. QVariant::fromValue<VolControl*>(vol));
  1949. /* ------------------- */
  1950. QMenu popup(this);
  1951. popup.addAction(&unhideAllAction);
  1952. popup.addAction(&hideAction);
  1953. popup.addAction(&mixerRenameAction);
  1954. popup.addSeparator();
  1955. popup.addAction(&filtersAction);
  1956. popup.addAction(&propertiesAction);
  1957. popup.addAction(&advPropAction);
  1958. popup.exec(QCursor::pos());
  1959. }
  1960. void OBSBasic::on_mixerScrollArea_customContextMenuRequested()
  1961. {
  1962. QAction unhideAllAction(QTStr("UnhideAll"), this);
  1963. QAction advPropAction(QTStr("Basic.MainMenu.Edit.AdvAudio"), this);
  1964. /* ------------------- */
  1965. connect(&unhideAllAction, &QAction::triggered,
  1966. this, &OBSBasic::UnhideAllAudioControls,
  1967. Qt::DirectConnection);
  1968. connect(&advPropAction, &QAction::triggered,
  1969. this, &OBSBasic::on_actionAdvAudioProperties_triggered,
  1970. Qt::DirectConnection);
  1971. /* ------------------- */
  1972. QMenu popup(this);
  1973. popup.addAction(&unhideAllAction);
  1974. popup.addSeparator();
  1975. popup.addAction(&advPropAction);
  1976. popup.exec(QCursor::pos());
  1977. }
  1978. void OBSBasic::ActivateAudioSource(OBSSource source)
  1979. {
  1980. if (SourceMixerHidden(source))
  1981. return;
  1982. VolControl *vol = new VolControl(source, true);
  1983. vol->setContextMenuPolicy(Qt::CustomContextMenu);
  1984. connect(vol, &QWidget::customContextMenuRequested,
  1985. this, &OBSBasic::VolControlContextMenu);
  1986. connect(vol, &VolControl::ConfigClicked,
  1987. this, &OBSBasic::VolControlContextMenu);
  1988. volumes.push_back(vol);
  1989. ui->volumeWidgets->layout()->addWidget(vol);
  1990. }
  1991. void OBSBasic::DeactivateAudioSource(OBSSource source)
  1992. {
  1993. for (size_t i = 0; i < volumes.size(); i++) {
  1994. if (volumes[i]->GetSource() == source) {
  1995. delete volumes[i];
  1996. volumes.erase(volumes.begin() + i);
  1997. break;
  1998. }
  1999. }
  2000. }
  2001. bool OBSBasic::QueryRemoveSource(obs_source_t *source)
  2002. {
  2003. if (obs_source_get_type(source) == OBS_SOURCE_TYPE_SCENE) {
  2004. int count = ui->scenes->count();
  2005. if (count == 1) {
  2006. OBSMessageBox::information(this,
  2007. QTStr("FinalScene.Title"),
  2008. QTStr("FinalScene.Text"));
  2009. return false;
  2010. }
  2011. }
  2012. const char *name = obs_source_get_name(source);
  2013. QString text = QTStr("ConfirmRemove.Text");
  2014. text.replace("$1", QT_UTF8(name));
  2015. QMessageBox remove_source(this);
  2016. remove_source.setText(text);
  2017. QAbstractButton *Yes = remove_source.addButton(QTStr("Yes"),
  2018. QMessageBox::YesRole);
  2019. remove_source.addButton(QTStr("No"), QMessageBox::NoRole);
  2020. remove_source.setIcon(QMessageBox::Question);
  2021. remove_source.setWindowTitle(QTStr("ConfirmRemove.Title"));
  2022. remove_source.exec();
  2023. return Yes == remove_source.clickedButton();
  2024. }
  2025. #define UPDATE_CHECK_INTERVAL (60*60*24*4) /* 4 days */
  2026. #ifdef UPDATE_SPARKLE
  2027. void init_sparkle_updater(bool update_to_undeployed);
  2028. void trigger_sparkle_update();
  2029. #endif
  2030. void OBSBasic::TimedCheckForUpdates()
  2031. {
  2032. if (!config_get_bool(App()->GlobalConfig(), "General",
  2033. "EnableAutoUpdates"))
  2034. return;
  2035. #ifdef UPDATE_SPARKLE
  2036. init_sparkle_updater(config_get_bool(App()->GlobalConfig(), "General",
  2037. "UpdateToUndeployed"));
  2038. #elif ENABLE_WIN_UPDATER
  2039. long long lastUpdate = config_get_int(App()->GlobalConfig(), "General",
  2040. "LastUpdateCheck");
  2041. uint32_t lastVersion = config_get_int(App()->GlobalConfig(), "General",
  2042. "LastVersion");
  2043. if (lastVersion < LIBOBS_API_VER) {
  2044. lastUpdate = 0;
  2045. config_set_int(App()->GlobalConfig(), "General",
  2046. "LastUpdateCheck", 0);
  2047. }
  2048. long long t = (long long)time(nullptr);
  2049. long long secs = t - lastUpdate;
  2050. if (secs > UPDATE_CHECK_INTERVAL)
  2051. CheckForUpdates(false);
  2052. #endif
  2053. }
  2054. void OBSBasic::CheckForUpdates(bool manualUpdate)
  2055. {
  2056. #ifdef UPDATE_SPARKLE
  2057. trigger_sparkle_update();
  2058. #elif ENABLE_WIN_UPDATER
  2059. ui->actionCheckForUpdates->setEnabled(false);
  2060. if (updateCheckThread && updateCheckThread->isRunning())
  2061. return;
  2062. updateCheckThread = new AutoUpdateThread(manualUpdate);
  2063. updateCheckThread->start();
  2064. #endif
  2065. UNUSED_PARAMETER(manualUpdate);
  2066. }
  2067. void OBSBasic::updateCheckFinished()
  2068. {
  2069. ui->actionCheckForUpdates->setEnabled(true);
  2070. }
  2071. void OBSBasic::DuplicateSelectedScene()
  2072. {
  2073. OBSScene curScene = GetCurrentScene();
  2074. if (!curScene)
  2075. return;
  2076. OBSSource curSceneSource = obs_scene_get_source(curScene);
  2077. QString format{obs_source_get_name(curSceneSource)};
  2078. format += " %1";
  2079. int i = 2;
  2080. QString placeHolderText = format.arg(i);
  2081. obs_source_t *source = nullptr;
  2082. while ((source = obs_get_source_by_name(QT_TO_UTF8(placeHolderText)))) {
  2083. obs_source_release(source);
  2084. placeHolderText = format.arg(++i);
  2085. }
  2086. for (;;) {
  2087. string name;
  2088. bool accepted = NameDialog::AskForName(this,
  2089. QTStr("Basic.Main.AddSceneDlg.Title"),
  2090. QTStr("Basic.Main.AddSceneDlg.Text"),
  2091. name,
  2092. placeHolderText);
  2093. if (!accepted)
  2094. return;
  2095. if (name.empty()) {
  2096. OBSMessageBox::information(this,
  2097. QTStr("NoNameEntered.Title"),
  2098. QTStr("NoNameEntered.Text"));
  2099. continue;
  2100. }
  2101. obs_source_t *source = obs_get_source_by_name(name.c_str());
  2102. if (source) {
  2103. OBSMessageBox::information(this,
  2104. QTStr("NameExists.Title"),
  2105. QTStr("NameExists.Text"));
  2106. obs_source_release(source);
  2107. continue;
  2108. }
  2109. obs_scene_t *scene = obs_scene_duplicate(curScene,
  2110. name.c_str(), OBS_SCENE_DUP_REFS);
  2111. source = obs_scene_get_source(scene);
  2112. AddScene(source);
  2113. SetCurrentScene(source, true);
  2114. obs_scene_release(scene);
  2115. break;
  2116. }
  2117. }
  2118. void OBSBasic::RemoveSelectedScene()
  2119. {
  2120. OBSScene scene = GetCurrentScene();
  2121. if (scene) {
  2122. obs_source_t *source = obs_scene_get_source(scene);
  2123. if (QueryRemoveSource(source)) {
  2124. obs_source_remove(source);
  2125. if (api)
  2126. api->on_event(OBS_FRONTEND_EVENT_SCENE_LIST_CHANGED);
  2127. }
  2128. }
  2129. }
  2130. void OBSBasic::RemoveSelectedSceneItem()
  2131. {
  2132. OBSSceneItem item = GetCurrentSceneItem();
  2133. if (item) {
  2134. obs_source_t *source = obs_sceneitem_get_source(item);
  2135. if (QueryRemoveSource(source))
  2136. obs_sceneitem_remove(item);
  2137. }
  2138. }
  2139. struct ReorderInfo {
  2140. int idx = 0;
  2141. OBSBasic *window;
  2142. inline ReorderInfo(OBSBasic *window_) : window(window_) {}
  2143. };
  2144. void OBSBasic::ReorderSceneItem(obs_sceneitem_t *item, size_t idx)
  2145. {
  2146. int count = ui->sources->count();
  2147. int idx_inv = count - (int)idx - 1;
  2148. for (int i = 0; i < count; i++) {
  2149. QListWidgetItem *listItem = ui->sources->item(i);
  2150. OBSSceneItem sceneItem = GetOBSRef<OBSSceneItem>(listItem);
  2151. if (sceneItem == item) {
  2152. if ((int)idx_inv != i) {
  2153. bool sel = (ui->sources->currentRow() == i);
  2154. listItem = TakeListItem(ui->sources, i);
  2155. if (listItem) {
  2156. ui->sources->insertItem(idx_inv,
  2157. listItem);
  2158. SetupVisibilityItem(ui->sources,
  2159. listItem, item);
  2160. if (sel)
  2161. ui->sources->setCurrentRow(
  2162. idx_inv);
  2163. }
  2164. }
  2165. break;
  2166. }
  2167. }
  2168. }
  2169. void OBSBasic::ReorderSources(OBSScene scene)
  2170. {
  2171. ReorderInfo info(this);
  2172. if (scene != GetCurrentScene() || ui->sources->IgnoreReorder())
  2173. return;
  2174. obs_scene_enum_items(scene,
  2175. [] (obs_scene_t*, obs_sceneitem_t *item, void *p)
  2176. {
  2177. ReorderInfo *info =
  2178. reinterpret_cast<ReorderInfo*>(p);
  2179. info->window->ReorderSceneItem(item,
  2180. info->idx++);
  2181. return true;
  2182. }, &info);
  2183. SaveProject();
  2184. }
  2185. /* OBS Callbacks */
  2186. void OBSBasic::SceneReordered(void *data, calldata_t *params)
  2187. {
  2188. OBSBasic *window = static_cast<OBSBasic*>(data);
  2189. obs_scene_t *scene = (obs_scene_t*)calldata_ptr(params, "scene");
  2190. QMetaObject::invokeMethod(window, "ReorderSources",
  2191. Q_ARG(OBSScene, OBSScene(scene)));
  2192. }
  2193. void OBSBasic::SceneItemAdded(void *data, calldata_t *params)
  2194. {
  2195. OBSBasic *window = static_cast<OBSBasic*>(data);
  2196. obs_sceneitem_t *item = (obs_sceneitem_t*)calldata_ptr(params, "item");
  2197. QMetaObject::invokeMethod(window, "AddSceneItem",
  2198. Q_ARG(OBSSceneItem, OBSSceneItem(item)));
  2199. }
  2200. void OBSBasic::SceneItemRemoved(void *data, calldata_t *params)
  2201. {
  2202. OBSBasic *window = static_cast<OBSBasic*>(data);
  2203. obs_sceneitem_t *item = (obs_sceneitem_t*)calldata_ptr(params, "item");
  2204. QMetaObject::invokeMethod(window, "RemoveSceneItem",
  2205. Q_ARG(OBSSceneItem, OBSSceneItem(item)));
  2206. }
  2207. void OBSBasic::SceneItemSelected(void *data, calldata_t *params)
  2208. {
  2209. OBSBasic *window = static_cast<OBSBasic*>(data);
  2210. obs_scene_t *scene = (obs_scene_t*)calldata_ptr(params, "scene");
  2211. obs_sceneitem_t *item = (obs_sceneitem_t*)calldata_ptr(params, "item");
  2212. QMetaObject::invokeMethod(window, "SelectSceneItem",
  2213. Q_ARG(OBSScene, scene), Q_ARG(OBSSceneItem, item),
  2214. Q_ARG(bool, true));
  2215. window->ui->actionCopySource->setEnabled(true);
  2216. }
  2217. void OBSBasic::SceneItemDeselected(void *data, calldata_t *params)
  2218. {
  2219. OBSBasic *window = static_cast<OBSBasic*>(data);
  2220. obs_scene_t *scene = (obs_scene_t*)calldata_ptr(params, "scene");
  2221. obs_sceneitem_t *item = (obs_sceneitem_t*)calldata_ptr(params, "item");
  2222. QMetaObject::invokeMethod(window, "SelectSceneItem",
  2223. Q_ARG(OBSScene, scene), Q_ARG(OBSSceneItem, item),
  2224. Q_ARG(bool, false));
  2225. window->ui->actionCopySource->setEnabled(false);
  2226. }
  2227. void OBSBasic::SourceLoaded(void *data, obs_source_t *source)
  2228. {
  2229. OBSBasic *window = static_cast<OBSBasic*>(data);
  2230. if (obs_scene_from_source(source) != NULL)
  2231. QMetaObject::invokeMethod(window,
  2232. "AddScene",
  2233. Q_ARG(OBSSource, OBSSource(source)));
  2234. }
  2235. void OBSBasic::SourceRemoved(void *data, calldata_t *params)
  2236. {
  2237. obs_source_t *source = (obs_source_t*)calldata_ptr(params, "source");
  2238. if (obs_scene_from_source(source) != NULL)
  2239. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  2240. "RemoveScene",
  2241. Q_ARG(OBSSource, OBSSource(source)));
  2242. }
  2243. void OBSBasic::SourceActivated(void *data, calldata_t *params)
  2244. {
  2245. obs_source_t *source = (obs_source_t*)calldata_ptr(params, "source");
  2246. uint32_t flags = obs_source_get_output_flags(source);
  2247. if (flags & OBS_SOURCE_AUDIO)
  2248. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  2249. "ActivateAudioSource",
  2250. Q_ARG(OBSSource, OBSSource(source)));
  2251. }
  2252. void OBSBasic::SourceDeactivated(void *data, calldata_t *params)
  2253. {
  2254. obs_source_t *source = (obs_source_t*)calldata_ptr(params, "source");
  2255. uint32_t flags = obs_source_get_output_flags(source);
  2256. if (flags & OBS_SOURCE_AUDIO)
  2257. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  2258. "DeactivateAudioSource",
  2259. Q_ARG(OBSSource, OBSSource(source)));
  2260. }
  2261. void OBSBasic::SourceRenamed(void *data, calldata_t *params)
  2262. {
  2263. const char *newName = calldata_string(params, "new_name");
  2264. const char *prevName = calldata_string(params, "prev_name");
  2265. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  2266. "RenameSources",
  2267. Q_ARG(QString, QT_UTF8(newName)),
  2268. Q_ARG(QString, QT_UTF8(prevName)));
  2269. blog(LOG_INFO, "Source '%s' renamed to '%s'", prevName, newName);
  2270. }
  2271. void OBSBasic::DrawBackdrop(float cx, float cy)
  2272. {
  2273. if (!box)
  2274. return;
  2275. gs_effect_t *solid = obs_get_base_effect(OBS_EFFECT_SOLID);
  2276. gs_eparam_t *color = gs_effect_get_param_by_name(solid, "color");
  2277. gs_technique_t *tech = gs_effect_get_technique(solid, "Solid");
  2278. vec4 colorVal;
  2279. vec4_set(&colorVal, 0.0f, 0.0f, 0.0f, 1.0f);
  2280. gs_effect_set_vec4(color, &colorVal);
  2281. gs_technique_begin(tech);
  2282. gs_technique_begin_pass(tech, 0);
  2283. gs_matrix_push();
  2284. gs_matrix_identity();
  2285. gs_matrix_scale3f(float(cx), float(cy), 1.0f);
  2286. gs_load_vertexbuffer(box);
  2287. gs_draw(GS_TRISTRIP, 0, 0);
  2288. gs_matrix_pop();
  2289. gs_technique_end_pass(tech);
  2290. gs_technique_end(tech);
  2291. gs_load_vertexbuffer(nullptr);
  2292. }
  2293. void OBSBasic::RenderMain(void *data, uint32_t cx, uint32_t cy)
  2294. {
  2295. OBSBasic *window = static_cast<OBSBasic*>(data);
  2296. obs_video_info ovi;
  2297. obs_get_video_info(&ovi);
  2298. window->previewCX = int(window->previewScale * float(ovi.base_width));
  2299. window->previewCY = int(window->previewScale * float(ovi.base_height));
  2300. gs_viewport_push();
  2301. gs_projection_push();
  2302. /* --------------------------------------- */
  2303. gs_ortho(0.0f, float(ovi.base_width), 0.0f, float(ovi.base_height),
  2304. -100.0f, 100.0f);
  2305. gs_set_viewport(window->previewX, window->previewY,
  2306. window->previewCX, window->previewCY);
  2307. window->DrawBackdrop(float(ovi.base_width), float(ovi.base_height));
  2308. if (window->IsPreviewProgramMode()) {
  2309. OBSScene scene = window->GetCurrentScene();
  2310. obs_source_t *source = obs_scene_get_source(scene);
  2311. if (source)
  2312. obs_source_video_render(source);
  2313. } else {
  2314. obs_render_main_view();
  2315. }
  2316. gs_load_vertexbuffer(nullptr);
  2317. /* --------------------------------------- */
  2318. QSize previewSize = GetPixelSize(window->ui->preview);
  2319. float right = float(previewSize.width()) - window->previewX;
  2320. float bottom = float(previewSize.height()) - window->previewY;
  2321. gs_ortho(-window->previewX, right,
  2322. -window->previewY, bottom,
  2323. -100.0f, 100.0f);
  2324. gs_reset_viewport();
  2325. window->ui->preview->DrawSceneEditing();
  2326. /* --------------------------------------- */
  2327. gs_projection_pop();
  2328. gs_viewport_pop();
  2329. UNUSED_PARAMETER(cx);
  2330. UNUSED_PARAMETER(cy);
  2331. }
  2332. /* Main class functions */
  2333. obs_service_t *OBSBasic::GetService()
  2334. {
  2335. if (!service) {
  2336. service = obs_service_create("rtmp_common", NULL, NULL,
  2337. nullptr);
  2338. obs_service_release(service);
  2339. }
  2340. return service;
  2341. }
  2342. void OBSBasic::SetService(obs_service_t *newService)
  2343. {
  2344. if (newService)
  2345. service = newService;
  2346. }
  2347. bool OBSBasic::StreamingActive() const
  2348. {
  2349. if (!outputHandler)
  2350. return false;
  2351. return outputHandler->StreamingActive();
  2352. }
  2353. bool OBSBasic::Active() const
  2354. {
  2355. if (!outputHandler)
  2356. return false;
  2357. return outputHandler->Active();
  2358. }
  2359. #ifdef _WIN32
  2360. #define IS_WIN32 1
  2361. #else
  2362. #define IS_WIN32 0
  2363. #endif
  2364. static inline int AttemptToResetVideo(struct obs_video_info *ovi)
  2365. {
  2366. return obs_reset_video(ovi);
  2367. }
  2368. static inline enum obs_scale_type GetScaleType(ConfigFile &basicConfig)
  2369. {
  2370. const char *scaleTypeStr = config_get_string(basicConfig,
  2371. "Video", "ScaleType");
  2372. if (astrcmpi(scaleTypeStr, "bilinear") == 0)
  2373. return OBS_SCALE_BILINEAR;
  2374. else if (astrcmpi(scaleTypeStr, "lanczos") == 0)
  2375. return OBS_SCALE_LANCZOS;
  2376. else
  2377. return OBS_SCALE_BICUBIC;
  2378. }
  2379. static inline enum video_format GetVideoFormatFromName(const char *name)
  2380. {
  2381. if (astrcmpi(name, "I420") == 0)
  2382. return VIDEO_FORMAT_I420;
  2383. else if (astrcmpi(name, "NV12") == 0)
  2384. return VIDEO_FORMAT_NV12;
  2385. else if (astrcmpi(name, "I444") == 0)
  2386. return VIDEO_FORMAT_I444;
  2387. #if 0 //currently unsupported
  2388. else if (astrcmpi(name, "YVYU") == 0)
  2389. return VIDEO_FORMAT_YVYU;
  2390. else if (astrcmpi(name, "YUY2") == 0)
  2391. return VIDEO_FORMAT_YUY2;
  2392. else if (astrcmpi(name, "UYVY") == 0)
  2393. return VIDEO_FORMAT_UYVY;
  2394. #endif
  2395. else
  2396. return VIDEO_FORMAT_RGBA;
  2397. }
  2398. void OBSBasic::ResetUI()
  2399. {
  2400. bool studioPortraitLayout = config_get_bool(GetGlobalConfig(),
  2401. "BasicWindow", "StudioPortraitLayout");
  2402. if (studioPortraitLayout)
  2403. ui->previewLayout->setDirection(QBoxLayout::TopToBottom);
  2404. else
  2405. ui->previewLayout->setDirection(QBoxLayout::LeftToRight);
  2406. }
  2407. int OBSBasic::ResetVideo()
  2408. {
  2409. if (outputHandler && outputHandler->Active())
  2410. return OBS_VIDEO_CURRENTLY_ACTIVE;
  2411. ProfileScope("OBSBasic::ResetVideo");
  2412. struct obs_video_info ovi;
  2413. int ret;
  2414. GetConfigFPS(ovi.fps_num, ovi.fps_den);
  2415. const char *colorFormat = config_get_string(basicConfig, "Video",
  2416. "ColorFormat");
  2417. const char *colorSpace = config_get_string(basicConfig, "Video",
  2418. "ColorSpace");
  2419. const char *colorRange = config_get_string(basicConfig, "Video",
  2420. "ColorRange");
  2421. ovi.graphics_module = App()->GetRenderModule();
  2422. ovi.base_width = (uint32_t)config_get_uint(basicConfig,
  2423. "Video", "BaseCX");
  2424. ovi.base_height = (uint32_t)config_get_uint(basicConfig,
  2425. "Video", "BaseCY");
  2426. ovi.output_width = (uint32_t)config_get_uint(basicConfig,
  2427. "Video", "OutputCX");
  2428. ovi.output_height = (uint32_t)config_get_uint(basicConfig,
  2429. "Video", "OutputCY");
  2430. ovi.output_format = GetVideoFormatFromName(colorFormat);
  2431. ovi.colorspace = astrcmpi(colorSpace, "601") == 0 ?
  2432. VIDEO_CS_601 : VIDEO_CS_709;
  2433. ovi.range = astrcmpi(colorRange, "Full") == 0 ?
  2434. VIDEO_RANGE_FULL : VIDEO_RANGE_PARTIAL;
  2435. ovi.adapter = config_get_uint(App()->GlobalConfig(),
  2436. "Video", "AdapterIdx");
  2437. ovi.gpu_conversion = true;
  2438. ovi.scale_type = GetScaleType(basicConfig);
  2439. if (ovi.base_width == 0 || ovi.base_height == 0) {
  2440. ovi.base_width = 1920;
  2441. ovi.base_height = 1080;
  2442. config_set_uint(basicConfig, "Video", "BaseCX", 1920);
  2443. config_set_uint(basicConfig, "Video", "BaseCY", 1080);
  2444. }
  2445. if (ovi.output_width == 0 || ovi.output_height == 0) {
  2446. ovi.output_width = ovi.base_width;
  2447. ovi.output_height = ovi.base_height;
  2448. config_set_uint(basicConfig, "Video", "OutputCX",
  2449. ovi.base_width);
  2450. config_set_uint(basicConfig, "Video", "OutputCY",
  2451. ovi.base_height);
  2452. }
  2453. ret = AttemptToResetVideo(&ovi);
  2454. if (IS_WIN32 && ret != OBS_VIDEO_SUCCESS) {
  2455. if (ret == OBS_VIDEO_CURRENTLY_ACTIVE) {
  2456. blog(LOG_WARNING, "Tried to reset when "
  2457. "already active");
  2458. return ret;
  2459. }
  2460. /* Try OpenGL if DirectX fails on windows */
  2461. if (astrcmpi(ovi.graphics_module, DL_OPENGL) != 0) {
  2462. blog(LOG_WARNING, "Failed to initialize obs video (%d) "
  2463. "with graphics_module='%s', retrying "
  2464. "with graphics_module='%s'",
  2465. ret, ovi.graphics_module,
  2466. DL_OPENGL);
  2467. ovi.graphics_module = DL_OPENGL;
  2468. ret = AttemptToResetVideo(&ovi);
  2469. }
  2470. } else if (ret == OBS_VIDEO_SUCCESS) {
  2471. ResizePreview(ovi.base_width, ovi.base_height);
  2472. if (program)
  2473. ResizeProgram(ovi.base_width, ovi.base_height);
  2474. }
  2475. if (ret == OBS_VIDEO_SUCCESS)
  2476. OBSBasicStats::InitializeValues();
  2477. return ret;
  2478. }
  2479. bool OBSBasic::ResetAudio()
  2480. {
  2481. ProfileScope("OBSBasic::ResetAudio");
  2482. struct obs_audio_info ai;
  2483. ai.samples_per_sec = config_get_uint(basicConfig, "Audio",
  2484. "SampleRate");
  2485. const char *channelSetupStr = config_get_string(basicConfig,
  2486. "Audio", "ChannelSetup");
  2487. if (strcmp(channelSetupStr, "Mono") == 0)
  2488. ai.speakers = SPEAKERS_MONO;
  2489. else if (strcmp(channelSetupStr, "2.1") == 0)
  2490. ai.speakers = SPEAKERS_2POINT1;
  2491. else if (strcmp(channelSetupStr, "4.0 Quad") == 0)
  2492. ai.speakers = SPEAKERS_QUAD;
  2493. else if (strcmp(channelSetupStr, "4.1") == 0)
  2494. ai.speakers = SPEAKERS_4POINT1;
  2495. else if (strcmp(channelSetupStr, "5.1") == 0)
  2496. ai.speakers = SPEAKERS_5POINT1;
  2497. else if (strcmp(channelSetupStr, "7.1") == 0)
  2498. ai.speakers = SPEAKERS_7POINT1;
  2499. else
  2500. ai.speakers = SPEAKERS_STEREO;
  2501. return obs_reset_audio(&ai);
  2502. }
  2503. void OBSBasic::ResetAudioDevice(const char *sourceId, const char *deviceId,
  2504. const char *deviceDesc, int channel)
  2505. {
  2506. bool disable = deviceId && strcmp(deviceId, "disabled") == 0;
  2507. obs_source_t *source;
  2508. obs_data_t *settings;
  2509. source = obs_get_output_source(channel);
  2510. if (source) {
  2511. if (disable) {
  2512. obs_set_output_source(channel, nullptr);
  2513. } else {
  2514. settings = obs_source_get_settings(source);
  2515. const char *oldId = obs_data_get_string(settings,
  2516. "device_id");
  2517. if (strcmp(oldId, deviceId) != 0) {
  2518. obs_data_set_string(settings, "device_id",
  2519. deviceId);
  2520. obs_source_update(source, settings);
  2521. }
  2522. obs_data_release(settings);
  2523. }
  2524. obs_source_release(source);
  2525. } else if (!disable) {
  2526. settings = obs_data_create();
  2527. obs_data_set_string(settings, "device_id", deviceId);
  2528. source = obs_source_create(sourceId, deviceDesc, settings,
  2529. nullptr);
  2530. obs_data_release(settings);
  2531. obs_set_output_source(channel, source);
  2532. obs_source_release(source);
  2533. }
  2534. }
  2535. void OBSBasic::ResizePreview(uint32_t cx, uint32_t cy)
  2536. {
  2537. QSize targetSize;
  2538. bool isFixedScaling;
  2539. obs_video_info ovi;
  2540. /* resize preview panel to fix to the top section of the window */
  2541. targetSize = GetPixelSize(ui->preview);
  2542. isFixedScaling = ui->preview->IsFixedScaling();
  2543. obs_get_video_info(&ovi);
  2544. if (isFixedScaling) {
  2545. previewScale = ui->preview->GetScalingAmount();
  2546. GetCenterPosFromFixedScale(int(cx), int(cy),
  2547. targetSize.width() - PREVIEW_EDGE_SIZE * 2,
  2548. targetSize.height() - PREVIEW_EDGE_SIZE * 2,
  2549. previewX, previewY, previewScale);
  2550. previewX += ui->preview->GetScrollX();
  2551. previewY += ui->preview->GetScrollY();
  2552. } else {
  2553. GetScaleAndCenterPos(int(cx), int(cy),
  2554. targetSize.width() - PREVIEW_EDGE_SIZE * 2,
  2555. targetSize.height() - PREVIEW_EDGE_SIZE * 2,
  2556. previewX, previewY, previewScale);
  2557. }
  2558. previewX += float(PREVIEW_EDGE_SIZE);
  2559. previewY += float(PREVIEW_EDGE_SIZE);
  2560. }
  2561. void OBSBasic::CloseDialogs()
  2562. {
  2563. QList<QDialog*> childDialogs = this->findChildren<QDialog *>();
  2564. if (!childDialogs.isEmpty()) {
  2565. for (int i = 0; i < childDialogs.size(); ++i) {
  2566. childDialogs.at(i)->close();
  2567. }
  2568. }
  2569. for (QPointer<QWidget> &projector : windowProjectors) {
  2570. delete projector;
  2571. projector.clear();
  2572. }
  2573. for (QPointer<QWidget> &projector : projectors) {
  2574. delete projector;
  2575. projector.clear();
  2576. }
  2577. if (!stats.isNull()) stats->close(); //call close to save Stats geometry
  2578. }
  2579. void OBSBasic::EnumDialogs()
  2580. {
  2581. visDialogs.clear();
  2582. modalDialogs.clear();
  2583. visMsgBoxes.clear();
  2584. /* fill list of Visible dialogs and Modal dialogs */
  2585. QList<QDialog*> dialogs = findChildren<QDialog*>();
  2586. for (QDialog *dialog : dialogs) {
  2587. if (dialog->isVisible())
  2588. visDialogs.append(dialog);
  2589. if (dialog->isModal())
  2590. modalDialogs.append(dialog);
  2591. }
  2592. /* fill list of Visible message boxes */
  2593. QList<QMessageBox*> msgBoxes = findChildren<QMessageBox*>();
  2594. for (QMessageBox *msgbox : msgBoxes) {
  2595. if (msgbox->isVisible())
  2596. visMsgBoxes.append(msgbox);
  2597. }
  2598. }
  2599. void OBSBasic::ClearSceneData()
  2600. {
  2601. disableSaving++;
  2602. CloseDialogs();
  2603. ClearVolumeControls();
  2604. ClearListItems(ui->scenes);
  2605. ClearListItems(ui->sources);
  2606. ClearQuickTransitions();
  2607. ui->transitions->clear();
  2608. obs_set_output_source(0, nullptr);
  2609. obs_set_output_source(1, nullptr);
  2610. obs_set_output_source(2, nullptr);
  2611. obs_set_output_source(3, nullptr);
  2612. obs_set_output_source(4, nullptr);
  2613. obs_set_output_source(5, nullptr);
  2614. lastScene = nullptr;
  2615. swapScene = nullptr;
  2616. programScene = nullptr;
  2617. auto cb = [](void *unused, obs_source_t *source)
  2618. {
  2619. obs_source_remove(source);
  2620. UNUSED_PARAMETER(unused);
  2621. return true;
  2622. };
  2623. obs_enum_sources(cb, nullptr);
  2624. disableSaving--;
  2625. blog(LOG_INFO, "All scene data cleared");
  2626. blog(LOG_INFO, "------------------------------------------------");
  2627. }
  2628. void OBSBasic::closeEvent(QCloseEvent *event)
  2629. {
  2630. if (isVisible())
  2631. config_set_string(App()->GlobalConfig(),
  2632. "BasicWindow", "geometry",
  2633. saveGeometry().toBase64().constData());
  2634. config_set_string(App()->GlobalConfig(),
  2635. "BasicWindow", "DockState",
  2636. saveState().toBase64().constData());
  2637. if (outputHandler && outputHandler->Active()) {
  2638. SetShowing(true);
  2639. QMessageBox::StandardButton button = OBSMessageBox::question(
  2640. this, QTStr("ConfirmExit.Title"),
  2641. QTStr("ConfirmExit.Text"));
  2642. if (button == QMessageBox::No) {
  2643. event->ignore();
  2644. return;
  2645. }
  2646. }
  2647. QWidget::closeEvent(event);
  2648. if (!event->isAccepted())
  2649. return;
  2650. blog(LOG_INFO, SHUTDOWN_SEPARATOR);
  2651. if (updateCheckThread)
  2652. updateCheckThread->wait();
  2653. if (logUploadThread)
  2654. logUploadThread->wait();
  2655. signalHandlers.clear();
  2656. SaveProjectNow();
  2657. if (api)
  2658. api->on_event(OBS_FRONTEND_EVENT_EXIT);
  2659. disableSaving++;
  2660. /* Clear all scene data (dialogs, widgets, widget sub-items, scenes,
  2661. * sources, etc) so that all references are released before shutdown */
  2662. ClearSceneData();
  2663. App()->quit();
  2664. }
  2665. void OBSBasic::changeEvent(QEvent *event)
  2666. {
  2667. if (event->type() == QEvent::WindowStateChange &&
  2668. isMinimized() &&
  2669. trayIcon &&
  2670. trayIcon->isVisible() &&
  2671. sysTrayMinimizeToTray()) {
  2672. ToggleShowHide();
  2673. }
  2674. }
  2675. void OBSBasic::on_actionShow_Recordings_triggered()
  2676. {
  2677. const char *mode = config_get_string(basicConfig, "Output", "Mode");
  2678. const char *path = strcmp(mode, "Advanced") ?
  2679. config_get_string(basicConfig, "SimpleOutput", "FilePath") :
  2680. config_get_string(basicConfig, "AdvOut", "RecFilePath");
  2681. QDesktopServices::openUrl(QUrl::fromLocalFile(path));
  2682. }
  2683. void OBSBasic::on_actionRemux_triggered()
  2684. {
  2685. const char *mode = config_get_string(basicConfig, "Output", "Mode");
  2686. const char *path = strcmp(mode, "Advanced") ?
  2687. config_get_string(basicConfig, "SimpleOutput", "FilePath") :
  2688. config_get_string(basicConfig, "AdvOut", "RecFilePath");
  2689. OBSRemux remux(path, this);
  2690. remux.exec();
  2691. }
  2692. void OBSBasic::on_action_Settings_triggered()
  2693. {
  2694. OBSBasicSettings settings(this);
  2695. settings.exec();
  2696. SystemTray(false);
  2697. }
  2698. void OBSBasic::on_actionAdvAudioProperties_triggered()
  2699. {
  2700. if (advAudioWindow != nullptr) {
  2701. advAudioWindow->raise();
  2702. return;
  2703. }
  2704. advAudioWindow = new OBSBasicAdvAudio(this);
  2705. advAudioWindow->show();
  2706. advAudioWindow->setAttribute(Qt::WA_DeleteOnClose, true);
  2707. connect(advAudioWindow, SIGNAL(destroyed()),
  2708. this, SLOT(on_advAudioProps_destroyed()));
  2709. }
  2710. void OBSBasic::on_advAudioProps_clicked()
  2711. {
  2712. on_actionAdvAudioProperties_triggered();
  2713. }
  2714. void OBSBasic::on_advAudioProps_destroyed()
  2715. {
  2716. advAudioWindow = nullptr;
  2717. }
  2718. void OBSBasic::on_scenes_currentItemChanged(QListWidgetItem *current,
  2719. QListWidgetItem *prev)
  2720. {
  2721. obs_source_t *source = NULL;
  2722. if (sceneChanging)
  2723. return;
  2724. if (current) {
  2725. obs_scene_t *scene;
  2726. scene = GetOBSRef<OBSScene>(current);
  2727. source = obs_scene_get_source(scene);
  2728. }
  2729. SetCurrentScene(source);
  2730. UNUSED_PARAMETER(prev);
  2731. }
  2732. void OBSBasic::EditSceneName()
  2733. {
  2734. QListWidgetItem *item = ui->scenes->currentItem();
  2735. Qt::ItemFlags flags = item->flags();
  2736. item->setFlags(flags | Qt::ItemIsEditable);
  2737. ui->scenes->editItem(item);
  2738. item->setFlags(flags);
  2739. }
  2740. static void AddProjectorMenuMonitors(QMenu *parent, QObject *target,
  2741. const char *slot)
  2742. {
  2743. QAction *action;
  2744. QList<QScreen*> screens = QGuiApplication::screens();
  2745. for (int i = 0; i < screens.size(); i++) {
  2746. QRect screenGeometry = screens[i]->geometry();
  2747. QString str = QString("%1 %2: %3x%4 @ %5,%6").
  2748. arg(QTStr("Display"),
  2749. QString::number(i),
  2750. QString::number((int)screenGeometry.width()),
  2751. QString::number((int)screenGeometry.height()),
  2752. QString::number((int)screenGeometry.x()),
  2753. QString::number((int)screenGeometry.y()));
  2754. action = parent->addAction(str, target, slot);
  2755. action->setProperty("monitor", i);
  2756. }
  2757. }
  2758. void OBSBasic::on_scenes_customContextMenuRequested(const QPoint &pos)
  2759. {
  2760. QListWidgetItem *item = ui->scenes->itemAt(pos);
  2761. QPointer<QMenu> sceneProjectorMenu;
  2762. QMenu popup(this);
  2763. QMenu order(QTStr("Basic.MainMenu.Edit.Order"), this);
  2764. popup.addAction(QTStr("Add"),
  2765. this, SLOT(on_actionAddScene_triggered()));
  2766. if (item) {
  2767. popup.addSeparator();
  2768. popup.addAction(QTStr("Duplicate"),
  2769. this, SLOT(DuplicateSelectedScene()));
  2770. popup.addAction(QTStr("Rename"),
  2771. this, SLOT(EditSceneName()));
  2772. popup.addAction(QTStr("Remove"),
  2773. this, SLOT(RemoveSelectedScene()),
  2774. DeleteKeys.front());
  2775. popup.addSeparator();
  2776. order.addAction(QTStr("Basic.MainMenu.Edit.Order.MoveUp"),
  2777. this, SLOT(on_actionSceneUp_triggered()));
  2778. order.addAction(QTStr("Basic.MainMenu.Edit.Order.MoveDown"),
  2779. this, SLOT(on_actionSceneDown_triggered()));
  2780. order.addSeparator();
  2781. order.addAction(QTStr("Basic.MainMenu.Edit.Order.MoveToTop"),
  2782. this, SLOT(MoveSceneToTop()));
  2783. order.addAction(QTStr("Basic.MainMenu.Edit.Order.MoveToBottom"),
  2784. this, SLOT(MoveSceneToBottom()));
  2785. popup.addMenu(&order);
  2786. popup.addSeparator();
  2787. sceneProjectorMenu = new QMenu(QTStr("SceneProjector"));
  2788. AddProjectorMenuMonitors(sceneProjectorMenu, this,
  2789. SLOT(OpenSceneProjector()));
  2790. popup.addMenu(sceneProjectorMenu);
  2791. QAction *sceneWindow = popup.addAction(
  2792. QTStr("SceneWindow"),
  2793. this, SLOT(OpenSceneWindow()));
  2794. popup.addAction(sceneWindow);
  2795. popup.addSeparator();
  2796. popup.addAction(QTStr("Filters"), this,
  2797. SLOT(OpenSceneFilters()));
  2798. }
  2799. popup.exec(QCursor::pos());
  2800. }
  2801. void OBSBasic::on_actionAddScene_triggered()
  2802. {
  2803. string name;
  2804. QString format{QTStr("Basic.Main.DefaultSceneName.Text")};
  2805. int i = 2;
  2806. QString placeHolderText = format.arg(i);
  2807. obs_source_t *source = nullptr;
  2808. while ((source = obs_get_source_by_name(QT_TO_UTF8(placeHolderText)))) {
  2809. obs_source_release(source);
  2810. placeHolderText = format.arg(++i);
  2811. }
  2812. bool accepted = NameDialog::AskForName(this,
  2813. QTStr("Basic.Main.AddSceneDlg.Title"),
  2814. QTStr("Basic.Main.AddSceneDlg.Text"),
  2815. name,
  2816. placeHolderText);
  2817. if (accepted) {
  2818. if (name.empty()) {
  2819. OBSMessageBox::information(this,
  2820. QTStr("NoNameEntered.Title"),
  2821. QTStr("NoNameEntered.Text"));
  2822. on_actionAddScene_triggered();
  2823. return;
  2824. }
  2825. obs_source_t *source = obs_get_source_by_name(name.c_str());
  2826. if (source) {
  2827. OBSMessageBox::information(this,
  2828. QTStr("NameExists.Title"),
  2829. QTStr("NameExists.Text"));
  2830. obs_source_release(source);
  2831. on_actionAddScene_triggered();
  2832. return;
  2833. }
  2834. obs_scene_t *scene = obs_scene_create(name.c_str());
  2835. source = obs_scene_get_source(scene);
  2836. AddScene(source);
  2837. SetCurrentScene(source);
  2838. obs_scene_release(scene);
  2839. }
  2840. }
  2841. void OBSBasic::on_actionRemoveScene_triggered()
  2842. {
  2843. OBSScene scene = GetCurrentScene();
  2844. obs_source_t *source = obs_scene_get_source(scene);
  2845. if (source && QueryRemoveSource(source))
  2846. obs_source_remove(source);
  2847. }
  2848. void OBSBasic::ChangeSceneIndex(bool relative, int offset, int invalidIdx)
  2849. {
  2850. int idx = ui->scenes->currentRow();
  2851. if (idx == -1 || idx == invalidIdx)
  2852. return;
  2853. sceneChanging = true;
  2854. QListWidgetItem *item = ui->scenes->takeItem(idx);
  2855. if (!relative)
  2856. idx = 0;
  2857. ui->scenes->insertItem(idx + offset, item);
  2858. ui->scenes->setCurrentRow(idx + offset);
  2859. item->setSelected(true);
  2860. sceneChanging = false;
  2861. }
  2862. void OBSBasic::on_actionSceneUp_triggered()
  2863. {
  2864. ChangeSceneIndex(true, -1, 0);
  2865. }
  2866. void OBSBasic::on_actionSceneDown_triggered()
  2867. {
  2868. ChangeSceneIndex(true, 1, ui->scenes->count() - 1);
  2869. }
  2870. void OBSBasic::MoveSceneToTop()
  2871. {
  2872. ChangeSceneIndex(false, 0, 0);
  2873. }
  2874. void OBSBasic::MoveSceneToBottom()
  2875. {
  2876. ChangeSceneIndex(false, ui->scenes->count() - 1,
  2877. ui->scenes->count() - 1);
  2878. }
  2879. void OBSBasic::on_sources_itemSelectionChanged()
  2880. {
  2881. SignalBlocker sourcesSignalBlocker(ui->sources);
  2882. auto updateItemSelection = [&]()
  2883. {
  2884. ignoreSelectionUpdate = true;
  2885. for (int i = 0; i < ui->sources->count(); i++)
  2886. {
  2887. QListWidgetItem *wItem = ui->sources->item(i);
  2888. OBSSceneItem item = GetOBSRef<OBSSceneItem>(wItem);
  2889. obs_sceneitem_select(item, wItem->isSelected());
  2890. }
  2891. ignoreSelectionUpdate = false;
  2892. };
  2893. using updateItemSelection_t = decltype(updateItemSelection);
  2894. obs_scene_atomic_update(GetCurrentScene(),
  2895. [](void *data, obs_scene_t *)
  2896. {
  2897. (*static_cast<updateItemSelection_t*>(data))();
  2898. }, static_cast<void*>(&updateItemSelection));
  2899. }
  2900. void OBSBasic::EditSceneItemName()
  2901. {
  2902. QListWidgetItem *item = GetTopSelectedSourceItem();
  2903. Qt::ItemFlags flags = item->flags();
  2904. OBSSceneItem sceneItem= GetOBSRef<OBSSceneItem>(item);
  2905. obs_source_t *source = obs_sceneitem_get_source(sceneItem);
  2906. const char *name = obs_source_get_name(source);
  2907. item->setText(QT_UTF8(name));
  2908. item->setFlags(flags | Qt::ItemIsEditable);
  2909. ui->sources->removeItemWidget(item);
  2910. ui->sources->editItem(item);
  2911. item->setFlags(flags);
  2912. }
  2913. void OBSBasic::SetDeinterlacingMode()
  2914. {
  2915. QAction *action = reinterpret_cast<QAction*>(sender());
  2916. obs_deinterlace_mode mode =
  2917. (obs_deinterlace_mode)action->property("mode").toInt();
  2918. OBSSceneItem sceneItem = GetCurrentSceneItem();
  2919. obs_source_t *source = obs_sceneitem_get_source(sceneItem);
  2920. obs_source_set_deinterlace_mode(source, mode);
  2921. }
  2922. void OBSBasic::SetDeinterlacingOrder()
  2923. {
  2924. QAction *action = reinterpret_cast<QAction*>(sender());
  2925. obs_deinterlace_field_order order =
  2926. (obs_deinterlace_field_order)action->property("order").toInt();
  2927. OBSSceneItem sceneItem = GetCurrentSceneItem();
  2928. obs_source_t *source = obs_sceneitem_get_source(sceneItem);
  2929. obs_source_set_deinterlace_field_order(source, order);
  2930. }
  2931. QMenu *OBSBasic::AddDeinterlacingMenu(obs_source_t *source)
  2932. {
  2933. QMenu *menu = new QMenu(QTStr("Deinterlacing"));
  2934. obs_deinterlace_mode deinterlaceMode =
  2935. obs_source_get_deinterlace_mode(source);
  2936. obs_deinterlace_field_order deinterlaceOrder =
  2937. obs_source_get_deinterlace_field_order(source);
  2938. QAction *action;
  2939. #define ADD_MODE(name, mode) \
  2940. action = menu->addAction(QTStr("" name), this, \
  2941. SLOT(SetDeinterlacingMode())); \
  2942. action->setProperty("mode", (int)mode); \
  2943. action->setCheckable(true); \
  2944. action->setChecked(deinterlaceMode == mode);
  2945. ADD_MODE("Disable", OBS_DEINTERLACE_MODE_DISABLE);
  2946. ADD_MODE("Deinterlacing.Discard", OBS_DEINTERLACE_MODE_DISCARD);
  2947. ADD_MODE("Deinterlacing.Retro", OBS_DEINTERLACE_MODE_RETRO);
  2948. ADD_MODE("Deinterlacing.Blend", OBS_DEINTERLACE_MODE_BLEND);
  2949. ADD_MODE("Deinterlacing.Blend2x", OBS_DEINTERLACE_MODE_BLEND_2X);
  2950. ADD_MODE("Deinterlacing.Linear", OBS_DEINTERLACE_MODE_LINEAR);
  2951. ADD_MODE("Deinterlacing.Linear2x", OBS_DEINTERLACE_MODE_LINEAR_2X);
  2952. ADD_MODE("Deinterlacing.Yadif", OBS_DEINTERLACE_MODE_YADIF);
  2953. ADD_MODE("Deinterlacing.Yadif2x", OBS_DEINTERLACE_MODE_YADIF_2X);
  2954. #undef ADD_MODE
  2955. menu->addSeparator();
  2956. #define ADD_ORDER(name, order) \
  2957. action = menu->addAction(QTStr("Deinterlacing." name), this, \
  2958. SLOT(SetDeinterlacingOrder())); \
  2959. action->setProperty("order", (int)order); \
  2960. action->setCheckable(true); \
  2961. action->setChecked(deinterlaceOrder == order);
  2962. ADD_ORDER("TopFieldFirst", OBS_DEINTERLACE_FIELD_ORDER_TOP);
  2963. ADD_ORDER("BottomFieldFirst", OBS_DEINTERLACE_FIELD_ORDER_BOTTOM);
  2964. #undef ADD_ORDER
  2965. return menu;
  2966. }
  2967. void OBSBasic::SetScaleFilter()
  2968. {
  2969. QAction *action = reinterpret_cast<QAction*>(sender());
  2970. obs_scale_type mode = (obs_scale_type)action->property("mode").toInt();
  2971. OBSSceneItem sceneItem = GetCurrentSceneItem();
  2972. obs_sceneitem_set_scale_filter(sceneItem, mode);
  2973. }
  2974. QMenu *OBSBasic::AddScaleFilteringMenu(obs_sceneitem_t *item)
  2975. {
  2976. QMenu *menu = new QMenu(QTStr("ScaleFiltering"));
  2977. obs_scale_type scaleFilter = obs_sceneitem_get_scale_filter(item);
  2978. QAction *action;
  2979. #define ADD_MODE(name, mode) \
  2980. action = menu->addAction(QTStr("" name), this, \
  2981. SLOT(SetScaleFilter())); \
  2982. action->setProperty("mode", (int)mode); \
  2983. action->setCheckable(true); \
  2984. action->setChecked(scaleFilter == mode);
  2985. ADD_MODE("Disable", OBS_SCALE_DISABLE);
  2986. ADD_MODE("ScaleFiltering.Point", OBS_SCALE_POINT);
  2987. ADD_MODE("ScaleFiltering.Bilinear", OBS_SCALE_BILINEAR);
  2988. ADD_MODE("ScaleFiltering.Bicubic", OBS_SCALE_BICUBIC);
  2989. ADD_MODE("ScaleFiltering.Lanczos", OBS_SCALE_LANCZOS);
  2990. #undef ADD_MODE
  2991. return menu;
  2992. }
  2993. void OBSBasic::CreateSourcePopupMenu(QListWidgetItem *item, bool preview)
  2994. {
  2995. QMenu popup(this);
  2996. QPointer<QMenu> previewProjector;
  2997. QPointer<QMenu> sourceProjector;
  2998. if (preview) {
  2999. QAction *action = popup.addAction(
  3000. QTStr("Basic.Main.PreviewConextMenu.Enable"),
  3001. this, SLOT(TogglePreview()));
  3002. action->setCheckable(true);
  3003. action->setChecked(
  3004. obs_display_enabled(ui->preview->GetDisplay()));
  3005. if (IsPreviewProgramMode())
  3006. action->setEnabled(false);
  3007. popup.addAction(ui->actionLockPreview);
  3008. popup.addMenu(ui->scalingMenu);
  3009. const char *slot = IsPreviewProgramMode()
  3010. ? SLOT(OpenStudioProgramProjector())
  3011. : SLOT(OpenPreviewProjector());
  3012. previewProjector = new QMenu(QTStr("PreviewProjector"));
  3013. AddProjectorMenuMonitors(previewProjector, this,
  3014. slot);
  3015. popup.addMenu(previewProjector);
  3016. slot = IsPreviewProgramMode()
  3017. ? SLOT(OpenStudioProgramWindow())
  3018. : SLOT(OpenPreviewWindow());
  3019. QAction *previewWindow = popup.addAction(
  3020. QTStr("PreviewWindow"),
  3021. this, slot);
  3022. popup.addAction(previewWindow);
  3023. popup.addSeparator();
  3024. }
  3025. QPointer<QMenu> addSourceMenu = CreateAddSourcePopupMenu();
  3026. if (addSourceMenu)
  3027. popup.addMenu(addSourceMenu);
  3028. ui->actionCopyFilters->setEnabled(false);
  3029. popup.addSeparator();
  3030. popup.addAction(ui->actionCopySource);
  3031. popup.addAction(ui->actionPasteRef);
  3032. popup.addAction(ui->actionPasteDup);
  3033. popup.addSeparator();
  3034. popup.addSeparator();
  3035. popup.addAction(ui->actionCopyFilters);
  3036. popup.addAction(ui->actionPasteFilters);
  3037. popup.addSeparator();
  3038. if (item) {
  3039. if (addSourceMenu)
  3040. popup.addSeparator();
  3041. OBSSceneItem sceneItem = GetSceneItem(item);
  3042. obs_source_t *source = obs_sceneitem_get_source(sceneItem);
  3043. uint32_t flags = obs_source_get_output_flags(source);
  3044. bool isAsyncVideo = (flags & OBS_SOURCE_ASYNC_VIDEO) ==
  3045. OBS_SOURCE_ASYNC_VIDEO;
  3046. bool hasAudio = (flags & OBS_SOURCE_AUDIO) ==
  3047. OBS_SOURCE_AUDIO;
  3048. QAction *action;
  3049. popup.addAction(QTStr("Rename"), this,
  3050. SLOT(EditSceneItemName()));
  3051. popup.addAction(QTStr("Remove"), this,
  3052. SLOT(on_actionRemoveSource_triggered()),
  3053. DeleteKeys.front());
  3054. popup.addSeparator();
  3055. popup.addMenu(ui->orderMenu);
  3056. popup.addMenu(ui->transformMenu);
  3057. sourceProjector = new QMenu(QTStr("SourceProjector"));
  3058. AddProjectorMenuMonitors(sourceProjector, this,
  3059. SLOT(OpenSourceProjector()));
  3060. QAction *sourceWindow = popup.addAction(
  3061. QTStr("SourceWindow"),
  3062. this, SLOT(OpenSourceWindow()));
  3063. popup.addAction(sourceWindow);
  3064. popup.addSeparator();
  3065. if (hasAudio) {
  3066. QAction *actionHideMixer = popup.addAction(
  3067. QTStr("HideMixer"),
  3068. this, SLOT(ToggleHideMixer()));
  3069. actionHideMixer->setCheckable(true);
  3070. actionHideMixer->setChecked(SourceMixerHidden(source));
  3071. }
  3072. if (isAsyncVideo) {
  3073. popup.addMenu(AddDeinterlacingMenu(source));
  3074. popup.addSeparator();
  3075. }
  3076. popup.addMenu(AddScaleFilteringMenu(sceneItem));
  3077. popup.addSeparator();
  3078. popup.addMenu(sourceProjector);
  3079. popup.addAction(sourceWindow);
  3080. popup.addSeparator();
  3081. action = popup.addAction(QTStr("Interact"), this,
  3082. SLOT(on_actionInteract_triggered()));
  3083. action->setEnabled(obs_source_get_output_flags(source) &
  3084. OBS_SOURCE_INTERACTION);
  3085. popup.addAction(QTStr("Filters"), this,
  3086. SLOT(OpenFilters()));
  3087. popup.addAction(QTStr("Properties"), this,
  3088. SLOT(on_actionSourceProperties_triggered()));
  3089. ui->actionCopyFilters->setEnabled(true);
  3090. }
  3091. popup.exec(QCursor::pos());
  3092. }
  3093. void OBSBasic::on_sources_customContextMenuRequested(const QPoint &pos)
  3094. {
  3095. if (ui->scenes->count())
  3096. CreateSourcePopupMenu(ui->sources->itemAt(pos), false);
  3097. }
  3098. void OBSBasic::on_sources_itemDoubleClicked(QListWidgetItem *witem)
  3099. {
  3100. if (!witem)
  3101. return;
  3102. OBSSceneItem item = GetSceneItem(witem);
  3103. OBSSource source = obs_sceneitem_get_source(item);
  3104. if (source)
  3105. CreatePropertiesWindow(source);
  3106. }
  3107. void OBSBasic::on_scenes_itemDoubleClicked(QListWidgetItem *witem)
  3108. {
  3109. if (!witem)
  3110. return;
  3111. if (IsPreviewProgramMode()) {
  3112. bool doubleClickSwitch = config_get_bool(App()->GlobalConfig(),
  3113. "BasicWindow", "TransitionOnDoubleClick");
  3114. if (doubleClickSwitch) {
  3115. OBSScene scene = GetCurrentScene();
  3116. if (scene)
  3117. SetCurrentScene(scene, false, true);
  3118. }
  3119. }
  3120. }
  3121. void OBSBasic::AddSource(const char *id)
  3122. {
  3123. if (id && *id) {
  3124. OBSBasicSourceSelect sourceSelect(this, id);
  3125. sourceSelect.exec();
  3126. if (sourceSelect.newSource)
  3127. CreatePropertiesWindow(sourceSelect.newSource);
  3128. }
  3129. }
  3130. QMenu *OBSBasic::CreateAddSourcePopupMenu()
  3131. {
  3132. const char *type;
  3133. bool foundValues = false;
  3134. bool foundDeprecated = false;
  3135. size_t idx = 0;
  3136. QMenu *popup = new QMenu(QTStr("Add"), this);
  3137. QMenu *deprecated = new QMenu(QTStr("Deprecated"), popup);
  3138. auto getActionAfter = [] (QMenu *menu, const QString &name)
  3139. {
  3140. QList<QAction*> actions = menu->actions();
  3141. for (QAction *menuAction : actions) {
  3142. if (menuAction->text().compare(name) >= 0)
  3143. return menuAction;
  3144. }
  3145. return (QAction*)nullptr;
  3146. };
  3147. auto addSource = [this, getActionAfter] (QMenu *popup,
  3148. const char *type, const char *name)
  3149. {
  3150. QString qname = QT_UTF8(name);
  3151. QAction *popupItem = new QAction(qname, this);
  3152. popupItem->setData(QT_UTF8(type));
  3153. connect(popupItem, SIGNAL(triggered(bool)),
  3154. this, SLOT(AddSourceFromAction()));
  3155. QAction *after = getActionAfter(popup, qname);
  3156. popup->insertAction(after, popupItem);
  3157. };
  3158. while (obs_enum_input_types(idx++, &type)) {
  3159. const char *name = obs_source_get_display_name(type);
  3160. uint32_t caps = obs_get_source_output_flags(type);
  3161. if ((caps & OBS_SOURCE_DEPRECATED) == 0) {
  3162. addSource(popup, type, name);
  3163. } else {
  3164. addSource(deprecated, type, name);
  3165. foundDeprecated = true;
  3166. }
  3167. foundValues = true;
  3168. }
  3169. addSource(popup, "scene", Str("Basic.Scene"));
  3170. if (!foundDeprecated) {
  3171. delete deprecated;
  3172. deprecated = nullptr;
  3173. }
  3174. if (!foundValues) {
  3175. delete popup;
  3176. popup = nullptr;
  3177. } else if (foundDeprecated) {
  3178. popup->addMenu(deprecated);
  3179. }
  3180. return popup;
  3181. }
  3182. void OBSBasic::AddSourceFromAction()
  3183. {
  3184. QAction *action = qobject_cast<QAction*>(sender());
  3185. if (!action)
  3186. return;
  3187. AddSource(QT_TO_UTF8(action->data().toString()));
  3188. }
  3189. void OBSBasic::AddSourcePopupMenu(const QPoint &pos)
  3190. {
  3191. if (!GetCurrentScene()) {
  3192. // Tell the user he needs a scene first (help beginners).
  3193. OBSMessageBox::information(this,
  3194. QTStr("Basic.Main.AddSourceHelp.Title"),
  3195. QTStr("Basic.Main.AddSourceHelp.Text"));
  3196. return;
  3197. }
  3198. QPointer<QMenu> popup = CreateAddSourcePopupMenu();
  3199. if (popup)
  3200. popup->exec(pos);
  3201. }
  3202. void OBSBasic::on_actionAddSource_triggered()
  3203. {
  3204. AddSourcePopupMenu(QCursor::pos());
  3205. }
  3206. void OBSBasic::on_actionRemoveSource_triggered()
  3207. {
  3208. vector<OBSSceneItem> items;
  3209. auto func = [] (obs_scene_t *, obs_sceneitem_t *item, void *param)
  3210. {
  3211. vector<OBSSceneItem> &items =
  3212. *reinterpret_cast<vector<OBSSceneItem>*>(param);
  3213. if (obs_sceneitem_selected(item))
  3214. items.emplace_back(item);
  3215. return true;
  3216. };
  3217. obs_scene_enum_items(GetCurrentScene(), func, &items);
  3218. if (!items.size())
  3219. return;
  3220. auto removeMultiple = [this] (size_t count)
  3221. {
  3222. QString text = QTStr("ConfirmRemove.TextMultiple")
  3223. .arg(QString::number(count));
  3224. QMessageBox remove_items(this);
  3225. remove_items.setText(text);
  3226. QAbstractButton *Yes = remove_items.addButton(QTStr("Yes"),
  3227. QMessageBox::YesRole);
  3228. remove_items.addButton(QTStr("No"), QMessageBox::NoRole);
  3229. remove_items.setIcon(QMessageBox::Question);
  3230. remove_items.setWindowTitle(QTStr("ConfirmRemove.Title"));
  3231. remove_items.exec();
  3232. return Yes == remove_items.clickedButton();
  3233. };
  3234. if (items.size() == 1) {
  3235. OBSSceneItem &item = items[0];
  3236. obs_source_t *source = obs_sceneitem_get_source(item);
  3237. if (source && QueryRemoveSource(source))
  3238. obs_sceneitem_remove(item);
  3239. } else {
  3240. if (removeMultiple(items.size())) {
  3241. for (auto &item : items)
  3242. obs_sceneitem_remove(item);
  3243. }
  3244. }
  3245. }
  3246. void OBSBasic::on_actionInteract_triggered()
  3247. {
  3248. OBSSceneItem item = GetCurrentSceneItem();
  3249. OBSSource source = obs_sceneitem_get_source(item);
  3250. if (source)
  3251. CreateInteractionWindow(source);
  3252. }
  3253. void OBSBasic::on_actionSourceProperties_triggered()
  3254. {
  3255. OBSSceneItem item = GetCurrentSceneItem();
  3256. OBSSource source = obs_sceneitem_get_source(item);
  3257. if (source)
  3258. CreatePropertiesWindow(source);
  3259. }
  3260. void OBSBasic::on_actionSourceUp_triggered()
  3261. {
  3262. OBSSceneItem item = GetCurrentSceneItem();
  3263. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_UP);
  3264. }
  3265. void OBSBasic::on_actionSourceDown_triggered()
  3266. {
  3267. OBSSceneItem item = GetCurrentSceneItem();
  3268. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_DOWN);
  3269. }
  3270. void OBSBasic::on_actionMoveUp_triggered()
  3271. {
  3272. OBSSceneItem item = GetCurrentSceneItem();
  3273. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_UP);
  3274. }
  3275. void OBSBasic::on_actionMoveDown_triggered()
  3276. {
  3277. OBSSceneItem item = GetCurrentSceneItem();
  3278. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_DOWN);
  3279. }
  3280. void OBSBasic::on_actionMoveToTop_triggered()
  3281. {
  3282. OBSSceneItem item = GetCurrentSceneItem();
  3283. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_TOP);
  3284. }
  3285. void OBSBasic::on_actionMoveToBottom_triggered()
  3286. {
  3287. OBSSceneItem item = GetCurrentSceneItem();
  3288. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_BOTTOM);
  3289. }
  3290. static BPtr<char> ReadLogFile(const char *log)
  3291. {
  3292. char logDir[512];
  3293. if (GetConfigPath(logDir, sizeof(logDir), "obs-studio/logs") <= 0)
  3294. return nullptr;
  3295. string path = (char*)logDir;
  3296. path += "/";
  3297. path += log;
  3298. BPtr<char> file = os_quick_read_utf8_file(path.c_str());
  3299. if (!file)
  3300. blog(LOG_WARNING, "Failed to read log file %s", path.c_str());
  3301. return file;
  3302. }
  3303. void OBSBasic::UploadLog(const char *file)
  3304. {
  3305. BPtr<char> fileString{ReadLogFile(file)};
  3306. if (!fileString)
  3307. return;
  3308. if (!*fileString)
  3309. return;
  3310. ui->menuLogFiles->setEnabled(false);
  3311. auto data_deleter = [](obs_data_t *d) { obs_data_release(d); };
  3312. using data_t = unique_ptr<struct obs_data, decltype(data_deleter)>;
  3313. data_t content{obs_data_create(), data_deleter};
  3314. data_t files{obs_data_create(), data_deleter};
  3315. data_t request{obs_data_create(), data_deleter};
  3316. obs_data_set_string(content.get(), "content", fileString);
  3317. obs_data_set_obj(files.get(), file, content.get());
  3318. stringstream ss;
  3319. ss << "OBS " << App()->GetVersionString()
  3320. << " log file uploaded at " << CurrentDateTimeString();
  3321. obs_data_set_string(request.get(), "description", ss.str().c_str());
  3322. obs_data_set_bool(request.get(), "public", false);
  3323. obs_data_set_obj(request.get(), "files", files.get());
  3324. const char *json = obs_data_get_json(request.get());
  3325. if (!json) {
  3326. blog(LOG_ERROR, "Failed to get JSON data for log upload");
  3327. return;
  3328. }
  3329. QBuffer *postData = new QBuffer();
  3330. postData->setData(json, (int) strlen(json));
  3331. if (logUploadThread) {
  3332. logUploadThread->wait();
  3333. delete logUploadThread;
  3334. }
  3335. RemoteTextThread *thread = new RemoteTextThread(
  3336. "https://api.github.com/gists",
  3337. "application/json", json);
  3338. logUploadThread = thread;
  3339. connect(thread, &RemoteTextThread::Result,
  3340. this, &OBSBasic::logUploadFinished);
  3341. logUploadThread->start();
  3342. }
  3343. void OBSBasic::on_actionShowLogs_triggered()
  3344. {
  3345. char logDir[512];
  3346. if (GetConfigPath(logDir, sizeof(logDir), "obs-studio/logs") <= 0)
  3347. return;
  3348. QUrl url = QUrl::fromLocalFile(QT_UTF8(logDir));
  3349. QDesktopServices::openUrl(url);
  3350. }
  3351. void OBSBasic::on_actionUploadCurrentLog_triggered()
  3352. {
  3353. UploadLog(App()->GetCurrentLog());
  3354. }
  3355. void OBSBasic::on_actionUploadLastLog_triggered()
  3356. {
  3357. UploadLog(App()->GetLastLog());
  3358. }
  3359. void OBSBasic::on_actionViewCurrentLog_triggered()
  3360. {
  3361. char logDir[512];
  3362. if (GetConfigPath(logDir, sizeof(logDir), "obs-studio/logs") <= 0)
  3363. return;
  3364. const char* log = App()->GetCurrentLog();
  3365. string path = (char*)logDir;
  3366. path += "/";
  3367. path += log;
  3368. QUrl url = QUrl::fromLocalFile(QT_UTF8(path.c_str()));
  3369. QDesktopServices::openUrl(url);
  3370. }
  3371. void OBSBasic::on_actionCheckForUpdates_triggered()
  3372. {
  3373. CheckForUpdates(true);
  3374. }
  3375. void OBSBasic::logUploadFinished(const QString &text, const QString &error)
  3376. {
  3377. ui->menuLogFiles->setEnabled(true);
  3378. if (text.isEmpty()) {
  3379. OBSMessageBox::information(this,
  3380. QTStr("LogReturnDialog.ErrorUploadingLog"),
  3381. error);
  3382. return;
  3383. }
  3384. obs_data_t *returnData = obs_data_create_from_json(QT_TO_UTF8(text));
  3385. QString logURL = obs_data_get_string(returnData, "html_url");
  3386. obs_data_release(returnData);
  3387. OBSLogReply logDialog(this, logURL);
  3388. logDialog.exec();
  3389. }
  3390. static void RenameListItem(OBSBasic *parent, QListWidget *listWidget,
  3391. obs_source_t *source, const string &name)
  3392. {
  3393. const char *prevName = obs_source_get_name(source);
  3394. if (name == prevName)
  3395. return;
  3396. obs_source_t *foundSource = obs_get_source_by_name(name.c_str());
  3397. QListWidgetItem *listItem = listWidget->currentItem();
  3398. if (foundSource || name.empty()) {
  3399. listItem->setText(QT_UTF8(prevName));
  3400. if (foundSource) {
  3401. OBSMessageBox::information(parent,
  3402. QTStr("NameExists.Title"),
  3403. QTStr("NameExists.Text"));
  3404. } else if (name.empty()) {
  3405. OBSMessageBox::information(parent,
  3406. QTStr("NoNameEntered.Title"),
  3407. QTStr("NoNameEntered.Text"));
  3408. }
  3409. obs_source_release(foundSource);
  3410. } else {
  3411. listItem->setText(QT_UTF8(name.c_str()));
  3412. obs_source_set_name(source, name.c_str());
  3413. }
  3414. }
  3415. void OBSBasic::SceneNameEdited(QWidget *editor,
  3416. QAbstractItemDelegate::EndEditHint endHint)
  3417. {
  3418. OBSScene scene = GetCurrentScene();
  3419. QLineEdit *edit = qobject_cast<QLineEdit*>(editor);
  3420. string text = QT_TO_UTF8(edit->text().trimmed());
  3421. if (!scene)
  3422. return;
  3423. obs_source_t *source = obs_scene_get_source(scene);
  3424. RenameListItem(this, ui->scenes, source, text);
  3425. if (api)
  3426. api->on_event(OBS_FRONTEND_EVENT_SCENE_LIST_CHANGED);
  3427. UNUSED_PARAMETER(endHint);
  3428. }
  3429. void OBSBasic::SceneItemNameEdited(QWidget *editor,
  3430. QAbstractItemDelegate::EndEditHint endHint)
  3431. {
  3432. OBSSceneItem item = GetCurrentSceneItem();
  3433. QLineEdit *edit = qobject_cast<QLineEdit*>(editor);
  3434. string text = QT_TO_UTF8(edit->text().trimmed());
  3435. if (!item)
  3436. return;
  3437. obs_source_t *source = obs_sceneitem_get_source(item);
  3438. RenameListItem(this, ui->sources, source, text);
  3439. QListWidgetItem *listItem = ui->sources->currentItem();
  3440. listItem->setText(QString());
  3441. SetupVisibilityItem(ui->sources, listItem, item);
  3442. UNUSED_PARAMETER(endHint);
  3443. }
  3444. void OBSBasic::OpenFilters()
  3445. {
  3446. OBSSceneItem item = GetCurrentSceneItem();
  3447. OBSSource source = obs_sceneitem_get_source(item);
  3448. CreateFiltersWindow(source);
  3449. }
  3450. void OBSBasic::OpenSceneFilters()
  3451. {
  3452. OBSScene scene = GetCurrentScene();
  3453. OBSSource source = obs_scene_get_source(scene);
  3454. CreateFiltersWindow(source);
  3455. }
  3456. #define RECORDING_START \
  3457. "==== Recording Start ==============================================="
  3458. #define RECORDING_STOP \
  3459. "==== Recording Stop ================================================"
  3460. #define REPLAY_BUFFER_START \
  3461. "==== Replay Buffer Start ==========================================="
  3462. #define REPLAY_BUFFER_STOP \
  3463. "==== Replay Buffer Stop ============================================"
  3464. #define STREAMING_START \
  3465. "==== Streaming Start ==============================================="
  3466. #define STREAMING_STOP \
  3467. "==== Streaming Stop ================================================"
  3468. void OBSBasic::StartStreaming()
  3469. {
  3470. if (outputHandler->StreamingActive())
  3471. return;
  3472. if (disableOutputsRef)
  3473. return;
  3474. if (api)
  3475. api->on_event(OBS_FRONTEND_EVENT_STREAMING_STARTING);
  3476. SaveProject();
  3477. ui->streamButton->setEnabled(false);
  3478. ui->streamButton->setText(QTStr("Basic.Main.Connecting"));
  3479. if (sysTrayStream) {
  3480. sysTrayStream->setEnabled(false);
  3481. sysTrayStream->setText(ui->streamButton->text());
  3482. }
  3483. if (!outputHandler->StartStreaming(service)) {
  3484. ui->streamButton->setText(QTStr("Basic.Main.StartStreaming"));
  3485. ui->streamButton->setEnabled(true);
  3486. ui->streamButton->setChecked(false);
  3487. if (sysTrayStream) {
  3488. sysTrayStream->setText(ui->streamButton->text());
  3489. sysTrayStream->setEnabled(true);
  3490. }
  3491. QMessageBox::critical(this,
  3492. QTStr("Output.StartStreamFailed"),
  3493. QTStr("Output.StartFailedGeneric"));
  3494. return;
  3495. }
  3496. bool recordWhenStreaming = config_get_bool(GetGlobalConfig(),
  3497. "BasicWindow", "RecordWhenStreaming");
  3498. if (recordWhenStreaming)
  3499. StartRecording();
  3500. bool replayBufferWhileStreaming = config_get_bool(GetGlobalConfig(),
  3501. "BasicWindow", "ReplayBufferWhileStreaming");
  3502. if (replayBufferWhileStreaming)
  3503. StartReplayBuffer();
  3504. }
  3505. #ifdef _WIN32
  3506. static inline void UpdateProcessPriority()
  3507. {
  3508. const char *priority = config_get_string(App()->GlobalConfig(),
  3509. "General", "ProcessPriority");
  3510. if (priority && strcmp(priority, "Normal") != 0)
  3511. SetProcessPriority(priority);
  3512. }
  3513. static inline void ClearProcessPriority()
  3514. {
  3515. const char *priority = config_get_string(App()->GlobalConfig(),
  3516. "General", "ProcessPriority");
  3517. if (priority && strcmp(priority, "Normal") != 0)
  3518. SetProcessPriority("Normal");
  3519. }
  3520. #else
  3521. #define UpdateProcessPriority() do {} while(false)
  3522. #define ClearProcessPriority() do {} while(false)
  3523. #endif
  3524. inline void OBSBasic::OnActivate()
  3525. {
  3526. if (ui->profileMenu->isEnabled()) {
  3527. ui->profileMenu->setEnabled(false);
  3528. ui->autoConfigure->setEnabled(false);
  3529. App()->IncrementSleepInhibition();
  3530. UpdateProcessPriority();
  3531. if (trayIcon)
  3532. trayIcon->setIcon(QIcon(":/res/images/tray_active.png"));
  3533. }
  3534. }
  3535. inline void OBSBasic::OnDeactivate()
  3536. {
  3537. if (!outputHandler->Active() && !ui->profileMenu->isEnabled()) {
  3538. ui->profileMenu->setEnabled(true);
  3539. ui->autoConfigure->setEnabled(true);
  3540. App()->DecrementSleepInhibition();
  3541. ClearProcessPriority();
  3542. if (trayIcon)
  3543. trayIcon->setIcon(QIcon(":/res/images/obs.png"));
  3544. }
  3545. }
  3546. void OBSBasic::StopStreaming()
  3547. {
  3548. SaveProject();
  3549. if (outputHandler->StreamingActive())
  3550. outputHandler->StopStreaming(streamingStopping);
  3551. OnDeactivate();
  3552. bool recordWhenStreaming = config_get_bool(GetGlobalConfig(),
  3553. "BasicWindow", "RecordWhenStreaming");
  3554. bool keepRecordingWhenStreamStops = config_get_bool(GetGlobalConfig(),
  3555. "BasicWindow", "KeepRecordingWhenStreamStops");
  3556. if (recordWhenStreaming && !keepRecordingWhenStreamStops)
  3557. StopRecording();
  3558. bool replayBufferWhileStreaming = config_get_bool(GetGlobalConfig(),
  3559. "BasicWindow", "ReplayBufferWhileStreaming");
  3560. bool keepReplayBufferStreamStops = config_get_bool(GetGlobalConfig(),
  3561. "BasicWindow", "KeepReplayBufferStreamStops");
  3562. if (replayBufferWhileStreaming && !keepReplayBufferStreamStops)
  3563. StopReplayBuffer();
  3564. }
  3565. void OBSBasic::ForceStopStreaming()
  3566. {
  3567. SaveProject();
  3568. if (outputHandler->StreamingActive())
  3569. outputHandler->StopStreaming(true);
  3570. OnDeactivate();
  3571. bool recordWhenStreaming = config_get_bool(GetGlobalConfig(),
  3572. "BasicWindow", "RecordWhenStreaming");
  3573. bool keepRecordingWhenStreamStops = config_get_bool(GetGlobalConfig(),
  3574. "BasicWindow", "KeepRecordingWhenStreamStops");
  3575. if (recordWhenStreaming && !keepRecordingWhenStreamStops)
  3576. StopRecording();
  3577. bool replayBufferWhileStreaming = config_get_bool(GetGlobalConfig(),
  3578. "BasicWindow", "ReplayBufferWhileStreaming");
  3579. bool keepReplayBufferStreamStops = config_get_bool(GetGlobalConfig(),
  3580. "BasicWindow", "KeepReplayBufferStreamStops");
  3581. if (replayBufferWhileStreaming && !keepReplayBufferStreamStops)
  3582. StopReplayBuffer();
  3583. }
  3584. void OBSBasic::StreamDelayStarting(int sec)
  3585. {
  3586. ui->streamButton->setText(QTStr("Basic.Main.StopStreaming"));
  3587. ui->streamButton->setEnabled(true);
  3588. ui->streamButton->setChecked(true);
  3589. if (sysTrayStream) {
  3590. sysTrayStream->setText(ui->streamButton->text());
  3591. sysTrayStream->setEnabled(true);
  3592. }
  3593. if (!startStreamMenu.isNull())
  3594. startStreamMenu->deleteLater();
  3595. startStreamMenu = new QMenu();
  3596. startStreamMenu->addAction(QTStr("Basic.Main.StopStreaming"),
  3597. this, SLOT(StopStreaming()));
  3598. startStreamMenu->addAction(QTStr("Basic.Main.ForceStopStreaming"),
  3599. this, SLOT(ForceStopStreaming()));
  3600. ui->streamButton->setMenu(startStreamMenu);
  3601. ui->statusbar->StreamDelayStarting(sec);
  3602. OnActivate();
  3603. }
  3604. void OBSBasic::StreamDelayStopping(int sec)
  3605. {
  3606. ui->streamButton->setText(QTStr("Basic.Main.StartStreaming"));
  3607. ui->streamButton->setEnabled(true);
  3608. ui->streamButton->setChecked(false);
  3609. if (sysTrayStream) {
  3610. sysTrayStream->setText(ui->streamButton->text());
  3611. sysTrayStream->setEnabled(true);
  3612. }
  3613. if (!startStreamMenu.isNull())
  3614. startStreamMenu->deleteLater();
  3615. startStreamMenu = new QMenu();
  3616. startStreamMenu->addAction(QTStr("Basic.Main.StartStreaming"),
  3617. this, SLOT(StartStreaming()));
  3618. startStreamMenu->addAction(QTStr("Basic.Main.ForceStopStreaming"),
  3619. this, SLOT(ForceStopStreaming()));
  3620. ui->streamButton->setMenu(startStreamMenu);
  3621. ui->statusbar->StreamDelayStopping(sec);
  3622. }
  3623. void OBSBasic::StreamingStart()
  3624. {
  3625. ui->streamButton->setText(QTStr("Basic.Main.StopStreaming"));
  3626. ui->streamButton->setEnabled(true);
  3627. ui->streamButton->setChecked(true);
  3628. ui->statusbar->StreamStarted(outputHandler->streamOutput);
  3629. if (sysTrayStream) {
  3630. sysTrayStream->setText(ui->streamButton->text());
  3631. sysTrayStream->setEnabled(true);
  3632. }
  3633. if (api)
  3634. api->on_event(OBS_FRONTEND_EVENT_STREAMING_STARTED);
  3635. OnActivate();
  3636. blog(LOG_INFO, STREAMING_START);
  3637. }
  3638. void OBSBasic::StreamStopping()
  3639. {
  3640. ui->streamButton->setText(QTStr("Basic.Main.StoppingStreaming"));
  3641. if (sysTrayStream)
  3642. sysTrayStream->setText(ui->streamButton->text());
  3643. streamingStopping = true;
  3644. if (api)
  3645. api->on_event(OBS_FRONTEND_EVENT_STREAMING_STOPPING);
  3646. }
  3647. void OBSBasic::StreamingStop(int code, QString last_error)
  3648. {
  3649. const char *errorDescription;
  3650. DStr errorMessage;
  3651. bool use_last_error = false;
  3652. switch (code) {
  3653. case OBS_OUTPUT_BAD_PATH:
  3654. errorDescription = Str("Output.ConnectFail.BadPath");
  3655. break;
  3656. case OBS_OUTPUT_CONNECT_FAILED:
  3657. use_last_error = true;
  3658. errorDescription = Str("Output.ConnectFail.ConnectFailed");
  3659. break;
  3660. case OBS_OUTPUT_INVALID_STREAM:
  3661. errorDescription = Str("Output.ConnectFail.InvalidStream");
  3662. break;
  3663. default:
  3664. case OBS_OUTPUT_ERROR:
  3665. use_last_error = true;
  3666. errorDescription = Str("Output.ConnectFail.Error");
  3667. break;
  3668. case OBS_OUTPUT_DISCONNECTED:
  3669. /* doesn't happen if output is set to reconnect. note that
  3670. * reconnects are handled in the output, not in the UI */
  3671. use_last_error = true;
  3672. errorDescription = Str("Output.ConnectFail.Disconnected");
  3673. }
  3674. if (use_last_error && !last_error.isEmpty())
  3675. dstr_printf(errorMessage, "%s\n\n%s", errorDescription,
  3676. QT_TO_UTF8(last_error));
  3677. else
  3678. dstr_copy(errorMessage, errorDescription);
  3679. ui->statusbar->StreamStopped();
  3680. ui->streamButton->setText(QTStr("Basic.Main.StartStreaming"));
  3681. ui->streamButton->setEnabled(true);
  3682. ui->streamButton->setChecked(false);
  3683. if (sysTrayStream) {
  3684. sysTrayStream->setText(ui->streamButton->text());
  3685. sysTrayStream->setEnabled(true);
  3686. }
  3687. streamingStopping = false;
  3688. if (api)
  3689. api->on_event(OBS_FRONTEND_EVENT_STREAMING_STOPPED);
  3690. OnDeactivate();
  3691. blog(LOG_INFO, STREAMING_STOP);
  3692. if (code != OBS_OUTPUT_SUCCESS && isVisible()) {
  3693. OBSMessageBox::information(this,
  3694. QTStr("Output.ConnectFail.Title"),
  3695. QT_UTF8(errorMessage));
  3696. } else if (code != OBS_OUTPUT_SUCCESS && !isVisible()) {
  3697. SysTrayNotify(QT_UTF8(errorDescription), QSystemTrayIcon::Warning);
  3698. }
  3699. if (!startStreamMenu.isNull()) {
  3700. ui->streamButton->setMenu(nullptr);
  3701. startStreamMenu->deleteLater();
  3702. startStreamMenu = nullptr;
  3703. }
  3704. }
  3705. void OBSBasic::StartRecording()
  3706. {
  3707. if (outputHandler->RecordingActive())
  3708. return;
  3709. if (disableOutputsRef)
  3710. return;
  3711. if (api)
  3712. api->on_event(OBS_FRONTEND_EVENT_RECORDING_STARTING);
  3713. SaveProject();
  3714. outputHandler->StartRecording();
  3715. }
  3716. void OBSBasic::RecordStopping()
  3717. {
  3718. ui->recordButton->setText(QTStr("Basic.Main.StoppingRecording"));
  3719. if (sysTrayRecord)
  3720. sysTrayRecord->setText(ui->recordButton->text());
  3721. recordingStopping = true;
  3722. if (api)
  3723. api->on_event(OBS_FRONTEND_EVENT_RECORDING_STOPPING);
  3724. }
  3725. void OBSBasic::StopRecording()
  3726. {
  3727. SaveProject();
  3728. if (outputHandler->RecordingActive())
  3729. outputHandler->StopRecording(recordingStopping);
  3730. OnDeactivate();
  3731. }
  3732. void OBSBasic::RecordingStart()
  3733. {
  3734. ui->statusbar->RecordingStarted(outputHandler->fileOutput);
  3735. ui->recordButton->setText(QTStr("Basic.Main.StopRecording"));
  3736. ui->recordButton->setChecked(true);
  3737. if (sysTrayRecord)
  3738. sysTrayRecord->setText(ui->recordButton->text());
  3739. recordingStopping = false;
  3740. if (api)
  3741. api->on_event(OBS_FRONTEND_EVENT_RECORDING_STARTED);
  3742. OnActivate();
  3743. blog(LOG_INFO, RECORDING_START);
  3744. }
  3745. void OBSBasic::RecordingStop(int code)
  3746. {
  3747. ui->statusbar->RecordingStopped();
  3748. ui->recordButton->setText(QTStr("Basic.Main.StartRecording"));
  3749. ui->recordButton->setChecked(false);
  3750. if (sysTrayRecord)
  3751. sysTrayRecord->setText(ui->recordButton->text());
  3752. blog(LOG_INFO, RECORDING_STOP);
  3753. if (code == OBS_OUTPUT_UNSUPPORTED && isVisible()) {
  3754. OBSMessageBox::information(this,
  3755. QTStr("Output.RecordFail.Title"),
  3756. QTStr("Output.RecordFail.Unsupported"));
  3757. } else if (code == OBS_OUTPUT_NO_SPACE && isVisible()) {
  3758. OBSMessageBox::information(this,
  3759. QTStr("Output.RecordNoSpace.Title"),
  3760. QTStr("Output.RecordNoSpace.Msg"));
  3761. } else if (code != OBS_OUTPUT_SUCCESS && isVisible()) {
  3762. OBSMessageBox::information(this,
  3763. QTStr("Output.RecordError.Title"),
  3764. QTStr("Output.RecordError.Msg"));
  3765. } else if (code == OBS_OUTPUT_UNSUPPORTED && !isVisible()) {
  3766. SysTrayNotify(QTStr("Output.RecordFail.Unsupported"),
  3767. QSystemTrayIcon::Warning);
  3768. } else if (code == OBS_OUTPUT_NO_SPACE && !isVisible()) {
  3769. SysTrayNotify(QTStr("Output.RecordNoSpace.Msg"),
  3770. QSystemTrayIcon::Warning);
  3771. } else if (code != OBS_OUTPUT_SUCCESS && !isVisible()) {
  3772. SysTrayNotify(QTStr("Output.RecordError.Msg"),
  3773. QSystemTrayIcon::Warning);
  3774. }
  3775. if (api)
  3776. api->on_event(OBS_FRONTEND_EVENT_RECORDING_STOPPED);
  3777. OnDeactivate();
  3778. }
  3779. #define RP_NO_HOTKEY_TITLE QTStr("Output.ReplayBuffer.NoHotkey.Title")
  3780. #define RP_NO_HOTKEY_TEXT QTStr("Output.ReplayBuffer.NoHotkey.Msg")
  3781. void OBSBasic::StartReplayBuffer()
  3782. {
  3783. if (!outputHandler || !outputHandler->replayBuffer)
  3784. return;
  3785. if (outputHandler->ReplayBufferActive())
  3786. return;
  3787. if (disableOutputsRef)
  3788. return;
  3789. obs_output_t *output = outputHandler->replayBuffer;
  3790. obs_data_t *hotkeys = obs_hotkeys_save_output(output);
  3791. obs_data_array_t *bindings = obs_data_get_array(hotkeys,
  3792. "ReplayBuffer.Save");
  3793. size_t count = obs_data_array_count(bindings);
  3794. obs_data_array_release(bindings);
  3795. obs_data_release(hotkeys);
  3796. if (!count) {
  3797. OBSMessageBox::information(this,
  3798. RP_NO_HOTKEY_TITLE,
  3799. RP_NO_HOTKEY_TEXT);
  3800. return;
  3801. }
  3802. if (api)
  3803. api->on_event(OBS_FRONTEND_EVENT_REPLAY_BUFFER_STARTING);
  3804. SaveProject();
  3805. outputHandler->StartReplayBuffer();
  3806. }
  3807. void OBSBasic::ReplayBufferStopping()
  3808. {
  3809. if (!outputHandler || !outputHandler->replayBuffer)
  3810. return;
  3811. replayBufferButton->setText(QTStr("Basic.Main.StoppingReplayBuffer"));
  3812. if (sysTrayReplayBuffer)
  3813. sysTrayReplayBuffer->setText(replayBufferButton->text());
  3814. replayBufferStopping = true;
  3815. if (api)
  3816. api->on_event(OBS_FRONTEND_EVENT_REPLAY_BUFFER_STOPPING);
  3817. }
  3818. void OBSBasic::StopReplayBuffer()
  3819. {
  3820. if (!outputHandler || !outputHandler->replayBuffer)
  3821. return;
  3822. SaveProject();
  3823. if (outputHandler->ReplayBufferActive())
  3824. outputHandler->StopReplayBuffer(replayBufferStopping);
  3825. OnDeactivate();
  3826. }
  3827. void OBSBasic::ReplayBufferStart()
  3828. {
  3829. if (!outputHandler || !outputHandler->replayBuffer)
  3830. return;
  3831. replayBufferButton->setText(QTStr("Basic.Main.StopReplayBuffer"));
  3832. if (sysTrayReplayBuffer)
  3833. sysTrayReplayBuffer->setText(replayBufferButton->text());
  3834. replayBufferStopping = false;
  3835. if (api)
  3836. api->on_event(OBS_FRONTEND_EVENT_REPLAY_BUFFER_STARTED);
  3837. OnActivate();
  3838. blog(LOG_INFO, REPLAY_BUFFER_START);
  3839. }
  3840. void OBSBasic::ReplayBufferSave()
  3841. {
  3842. if (!outputHandler || !outputHandler->replayBuffer)
  3843. return;
  3844. if (!outputHandler->ReplayBufferActive())
  3845. return;
  3846. calldata_t cd = {0};
  3847. proc_handler_t *ph = obs_output_get_proc_handler(
  3848. outputHandler->replayBuffer);
  3849. proc_handler_call(ph, "save", &cd);
  3850. calldata_free(&cd);
  3851. }
  3852. void OBSBasic::ReplayBufferStop(int code)
  3853. {
  3854. if (!outputHandler || !outputHandler->replayBuffer)
  3855. return;
  3856. replayBufferButton->setText(QTStr("Basic.Main.StartReplayBuffer"));
  3857. if (sysTrayReplayBuffer)
  3858. sysTrayReplayBuffer->setText(replayBufferButton->text());
  3859. blog(LOG_INFO, REPLAY_BUFFER_STOP);
  3860. if (code == OBS_OUTPUT_UNSUPPORTED && isVisible()) {
  3861. OBSMessageBox::information(this,
  3862. QTStr("Output.RecordFail.Title"),
  3863. QTStr("Output.RecordFail.Unsupported"));
  3864. } else if (code == OBS_OUTPUT_NO_SPACE && isVisible()) {
  3865. OBSMessageBox::information(this,
  3866. QTStr("Output.RecordNoSpace.Title"),
  3867. QTStr("Output.RecordNoSpace.Msg"));
  3868. } else if (code != OBS_OUTPUT_SUCCESS && isVisible()) {
  3869. OBSMessageBox::information(this,
  3870. QTStr("Output.RecordError.Title"),
  3871. QTStr("Output.RecordError.Msg"));
  3872. } else if (code == OBS_OUTPUT_UNSUPPORTED && !isVisible()) {
  3873. SysTrayNotify(QTStr("Output.RecordFail.Unsupported"),
  3874. QSystemTrayIcon::Warning);
  3875. } else if (code == OBS_OUTPUT_NO_SPACE && !isVisible()) {
  3876. SysTrayNotify(QTStr("Output.RecordNoSpace.Msg"),
  3877. QSystemTrayIcon::Warning);
  3878. } else if (code != OBS_OUTPUT_SUCCESS && !isVisible()) {
  3879. SysTrayNotify(QTStr("Output.RecordError.Msg"),
  3880. QSystemTrayIcon::Warning);
  3881. }
  3882. if (api)
  3883. api->on_event(OBS_FRONTEND_EVENT_REPLAY_BUFFER_STOPPED);
  3884. OnDeactivate();
  3885. }
  3886. void OBSBasic::on_streamButton_clicked()
  3887. {
  3888. if (outputHandler->StreamingActive()) {
  3889. bool confirm = config_get_bool(GetGlobalConfig(), "BasicWindow",
  3890. "WarnBeforeStoppingStream");
  3891. if (confirm && isVisible()) {
  3892. QMessageBox::StandardButton button =
  3893. OBSMessageBox::question(this,
  3894. QTStr("ConfirmStop.Title"),
  3895. QTStr("ConfirmStop.Text"));
  3896. if (button == QMessageBox::No)
  3897. return;
  3898. }
  3899. StopStreaming();
  3900. } else {
  3901. bool confirm = config_get_bool(GetGlobalConfig(), "BasicWindow",
  3902. "WarnBeforeStartingStream");
  3903. if (confirm && isVisible()) {
  3904. QMessageBox::StandardButton button =
  3905. OBSMessageBox::question(this,
  3906. QTStr("ConfirmStart.Title"),
  3907. QTStr("ConfirmStart.Text"));
  3908. if (button == QMessageBox::No)
  3909. return;
  3910. }
  3911. StartStreaming();
  3912. }
  3913. }
  3914. void OBSBasic::on_recordButton_clicked()
  3915. {
  3916. if (outputHandler->RecordingActive())
  3917. StopRecording();
  3918. else
  3919. StartRecording();
  3920. }
  3921. void OBSBasic::on_settingsButton_clicked()
  3922. {
  3923. on_action_Settings_triggered();
  3924. }
  3925. void OBSBasic::on_actionWebsite_triggered()
  3926. {
  3927. QUrl url = QUrl("https://obsproject.com", QUrl::TolerantMode);
  3928. QDesktopServices::openUrl(url);
  3929. }
  3930. void OBSBasic::on_actionShowSettingsFolder_triggered()
  3931. {
  3932. char path[512];
  3933. int ret = GetConfigPath(path, 512, "obs-studio");
  3934. if (ret <= 0)
  3935. return;
  3936. QDesktopServices::openUrl(QUrl::fromLocalFile(path));
  3937. }
  3938. void OBSBasic::on_actionShowProfileFolder_triggered()
  3939. {
  3940. char path[512];
  3941. int ret = GetProfilePath(path, 512, "");
  3942. if (ret <= 0)
  3943. return;
  3944. QDesktopServices::openUrl(QUrl::fromLocalFile(path));
  3945. }
  3946. QListWidgetItem *OBSBasic::GetTopSelectedSourceItem()
  3947. {
  3948. QList<QListWidgetItem*> selectedItems = ui->sources->selectedItems();
  3949. QListWidgetItem *topItem = nullptr;
  3950. if (selectedItems.size() != 0)
  3951. topItem = selectedItems[0];
  3952. return topItem;
  3953. }
  3954. void OBSBasic::on_preview_customContextMenuRequested(const QPoint &pos)
  3955. {
  3956. CreateSourcePopupMenu(GetTopSelectedSourceItem(), true);
  3957. UNUSED_PARAMETER(pos);
  3958. }
  3959. void OBSBasic::on_program_customContextMenuRequested(const QPoint&)
  3960. {
  3961. QMenu popup(this);
  3962. QPointer<QMenu> studioProgramProjector;
  3963. studioProgramProjector = new QMenu(
  3964. QTStr("StudioProgramProjector"));
  3965. AddProjectorMenuMonitors(studioProgramProjector, this,
  3966. SLOT(OpenPreviewProjector()));
  3967. popup.addMenu(studioProgramProjector);
  3968. QAction *studioProgramWindow = popup.addAction(
  3969. QTStr("StudioProgramWindow"),
  3970. this, SLOT(OpenPreviewWindow()));
  3971. popup.addAction(studioProgramWindow);
  3972. popup.exec(QCursor::pos());
  3973. }
  3974. void OBSBasic::on_previewDisabledLabel_customContextMenuRequested(
  3975. const QPoint &pos)
  3976. {
  3977. QMenu popup(this);
  3978. QPointer<QMenu> previewProjector;
  3979. QAction *action = popup.addAction(
  3980. QTStr("Basic.Main.PreviewConextMenu.Enable"),
  3981. this, SLOT(TogglePreview()));
  3982. action->setCheckable(true);
  3983. action->setChecked(obs_display_enabled(ui->preview->GetDisplay()));
  3984. previewProjector = new QMenu(QTStr("PreviewProjector"));
  3985. AddProjectorMenuMonitors(previewProjector, this,
  3986. SLOT(OpenPreviewProjector()));
  3987. QAction *previewWindow = popup.addAction(
  3988. QTStr("PreviewWindow"),
  3989. this, SLOT(OpenPreviewWindow()));
  3990. popup.addMenu(previewProjector);
  3991. popup.addAction(previewWindow);
  3992. popup.exec(QCursor::pos());
  3993. UNUSED_PARAMETER(pos);
  3994. }
  3995. void OBSBasic::on_actionAlwaysOnTop_triggered()
  3996. {
  3997. CloseDialogs();
  3998. /* Make sure all dialogs are safely and successfully closed before
  3999. * switching the always on top mode due to the fact that windows all
  4000. * have to be recreated, so queue the actual toggle to happen after
  4001. * all events related to closing the dialogs have finished */
  4002. QMetaObject::invokeMethod(this, "ToggleAlwaysOnTop",
  4003. Qt::QueuedConnection);
  4004. }
  4005. void OBSBasic::ToggleAlwaysOnTop()
  4006. {
  4007. bool isAlwaysOnTop = IsAlwaysOnTop(this);
  4008. ui->actionAlwaysOnTop->setChecked(!isAlwaysOnTop);
  4009. SetAlwaysOnTop(this, !isAlwaysOnTop);
  4010. show();
  4011. }
  4012. void OBSBasic::GetFPSCommon(uint32_t &num, uint32_t &den) const
  4013. {
  4014. const char *val = config_get_string(basicConfig, "Video", "FPSCommon");
  4015. if (strcmp(val, "10") == 0) {
  4016. num = 10;
  4017. den = 1;
  4018. } else if (strcmp(val, "20") == 0) {
  4019. num = 20;
  4020. den = 1;
  4021. } else if (strcmp(val, "24 NTSC") == 0) {
  4022. num = 24000;
  4023. den = 1001;
  4024. } else if (strcmp(val, "25") == 0) {
  4025. num = 25;
  4026. den = 1;
  4027. } else if (strcmp(val, "29.97") == 0) {
  4028. num = 30000;
  4029. den = 1001;
  4030. } else if (strcmp(val, "48") == 0) {
  4031. num = 48;
  4032. den = 1;
  4033. } else if (strcmp(val, "59.94") == 0) {
  4034. num = 60000;
  4035. den = 1001;
  4036. } else if (strcmp(val, "60") == 0) {
  4037. num = 60;
  4038. den = 1;
  4039. } else {
  4040. num = 30;
  4041. den = 1;
  4042. }
  4043. }
  4044. void OBSBasic::GetFPSInteger(uint32_t &num, uint32_t &den) const
  4045. {
  4046. num = (uint32_t)config_get_uint(basicConfig, "Video", "FPSInt");
  4047. den = 1;
  4048. }
  4049. void OBSBasic::GetFPSFraction(uint32_t &num, uint32_t &den) const
  4050. {
  4051. num = (uint32_t)config_get_uint(basicConfig, "Video", "FPSNum");
  4052. den = (uint32_t)config_get_uint(basicConfig, "Video", "FPSDen");
  4053. }
  4054. void OBSBasic::GetFPSNanoseconds(uint32_t &num, uint32_t &den) const
  4055. {
  4056. num = 1000000000;
  4057. den = (uint32_t)config_get_uint(basicConfig, "Video", "FPSNS");
  4058. }
  4059. void OBSBasic::GetConfigFPS(uint32_t &num, uint32_t &den) const
  4060. {
  4061. uint32_t type = config_get_uint(basicConfig, "Video", "FPSType");
  4062. if (type == 1) //"Integer"
  4063. GetFPSInteger(num, den);
  4064. else if (type == 2) //"Fraction"
  4065. GetFPSFraction(num, den);
  4066. else if (false) //"Nanoseconds", currently not implemented
  4067. GetFPSNanoseconds(num, den);
  4068. else
  4069. GetFPSCommon(num, den);
  4070. }
  4071. config_t *OBSBasic::Config() const
  4072. {
  4073. return basicConfig;
  4074. }
  4075. void OBSBasic::on_actionEditTransform_triggered()
  4076. {
  4077. if (transformWindow)
  4078. transformWindow->close();
  4079. transformWindow = new OBSBasicTransform(this);
  4080. transformWindow->show();
  4081. transformWindow->setAttribute(Qt::WA_DeleteOnClose, true);
  4082. }
  4083. static obs_transform_info copiedTransformInfo;
  4084. static obs_sceneitem_crop copiedCropInfo;
  4085. void OBSBasic::on_actionCopyTransform_triggered()
  4086. {
  4087. auto func = [](obs_scene_t *scene, obs_sceneitem_t *item, void *param)
  4088. {
  4089. if (!obs_sceneitem_selected(item))
  4090. return true;
  4091. obs_sceneitem_defer_update_begin(item);
  4092. obs_sceneitem_get_info(item, &copiedTransformInfo);
  4093. obs_sceneitem_get_crop(item, &copiedCropInfo);
  4094. obs_sceneitem_defer_update_end(item);
  4095. UNUSED_PARAMETER(scene);
  4096. UNUSED_PARAMETER(param);
  4097. return true;
  4098. };
  4099. obs_scene_enum_items(GetCurrentScene(), func, nullptr);
  4100. ui->actionPasteTransform->setEnabled(true);
  4101. }
  4102. void OBSBasic::on_actionPasteTransform_triggered()
  4103. {
  4104. auto func = [](obs_scene_t *scene, obs_sceneitem_t *item, void *param)
  4105. {
  4106. if (!obs_sceneitem_selected(item))
  4107. return true;
  4108. obs_sceneitem_defer_update_begin(item);
  4109. obs_sceneitem_set_info(item, &copiedTransformInfo);
  4110. obs_sceneitem_set_crop(item, &copiedCropInfo);
  4111. obs_sceneitem_defer_update_end(item);
  4112. UNUSED_PARAMETER(scene);
  4113. UNUSED_PARAMETER(param);
  4114. return true;
  4115. };
  4116. obs_scene_enum_items(GetCurrentScene(), func, nullptr);
  4117. }
  4118. void OBSBasic::on_actionResetTransform_triggered()
  4119. {
  4120. auto func = [] (obs_scene_t *scene, obs_sceneitem_t *item, void *param)
  4121. {
  4122. if (!obs_sceneitem_selected(item))
  4123. return true;
  4124. obs_sceneitem_defer_update_begin(item);
  4125. obs_transform_info info;
  4126. vec2_set(&info.pos, 0.0f, 0.0f);
  4127. vec2_set(&info.scale, 1.0f, 1.0f);
  4128. info.rot = 0.0f;
  4129. info.alignment = OBS_ALIGN_TOP | OBS_ALIGN_LEFT;
  4130. info.bounds_type = OBS_BOUNDS_NONE;
  4131. info.bounds_alignment = OBS_ALIGN_CENTER;
  4132. vec2_set(&info.bounds, 0.0f, 0.0f);
  4133. obs_sceneitem_set_info(item, &info);
  4134. obs_sceneitem_crop crop = {};
  4135. obs_sceneitem_set_crop(item, &crop);
  4136. obs_sceneitem_defer_update_end(item);
  4137. UNUSED_PARAMETER(scene);
  4138. UNUSED_PARAMETER(param);
  4139. return true;
  4140. };
  4141. obs_scene_enum_items(GetCurrentScene(), func, nullptr);
  4142. }
  4143. static void GetItemBox(obs_sceneitem_t *item, vec3 &tl, vec3 &br)
  4144. {
  4145. matrix4 boxTransform;
  4146. obs_sceneitem_get_box_transform(item, &boxTransform);
  4147. vec3_set(&tl, M_INFINITE, M_INFINITE, 0.0f);
  4148. vec3_set(&br, -M_INFINITE, -M_INFINITE, 0.0f);
  4149. auto GetMinPos = [&] (float x, float y)
  4150. {
  4151. vec3 pos;
  4152. vec3_set(&pos, x, y, 0.0f);
  4153. vec3_transform(&pos, &pos, &boxTransform);
  4154. vec3_min(&tl, &tl, &pos);
  4155. vec3_max(&br, &br, &pos);
  4156. };
  4157. GetMinPos(0.0f, 0.0f);
  4158. GetMinPos(1.0f, 0.0f);
  4159. GetMinPos(0.0f, 1.0f);
  4160. GetMinPos(1.0f, 1.0f);
  4161. }
  4162. static vec3 GetItemTL(obs_sceneitem_t *item)
  4163. {
  4164. vec3 tl, br;
  4165. GetItemBox(item, tl, br);
  4166. return tl;
  4167. }
  4168. static void SetItemTL(obs_sceneitem_t *item, const vec3 &tl)
  4169. {
  4170. vec3 newTL;
  4171. vec2 pos;
  4172. obs_sceneitem_get_pos(item, &pos);
  4173. newTL = GetItemTL(item);
  4174. pos.x += tl.x - newTL.x;
  4175. pos.y += tl.y - newTL.y;
  4176. obs_sceneitem_set_pos(item, &pos);
  4177. }
  4178. static bool RotateSelectedSources(obs_scene_t *scene, obs_sceneitem_t *item,
  4179. void *param)
  4180. {
  4181. if (!obs_sceneitem_selected(item))
  4182. return true;
  4183. float rot = *reinterpret_cast<float*>(param);
  4184. vec3 tl = GetItemTL(item);
  4185. rot += obs_sceneitem_get_rot(item);
  4186. if (rot >= 360.0f) rot -= 360.0f;
  4187. else if (rot <= -360.0f) rot += 360.0f;
  4188. obs_sceneitem_set_rot(item, rot);
  4189. SetItemTL(item, tl);
  4190. UNUSED_PARAMETER(scene);
  4191. UNUSED_PARAMETER(param);
  4192. return true;
  4193. };
  4194. void OBSBasic::on_actionRotate90CW_triggered()
  4195. {
  4196. float f90CW = 90.0f;
  4197. obs_scene_enum_items(GetCurrentScene(), RotateSelectedSources, &f90CW);
  4198. }
  4199. void OBSBasic::on_actionRotate90CCW_triggered()
  4200. {
  4201. float f90CCW = -90.0f;
  4202. obs_scene_enum_items(GetCurrentScene(), RotateSelectedSources, &f90CCW);
  4203. }
  4204. void OBSBasic::on_actionRotate180_triggered()
  4205. {
  4206. float f180 = 180.0f;
  4207. obs_scene_enum_items(GetCurrentScene(), RotateSelectedSources, &f180);
  4208. }
  4209. static bool MultiplySelectedItemScale(obs_scene_t *scene, obs_sceneitem_t *item,
  4210. void *param)
  4211. {
  4212. vec2 &mul = *reinterpret_cast<vec2*>(param);
  4213. if (!obs_sceneitem_selected(item))
  4214. return true;
  4215. vec3 tl = GetItemTL(item);
  4216. vec2 scale;
  4217. obs_sceneitem_get_scale(item, &scale);
  4218. vec2_mul(&scale, &scale, &mul);
  4219. obs_sceneitem_set_scale(item, &scale);
  4220. SetItemTL(item, tl);
  4221. UNUSED_PARAMETER(scene);
  4222. return true;
  4223. }
  4224. void OBSBasic::on_actionFlipHorizontal_triggered()
  4225. {
  4226. vec2 scale;
  4227. vec2_set(&scale, -1.0f, 1.0f);
  4228. obs_scene_enum_items(GetCurrentScene(), MultiplySelectedItemScale,
  4229. &scale);
  4230. }
  4231. void OBSBasic::on_actionFlipVertical_triggered()
  4232. {
  4233. vec2 scale;
  4234. vec2_set(&scale, 1.0f, -1.0f);
  4235. obs_scene_enum_items(GetCurrentScene(), MultiplySelectedItemScale,
  4236. &scale);
  4237. }
  4238. static bool CenterAlignSelectedItems(obs_scene_t *scene, obs_sceneitem_t *item,
  4239. void *param)
  4240. {
  4241. obs_bounds_type boundsType = *reinterpret_cast<obs_bounds_type*>(param);
  4242. if (!obs_sceneitem_selected(item))
  4243. return true;
  4244. obs_video_info ovi;
  4245. obs_get_video_info(&ovi);
  4246. obs_transform_info itemInfo;
  4247. vec2_set(&itemInfo.pos, 0.0f, 0.0f);
  4248. vec2_set(&itemInfo.scale, 1.0f, 1.0f);
  4249. itemInfo.alignment = OBS_ALIGN_LEFT | OBS_ALIGN_TOP;
  4250. itemInfo.rot = 0.0f;
  4251. vec2_set(&itemInfo.bounds,
  4252. float(ovi.base_width), float(ovi.base_height));
  4253. itemInfo.bounds_type = boundsType;
  4254. itemInfo.bounds_alignment = OBS_ALIGN_CENTER;
  4255. obs_sceneitem_set_info(item, &itemInfo);
  4256. UNUSED_PARAMETER(scene);
  4257. return true;
  4258. }
  4259. void OBSBasic::on_actionFitToScreen_triggered()
  4260. {
  4261. obs_bounds_type boundsType = OBS_BOUNDS_SCALE_INNER;
  4262. obs_scene_enum_items(GetCurrentScene(), CenterAlignSelectedItems,
  4263. &boundsType);
  4264. }
  4265. void OBSBasic::on_actionStretchToScreen_triggered()
  4266. {
  4267. obs_bounds_type boundsType = OBS_BOUNDS_STRETCH;
  4268. obs_scene_enum_items(GetCurrentScene(), CenterAlignSelectedItems,
  4269. &boundsType);
  4270. }
  4271. void OBSBasic::on_actionCenterToScreen_triggered()
  4272. {
  4273. auto func = [] (obs_scene_t *scene, obs_sceneitem_t *item, void *param)
  4274. {
  4275. vec3 tl, br, itemCenter, screenCenter, offset;
  4276. obs_video_info ovi;
  4277. if (!obs_sceneitem_selected(item))
  4278. return true;
  4279. obs_get_video_info(&ovi);
  4280. vec3_set(&screenCenter, float(ovi.base_width),
  4281. float(ovi.base_height), 0.0f);
  4282. vec3_mulf(&screenCenter, &screenCenter, 0.5f);
  4283. GetItemBox(item, tl, br);
  4284. vec3_sub(&itemCenter, &br, &tl);
  4285. vec3_mulf(&itemCenter, &itemCenter, 0.5f);
  4286. vec3_add(&itemCenter, &itemCenter, &tl);
  4287. vec3_sub(&offset, &screenCenter, &itemCenter);
  4288. vec3_add(&tl, &tl, &offset);
  4289. SetItemTL(item, tl);
  4290. UNUSED_PARAMETER(scene);
  4291. UNUSED_PARAMETER(param);
  4292. return true;
  4293. };
  4294. obs_scene_enum_items(GetCurrentScene(), func, nullptr);
  4295. }
  4296. void OBSBasic::EnablePreviewDisplay(bool enable)
  4297. {
  4298. obs_display_set_enabled(ui->preview->GetDisplay(), enable);
  4299. ui->preview->setVisible(enable);
  4300. ui->previewDisabledLabel->setVisible(!enable);
  4301. }
  4302. void OBSBasic::TogglePreview()
  4303. {
  4304. previewEnabled = !previewEnabled;
  4305. EnablePreviewDisplay(previewEnabled);
  4306. }
  4307. void OBSBasic::Nudge(int dist, MoveDir dir)
  4308. {
  4309. if (ui->preview->Locked())
  4310. return;
  4311. struct MoveInfo {
  4312. float dist;
  4313. MoveDir dir;
  4314. } info = {(float)dist, dir};
  4315. auto func = [] (obs_scene_t*, obs_sceneitem_t *item, void *param)
  4316. {
  4317. if (obs_sceneitem_locked(item))
  4318. return true;
  4319. MoveInfo *info = reinterpret_cast<MoveInfo*>(param);
  4320. struct vec2 dir;
  4321. struct vec2 pos;
  4322. vec2_set(&dir, 0.0f, 0.0f);
  4323. if (!obs_sceneitem_selected(item))
  4324. return true;
  4325. switch (info->dir) {
  4326. case MoveDir::Up: dir.y = -info->dist; break;
  4327. case MoveDir::Down: dir.y = info->dist; break;
  4328. case MoveDir::Left: dir.x = -info->dist; break;
  4329. case MoveDir::Right: dir.x = info->dist; break;
  4330. }
  4331. obs_sceneitem_get_pos(item, &pos);
  4332. vec2_add(&pos, &pos, &dir);
  4333. obs_sceneitem_set_pos(item, &pos);
  4334. return true;
  4335. };
  4336. obs_scene_enum_items(GetCurrentScene(), func, &info);
  4337. }
  4338. void OBSBasic::NudgeUp() {Nudge(1, MoveDir::Up);}
  4339. void OBSBasic::NudgeDown() {Nudge(1, MoveDir::Down);}
  4340. void OBSBasic::NudgeLeft() {Nudge(1, MoveDir::Left);}
  4341. void OBSBasic::NudgeRight() {Nudge(1, MoveDir::Right);}
  4342. void OBSBasic::OpenProjector(obs_source_t *source, int monitor, bool window,
  4343. QString title, bool studioProgram)
  4344. {
  4345. /* seriously? 10 monitors? */
  4346. if (monitor > 9 || monitor > QGuiApplication::screens().size() - 1)
  4347. return;
  4348. bool isPreview = false;
  4349. if (source == nullptr)
  4350. isPreview = true;
  4351. if (!window) {
  4352. delete projectors[monitor];
  4353. projectors[monitor].clear();
  4354. RemoveSavedProjectors(monitor);
  4355. }
  4356. OBSProjector *projector = new OBSProjector(nullptr, source, !!window);
  4357. const char *name = obs_source_get_name(source);
  4358. if (!window) {
  4359. if (studioProgram) {
  4360. studioProgramProjectorArray.at((size_t)monitor) = 1;
  4361. } else if (isPreview) {
  4362. previewProjectorArray.at((size_t)monitor) = 1;
  4363. } else {
  4364. projectorArray.at((size_t)monitor) = name;
  4365. }
  4366. }
  4367. if (!window) {
  4368. projector->Init(monitor, false, nullptr, studioProgram);
  4369. projectors[monitor] = projector;
  4370. } else {
  4371. projector->Init(monitor, true, title, studioProgram);
  4372. for (auto &projPtr : windowProjectors) {
  4373. if (!projPtr) {
  4374. projPtr = projector;
  4375. projector = nullptr;
  4376. }
  4377. }
  4378. if (projector)
  4379. windowProjectors.push_back(projector);
  4380. }
  4381. }
  4382. void OBSBasic::OpenStudioProgramProjector()
  4383. {
  4384. int monitor = sender()->property("monitor").toInt();
  4385. OpenProjector(nullptr, monitor, false, nullptr, true);
  4386. }
  4387. void OBSBasic::OpenPreviewProjector()
  4388. {
  4389. int monitor = sender()->property("monitor").toInt();
  4390. OpenProjector(nullptr, monitor, false);
  4391. }
  4392. void OBSBasic::OpenSourceProjector()
  4393. {
  4394. int monitor = sender()->property("monitor").toInt();
  4395. OBSSceneItem item = GetCurrentSceneItem();
  4396. if (!item)
  4397. return;
  4398. OpenProjector(obs_sceneitem_get_source(item), monitor, false);
  4399. }
  4400. void OBSBasic::OpenSceneProjector()
  4401. {
  4402. int monitor = sender()->property("monitor").toInt();
  4403. OBSScene scene = GetCurrentScene();
  4404. if (!scene)
  4405. return;
  4406. OpenProjector(obs_scene_get_source(scene), monitor, false);
  4407. }
  4408. void OBSBasic::OpenStudioProgramWindow()
  4409. {
  4410. int monitor = sender()->property("monitor").toInt();
  4411. QString title = QTStr("StudioProgramWindow");
  4412. OpenProjector(nullptr, monitor, true, title, true);
  4413. }
  4414. void OBSBasic::OpenPreviewWindow()
  4415. {
  4416. int monitor = sender()->property("monitor").toInt();
  4417. QString title = QTStr("PreviewWindow");
  4418. OpenProjector(nullptr, monitor, true, title);
  4419. }
  4420. void OBSBasic::OpenSourceWindow()
  4421. {
  4422. int monitor = sender()->property("monitor").toInt();
  4423. OBSSceneItem item = GetCurrentSceneItem();
  4424. OBSSource source = obs_sceneitem_get_source(item);
  4425. QString text = QString::fromUtf8(obs_source_get_name(source));
  4426. QString title = QTStr("SourceWindow") + " - " + text;
  4427. if (!item)
  4428. return;
  4429. OpenProjector(obs_sceneitem_get_source(item), monitor, true, title);
  4430. }
  4431. void OBSBasic::OpenSceneWindow()
  4432. {
  4433. int monitor = sender()->property("monitor").toInt();
  4434. OBSScene scene = GetCurrentScene();
  4435. OBSSource source = obs_scene_get_source(scene);
  4436. QString text = QString::fromUtf8(obs_source_get_name(source));
  4437. QString title = QTStr("SceneWindow") + " - " + text;
  4438. if (!scene)
  4439. return;
  4440. OpenProjector(obs_scene_get_source(scene), monitor, true, title);
  4441. }
  4442. void OBSBasic::OpenSavedProjectors()
  4443. {
  4444. bool projectorSave = config_get_bool(GetGlobalConfig(),
  4445. "BasicWindow", "SaveProjectors");
  4446. if (projectorSave) {
  4447. for (size_t i = 0; i < projectorArray.size(); i++) {
  4448. if (projectorArray.at(i).empty() == false) {
  4449. OBSSource source = obs_get_source_by_name(
  4450. projectorArray.at(i).c_str());
  4451. if (!source) {
  4452. RemoveSavedProjectors((int)i);
  4453. obs_source_release(source);
  4454. continue;
  4455. }
  4456. OpenProjector(source, (int)i, false);
  4457. obs_source_release(source);
  4458. }
  4459. }
  4460. for (size_t i = 0; i < studioProgramProjectorArray.size(); i++) {
  4461. if (studioProgramProjectorArray.at(i) == 1) {
  4462. OpenProjector(nullptr, (int)i, false, nullptr,
  4463. true);
  4464. }
  4465. }
  4466. for (size_t i = 0; i < previewProjectorArray.size(); i++) {
  4467. if (previewProjectorArray.at(i) == 1) {
  4468. OpenProjector(nullptr, (int)i, false);
  4469. }
  4470. }
  4471. }
  4472. }
  4473. void OBSBasic::RemoveSavedProjectors(int monitor)
  4474. {
  4475. studioProgramProjectorArray.at((size_t)monitor) = 0;
  4476. previewProjectorArray.at((size_t)monitor) = 0;
  4477. projectorArray.at((size_t)monitor) = "";
  4478. }
  4479. void OBSBasic::on_actionFullscreenInterface_triggered()
  4480. {
  4481. if (!fullscreenInterface)
  4482. showFullScreen();
  4483. else
  4484. showNormal();
  4485. fullscreenInterface = !fullscreenInterface;
  4486. }
  4487. void OBSBasic::UpdateTitleBar()
  4488. {
  4489. stringstream name;
  4490. const char *profile = config_get_string(App()->GlobalConfig(),
  4491. "Basic", "Profile");
  4492. const char *sceneCollection = config_get_string(App()->GlobalConfig(),
  4493. "Basic", "SceneCollection");
  4494. name << "OBS ";
  4495. if (previewProgramMode)
  4496. name << "Studio ";
  4497. name << App()->GetVersionString();
  4498. if (App()->IsPortableMode())
  4499. name << " - Portable Mode";
  4500. name << " - " << Str("TitleBar.Profile") << ": " << profile;
  4501. name << " - " << Str("TitleBar.Scenes") << ": " << sceneCollection;
  4502. setWindowTitle(QT_UTF8(name.str().c_str()));
  4503. }
  4504. int OBSBasic::GetProfilePath(char *path, size_t size, const char *file) const
  4505. {
  4506. char profiles_path[512];
  4507. const char *profile = config_get_string(App()->GlobalConfig(),
  4508. "Basic", "ProfileDir");
  4509. int ret;
  4510. if (!profile)
  4511. return -1;
  4512. if (!path)
  4513. return -1;
  4514. if (!file)
  4515. file = "";
  4516. ret = GetConfigPath(profiles_path, 512, "obs-studio/basic/profiles");
  4517. if (ret <= 0)
  4518. return ret;
  4519. if (!*file)
  4520. return snprintf(path, size, "%s/%s", profiles_path, profile);
  4521. return snprintf(path, size, "%s/%s/%s", profiles_path, profile, file);
  4522. }
  4523. void OBSBasic::on_resetUI_triggered()
  4524. {
  4525. restoreState(startingDockLayout);
  4526. #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
  4527. int cx = width();
  4528. int cy = height();
  4529. int cx22_5 = cx * 225 / 1000;
  4530. int cx5 = cx * 5 / 100;
  4531. cy = cy * 225 / 1000;
  4532. int mixerSize = cx - (cx22_5 * 2 + cx5 * 2);
  4533. QList<QDockWidget*> docks {
  4534. ui->scenesDock,
  4535. ui->sourcesDock,
  4536. ui->mixerDock,
  4537. ui->transitionsDock,
  4538. ui->controlsDock
  4539. };
  4540. QList<int> sizes {
  4541. cx22_5,
  4542. cx22_5,
  4543. mixerSize,
  4544. cx5,
  4545. cx5
  4546. };
  4547. ui->scenesDock->setVisible(true);
  4548. ui->sourcesDock->setVisible(true);
  4549. ui->mixerDock->setVisible(true);
  4550. ui->transitionsDock->setVisible(true);
  4551. ui->controlsDock->setVisible(true);
  4552. resizeDocks(docks, {cy, cy, cy, cy, cy}, Qt::Vertical);
  4553. resizeDocks(docks, sizes, Qt::Horizontal);
  4554. #endif
  4555. }
  4556. void OBSBasic::on_lockUI_toggled(bool lock)
  4557. {
  4558. QDockWidget::DockWidgetFeatures features = lock
  4559. ? QDockWidget::NoDockWidgetFeatures
  4560. : QDockWidget::AllDockWidgetFeatures;
  4561. ui->scenesDock->setFeatures(features);
  4562. ui->sourcesDock->setFeatures(features);
  4563. ui->mixerDock->setFeatures(features);
  4564. ui->transitionsDock->setFeatures(features);
  4565. ui->controlsDock->setFeatures(features);
  4566. }
  4567. void OBSBasic::on_toggleListboxToolbars_toggled(bool visible)
  4568. {
  4569. ui->sourcesToolbar->setVisible(visible);
  4570. ui->scenesToolbar->setVisible(visible);
  4571. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  4572. "ShowListboxToolbars", visible);
  4573. }
  4574. void OBSBasic::on_toggleStatusBar_toggled(bool visible)
  4575. {
  4576. ui->statusbar->setVisible(visible);
  4577. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  4578. "ShowStatusBar", visible);
  4579. }
  4580. void OBSBasic::on_actionLockPreview_triggered()
  4581. {
  4582. ui->preview->ToggleLocked();
  4583. ui->actionLockPreview->setChecked(ui->preview->Locked());
  4584. }
  4585. void OBSBasic::on_scalingMenu_aboutToShow()
  4586. {
  4587. obs_video_info ovi;
  4588. obs_get_video_info(&ovi);
  4589. QAction *action = ui->actionScaleCanvas;
  4590. QString text = QTStr("Basic.MainMenu.Edit.Scale.Canvas");
  4591. text = text.arg(QString::number(ovi.base_width),
  4592. QString::number(ovi.base_height));
  4593. action->setText(text);
  4594. action = ui->actionScaleOutput;
  4595. text = QTStr("Basic.MainMenu.Edit.Scale.Output");
  4596. text = text.arg(QString::number(ovi.output_width),
  4597. QString::number(ovi.output_height));
  4598. action->setText(text);
  4599. action->setVisible(!(ovi.output_width == ovi.base_width &&
  4600. ovi.output_height == ovi.base_height));
  4601. UpdatePreviewScalingMenu();
  4602. }
  4603. void OBSBasic::on_actionScaleWindow_triggered()
  4604. {
  4605. ui->preview->SetFixedScaling(false);
  4606. ui->preview->ResetScrollingOffset();
  4607. emit ui->preview->DisplayResized();
  4608. }
  4609. void OBSBasic::on_actionScaleCanvas_triggered()
  4610. {
  4611. ui->preview->SetFixedScaling(true);
  4612. ui->preview->SetScalingLevel(0);
  4613. emit ui->preview->DisplayResized();
  4614. }
  4615. void OBSBasic::on_actionScaleOutput_triggered()
  4616. {
  4617. obs_video_info ovi;
  4618. obs_get_video_info(&ovi);
  4619. ui->preview->SetFixedScaling(true);
  4620. float scalingAmount = float(ovi.output_width) / float(ovi.base_width);
  4621. // log base ZOOM_SENSITIVITY of x = log(x) / log(ZOOM_SENSITIVITY)
  4622. int32_t approxScalingLevel = int32_t(
  4623. round(log(scalingAmount) / log(ZOOM_SENSITIVITY)));
  4624. ui->preview->SetScalingLevel(approxScalingLevel);
  4625. ui->preview->SetScalingAmount(scalingAmount);
  4626. emit ui->preview->DisplayResized();
  4627. }
  4628. void OBSBasic::SetShowing(bool showing)
  4629. {
  4630. if (!showing && isVisible()) {
  4631. config_set_string(App()->GlobalConfig(),
  4632. "BasicWindow", "geometry",
  4633. saveGeometry().toBase64().constData());
  4634. /* hide all visible child dialogs */
  4635. visDlgPositions.clear();
  4636. if (!visDialogs.isEmpty()) {
  4637. for (QDialog *dlg : visDialogs) {
  4638. visDlgPositions.append(dlg->pos());
  4639. dlg->hide();
  4640. }
  4641. }
  4642. if (showHide)
  4643. showHide->setText(QTStr("Basic.SystemTray.Show"));
  4644. QTimer::singleShot(250, this, SLOT(hide()));
  4645. if (previewEnabled)
  4646. EnablePreviewDisplay(false);
  4647. setVisible(false);
  4648. } else if (showing && !isVisible()) {
  4649. if (showHide)
  4650. showHide->setText(QTStr("Basic.SystemTray.Hide"));
  4651. QTimer::singleShot(250, this, SLOT(show()));
  4652. if (previewEnabled)
  4653. EnablePreviewDisplay(true);
  4654. setVisible(true);
  4655. /* show all child dialogs that was visible earlier */
  4656. if (!visDialogs.isEmpty()) {
  4657. for (int i = 0; i < visDialogs.size(); ++i) {
  4658. QDialog *dlg = visDialogs[i];
  4659. dlg->move(visDlgPositions[i]);
  4660. dlg->show();
  4661. }
  4662. }
  4663. /* Unminimize window if it was hidden to tray instead of task
  4664. * bar. */
  4665. if (sysTrayMinimizeToTray()) {
  4666. Qt::WindowStates state;
  4667. state = windowState() & ~Qt::WindowMinimized;
  4668. state |= Qt::WindowActive;
  4669. setWindowState(state);
  4670. }
  4671. }
  4672. }
  4673. void OBSBasic::ToggleShowHide()
  4674. {
  4675. bool showing = isVisible();
  4676. if (showing) {
  4677. /* check for modal dialogs */
  4678. EnumDialogs();
  4679. if (!modalDialogs.isEmpty() || !visMsgBoxes.isEmpty())
  4680. return;
  4681. }
  4682. SetShowing(!showing);
  4683. }
  4684. void OBSBasic::SystemTrayInit()
  4685. {
  4686. trayIcon = new QSystemTrayIcon(QIcon(":/res/images/obs.png"),
  4687. this);
  4688. trayIcon->setToolTip("OBS Studio");
  4689. showHide = new QAction(QTStr("Basic.SystemTray.Show"),
  4690. trayIcon);
  4691. sysTrayStream = new QAction(QTStr("Basic.Main.StartStreaming"),
  4692. trayIcon);
  4693. sysTrayRecord = new QAction(QTStr("Basic.Main.StartRecording"),
  4694. trayIcon);
  4695. sysTrayReplayBuffer = new QAction(QTStr("Basic.Main.StartReplayBuffer"),
  4696. trayIcon);
  4697. exit = new QAction(QTStr("Exit"),
  4698. trayIcon);
  4699. if (outputHandler && !outputHandler->replayBuffer)
  4700. sysTrayReplayBuffer->setEnabled(false);
  4701. connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
  4702. this,
  4703. SLOT(IconActivated(QSystemTrayIcon::ActivationReason)));
  4704. connect(showHide, SIGNAL(triggered()),
  4705. this, SLOT(ToggleShowHide()));
  4706. connect(sysTrayStream, SIGNAL(triggered()),
  4707. this, SLOT(on_streamButton_clicked()));
  4708. connect(sysTrayRecord, SIGNAL(triggered()),
  4709. this, SLOT(on_recordButton_clicked()));
  4710. connect(sysTrayReplayBuffer.data(), &QAction::triggered,
  4711. this, &OBSBasic::ReplayBufferClicked);
  4712. connect(exit, SIGNAL(triggered()),
  4713. this, SLOT(close()));
  4714. QMenu *previewProjector = new QMenu(QTStr("PreviewProjector"));
  4715. AddProjectorMenuMonitors(previewProjector, this,
  4716. SLOT(OpenPreviewProjector()));
  4717. QMenu *studioProgramProjector = new QMenu(
  4718. QTStr("StudioProgramProjector"));
  4719. AddProjectorMenuMonitors(studioProgramProjector, this,
  4720. SLOT(OpenStudioProgramProjector()));
  4721. trayMenu = new QMenu;
  4722. trayMenu->addAction(showHide);
  4723. trayMenu->addMenu(previewProjector);
  4724. trayMenu->addMenu(studioProgramProjector);
  4725. trayMenu->addAction(sysTrayStream);
  4726. trayMenu->addAction(sysTrayRecord);
  4727. trayMenu->addAction(sysTrayReplayBuffer);
  4728. trayMenu->addAction(exit);
  4729. trayIcon->setContextMenu(trayMenu);
  4730. }
  4731. void OBSBasic::IconActivated(QSystemTrayIcon::ActivationReason reason)
  4732. {
  4733. if (reason == QSystemTrayIcon::Trigger)
  4734. ToggleShowHide();
  4735. }
  4736. void OBSBasic::SysTrayNotify(const QString &text,
  4737. QSystemTrayIcon::MessageIcon n)
  4738. {
  4739. if (QSystemTrayIcon::supportsMessages()) {
  4740. QSystemTrayIcon::MessageIcon icon =
  4741. QSystemTrayIcon::MessageIcon(n);
  4742. trayIcon->showMessage("OBS Studio", text, icon, 10000);
  4743. }
  4744. }
  4745. void OBSBasic::SystemTray(bool firstStarted)
  4746. {
  4747. if (!QSystemTrayIcon::isSystemTrayAvailable())
  4748. return;
  4749. bool sysTrayWhenStarted = config_get_bool(GetGlobalConfig(),
  4750. "BasicWindow", "SysTrayWhenStarted");
  4751. bool sysTrayEnabled = config_get_bool(GetGlobalConfig(),
  4752. "BasicWindow", "SysTrayEnabled");
  4753. if (firstStarted)
  4754. SystemTrayInit();
  4755. if (!sysTrayWhenStarted && !sysTrayEnabled) {
  4756. trayIcon->hide();
  4757. } else if ((sysTrayWhenStarted && sysTrayEnabled)
  4758. || opt_minimize_tray) {
  4759. trayIcon->show();
  4760. if (firstStarted) {
  4761. QTimer::singleShot(50, this, SLOT(hide()));
  4762. EnablePreviewDisplay(false);
  4763. setVisible(false);
  4764. opt_minimize_tray = false;
  4765. }
  4766. } else if (sysTrayEnabled) {
  4767. trayIcon->show();
  4768. } else if (!sysTrayEnabled) {
  4769. trayIcon->hide();
  4770. } else if (!sysTrayWhenStarted && sysTrayEnabled) {
  4771. trayIcon->hide();
  4772. }
  4773. if (isVisible())
  4774. showHide->setText(QTStr("Basic.SystemTray.Hide"));
  4775. else
  4776. showHide->setText(QTStr("Basic.SystemTray.Show"));
  4777. }
  4778. bool OBSBasic::sysTrayMinimizeToTray()
  4779. {
  4780. return config_get_bool(GetGlobalConfig(),
  4781. "BasicWindow", "SysTrayMinimizeToTray");
  4782. }
  4783. void OBSBasic::on_actionCopySource_triggered()
  4784. {
  4785. on_actionCopyTransform_triggered();
  4786. OBSSceneItem item = GetCurrentSceneItem();
  4787. if (!item)
  4788. return;
  4789. OBSSource source = obs_sceneitem_get_source(item);
  4790. copyString = obs_source_get_name(source);
  4791. copyVisible = obs_sceneitem_visible(item);
  4792. ui->actionPasteRef->setEnabled(true);
  4793. uint32_t output_flags = obs_source_get_output_flags(source);
  4794. if ((output_flags & OBS_SOURCE_DO_NOT_DUPLICATE) == 0)
  4795. ui->actionPasteDup->setEnabled(true);
  4796. else
  4797. ui->actionPasteDup->setEnabled(false);
  4798. }
  4799. void OBSBasic::on_actionPasteRef_triggered()
  4800. {
  4801. OBSBasicSourceSelect::SourcePaste(copyString, copyVisible, false);
  4802. on_actionPasteTransform_triggered();
  4803. }
  4804. void OBSBasic::on_actionPasteDup_triggered()
  4805. {
  4806. OBSBasicSourceSelect::SourcePaste(copyString, copyVisible, true);
  4807. on_actionPasteTransform_triggered();
  4808. }
  4809. void OBSBasic::on_actionCopyFilters_triggered()
  4810. {
  4811. OBSSceneItem item = GetCurrentSceneItem();
  4812. if (!item)
  4813. return;
  4814. OBSSource source = obs_sceneitem_get_source(item);
  4815. copyFiltersString = obs_source_get_name(source);
  4816. ui->actionPasteFilters->setEnabled(true);
  4817. }
  4818. void OBSBasic::on_actionPasteFilters_triggered()
  4819. {
  4820. OBSSource source = obs_get_source_by_name(copyFiltersString);
  4821. OBSSceneItem sceneItem = GetCurrentSceneItem();
  4822. OBSSource dstSource = obs_sceneitem_get_source(sceneItem);
  4823. if (source == dstSource)
  4824. return;
  4825. obs_source_copy_filters(dstSource, source);
  4826. }
  4827. void OBSBasic::on_autoConfigure_triggered()
  4828. {
  4829. AutoConfig test(this);
  4830. test.setModal(true);
  4831. test.show();
  4832. test.exec();
  4833. }
  4834. void OBSBasic::on_stats_triggered()
  4835. {
  4836. if (!stats.isNull()) {
  4837. stats->show();
  4838. stats->raise();
  4839. return;
  4840. }
  4841. OBSBasicStats *statsDlg;
  4842. statsDlg = new OBSBasicStats(nullptr);
  4843. statsDlg->show();
  4844. stats = statsDlg;
  4845. }