window-basic-main.cpp 158 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045
  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, "");
  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_string(data, "saved_studio_preview_projectors",
  376. studioProgramProjectorArray.at(i).c_str());
  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_string(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. int OBSBasic::ResetVideo()
  2399. {
  2400. if (outputHandler && outputHandler->Active())
  2401. return OBS_VIDEO_CURRENTLY_ACTIVE;
  2402. ProfileScope("OBSBasic::ResetVideo");
  2403. struct obs_video_info ovi;
  2404. int ret;
  2405. GetConfigFPS(ovi.fps_num, ovi.fps_den);
  2406. const char *colorFormat = config_get_string(basicConfig, "Video",
  2407. "ColorFormat");
  2408. const char *colorSpace = config_get_string(basicConfig, "Video",
  2409. "ColorSpace");
  2410. const char *colorRange = config_get_string(basicConfig, "Video",
  2411. "ColorRange");
  2412. ovi.graphics_module = App()->GetRenderModule();
  2413. ovi.base_width = (uint32_t)config_get_uint(basicConfig,
  2414. "Video", "BaseCX");
  2415. ovi.base_height = (uint32_t)config_get_uint(basicConfig,
  2416. "Video", "BaseCY");
  2417. ovi.output_width = (uint32_t)config_get_uint(basicConfig,
  2418. "Video", "OutputCX");
  2419. ovi.output_height = (uint32_t)config_get_uint(basicConfig,
  2420. "Video", "OutputCY");
  2421. ovi.output_format = GetVideoFormatFromName(colorFormat);
  2422. ovi.colorspace = astrcmpi(colorSpace, "601") == 0 ?
  2423. VIDEO_CS_601 : VIDEO_CS_709;
  2424. ovi.range = astrcmpi(colorRange, "Full") == 0 ?
  2425. VIDEO_RANGE_FULL : VIDEO_RANGE_PARTIAL;
  2426. ovi.adapter = config_get_uint(App()->GlobalConfig(),
  2427. "Video", "AdapterIdx");
  2428. ovi.gpu_conversion = true;
  2429. ovi.scale_type = GetScaleType(basicConfig);
  2430. if (ovi.base_width == 0 || ovi.base_height == 0) {
  2431. ovi.base_width = 1920;
  2432. ovi.base_height = 1080;
  2433. config_set_uint(basicConfig, "Video", "BaseCX", 1920);
  2434. config_set_uint(basicConfig, "Video", "BaseCY", 1080);
  2435. }
  2436. if (ovi.output_width == 0 || ovi.output_height == 0) {
  2437. ovi.output_width = ovi.base_width;
  2438. ovi.output_height = ovi.base_height;
  2439. config_set_uint(basicConfig, "Video", "OutputCX",
  2440. ovi.base_width);
  2441. config_set_uint(basicConfig, "Video", "OutputCY",
  2442. ovi.base_height);
  2443. }
  2444. ret = AttemptToResetVideo(&ovi);
  2445. if (IS_WIN32 && ret != OBS_VIDEO_SUCCESS) {
  2446. if (ret == OBS_VIDEO_CURRENTLY_ACTIVE) {
  2447. blog(LOG_WARNING, "Tried to reset when "
  2448. "already active");
  2449. return ret;
  2450. }
  2451. /* Try OpenGL if DirectX fails on windows */
  2452. if (astrcmpi(ovi.graphics_module, DL_OPENGL) != 0) {
  2453. blog(LOG_WARNING, "Failed to initialize obs video (%d) "
  2454. "with graphics_module='%s', retrying "
  2455. "with graphics_module='%s'",
  2456. ret, ovi.graphics_module,
  2457. DL_OPENGL);
  2458. ovi.graphics_module = DL_OPENGL;
  2459. ret = AttemptToResetVideo(&ovi);
  2460. }
  2461. } else if (ret == OBS_VIDEO_SUCCESS) {
  2462. ResizePreview(ovi.base_width, ovi.base_height);
  2463. if (program)
  2464. ResizeProgram(ovi.base_width, ovi.base_height);
  2465. }
  2466. if (ret == OBS_VIDEO_SUCCESS)
  2467. OBSBasicStats::InitializeValues();
  2468. return ret;
  2469. }
  2470. bool OBSBasic::ResetAudio()
  2471. {
  2472. ProfileScope("OBSBasic::ResetAudio");
  2473. struct obs_audio_info ai;
  2474. ai.samples_per_sec = config_get_uint(basicConfig, "Audio",
  2475. "SampleRate");
  2476. const char *channelSetupStr = config_get_string(basicConfig,
  2477. "Audio", "ChannelSetup");
  2478. if (strcmp(channelSetupStr, "Mono") == 0)
  2479. ai.speakers = SPEAKERS_MONO;
  2480. else if (strcmp(channelSetupStr, "2.1") == 0)
  2481. ai.speakers = SPEAKERS_2POINT1;
  2482. else if (strcmp(channelSetupStr, "4.0 Quad") == 0)
  2483. ai.speakers = SPEAKERS_QUAD;
  2484. else if (strcmp(channelSetupStr, "4.1") == 0)
  2485. ai.speakers = SPEAKERS_4POINT1;
  2486. else if (strcmp(channelSetupStr, "5.1") == 0)
  2487. ai.speakers = SPEAKERS_5POINT1;
  2488. else if (strcmp(channelSetupStr, "7.1") == 0)
  2489. ai.speakers = SPEAKERS_7POINT1;
  2490. else
  2491. ai.speakers = SPEAKERS_STEREO;
  2492. return obs_reset_audio(&ai);
  2493. }
  2494. void OBSBasic::ResetAudioDevice(const char *sourceId, const char *deviceId,
  2495. const char *deviceDesc, int channel)
  2496. {
  2497. bool disable = deviceId && strcmp(deviceId, "disabled") == 0;
  2498. obs_source_t *source;
  2499. obs_data_t *settings;
  2500. source = obs_get_output_source(channel);
  2501. if (source) {
  2502. if (disable) {
  2503. obs_set_output_source(channel, nullptr);
  2504. } else {
  2505. settings = obs_source_get_settings(source);
  2506. const char *oldId = obs_data_get_string(settings,
  2507. "device_id");
  2508. if (strcmp(oldId, deviceId) != 0) {
  2509. obs_data_set_string(settings, "device_id",
  2510. deviceId);
  2511. obs_source_update(source, settings);
  2512. }
  2513. obs_data_release(settings);
  2514. }
  2515. obs_source_release(source);
  2516. } else if (!disable) {
  2517. settings = obs_data_create();
  2518. obs_data_set_string(settings, "device_id", deviceId);
  2519. source = obs_source_create(sourceId, deviceDesc, settings,
  2520. nullptr);
  2521. obs_data_release(settings);
  2522. obs_set_output_source(channel, source);
  2523. obs_source_release(source);
  2524. }
  2525. }
  2526. void OBSBasic::ResizePreview(uint32_t cx, uint32_t cy)
  2527. {
  2528. QSize targetSize;
  2529. bool isFixedScaling;
  2530. obs_video_info ovi;
  2531. /* resize preview panel to fix to the top section of the window */
  2532. targetSize = GetPixelSize(ui->preview);
  2533. isFixedScaling = ui->preview->IsFixedScaling();
  2534. obs_get_video_info(&ovi);
  2535. if (isFixedScaling) {
  2536. previewScale = ui->preview->GetScalingAmount();
  2537. GetCenterPosFromFixedScale(int(cx), int(cy),
  2538. targetSize.width() - PREVIEW_EDGE_SIZE * 2,
  2539. targetSize.height() - PREVIEW_EDGE_SIZE * 2,
  2540. previewX, previewY, previewScale);
  2541. previewX += ui->preview->GetScrollX();
  2542. previewY += ui->preview->GetScrollY();
  2543. } else {
  2544. GetScaleAndCenterPos(int(cx), int(cy),
  2545. targetSize.width() - PREVIEW_EDGE_SIZE * 2,
  2546. targetSize.height() - PREVIEW_EDGE_SIZE * 2,
  2547. previewX, previewY, previewScale);
  2548. }
  2549. previewX += float(PREVIEW_EDGE_SIZE);
  2550. previewY += float(PREVIEW_EDGE_SIZE);
  2551. }
  2552. void OBSBasic::CloseDialogs()
  2553. {
  2554. QList<QDialog*> childDialogs = this->findChildren<QDialog *>();
  2555. if (!childDialogs.isEmpty()) {
  2556. for (int i = 0; i < childDialogs.size(); ++i) {
  2557. childDialogs.at(i)->close();
  2558. }
  2559. }
  2560. for (QPointer<QWidget> &projector : windowProjectors) {
  2561. delete projector;
  2562. projector.clear();
  2563. }
  2564. for (QPointer<QWidget> &projector : projectors) {
  2565. delete projector;
  2566. projector.clear();
  2567. }
  2568. if (!stats.isNull()) stats->close(); //call close to save Stats geometry
  2569. }
  2570. void OBSBasic::EnumDialogs()
  2571. {
  2572. visDialogs.clear();
  2573. modalDialogs.clear();
  2574. visMsgBoxes.clear();
  2575. /* fill list of Visible dialogs and Modal dialogs */
  2576. QList<QDialog*> dialogs = findChildren<QDialog*>();
  2577. for (QDialog *dialog : dialogs) {
  2578. if (dialog->isVisible())
  2579. visDialogs.append(dialog);
  2580. if (dialog->isModal())
  2581. modalDialogs.append(dialog);
  2582. }
  2583. /* fill list of Visible message boxes */
  2584. QList<QMessageBox*> msgBoxes = findChildren<QMessageBox*>();
  2585. for (QMessageBox *msgbox : msgBoxes) {
  2586. if (msgbox->isVisible())
  2587. visMsgBoxes.append(msgbox);
  2588. }
  2589. }
  2590. void OBSBasic::ClearSceneData()
  2591. {
  2592. disableSaving++;
  2593. CloseDialogs();
  2594. ClearVolumeControls();
  2595. ClearListItems(ui->scenes);
  2596. ClearListItems(ui->sources);
  2597. ClearQuickTransitions();
  2598. ui->transitions->clear();
  2599. obs_set_output_source(0, nullptr);
  2600. obs_set_output_source(1, nullptr);
  2601. obs_set_output_source(2, nullptr);
  2602. obs_set_output_source(3, nullptr);
  2603. obs_set_output_source(4, nullptr);
  2604. obs_set_output_source(5, nullptr);
  2605. lastScene = nullptr;
  2606. swapScene = nullptr;
  2607. programScene = nullptr;
  2608. auto cb = [](void *unused, obs_source_t *source)
  2609. {
  2610. obs_source_remove(source);
  2611. UNUSED_PARAMETER(unused);
  2612. return true;
  2613. };
  2614. obs_enum_sources(cb, nullptr);
  2615. disableSaving--;
  2616. blog(LOG_INFO, "All scene data cleared");
  2617. blog(LOG_INFO, "------------------------------------------------");
  2618. }
  2619. void OBSBasic::closeEvent(QCloseEvent *event)
  2620. {
  2621. if (isVisible())
  2622. config_set_string(App()->GlobalConfig(),
  2623. "BasicWindow", "geometry",
  2624. saveGeometry().toBase64().constData());
  2625. config_set_string(App()->GlobalConfig(),
  2626. "BasicWindow", "DockState",
  2627. saveState().toBase64().constData());
  2628. if (outputHandler && outputHandler->Active()) {
  2629. SetShowing(true);
  2630. QMessageBox::StandardButton button = OBSMessageBox::question(
  2631. this, QTStr("ConfirmExit.Title"),
  2632. QTStr("ConfirmExit.Text"));
  2633. if (button == QMessageBox::No) {
  2634. event->ignore();
  2635. return;
  2636. }
  2637. }
  2638. QWidget::closeEvent(event);
  2639. if (!event->isAccepted())
  2640. return;
  2641. blog(LOG_INFO, SHUTDOWN_SEPARATOR);
  2642. if (updateCheckThread)
  2643. updateCheckThread->wait();
  2644. if (logUploadThread)
  2645. logUploadThread->wait();
  2646. signalHandlers.clear();
  2647. SaveProjectNow();
  2648. if (api)
  2649. api->on_event(OBS_FRONTEND_EVENT_EXIT);
  2650. disableSaving++;
  2651. /* Clear all scene data (dialogs, widgets, widget sub-items, scenes,
  2652. * sources, etc) so that all references are released before shutdown */
  2653. ClearSceneData();
  2654. App()->quit();
  2655. }
  2656. void OBSBasic::changeEvent(QEvent *event)
  2657. {
  2658. if (event->type() == QEvent::WindowStateChange &&
  2659. isMinimized() &&
  2660. trayIcon &&
  2661. trayIcon->isVisible() &&
  2662. sysTrayMinimizeToTray()) {
  2663. ToggleShowHide();
  2664. }
  2665. }
  2666. void OBSBasic::on_actionShow_Recordings_triggered()
  2667. {
  2668. const char *mode = config_get_string(basicConfig, "Output", "Mode");
  2669. const char *path = strcmp(mode, "Advanced") ?
  2670. config_get_string(basicConfig, "SimpleOutput", "FilePath") :
  2671. config_get_string(basicConfig, "AdvOut", "RecFilePath");
  2672. QDesktopServices::openUrl(QUrl::fromLocalFile(path));
  2673. }
  2674. void OBSBasic::on_actionRemux_triggered()
  2675. {
  2676. const char *mode = config_get_string(basicConfig, "Output", "Mode");
  2677. const char *path = strcmp(mode, "Advanced") ?
  2678. config_get_string(basicConfig, "SimpleOutput", "FilePath") :
  2679. config_get_string(basicConfig, "AdvOut", "RecFilePath");
  2680. OBSRemux remux(path, this);
  2681. remux.exec();
  2682. }
  2683. void OBSBasic::on_action_Settings_triggered()
  2684. {
  2685. OBSBasicSettings settings(this);
  2686. settings.exec();
  2687. SystemTray(false);
  2688. }
  2689. void OBSBasic::on_actionAdvAudioProperties_triggered()
  2690. {
  2691. if (advAudioWindow != nullptr) {
  2692. advAudioWindow->raise();
  2693. return;
  2694. }
  2695. advAudioWindow = new OBSBasicAdvAudio(this);
  2696. advAudioWindow->show();
  2697. advAudioWindow->setAttribute(Qt::WA_DeleteOnClose, true);
  2698. connect(advAudioWindow, SIGNAL(destroyed()),
  2699. this, SLOT(on_advAudioProps_destroyed()));
  2700. }
  2701. void OBSBasic::on_advAudioProps_clicked()
  2702. {
  2703. on_actionAdvAudioProperties_triggered();
  2704. }
  2705. void OBSBasic::on_advAudioProps_destroyed()
  2706. {
  2707. advAudioWindow = nullptr;
  2708. }
  2709. void OBSBasic::on_scenes_currentItemChanged(QListWidgetItem *current,
  2710. QListWidgetItem *prev)
  2711. {
  2712. obs_source_t *source = NULL;
  2713. if (sceneChanging)
  2714. return;
  2715. if (current) {
  2716. obs_scene_t *scene;
  2717. scene = GetOBSRef<OBSScene>(current);
  2718. source = obs_scene_get_source(scene);
  2719. }
  2720. SetCurrentScene(source);
  2721. UNUSED_PARAMETER(prev);
  2722. }
  2723. void OBSBasic::EditSceneName()
  2724. {
  2725. QListWidgetItem *item = ui->scenes->currentItem();
  2726. Qt::ItemFlags flags = item->flags();
  2727. item->setFlags(flags | Qt::ItemIsEditable);
  2728. ui->scenes->editItem(item);
  2729. item->setFlags(flags);
  2730. }
  2731. static void AddProjectorMenuMonitors(QMenu *parent, QObject *target,
  2732. const char *slot)
  2733. {
  2734. QAction *action;
  2735. QList<QScreen*> screens = QGuiApplication::screens();
  2736. for (int i = 0; i < screens.size(); i++) {
  2737. QRect screenGeometry = screens[i]->geometry();
  2738. QString str = QString("%1 %2: %3x%4 @ %5,%6").
  2739. arg(QTStr("Display"),
  2740. QString::number(i),
  2741. QString::number((int)screenGeometry.width()),
  2742. QString::number((int)screenGeometry.height()),
  2743. QString::number((int)screenGeometry.x()),
  2744. QString::number((int)screenGeometry.y()));
  2745. action = parent->addAction(str, target, slot);
  2746. action->setProperty("monitor", i);
  2747. }
  2748. }
  2749. void OBSBasic::on_scenes_customContextMenuRequested(const QPoint &pos)
  2750. {
  2751. QListWidgetItem *item = ui->scenes->itemAt(pos);
  2752. QPointer<QMenu> sceneProjectorMenu;
  2753. QMenu popup(this);
  2754. QMenu order(QTStr("Basic.MainMenu.Edit.Order"), this);
  2755. popup.addAction(QTStr("Add"),
  2756. this, SLOT(on_actionAddScene_triggered()));
  2757. if (item) {
  2758. popup.addSeparator();
  2759. popup.addAction(QTStr("Duplicate"),
  2760. this, SLOT(DuplicateSelectedScene()));
  2761. popup.addAction(QTStr("Rename"),
  2762. this, SLOT(EditSceneName()));
  2763. popup.addAction(QTStr("Remove"),
  2764. this, SLOT(RemoveSelectedScene()),
  2765. DeleteKeys.front());
  2766. popup.addSeparator();
  2767. order.addAction(QTStr("Basic.MainMenu.Edit.Order.MoveUp"),
  2768. this, SLOT(on_actionSceneUp_triggered()));
  2769. order.addAction(QTStr("Basic.MainMenu.Edit.Order.MoveDown"),
  2770. this, SLOT(on_actionSceneDown_triggered()));
  2771. order.addSeparator();
  2772. order.addAction(QTStr("Basic.MainMenu.Edit.Order.MoveToTop"),
  2773. this, SLOT(MoveSceneToTop()));
  2774. order.addAction(QTStr("Basic.MainMenu.Edit.Order.MoveToBottom"),
  2775. this, SLOT(MoveSceneToBottom()));
  2776. popup.addMenu(&order);
  2777. popup.addSeparator();
  2778. sceneProjectorMenu = new QMenu(QTStr("SceneProjector"));
  2779. AddProjectorMenuMonitors(sceneProjectorMenu, this,
  2780. SLOT(OpenSceneProjector()));
  2781. popup.addMenu(sceneProjectorMenu);
  2782. QAction *sceneWindow = popup.addAction(
  2783. QTStr("SceneWindow"),
  2784. this, SLOT(OpenSceneWindow()));
  2785. popup.addAction(sceneWindow);
  2786. popup.addSeparator();
  2787. popup.addAction(QTStr("Filters"), this,
  2788. SLOT(OpenSceneFilters()));
  2789. }
  2790. popup.exec(QCursor::pos());
  2791. }
  2792. void OBSBasic::on_actionAddScene_triggered()
  2793. {
  2794. string name;
  2795. QString format{QTStr("Basic.Main.DefaultSceneName.Text")};
  2796. int i = 2;
  2797. QString placeHolderText = format.arg(i);
  2798. obs_source_t *source = nullptr;
  2799. while ((source = obs_get_source_by_name(QT_TO_UTF8(placeHolderText)))) {
  2800. obs_source_release(source);
  2801. placeHolderText = format.arg(++i);
  2802. }
  2803. bool accepted = NameDialog::AskForName(this,
  2804. QTStr("Basic.Main.AddSceneDlg.Title"),
  2805. QTStr("Basic.Main.AddSceneDlg.Text"),
  2806. name,
  2807. placeHolderText);
  2808. if (accepted) {
  2809. if (name.empty()) {
  2810. OBSMessageBox::information(this,
  2811. QTStr("NoNameEntered.Title"),
  2812. QTStr("NoNameEntered.Text"));
  2813. on_actionAddScene_triggered();
  2814. return;
  2815. }
  2816. obs_source_t *source = obs_get_source_by_name(name.c_str());
  2817. if (source) {
  2818. OBSMessageBox::information(this,
  2819. QTStr("NameExists.Title"),
  2820. QTStr("NameExists.Text"));
  2821. obs_source_release(source);
  2822. on_actionAddScene_triggered();
  2823. return;
  2824. }
  2825. obs_scene_t *scene = obs_scene_create(name.c_str());
  2826. source = obs_scene_get_source(scene);
  2827. AddScene(source);
  2828. SetCurrentScene(source);
  2829. obs_scene_release(scene);
  2830. }
  2831. }
  2832. void OBSBasic::on_actionRemoveScene_triggered()
  2833. {
  2834. OBSScene scene = GetCurrentScene();
  2835. obs_source_t *source = obs_scene_get_source(scene);
  2836. if (source && QueryRemoveSource(source))
  2837. obs_source_remove(source);
  2838. }
  2839. void OBSBasic::ChangeSceneIndex(bool relative, int offset, int invalidIdx)
  2840. {
  2841. int idx = ui->scenes->currentRow();
  2842. if (idx == -1 || idx == invalidIdx)
  2843. return;
  2844. sceneChanging = true;
  2845. QListWidgetItem *item = ui->scenes->takeItem(idx);
  2846. if (!relative)
  2847. idx = 0;
  2848. ui->scenes->insertItem(idx + offset, item);
  2849. ui->scenes->setCurrentRow(idx + offset);
  2850. item->setSelected(true);
  2851. sceneChanging = false;
  2852. }
  2853. void OBSBasic::on_actionSceneUp_triggered()
  2854. {
  2855. ChangeSceneIndex(true, -1, 0);
  2856. }
  2857. void OBSBasic::on_actionSceneDown_triggered()
  2858. {
  2859. ChangeSceneIndex(true, 1, ui->scenes->count() - 1);
  2860. }
  2861. void OBSBasic::MoveSceneToTop()
  2862. {
  2863. ChangeSceneIndex(false, 0, 0);
  2864. }
  2865. void OBSBasic::MoveSceneToBottom()
  2866. {
  2867. ChangeSceneIndex(false, ui->scenes->count() - 1,
  2868. ui->scenes->count() - 1);
  2869. }
  2870. void OBSBasic::on_sources_itemSelectionChanged()
  2871. {
  2872. SignalBlocker sourcesSignalBlocker(ui->sources);
  2873. auto updateItemSelection = [&]()
  2874. {
  2875. ignoreSelectionUpdate = true;
  2876. for (int i = 0; i < ui->sources->count(); i++)
  2877. {
  2878. QListWidgetItem *wItem = ui->sources->item(i);
  2879. OBSSceneItem item = GetOBSRef<OBSSceneItem>(wItem);
  2880. obs_sceneitem_select(item, wItem->isSelected());
  2881. }
  2882. ignoreSelectionUpdate = false;
  2883. };
  2884. using updateItemSelection_t = decltype(updateItemSelection);
  2885. obs_scene_atomic_update(GetCurrentScene(),
  2886. [](void *data, obs_scene_t *)
  2887. {
  2888. (*static_cast<updateItemSelection_t*>(data))();
  2889. }, static_cast<void*>(&updateItemSelection));
  2890. }
  2891. void OBSBasic::EditSceneItemName()
  2892. {
  2893. QListWidgetItem *item = GetTopSelectedSourceItem();
  2894. Qt::ItemFlags flags = item->flags();
  2895. OBSSceneItem sceneItem= GetOBSRef<OBSSceneItem>(item);
  2896. obs_source_t *source = obs_sceneitem_get_source(sceneItem);
  2897. const char *name = obs_source_get_name(source);
  2898. item->setText(QT_UTF8(name));
  2899. item->setFlags(flags | Qt::ItemIsEditable);
  2900. ui->sources->removeItemWidget(item);
  2901. ui->sources->editItem(item);
  2902. item->setFlags(flags);
  2903. }
  2904. void OBSBasic::SetDeinterlacingMode()
  2905. {
  2906. QAction *action = reinterpret_cast<QAction*>(sender());
  2907. obs_deinterlace_mode mode =
  2908. (obs_deinterlace_mode)action->property("mode").toInt();
  2909. OBSSceneItem sceneItem = GetCurrentSceneItem();
  2910. obs_source_t *source = obs_sceneitem_get_source(sceneItem);
  2911. obs_source_set_deinterlace_mode(source, mode);
  2912. }
  2913. void OBSBasic::SetDeinterlacingOrder()
  2914. {
  2915. QAction *action = reinterpret_cast<QAction*>(sender());
  2916. obs_deinterlace_field_order order =
  2917. (obs_deinterlace_field_order)action->property("order").toInt();
  2918. OBSSceneItem sceneItem = GetCurrentSceneItem();
  2919. obs_source_t *source = obs_sceneitem_get_source(sceneItem);
  2920. obs_source_set_deinterlace_field_order(source, order);
  2921. }
  2922. QMenu *OBSBasic::AddDeinterlacingMenu(obs_source_t *source)
  2923. {
  2924. QMenu *menu = new QMenu(QTStr("Deinterlacing"));
  2925. obs_deinterlace_mode deinterlaceMode =
  2926. obs_source_get_deinterlace_mode(source);
  2927. obs_deinterlace_field_order deinterlaceOrder =
  2928. obs_source_get_deinterlace_field_order(source);
  2929. QAction *action;
  2930. #define ADD_MODE(name, mode) \
  2931. action = menu->addAction(QTStr("" name), this, \
  2932. SLOT(SetDeinterlacingMode())); \
  2933. action->setProperty("mode", (int)mode); \
  2934. action->setCheckable(true); \
  2935. action->setChecked(deinterlaceMode == mode);
  2936. ADD_MODE("Disable", OBS_DEINTERLACE_MODE_DISABLE);
  2937. ADD_MODE("Deinterlacing.Discard", OBS_DEINTERLACE_MODE_DISCARD);
  2938. ADD_MODE("Deinterlacing.Retro", OBS_DEINTERLACE_MODE_RETRO);
  2939. ADD_MODE("Deinterlacing.Blend", OBS_DEINTERLACE_MODE_BLEND);
  2940. ADD_MODE("Deinterlacing.Blend2x", OBS_DEINTERLACE_MODE_BLEND_2X);
  2941. ADD_MODE("Deinterlacing.Linear", OBS_DEINTERLACE_MODE_LINEAR);
  2942. ADD_MODE("Deinterlacing.Linear2x", OBS_DEINTERLACE_MODE_LINEAR_2X);
  2943. ADD_MODE("Deinterlacing.Yadif", OBS_DEINTERLACE_MODE_YADIF);
  2944. ADD_MODE("Deinterlacing.Yadif2x", OBS_DEINTERLACE_MODE_YADIF_2X);
  2945. #undef ADD_MODE
  2946. menu->addSeparator();
  2947. #define ADD_ORDER(name, order) \
  2948. action = menu->addAction(QTStr("Deinterlacing." name), this, \
  2949. SLOT(SetDeinterlacingOrder())); \
  2950. action->setProperty("order", (int)order); \
  2951. action->setCheckable(true); \
  2952. action->setChecked(deinterlaceOrder == order);
  2953. ADD_ORDER("TopFieldFirst", OBS_DEINTERLACE_FIELD_ORDER_TOP);
  2954. ADD_ORDER("BottomFieldFirst", OBS_DEINTERLACE_FIELD_ORDER_BOTTOM);
  2955. #undef ADD_ORDER
  2956. return menu;
  2957. }
  2958. void OBSBasic::SetScaleFilter()
  2959. {
  2960. QAction *action = reinterpret_cast<QAction*>(sender());
  2961. obs_scale_type mode = (obs_scale_type)action->property("mode").toInt();
  2962. OBSSceneItem sceneItem = GetCurrentSceneItem();
  2963. obs_sceneitem_set_scale_filter(sceneItem, mode);
  2964. }
  2965. QMenu *OBSBasic::AddScaleFilteringMenu(obs_sceneitem_t *item)
  2966. {
  2967. QMenu *menu = new QMenu(QTStr("ScaleFiltering"));
  2968. obs_scale_type scaleFilter = obs_sceneitem_get_scale_filter(item);
  2969. QAction *action;
  2970. #define ADD_MODE(name, mode) \
  2971. action = menu->addAction(QTStr("" name), this, \
  2972. SLOT(SetScaleFilter())); \
  2973. action->setProperty("mode", (int)mode); \
  2974. action->setCheckable(true); \
  2975. action->setChecked(scaleFilter == mode);
  2976. ADD_MODE("Disable", OBS_SCALE_DISABLE);
  2977. ADD_MODE("ScaleFiltering.Point", OBS_SCALE_POINT);
  2978. ADD_MODE("ScaleFiltering.Bilinear", OBS_SCALE_BILINEAR);
  2979. ADD_MODE("ScaleFiltering.Bicubic", OBS_SCALE_BICUBIC);
  2980. ADD_MODE("ScaleFiltering.Lanczos", OBS_SCALE_LANCZOS);
  2981. #undef ADD_MODE
  2982. return menu;
  2983. }
  2984. void OBSBasic::CreateSourcePopupMenu(QListWidgetItem *item, bool preview)
  2985. {
  2986. QMenu popup(this);
  2987. QPointer<QMenu> previewProjector;
  2988. QPointer<QMenu> sourceProjector;
  2989. if (preview) {
  2990. QAction *action = popup.addAction(
  2991. QTStr("Basic.Main.PreviewConextMenu.Enable"),
  2992. this, SLOT(TogglePreview()));
  2993. action->setCheckable(true);
  2994. action->setChecked(
  2995. obs_display_enabled(ui->preview->GetDisplay()));
  2996. if (IsPreviewProgramMode())
  2997. action->setEnabled(false);
  2998. popup.addAction(ui->actionLockPreview);
  2999. popup.addMenu(ui->scalingMenu);
  3000. const char *slot = IsPreviewProgramMode()
  3001. ? SLOT(OpenStudioProgramProjector())
  3002. : SLOT(OpenPreviewProjector());
  3003. previewProjector = new QMenu(QTStr("PreviewProjector"));
  3004. AddProjectorMenuMonitors(previewProjector, this,
  3005. slot);
  3006. popup.addMenu(previewProjector);
  3007. slot = IsPreviewProgramMode()
  3008. ? SLOT(OpenStudioProgramWindow())
  3009. : SLOT(OpenPreviewWindow());
  3010. QAction *previewWindow = popup.addAction(
  3011. QTStr("PreviewWindow"),
  3012. this, slot);
  3013. popup.addAction(previewWindow);
  3014. popup.addSeparator();
  3015. }
  3016. QPointer<QMenu> addSourceMenu = CreateAddSourcePopupMenu();
  3017. if (addSourceMenu)
  3018. popup.addMenu(addSourceMenu);
  3019. ui->actionCopyFilters->setEnabled(false);
  3020. popup.addSeparator();
  3021. popup.addAction(ui->actionCopySource);
  3022. popup.addAction(ui->actionPasteRef);
  3023. popup.addAction(ui->actionPasteDup);
  3024. popup.addSeparator();
  3025. popup.addSeparator();
  3026. popup.addAction(ui->actionCopyFilters);
  3027. popup.addAction(ui->actionPasteFilters);
  3028. popup.addSeparator();
  3029. if (item) {
  3030. if (addSourceMenu)
  3031. popup.addSeparator();
  3032. OBSSceneItem sceneItem = GetSceneItem(item);
  3033. obs_source_t *source = obs_sceneitem_get_source(sceneItem);
  3034. uint32_t flags = obs_source_get_output_flags(source);
  3035. bool isAsyncVideo = (flags & OBS_SOURCE_ASYNC_VIDEO) ==
  3036. OBS_SOURCE_ASYNC_VIDEO;
  3037. bool hasAudio = (flags & OBS_SOURCE_AUDIO) ==
  3038. OBS_SOURCE_AUDIO;
  3039. QAction *action;
  3040. popup.addAction(QTStr("Rename"), this,
  3041. SLOT(EditSceneItemName()));
  3042. popup.addAction(QTStr("Remove"), this,
  3043. SLOT(on_actionRemoveSource_triggered()),
  3044. DeleteKeys.front());
  3045. popup.addSeparator();
  3046. popup.addMenu(ui->orderMenu);
  3047. popup.addMenu(ui->transformMenu);
  3048. sourceProjector = new QMenu(QTStr("SourceProjector"));
  3049. AddProjectorMenuMonitors(sourceProjector, this,
  3050. SLOT(OpenSourceProjector()));
  3051. QAction *sourceWindow = popup.addAction(
  3052. QTStr("SourceWindow"),
  3053. this, SLOT(OpenSourceWindow()));
  3054. popup.addAction(sourceWindow);
  3055. popup.addSeparator();
  3056. if (hasAudio) {
  3057. QAction *actionHideMixer = popup.addAction(
  3058. QTStr("HideMixer"),
  3059. this, SLOT(ToggleHideMixer()));
  3060. actionHideMixer->setCheckable(true);
  3061. actionHideMixer->setChecked(SourceMixerHidden(source));
  3062. }
  3063. if (isAsyncVideo) {
  3064. popup.addMenu(AddDeinterlacingMenu(source));
  3065. popup.addSeparator();
  3066. }
  3067. popup.addMenu(AddScaleFilteringMenu(sceneItem));
  3068. popup.addSeparator();
  3069. popup.addMenu(sourceProjector);
  3070. popup.addAction(sourceWindow);
  3071. popup.addSeparator();
  3072. action = popup.addAction(QTStr("Interact"), this,
  3073. SLOT(on_actionInteract_triggered()));
  3074. action->setEnabled(obs_source_get_output_flags(source) &
  3075. OBS_SOURCE_INTERACTION);
  3076. popup.addAction(QTStr("Filters"), this,
  3077. SLOT(OpenFilters()));
  3078. popup.addAction(QTStr("Properties"), this,
  3079. SLOT(on_actionSourceProperties_triggered()));
  3080. ui->actionCopyFilters->setEnabled(true);
  3081. }
  3082. popup.exec(QCursor::pos());
  3083. }
  3084. void OBSBasic::on_sources_customContextMenuRequested(const QPoint &pos)
  3085. {
  3086. if (ui->scenes->count())
  3087. CreateSourcePopupMenu(ui->sources->itemAt(pos), false);
  3088. }
  3089. void OBSBasic::on_sources_itemDoubleClicked(QListWidgetItem *witem)
  3090. {
  3091. if (!witem)
  3092. return;
  3093. OBSSceneItem item = GetSceneItem(witem);
  3094. OBSSource source = obs_sceneitem_get_source(item);
  3095. if (source)
  3096. CreatePropertiesWindow(source);
  3097. }
  3098. void OBSBasic::on_scenes_itemDoubleClicked(QListWidgetItem *witem)
  3099. {
  3100. if (!witem)
  3101. return;
  3102. if (IsPreviewProgramMode()) {
  3103. bool doubleClickSwitch = config_get_bool(App()->GlobalConfig(),
  3104. "BasicWindow", "TransitionOnDoubleClick");
  3105. if (doubleClickSwitch) {
  3106. OBSScene scene = GetCurrentScene();
  3107. if (scene)
  3108. SetCurrentScene(scene, false, true);
  3109. }
  3110. }
  3111. }
  3112. void OBSBasic::AddSource(const char *id)
  3113. {
  3114. if (id && *id) {
  3115. OBSBasicSourceSelect sourceSelect(this, id);
  3116. sourceSelect.exec();
  3117. if (sourceSelect.newSource)
  3118. CreatePropertiesWindow(sourceSelect.newSource);
  3119. }
  3120. }
  3121. QMenu *OBSBasic::CreateAddSourcePopupMenu()
  3122. {
  3123. const char *type;
  3124. bool foundValues = false;
  3125. bool foundDeprecated = false;
  3126. size_t idx = 0;
  3127. QMenu *popup = new QMenu(QTStr("Add"), this);
  3128. QMenu *deprecated = new QMenu(QTStr("Deprecated"), popup);
  3129. auto getActionAfter = [] (QMenu *menu, const QString &name)
  3130. {
  3131. QList<QAction*> actions = menu->actions();
  3132. for (QAction *menuAction : actions) {
  3133. if (menuAction->text().compare(name) >= 0)
  3134. return menuAction;
  3135. }
  3136. return (QAction*)nullptr;
  3137. };
  3138. auto addSource = [this, getActionAfter] (QMenu *popup,
  3139. const char *type, const char *name)
  3140. {
  3141. QString qname = QT_UTF8(name);
  3142. QAction *popupItem = new QAction(qname, this);
  3143. popupItem->setData(QT_UTF8(type));
  3144. connect(popupItem, SIGNAL(triggered(bool)),
  3145. this, SLOT(AddSourceFromAction()));
  3146. QAction *after = getActionAfter(popup, qname);
  3147. popup->insertAction(after, popupItem);
  3148. };
  3149. while (obs_enum_input_types(idx++, &type)) {
  3150. const char *name = obs_source_get_display_name(type);
  3151. uint32_t caps = obs_get_source_output_flags(type);
  3152. if ((caps & OBS_SOURCE_DEPRECATED) == 0) {
  3153. addSource(popup, type, name);
  3154. } else {
  3155. addSource(deprecated, type, name);
  3156. foundDeprecated = true;
  3157. }
  3158. foundValues = true;
  3159. }
  3160. addSource(popup, "scene", Str("Basic.Scene"));
  3161. if (!foundDeprecated) {
  3162. delete deprecated;
  3163. deprecated = nullptr;
  3164. }
  3165. if (!foundValues) {
  3166. delete popup;
  3167. popup = nullptr;
  3168. } else if (foundDeprecated) {
  3169. popup->addMenu(deprecated);
  3170. }
  3171. return popup;
  3172. }
  3173. void OBSBasic::AddSourceFromAction()
  3174. {
  3175. QAction *action = qobject_cast<QAction*>(sender());
  3176. if (!action)
  3177. return;
  3178. AddSource(QT_TO_UTF8(action->data().toString()));
  3179. }
  3180. void OBSBasic::AddSourcePopupMenu(const QPoint &pos)
  3181. {
  3182. if (!GetCurrentScene()) {
  3183. // Tell the user he needs a scene first (help beginners).
  3184. OBSMessageBox::information(this,
  3185. QTStr("Basic.Main.AddSourceHelp.Title"),
  3186. QTStr("Basic.Main.AddSourceHelp.Text"));
  3187. return;
  3188. }
  3189. QPointer<QMenu> popup = CreateAddSourcePopupMenu();
  3190. if (popup)
  3191. popup->exec(pos);
  3192. }
  3193. void OBSBasic::on_actionAddSource_triggered()
  3194. {
  3195. AddSourcePopupMenu(QCursor::pos());
  3196. }
  3197. void OBSBasic::on_actionRemoveSource_triggered()
  3198. {
  3199. vector<OBSSceneItem> items;
  3200. auto func = [] (obs_scene_t *, obs_sceneitem_t *item, void *param)
  3201. {
  3202. vector<OBSSceneItem> &items =
  3203. *reinterpret_cast<vector<OBSSceneItem>*>(param);
  3204. if (obs_sceneitem_selected(item))
  3205. items.emplace_back(item);
  3206. return true;
  3207. };
  3208. obs_scene_enum_items(GetCurrentScene(), func, &items);
  3209. if (!items.size())
  3210. return;
  3211. auto removeMultiple = [this] (size_t count)
  3212. {
  3213. QString text = QTStr("ConfirmRemove.TextMultiple")
  3214. .arg(QString::number(count));
  3215. QMessageBox remove_items(this);
  3216. remove_items.setText(text);
  3217. QAbstractButton *Yes = remove_items.addButton(QTStr("Yes"),
  3218. QMessageBox::YesRole);
  3219. remove_items.addButton(QTStr("No"), QMessageBox::NoRole);
  3220. remove_items.setIcon(QMessageBox::Question);
  3221. remove_items.setWindowTitle(QTStr("ConfirmRemove.Title"));
  3222. remove_items.exec();
  3223. return Yes == remove_items.clickedButton();
  3224. };
  3225. if (items.size() == 1) {
  3226. OBSSceneItem &item = items[0];
  3227. obs_source_t *source = obs_sceneitem_get_source(item);
  3228. if (source && QueryRemoveSource(source))
  3229. obs_sceneitem_remove(item);
  3230. } else {
  3231. if (removeMultiple(items.size())) {
  3232. for (auto &item : items)
  3233. obs_sceneitem_remove(item);
  3234. }
  3235. }
  3236. }
  3237. void OBSBasic::on_actionInteract_triggered()
  3238. {
  3239. OBSSceneItem item = GetCurrentSceneItem();
  3240. OBSSource source = obs_sceneitem_get_source(item);
  3241. if (source)
  3242. CreateInteractionWindow(source);
  3243. }
  3244. void OBSBasic::on_actionSourceProperties_triggered()
  3245. {
  3246. OBSSceneItem item = GetCurrentSceneItem();
  3247. OBSSource source = obs_sceneitem_get_source(item);
  3248. if (source)
  3249. CreatePropertiesWindow(source);
  3250. }
  3251. void OBSBasic::on_actionSourceUp_triggered()
  3252. {
  3253. OBSSceneItem item = GetCurrentSceneItem();
  3254. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_UP);
  3255. }
  3256. void OBSBasic::on_actionSourceDown_triggered()
  3257. {
  3258. OBSSceneItem item = GetCurrentSceneItem();
  3259. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_DOWN);
  3260. }
  3261. void OBSBasic::on_actionMoveUp_triggered()
  3262. {
  3263. OBSSceneItem item = GetCurrentSceneItem();
  3264. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_UP);
  3265. }
  3266. void OBSBasic::on_actionMoveDown_triggered()
  3267. {
  3268. OBSSceneItem item = GetCurrentSceneItem();
  3269. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_DOWN);
  3270. }
  3271. void OBSBasic::on_actionMoveToTop_triggered()
  3272. {
  3273. OBSSceneItem item = GetCurrentSceneItem();
  3274. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_TOP);
  3275. }
  3276. void OBSBasic::on_actionMoveToBottom_triggered()
  3277. {
  3278. OBSSceneItem item = GetCurrentSceneItem();
  3279. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_BOTTOM);
  3280. }
  3281. static BPtr<char> ReadLogFile(const char *log)
  3282. {
  3283. char logDir[512];
  3284. if (GetConfigPath(logDir, sizeof(logDir), "obs-studio/logs") <= 0)
  3285. return nullptr;
  3286. string path = (char*)logDir;
  3287. path += "/";
  3288. path += log;
  3289. BPtr<char> file = os_quick_read_utf8_file(path.c_str());
  3290. if (!file)
  3291. blog(LOG_WARNING, "Failed to read log file %s", path.c_str());
  3292. return file;
  3293. }
  3294. void OBSBasic::UploadLog(const char *file)
  3295. {
  3296. BPtr<char> fileString{ReadLogFile(file)};
  3297. if (!fileString)
  3298. return;
  3299. if (!*fileString)
  3300. return;
  3301. ui->menuLogFiles->setEnabled(false);
  3302. auto data_deleter = [](obs_data_t *d) { obs_data_release(d); };
  3303. using data_t = unique_ptr<struct obs_data, decltype(data_deleter)>;
  3304. data_t content{obs_data_create(), data_deleter};
  3305. data_t files{obs_data_create(), data_deleter};
  3306. data_t request{obs_data_create(), data_deleter};
  3307. obs_data_set_string(content.get(), "content", fileString);
  3308. obs_data_set_obj(files.get(), file, content.get());
  3309. stringstream ss;
  3310. ss << "OBS " << App()->GetVersionString()
  3311. << " log file uploaded at " << CurrentDateTimeString();
  3312. obs_data_set_string(request.get(), "description", ss.str().c_str());
  3313. obs_data_set_bool(request.get(), "public", false);
  3314. obs_data_set_obj(request.get(), "files", files.get());
  3315. const char *json = obs_data_get_json(request.get());
  3316. if (!json) {
  3317. blog(LOG_ERROR, "Failed to get JSON data for log upload");
  3318. return;
  3319. }
  3320. QBuffer *postData = new QBuffer();
  3321. postData->setData(json, (int) strlen(json));
  3322. if (logUploadThread) {
  3323. logUploadThread->wait();
  3324. delete logUploadThread;
  3325. }
  3326. RemoteTextThread *thread = new RemoteTextThread(
  3327. "https://api.github.com/gists",
  3328. "application/json", json);
  3329. logUploadThread = thread;
  3330. connect(thread, &RemoteTextThread::Result,
  3331. this, &OBSBasic::logUploadFinished);
  3332. logUploadThread->start();
  3333. }
  3334. void OBSBasic::on_actionShowLogs_triggered()
  3335. {
  3336. char logDir[512];
  3337. if (GetConfigPath(logDir, sizeof(logDir), "obs-studio/logs") <= 0)
  3338. return;
  3339. QUrl url = QUrl::fromLocalFile(QT_UTF8(logDir));
  3340. QDesktopServices::openUrl(url);
  3341. }
  3342. void OBSBasic::on_actionUploadCurrentLog_triggered()
  3343. {
  3344. UploadLog(App()->GetCurrentLog());
  3345. }
  3346. void OBSBasic::on_actionUploadLastLog_triggered()
  3347. {
  3348. UploadLog(App()->GetLastLog());
  3349. }
  3350. void OBSBasic::on_actionViewCurrentLog_triggered()
  3351. {
  3352. char logDir[512];
  3353. if (GetConfigPath(logDir, sizeof(logDir), "obs-studio/logs") <= 0)
  3354. return;
  3355. const char* log = App()->GetCurrentLog();
  3356. string path = (char*)logDir;
  3357. path += "/";
  3358. path += log;
  3359. QUrl url = QUrl::fromLocalFile(QT_UTF8(path.c_str()));
  3360. QDesktopServices::openUrl(url);
  3361. }
  3362. void OBSBasic::on_actionCheckForUpdates_triggered()
  3363. {
  3364. CheckForUpdates(true);
  3365. }
  3366. void OBSBasic::logUploadFinished(const QString &text, const QString &error)
  3367. {
  3368. ui->menuLogFiles->setEnabled(true);
  3369. if (text.isEmpty()) {
  3370. OBSMessageBox::information(this,
  3371. QTStr("LogReturnDialog.ErrorUploadingLog"),
  3372. error);
  3373. return;
  3374. }
  3375. obs_data_t *returnData = obs_data_create_from_json(QT_TO_UTF8(text));
  3376. QString logURL = obs_data_get_string(returnData, "html_url");
  3377. obs_data_release(returnData);
  3378. OBSLogReply logDialog(this, logURL);
  3379. logDialog.exec();
  3380. }
  3381. static void RenameListItem(OBSBasic *parent, QListWidget *listWidget,
  3382. obs_source_t *source, const string &name)
  3383. {
  3384. const char *prevName = obs_source_get_name(source);
  3385. if (name == prevName)
  3386. return;
  3387. obs_source_t *foundSource = obs_get_source_by_name(name.c_str());
  3388. QListWidgetItem *listItem = listWidget->currentItem();
  3389. if (foundSource || name.empty()) {
  3390. listItem->setText(QT_UTF8(prevName));
  3391. if (foundSource) {
  3392. OBSMessageBox::information(parent,
  3393. QTStr("NameExists.Title"),
  3394. QTStr("NameExists.Text"));
  3395. } else if (name.empty()) {
  3396. OBSMessageBox::information(parent,
  3397. QTStr("NoNameEntered.Title"),
  3398. QTStr("NoNameEntered.Text"));
  3399. }
  3400. obs_source_release(foundSource);
  3401. } else {
  3402. listItem->setText(QT_UTF8(name.c_str()));
  3403. obs_source_set_name(source, name.c_str());
  3404. }
  3405. }
  3406. void OBSBasic::SceneNameEdited(QWidget *editor,
  3407. QAbstractItemDelegate::EndEditHint endHint)
  3408. {
  3409. OBSScene scene = GetCurrentScene();
  3410. QLineEdit *edit = qobject_cast<QLineEdit*>(editor);
  3411. string text = QT_TO_UTF8(edit->text().trimmed());
  3412. if (!scene)
  3413. return;
  3414. obs_source_t *source = obs_scene_get_source(scene);
  3415. RenameListItem(this, ui->scenes, source, text);
  3416. if (api)
  3417. api->on_event(OBS_FRONTEND_EVENT_SCENE_LIST_CHANGED);
  3418. UNUSED_PARAMETER(endHint);
  3419. }
  3420. void OBSBasic::SceneItemNameEdited(QWidget *editor,
  3421. QAbstractItemDelegate::EndEditHint endHint)
  3422. {
  3423. OBSSceneItem item = GetCurrentSceneItem();
  3424. QLineEdit *edit = qobject_cast<QLineEdit*>(editor);
  3425. string text = QT_TO_UTF8(edit->text().trimmed());
  3426. if (!item)
  3427. return;
  3428. obs_source_t *source = obs_sceneitem_get_source(item);
  3429. RenameListItem(this, ui->sources, source, text);
  3430. QListWidgetItem *listItem = ui->sources->currentItem();
  3431. listItem->setText(QString());
  3432. SetupVisibilityItem(ui->sources, listItem, item);
  3433. UNUSED_PARAMETER(endHint);
  3434. }
  3435. void OBSBasic::OpenFilters()
  3436. {
  3437. OBSSceneItem item = GetCurrentSceneItem();
  3438. OBSSource source = obs_sceneitem_get_source(item);
  3439. CreateFiltersWindow(source);
  3440. }
  3441. void OBSBasic::OpenSceneFilters()
  3442. {
  3443. OBSScene scene = GetCurrentScene();
  3444. OBSSource source = obs_scene_get_source(scene);
  3445. CreateFiltersWindow(source);
  3446. }
  3447. #define RECORDING_START \
  3448. "==== Recording Start ==============================================="
  3449. #define RECORDING_STOP \
  3450. "==== Recording Stop ================================================"
  3451. #define REPLAY_BUFFER_START \
  3452. "==== Replay Buffer Start ==========================================="
  3453. #define REPLAY_BUFFER_STOP \
  3454. "==== Replay Buffer Stop ============================================"
  3455. #define STREAMING_START \
  3456. "==== Streaming Start ==============================================="
  3457. #define STREAMING_STOP \
  3458. "==== Streaming Stop ================================================"
  3459. void OBSBasic::StartStreaming()
  3460. {
  3461. if (outputHandler->StreamingActive())
  3462. return;
  3463. if (disableOutputsRef)
  3464. return;
  3465. if (api)
  3466. api->on_event(OBS_FRONTEND_EVENT_STREAMING_STARTING);
  3467. SaveProject();
  3468. ui->streamButton->setEnabled(false);
  3469. ui->streamButton->setText(QTStr("Basic.Main.Connecting"));
  3470. if (sysTrayStream) {
  3471. sysTrayStream->setEnabled(false);
  3472. sysTrayStream->setText(ui->streamButton->text());
  3473. }
  3474. if (!outputHandler->StartStreaming(service)) {
  3475. ui->streamButton->setText(QTStr("Basic.Main.StartStreaming"));
  3476. ui->streamButton->setEnabled(true);
  3477. ui->streamButton->setChecked(false);
  3478. if (sysTrayStream) {
  3479. sysTrayStream->setText(ui->streamButton->text());
  3480. sysTrayStream->setEnabled(true);
  3481. }
  3482. QMessageBox::critical(this,
  3483. QTStr("Output.StartStreamFailed"),
  3484. QTStr("Output.StartFailedGeneric"));
  3485. return;
  3486. }
  3487. bool recordWhenStreaming = config_get_bool(GetGlobalConfig(),
  3488. "BasicWindow", "RecordWhenStreaming");
  3489. if (recordWhenStreaming)
  3490. StartRecording();
  3491. bool replayBufferWhileStreaming = config_get_bool(GetGlobalConfig(),
  3492. "BasicWindow", "ReplayBufferWhileStreaming");
  3493. if (replayBufferWhileStreaming)
  3494. StartReplayBuffer();
  3495. }
  3496. #ifdef _WIN32
  3497. static inline void UpdateProcessPriority()
  3498. {
  3499. const char *priority = config_get_string(App()->GlobalConfig(),
  3500. "General", "ProcessPriority");
  3501. if (priority && strcmp(priority, "Normal") != 0)
  3502. SetProcessPriority(priority);
  3503. }
  3504. static inline void ClearProcessPriority()
  3505. {
  3506. const char *priority = config_get_string(App()->GlobalConfig(),
  3507. "General", "ProcessPriority");
  3508. if (priority && strcmp(priority, "Normal") != 0)
  3509. SetProcessPriority("Normal");
  3510. }
  3511. #else
  3512. #define UpdateProcessPriority() do {} while(false)
  3513. #define ClearProcessPriority() do {} while(false)
  3514. #endif
  3515. inline void OBSBasic::OnActivate()
  3516. {
  3517. if (ui->profileMenu->isEnabled()) {
  3518. ui->profileMenu->setEnabled(false);
  3519. ui->autoConfigure->setEnabled(false);
  3520. App()->IncrementSleepInhibition();
  3521. UpdateProcessPriority();
  3522. if (trayIcon)
  3523. trayIcon->setIcon(QIcon(":/res/images/tray_active.png"));
  3524. }
  3525. }
  3526. inline void OBSBasic::OnDeactivate()
  3527. {
  3528. if (!outputHandler->Active() && !ui->profileMenu->isEnabled()) {
  3529. ui->profileMenu->setEnabled(true);
  3530. ui->autoConfigure->setEnabled(true);
  3531. App()->DecrementSleepInhibition();
  3532. ClearProcessPriority();
  3533. if (trayIcon)
  3534. trayIcon->setIcon(QIcon(":/res/images/obs.png"));
  3535. }
  3536. }
  3537. void OBSBasic::StopStreaming()
  3538. {
  3539. SaveProject();
  3540. if (outputHandler->StreamingActive())
  3541. outputHandler->StopStreaming(streamingStopping);
  3542. OnDeactivate();
  3543. bool recordWhenStreaming = config_get_bool(GetGlobalConfig(),
  3544. "BasicWindow", "RecordWhenStreaming");
  3545. bool keepRecordingWhenStreamStops = config_get_bool(GetGlobalConfig(),
  3546. "BasicWindow", "KeepRecordingWhenStreamStops");
  3547. if (recordWhenStreaming && !keepRecordingWhenStreamStops)
  3548. StopRecording();
  3549. bool replayBufferWhileStreaming = config_get_bool(GetGlobalConfig(),
  3550. "BasicWindow", "ReplayBufferWhileStreaming");
  3551. bool keepReplayBufferStreamStops = config_get_bool(GetGlobalConfig(),
  3552. "BasicWindow", "KeepReplayBufferStreamStops");
  3553. if (replayBufferWhileStreaming && !keepReplayBufferStreamStops)
  3554. StopReplayBuffer();
  3555. }
  3556. void OBSBasic::ForceStopStreaming()
  3557. {
  3558. SaveProject();
  3559. if (outputHandler->StreamingActive())
  3560. outputHandler->StopStreaming(true);
  3561. OnDeactivate();
  3562. bool recordWhenStreaming = config_get_bool(GetGlobalConfig(),
  3563. "BasicWindow", "RecordWhenStreaming");
  3564. bool keepRecordingWhenStreamStops = config_get_bool(GetGlobalConfig(),
  3565. "BasicWindow", "KeepRecordingWhenStreamStops");
  3566. if (recordWhenStreaming && !keepRecordingWhenStreamStops)
  3567. StopRecording();
  3568. bool replayBufferWhileStreaming = config_get_bool(GetGlobalConfig(),
  3569. "BasicWindow", "ReplayBufferWhileStreaming");
  3570. bool keepReplayBufferStreamStops = config_get_bool(GetGlobalConfig(),
  3571. "BasicWindow", "KeepReplayBufferStreamStops");
  3572. if (replayBufferWhileStreaming && !keepReplayBufferStreamStops)
  3573. StopReplayBuffer();
  3574. }
  3575. void OBSBasic::StreamDelayStarting(int sec)
  3576. {
  3577. ui->streamButton->setText(QTStr("Basic.Main.StopStreaming"));
  3578. ui->streamButton->setEnabled(true);
  3579. ui->streamButton->setChecked(true);
  3580. if (sysTrayStream) {
  3581. sysTrayStream->setText(ui->streamButton->text());
  3582. sysTrayStream->setEnabled(true);
  3583. }
  3584. if (!startStreamMenu.isNull())
  3585. startStreamMenu->deleteLater();
  3586. startStreamMenu = new QMenu();
  3587. startStreamMenu->addAction(QTStr("Basic.Main.StopStreaming"),
  3588. this, SLOT(StopStreaming()));
  3589. startStreamMenu->addAction(QTStr("Basic.Main.ForceStopStreaming"),
  3590. this, SLOT(ForceStopStreaming()));
  3591. ui->streamButton->setMenu(startStreamMenu);
  3592. ui->statusbar->StreamDelayStarting(sec);
  3593. OnActivate();
  3594. }
  3595. void OBSBasic::StreamDelayStopping(int sec)
  3596. {
  3597. ui->streamButton->setText(QTStr("Basic.Main.StartStreaming"));
  3598. ui->streamButton->setEnabled(true);
  3599. ui->streamButton->setChecked(false);
  3600. if (sysTrayStream) {
  3601. sysTrayStream->setText(ui->streamButton->text());
  3602. sysTrayStream->setEnabled(true);
  3603. }
  3604. if (!startStreamMenu.isNull())
  3605. startStreamMenu->deleteLater();
  3606. startStreamMenu = new QMenu();
  3607. startStreamMenu->addAction(QTStr("Basic.Main.StartStreaming"),
  3608. this, SLOT(StartStreaming()));
  3609. startStreamMenu->addAction(QTStr("Basic.Main.ForceStopStreaming"),
  3610. this, SLOT(ForceStopStreaming()));
  3611. ui->streamButton->setMenu(startStreamMenu);
  3612. ui->statusbar->StreamDelayStopping(sec);
  3613. }
  3614. void OBSBasic::StreamingStart()
  3615. {
  3616. ui->streamButton->setText(QTStr("Basic.Main.StopStreaming"));
  3617. ui->streamButton->setEnabled(true);
  3618. ui->streamButton->setChecked(true);
  3619. ui->statusbar->StreamStarted(outputHandler->streamOutput);
  3620. if (sysTrayStream) {
  3621. sysTrayStream->setText(ui->streamButton->text());
  3622. sysTrayStream->setEnabled(true);
  3623. }
  3624. if (api)
  3625. api->on_event(OBS_FRONTEND_EVENT_STREAMING_STARTED);
  3626. OnActivate();
  3627. blog(LOG_INFO, STREAMING_START);
  3628. }
  3629. void OBSBasic::StreamStopping()
  3630. {
  3631. ui->streamButton->setText(QTStr("Basic.Main.StoppingStreaming"));
  3632. if (sysTrayStream)
  3633. sysTrayStream->setText(ui->streamButton->text());
  3634. streamingStopping = true;
  3635. if (api)
  3636. api->on_event(OBS_FRONTEND_EVENT_STREAMING_STOPPING);
  3637. }
  3638. void OBSBasic::StreamingStop(int code, QString last_error)
  3639. {
  3640. const char *errorDescription;
  3641. DStr errorMessage;
  3642. bool use_last_error = false;
  3643. switch (code) {
  3644. case OBS_OUTPUT_BAD_PATH:
  3645. errorDescription = Str("Output.ConnectFail.BadPath");
  3646. break;
  3647. case OBS_OUTPUT_CONNECT_FAILED:
  3648. use_last_error = true;
  3649. errorDescription = Str("Output.ConnectFail.ConnectFailed");
  3650. break;
  3651. case OBS_OUTPUT_INVALID_STREAM:
  3652. errorDescription = Str("Output.ConnectFail.InvalidStream");
  3653. break;
  3654. default:
  3655. case OBS_OUTPUT_ERROR:
  3656. use_last_error = true;
  3657. errorDescription = Str("Output.ConnectFail.Error");
  3658. break;
  3659. case OBS_OUTPUT_DISCONNECTED:
  3660. /* doesn't happen if output is set to reconnect. note that
  3661. * reconnects are handled in the output, not in the UI */
  3662. use_last_error = true;
  3663. errorDescription = Str("Output.ConnectFail.Disconnected");
  3664. }
  3665. if (use_last_error && !last_error.isEmpty())
  3666. dstr_printf(errorMessage, "%s\n\n%s", errorDescription,
  3667. QT_TO_UTF8(last_error));
  3668. else
  3669. dstr_copy(errorMessage, errorDescription);
  3670. ui->statusbar->StreamStopped();
  3671. ui->streamButton->setText(QTStr("Basic.Main.StartStreaming"));
  3672. ui->streamButton->setEnabled(true);
  3673. ui->streamButton->setChecked(false);
  3674. if (sysTrayStream) {
  3675. sysTrayStream->setText(ui->streamButton->text());
  3676. sysTrayStream->setEnabled(true);
  3677. }
  3678. streamingStopping = false;
  3679. if (api)
  3680. api->on_event(OBS_FRONTEND_EVENT_STREAMING_STOPPED);
  3681. OnDeactivate();
  3682. blog(LOG_INFO, STREAMING_STOP);
  3683. if (code != OBS_OUTPUT_SUCCESS && isVisible()) {
  3684. OBSMessageBox::information(this,
  3685. QTStr("Output.ConnectFail.Title"),
  3686. QT_UTF8(errorMessage));
  3687. } else if (code != OBS_OUTPUT_SUCCESS && !isVisible()) {
  3688. SysTrayNotify(QT_UTF8(errorDescription), QSystemTrayIcon::Warning);
  3689. }
  3690. if (!startStreamMenu.isNull()) {
  3691. ui->streamButton->setMenu(nullptr);
  3692. startStreamMenu->deleteLater();
  3693. startStreamMenu = nullptr;
  3694. }
  3695. }
  3696. void OBSBasic::StartRecording()
  3697. {
  3698. if (outputHandler->RecordingActive())
  3699. return;
  3700. if (disableOutputsRef)
  3701. return;
  3702. if (api)
  3703. api->on_event(OBS_FRONTEND_EVENT_RECORDING_STARTING);
  3704. SaveProject();
  3705. outputHandler->StartRecording();
  3706. }
  3707. void OBSBasic::RecordStopping()
  3708. {
  3709. ui->recordButton->setText(QTStr("Basic.Main.StoppingRecording"));
  3710. if (sysTrayRecord)
  3711. sysTrayRecord->setText(ui->recordButton->text());
  3712. recordingStopping = true;
  3713. if (api)
  3714. api->on_event(OBS_FRONTEND_EVENT_RECORDING_STOPPING);
  3715. }
  3716. void OBSBasic::StopRecording()
  3717. {
  3718. SaveProject();
  3719. if (outputHandler->RecordingActive())
  3720. outputHandler->StopRecording(recordingStopping);
  3721. OnDeactivate();
  3722. }
  3723. void OBSBasic::RecordingStart()
  3724. {
  3725. ui->statusbar->RecordingStarted(outputHandler->fileOutput);
  3726. ui->recordButton->setText(QTStr("Basic.Main.StopRecording"));
  3727. ui->recordButton->setChecked(true);
  3728. if (sysTrayRecord)
  3729. sysTrayRecord->setText(ui->recordButton->text());
  3730. recordingStopping = false;
  3731. if (api)
  3732. api->on_event(OBS_FRONTEND_EVENT_RECORDING_STARTED);
  3733. OnActivate();
  3734. blog(LOG_INFO, RECORDING_START);
  3735. }
  3736. void OBSBasic::RecordingStop(int code)
  3737. {
  3738. ui->statusbar->RecordingStopped();
  3739. ui->recordButton->setText(QTStr("Basic.Main.StartRecording"));
  3740. ui->recordButton->setChecked(false);
  3741. if (sysTrayRecord)
  3742. sysTrayRecord->setText(ui->recordButton->text());
  3743. blog(LOG_INFO, RECORDING_STOP);
  3744. if (code == OBS_OUTPUT_UNSUPPORTED && isVisible()) {
  3745. OBSMessageBox::information(this,
  3746. QTStr("Output.RecordFail.Title"),
  3747. QTStr("Output.RecordFail.Unsupported"));
  3748. } else if (code == OBS_OUTPUT_NO_SPACE && isVisible()) {
  3749. OBSMessageBox::information(this,
  3750. QTStr("Output.RecordNoSpace.Title"),
  3751. QTStr("Output.RecordNoSpace.Msg"));
  3752. } else if (code != OBS_OUTPUT_SUCCESS && isVisible()) {
  3753. OBSMessageBox::information(this,
  3754. QTStr("Output.RecordError.Title"),
  3755. QTStr("Output.RecordError.Msg"));
  3756. } else if (code == OBS_OUTPUT_UNSUPPORTED && !isVisible()) {
  3757. SysTrayNotify(QTStr("Output.RecordFail.Unsupported"),
  3758. QSystemTrayIcon::Warning);
  3759. } else if (code == OBS_OUTPUT_NO_SPACE && !isVisible()) {
  3760. SysTrayNotify(QTStr("Output.RecordNoSpace.Msg"),
  3761. QSystemTrayIcon::Warning);
  3762. } else if (code != OBS_OUTPUT_SUCCESS && !isVisible()) {
  3763. SysTrayNotify(QTStr("Output.RecordError.Msg"),
  3764. QSystemTrayIcon::Warning);
  3765. }
  3766. if (api)
  3767. api->on_event(OBS_FRONTEND_EVENT_RECORDING_STOPPED);
  3768. OnDeactivate();
  3769. }
  3770. #define RP_NO_HOTKEY_TITLE QTStr("Output.ReplayBuffer.NoHotkey.Title")
  3771. #define RP_NO_HOTKEY_TEXT QTStr("Output.ReplayBuffer.NoHotkey.Msg")
  3772. void OBSBasic::StartReplayBuffer()
  3773. {
  3774. if (!outputHandler || !outputHandler->replayBuffer)
  3775. return;
  3776. if (outputHandler->ReplayBufferActive())
  3777. return;
  3778. if (disableOutputsRef)
  3779. return;
  3780. obs_output_t *output = outputHandler->replayBuffer;
  3781. obs_data_t *hotkeys = obs_hotkeys_save_output(output);
  3782. obs_data_array_t *bindings = obs_data_get_array(hotkeys,
  3783. "ReplayBuffer.Save");
  3784. size_t count = obs_data_array_count(bindings);
  3785. obs_data_array_release(bindings);
  3786. obs_data_release(hotkeys);
  3787. if (!count) {
  3788. OBSMessageBox::information(this,
  3789. RP_NO_HOTKEY_TITLE,
  3790. RP_NO_HOTKEY_TEXT);
  3791. return;
  3792. }
  3793. if (api)
  3794. api->on_event(OBS_FRONTEND_EVENT_REPLAY_BUFFER_STARTING);
  3795. SaveProject();
  3796. outputHandler->StartReplayBuffer();
  3797. }
  3798. void OBSBasic::ReplayBufferStopping()
  3799. {
  3800. if (!outputHandler || !outputHandler->replayBuffer)
  3801. return;
  3802. replayBufferButton->setText(QTStr("Basic.Main.StoppingReplayBuffer"));
  3803. if (sysTrayReplayBuffer)
  3804. sysTrayReplayBuffer->setText(replayBufferButton->text());
  3805. replayBufferStopping = true;
  3806. if (api)
  3807. api->on_event(OBS_FRONTEND_EVENT_REPLAY_BUFFER_STOPPING);
  3808. }
  3809. void OBSBasic::StopReplayBuffer()
  3810. {
  3811. if (!outputHandler || !outputHandler->replayBuffer)
  3812. return;
  3813. SaveProject();
  3814. if (outputHandler->ReplayBufferActive())
  3815. outputHandler->StopReplayBuffer(replayBufferStopping);
  3816. OnDeactivate();
  3817. }
  3818. void OBSBasic::ReplayBufferStart()
  3819. {
  3820. if (!outputHandler || !outputHandler->replayBuffer)
  3821. return;
  3822. replayBufferButton->setText(QTStr("Basic.Main.StopReplayBuffer"));
  3823. if (sysTrayReplayBuffer)
  3824. sysTrayReplayBuffer->setText(replayBufferButton->text());
  3825. replayBufferStopping = false;
  3826. if (api)
  3827. api->on_event(OBS_FRONTEND_EVENT_REPLAY_BUFFER_STARTED);
  3828. OnActivate();
  3829. blog(LOG_INFO, REPLAY_BUFFER_START);
  3830. }
  3831. void OBSBasic::ReplayBufferSave()
  3832. {
  3833. if (!outputHandler || !outputHandler->replayBuffer)
  3834. return;
  3835. if (!outputHandler->ReplayBufferActive())
  3836. return;
  3837. calldata_t cd = {0};
  3838. proc_handler_t *ph = obs_output_get_proc_handler(
  3839. outputHandler->replayBuffer);
  3840. proc_handler_call(ph, "save", &cd);
  3841. calldata_free(&cd);
  3842. }
  3843. void OBSBasic::ReplayBufferStop(int code)
  3844. {
  3845. if (!outputHandler || !outputHandler->replayBuffer)
  3846. return;
  3847. replayBufferButton->setText(QTStr("Basic.Main.StartReplayBuffer"));
  3848. if (sysTrayReplayBuffer)
  3849. sysTrayReplayBuffer->setText(replayBufferButton->text());
  3850. blog(LOG_INFO, REPLAY_BUFFER_STOP);
  3851. if (code == OBS_OUTPUT_UNSUPPORTED && isVisible()) {
  3852. OBSMessageBox::information(this,
  3853. QTStr("Output.RecordFail.Title"),
  3854. QTStr("Output.RecordFail.Unsupported"));
  3855. } else if (code == OBS_OUTPUT_NO_SPACE && isVisible()) {
  3856. OBSMessageBox::information(this,
  3857. QTStr("Output.RecordNoSpace.Title"),
  3858. QTStr("Output.RecordNoSpace.Msg"));
  3859. } else if (code != OBS_OUTPUT_SUCCESS && isVisible()) {
  3860. OBSMessageBox::information(this,
  3861. QTStr("Output.RecordError.Title"),
  3862. QTStr("Output.RecordError.Msg"));
  3863. } else if (code == OBS_OUTPUT_UNSUPPORTED && !isVisible()) {
  3864. SysTrayNotify(QTStr("Output.RecordFail.Unsupported"),
  3865. QSystemTrayIcon::Warning);
  3866. } else if (code == OBS_OUTPUT_NO_SPACE && !isVisible()) {
  3867. SysTrayNotify(QTStr("Output.RecordNoSpace.Msg"),
  3868. QSystemTrayIcon::Warning);
  3869. } else if (code != OBS_OUTPUT_SUCCESS && !isVisible()) {
  3870. SysTrayNotify(QTStr("Output.RecordError.Msg"),
  3871. QSystemTrayIcon::Warning);
  3872. }
  3873. if (api)
  3874. api->on_event(OBS_FRONTEND_EVENT_REPLAY_BUFFER_STOPPED);
  3875. OnDeactivate();
  3876. }
  3877. void OBSBasic::on_streamButton_clicked()
  3878. {
  3879. if (outputHandler->StreamingActive()) {
  3880. bool confirm = config_get_bool(GetGlobalConfig(), "BasicWindow",
  3881. "WarnBeforeStoppingStream");
  3882. if (confirm && isVisible()) {
  3883. QMessageBox::StandardButton button =
  3884. OBSMessageBox::question(this,
  3885. QTStr("ConfirmStop.Title"),
  3886. QTStr("ConfirmStop.Text"));
  3887. if (button == QMessageBox::No)
  3888. return;
  3889. }
  3890. StopStreaming();
  3891. } else {
  3892. bool confirm = config_get_bool(GetGlobalConfig(), "BasicWindow",
  3893. "WarnBeforeStartingStream");
  3894. if (confirm && isVisible()) {
  3895. QMessageBox::StandardButton button =
  3896. OBSMessageBox::question(this,
  3897. QTStr("ConfirmStart.Title"),
  3898. QTStr("ConfirmStart.Text"));
  3899. if (button == QMessageBox::No)
  3900. return;
  3901. }
  3902. StartStreaming();
  3903. }
  3904. }
  3905. void OBSBasic::on_recordButton_clicked()
  3906. {
  3907. if (outputHandler->RecordingActive())
  3908. StopRecording();
  3909. else
  3910. StartRecording();
  3911. }
  3912. void OBSBasic::on_settingsButton_clicked()
  3913. {
  3914. on_action_Settings_triggered();
  3915. }
  3916. void OBSBasic::on_actionWebsite_triggered()
  3917. {
  3918. QUrl url = QUrl("https://obsproject.com", QUrl::TolerantMode);
  3919. QDesktopServices::openUrl(url);
  3920. }
  3921. void OBSBasic::on_actionShowSettingsFolder_triggered()
  3922. {
  3923. char path[512];
  3924. int ret = GetConfigPath(path, 512, "obs-studio");
  3925. if (ret <= 0)
  3926. return;
  3927. QDesktopServices::openUrl(QUrl::fromLocalFile(path));
  3928. }
  3929. void OBSBasic::on_actionShowProfileFolder_triggered()
  3930. {
  3931. char path[512];
  3932. int ret = GetProfilePath(path, 512, "");
  3933. if (ret <= 0)
  3934. return;
  3935. QDesktopServices::openUrl(QUrl::fromLocalFile(path));
  3936. }
  3937. QListWidgetItem *OBSBasic::GetTopSelectedSourceItem()
  3938. {
  3939. QList<QListWidgetItem*> selectedItems = ui->sources->selectedItems();
  3940. QListWidgetItem *topItem = nullptr;
  3941. if (selectedItems.size() != 0)
  3942. topItem = selectedItems[0];
  3943. return topItem;
  3944. }
  3945. void OBSBasic::on_preview_customContextMenuRequested(const QPoint &pos)
  3946. {
  3947. CreateSourcePopupMenu(GetTopSelectedSourceItem(), true);
  3948. UNUSED_PARAMETER(pos);
  3949. }
  3950. void OBSBasic::on_program_customContextMenuRequested(const QPoint&)
  3951. {
  3952. QMenu popup(this);
  3953. QPointer<QMenu> studioProgramProjector;
  3954. studioProgramProjector = new QMenu(
  3955. QTStr("StudioProgramProjector"));
  3956. AddProjectorMenuMonitors(studioProgramProjector, this,
  3957. SLOT(OpenPreviewProjector()));
  3958. popup.addMenu(studioProgramProjector);
  3959. QAction *studioProgramWindow = popup.addAction(
  3960. QTStr("StudioProgramWindow"),
  3961. this, SLOT(OpenPreviewWindow()));
  3962. popup.addAction(studioProgramWindow);
  3963. popup.exec(QCursor::pos());
  3964. }
  3965. void OBSBasic::on_previewDisabledLabel_customContextMenuRequested(
  3966. const QPoint &pos)
  3967. {
  3968. QMenu popup(this);
  3969. QPointer<QMenu> previewProjector;
  3970. QAction *action = popup.addAction(
  3971. QTStr("Basic.Main.PreviewConextMenu.Enable"),
  3972. this, SLOT(TogglePreview()));
  3973. action->setCheckable(true);
  3974. action->setChecked(obs_display_enabled(ui->preview->GetDisplay()));
  3975. previewProjector = new QMenu(QTStr("PreviewProjector"));
  3976. AddProjectorMenuMonitors(previewProjector, this,
  3977. SLOT(OpenPreviewProjector()));
  3978. QAction *previewWindow = popup.addAction(
  3979. QTStr("PreviewWindow"),
  3980. this, SLOT(OpenPreviewWindow()));
  3981. popup.addMenu(previewProjector);
  3982. popup.addAction(previewWindow);
  3983. popup.exec(QCursor::pos());
  3984. UNUSED_PARAMETER(pos);
  3985. }
  3986. void OBSBasic::on_actionAlwaysOnTop_triggered()
  3987. {
  3988. CloseDialogs();
  3989. /* Make sure all dialogs are safely and successfully closed before
  3990. * switching the always on top mode due to the fact that windows all
  3991. * have to be recreated, so queue the actual toggle to happen after
  3992. * all events related to closing the dialogs have finished */
  3993. QMetaObject::invokeMethod(this, "ToggleAlwaysOnTop",
  3994. Qt::QueuedConnection);
  3995. }
  3996. void OBSBasic::ToggleAlwaysOnTop()
  3997. {
  3998. bool isAlwaysOnTop = IsAlwaysOnTop(this);
  3999. ui->actionAlwaysOnTop->setChecked(!isAlwaysOnTop);
  4000. SetAlwaysOnTop(this, !isAlwaysOnTop);
  4001. show();
  4002. }
  4003. void OBSBasic::GetFPSCommon(uint32_t &num, uint32_t &den) const
  4004. {
  4005. const char *val = config_get_string(basicConfig, "Video", "FPSCommon");
  4006. if (strcmp(val, "10") == 0) {
  4007. num = 10;
  4008. den = 1;
  4009. } else if (strcmp(val, "20") == 0) {
  4010. num = 20;
  4011. den = 1;
  4012. } else if (strcmp(val, "24 NTSC") == 0) {
  4013. num = 24000;
  4014. den = 1001;
  4015. } else if (strcmp(val, "25") == 0) {
  4016. num = 25;
  4017. den = 1;
  4018. } else if (strcmp(val, "29.97") == 0) {
  4019. num = 30000;
  4020. den = 1001;
  4021. } else if (strcmp(val, "48") == 0) {
  4022. num = 48;
  4023. den = 1;
  4024. } else if (strcmp(val, "59.94") == 0) {
  4025. num = 60000;
  4026. den = 1001;
  4027. } else if (strcmp(val, "60") == 0) {
  4028. num = 60;
  4029. den = 1;
  4030. } else {
  4031. num = 30;
  4032. den = 1;
  4033. }
  4034. }
  4035. void OBSBasic::GetFPSInteger(uint32_t &num, uint32_t &den) const
  4036. {
  4037. num = (uint32_t)config_get_uint(basicConfig, "Video", "FPSInt");
  4038. den = 1;
  4039. }
  4040. void OBSBasic::GetFPSFraction(uint32_t &num, uint32_t &den) const
  4041. {
  4042. num = (uint32_t)config_get_uint(basicConfig, "Video", "FPSNum");
  4043. den = (uint32_t)config_get_uint(basicConfig, "Video", "FPSDen");
  4044. }
  4045. void OBSBasic::GetFPSNanoseconds(uint32_t &num, uint32_t &den) const
  4046. {
  4047. num = 1000000000;
  4048. den = (uint32_t)config_get_uint(basicConfig, "Video", "FPSNS");
  4049. }
  4050. void OBSBasic::GetConfigFPS(uint32_t &num, uint32_t &den) const
  4051. {
  4052. uint32_t type = config_get_uint(basicConfig, "Video", "FPSType");
  4053. if (type == 1) //"Integer"
  4054. GetFPSInteger(num, den);
  4055. else if (type == 2) //"Fraction"
  4056. GetFPSFraction(num, den);
  4057. else if (false) //"Nanoseconds", currently not implemented
  4058. GetFPSNanoseconds(num, den);
  4059. else
  4060. GetFPSCommon(num, den);
  4061. }
  4062. config_t *OBSBasic::Config() const
  4063. {
  4064. return basicConfig;
  4065. }
  4066. void OBSBasic::on_actionEditTransform_triggered()
  4067. {
  4068. if (transformWindow)
  4069. transformWindow->close();
  4070. transformWindow = new OBSBasicTransform(this);
  4071. transformWindow->show();
  4072. transformWindow->setAttribute(Qt::WA_DeleteOnClose, true);
  4073. }
  4074. static obs_transform_info copiedTransformInfo;
  4075. static obs_sceneitem_crop copiedCropInfo;
  4076. void OBSBasic::on_actionCopyTransform_triggered()
  4077. {
  4078. auto func = [](obs_scene_t *scene, obs_sceneitem_t *item, void *param)
  4079. {
  4080. if (!obs_sceneitem_selected(item))
  4081. return true;
  4082. obs_sceneitem_defer_update_begin(item);
  4083. obs_sceneitem_get_info(item, &copiedTransformInfo);
  4084. obs_sceneitem_get_crop(item, &copiedCropInfo);
  4085. obs_sceneitem_defer_update_end(item);
  4086. UNUSED_PARAMETER(scene);
  4087. UNUSED_PARAMETER(param);
  4088. return true;
  4089. };
  4090. obs_scene_enum_items(GetCurrentScene(), func, nullptr);
  4091. ui->actionPasteTransform->setEnabled(true);
  4092. }
  4093. void OBSBasic::on_actionPasteTransform_triggered()
  4094. {
  4095. auto func = [](obs_scene_t *scene, obs_sceneitem_t *item, void *param)
  4096. {
  4097. if (!obs_sceneitem_selected(item))
  4098. return true;
  4099. obs_sceneitem_defer_update_begin(item);
  4100. obs_sceneitem_set_info(item, &copiedTransformInfo);
  4101. obs_sceneitem_set_crop(item, &copiedCropInfo);
  4102. obs_sceneitem_defer_update_end(item);
  4103. UNUSED_PARAMETER(scene);
  4104. UNUSED_PARAMETER(param);
  4105. return true;
  4106. };
  4107. obs_scene_enum_items(GetCurrentScene(), func, nullptr);
  4108. }
  4109. void OBSBasic::on_actionResetTransform_triggered()
  4110. {
  4111. auto func = [] (obs_scene_t *scene, obs_sceneitem_t *item, void *param)
  4112. {
  4113. if (!obs_sceneitem_selected(item))
  4114. return true;
  4115. obs_sceneitem_defer_update_begin(item);
  4116. obs_transform_info info;
  4117. vec2_set(&info.pos, 0.0f, 0.0f);
  4118. vec2_set(&info.scale, 1.0f, 1.0f);
  4119. info.rot = 0.0f;
  4120. info.alignment = OBS_ALIGN_TOP | OBS_ALIGN_LEFT;
  4121. info.bounds_type = OBS_BOUNDS_NONE;
  4122. info.bounds_alignment = OBS_ALIGN_CENTER;
  4123. vec2_set(&info.bounds, 0.0f, 0.0f);
  4124. obs_sceneitem_set_info(item, &info);
  4125. obs_sceneitem_crop crop = {};
  4126. obs_sceneitem_set_crop(item, &crop);
  4127. obs_sceneitem_defer_update_end(item);
  4128. UNUSED_PARAMETER(scene);
  4129. UNUSED_PARAMETER(param);
  4130. return true;
  4131. };
  4132. obs_scene_enum_items(GetCurrentScene(), func, nullptr);
  4133. }
  4134. static void GetItemBox(obs_sceneitem_t *item, vec3 &tl, vec3 &br)
  4135. {
  4136. matrix4 boxTransform;
  4137. obs_sceneitem_get_box_transform(item, &boxTransform);
  4138. vec3_set(&tl, M_INFINITE, M_INFINITE, 0.0f);
  4139. vec3_set(&br, -M_INFINITE, -M_INFINITE, 0.0f);
  4140. auto GetMinPos = [&] (float x, float y)
  4141. {
  4142. vec3 pos;
  4143. vec3_set(&pos, x, y, 0.0f);
  4144. vec3_transform(&pos, &pos, &boxTransform);
  4145. vec3_min(&tl, &tl, &pos);
  4146. vec3_max(&br, &br, &pos);
  4147. };
  4148. GetMinPos(0.0f, 0.0f);
  4149. GetMinPos(1.0f, 0.0f);
  4150. GetMinPos(0.0f, 1.0f);
  4151. GetMinPos(1.0f, 1.0f);
  4152. }
  4153. static vec3 GetItemTL(obs_sceneitem_t *item)
  4154. {
  4155. vec3 tl, br;
  4156. GetItemBox(item, tl, br);
  4157. return tl;
  4158. }
  4159. static void SetItemTL(obs_sceneitem_t *item, const vec3 &tl)
  4160. {
  4161. vec3 newTL;
  4162. vec2 pos;
  4163. obs_sceneitem_get_pos(item, &pos);
  4164. newTL = GetItemTL(item);
  4165. pos.x += tl.x - newTL.x;
  4166. pos.y += tl.y - newTL.y;
  4167. obs_sceneitem_set_pos(item, &pos);
  4168. }
  4169. static bool RotateSelectedSources(obs_scene_t *scene, obs_sceneitem_t *item,
  4170. void *param)
  4171. {
  4172. if (!obs_sceneitem_selected(item))
  4173. return true;
  4174. float rot = *reinterpret_cast<float*>(param);
  4175. vec3 tl = GetItemTL(item);
  4176. rot += obs_sceneitem_get_rot(item);
  4177. if (rot >= 360.0f) rot -= 360.0f;
  4178. else if (rot <= -360.0f) rot += 360.0f;
  4179. obs_sceneitem_set_rot(item, rot);
  4180. SetItemTL(item, tl);
  4181. UNUSED_PARAMETER(scene);
  4182. UNUSED_PARAMETER(param);
  4183. return true;
  4184. };
  4185. void OBSBasic::on_actionRotate90CW_triggered()
  4186. {
  4187. float f90CW = 90.0f;
  4188. obs_scene_enum_items(GetCurrentScene(), RotateSelectedSources, &f90CW);
  4189. }
  4190. void OBSBasic::on_actionRotate90CCW_triggered()
  4191. {
  4192. float f90CCW = -90.0f;
  4193. obs_scene_enum_items(GetCurrentScene(), RotateSelectedSources, &f90CCW);
  4194. }
  4195. void OBSBasic::on_actionRotate180_triggered()
  4196. {
  4197. float f180 = 180.0f;
  4198. obs_scene_enum_items(GetCurrentScene(), RotateSelectedSources, &f180);
  4199. }
  4200. static bool MultiplySelectedItemScale(obs_scene_t *scene, obs_sceneitem_t *item,
  4201. void *param)
  4202. {
  4203. vec2 &mul = *reinterpret_cast<vec2*>(param);
  4204. if (!obs_sceneitem_selected(item))
  4205. return true;
  4206. vec3 tl = GetItemTL(item);
  4207. vec2 scale;
  4208. obs_sceneitem_get_scale(item, &scale);
  4209. vec2_mul(&scale, &scale, &mul);
  4210. obs_sceneitem_set_scale(item, &scale);
  4211. SetItemTL(item, tl);
  4212. UNUSED_PARAMETER(scene);
  4213. return true;
  4214. }
  4215. void OBSBasic::on_actionFlipHorizontal_triggered()
  4216. {
  4217. vec2 scale;
  4218. vec2_set(&scale, -1.0f, 1.0f);
  4219. obs_scene_enum_items(GetCurrentScene(), MultiplySelectedItemScale,
  4220. &scale);
  4221. }
  4222. void OBSBasic::on_actionFlipVertical_triggered()
  4223. {
  4224. vec2 scale;
  4225. vec2_set(&scale, 1.0f, -1.0f);
  4226. obs_scene_enum_items(GetCurrentScene(), MultiplySelectedItemScale,
  4227. &scale);
  4228. }
  4229. static bool CenterAlignSelectedItems(obs_scene_t *scene, obs_sceneitem_t *item,
  4230. void *param)
  4231. {
  4232. obs_bounds_type boundsType = *reinterpret_cast<obs_bounds_type*>(param);
  4233. if (!obs_sceneitem_selected(item))
  4234. return true;
  4235. obs_video_info ovi;
  4236. obs_get_video_info(&ovi);
  4237. obs_transform_info itemInfo;
  4238. vec2_set(&itemInfo.pos, 0.0f, 0.0f);
  4239. vec2_set(&itemInfo.scale, 1.0f, 1.0f);
  4240. itemInfo.alignment = OBS_ALIGN_LEFT | OBS_ALIGN_TOP;
  4241. itemInfo.rot = 0.0f;
  4242. vec2_set(&itemInfo.bounds,
  4243. float(ovi.base_width), float(ovi.base_height));
  4244. itemInfo.bounds_type = boundsType;
  4245. itemInfo.bounds_alignment = OBS_ALIGN_CENTER;
  4246. obs_sceneitem_set_info(item, &itemInfo);
  4247. UNUSED_PARAMETER(scene);
  4248. return true;
  4249. }
  4250. void OBSBasic::on_actionFitToScreen_triggered()
  4251. {
  4252. obs_bounds_type boundsType = OBS_BOUNDS_SCALE_INNER;
  4253. obs_scene_enum_items(GetCurrentScene(), CenterAlignSelectedItems,
  4254. &boundsType);
  4255. }
  4256. void OBSBasic::on_actionStretchToScreen_triggered()
  4257. {
  4258. obs_bounds_type boundsType = OBS_BOUNDS_STRETCH;
  4259. obs_scene_enum_items(GetCurrentScene(), CenterAlignSelectedItems,
  4260. &boundsType);
  4261. }
  4262. void OBSBasic::on_actionCenterToScreen_triggered()
  4263. {
  4264. auto func = [] (obs_scene_t *scene, obs_sceneitem_t *item, void *param)
  4265. {
  4266. vec3 tl, br, itemCenter, screenCenter, offset;
  4267. obs_video_info ovi;
  4268. if (!obs_sceneitem_selected(item))
  4269. return true;
  4270. obs_get_video_info(&ovi);
  4271. vec3_set(&screenCenter, float(ovi.base_width),
  4272. float(ovi.base_height), 0.0f);
  4273. vec3_mulf(&screenCenter, &screenCenter, 0.5f);
  4274. GetItemBox(item, tl, br);
  4275. vec3_sub(&itemCenter, &br, &tl);
  4276. vec3_mulf(&itemCenter, &itemCenter, 0.5f);
  4277. vec3_add(&itemCenter, &itemCenter, &tl);
  4278. vec3_sub(&offset, &screenCenter, &itemCenter);
  4279. vec3_add(&tl, &tl, &offset);
  4280. SetItemTL(item, tl);
  4281. UNUSED_PARAMETER(scene);
  4282. UNUSED_PARAMETER(param);
  4283. return true;
  4284. };
  4285. obs_scene_enum_items(GetCurrentScene(), func, nullptr);
  4286. }
  4287. void OBSBasic::EnablePreviewDisplay(bool enable)
  4288. {
  4289. obs_display_set_enabled(ui->preview->GetDisplay(), enable);
  4290. ui->preview->setVisible(enable);
  4291. ui->previewDisabledLabel->setVisible(!enable);
  4292. }
  4293. void OBSBasic::TogglePreview()
  4294. {
  4295. previewEnabled = !previewEnabled;
  4296. EnablePreviewDisplay(previewEnabled);
  4297. }
  4298. void OBSBasic::Nudge(int dist, MoveDir dir)
  4299. {
  4300. if (ui->preview->Locked())
  4301. return;
  4302. struct MoveInfo {
  4303. float dist;
  4304. MoveDir dir;
  4305. } info = {(float)dist, dir};
  4306. auto func = [] (obs_scene_t*, obs_sceneitem_t *item, void *param)
  4307. {
  4308. if (obs_sceneitem_locked(item))
  4309. return true;
  4310. MoveInfo *info = reinterpret_cast<MoveInfo*>(param);
  4311. struct vec2 dir;
  4312. struct vec2 pos;
  4313. vec2_set(&dir, 0.0f, 0.0f);
  4314. if (!obs_sceneitem_selected(item))
  4315. return true;
  4316. switch (info->dir) {
  4317. case MoveDir::Up: dir.y = -info->dist; break;
  4318. case MoveDir::Down: dir.y = info->dist; break;
  4319. case MoveDir::Left: dir.x = -info->dist; break;
  4320. case MoveDir::Right: dir.x = info->dist; break;
  4321. }
  4322. obs_sceneitem_get_pos(item, &pos);
  4323. vec2_add(&pos, &pos, &dir);
  4324. obs_sceneitem_set_pos(item, &pos);
  4325. return true;
  4326. };
  4327. obs_scene_enum_items(GetCurrentScene(), func, &info);
  4328. }
  4329. void OBSBasic::NudgeUp() {Nudge(1, MoveDir::Up);}
  4330. void OBSBasic::NudgeDown() {Nudge(1, MoveDir::Down);}
  4331. void OBSBasic::NudgeLeft() {Nudge(1, MoveDir::Left);}
  4332. void OBSBasic::NudgeRight() {Nudge(1, MoveDir::Right);}
  4333. void OBSBasic::OpenProjector(obs_source_t *source, int monitor, bool window,
  4334. QString title, bool studioProgram)
  4335. {
  4336. /* seriously? 10 monitors? */
  4337. if (monitor > 9 || monitor > QGuiApplication::screens().size() - 1)
  4338. return;
  4339. bool isPreview = false;
  4340. if (source == nullptr)
  4341. isPreview = true;
  4342. if (!window) {
  4343. delete projectors[monitor];
  4344. projectors[monitor].clear();
  4345. RemoveSavedProjectors(monitor);
  4346. }
  4347. OBSProjector *projector = new OBSProjector(nullptr, source, !!window);
  4348. const char *name = obs_source_get_name(source);
  4349. if (!window) {
  4350. if (studioProgram) {
  4351. studioProgramProjectorArray.at((size_t)monitor) = name;
  4352. } else if (isPreview) {
  4353. previewProjectorArray.at((size_t)monitor) = 1;
  4354. } else {
  4355. projectorArray.at((size_t)monitor) = name;
  4356. }
  4357. }
  4358. if (!window) {
  4359. projector->Init(monitor, false, nullptr, studioProgram);
  4360. projectors[monitor] = projector;
  4361. } else {
  4362. projector->Init(monitor, true, title, studioProgram);
  4363. for (auto &projPtr : windowProjectors) {
  4364. if (!projPtr) {
  4365. projPtr = projector;
  4366. projector = nullptr;
  4367. }
  4368. }
  4369. if (projector)
  4370. windowProjectors.push_back(projector);
  4371. }
  4372. }
  4373. void OBSBasic::OpenStudioProgramProjector()
  4374. {
  4375. int monitor = sender()->property("monitor").toInt();
  4376. obs_source_t *source = GetCurrentSceneSource();
  4377. if (!source)
  4378. return;
  4379. OpenProjector(source, monitor, false, nullptr, true);
  4380. }
  4381. void OBSBasic::OpenPreviewProjector()
  4382. {
  4383. int monitor = sender()->property("monitor").toInt();
  4384. OpenProjector(nullptr, monitor, false);
  4385. }
  4386. void OBSBasic::OpenSourceProjector()
  4387. {
  4388. int monitor = sender()->property("monitor").toInt();
  4389. OBSSceneItem item = GetCurrentSceneItem();
  4390. if (!item)
  4391. return;
  4392. OpenProjector(obs_sceneitem_get_source(item), monitor, false);
  4393. }
  4394. void OBSBasic::OpenSceneProjector()
  4395. {
  4396. int monitor = sender()->property("monitor").toInt();
  4397. OBSScene scene = GetCurrentScene();
  4398. if (!scene)
  4399. return;
  4400. OpenProjector(obs_scene_get_source(scene), monitor, false);
  4401. }
  4402. void OBSBasic::OpenStudioProgramWindow()
  4403. {
  4404. int monitor = sender()->property("monitor").toInt();
  4405. QString title = QTStr("StudioProgramWindow");
  4406. obs_source_t *source = GetCurrentSceneSource();
  4407. if (!source)
  4408. return;
  4409. OpenProjector(source, monitor, true, title, true);
  4410. }
  4411. void OBSBasic::OpenPreviewWindow()
  4412. {
  4413. int monitor = sender()->property("monitor").toInt();
  4414. QString title = QTStr("PreviewWindow");
  4415. OpenProjector(nullptr, monitor, true, title);
  4416. }
  4417. void OBSBasic::OpenSourceWindow()
  4418. {
  4419. int monitor = sender()->property("monitor").toInt();
  4420. OBSSceneItem item = GetCurrentSceneItem();
  4421. OBSSource source = obs_sceneitem_get_source(item);
  4422. QString text = QString::fromUtf8(obs_source_get_name(source));
  4423. QString title = QTStr("SourceWindow") + " - " + text;
  4424. if (!item)
  4425. return;
  4426. OpenProjector(obs_sceneitem_get_source(item), monitor, true, title);
  4427. }
  4428. void OBSBasic::OpenSceneWindow()
  4429. {
  4430. int monitor = sender()->property("monitor").toInt();
  4431. OBSScene scene = GetCurrentScene();
  4432. OBSSource source = obs_scene_get_source(scene);
  4433. QString text = QString::fromUtf8(obs_source_get_name(source));
  4434. QString title = QTStr("SceneWindow") + " - " + text;
  4435. if (!scene)
  4436. return;
  4437. OpenProjector(obs_scene_get_source(scene), monitor, true, title);
  4438. }
  4439. void OBSBasic::OpenSavedProjectors()
  4440. {
  4441. bool projectorSave = config_get_bool(GetGlobalConfig(),
  4442. "BasicWindow", "SaveProjectors");
  4443. if (projectorSave) {
  4444. for (size_t i = 0; i < projectorArray.size(); i++) {
  4445. if (projectorArray.at(i).empty() == false) {
  4446. OBSSource source = obs_get_source_by_name(
  4447. projectorArray.at(i).c_str());
  4448. if (!source) {
  4449. RemoveSavedProjectors((int)i);
  4450. obs_source_release(source);
  4451. continue;
  4452. }
  4453. OpenProjector(source, (int)i, false);
  4454. obs_source_release(source);
  4455. }
  4456. }
  4457. for (size_t i = 0; i < studioProgramProjectorArray.size(); i++) {
  4458. if (studioProgramProjectorArray.at(i).empty() == false) {
  4459. OBSSource source = obs_get_source_by_name(
  4460. studioProgramProjectorArray.at(i).c_str());
  4461. if (!source) {
  4462. RemoveSavedProjectors((int)i);
  4463. obs_source_release(source);
  4464. continue;
  4465. }
  4466. OpenProjector(source, (int)i, false, nullptr, true);
  4467. obs_source_release(source);
  4468. }
  4469. }
  4470. for (size_t i = 0; i < previewProjectorArray.size(); i++) {
  4471. if (previewProjectorArray.at(i) == 1) {
  4472. OpenProjector(nullptr, (int)i, false);
  4473. }
  4474. }
  4475. }
  4476. }
  4477. void OBSBasic::RemoveSavedProjectors(int monitor)
  4478. {
  4479. studioProgramProjectorArray.at((size_t)monitor) = "";
  4480. previewProjectorArray.at((size_t)monitor) = 0;
  4481. projectorArray.at((size_t)monitor) = "";
  4482. }
  4483. void OBSBasic::on_actionFullscreenInterface_triggered()
  4484. {
  4485. if (!fullscreenInterface)
  4486. showFullScreen();
  4487. else
  4488. showNormal();
  4489. fullscreenInterface = !fullscreenInterface;
  4490. }
  4491. void OBSBasic::UpdateTitleBar()
  4492. {
  4493. stringstream name;
  4494. const char *profile = config_get_string(App()->GlobalConfig(),
  4495. "Basic", "Profile");
  4496. const char *sceneCollection = config_get_string(App()->GlobalConfig(),
  4497. "Basic", "SceneCollection");
  4498. name << "OBS ";
  4499. if (previewProgramMode)
  4500. name << "Studio ";
  4501. name << App()->GetVersionString();
  4502. if (App()->IsPortableMode())
  4503. name << " - Portable Mode";
  4504. name << " - " << Str("TitleBar.Profile") << ": " << profile;
  4505. name << " - " << Str("TitleBar.Scenes") << ": " << sceneCollection;
  4506. setWindowTitle(QT_UTF8(name.str().c_str()));
  4507. }
  4508. int OBSBasic::GetProfilePath(char *path, size_t size, const char *file) const
  4509. {
  4510. char profiles_path[512];
  4511. const char *profile = config_get_string(App()->GlobalConfig(),
  4512. "Basic", "ProfileDir");
  4513. int ret;
  4514. if (!profile)
  4515. return -1;
  4516. if (!path)
  4517. return -1;
  4518. if (!file)
  4519. file = "";
  4520. ret = GetConfigPath(profiles_path, 512, "obs-studio/basic/profiles");
  4521. if (ret <= 0)
  4522. return ret;
  4523. if (!*file)
  4524. return snprintf(path, size, "%s/%s", profiles_path, profile);
  4525. return snprintf(path, size, "%s/%s/%s", profiles_path, profile, file);
  4526. }
  4527. void OBSBasic::on_resetUI_triggered()
  4528. {
  4529. restoreState(startingDockLayout);
  4530. #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
  4531. int cx = width();
  4532. int cy = height();
  4533. int cx22_5 = cx * 225 / 1000;
  4534. int cx5 = cx * 5 / 100;
  4535. cy = cy * 225 / 1000;
  4536. int mixerSize = cx - (cx22_5 * 2 + cx5 * 2);
  4537. QList<QDockWidget*> docks {
  4538. ui->scenesDock,
  4539. ui->sourcesDock,
  4540. ui->mixerDock,
  4541. ui->transitionsDock,
  4542. ui->controlsDock
  4543. };
  4544. QList<int> sizes {
  4545. cx22_5,
  4546. cx22_5,
  4547. mixerSize,
  4548. cx5,
  4549. cx5
  4550. };
  4551. ui->scenesDock->setVisible(true);
  4552. ui->sourcesDock->setVisible(true);
  4553. ui->mixerDock->setVisible(true);
  4554. ui->transitionsDock->setVisible(true);
  4555. ui->controlsDock->setVisible(true);
  4556. resizeDocks(docks, {cy, cy, cy, cy, cy}, Qt::Vertical);
  4557. resizeDocks(docks, sizes, Qt::Horizontal);
  4558. #endif
  4559. }
  4560. void OBSBasic::on_lockUI_toggled(bool lock)
  4561. {
  4562. QDockWidget::DockWidgetFeatures features = lock
  4563. ? QDockWidget::NoDockWidgetFeatures
  4564. : QDockWidget::AllDockWidgetFeatures;
  4565. ui->scenesDock->setFeatures(features);
  4566. ui->sourcesDock->setFeatures(features);
  4567. ui->mixerDock->setFeatures(features);
  4568. ui->transitionsDock->setFeatures(features);
  4569. ui->controlsDock->setFeatures(features);
  4570. }
  4571. void OBSBasic::on_toggleListboxToolbars_toggled(bool visible)
  4572. {
  4573. ui->sourcesToolbar->setVisible(visible);
  4574. ui->scenesToolbar->setVisible(visible);
  4575. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  4576. "ShowListboxToolbars", visible);
  4577. }
  4578. void OBSBasic::on_toggleStatusBar_toggled(bool visible)
  4579. {
  4580. ui->statusbar->setVisible(visible);
  4581. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  4582. "ShowStatusBar", visible);
  4583. }
  4584. void OBSBasic::on_actionLockPreview_triggered()
  4585. {
  4586. ui->preview->ToggleLocked();
  4587. ui->actionLockPreview->setChecked(ui->preview->Locked());
  4588. }
  4589. void OBSBasic::on_scalingMenu_aboutToShow()
  4590. {
  4591. obs_video_info ovi;
  4592. obs_get_video_info(&ovi);
  4593. QAction *action = ui->actionScaleCanvas;
  4594. QString text = QTStr("Basic.MainMenu.Edit.Scale.Canvas");
  4595. text = text.arg(QString::number(ovi.base_width),
  4596. QString::number(ovi.base_height));
  4597. action->setText(text);
  4598. action = ui->actionScaleOutput;
  4599. text = QTStr("Basic.MainMenu.Edit.Scale.Output");
  4600. text = text.arg(QString::number(ovi.output_width),
  4601. QString::number(ovi.output_height));
  4602. action->setText(text);
  4603. action->setVisible(!(ovi.output_width == ovi.base_width &&
  4604. ovi.output_height == ovi.base_height));
  4605. UpdatePreviewScalingMenu();
  4606. }
  4607. void OBSBasic::on_actionScaleWindow_triggered()
  4608. {
  4609. ui->preview->SetFixedScaling(false);
  4610. ui->preview->ResetScrollingOffset();
  4611. emit ui->preview->DisplayResized();
  4612. }
  4613. void OBSBasic::on_actionScaleCanvas_triggered()
  4614. {
  4615. ui->preview->SetFixedScaling(true);
  4616. ui->preview->SetScalingLevel(0);
  4617. emit ui->preview->DisplayResized();
  4618. }
  4619. void OBSBasic::on_actionScaleOutput_triggered()
  4620. {
  4621. obs_video_info ovi;
  4622. obs_get_video_info(&ovi);
  4623. ui->preview->SetFixedScaling(true);
  4624. float scalingAmount = float(ovi.output_width) / float(ovi.base_width);
  4625. // log base ZOOM_SENSITIVITY of x = log(x) / log(ZOOM_SENSITIVITY)
  4626. int32_t approxScalingLevel = int32_t(
  4627. round(log(scalingAmount) / log(ZOOM_SENSITIVITY)));
  4628. ui->preview->SetScalingLevel(approxScalingLevel);
  4629. ui->preview->SetScalingAmount(scalingAmount);
  4630. emit ui->preview->DisplayResized();
  4631. }
  4632. void OBSBasic::SetShowing(bool showing)
  4633. {
  4634. if (!showing && isVisible()) {
  4635. config_set_string(App()->GlobalConfig(),
  4636. "BasicWindow", "geometry",
  4637. saveGeometry().toBase64().constData());
  4638. /* hide all visible child dialogs */
  4639. visDlgPositions.clear();
  4640. if (!visDialogs.isEmpty()) {
  4641. for (QDialog *dlg : visDialogs) {
  4642. visDlgPositions.append(dlg->pos());
  4643. dlg->hide();
  4644. }
  4645. }
  4646. if (showHide)
  4647. showHide->setText(QTStr("Basic.SystemTray.Show"));
  4648. QTimer::singleShot(250, this, SLOT(hide()));
  4649. if (previewEnabled)
  4650. EnablePreviewDisplay(false);
  4651. setVisible(false);
  4652. } else if (showing && !isVisible()) {
  4653. if (showHide)
  4654. showHide->setText(QTStr("Basic.SystemTray.Hide"));
  4655. QTimer::singleShot(250, this, SLOT(show()));
  4656. if (previewEnabled)
  4657. EnablePreviewDisplay(true);
  4658. setVisible(true);
  4659. /* show all child dialogs that was visible earlier */
  4660. if (!visDialogs.isEmpty()) {
  4661. for (int i = 0; i < visDialogs.size(); ++i) {
  4662. QDialog *dlg = visDialogs[i];
  4663. dlg->move(visDlgPositions[i]);
  4664. dlg->show();
  4665. }
  4666. }
  4667. /* Unminimize window if it was hidden to tray instead of task
  4668. * bar. */
  4669. if (sysTrayMinimizeToTray()) {
  4670. Qt::WindowStates state;
  4671. state = windowState() & ~Qt::WindowMinimized;
  4672. state |= Qt::WindowActive;
  4673. setWindowState(state);
  4674. }
  4675. }
  4676. }
  4677. void OBSBasic::ToggleShowHide()
  4678. {
  4679. bool showing = isVisible();
  4680. if (showing) {
  4681. /* check for modal dialogs */
  4682. EnumDialogs();
  4683. if (!modalDialogs.isEmpty() || !visMsgBoxes.isEmpty())
  4684. return;
  4685. }
  4686. SetShowing(!showing);
  4687. }
  4688. void OBSBasic::SystemTrayInit()
  4689. {
  4690. trayIcon = new QSystemTrayIcon(QIcon(":/res/images/obs.png"),
  4691. this);
  4692. trayIcon->setToolTip("OBS Studio");
  4693. showHide = new QAction(QTStr("Basic.SystemTray.Show"),
  4694. trayIcon);
  4695. sysTrayStream = new QAction(QTStr("Basic.Main.StartStreaming"),
  4696. trayIcon);
  4697. sysTrayRecord = new QAction(QTStr("Basic.Main.StartRecording"),
  4698. trayIcon);
  4699. sysTrayReplayBuffer = new QAction(QTStr("Basic.Main.StartReplayBuffer"),
  4700. trayIcon);
  4701. exit = new QAction(QTStr("Exit"),
  4702. trayIcon);
  4703. if (outputHandler && !outputHandler->replayBuffer)
  4704. sysTrayReplayBuffer->setEnabled(false);
  4705. connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
  4706. this,
  4707. SLOT(IconActivated(QSystemTrayIcon::ActivationReason)));
  4708. connect(showHide, SIGNAL(triggered()),
  4709. this, SLOT(ToggleShowHide()));
  4710. connect(sysTrayStream, SIGNAL(triggered()),
  4711. this, SLOT(on_streamButton_clicked()));
  4712. connect(sysTrayRecord, SIGNAL(triggered()),
  4713. this, SLOT(on_recordButton_clicked()));
  4714. connect(sysTrayReplayBuffer.data(), &QAction::triggered,
  4715. this, &OBSBasic::ReplayBufferClicked);
  4716. connect(exit, SIGNAL(triggered()),
  4717. this, SLOT(close()));
  4718. QMenu *previewProjector = new QMenu(QTStr("PreviewProjector"));
  4719. AddProjectorMenuMonitors(previewProjector, this,
  4720. SLOT(OpenPreviewProjector()));
  4721. QMenu *studioProgramProjector = new QMenu(
  4722. QTStr("StudioProgramProjector"));
  4723. AddProjectorMenuMonitors(studioProgramProjector, this,
  4724. SLOT(OpenStudioProgramProjector()));
  4725. trayMenu = new QMenu;
  4726. trayMenu->addAction(showHide);
  4727. trayMenu->addMenu(previewProjector);
  4728. trayMenu->addMenu(studioProgramProjector);
  4729. trayMenu->addAction(sysTrayStream);
  4730. trayMenu->addAction(sysTrayRecord);
  4731. trayMenu->addAction(sysTrayReplayBuffer);
  4732. trayMenu->addAction(exit);
  4733. trayIcon->setContextMenu(trayMenu);
  4734. }
  4735. void OBSBasic::IconActivated(QSystemTrayIcon::ActivationReason reason)
  4736. {
  4737. if (reason == QSystemTrayIcon::Trigger)
  4738. ToggleShowHide();
  4739. }
  4740. void OBSBasic::SysTrayNotify(const QString &text,
  4741. QSystemTrayIcon::MessageIcon n)
  4742. {
  4743. if (QSystemTrayIcon::supportsMessages()) {
  4744. QSystemTrayIcon::MessageIcon icon =
  4745. QSystemTrayIcon::MessageIcon(n);
  4746. trayIcon->showMessage("OBS Studio", text, icon, 10000);
  4747. }
  4748. }
  4749. void OBSBasic::SystemTray(bool firstStarted)
  4750. {
  4751. if (!QSystemTrayIcon::isSystemTrayAvailable())
  4752. return;
  4753. bool sysTrayWhenStarted = config_get_bool(GetGlobalConfig(),
  4754. "BasicWindow", "SysTrayWhenStarted");
  4755. bool sysTrayEnabled = config_get_bool(GetGlobalConfig(),
  4756. "BasicWindow", "SysTrayEnabled");
  4757. if (firstStarted)
  4758. SystemTrayInit();
  4759. if (!sysTrayWhenStarted && !sysTrayEnabled) {
  4760. trayIcon->hide();
  4761. } else if ((sysTrayWhenStarted && sysTrayEnabled)
  4762. || opt_minimize_tray) {
  4763. trayIcon->show();
  4764. if (firstStarted) {
  4765. QTimer::singleShot(50, this, SLOT(hide()));
  4766. EnablePreviewDisplay(false);
  4767. setVisible(false);
  4768. opt_minimize_tray = false;
  4769. }
  4770. } else if (sysTrayEnabled) {
  4771. trayIcon->show();
  4772. } else if (!sysTrayEnabled) {
  4773. trayIcon->hide();
  4774. } else if (!sysTrayWhenStarted && sysTrayEnabled) {
  4775. trayIcon->hide();
  4776. }
  4777. if (isVisible())
  4778. showHide->setText(QTStr("Basic.SystemTray.Hide"));
  4779. else
  4780. showHide->setText(QTStr("Basic.SystemTray.Show"));
  4781. }
  4782. bool OBSBasic::sysTrayMinimizeToTray()
  4783. {
  4784. return config_get_bool(GetGlobalConfig(),
  4785. "BasicWindow", "SysTrayMinimizeToTray");
  4786. }
  4787. void OBSBasic::on_actionCopySource_triggered()
  4788. {
  4789. on_actionCopyTransform_triggered();
  4790. OBSSceneItem item = GetCurrentSceneItem();
  4791. if (!item)
  4792. return;
  4793. OBSSource source = obs_sceneitem_get_source(item);
  4794. copyString = obs_source_get_name(source);
  4795. copyVisible = obs_sceneitem_visible(item);
  4796. ui->actionPasteRef->setEnabled(true);
  4797. uint32_t output_flags = obs_source_get_output_flags(source);
  4798. if ((output_flags & OBS_SOURCE_DO_NOT_DUPLICATE) == 0)
  4799. ui->actionPasteDup->setEnabled(true);
  4800. else
  4801. ui->actionPasteDup->setEnabled(false);
  4802. }
  4803. void OBSBasic::on_actionPasteRef_triggered()
  4804. {
  4805. OBSBasicSourceSelect::SourcePaste(copyString, copyVisible, false);
  4806. on_actionPasteTransform_triggered();
  4807. }
  4808. void OBSBasic::on_actionPasteDup_triggered()
  4809. {
  4810. OBSBasicSourceSelect::SourcePaste(copyString, copyVisible, true);
  4811. on_actionPasteTransform_triggered();
  4812. }
  4813. void OBSBasic::on_actionCopyFilters_triggered()
  4814. {
  4815. OBSSceneItem item = GetCurrentSceneItem();
  4816. if (!item)
  4817. return;
  4818. OBSSource source = obs_sceneitem_get_source(item);
  4819. copyFiltersString = obs_source_get_name(source);
  4820. ui->actionPasteFilters->setEnabled(true);
  4821. }
  4822. void OBSBasic::on_actionPasteFilters_triggered()
  4823. {
  4824. OBSSource source = obs_get_source_by_name(copyFiltersString);
  4825. OBSSceneItem sceneItem = GetCurrentSceneItem();
  4826. OBSSource dstSource = obs_sceneitem_get_source(sceneItem);
  4827. if (source == dstSource)
  4828. return;
  4829. obs_source_copy_filters(dstSource, source);
  4830. }
  4831. void OBSBasic::on_autoConfigure_triggered()
  4832. {
  4833. AutoConfig test(this);
  4834. test.setModal(true);
  4835. test.show();
  4836. test.exec();
  4837. }
  4838. void OBSBasic::on_stats_triggered()
  4839. {
  4840. if (!stats.isNull()) {
  4841. stats->show();
  4842. stats->raise();
  4843. return;
  4844. }
  4845. OBSBasicStats *statsDlg;
  4846. statsDlg = new OBSBasicStats(nullptr);
  4847. statsDlg->show();
  4848. stats = statsDlg;
  4849. }