window-basic-main.cpp 173 KB

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