window-basic-main.cpp 174 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672
  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 && loaded) {
  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. #ifndef __APPLE__
  1282. SystemTray(true);
  1283. #endif
  1284. if (windowState().testFlag(Qt::WindowFullScreen))
  1285. fullscreenInterface = true;
  1286. bool has_last_version = config_has_user_value(App()->GlobalConfig(),
  1287. "General", "LastVersion");
  1288. bool first_run = config_get_bool(App()->GlobalConfig(), "General",
  1289. "FirstRun");
  1290. if (!first_run) {
  1291. config_set_bool(App()->GlobalConfig(), "General", "FirstRun",
  1292. true);
  1293. config_save_safe(App()->GlobalConfig(), "tmp", nullptr);
  1294. }
  1295. if (!first_run && !has_last_version && !Active()) {
  1296. QString msg;
  1297. msg = QTStr("Basic.FirstStartup.RunWizard");
  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. /* Minimizng to tray on initial startup does not work on mac
  1389. * unless it is done in the deferred load */
  1390. SystemTray(true);
  1391. }
  1392. /* shows a "what's new" page on startup of new versions using CEF */
  1393. void OBSBasic::ReceivedIntroJson(const QString &text)
  1394. {
  1395. #ifdef _WIN32
  1396. std::string err;
  1397. Json json = Json::parse(QT_TO_UTF8(text), err);
  1398. if (!err.empty())
  1399. return;
  1400. std::string info_url;
  1401. int info_increment = -1;
  1402. /* check to see if there's an info page for this version */
  1403. const Json::array &items = json.array_items();
  1404. for (const Json &item : items) {
  1405. const std::string &version = item["version"].string_value();
  1406. const std::string &url = item["url"].string_value();
  1407. int increment = item["increment"].int_value();
  1408. int rc = item["RC"].int_value();
  1409. int major = 0;
  1410. int minor = 0;
  1411. sscanf(version.c_str(), "%d.%d", &major, &minor);
  1412. #if OBS_RELEASE_CANDIDATE > 0
  1413. if (major == OBS_RELEASE_CANDIDATE_MAJOR &&
  1414. minor == OBS_RELEASE_CANDIDATE_MINOR &&
  1415. rc == OBS_RELEASE_CANDIDATE) {
  1416. #else
  1417. if (major == LIBOBS_API_MAJOR_VER &&
  1418. minor == LIBOBS_API_MINOR_VER &&
  1419. rc == 0) {
  1420. #endif
  1421. info_url = url;
  1422. info_increment = increment;
  1423. }
  1424. }
  1425. /* this version was not found, or no info for this version */
  1426. if (info_increment == -1) {
  1427. return;
  1428. }
  1429. #if OBS_RELEASE_CANDIDATE > 0
  1430. uint32_t lastVersion = config_get_int(App()->GlobalConfig(), "General",
  1431. "LastRCVersion");
  1432. #else
  1433. uint32_t lastVersion = config_get_int(App()->GlobalConfig(), "General",
  1434. "LastVersion");
  1435. #endif
  1436. int current_version_increment = -1;
  1437. #if OBS_RELEASE_CANDIDATE > 0
  1438. if (lastVersion < OBS_RELEASE_CANDIDATE_VER) {
  1439. #else
  1440. if (lastVersion < LIBOBS_API_VER) {
  1441. #endif
  1442. config_set_int(App()->GlobalConfig(), "General",
  1443. "InfoIncrement", -1);
  1444. } else {
  1445. current_version_increment = config_get_int(
  1446. App()->GlobalConfig(), "General",
  1447. "InfoIncrement");
  1448. }
  1449. if (info_increment <= current_version_increment) {
  1450. return;
  1451. }
  1452. config_set_int(App()->GlobalConfig(), "General",
  1453. "InfoIncrement", info_increment);
  1454. QDialog dlg(this);
  1455. dlg.setWindowTitle("What's New");
  1456. dlg.resize(700, 600);
  1457. QCefWidget *cefWidget = create_browser_widget(nullptr, info_url);
  1458. if (!cefWidget) {
  1459. return;
  1460. }
  1461. connect(cefWidget, SIGNAL(titleChanged(const QString &)),
  1462. &dlg, SLOT(setWindowTitle(const QString &)));
  1463. QPushButton *close = new QPushButton(QTStr("Close"));
  1464. connect(close, &QAbstractButton::clicked,
  1465. &dlg, &QDialog::accept);
  1466. QHBoxLayout *bottomLayout = new QHBoxLayout();
  1467. bottomLayout->addStretch();
  1468. bottomLayout->addWidget(close);
  1469. bottomLayout->addStretch();
  1470. QVBoxLayout *topLayout = new QVBoxLayout(&dlg);
  1471. topLayout->addWidget(cefWidget);
  1472. topLayout->addLayout(bottomLayout);
  1473. dlg.exec();
  1474. #else
  1475. UNUSED_PARAMETER(text);
  1476. #endif
  1477. }
  1478. void OBSBasic::UpdateMultiviewProjectorMenu()
  1479. {
  1480. multiviewProjectorMenu->clear();
  1481. AddProjectorMenuMonitors(multiviewProjectorMenu, this,
  1482. SLOT(OpenMultiviewProjector()));
  1483. }
  1484. void OBSBasic::InitHotkeys()
  1485. {
  1486. ProfileScope("OBSBasic::InitHotkeys");
  1487. struct obs_hotkeys_translations t = {};
  1488. t.insert = Str("Hotkeys.Insert");
  1489. t.del = Str("Hotkeys.Delete");
  1490. t.home = Str("Hotkeys.Home");
  1491. t.end = Str("Hotkeys.End");
  1492. t.page_up = Str("Hotkeys.PageUp");
  1493. t.page_down = Str("Hotkeys.PageDown");
  1494. t.num_lock = Str("Hotkeys.NumLock");
  1495. t.scroll_lock = Str("Hotkeys.ScrollLock");
  1496. t.caps_lock = Str("Hotkeys.CapsLock");
  1497. t.backspace = Str("Hotkeys.Backspace");
  1498. t.tab = Str("Hotkeys.Tab");
  1499. t.print = Str("Hotkeys.Print");
  1500. t.pause = Str("Hotkeys.Pause");
  1501. t.left = Str("Hotkeys.Left");
  1502. t.right = Str("Hotkeys.Right");
  1503. t.up = Str("Hotkeys.Up");
  1504. t.down = Str("Hotkeys.Down");
  1505. #ifdef _WIN32
  1506. t.meta = Str("Hotkeys.Windows");
  1507. #else
  1508. t.meta = Str("Hotkeys.Super");
  1509. #endif
  1510. t.menu = Str("Hotkeys.Menu");
  1511. t.space = Str("Hotkeys.Space");
  1512. t.numpad_num = Str("Hotkeys.NumpadNum");
  1513. t.numpad_multiply = Str("Hotkeys.NumpadMultiply");
  1514. t.numpad_divide = Str("Hotkeys.NumpadDivide");
  1515. t.numpad_plus = Str("Hotkeys.NumpadAdd");
  1516. t.numpad_minus = Str("Hotkeys.NumpadSubtract");
  1517. t.numpad_decimal = Str("Hotkeys.NumpadDecimal");
  1518. t.apple_keypad_num = Str("Hotkeys.AppleKeypadNum");
  1519. t.apple_keypad_multiply = Str("Hotkeys.AppleKeypadMultiply");
  1520. t.apple_keypad_divide = Str("Hotkeys.AppleKeypadDivide");
  1521. t.apple_keypad_plus = Str("Hotkeys.AppleKeypadAdd");
  1522. t.apple_keypad_minus = Str("Hotkeys.AppleKeypadSubtract");
  1523. t.apple_keypad_decimal = Str("Hotkeys.AppleKeypadDecimal");
  1524. t.apple_keypad_equal = Str("Hotkeys.AppleKeypadEqual");
  1525. t.mouse_num = Str("Hotkeys.MouseButton");
  1526. obs_hotkeys_set_translations(&t);
  1527. obs_hotkeys_set_audio_hotkeys_translations(Str("Mute"), Str("Unmute"),
  1528. Str("Push-to-mute"), Str("Push-to-talk"));
  1529. obs_hotkeys_set_sceneitem_hotkeys_translations(
  1530. Str("SceneItemShow"), Str("SceneItemHide"));
  1531. obs_hotkey_enable_callback_rerouting(true);
  1532. obs_hotkey_set_callback_routing_func(OBSBasic::HotkeyTriggered, this);
  1533. }
  1534. void OBSBasic::ProcessHotkey(obs_hotkey_id id, bool pressed)
  1535. {
  1536. obs_hotkey_trigger_routed_callback(id, pressed);
  1537. }
  1538. void OBSBasic::HotkeyTriggered(void *data, obs_hotkey_id id, bool pressed)
  1539. {
  1540. OBSBasic &basic = *static_cast<OBSBasic*>(data);
  1541. QMetaObject::invokeMethod(&basic, "ProcessHotkey",
  1542. Q_ARG(obs_hotkey_id, id), Q_ARG(bool, pressed));
  1543. }
  1544. void OBSBasic::CreateHotkeys()
  1545. {
  1546. ProfileScope("OBSBasic::CreateHotkeys");
  1547. auto LoadHotkeyData = [&](const char *name) -> OBSData
  1548. {
  1549. const char *info = config_get_string(basicConfig,
  1550. "Hotkeys", name);
  1551. if (!info)
  1552. return {};
  1553. obs_data_t *data = obs_data_create_from_json(info);
  1554. if (!data)
  1555. return {};
  1556. OBSData res = data;
  1557. obs_data_release(data);
  1558. return res;
  1559. };
  1560. auto LoadHotkey = [&](obs_hotkey_id id, const char *name)
  1561. {
  1562. obs_data_array_t *array =
  1563. obs_data_get_array(LoadHotkeyData(name), "bindings");
  1564. obs_hotkey_load(id, array);
  1565. obs_data_array_release(array);
  1566. };
  1567. auto LoadHotkeyPair = [&](obs_hotkey_pair_id id, const char *name0,
  1568. const char *name1)
  1569. {
  1570. obs_data_array_t *array0 =
  1571. obs_data_get_array(LoadHotkeyData(name0), "bindings");
  1572. obs_data_array_t *array1 =
  1573. obs_data_get_array(LoadHotkeyData(name1), "bindings");
  1574. obs_hotkey_pair_load(id, array0, array1);
  1575. obs_data_array_release(array0);
  1576. obs_data_array_release(array1);
  1577. };
  1578. #define MAKE_CALLBACK(pred, method, log_action) \
  1579. [](void *data, obs_hotkey_pair_id, obs_hotkey_t*, bool pressed) \
  1580. { \
  1581. OBSBasic &basic = *static_cast<OBSBasic*>(data); \
  1582. if ((pred) && pressed) { \
  1583. blog(LOG_INFO, log_action " due to hotkey"); \
  1584. method(); \
  1585. return true; \
  1586. } \
  1587. return false; \
  1588. }
  1589. streamingHotkeys = obs_hotkey_pair_register_frontend(
  1590. "OBSBasic.StartStreaming",
  1591. Str("Basic.Main.StartStreaming"),
  1592. "OBSBasic.StopStreaming",
  1593. Str("Basic.Main.StopStreaming"),
  1594. MAKE_CALLBACK(!basic.outputHandler->StreamingActive() &&
  1595. basic.ui->streamButton->isEnabled(),
  1596. basic.StartStreaming, "Starting stream"),
  1597. MAKE_CALLBACK(basic.outputHandler->StreamingActive() &&
  1598. basic.ui->streamButton->isEnabled(),
  1599. basic.StopStreaming, "Stopping stream"),
  1600. this, this);
  1601. LoadHotkeyPair(streamingHotkeys,
  1602. "OBSBasic.StartStreaming", "OBSBasic.StopStreaming");
  1603. auto cb = [] (void *data, obs_hotkey_id, obs_hotkey_t*, bool pressed)
  1604. {
  1605. OBSBasic &basic = *static_cast<OBSBasic*>(data);
  1606. if (basic.outputHandler->StreamingActive() && pressed) {
  1607. basic.ForceStopStreaming();
  1608. }
  1609. };
  1610. forceStreamingStopHotkey = obs_hotkey_register_frontend(
  1611. "OBSBasic.ForceStopStreaming",
  1612. Str("Basic.Main.ForceStopStreaming"),
  1613. cb, this);
  1614. LoadHotkey(forceStreamingStopHotkey,
  1615. "OBSBasic.ForceStopStreaming");
  1616. recordingHotkeys = obs_hotkey_pair_register_frontend(
  1617. "OBSBasic.StartRecording",
  1618. Str("Basic.Main.StartRecording"),
  1619. "OBSBasic.StopRecording",
  1620. Str("Basic.Main.StopRecording"),
  1621. MAKE_CALLBACK(!basic.outputHandler->RecordingActive() &&
  1622. !basic.ui->recordButton->isChecked(),
  1623. basic.StartRecording, "Starting recording"),
  1624. MAKE_CALLBACK(basic.outputHandler->RecordingActive() &&
  1625. basic.ui->recordButton->isChecked(),
  1626. basic.StopRecording, "Stopping recording"),
  1627. this, this);
  1628. LoadHotkeyPair(recordingHotkeys,
  1629. "OBSBasic.StartRecording", "OBSBasic.StopRecording");
  1630. replayBufHotkeys = obs_hotkey_pair_register_frontend(
  1631. "OBSBasic.StartReplayBuffer",
  1632. Str("Basic.Main.StartReplayBuffer"),
  1633. "OBSBasic.StopReplayBuffer",
  1634. Str("Basic.Main.StopReplayBuffer"),
  1635. MAKE_CALLBACK(!basic.outputHandler->ReplayBufferActive(),
  1636. basic.StartReplayBuffer, "Starting replay buffer"),
  1637. MAKE_CALLBACK(basic.outputHandler->ReplayBufferActive(),
  1638. basic.StopReplayBuffer, "Stopping replay buffer"),
  1639. this, this);
  1640. LoadHotkeyPair(replayBufHotkeys,
  1641. "OBSBasic.StartReplayBuffer", "OBSBasic.StopReplayBuffer");
  1642. #undef MAKE_CALLBACK
  1643. auto togglePreviewProgram = [] (void *data, obs_hotkey_id,
  1644. obs_hotkey_t*, bool pressed)
  1645. {
  1646. if (pressed)
  1647. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  1648. "on_modeSwitch_clicked",
  1649. Qt::QueuedConnection);
  1650. };
  1651. togglePreviewProgramHotkey = obs_hotkey_register_frontend(
  1652. "OBSBasic.TogglePreviewProgram",
  1653. Str("Basic.TogglePreviewProgramMode"),
  1654. togglePreviewProgram, this);
  1655. LoadHotkey(togglePreviewProgramHotkey, "OBSBasic.TogglePreviewProgram");
  1656. auto transition = [] (void *data, obs_hotkey_id, obs_hotkey_t*,
  1657. bool pressed)
  1658. {
  1659. if (pressed)
  1660. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  1661. "TransitionClicked",
  1662. Qt::QueuedConnection);
  1663. };
  1664. transitionHotkey = obs_hotkey_register_frontend(
  1665. "OBSBasic.Transition",
  1666. Str("Transition"), transition, this);
  1667. LoadHotkey(transitionHotkey, "OBSBasic.Transition");
  1668. }
  1669. void OBSBasic::ClearHotkeys()
  1670. {
  1671. obs_hotkey_pair_unregister(streamingHotkeys);
  1672. obs_hotkey_pair_unregister(recordingHotkeys);
  1673. obs_hotkey_pair_unregister(replayBufHotkeys);
  1674. obs_hotkey_unregister(forceStreamingStopHotkey);
  1675. obs_hotkey_unregister(togglePreviewProgramHotkey);
  1676. obs_hotkey_unregister(transitionHotkey);
  1677. }
  1678. OBSBasic::~OBSBasic()
  1679. {
  1680. if (updateCheckThread && updateCheckThread->isRunning())
  1681. updateCheckThread->wait();
  1682. delete multiviewProjectorMenu;
  1683. delete trayMenu;
  1684. delete programOptions;
  1685. delete program;
  1686. /* XXX: any obs data must be released before calling obs_shutdown.
  1687. * currently, we can't automate this with C++ RAII because of the
  1688. * delicate nature of obs_shutdown needing to be freed before the UI
  1689. * can be freed, and we have no control over the destruction order of
  1690. * the Qt UI stuff, so we have to manually clear any references to
  1691. * libobs. */
  1692. delete cpuUsageTimer;
  1693. os_cpu_usage_info_destroy(cpuUsageInfo);
  1694. obs_hotkey_set_callback_routing_func(nullptr, nullptr);
  1695. ClearHotkeys();
  1696. service = nullptr;
  1697. outputHandler.reset();
  1698. if (interaction)
  1699. delete interaction;
  1700. if (properties)
  1701. delete properties;
  1702. if (filters)
  1703. delete filters;
  1704. if (transformWindow)
  1705. delete transformWindow;
  1706. if (advAudioWindow)
  1707. delete advAudioWindow;
  1708. obs_display_remove_draw_callback(ui->preview->GetDisplay(),
  1709. OBSBasic::RenderMain, this);
  1710. obs_enter_graphics();
  1711. gs_vertexbuffer_destroy(box);
  1712. gs_vertexbuffer_destroy(boxLeft);
  1713. gs_vertexbuffer_destroy(boxTop);
  1714. gs_vertexbuffer_destroy(boxRight);
  1715. gs_vertexbuffer_destroy(boxBottom);
  1716. gs_vertexbuffer_destroy(circle);
  1717. obs_leave_graphics();
  1718. /* When shutting down, sometimes source references can get in to the
  1719. * event queue, and if we don't forcibly process those events they
  1720. * won't get processed until after obs_shutdown has been called. I
  1721. * really wish there were a more elegant way to deal with this via C++,
  1722. * but Qt doesn't use C++ in a normal way, so you can't really rely on
  1723. * normal C++ behavior for your data to be freed in the order that you
  1724. * expect or want it to. */
  1725. QApplication::sendPostedEvents(this);
  1726. config_set_int(App()->GlobalConfig(), "General", "LastVersion",
  1727. LIBOBS_API_VER);
  1728. #if OBS_RELEASE_CANDIDATE > 0
  1729. config_set_int(App()->GlobalConfig(), "General", "LastRCVersion",
  1730. OBS_RELEASE_CANDIDATE_VER);
  1731. #endif
  1732. bool alwaysOnTop = IsAlwaysOnTop(this);
  1733. config_set_bool(App()->GlobalConfig(), "BasicWindow", "PreviewEnabled",
  1734. previewEnabled);
  1735. config_set_bool(App()->GlobalConfig(), "BasicWindow", "AlwaysOnTop",
  1736. alwaysOnTop);
  1737. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  1738. "SceneDuplicationMode", sceneDuplicationMode);
  1739. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  1740. "SwapScenesMode", swapScenesMode);
  1741. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  1742. "EditPropertiesMode", editPropertiesMode);
  1743. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  1744. "PreviewProgramMode", IsPreviewProgramMode());
  1745. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  1746. "DocksLocked", ui->lockUI->isChecked());
  1747. config_save_safe(App()->GlobalConfig(), "tmp", nullptr);
  1748. #ifdef _WIN32
  1749. uint32_t winVer = GetWindowsVersion();
  1750. if (winVer > 0 && winVer < 0x602) {
  1751. bool disableAero = config_get_bool(basicConfig, "Video",
  1752. "DisableAero");
  1753. if (disableAero) {
  1754. SetAeroEnabled(true);
  1755. }
  1756. }
  1757. #endif
  1758. }
  1759. void OBSBasic::SaveProjectNow()
  1760. {
  1761. if (disableSaving)
  1762. return;
  1763. projectChanged = true;
  1764. SaveProjectDeferred();
  1765. }
  1766. void OBSBasic::SaveProject()
  1767. {
  1768. if (disableSaving)
  1769. return;
  1770. projectChanged = true;
  1771. QMetaObject::invokeMethod(this, "SaveProjectDeferred",
  1772. Qt::QueuedConnection);
  1773. }
  1774. void OBSBasic::SaveProjectDeferred()
  1775. {
  1776. if (disableSaving)
  1777. return;
  1778. if (!projectChanged)
  1779. return;
  1780. projectChanged = false;
  1781. const char *sceneCollection = config_get_string(App()->GlobalConfig(),
  1782. "Basic", "SceneCollectionFile");
  1783. char savePath[512];
  1784. char fileName[512];
  1785. int ret;
  1786. if (!sceneCollection)
  1787. return;
  1788. ret = snprintf(fileName, 512, "obs-studio/basic/scenes/%s.json",
  1789. sceneCollection);
  1790. if (ret <= 0)
  1791. return;
  1792. ret = GetConfigPath(savePath, sizeof(savePath), fileName);
  1793. if (ret <= 0)
  1794. return;
  1795. Save(savePath);
  1796. }
  1797. OBSSource OBSBasic::GetProgramSource()
  1798. {
  1799. return OBSGetStrongRef(programScene);
  1800. }
  1801. OBSScene OBSBasic::GetCurrentScene()
  1802. {
  1803. QListWidgetItem *item = ui->scenes->currentItem();
  1804. return item ? GetOBSRef<OBSScene>(item) : nullptr;
  1805. }
  1806. OBSSceneItem OBSBasic::GetSceneItem(QListWidgetItem *item)
  1807. {
  1808. return item ? GetOBSRef<OBSSceneItem>(item) : nullptr;
  1809. }
  1810. OBSSceneItem OBSBasic::GetCurrentSceneItem()
  1811. {
  1812. return ui->sources->Get(GetTopSelectedSourceItem());
  1813. }
  1814. void OBSBasic::UpdatePreviewScalingMenu()
  1815. {
  1816. bool fixedScaling = ui->preview->IsFixedScaling();
  1817. float scalingAmount = ui->preview->GetScalingAmount();
  1818. if (!fixedScaling) {
  1819. ui->actionScaleWindow->setChecked(true);
  1820. ui->actionScaleCanvas->setChecked(false);
  1821. ui->actionScaleOutput->setChecked(false);
  1822. return;
  1823. }
  1824. obs_video_info ovi;
  1825. obs_get_video_info(&ovi);
  1826. ui->actionScaleWindow->setChecked(false);
  1827. ui->actionScaleCanvas->setChecked(scalingAmount == 1.0f);
  1828. ui->actionScaleOutput->setChecked(
  1829. scalingAmount == float(ovi.output_width) / float(ovi.base_width));
  1830. }
  1831. void OBSBasic::CreateInteractionWindow(obs_source_t *source)
  1832. {
  1833. if (interaction)
  1834. interaction->close();
  1835. interaction = new OBSBasicInteraction(this, source);
  1836. interaction->Init();
  1837. interaction->setAttribute(Qt::WA_DeleteOnClose, true);
  1838. }
  1839. void OBSBasic::CreatePropertiesWindow(obs_source_t *source)
  1840. {
  1841. if (properties)
  1842. properties->close();
  1843. properties = new OBSBasicProperties(this, source);
  1844. properties->Init();
  1845. properties->setAttribute(Qt::WA_DeleteOnClose, true);
  1846. }
  1847. void OBSBasic::CreateFiltersWindow(obs_source_t *source)
  1848. {
  1849. if (filters)
  1850. filters->close();
  1851. filters = new OBSBasicFilters(this, source);
  1852. filters->Init();
  1853. filters->setAttribute(Qt::WA_DeleteOnClose, true);
  1854. }
  1855. /* Qt callbacks for invokeMethod */
  1856. void OBSBasic::AddScene(OBSSource source)
  1857. {
  1858. const char *name = obs_source_get_name(source);
  1859. obs_scene_t *scene = obs_scene_from_source(source);
  1860. QListWidgetItem *item = new QListWidgetItem(QT_UTF8(name));
  1861. SetOBSRef(item, OBSScene(scene));
  1862. ui->scenes->addItem(item);
  1863. obs_hotkey_register_source(source, "OBSBasic.SelectScene",
  1864. Str("Basic.Hotkeys.SelectScene"),
  1865. [](void *data,
  1866. obs_hotkey_id, obs_hotkey_t*, bool pressed)
  1867. {
  1868. OBSBasic *main =
  1869. reinterpret_cast<OBSBasic*>(App()->GetMainWindow());
  1870. auto potential_source = static_cast<obs_source_t*>(data);
  1871. auto source = obs_source_get_ref(potential_source);
  1872. if (source && pressed)
  1873. main->SetCurrentScene(source);
  1874. obs_source_release(source);
  1875. }, static_cast<obs_source_t*>(source));
  1876. signal_handler_t *handler = obs_source_get_signal_handler(source);
  1877. SignalContainer<OBSScene> container;
  1878. container.ref = scene;
  1879. container.handlers.assign({
  1880. std::make_shared<OBSSignal>(handler, "item_add",
  1881. OBSBasic::SceneItemAdded, this),
  1882. std::make_shared<OBSSignal>(handler, "item_select",
  1883. OBSBasic::SceneItemSelected, this),
  1884. std::make_shared<OBSSignal>(handler, "item_deselect",
  1885. OBSBasic::SceneItemDeselected, this),
  1886. std::make_shared<OBSSignal>(handler, "reorder",
  1887. OBSBasic::SceneReordered, this),
  1888. });
  1889. item->setData(static_cast<int>(QtDataRole::OBSSignals),
  1890. QVariant::fromValue(container));
  1891. /* if the scene already has items (a duplicated scene) add them */
  1892. auto addSceneItem = [this] (obs_sceneitem_t *item)
  1893. {
  1894. AddSceneItem(item);
  1895. };
  1896. using addSceneItem_t = decltype(addSceneItem);
  1897. obs_scene_enum_items(scene,
  1898. [] (obs_scene_t*, obs_sceneitem_t *item, void *param)
  1899. {
  1900. addSceneItem_t *func;
  1901. func = reinterpret_cast<addSceneItem_t*>(param);
  1902. (*func)(item);
  1903. return true;
  1904. }, &addSceneItem);
  1905. SaveProject();
  1906. if (!disableSaving) {
  1907. obs_source_t *source = obs_scene_get_source(scene);
  1908. blog(LOG_INFO, "User added scene '%s'",
  1909. obs_source_get_name(source));
  1910. OBSProjector::UpdateMultiviewProjectors();
  1911. }
  1912. if (api)
  1913. api->on_event(OBS_FRONTEND_EVENT_SCENE_LIST_CHANGED);
  1914. }
  1915. void OBSBasic::RemoveScene(OBSSource source)
  1916. {
  1917. obs_scene_t *scene = obs_scene_from_source(source);
  1918. QListWidgetItem *sel = nullptr;
  1919. int count = ui->scenes->count();
  1920. for (int i = 0; i < count; i++) {
  1921. auto item = ui->scenes->item(i);
  1922. auto cur_scene = GetOBSRef<OBSScene>(item);
  1923. if (cur_scene != scene)
  1924. continue;
  1925. sel = item;
  1926. break;
  1927. }
  1928. if (sel != nullptr) {
  1929. if (sel == ui->scenes->currentItem())
  1930. ui->sources->Clear();
  1931. delete sel;
  1932. }
  1933. SaveProject();
  1934. if (!disableSaving) {
  1935. blog(LOG_INFO, "User Removed scene '%s'",
  1936. obs_source_get_name(source));
  1937. OBSProjector::UpdateMultiviewProjectors();
  1938. }
  1939. if (api)
  1940. api->on_event(OBS_FRONTEND_EVENT_SCENE_LIST_CHANGED);
  1941. }
  1942. static bool select_one(obs_scene_t *scene, obs_sceneitem_t *item, void *param)
  1943. {
  1944. obs_sceneitem_t *selectedItem =
  1945. reinterpret_cast<obs_sceneitem_t*>(param);
  1946. if (obs_sceneitem_is_group(item))
  1947. obs_sceneitem_group_enum_items(item, select_one, param);
  1948. obs_sceneitem_select(item, (selectedItem == item));
  1949. UNUSED_PARAMETER(scene);
  1950. return true;
  1951. }
  1952. void OBSBasic::AddSceneItem(OBSSceneItem item)
  1953. {
  1954. obs_scene_t *scene = obs_sceneitem_get_scene(item);
  1955. if (GetCurrentScene() == scene)
  1956. ui->sources->Add(item);
  1957. SaveProject();
  1958. if (!disableSaving) {
  1959. obs_source_t *sceneSource = obs_scene_get_source(scene);
  1960. obs_source_t *itemSource = obs_sceneitem_get_source(item);
  1961. blog(LOG_INFO, "User added source '%s' (%s) to scene '%s'",
  1962. obs_source_get_name(itemSource),
  1963. obs_source_get_id(itemSource),
  1964. obs_source_get_name(sceneSource));
  1965. obs_scene_enum_items(scene, select_one, (obs_sceneitem_t*)item);
  1966. }
  1967. }
  1968. void OBSBasic::UpdateSceneSelection(OBSSource source)
  1969. {
  1970. if (source) {
  1971. obs_scene_t *scene = obs_scene_from_source(source);
  1972. const char *name = obs_source_get_name(source);
  1973. if (!scene)
  1974. return;
  1975. QList<QListWidgetItem*> items =
  1976. ui->scenes->findItems(QT_UTF8(name), Qt::MatchExactly);
  1977. if (items.count()) {
  1978. sceneChanging = true;
  1979. ui->scenes->setCurrentItem(items.first());
  1980. sceneChanging = false;
  1981. OBSScene curScene =
  1982. GetOBSRef<OBSScene>(ui->scenes->currentItem());
  1983. if (api && scene != curScene)
  1984. api->on_event(OBS_FRONTEND_EVENT_PREVIEW_SCENE_CHANGED);
  1985. }
  1986. }
  1987. }
  1988. static void RenameListValues(QListWidget *listWidget, const QString &newName,
  1989. const QString &prevName)
  1990. {
  1991. QList<QListWidgetItem*> items =
  1992. listWidget->findItems(prevName, Qt::MatchExactly);
  1993. for (int i = 0; i < items.count(); i++)
  1994. items[i]->setText(newName);
  1995. }
  1996. void OBSBasic::RenameSources(OBSSource source, QString newName,
  1997. QString prevName)
  1998. {
  1999. RenameListValues(ui->scenes, newName, prevName);
  2000. for (size_t i = 0; i < volumes.size(); i++) {
  2001. if (volumes[i]->GetName().compare(prevName) == 0)
  2002. volumes[i]->SetName(newName);
  2003. }
  2004. OBSProjector::RenameProjector(prevName, newName);
  2005. SaveProject();
  2006. obs_scene_t *scene = obs_scene_from_source(source);
  2007. if (scene)
  2008. OBSProjector::UpdateMultiviewProjectors();
  2009. }
  2010. void OBSBasic::SelectSceneItem(OBSScene scene, OBSSceneItem item, bool select)
  2011. {
  2012. SignalBlocker sourcesSignalBlocker(ui->sources);
  2013. if (scene != GetCurrentScene() || ignoreSelectionUpdate)
  2014. return;
  2015. ui->sources->SelectItem(item, select);
  2016. }
  2017. static inline bool SourceMixerHidden(obs_source_t *source)
  2018. {
  2019. obs_data_t *priv_settings = obs_source_get_private_settings(source);
  2020. bool hidden = obs_data_get_bool(priv_settings, "mixer_hidden");
  2021. obs_data_release(priv_settings);
  2022. return hidden;
  2023. }
  2024. static inline void SetSourceMixerHidden(obs_source_t *source, bool hidden)
  2025. {
  2026. obs_data_t *priv_settings = obs_source_get_private_settings(source);
  2027. obs_data_set_bool(priv_settings, "mixer_hidden", hidden);
  2028. obs_data_release(priv_settings);
  2029. }
  2030. void OBSBasic::GetAudioSourceFilters()
  2031. {
  2032. QAction *action = reinterpret_cast<QAction*>(sender());
  2033. VolControl *vol = action->property("volControl").value<VolControl*>();
  2034. obs_source_t *source = vol->GetSource();
  2035. CreateFiltersWindow(source);
  2036. }
  2037. void OBSBasic::GetAudioSourceProperties()
  2038. {
  2039. QAction *action = reinterpret_cast<QAction*>(sender());
  2040. VolControl *vol = action->property("volControl").value<VolControl*>();
  2041. obs_source_t *source = vol->GetSource();
  2042. CreatePropertiesWindow(source);
  2043. }
  2044. void OBSBasic::HideAudioControl()
  2045. {
  2046. QAction *action = reinterpret_cast<QAction*>(sender());
  2047. VolControl *vol = action->property("volControl").value<VolControl*>();
  2048. obs_source_t *source = vol->GetSource();
  2049. if (!SourceMixerHidden(source)) {
  2050. SetSourceMixerHidden(source, true);
  2051. DeactivateAudioSource(source);
  2052. }
  2053. }
  2054. void OBSBasic::UnhideAllAudioControls()
  2055. {
  2056. auto UnhideAudioMixer = [this] (obs_source_t *source) /* -- */
  2057. {
  2058. if (!obs_source_active(source))
  2059. return true;
  2060. if (!SourceMixerHidden(source))
  2061. return true;
  2062. SetSourceMixerHidden(source, false);
  2063. ActivateAudioSource(source);
  2064. return true;
  2065. };
  2066. using UnhideAudioMixer_t = decltype(UnhideAudioMixer);
  2067. auto PreEnum = [] (void *data, obs_source_t *source) -> bool /* -- */
  2068. {
  2069. return (*reinterpret_cast<UnhideAudioMixer_t *>(data))(source);
  2070. };
  2071. obs_enum_sources(PreEnum, &UnhideAudioMixer);
  2072. }
  2073. void OBSBasic::ToggleHideMixer()
  2074. {
  2075. OBSSceneItem item = GetCurrentSceneItem();
  2076. OBSSource source = obs_sceneitem_get_source(item);
  2077. if (!SourceMixerHidden(source)) {
  2078. SetSourceMixerHidden(source, true);
  2079. DeactivateAudioSource(source);
  2080. } else {
  2081. SetSourceMixerHidden(source, false);
  2082. ActivateAudioSource(source);
  2083. }
  2084. }
  2085. void OBSBasic::MixerRenameSource()
  2086. {
  2087. QAction *action = reinterpret_cast<QAction*>(sender());
  2088. VolControl *vol = action->property("volControl").value<VolControl*>();
  2089. OBSSource source = vol->GetSource();
  2090. const char *prevName = obs_source_get_name(source);
  2091. for (;;) {
  2092. string name;
  2093. bool accepted = NameDialog::AskForName(this,
  2094. QTStr("Basic.Main.MixerRename.Title"),
  2095. QTStr("Basic.Main.MixerRename.Text"),
  2096. name,
  2097. QT_UTF8(prevName));
  2098. if (!accepted)
  2099. return;
  2100. if (name.empty()) {
  2101. OBSMessageBox::information(this,
  2102. QTStr("NoNameEntered.Title"),
  2103. QTStr("NoNameEntered.Text"));
  2104. continue;
  2105. }
  2106. OBSSource sourceTest = obs_get_source_by_name(name.c_str());
  2107. obs_source_release(sourceTest);
  2108. if (sourceTest) {
  2109. OBSMessageBox::information(this,
  2110. QTStr("NameExists.Title"),
  2111. QTStr("NameExists.Text"));
  2112. continue;
  2113. }
  2114. obs_source_set_name(source, name.c_str());
  2115. break;
  2116. }
  2117. }
  2118. void OBSBasic::VolControlContextMenu()
  2119. {
  2120. VolControl *vol = reinterpret_cast<VolControl*>(sender());
  2121. /* ------------------- */
  2122. QAction hideAction(QTStr("Hide"), this);
  2123. QAction unhideAllAction(QTStr("UnhideAll"), this);
  2124. QAction mixerRenameAction(QTStr("Rename"), this);
  2125. QAction filtersAction(QTStr("Filters"), this);
  2126. QAction propertiesAction(QTStr("Properties"), this);
  2127. QAction advPropAction(QTStr("Basic.MainMenu.Edit.AdvAudio"), this);
  2128. QAction toggleControlLayoutAction(QTStr("VerticalLayout"), this);
  2129. toggleControlLayoutAction.setCheckable(true);
  2130. toggleControlLayoutAction.setChecked(config_get_bool(GetGlobalConfig(),
  2131. "BasicWindow", "VerticalVolControl"));
  2132. /* ------------------- */
  2133. connect(&hideAction, &QAction::triggered,
  2134. this, &OBSBasic::HideAudioControl,
  2135. Qt::DirectConnection);
  2136. connect(&unhideAllAction, &QAction::triggered,
  2137. this, &OBSBasic::UnhideAllAudioControls,
  2138. Qt::DirectConnection);
  2139. connect(&mixerRenameAction, &QAction::triggered,
  2140. this, &OBSBasic::MixerRenameSource,
  2141. Qt::DirectConnection);
  2142. connect(&filtersAction, &QAction::triggered,
  2143. this, &OBSBasic::GetAudioSourceFilters,
  2144. Qt::DirectConnection);
  2145. connect(&propertiesAction, &QAction::triggered,
  2146. this, &OBSBasic::GetAudioSourceProperties,
  2147. Qt::DirectConnection);
  2148. connect(&advPropAction, &QAction::triggered,
  2149. this, &OBSBasic::on_actionAdvAudioProperties_triggered,
  2150. Qt::DirectConnection);
  2151. /* ------------------- */
  2152. connect(&toggleControlLayoutAction, &QAction::changed, this,
  2153. &OBSBasic::ToggleVolControlLayout,
  2154. Qt::DirectConnection);
  2155. /* ------------------- */
  2156. hideAction.setProperty("volControl",
  2157. QVariant::fromValue<VolControl*>(vol));
  2158. mixerRenameAction.setProperty("volControl",
  2159. QVariant::fromValue<VolControl*>(vol));
  2160. filtersAction.setProperty("volControl",
  2161. QVariant::fromValue<VolControl*>(vol));
  2162. propertiesAction.setProperty("volControl",
  2163. QVariant::fromValue<VolControl*>(vol));
  2164. /* ------------------- */
  2165. QMenu popup;
  2166. popup.addAction(&unhideAllAction);
  2167. popup.addAction(&hideAction);
  2168. popup.addAction(&mixerRenameAction);
  2169. popup.addSeparator();
  2170. popup.addAction(&toggleControlLayoutAction);
  2171. popup.addSeparator();
  2172. popup.addAction(&filtersAction);
  2173. popup.addAction(&propertiesAction);
  2174. popup.addAction(&advPropAction);
  2175. popup.exec(QCursor::pos());
  2176. }
  2177. void OBSBasic::on_hMixerScrollArea_customContextMenuRequested()
  2178. {
  2179. StackedMixerAreaContextMenuRequested();
  2180. }
  2181. void OBSBasic::on_vMixerScrollArea_customContextMenuRequested()
  2182. {
  2183. StackedMixerAreaContextMenuRequested();
  2184. }
  2185. void OBSBasic::StackedMixerAreaContextMenuRequested()
  2186. {
  2187. QAction unhideAllAction(QTStr("UnhideAll"), this);
  2188. QAction advPropAction(QTStr("Basic.MainMenu.Edit.AdvAudio"), this);
  2189. QAction toggleControlLayoutAction(QTStr("VerticalLayout"), this);
  2190. toggleControlLayoutAction.setCheckable(true);
  2191. toggleControlLayoutAction.setChecked(config_get_bool(GetGlobalConfig(),
  2192. "BasicWindow", "VerticalVolControl"));
  2193. /* ------------------- */
  2194. connect(&unhideAllAction, &QAction::triggered,
  2195. this, &OBSBasic::UnhideAllAudioControls,
  2196. Qt::DirectConnection);
  2197. connect(&advPropAction, &QAction::triggered,
  2198. this, &OBSBasic::on_actionAdvAudioProperties_triggered,
  2199. Qt::DirectConnection);
  2200. /* ------------------- */
  2201. connect(&toggleControlLayoutAction, &QAction::changed, this,
  2202. &OBSBasic::ToggleVolControlLayout,
  2203. Qt::DirectConnection);
  2204. /* ------------------- */
  2205. QMenu popup;
  2206. popup.addAction(&unhideAllAction);
  2207. popup.addSeparator();
  2208. popup.addAction(&toggleControlLayoutAction);
  2209. popup.addSeparator();
  2210. popup.addAction(&advPropAction);
  2211. popup.exec(QCursor::pos());
  2212. }
  2213. void OBSBasic::ToggleMixerLayout(bool vertical)
  2214. {
  2215. if (vertical) {
  2216. ui->stackedMixerArea->setMinimumSize(180, 220);
  2217. ui->stackedMixerArea->setCurrentIndex(1);
  2218. } else {
  2219. ui->stackedMixerArea->setMinimumSize(220, 0);
  2220. ui->stackedMixerArea->setCurrentIndex(0);
  2221. }
  2222. }
  2223. void OBSBasic::ToggleVolControlLayout()
  2224. {
  2225. bool vertical = !config_get_bool(GetGlobalConfig(), "BasicWindow",
  2226. "VerticalVolControl");
  2227. config_set_bool(GetGlobalConfig(), "BasicWindow", "VerticalVolControl",
  2228. vertical);
  2229. ToggleMixerLayout(vertical);
  2230. // We need to store it so we can delete current and then add
  2231. // at the right order
  2232. vector<OBSSource> sources;
  2233. for (size_t i = 0; i != volumes.size(); i++)
  2234. sources.emplace_back(volumes[i]->GetSource());
  2235. ClearVolumeControls();
  2236. for (const auto &source : sources)
  2237. ActivateAudioSource(source);
  2238. }
  2239. void OBSBasic::ActivateAudioSource(OBSSource source)
  2240. {
  2241. if (SourceMixerHidden(source))
  2242. return;
  2243. bool vertical = config_get_bool(GetGlobalConfig(), "BasicWindow",
  2244. "VerticalVolControl");
  2245. VolControl *vol = new VolControl(source, true, vertical);
  2246. double meterDecayRate = config_get_double(basicConfig, "Audio",
  2247. "MeterDecayRate");
  2248. vol->SetMeterDecayRate(meterDecayRate);
  2249. uint32_t peakMeterTypeIdx = config_get_uint(basicConfig, "Audio",
  2250. "PeakMeterType");
  2251. enum obs_peak_meter_type peakMeterType;
  2252. switch (peakMeterTypeIdx) {
  2253. case 0:
  2254. peakMeterType = SAMPLE_PEAK_METER;
  2255. break;
  2256. case 1:
  2257. peakMeterType = TRUE_PEAK_METER;
  2258. break;
  2259. default:
  2260. peakMeterType = SAMPLE_PEAK_METER;
  2261. break;
  2262. }
  2263. vol->setPeakMeterType(peakMeterType);
  2264. vol->setContextMenuPolicy(Qt::CustomContextMenu);
  2265. connect(vol, &QWidget::customContextMenuRequested,
  2266. this, &OBSBasic::VolControlContextMenu);
  2267. connect(vol, &VolControl::ConfigClicked,
  2268. this, &OBSBasic::VolControlContextMenu);
  2269. InsertQObjectByName(volumes, vol);
  2270. for (auto volume : volumes) {
  2271. if (vertical)
  2272. ui->vVolControlLayout->addWidget(volume);
  2273. else
  2274. ui->hVolControlLayout->addWidget(volume);
  2275. }
  2276. }
  2277. void OBSBasic::DeactivateAudioSource(OBSSource source)
  2278. {
  2279. for (size_t i = 0; i < volumes.size(); i++) {
  2280. if (volumes[i]->GetSource() == source) {
  2281. delete volumes[i];
  2282. volumes.erase(volumes.begin() + i);
  2283. break;
  2284. }
  2285. }
  2286. }
  2287. bool OBSBasic::QueryRemoveSource(obs_source_t *source)
  2288. {
  2289. if (obs_source_get_type(source) == OBS_SOURCE_TYPE_SCENE &&
  2290. !obs_source_is_group(source)) {
  2291. int count = ui->scenes->count();
  2292. if (count == 1) {
  2293. OBSMessageBox::information(this,
  2294. QTStr("FinalScene.Title"),
  2295. QTStr("FinalScene.Text"));
  2296. return false;
  2297. }
  2298. }
  2299. const char *name = obs_source_get_name(source);
  2300. QString text = QTStr("ConfirmRemove.Text");
  2301. text.replace("$1", QT_UTF8(name));
  2302. QMessageBox remove_source(this);
  2303. remove_source.setText(text);
  2304. QAbstractButton *Yes = remove_source.addButton(QTStr("Yes"),
  2305. QMessageBox::YesRole);
  2306. remove_source.addButton(QTStr("No"), QMessageBox::NoRole);
  2307. remove_source.setIcon(QMessageBox::Question);
  2308. remove_source.setWindowTitle(QTStr("ConfirmRemove.Title"));
  2309. remove_source.exec();
  2310. return Yes == remove_source.clickedButton();
  2311. }
  2312. #define UPDATE_CHECK_INTERVAL (60*60*24*4) /* 4 days */
  2313. #ifdef UPDATE_SPARKLE
  2314. void init_sparkle_updater(bool update_to_undeployed);
  2315. void trigger_sparkle_update();
  2316. #endif
  2317. void OBSBasic::TimedCheckForUpdates()
  2318. {
  2319. if (!config_get_bool(App()->GlobalConfig(), "General",
  2320. "EnableAutoUpdates"))
  2321. return;
  2322. #ifdef UPDATE_SPARKLE
  2323. init_sparkle_updater(config_get_bool(App()->GlobalConfig(), "General",
  2324. "UpdateToUndeployed"));
  2325. #elif _WIN32
  2326. long long lastUpdate = config_get_int(App()->GlobalConfig(), "General",
  2327. "LastUpdateCheck");
  2328. uint32_t lastVersion = config_get_int(App()->GlobalConfig(), "General",
  2329. "LastVersion");
  2330. if (lastVersion < LIBOBS_API_VER) {
  2331. lastUpdate = 0;
  2332. config_set_int(App()->GlobalConfig(), "General",
  2333. "LastUpdateCheck", 0);
  2334. }
  2335. long long t = (long long)time(nullptr);
  2336. long long secs = t - lastUpdate;
  2337. if (secs > UPDATE_CHECK_INTERVAL)
  2338. CheckForUpdates(false);
  2339. #endif
  2340. }
  2341. void OBSBasic::CheckForUpdates(bool manualUpdate)
  2342. {
  2343. #ifdef UPDATE_SPARKLE
  2344. trigger_sparkle_update();
  2345. #elif _WIN32
  2346. ui->actionCheckForUpdates->setEnabled(false);
  2347. if (updateCheckThread && updateCheckThread->isRunning())
  2348. return;
  2349. updateCheckThread.reset(new AutoUpdateThread(manualUpdate));
  2350. updateCheckThread->start();
  2351. #endif
  2352. UNUSED_PARAMETER(manualUpdate);
  2353. }
  2354. void OBSBasic::updateCheckFinished()
  2355. {
  2356. ui->actionCheckForUpdates->setEnabled(true);
  2357. }
  2358. void OBSBasic::DuplicateSelectedScene()
  2359. {
  2360. OBSScene curScene = GetCurrentScene();
  2361. if (!curScene)
  2362. return;
  2363. OBSSource curSceneSource = obs_scene_get_source(curScene);
  2364. QString format{obs_source_get_name(curSceneSource)};
  2365. format += " %1";
  2366. int i = 2;
  2367. QString placeHolderText = format.arg(i);
  2368. obs_source_t *source = nullptr;
  2369. while ((source = obs_get_source_by_name(QT_TO_UTF8(placeHolderText)))) {
  2370. obs_source_release(source);
  2371. placeHolderText = format.arg(++i);
  2372. }
  2373. for (;;) {
  2374. string name;
  2375. bool accepted = NameDialog::AskForName(this,
  2376. QTStr("Basic.Main.AddSceneDlg.Title"),
  2377. QTStr("Basic.Main.AddSceneDlg.Text"),
  2378. name,
  2379. placeHolderText);
  2380. if (!accepted)
  2381. return;
  2382. if (name.empty()) {
  2383. OBSMessageBox::information(this,
  2384. QTStr("NoNameEntered.Title"),
  2385. QTStr("NoNameEntered.Text"));
  2386. continue;
  2387. }
  2388. obs_source_t *source = obs_get_source_by_name(name.c_str());
  2389. if (source) {
  2390. OBSMessageBox::information(this,
  2391. QTStr("NameExists.Title"),
  2392. QTStr("NameExists.Text"));
  2393. obs_source_release(source);
  2394. continue;
  2395. }
  2396. obs_scene_t *scene = obs_scene_duplicate(curScene,
  2397. name.c_str(), OBS_SCENE_DUP_REFS);
  2398. source = obs_scene_get_source(scene);
  2399. SetCurrentScene(source, true);
  2400. obs_scene_release(scene);
  2401. break;
  2402. }
  2403. }
  2404. void OBSBasic::RemoveSelectedScene()
  2405. {
  2406. OBSScene scene = GetCurrentScene();
  2407. if (scene) {
  2408. obs_source_t *source = obs_scene_get_source(scene);
  2409. if (QueryRemoveSource(source)) {
  2410. obs_source_remove(source);
  2411. if (api)
  2412. api->on_event(OBS_FRONTEND_EVENT_SCENE_LIST_CHANGED);
  2413. }
  2414. }
  2415. }
  2416. void OBSBasic::RemoveSelectedSceneItem()
  2417. {
  2418. OBSSceneItem item = GetCurrentSceneItem();
  2419. if (item) {
  2420. obs_source_t *source = obs_sceneitem_get_source(item);
  2421. if (QueryRemoveSource(source))
  2422. obs_sceneitem_remove(item);
  2423. }
  2424. }
  2425. void OBSBasic::ReorderSources(OBSScene scene)
  2426. {
  2427. if (scene != GetCurrentScene() || ui->sources->IgnoreReorder())
  2428. return;
  2429. ui->sources->ReorderItems();
  2430. SaveProject();
  2431. }
  2432. /* OBS Callbacks */
  2433. void OBSBasic::SceneReordered(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. QMetaObject::invokeMethod(window, "ReorderSources",
  2438. Q_ARG(OBSScene, OBSScene(scene)));
  2439. }
  2440. void OBSBasic::SceneItemAdded(void *data, calldata_t *params)
  2441. {
  2442. OBSBasic *window = static_cast<OBSBasic*>(data);
  2443. obs_sceneitem_t *item = (obs_sceneitem_t*)calldata_ptr(params, "item");
  2444. QMetaObject::invokeMethod(window, "AddSceneItem",
  2445. Q_ARG(OBSSceneItem, OBSSceneItem(item)));
  2446. }
  2447. void OBSBasic::SceneItemSelected(void *data, calldata_t *params)
  2448. {
  2449. OBSBasic *window = static_cast<OBSBasic*>(data);
  2450. obs_scene_t *scene = (obs_scene_t*)calldata_ptr(params, "scene");
  2451. obs_sceneitem_t *item = (obs_sceneitem_t*)calldata_ptr(params, "item");
  2452. QMetaObject::invokeMethod(window, "SelectSceneItem",
  2453. Q_ARG(OBSScene, scene), Q_ARG(OBSSceneItem, item),
  2454. Q_ARG(bool, true));
  2455. }
  2456. void OBSBasic::SceneItemDeselected(void *data, calldata_t *params)
  2457. {
  2458. OBSBasic *window = static_cast<OBSBasic*>(data);
  2459. obs_scene_t *scene = (obs_scene_t*)calldata_ptr(params, "scene");
  2460. obs_sceneitem_t *item = (obs_sceneitem_t*)calldata_ptr(params, "item");
  2461. QMetaObject::invokeMethod(window, "SelectSceneItem",
  2462. Q_ARG(OBSScene, scene), Q_ARG(OBSSceneItem, item),
  2463. Q_ARG(bool, false));
  2464. }
  2465. void OBSBasic::SourceCreated(void *data, calldata_t *params)
  2466. {
  2467. obs_source_t *source = (obs_source_t*)calldata_ptr(params, "source");
  2468. if (obs_scene_from_source(source) != NULL)
  2469. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  2470. "AddScene", WaitConnection(),
  2471. Q_ARG(OBSSource, OBSSource(source)));
  2472. }
  2473. void OBSBasic::SourceRemoved(void *data, calldata_t *params)
  2474. {
  2475. obs_source_t *source = (obs_source_t*)calldata_ptr(params, "source");
  2476. if (obs_scene_from_source(source) != NULL)
  2477. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  2478. "RemoveScene",
  2479. Q_ARG(OBSSource, OBSSource(source)));
  2480. }
  2481. void OBSBasic::SourceActivated(void *data, calldata_t *params)
  2482. {
  2483. obs_source_t *source = (obs_source_t*)calldata_ptr(params, "source");
  2484. uint32_t flags = obs_source_get_output_flags(source);
  2485. if (flags & OBS_SOURCE_AUDIO)
  2486. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  2487. "ActivateAudioSource",
  2488. Q_ARG(OBSSource, OBSSource(source)));
  2489. }
  2490. void OBSBasic::SourceDeactivated(void *data, calldata_t *params)
  2491. {
  2492. obs_source_t *source = (obs_source_t*)calldata_ptr(params, "source");
  2493. uint32_t flags = obs_source_get_output_flags(source);
  2494. if (flags & OBS_SOURCE_AUDIO)
  2495. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  2496. "DeactivateAudioSource",
  2497. Q_ARG(OBSSource, OBSSource(source)));
  2498. }
  2499. void OBSBasic::SourceRenamed(void *data, calldata_t *params)
  2500. {
  2501. obs_source_t *source = (obs_source_t*)calldata_ptr(params, "source");
  2502. const char *newName = calldata_string(params, "new_name");
  2503. const char *prevName = calldata_string(params, "prev_name");
  2504. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  2505. "RenameSources",
  2506. Q_ARG(OBSSource, source),
  2507. Q_ARG(QString, QT_UTF8(newName)),
  2508. Q_ARG(QString, QT_UTF8(prevName)));
  2509. blog(LOG_INFO, "Source '%s' renamed to '%s'", prevName, newName);
  2510. }
  2511. void OBSBasic::DrawBackdrop(float cx, float cy)
  2512. {
  2513. if (!box)
  2514. return;
  2515. gs_effect_t *solid = obs_get_base_effect(OBS_EFFECT_SOLID);
  2516. gs_eparam_t *color = gs_effect_get_param_by_name(solid, "color");
  2517. gs_technique_t *tech = gs_effect_get_technique(solid, "Solid");
  2518. vec4 colorVal;
  2519. vec4_set(&colorVal, 0.0f, 0.0f, 0.0f, 1.0f);
  2520. gs_effect_set_vec4(color, &colorVal);
  2521. gs_technique_begin(tech);
  2522. gs_technique_begin_pass(tech, 0);
  2523. gs_matrix_push();
  2524. gs_matrix_identity();
  2525. gs_matrix_scale3f(float(cx), float(cy), 1.0f);
  2526. gs_load_vertexbuffer(box);
  2527. gs_draw(GS_TRISTRIP, 0, 0);
  2528. gs_matrix_pop();
  2529. gs_technique_end_pass(tech);
  2530. gs_technique_end(tech);
  2531. gs_load_vertexbuffer(nullptr);
  2532. }
  2533. void OBSBasic::RenderMain(void *data, uint32_t cx, uint32_t cy)
  2534. {
  2535. OBSBasic *window = static_cast<OBSBasic*>(data);
  2536. obs_video_info ovi;
  2537. obs_get_video_info(&ovi);
  2538. window->previewCX = int(window->previewScale * float(ovi.base_width));
  2539. window->previewCY = int(window->previewScale * float(ovi.base_height));
  2540. gs_viewport_push();
  2541. gs_projection_push();
  2542. /* --------------------------------------- */
  2543. gs_ortho(0.0f, float(ovi.base_width), 0.0f, float(ovi.base_height),
  2544. -100.0f, 100.0f);
  2545. gs_set_viewport(window->previewX, window->previewY,
  2546. window->previewCX, window->previewCY);
  2547. window->DrawBackdrop(float(ovi.base_width), float(ovi.base_height));
  2548. if (window->IsPreviewProgramMode()) {
  2549. OBSScene scene = window->GetCurrentScene();
  2550. obs_source_t *source = obs_scene_get_source(scene);
  2551. if (source)
  2552. obs_source_video_render(source);
  2553. } else {
  2554. obs_render_main_texture();
  2555. }
  2556. gs_load_vertexbuffer(nullptr);
  2557. /* --------------------------------------- */
  2558. QSize previewSize = GetPixelSize(window->ui->preview);
  2559. float right = float(previewSize.width()) - window->previewX;
  2560. float bottom = float(previewSize.height()) - window->previewY;
  2561. gs_ortho(-window->previewX, right,
  2562. -window->previewY, bottom,
  2563. -100.0f, 100.0f);
  2564. gs_reset_viewport();
  2565. window->ui->preview->DrawSceneEditing();
  2566. /* --------------------------------------- */
  2567. gs_projection_pop();
  2568. gs_viewport_pop();
  2569. UNUSED_PARAMETER(cx);
  2570. UNUSED_PARAMETER(cy);
  2571. }
  2572. /* Main class functions */
  2573. obs_service_t *OBSBasic::GetService()
  2574. {
  2575. if (!service) {
  2576. service = obs_service_create("rtmp_common", NULL, NULL,
  2577. nullptr);
  2578. obs_service_release(service);
  2579. }
  2580. return service;
  2581. }
  2582. void OBSBasic::SetService(obs_service_t *newService)
  2583. {
  2584. if (newService)
  2585. service = newService;
  2586. }
  2587. bool OBSBasic::StreamingActive() const
  2588. {
  2589. if (!outputHandler)
  2590. return false;
  2591. return outputHandler->StreamingActive();
  2592. }
  2593. bool OBSBasic::Active() const
  2594. {
  2595. if (!outputHandler)
  2596. return false;
  2597. return outputHandler->Active();
  2598. }
  2599. #ifdef _WIN32
  2600. #define IS_WIN32 1
  2601. #else
  2602. #define IS_WIN32 0
  2603. #endif
  2604. static inline int AttemptToResetVideo(struct obs_video_info *ovi)
  2605. {
  2606. return obs_reset_video(ovi);
  2607. }
  2608. static inline enum obs_scale_type GetScaleType(ConfigFile &basicConfig)
  2609. {
  2610. const char *scaleTypeStr = config_get_string(basicConfig,
  2611. "Video", "ScaleType");
  2612. if (astrcmpi(scaleTypeStr, "bilinear") == 0)
  2613. return OBS_SCALE_BILINEAR;
  2614. else if (astrcmpi(scaleTypeStr, "lanczos") == 0)
  2615. return OBS_SCALE_LANCZOS;
  2616. else
  2617. return OBS_SCALE_BICUBIC;
  2618. }
  2619. static inline enum video_format GetVideoFormatFromName(const char *name)
  2620. {
  2621. if (astrcmpi(name, "I420") == 0)
  2622. return VIDEO_FORMAT_I420;
  2623. else if (astrcmpi(name, "NV12") == 0)
  2624. return VIDEO_FORMAT_NV12;
  2625. else if (astrcmpi(name, "I444") == 0)
  2626. return VIDEO_FORMAT_I444;
  2627. #if 0 //currently unsupported
  2628. else if (astrcmpi(name, "YVYU") == 0)
  2629. return VIDEO_FORMAT_YVYU;
  2630. else if (astrcmpi(name, "YUY2") == 0)
  2631. return VIDEO_FORMAT_YUY2;
  2632. else if (astrcmpi(name, "UYVY") == 0)
  2633. return VIDEO_FORMAT_UYVY;
  2634. #endif
  2635. else
  2636. return VIDEO_FORMAT_RGBA;
  2637. }
  2638. void OBSBasic::ResetUI()
  2639. {
  2640. bool studioPortraitLayout = config_get_bool(GetGlobalConfig(),
  2641. "BasicWindow", "StudioPortraitLayout");
  2642. if (studioPortraitLayout)
  2643. ui->previewLayout->setDirection(QBoxLayout::TopToBottom);
  2644. else
  2645. ui->previewLayout->setDirection(QBoxLayout::LeftToRight);
  2646. }
  2647. int OBSBasic::ResetVideo()
  2648. {
  2649. if (outputHandler && outputHandler->Active())
  2650. return OBS_VIDEO_CURRENTLY_ACTIVE;
  2651. ProfileScope("OBSBasic::ResetVideo");
  2652. struct obs_video_info ovi;
  2653. int ret;
  2654. GetConfigFPS(ovi.fps_num, ovi.fps_den);
  2655. const char *colorFormat = config_get_string(basicConfig, "Video",
  2656. "ColorFormat");
  2657. const char *colorSpace = config_get_string(basicConfig, "Video",
  2658. "ColorSpace");
  2659. const char *colorRange = config_get_string(basicConfig, "Video",
  2660. "ColorRange");
  2661. ovi.graphics_module = App()->GetRenderModule();
  2662. ovi.base_width = (uint32_t)config_get_uint(basicConfig,
  2663. "Video", "BaseCX");
  2664. ovi.base_height = (uint32_t)config_get_uint(basicConfig,
  2665. "Video", "BaseCY");
  2666. ovi.output_width = (uint32_t)config_get_uint(basicConfig,
  2667. "Video", "OutputCX");
  2668. ovi.output_height = (uint32_t)config_get_uint(basicConfig,
  2669. "Video", "OutputCY");
  2670. ovi.output_format = GetVideoFormatFromName(colorFormat);
  2671. ovi.colorspace = astrcmpi(colorSpace, "601") == 0 ?
  2672. VIDEO_CS_601 : VIDEO_CS_709;
  2673. ovi.range = astrcmpi(colorRange, "Full") == 0 ?
  2674. VIDEO_RANGE_FULL : VIDEO_RANGE_PARTIAL;
  2675. ovi.adapter = config_get_uint(App()->GlobalConfig(),
  2676. "Video", "AdapterIdx");
  2677. ovi.gpu_conversion = true;
  2678. ovi.scale_type = GetScaleType(basicConfig);
  2679. if (ovi.base_width == 0 || ovi.base_height == 0) {
  2680. ovi.base_width = 1920;
  2681. ovi.base_height = 1080;
  2682. config_set_uint(basicConfig, "Video", "BaseCX", 1920);
  2683. config_set_uint(basicConfig, "Video", "BaseCY", 1080);
  2684. }
  2685. if (ovi.output_width == 0 || ovi.output_height == 0) {
  2686. ovi.output_width = ovi.base_width;
  2687. ovi.output_height = ovi.base_height;
  2688. config_set_uint(basicConfig, "Video", "OutputCX",
  2689. ovi.base_width);
  2690. config_set_uint(basicConfig, "Video", "OutputCY",
  2691. ovi.base_height);
  2692. }
  2693. ret = AttemptToResetVideo(&ovi);
  2694. if (IS_WIN32 && ret != OBS_VIDEO_SUCCESS) {
  2695. if (ret == OBS_VIDEO_CURRENTLY_ACTIVE) {
  2696. blog(LOG_WARNING, "Tried to reset when "
  2697. "already active");
  2698. return ret;
  2699. }
  2700. /* Try OpenGL if DirectX fails on windows */
  2701. if (astrcmpi(ovi.graphics_module, DL_OPENGL) != 0) {
  2702. blog(LOG_WARNING, "Failed to initialize obs video (%d) "
  2703. "with graphics_module='%s', retrying "
  2704. "with graphics_module='%s'",
  2705. ret, ovi.graphics_module,
  2706. DL_OPENGL);
  2707. ovi.graphics_module = DL_OPENGL;
  2708. ret = AttemptToResetVideo(&ovi);
  2709. }
  2710. } else if (ret == OBS_VIDEO_SUCCESS) {
  2711. ResizePreview(ovi.base_width, ovi.base_height);
  2712. if (program)
  2713. ResizeProgram(ovi.base_width, ovi.base_height);
  2714. }
  2715. if (ret == OBS_VIDEO_SUCCESS) {
  2716. OBSBasicStats::InitializeValues();
  2717. OBSProjector::UpdateMultiviewProjectors();
  2718. }
  2719. return ret;
  2720. }
  2721. bool OBSBasic::ResetAudio()
  2722. {
  2723. ProfileScope("OBSBasic::ResetAudio");
  2724. struct obs_audio_info ai;
  2725. ai.samples_per_sec = config_get_uint(basicConfig, "Audio",
  2726. "SampleRate");
  2727. const char *channelSetupStr = config_get_string(basicConfig,
  2728. "Audio", "ChannelSetup");
  2729. if (strcmp(channelSetupStr, "Mono") == 0)
  2730. ai.speakers = SPEAKERS_MONO;
  2731. else if (strcmp(channelSetupStr, "2.1") == 0)
  2732. ai.speakers = SPEAKERS_2POINT1;
  2733. else if (strcmp(channelSetupStr, "4.0") == 0)
  2734. ai.speakers = SPEAKERS_4POINT0;
  2735. else if (strcmp(channelSetupStr, "4.1") == 0)
  2736. ai.speakers = SPEAKERS_4POINT1;
  2737. else if (strcmp(channelSetupStr, "5.1") == 0)
  2738. ai.speakers = SPEAKERS_5POINT1;
  2739. else if (strcmp(channelSetupStr, "7.1") == 0)
  2740. ai.speakers = SPEAKERS_7POINT1;
  2741. else
  2742. ai.speakers = SPEAKERS_STEREO;
  2743. return obs_reset_audio(&ai);
  2744. }
  2745. void OBSBasic::ResetAudioDevice(const char *sourceId, const char *deviceId,
  2746. const char *deviceDesc, int channel)
  2747. {
  2748. bool disable = deviceId && strcmp(deviceId, "disabled") == 0;
  2749. obs_source_t *source;
  2750. obs_data_t *settings;
  2751. source = obs_get_output_source(channel);
  2752. if (source) {
  2753. if (disable) {
  2754. obs_set_output_source(channel, nullptr);
  2755. } else {
  2756. settings = obs_source_get_settings(source);
  2757. const char *oldId = obs_data_get_string(settings,
  2758. "device_id");
  2759. if (strcmp(oldId, deviceId) != 0) {
  2760. obs_data_set_string(settings, "device_id",
  2761. deviceId);
  2762. obs_source_update(source, settings);
  2763. }
  2764. obs_data_release(settings);
  2765. }
  2766. obs_source_release(source);
  2767. } else if (!disable) {
  2768. settings = obs_data_create();
  2769. obs_data_set_string(settings, "device_id", deviceId);
  2770. source = obs_source_create(sourceId, deviceDesc, settings,
  2771. nullptr);
  2772. obs_data_release(settings);
  2773. obs_set_output_source(channel, source);
  2774. obs_source_release(source);
  2775. }
  2776. }
  2777. void OBSBasic::ResizePreview(uint32_t cx, uint32_t cy)
  2778. {
  2779. QSize targetSize;
  2780. bool isFixedScaling;
  2781. obs_video_info ovi;
  2782. /* resize preview panel to fix to the top section of the window */
  2783. targetSize = GetPixelSize(ui->preview);
  2784. isFixedScaling = ui->preview->IsFixedScaling();
  2785. obs_get_video_info(&ovi);
  2786. if (isFixedScaling) {
  2787. previewScale = ui->preview->GetScalingAmount();
  2788. GetCenterPosFromFixedScale(int(cx), int(cy),
  2789. targetSize.width() - PREVIEW_EDGE_SIZE * 2,
  2790. targetSize.height() - PREVIEW_EDGE_SIZE * 2,
  2791. previewX, previewY, previewScale);
  2792. previewX += ui->preview->GetScrollX();
  2793. previewY += ui->preview->GetScrollY();
  2794. } else {
  2795. GetScaleAndCenterPos(int(cx), int(cy),
  2796. targetSize.width() - PREVIEW_EDGE_SIZE * 2,
  2797. targetSize.height() - PREVIEW_EDGE_SIZE * 2,
  2798. previewX, previewY, previewScale);
  2799. }
  2800. previewX += float(PREVIEW_EDGE_SIZE);
  2801. previewY += float(PREVIEW_EDGE_SIZE);
  2802. }
  2803. void OBSBasic::CloseDialogs()
  2804. {
  2805. QList<QDialog*> childDialogs = this->findChildren<QDialog *>();
  2806. if (!childDialogs.isEmpty()) {
  2807. for (int i = 0; i < childDialogs.size(); ++i) {
  2808. childDialogs.at(i)->close();
  2809. }
  2810. }
  2811. for (QPointer<QWidget> &projector : windowProjectors) {
  2812. delete projector;
  2813. projector.clear();
  2814. }
  2815. for (QPointer<QWidget> &projector : projectors) {
  2816. delete projector;
  2817. projector.clear();
  2818. }
  2819. if (!stats.isNull()) stats->close(); //call close to save Stats geometry
  2820. if (!remux.isNull()) remux->close();
  2821. }
  2822. void OBSBasic::EnumDialogs()
  2823. {
  2824. visDialogs.clear();
  2825. modalDialogs.clear();
  2826. visMsgBoxes.clear();
  2827. /* fill list of Visible dialogs and Modal dialogs */
  2828. QList<QDialog*> dialogs = findChildren<QDialog*>();
  2829. for (QDialog *dialog : dialogs) {
  2830. if (dialog->isVisible())
  2831. visDialogs.append(dialog);
  2832. if (dialog->isModal())
  2833. modalDialogs.append(dialog);
  2834. }
  2835. /* fill list of Visible message boxes */
  2836. QList<QMessageBox*> msgBoxes = findChildren<QMessageBox*>();
  2837. for (QMessageBox *msgbox : msgBoxes) {
  2838. if (msgbox->isVisible())
  2839. visMsgBoxes.append(msgbox);
  2840. }
  2841. }
  2842. void OBSBasic::ClearSceneData()
  2843. {
  2844. disableSaving++;
  2845. CloseDialogs();
  2846. ClearVolumeControls();
  2847. ClearListItems(ui->scenes);
  2848. ui->sources->Clear();
  2849. ClearQuickTransitions();
  2850. ui->transitions->clear();
  2851. obs_set_output_source(0, nullptr);
  2852. obs_set_output_source(1, nullptr);
  2853. obs_set_output_source(2, nullptr);
  2854. obs_set_output_source(3, nullptr);
  2855. obs_set_output_source(4, nullptr);
  2856. obs_set_output_source(5, nullptr);
  2857. lastScene = nullptr;
  2858. swapScene = nullptr;
  2859. programScene = nullptr;
  2860. auto cb = [](void *unused, obs_source_t *source)
  2861. {
  2862. obs_source_remove(source);
  2863. UNUSED_PARAMETER(unused);
  2864. return true;
  2865. };
  2866. obs_enum_sources(cb, nullptr);
  2867. if (api)
  2868. api->on_event(OBS_FRONTEND_EVENT_SCENE_COLLECTION_CLEANUP);
  2869. disableSaving--;
  2870. blog(LOG_INFO, "All scene data cleared");
  2871. blog(LOG_INFO, "------------------------------------------------");
  2872. }
  2873. void OBSBasic::closeEvent(QCloseEvent *event)
  2874. {
  2875. if (isVisible())
  2876. config_set_string(App()->GlobalConfig(),
  2877. "BasicWindow", "geometry",
  2878. saveGeometry().toBase64().constData());
  2879. config_set_string(App()->GlobalConfig(),
  2880. "BasicWindow", "DockState",
  2881. saveState().toBase64().constData());
  2882. if (outputHandler && outputHandler->Active()) {
  2883. SetShowing(true);
  2884. QMessageBox::StandardButton button = OBSMessageBox::question(
  2885. this, QTStr("ConfirmExit.Title"),
  2886. QTStr("ConfirmExit.Text"));
  2887. if (button == QMessageBox::No) {
  2888. event->ignore();
  2889. return;
  2890. }
  2891. }
  2892. QWidget::closeEvent(event);
  2893. if (!event->isAccepted())
  2894. return;
  2895. blog(LOG_INFO, SHUTDOWN_SEPARATOR);
  2896. if (introCheckThread)
  2897. introCheckThread->wait();
  2898. if (updateCheckThread)
  2899. updateCheckThread->wait();
  2900. if (logUploadThread)
  2901. logUploadThread->wait();
  2902. signalHandlers.clear();
  2903. SaveProjectNow();
  2904. if (api)
  2905. api->on_event(OBS_FRONTEND_EVENT_EXIT);
  2906. disableSaving++;
  2907. /* Clear all scene data (dialogs, widgets, widget sub-items, scenes,
  2908. * sources, etc) so that all references are released before shutdown */
  2909. ClearSceneData();
  2910. App()->quit();
  2911. }
  2912. void OBSBasic::changeEvent(QEvent *event)
  2913. {
  2914. if (event->type() == QEvent::WindowStateChange &&
  2915. isMinimized() &&
  2916. trayIcon &&
  2917. trayIcon->isVisible() &&
  2918. sysTrayMinimizeToTray()) {
  2919. ToggleShowHide();
  2920. }
  2921. }
  2922. void OBSBasic::on_actionShow_Recordings_triggered()
  2923. {
  2924. const char *mode = config_get_string(basicConfig, "Output", "Mode");
  2925. const char *type = config_get_string(basicConfig, "AdvOut", "RecType");
  2926. const char *adv_path = strcmp(type, "Standard") ?
  2927. config_get_string(basicConfig, "AdvOut", "FFFilePath") :
  2928. config_get_string(basicConfig, "AdvOut", "RecFilePath");
  2929. const char *path = strcmp(mode, "Advanced") ?
  2930. config_get_string(basicConfig, "SimpleOutput", "FilePath") :
  2931. adv_path;
  2932. QDesktopServices::openUrl(QUrl::fromLocalFile(path));
  2933. }
  2934. void OBSBasic::on_actionRemux_triggered()
  2935. {
  2936. if (!remux.isNull()) {
  2937. remux->show();
  2938. remux->raise();
  2939. return;
  2940. }
  2941. const char *mode = config_get_string(basicConfig, "Output", "Mode");
  2942. const char *path = strcmp(mode, "Advanced") ?
  2943. config_get_string(basicConfig, "SimpleOutput", "FilePath") :
  2944. config_get_string(basicConfig, "AdvOut", "RecFilePath");
  2945. OBSRemux *remuxDlg;
  2946. remuxDlg = new OBSRemux(path, this);
  2947. remuxDlg->show();
  2948. remux = remuxDlg;
  2949. }
  2950. void OBSBasic::on_action_Settings_triggered()
  2951. {
  2952. OBSBasicSettings settings(this);
  2953. settings.exec();
  2954. SystemTray(false);
  2955. }
  2956. void OBSBasic::on_actionAdvAudioProperties_triggered()
  2957. {
  2958. if (advAudioWindow != nullptr) {
  2959. advAudioWindow->raise();
  2960. return;
  2961. }
  2962. advAudioWindow = new OBSBasicAdvAudio(this);
  2963. advAudioWindow->show();
  2964. advAudioWindow->setAttribute(Qt::WA_DeleteOnClose, true);
  2965. connect(advAudioWindow, SIGNAL(destroyed()),
  2966. this, SLOT(on_advAudioProps_destroyed()));
  2967. }
  2968. void OBSBasic::on_advAudioProps_clicked()
  2969. {
  2970. on_actionAdvAudioProperties_triggered();
  2971. }
  2972. void OBSBasic::on_advAudioProps_destroyed()
  2973. {
  2974. advAudioWindow = nullptr;
  2975. }
  2976. void OBSBasic::on_scenes_currentItemChanged(QListWidgetItem *current,
  2977. QListWidgetItem *prev)
  2978. {
  2979. obs_source_t *source = NULL;
  2980. if (sceneChanging)
  2981. return;
  2982. if (current) {
  2983. obs_scene_t *scene;
  2984. scene = GetOBSRef<OBSScene>(current);
  2985. source = obs_scene_get_source(scene);
  2986. }
  2987. SetCurrentScene(source);
  2988. if (api)
  2989. api->on_event(OBS_FRONTEND_EVENT_PREVIEW_SCENE_CHANGED);
  2990. UNUSED_PARAMETER(prev);
  2991. }
  2992. void OBSBasic::EditSceneName()
  2993. {
  2994. QListWidgetItem *item = ui->scenes->currentItem();
  2995. Qt::ItemFlags flags = item->flags();
  2996. item->setFlags(flags | Qt::ItemIsEditable);
  2997. ui->scenes->editItem(item);
  2998. item->setFlags(flags);
  2999. }
  3000. static void AddProjectorMenuMonitors(QMenu *parent, QObject *target,
  3001. const char *slot)
  3002. {
  3003. QAction *action;
  3004. QList<QScreen*> screens = QGuiApplication::screens();
  3005. for (int i = 0; i < screens.size(); i++) {
  3006. QRect screenGeometry = screens[i]->geometry();
  3007. QString str = QString("%1 %2: %3x%4 @ %5,%6").
  3008. arg(QTStr("Display"),
  3009. QString::number(i),
  3010. QString::number(screenGeometry.width()),
  3011. QString::number(screenGeometry.height()),
  3012. QString::number(screenGeometry.x()),
  3013. QString::number(screenGeometry.y()));
  3014. action = parent->addAction(str, target, slot);
  3015. action->setProperty("monitor", i);
  3016. }
  3017. }
  3018. void OBSBasic::on_scenes_customContextMenuRequested(const QPoint &pos)
  3019. {
  3020. QListWidgetItem *item = ui->scenes->itemAt(pos);
  3021. QPointer<QMenu> sceneProjectorMenu;
  3022. QMenu popup(this);
  3023. QMenu order(QTStr("Basic.MainMenu.Edit.Order"), this);
  3024. popup.addAction(QTStr("Add"),
  3025. this, SLOT(on_actionAddScene_triggered()));
  3026. if (item) {
  3027. popup.addSeparator();
  3028. popup.addAction(QTStr("Duplicate"),
  3029. this, SLOT(DuplicateSelectedScene()));
  3030. popup.addAction(QTStr("Rename"),
  3031. this, SLOT(EditSceneName()));
  3032. popup.addAction(QTStr("Remove"),
  3033. this, SLOT(RemoveSelectedScene()));
  3034. popup.addSeparator();
  3035. order.addAction(QTStr("Basic.MainMenu.Edit.Order.MoveUp"),
  3036. this, SLOT(on_actionSceneUp_triggered()));
  3037. order.addAction(QTStr("Basic.MainMenu.Edit.Order.MoveDown"),
  3038. this, SLOT(on_actionSceneDown_triggered()));
  3039. order.addSeparator();
  3040. order.addAction(QTStr("Basic.MainMenu.Edit.Order.MoveToTop"),
  3041. this, SLOT(MoveSceneToTop()));
  3042. order.addAction(QTStr("Basic.MainMenu.Edit.Order.MoveToBottom"),
  3043. this, SLOT(MoveSceneToBottom()));
  3044. popup.addMenu(&order);
  3045. popup.addSeparator();
  3046. sceneProjectorMenu = new QMenu(QTStr("SceneProjector"));
  3047. AddProjectorMenuMonitors(sceneProjectorMenu, this,
  3048. SLOT(OpenSceneProjector()));
  3049. popup.addMenu(sceneProjectorMenu);
  3050. QAction *sceneWindow = popup.addAction(
  3051. QTStr("SceneWindow"),
  3052. this, SLOT(OpenSceneWindow()));
  3053. popup.addAction(sceneWindow);
  3054. popup.addSeparator();
  3055. popup.addAction(QTStr("Filters"), this,
  3056. SLOT(OpenSceneFilters()));
  3057. popup.addSeparator();
  3058. QMenu *transitionMenu = CreatePerSceneTransitionMenu();
  3059. popup.addMenu(transitionMenu);
  3060. /* ---------------------- */
  3061. QAction *multiviewAction = popup.addAction(
  3062. QTStr("ShowInMultiview"));
  3063. OBSSource source = GetCurrentSceneSource();
  3064. OBSData data = obs_source_get_private_settings(source);
  3065. obs_data_release(data);
  3066. obs_data_set_default_bool(data, "show_in_multiview",
  3067. true);
  3068. bool show = obs_data_get_bool(data, "show_in_multiview");
  3069. multiviewAction->setCheckable(true);
  3070. multiviewAction->setChecked(show);
  3071. auto showInMultiview = [] (OBSData data)
  3072. {
  3073. bool show = obs_data_get_bool(data,
  3074. "show_in_multiview");
  3075. obs_data_set_bool(data, "show_in_multiview",
  3076. !show);
  3077. OBSProjector::UpdateMultiviewProjectors();
  3078. };
  3079. connect(multiviewAction, &QAction::triggered,
  3080. std::bind(showInMultiview, data));
  3081. }
  3082. popup.exec(QCursor::pos());
  3083. }
  3084. void OBSBasic::on_actionAddScene_triggered()
  3085. {
  3086. string name;
  3087. QString format{QTStr("Basic.Main.DefaultSceneName.Text")};
  3088. int i = 2;
  3089. QString placeHolderText = format.arg(i);
  3090. obs_source_t *source = nullptr;
  3091. while ((source = obs_get_source_by_name(QT_TO_UTF8(placeHolderText)))) {
  3092. obs_source_release(source);
  3093. placeHolderText = format.arg(++i);
  3094. }
  3095. bool accepted = NameDialog::AskForName(this,
  3096. QTStr("Basic.Main.AddSceneDlg.Title"),
  3097. QTStr("Basic.Main.AddSceneDlg.Text"),
  3098. name,
  3099. placeHolderText);
  3100. if (accepted) {
  3101. if (name.empty()) {
  3102. OBSMessageBox::information(this,
  3103. QTStr("NoNameEntered.Title"),
  3104. QTStr("NoNameEntered.Text"));
  3105. on_actionAddScene_triggered();
  3106. return;
  3107. }
  3108. obs_source_t *source = obs_get_source_by_name(name.c_str());
  3109. if (source) {
  3110. OBSMessageBox::information(this,
  3111. QTStr("NameExists.Title"),
  3112. QTStr("NameExists.Text"));
  3113. obs_source_release(source);
  3114. on_actionAddScene_triggered();
  3115. return;
  3116. }
  3117. obs_scene_t *scene = obs_scene_create(name.c_str());
  3118. source = obs_scene_get_source(scene);
  3119. SetCurrentScene(source);
  3120. obs_scene_release(scene);
  3121. }
  3122. }
  3123. void OBSBasic::on_actionRemoveScene_triggered()
  3124. {
  3125. OBSScene scene = GetCurrentScene();
  3126. obs_source_t *source = obs_scene_get_source(scene);
  3127. if (source && QueryRemoveSource(source))
  3128. obs_source_remove(source);
  3129. }
  3130. void OBSBasic::ChangeSceneIndex(bool relative, int offset, int invalidIdx)
  3131. {
  3132. int idx = ui->scenes->currentRow();
  3133. if (idx == -1 || idx == invalidIdx)
  3134. return;
  3135. sceneChanging = true;
  3136. QListWidgetItem *item = ui->scenes->takeItem(idx);
  3137. if (!relative)
  3138. idx = 0;
  3139. ui->scenes->insertItem(idx + offset, item);
  3140. ui->scenes->setCurrentRow(idx + offset);
  3141. item->setSelected(true);
  3142. sceneChanging = false;
  3143. OBSProjector::UpdateMultiviewProjectors();
  3144. }
  3145. void OBSBasic::on_actionSceneUp_triggered()
  3146. {
  3147. ChangeSceneIndex(true, -1, 0);
  3148. }
  3149. void OBSBasic::on_actionSceneDown_triggered()
  3150. {
  3151. ChangeSceneIndex(true, 1, ui->scenes->count() - 1);
  3152. }
  3153. void OBSBasic::MoveSceneToTop()
  3154. {
  3155. ChangeSceneIndex(false, 0, 0);
  3156. }
  3157. void OBSBasic::MoveSceneToBottom()
  3158. {
  3159. ChangeSceneIndex(false, ui->scenes->count() - 1,
  3160. ui->scenes->count() - 1);
  3161. }
  3162. void OBSBasic::EditSceneItemName()
  3163. {
  3164. int idx = GetTopSelectedSourceItem();
  3165. ui->sources->Edit(idx);
  3166. }
  3167. void OBSBasic::SetDeinterlacingMode()
  3168. {
  3169. QAction *action = reinterpret_cast<QAction*>(sender());
  3170. obs_deinterlace_mode mode =
  3171. (obs_deinterlace_mode)action->property("mode").toInt();
  3172. OBSSceneItem sceneItem = GetCurrentSceneItem();
  3173. obs_source_t *source = obs_sceneitem_get_source(sceneItem);
  3174. obs_source_set_deinterlace_mode(source, mode);
  3175. }
  3176. void OBSBasic::SetDeinterlacingOrder()
  3177. {
  3178. QAction *action = reinterpret_cast<QAction*>(sender());
  3179. obs_deinterlace_field_order order =
  3180. (obs_deinterlace_field_order)action->property("order").toInt();
  3181. OBSSceneItem sceneItem = GetCurrentSceneItem();
  3182. obs_source_t *source = obs_sceneitem_get_source(sceneItem);
  3183. obs_source_set_deinterlace_field_order(source, order);
  3184. }
  3185. QMenu *OBSBasic::AddDeinterlacingMenu(obs_source_t *source)
  3186. {
  3187. QMenu *menu = new QMenu(QTStr("Deinterlacing"));
  3188. obs_deinterlace_mode deinterlaceMode =
  3189. obs_source_get_deinterlace_mode(source);
  3190. obs_deinterlace_field_order deinterlaceOrder =
  3191. obs_source_get_deinterlace_field_order(source);
  3192. QAction *action;
  3193. #define ADD_MODE(name, mode) \
  3194. action = menu->addAction(QTStr("" name), this, \
  3195. SLOT(SetDeinterlacingMode())); \
  3196. action->setProperty("mode", (int)mode); \
  3197. action->setCheckable(true); \
  3198. action->setChecked(deinterlaceMode == mode);
  3199. ADD_MODE("Disable", OBS_DEINTERLACE_MODE_DISABLE);
  3200. ADD_MODE("Deinterlacing.Discard", OBS_DEINTERLACE_MODE_DISCARD);
  3201. ADD_MODE("Deinterlacing.Retro", OBS_DEINTERLACE_MODE_RETRO);
  3202. ADD_MODE("Deinterlacing.Blend", OBS_DEINTERLACE_MODE_BLEND);
  3203. ADD_MODE("Deinterlacing.Blend2x", OBS_DEINTERLACE_MODE_BLEND_2X);
  3204. ADD_MODE("Deinterlacing.Linear", OBS_DEINTERLACE_MODE_LINEAR);
  3205. ADD_MODE("Deinterlacing.Linear2x", OBS_DEINTERLACE_MODE_LINEAR_2X);
  3206. ADD_MODE("Deinterlacing.Yadif", OBS_DEINTERLACE_MODE_YADIF);
  3207. ADD_MODE("Deinterlacing.Yadif2x", OBS_DEINTERLACE_MODE_YADIF_2X);
  3208. #undef ADD_MODE
  3209. menu->addSeparator();
  3210. #define ADD_ORDER(name, order) \
  3211. action = menu->addAction(QTStr("Deinterlacing." name), this, \
  3212. SLOT(SetDeinterlacingOrder())); \
  3213. action->setProperty("order", (int)order); \
  3214. action->setCheckable(true); \
  3215. action->setChecked(deinterlaceOrder == order);
  3216. ADD_ORDER("TopFieldFirst", OBS_DEINTERLACE_FIELD_ORDER_TOP);
  3217. ADD_ORDER("BottomFieldFirst", OBS_DEINTERLACE_FIELD_ORDER_BOTTOM);
  3218. #undef ADD_ORDER
  3219. return menu;
  3220. }
  3221. void OBSBasic::SetScaleFilter()
  3222. {
  3223. QAction *action = reinterpret_cast<QAction*>(sender());
  3224. obs_scale_type mode = (obs_scale_type)action->property("mode").toInt();
  3225. OBSSceneItem sceneItem = GetCurrentSceneItem();
  3226. obs_sceneitem_set_scale_filter(sceneItem, mode);
  3227. }
  3228. QMenu *OBSBasic::AddScaleFilteringMenu(obs_sceneitem_t *item)
  3229. {
  3230. QMenu *menu = new QMenu(QTStr("ScaleFiltering"));
  3231. obs_scale_type scaleFilter = obs_sceneitem_get_scale_filter(item);
  3232. QAction *action;
  3233. #define ADD_MODE(name, mode) \
  3234. action = menu->addAction(QTStr("" name), this, \
  3235. SLOT(SetScaleFilter())); \
  3236. action->setProperty("mode", (int)mode); \
  3237. action->setCheckable(true); \
  3238. action->setChecked(scaleFilter == mode);
  3239. ADD_MODE("Disable", OBS_SCALE_DISABLE);
  3240. ADD_MODE("ScaleFiltering.Point", OBS_SCALE_POINT);
  3241. ADD_MODE("ScaleFiltering.Bilinear", OBS_SCALE_BILINEAR);
  3242. ADD_MODE("ScaleFiltering.Bicubic", OBS_SCALE_BICUBIC);
  3243. ADD_MODE("ScaleFiltering.Lanczos", OBS_SCALE_LANCZOS);
  3244. #undef ADD_MODE
  3245. return menu;
  3246. }
  3247. QMenu *OBSBasic::AddBackgroundColorMenu(obs_sceneitem_t *item)
  3248. {
  3249. QMenu *menu = new QMenu(QTStr("ChangeBG"));
  3250. QAction *action;
  3251. menu->setStyleSheet(QString(
  3252. "*[bgColor=\"1\"]{background-color:rgba(255,68,68,33%);}" \
  3253. "*[bgColor=\"2\"]{background-color:rgba(255,255,68,33%);}" \
  3254. "*[bgColor=\"3\"]{background-color:rgba(68,255,68,33%);}" \
  3255. "*[bgColor=\"4\"]{background-color:rgba(68,255,255,33%);}" \
  3256. "*[bgColor=\"5\"]{background-color:rgba(68,68,255,33%);}" \
  3257. "*[bgColor=\"6\"]{background-color:rgba(255,68,255,33%);}" \
  3258. "*[bgColor=\"7\"]{background-color:rgba(68,68,68,33%);}" \
  3259. "*[bgColor=\"8\"]{background-color:rgba(255,255,255,33%);}"));
  3260. obs_data_t *privData = obs_sceneitem_get_private_settings(item);
  3261. obs_data_release(privData);
  3262. obs_data_set_default_int(privData, "color-preset", 0);
  3263. int preset = obs_data_get_int(privData, "color-preset");
  3264. action = menu->addAction(QTStr("Clear"), this,
  3265. + SLOT(ColorChange()));
  3266. action->setCheckable(true);
  3267. action->setProperty("bgColor", 0);
  3268. action->setChecked(preset == 0);
  3269. action = menu->addAction(QTStr("CustomColor"), this,
  3270. + SLOT(ColorChange()));
  3271. action->setCheckable(true);
  3272. action->setProperty("bgColor", 1);
  3273. action->setChecked(preset == 1);
  3274. menu->addSeparator();
  3275. QWidgetAction *widgetAction = new QWidgetAction(menu);
  3276. ColorSelect *select = new ColorSelect(menu);
  3277. widgetAction->setDefaultWidget(select);
  3278. for (int i = 1; i < 9; i++) {
  3279. stringstream button;
  3280. button << "preset" << i;
  3281. QPushButton *colorButton = select->findChild<QPushButton *>(
  3282. button.str().c_str());
  3283. if (preset == i + 1)
  3284. colorButton->setStyleSheet("border: 2px solid black");
  3285. colorButton->setProperty("bgColor", i);
  3286. select->connect(colorButton, SIGNAL(released()), this,
  3287. SLOT(ColorChange()));
  3288. }
  3289. menu->addAction(widgetAction);
  3290. return menu;
  3291. }
  3292. void OBSBasic::CreateSourcePopupMenu(int idx, bool preview)
  3293. {
  3294. QMenu popup(this);
  3295. QPointer<QMenu> previewProjector;
  3296. QPointer<QMenu> sourceProjector;
  3297. if (preview) {
  3298. QAction *action = popup.addAction(
  3299. QTStr("Basic.Main.PreviewConextMenu.Enable"),
  3300. this, SLOT(TogglePreview()));
  3301. action->setCheckable(true);
  3302. action->setChecked(
  3303. obs_display_enabled(ui->preview->GetDisplay()));
  3304. if (IsPreviewProgramMode())
  3305. action->setEnabled(false);
  3306. popup.addAction(ui->actionLockPreview);
  3307. popup.addMenu(ui->scalingMenu);
  3308. previewProjector = new QMenu(QTStr("PreviewProjector"));
  3309. AddProjectorMenuMonitors(previewProjector, this,
  3310. SLOT(OpenPreviewProjector()));
  3311. popup.addMenu(previewProjector);
  3312. QAction *previewWindow = popup.addAction(
  3313. QTStr("PreviewWindow"),
  3314. this, SLOT(OpenPreviewWindow()));
  3315. popup.addAction(previewWindow);
  3316. popup.addSeparator();
  3317. }
  3318. QPointer<QMenu> addSourceMenu = CreateAddSourcePopupMenu();
  3319. if (addSourceMenu)
  3320. popup.addMenu(addSourceMenu);
  3321. ui->actionCopyFilters->setEnabled(false);
  3322. ui->actionCopySource->setEnabled(false);
  3323. if (ui->sources->MultipleBaseSelected()) {
  3324. popup.addSeparator();
  3325. popup.addAction(QTStr("Basic.Main.GroupItems"),
  3326. ui->sources, SLOT(GroupSelectedItems()));
  3327. } else if (ui->sources->GroupsSelected()) {
  3328. popup.addSeparator();
  3329. popup.addAction(QTStr("Basic.Main.Ungroup"),
  3330. ui->sources, SLOT(UngroupSelectedGroups()));
  3331. }
  3332. popup.addSeparator();
  3333. popup.addAction(ui->actionCopySource);
  3334. popup.addAction(ui->actionPasteRef);
  3335. popup.addAction(ui->actionPasteDup);
  3336. popup.addSeparator();
  3337. popup.addSeparator();
  3338. popup.addAction(ui->actionCopyFilters);
  3339. popup.addAction(ui->actionPasteFilters);
  3340. popup.addSeparator();
  3341. if (idx != -1) {
  3342. if (addSourceMenu)
  3343. popup.addSeparator();
  3344. OBSSceneItem sceneItem = ui->sources->Get(idx);
  3345. obs_source_t *source = obs_sceneitem_get_source(sceneItem);
  3346. uint32_t flags = obs_source_get_output_flags(source);
  3347. bool isAsyncVideo = (flags & OBS_SOURCE_ASYNC_VIDEO) ==
  3348. OBS_SOURCE_ASYNC_VIDEO;
  3349. bool hasAudio = (flags & OBS_SOURCE_AUDIO) ==
  3350. OBS_SOURCE_AUDIO;
  3351. QAction *action;
  3352. popup.addMenu(AddBackgroundColorMenu(sceneItem));
  3353. popup.addAction(QTStr("Rename"), this,
  3354. SLOT(EditSceneItemName()));
  3355. popup.addAction(QTStr("Remove"), this,
  3356. SLOT(on_actionRemoveSource_triggered()));
  3357. popup.addSeparator();
  3358. popup.addMenu(ui->orderMenu);
  3359. popup.addMenu(ui->transformMenu);
  3360. sourceProjector = new QMenu(QTStr("SourceProjector"));
  3361. AddProjectorMenuMonitors(sourceProjector, this,
  3362. SLOT(OpenSourceProjector()));
  3363. QAction *sourceWindow = popup.addAction(
  3364. QTStr("SourceWindow"),
  3365. this, SLOT(OpenSourceWindow()));
  3366. popup.addAction(sourceWindow);
  3367. popup.addSeparator();
  3368. if (hasAudio) {
  3369. QAction *actionHideMixer = popup.addAction(
  3370. QTStr("HideMixer"),
  3371. this, SLOT(ToggleHideMixer()));
  3372. actionHideMixer->setCheckable(true);
  3373. actionHideMixer->setChecked(SourceMixerHidden(source));
  3374. }
  3375. if (isAsyncVideo) {
  3376. popup.addMenu(AddDeinterlacingMenu(source));
  3377. popup.addSeparator();
  3378. }
  3379. popup.addMenu(AddScaleFilteringMenu(sceneItem));
  3380. popup.addSeparator();
  3381. popup.addMenu(sourceProjector);
  3382. popup.addAction(sourceWindow);
  3383. popup.addSeparator();
  3384. action = popup.addAction(QTStr("Interact"), this,
  3385. SLOT(on_actionInteract_triggered()));
  3386. action->setEnabled(obs_source_get_output_flags(source) &
  3387. OBS_SOURCE_INTERACTION);
  3388. popup.addAction(QTStr("Filters"), this,
  3389. SLOT(OpenFilters()));
  3390. popup.addAction(QTStr("Properties"), this,
  3391. SLOT(on_actionSourceProperties_triggered()));
  3392. ui->actionCopyFilters->setEnabled(true);
  3393. ui->actionCopySource->setEnabled(true);
  3394. } else {
  3395. ui->actionPasteFilters->setEnabled(false);
  3396. }
  3397. popup.exec(QCursor::pos());
  3398. }
  3399. void OBSBasic::on_sources_customContextMenuRequested(const QPoint &pos)
  3400. {
  3401. if (ui->scenes->count()) {
  3402. QModelIndex idx = ui->sources->indexAt(pos);
  3403. CreateSourcePopupMenu(idx.row(), false);
  3404. }
  3405. }
  3406. void OBSBasic::on_scenes_itemDoubleClicked(QListWidgetItem *witem)
  3407. {
  3408. if (!witem)
  3409. return;
  3410. if (IsPreviewProgramMode()) {
  3411. bool doubleClickSwitch = config_get_bool(App()->GlobalConfig(),
  3412. "BasicWindow", "TransitionOnDoubleClick");
  3413. if (doubleClickSwitch) {
  3414. OBSScene scene = GetCurrentScene();
  3415. if (scene)
  3416. SetCurrentScene(scene, false, true);
  3417. }
  3418. }
  3419. }
  3420. void OBSBasic::AddSource(const char *id)
  3421. {
  3422. if (id && *id) {
  3423. OBSBasicSourceSelect sourceSelect(this, id);
  3424. sourceSelect.exec();
  3425. if (sourceSelect.newSource && strcmp(id, "group") != 0)
  3426. CreatePropertiesWindow(sourceSelect.newSource);
  3427. }
  3428. }
  3429. QMenu *OBSBasic::CreateAddSourcePopupMenu()
  3430. {
  3431. const char *type;
  3432. bool foundValues = false;
  3433. bool foundDeprecated = false;
  3434. size_t idx = 0;
  3435. QMenu *popup = new QMenu(QTStr("Add"), this);
  3436. QMenu *deprecated = new QMenu(QTStr("Deprecated"), popup);
  3437. auto getActionAfter = [] (QMenu *menu, const QString &name)
  3438. {
  3439. QList<QAction*> actions = menu->actions();
  3440. for (QAction *menuAction : actions) {
  3441. if (menuAction->text().compare(name) >= 0)
  3442. return menuAction;
  3443. }
  3444. return (QAction*)nullptr;
  3445. };
  3446. auto addSource = [this, getActionAfter] (QMenu *popup,
  3447. const char *type, const char *name)
  3448. {
  3449. QString qname = QT_UTF8(name);
  3450. QAction *popupItem = new QAction(qname, this);
  3451. popupItem->setData(QT_UTF8(type));
  3452. connect(popupItem, SIGNAL(triggered(bool)),
  3453. this, SLOT(AddSourceFromAction()));
  3454. QAction *after = getActionAfter(popup, qname);
  3455. popup->insertAction(after, popupItem);
  3456. };
  3457. while (obs_enum_input_types(idx++, &type)) {
  3458. const char *name = obs_source_get_display_name(type);
  3459. uint32_t caps = obs_get_source_output_flags(type);
  3460. if ((caps & OBS_SOURCE_CAP_DISABLED) != 0)
  3461. continue;
  3462. if ((caps & OBS_SOURCE_DEPRECATED) == 0) {
  3463. addSource(popup, type, name);
  3464. } else {
  3465. addSource(deprecated, type, name);
  3466. foundDeprecated = true;
  3467. }
  3468. foundValues = true;
  3469. }
  3470. addSource(popup, "scene", Str("Basic.Scene"));
  3471. popup->addSeparator();
  3472. QAction *addGroup = new QAction(QTStr("Group"), this);
  3473. addGroup->setData(QT_UTF8("group"));
  3474. connect(addGroup, SIGNAL(triggered(bool)),
  3475. this, SLOT(AddSourceFromAction()));
  3476. popup->addAction(addGroup);
  3477. if (!foundDeprecated) {
  3478. delete deprecated;
  3479. deprecated = nullptr;
  3480. }
  3481. if (!foundValues) {
  3482. delete popup;
  3483. popup = nullptr;
  3484. } else if (foundDeprecated) {
  3485. popup->addSeparator();
  3486. popup->addMenu(deprecated);
  3487. }
  3488. return popup;
  3489. }
  3490. void OBSBasic::AddSourceFromAction()
  3491. {
  3492. QAction *action = qobject_cast<QAction*>(sender());
  3493. if (!action)
  3494. return;
  3495. AddSource(QT_TO_UTF8(action->data().toString()));
  3496. }
  3497. void OBSBasic::AddSourcePopupMenu(const QPoint &pos)
  3498. {
  3499. if (!GetCurrentScene()) {
  3500. // Tell the user he needs a scene first (help beginners).
  3501. OBSMessageBox::information(this,
  3502. QTStr("Basic.Main.AddSourceHelp.Title"),
  3503. QTStr("Basic.Main.AddSourceHelp.Text"));
  3504. return;
  3505. }
  3506. QScopedPointer<QMenu> popup(CreateAddSourcePopupMenu());
  3507. if (popup)
  3508. popup->exec(pos);
  3509. }
  3510. void OBSBasic::on_actionAddSource_triggered()
  3511. {
  3512. AddSourcePopupMenu(QCursor::pos());
  3513. }
  3514. static bool remove_items(obs_scene_t *, obs_sceneitem_t *item, void *param)
  3515. {
  3516. vector<OBSSceneItem> &items =
  3517. *reinterpret_cast<vector<OBSSceneItem>*>(param);
  3518. if (obs_sceneitem_selected(item)) {
  3519. items.emplace_back(item);
  3520. } else if (obs_sceneitem_is_group(item)) {
  3521. obs_sceneitem_group_enum_items(item, remove_items, &items);
  3522. }
  3523. return true;
  3524. };
  3525. void OBSBasic::on_actionRemoveSource_triggered()
  3526. {
  3527. vector<OBSSceneItem> items;
  3528. obs_scene_enum_items(GetCurrentScene(), remove_items, &items);
  3529. if (!items.size())
  3530. return;
  3531. auto removeMultiple = [this] (size_t count)
  3532. {
  3533. QString text = QTStr("ConfirmRemove.TextMultiple")
  3534. .arg(QString::number(count));
  3535. QMessageBox remove_items(this);
  3536. remove_items.setText(text);
  3537. QAbstractButton *Yes = remove_items.addButton(QTStr("Yes"),
  3538. QMessageBox::YesRole);
  3539. remove_items.addButton(QTStr("No"), QMessageBox::NoRole);
  3540. remove_items.setIcon(QMessageBox::Question);
  3541. remove_items.setWindowTitle(QTStr("ConfirmRemove.Title"));
  3542. remove_items.exec();
  3543. return Yes == remove_items.clickedButton();
  3544. };
  3545. if (items.size() == 1) {
  3546. OBSSceneItem &item = items[0];
  3547. obs_source_t *source = obs_sceneitem_get_source(item);
  3548. if (source && QueryRemoveSource(source))
  3549. obs_sceneitem_remove(item);
  3550. } else {
  3551. if (removeMultiple(items.size())) {
  3552. for (auto &item : items)
  3553. obs_sceneitem_remove(item);
  3554. }
  3555. }
  3556. }
  3557. void OBSBasic::on_actionInteract_triggered()
  3558. {
  3559. OBSSceneItem item = GetCurrentSceneItem();
  3560. OBSSource source = obs_sceneitem_get_source(item);
  3561. if (source)
  3562. CreateInteractionWindow(source);
  3563. }
  3564. void OBSBasic::on_actionSourceProperties_triggered()
  3565. {
  3566. OBSSceneItem item = GetCurrentSceneItem();
  3567. OBSSource source = obs_sceneitem_get_source(item);
  3568. if (source)
  3569. CreatePropertiesWindow(source);
  3570. }
  3571. void OBSBasic::on_actionSourceUp_triggered()
  3572. {
  3573. OBSSceneItem item = GetCurrentSceneItem();
  3574. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_UP);
  3575. }
  3576. void OBSBasic::on_actionSourceDown_triggered()
  3577. {
  3578. OBSSceneItem item = GetCurrentSceneItem();
  3579. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_DOWN);
  3580. }
  3581. void OBSBasic::on_actionMoveUp_triggered()
  3582. {
  3583. OBSSceneItem item = GetCurrentSceneItem();
  3584. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_UP);
  3585. }
  3586. void OBSBasic::on_actionMoveDown_triggered()
  3587. {
  3588. OBSSceneItem item = GetCurrentSceneItem();
  3589. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_DOWN);
  3590. }
  3591. void OBSBasic::on_actionMoveToTop_triggered()
  3592. {
  3593. OBSSceneItem item = GetCurrentSceneItem();
  3594. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_TOP);
  3595. }
  3596. void OBSBasic::on_actionMoveToBottom_triggered()
  3597. {
  3598. OBSSceneItem item = GetCurrentSceneItem();
  3599. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_BOTTOM);
  3600. }
  3601. static BPtr<char> ReadLogFile(const char *subdir, const char *log)
  3602. {
  3603. char logDir[512];
  3604. if (GetConfigPath(logDir, sizeof(logDir), subdir) <= 0)
  3605. return nullptr;
  3606. string path = (char*)logDir;
  3607. path += "/";
  3608. path += log;
  3609. BPtr<char> file = os_quick_read_utf8_file(path.c_str());
  3610. if (!file)
  3611. blog(LOG_WARNING, "Failed to read log file %s", path.c_str());
  3612. return file;
  3613. }
  3614. void OBSBasic::UploadLog(const char *subdir, const char *file)
  3615. {
  3616. BPtr<char> fileString{ReadLogFile(subdir, file)};
  3617. if (!fileString)
  3618. return;
  3619. if (!*fileString)
  3620. return;
  3621. ui->menuLogFiles->setEnabled(false);
  3622. stringstream ss;
  3623. ss << "OBS " << App()->GetVersionString()
  3624. << " log file uploaded at " << CurrentDateTimeString()
  3625. << "\n\n" << fileString;
  3626. if (logUploadThread) {
  3627. logUploadThread->wait();
  3628. }
  3629. RemoteTextThread *thread = new RemoteTextThread(
  3630. "https://obsproject.com/logs/upload",
  3631. "text/plain", ss.str().c_str());
  3632. logUploadThread.reset(thread);
  3633. connect(thread, &RemoteTextThread::Result,
  3634. this, &OBSBasic::logUploadFinished);
  3635. logUploadThread->start();
  3636. }
  3637. void OBSBasic::on_actionShowLogs_triggered()
  3638. {
  3639. char logDir[512];
  3640. if (GetConfigPath(logDir, sizeof(logDir), "obs-studio/logs") <= 0)
  3641. return;
  3642. QUrl url = QUrl::fromLocalFile(QT_UTF8(logDir));
  3643. QDesktopServices::openUrl(url);
  3644. }
  3645. void OBSBasic::on_actionUploadCurrentLog_triggered()
  3646. {
  3647. UploadLog("obs-studio/logs", App()->GetCurrentLog());
  3648. }
  3649. void OBSBasic::on_actionUploadLastLog_triggered()
  3650. {
  3651. UploadLog("obs-studio/logs", App()->GetLastLog());
  3652. }
  3653. void OBSBasic::on_actionViewCurrentLog_triggered()
  3654. {
  3655. char logDir[512];
  3656. if (GetConfigPath(logDir, sizeof(logDir), "obs-studio/logs") <= 0)
  3657. return;
  3658. const char* log = App()->GetCurrentLog();
  3659. string path = (char*)logDir;
  3660. path += "/";
  3661. path += log;
  3662. QUrl url = QUrl::fromLocalFile(QT_UTF8(path.c_str()));
  3663. QDesktopServices::openUrl(url);
  3664. }
  3665. void OBSBasic::on_actionShowCrashLogs_triggered()
  3666. {
  3667. char logDir[512];
  3668. if (GetConfigPath(logDir, sizeof(logDir), "obs-studio/crashes") <= 0)
  3669. return;
  3670. QUrl url = QUrl::fromLocalFile(QT_UTF8(logDir));
  3671. QDesktopServices::openUrl(url);
  3672. }
  3673. void OBSBasic::on_actionUploadLastCrashLog_triggered()
  3674. {
  3675. UploadLog("obs-studio/crashes", App()->GetLastCrashLog());
  3676. }
  3677. void OBSBasic::on_actionCheckForUpdates_triggered()
  3678. {
  3679. CheckForUpdates(true);
  3680. }
  3681. void OBSBasic::logUploadFinished(const QString &text, const QString &error)
  3682. {
  3683. ui->menuLogFiles->setEnabled(true);
  3684. if (text.isEmpty()) {
  3685. OBSMessageBox::information(this,
  3686. QTStr("LogReturnDialog.ErrorUploadingLog"),
  3687. error);
  3688. return;
  3689. }
  3690. obs_data_t *returnData = obs_data_create_from_json(QT_TO_UTF8(text));
  3691. string resURL = obs_data_get_string(returnData, "url");
  3692. QString logURL = resURL.c_str();
  3693. obs_data_release(returnData);
  3694. OBSLogReply logDialog(this, logURL);
  3695. logDialog.exec();
  3696. }
  3697. static void RenameListItem(OBSBasic *parent, QListWidget *listWidget,
  3698. obs_source_t *source, const string &name)
  3699. {
  3700. const char *prevName = obs_source_get_name(source);
  3701. if (name == prevName)
  3702. return;
  3703. obs_source_t *foundSource = obs_get_source_by_name(name.c_str());
  3704. QListWidgetItem *listItem = listWidget->currentItem();
  3705. if (foundSource || name.empty()) {
  3706. listItem->setText(QT_UTF8(prevName));
  3707. if (foundSource) {
  3708. OBSMessageBox::information(parent,
  3709. QTStr("NameExists.Title"),
  3710. QTStr("NameExists.Text"));
  3711. } else if (name.empty()) {
  3712. OBSMessageBox::information(parent,
  3713. QTStr("NoNameEntered.Title"),
  3714. QTStr("NoNameEntered.Text"));
  3715. }
  3716. obs_source_release(foundSource);
  3717. } else {
  3718. listItem->setText(QT_UTF8(name.c_str()));
  3719. obs_source_set_name(source, name.c_str());
  3720. }
  3721. }
  3722. void OBSBasic::SceneNameEdited(QWidget *editor,
  3723. QAbstractItemDelegate::EndEditHint endHint)
  3724. {
  3725. OBSScene scene = GetCurrentScene();
  3726. QLineEdit *edit = qobject_cast<QLineEdit*>(editor);
  3727. string text = QT_TO_UTF8(edit->text().trimmed());
  3728. if (!scene)
  3729. return;
  3730. obs_source_t *source = obs_scene_get_source(scene);
  3731. RenameListItem(this, ui->scenes, source, text);
  3732. if (api)
  3733. api->on_event(OBS_FRONTEND_EVENT_SCENE_LIST_CHANGED);
  3734. UNUSED_PARAMETER(endHint);
  3735. }
  3736. void OBSBasic::OpenFilters()
  3737. {
  3738. OBSSceneItem item = GetCurrentSceneItem();
  3739. OBSSource source = obs_sceneitem_get_source(item);
  3740. CreateFiltersWindow(source);
  3741. }
  3742. void OBSBasic::OpenSceneFilters()
  3743. {
  3744. OBSScene scene = GetCurrentScene();
  3745. OBSSource source = obs_scene_get_source(scene);
  3746. CreateFiltersWindow(source);
  3747. }
  3748. #define RECORDING_START \
  3749. "==== Recording Start ==============================================="
  3750. #define RECORDING_STOP \
  3751. "==== Recording Stop ================================================"
  3752. #define REPLAY_BUFFER_START \
  3753. "==== Replay Buffer Start ==========================================="
  3754. #define REPLAY_BUFFER_STOP \
  3755. "==== Replay Buffer Stop ============================================"
  3756. #define STREAMING_START \
  3757. "==== Streaming Start ==============================================="
  3758. #define STREAMING_STOP \
  3759. "==== Streaming Stop ================================================"
  3760. void OBSBasic::StartStreaming()
  3761. {
  3762. if (outputHandler->StreamingActive())
  3763. return;
  3764. if (disableOutputsRef)
  3765. return;
  3766. if (api)
  3767. api->on_event(OBS_FRONTEND_EVENT_STREAMING_STARTING);
  3768. SaveProject();
  3769. ui->streamButton->setEnabled(false);
  3770. ui->streamButton->setText(QTStr("Basic.Main.Connecting"));
  3771. if (sysTrayStream) {
  3772. sysTrayStream->setEnabled(false);
  3773. sysTrayStream->setText(ui->streamButton->text());
  3774. }
  3775. if (!outputHandler->StartStreaming(service)) {
  3776. ui->streamButton->setText(QTStr("Basic.Main.StartStreaming"));
  3777. ui->streamButton->setEnabled(true);
  3778. ui->streamButton->setChecked(false);
  3779. if (sysTrayStream) {
  3780. sysTrayStream->setText(ui->streamButton->text());
  3781. sysTrayStream->setEnabled(true);
  3782. }
  3783. QMessageBox::critical(this,
  3784. QTStr("Output.StartStreamFailed"),
  3785. QTStr("Output.StartFailedGeneric"));
  3786. return;
  3787. }
  3788. bool recordWhenStreaming = config_get_bool(GetGlobalConfig(),
  3789. "BasicWindow", "RecordWhenStreaming");
  3790. if (recordWhenStreaming)
  3791. StartRecording();
  3792. bool replayBufferWhileStreaming = config_get_bool(GetGlobalConfig(),
  3793. "BasicWindow", "ReplayBufferWhileStreaming");
  3794. if (replayBufferWhileStreaming)
  3795. StartReplayBuffer();
  3796. }
  3797. #ifdef _WIN32
  3798. static inline void UpdateProcessPriority()
  3799. {
  3800. const char *priority = config_get_string(App()->GlobalConfig(),
  3801. "General", "ProcessPriority");
  3802. if (priority && strcmp(priority, "Normal") != 0)
  3803. SetProcessPriority(priority);
  3804. }
  3805. static inline void ClearProcessPriority()
  3806. {
  3807. const char *priority = config_get_string(App()->GlobalConfig(),
  3808. "General", "ProcessPriority");
  3809. if (priority && strcmp(priority, "Normal") != 0)
  3810. SetProcessPriority("Normal");
  3811. }
  3812. #else
  3813. #define UpdateProcessPriority() do {} while(false)
  3814. #define ClearProcessPriority() do {} while(false)
  3815. #endif
  3816. inline void OBSBasic::OnActivate()
  3817. {
  3818. if (ui->profileMenu->isEnabled()) {
  3819. ui->profileMenu->setEnabled(false);
  3820. ui->autoConfigure->setEnabled(false);
  3821. App()->IncrementSleepInhibition();
  3822. UpdateProcessPriority();
  3823. if (trayIcon)
  3824. trayIcon->setIcon(QIcon(":/res/images/tray_active.png"));
  3825. }
  3826. }
  3827. inline void OBSBasic::OnDeactivate()
  3828. {
  3829. if (!outputHandler->Active() && !ui->profileMenu->isEnabled()) {
  3830. ui->profileMenu->setEnabled(true);
  3831. ui->autoConfigure->setEnabled(true);
  3832. App()->DecrementSleepInhibition();
  3833. ClearProcessPriority();
  3834. if (trayIcon)
  3835. trayIcon->setIcon(QIcon(":/res/images/obs.png"));
  3836. }
  3837. }
  3838. void OBSBasic::StopStreaming()
  3839. {
  3840. SaveProject();
  3841. if (outputHandler->StreamingActive())
  3842. outputHandler->StopStreaming(streamingStopping);
  3843. OnDeactivate();
  3844. bool recordWhenStreaming = config_get_bool(GetGlobalConfig(),
  3845. "BasicWindow", "RecordWhenStreaming");
  3846. bool keepRecordingWhenStreamStops = config_get_bool(GetGlobalConfig(),
  3847. "BasicWindow", "KeepRecordingWhenStreamStops");
  3848. if (recordWhenStreaming && !keepRecordingWhenStreamStops)
  3849. StopRecording();
  3850. bool replayBufferWhileStreaming = config_get_bool(GetGlobalConfig(),
  3851. "BasicWindow", "ReplayBufferWhileStreaming");
  3852. bool keepReplayBufferStreamStops = config_get_bool(GetGlobalConfig(),
  3853. "BasicWindow", "KeepReplayBufferStreamStops");
  3854. if (replayBufferWhileStreaming && !keepReplayBufferStreamStops)
  3855. StopReplayBuffer();
  3856. }
  3857. void OBSBasic::ForceStopStreaming()
  3858. {
  3859. SaveProject();
  3860. if (outputHandler->StreamingActive())
  3861. outputHandler->StopStreaming(true);
  3862. OnDeactivate();
  3863. bool recordWhenStreaming = config_get_bool(GetGlobalConfig(),
  3864. "BasicWindow", "RecordWhenStreaming");
  3865. bool keepRecordingWhenStreamStops = config_get_bool(GetGlobalConfig(),
  3866. "BasicWindow", "KeepRecordingWhenStreamStops");
  3867. if (recordWhenStreaming && !keepRecordingWhenStreamStops)
  3868. StopRecording();
  3869. bool replayBufferWhileStreaming = config_get_bool(GetGlobalConfig(),
  3870. "BasicWindow", "ReplayBufferWhileStreaming");
  3871. bool keepReplayBufferStreamStops = config_get_bool(GetGlobalConfig(),
  3872. "BasicWindow", "KeepReplayBufferStreamStops");
  3873. if (replayBufferWhileStreaming && !keepReplayBufferStreamStops)
  3874. StopReplayBuffer();
  3875. }
  3876. void OBSBasic::StreamDelayStarting(int sec)
  3877. {
  3878. ui->streamButton->setText(QTStr("Basic.Main.StopStreaming"));
  3879. ui->streamButton->setEnabled(true);
  3880. ui->streamButton->setChecked(true);
  3881. if (sysTrayStream) {
  3882. sysTrayStream->setText(ui->streamButton->text());
  3883. sysTrayStream->setEnabled(true);
  3884. }
  3885. if (!startStreamMenu.isNull())
  3886. startStreamMenu->deleteLater();
  3887. startStreamMenu = new QMenu();
  3888. startStreamMenu->addAction(QTStr("Basic.Main.StopStreaming"),
  3889. this, SLOT(StopStreaming()));
  3890. startStreamMenu->addAction(QTStr("Basic.Main.ForceStopStreaming"),
  3891. this, SLOT(ForceStopStreaming()));
  3892. ui->streamButton->setMenu(startStreamMenu);
  3893. ui->statusbar->StreamDelayStarting(sec);
  3894. OnActivate();
  3895. }
  3896. void OBSBasic::StreamDelayStopping(int sec)
  3897. {
  3898. ui->streamButton->setText(QTStr("Basic.Main.StartStreaming"));
  3899. ui->streamButton->setEnabled(true);
  3900. ui->streamButton->setChecked(false);
  3901. if (sysTrayStream) {
  3902. sysTrayStream->setText(ui->streamButton->text());
  3903. sysTrayStream->setEnabled(true);
  3904. }
  3905. if (!startStreamMenu.isNull())
  3906. startStreamMenu->deleteLater();
  3907. startStreamMenu = new QMenu();
  3908. startStreamMenu->addAction(QTStr("Basic.Main.StartStreaming"),
  3909. this, SLOT(StartStreaming()));
  3910. startStreamMenu->addAction(QTStr("Basic.Main.ForceStopStreaming"),
  3911. this, SLOT(ForceStopStreaming()));
  3912. ui->streamButton->setMenu(startStreamMenu);
  3913. ui->statusbar->StreamDelayStopping(sec);
  3914. }
  3915. void OBSBasic::StreamingStart()
  3916. {
  3917. ui->streamButton->setText(QTStr("Basic.Main.StopStreaming"));
  3918. ui->streamButton->setEnabled(true);
  3919. ui->streamButton->setChecked(true);
  3920. ui->statusbar->StreamStarted(outputHandler->streamOutput);
  3921. if (sysTrayStream) {
  3922. sysTrayStream->setText(ui->streamButton->text());
  3923. sysTrayStream->setEnabled(true);
  3924. }
  3925. if (api)
  3926. api->on_event(OBS_FRONTEND_EVENT_STREAMING_STARTED);
  3927. OnActivate();
  3928. blog(LOG_INFO, STREAMING_START);
  3929. }
  3930. void OBSBasic::StreamStopping()
  3931. {
  3932. ui->streamButton->setText(QTStr("Basic.Main.StoppingStreaming"));
  3933. if (sysTrayStream)
  3934. sysTrayStream->setText(ui->streamButton->text());
  3935. streamingStopping = true;
  3936. if (api)
  3937. api->on_event(OBS_FRONTEND_EVENT_STREAMING_STOPPING);
  3938. }
  3939. void OBSBasic::StreamingStop(int code, QString last_error)
  3940. {
  3941. const char *errorDescription;
  3942. DStr errorMessage;
  3943. bool use_last_error = false;
  3944. switch (code) {
  3945. case OBS_OUTPUT_BAD_PATH:
  3946. errorDescription = Str("Output.ConnectFail.BadPath");
  3947. break;
  3948. case OBS_OUTPUT_CONNECT_FAILED:
  3949. use_last_error = true;
  3950. errorDescription = Str("Output.ConnectFail.ConnectFailed");
  3951. break;
  3952. case OBS_OUTPUT_INVALID_STREAM:
  3953. errorDescription = Str("Output.ConnectFail.InvalidStream");
  3954. break;
  3955. default:
  3956. case OBS_OUTPUT_ERROR:
  3957. use_last_error = true;
  3958. errorDescription = Str("Output.ConnectFail.Error");
  3959. break;
  3960. case OBS_OUTPUT_DISCONNECTED:
  3961. /* doesn't happen if output is set to reconnect. note that
  3962. * reconnects are handled in the output, not in the UI */
  3963. use_last_error = true;
  3964. errorDescription = Str("Output.ConnectFail.Disconnected");
  3965. }
  3966. if (use_last_error && !last_error.isEmpty())
  3967. dstr_printf(errorMessage, "%s\n\n%s", errorDescription,
  3968. QT_TO_UTF8(last_error));
  3969. else
  3970. dstr_copy(errorMessage, errorDescription);
  3971. ui->statusbar->StreamStopped();
  3972. ui->streamButton->setText(QTStr("Basic.Main.StartStreaming"));
  3973. ui->streamButton->setEnabled(true);
  3974. ui->streamButton->setChecked(false);
  3975. if (sysTrayStream) {
  3976. sysTrayStream->setText(ui->streamButton->text());
  3977. sysTrayStream->setEnabled(true);
  3978. }
  3979. streamingStopping = false;
  3980. if (api)
  3981. api->on_event(OBS_FRONTEND_EVENT_STREAMING_STOPPED);
  3982. OnDeactivate();
  3983. blog(LOG_INFO, STREAMING_STOP);
  3984. if (code != OBS_OUTPUT_SUCCESS && isVisible()) {
  3985. OBSMessageBox::information(this,
  3986. QTStr("Output.ConnectFail.Title"),
  3987. QT_UTF8(errorMessage));
  3988. } else if (code != OBS_OUTPUT_SUCCESS && !isVisible()) {
  3989. SysTrayNotify(QT_UTF8(errorDescription), QSystemTrayIcon::Warning);
  3990. }
  3991. if (!startStreamMenu.isNull()) {
  3992. ui->streamButton->setMenu(nullptr);
  3993. startStreamMenu->deleteLater();
  3994. startStreamMenu = nullptr;
  3995. }
  3996. }
  3997. void OBSBasic::StartRecording()
  3998. {
  3999. if (outputHandler->RecordingActive())
  4000. return;
  4001. if (disableOutputsRef)
  4002. return;
  4003. if (api)
  4004. api->on_event(OBS_FRONTEND_EVENT_RECORDING_STARTING);
  4005. SaveProject();
  4006. if (!outputHandler->StartRecording())
  4007. ui->recordButton->setChecked(false);
  4008. }
  4009. void OBSBasic::RecordStopping()
  4010. {
  4011. ui->recordButton->setText(QTStr("Basic.Main.StoppingRecording"));
  4012. if (sysTrayRecord)
  4013. sysTrayRecord->setText(ui->recordButton->text());
  4014. recordingStopping = true;
  4015. if (api)
  4016. api->on_event(OBS_FRONTEND_EVENT_RECORDING_STOPPING);
  4017. }
  4018. void OBSBasic::StopRecording()
  4019. {
  4020. SaveProject();
  4021. if (outputHandler->RecordingActive())
  4022. outputHandler->StopRecording(recordingStopping);
  4023. OnDeactivate();
  4024. }
  4025. void OBSBasic::RecordingStart()
  4026. {
  4027. ui->statusbar->RecordingStarted(outputHandler->fileOutput);
  4028. ui->recordButton->setText(QTStr("Basic.Main.StopRecording"));
  4029. ui->recordButton->setChecked(true);
  4030. if (sysTrayRecord)
  4031. sysTrayRecord->setText(ui->recordButton->text());
  4032. recordingStopping = false;
  4033. if (api)
  4034. api->on_event(OBS_FRONTEND_EVENT_RECORDING_STARTED);
  4035. OnActivate();
  4036. blog(LOG_INFO, RECORDING_START);
  4037. }
  4038. void OBSBasic::RecordingStop(int code)
  4039. {
  4040. ui->statusbar->RecordingStopped();
  4041. ui->recordButton->setText(QTStr("Basic.Main.StartRecording"));
  4042. ui->recordButton->setChecked(false);
  4043. if (sysTrayRecord)
  4044. sysTrayRecord->setText(ui->recordButton->text());
  4045. blog(LOG_INFO, RECORDING_STOP);
  4046. if (code == OBS_OUTPUT_UNSUPPORTED && isVisible()) {
  4047. OBSMessageBox::information(this,
  4048. QTStr("Output.RecordFail.Title"),
  4049. QTStr("Output.RecordFail.Unsupported"));
  4050. } else if (code == OBS_OUTPUT_NO_SPACE && isVisible()) {
  4051. OBSMessageBox::information(this,
  4052. QTStr("Output.RecordNoSpace.Title"),
  4053. QTStr("Output.RecordNoSpace.Msg"));
  4054. } else if (code != OBS_OUTPUT_SUCCESS && isVisible()) {
  4055. OBSMessageBox::information(this,
  4056. QTStr("Output.RecordError.Title"),
  4057. QTStr("Output.RecordError.Msg"));
  4058. } else if (code == OBS_OUTPUT_UNSUPPORTED && !isVisible()) {
  4059. SysTrayNotify(QTStr("Output.RecordFail.Unsupported"),
  4060. QSystemTrayIcon::Warning);
  4061. } else if (code == OBS_OUTPUT_NO_SPACE && !isVisible()) {
  4062. SysTrayNotify(QTStr("Output.RecordNoSpace.Msg"),
  4063. QSystemTrayIcon::Warning);
  4064. } else if (code != OBS_OUTPUT_SUCCESS && !isVisible()) {
  4065. SysTrayNotify(QTStr("Output.RecordError.Msg"),
  4066. QSystemTrayIcon::Warning);
  4067. }
  4068. if (api)
  4069. api->on_event(OBS_FRONTEND_EVENT_RECORDING_STOPPED);
  4070. OnDeactivate();
  4071. }
  4072. #define RP_NO_HOTKEY_TITLE QTStr("Output.ReplayBuffer.NoHotkey.Title")
  4073. #define RP_NO_HOTKEY_TEXT QTStr("Output.ReplayBuffer.NoHotkey.Msg")
  4074. void OBSBasic::StartReplayBuffer()
  4075. {
  4076. if (!outputHandler || !outputHandler->replayBuffer)
  4077. return;
  4078. if (outputHandler->ReplayBufferActive())
  4079. return;
  4080. if (disableOutputsRef)
  4081. return;
  4082. if (!NoSourcesConfirmation()) {
  4083. replayBufferButton->setChecked(false);
  4084. return;
  4085. }
  4086. obs_output_t *output = outputHandler->replayBuffer;
  4087. obs_data_t *hotkeys = obs_hotkeys_save_output(output);
  4088. obs_data_array_t *bindings = obs_data_get_array(hotkeys,
  4089. "ReplayBuffer.Save");
  4090. size_t count = obs_data_array_count(bindings);
  4091. obs_data_array_release(bindings);
  4092. obs_data_release(hotkeys);
  4093. if (!count) {
  4094. OBSMessageBox::information(this,
  4095. RP_NO_HOTKEY_TITLE,
  4096. RP_NO_HOTKEY_TEXT);
  4097. return;
  4098. }
  4099. if (api)
  4100. api->on_event(OBS_FRONTEND_EVENT_REPLAY_BUFFER_STARTING);
  4101. SaveProject();
  4102. if (!outputHandler->StartReplayBuffer())
  4103. replayBufferButton->setChecked(false);
  4104. }
  4105. void OBSBasic::ReplayBufferStopping()
  4106. {
  4107. if (!outputHandler || !outputHandler->replayBuffer)
  4108. return;
  4109. replayBufferButton->setText(QTStr("Basic.Main.StoppingReplayBuffer"));
  4110. if (sysTrayReplayBuffer)
  4111. sysTrayReplayBuffer->setText(replayBufferButton->text());
  4112. replayBufferStopping = true;
  4113. if (api)
  4114. api->on_event(OBS_FRONTEND_EVENT_REPLAY_BUFFER_STOPPING);
  4115. }
  4116. void OBSBasic::StopReplayBuffer()
  4117. {
  4118. if (!outputHandler || !outputHandler->replayBuffer)
  4119. return;
  4120. SaveProject();
  4121. if (outputHandler->ReplayBufferActive())
  4122. outputHandler->StopReplayBuffer(replayBufferStopping);
  4123. OnDeactivate();
  4124. }
  4125. void OBSBasic::ReplayBufferStart()
  4126. {
  4127. if (!outputHandler || !outputHandler->replayBuffer)
  4128. return;
  4129. replayBufferButton->setText(QTStr("Basic.Main.StopReplayBuffer"));
  4130. if (sysTrayReplayBuffer)
  4131. sysTrayReplayBuffer->setText(replayBufferButton->text());
  4132. replayBufferStopping = false;
  4133. if (api)
  4134. api->on_event(OBS_FRONTEND_EVENT_REPLAY_BUFFER_STARTED);
  4135. OnActivate();
  4136. blog(LOG_INFO, REPLAY_BUFFER_START);
  4137. }
  4138. void OBSBasic::ReplayBufferSave()
  4139. {
  4140. if (!outputHandler || !outputHandler->replayBuffer)
  4141. return;
  4142. if (!outputHandler->ReplayBufferActive())
  4143. return;
  4144. calldata_t cd = {0};
  4145. proc_handler_t *ph = obs_output_get_proc_handler(
  4146. outputHandler->replayBuffer);
  4147. proc_handler_call(ph, "save", &cd);
  4148. calldata_free(&cd);
  4149. }
  4150. void OBSBasic::ReplayBufferStop(int code)
  4151. {
  4152. if (!outputHandler || !outputHandler->replayBuffer)
  4153. return;
  4154. replayBufferButton->setText(QTStr("Basic.Main.StartReplayBuffer"));
  4155. if (sysTrayReplayBuffer)
  4156. sysTrayReplayBuffer->setText(replayBufferButton->text());
  4157. blog(LOG_INFO, REPLAY_BUFFER_STOP);
  4158. if (code == OBS_OUTPUT_UNSUPPORTED && isVisible()) {
  4159. OBSMessageBox::information(this,
  4160. QTStr("Output.RecordFail.Title"),
  4161. QTStr("Output.RecordFail.Unsupported"));
  4162. } else if (code == OBS_OUTPUT_NO_SPACE && isVisible()) {
  4163. OBSMessageBox::information(this,
  4164. QTStr("Output.RecordNoSpace.Title"),
  4165. QTStr("Output.RecordNoSpace.Msg"));
  4166. } else if (code != OBS_OUTPUT_SUCCESS && isVisible()) {
  4167. OBSMessageBox::information(this,
  4168. QTStr("Output.RecordError.Title"),
  4169. QTStr("Output.RecordError.Msg"));
  4170. } else if (code == OBS_OUTPUT_UNSUPPORTED && !isVisible()) {
  4171. SysTrayNotify(QTStr("Output.RecordFail.Unsupported"),
  4172. QSystemTrayIcon::Warning);
  4173. } else if (code == OBS_OUTPUT_NO_SPACE && !isVisible()) {
  4174. SysTrayNotify(QTStr("Output.RecordNoSpace.Msg"),
  4175. QSystemTrayIcon::Warning);
  4176. } else if (code != OBS_OUTPUT_SUCCESS && !isVisible()) {
  4177. SysTrayNotify(QTStr("Output.RecordError.Msg"),
  4178. QSystemTrayIcon::Warning);
  4179. }
  4180. if (api)
  4181. api->on_event(OBS_FRONTEND_EVENT_REPLAY_BUFFER_STOPPED);
  4182. OnDeactivate();
  4183. }
  4184. bool OBSBasic::NoSourcesConfirmation()
  4185. {
  4186. if (CountVideoSources() == 0 && isVisible()) {
  4187. QString msg;
  4188. msg = QTStr("NoSources.Text");
  4189. msg += "\n\n";
  4190. msg += QTStr("NoSources.Text.AddSource");
  4191. QMessageBox messageBox(QMessageBox::Question,
  4192. QTStr("NoSources.title"),
  4193. msg,
  4194. QMessageBox::Yes | QMessageBox::No,
  4195. this);
  4196. messageBox.setDefaultButton(QMessageBox::No);
  4197. if (QMessageBox::No == messageBox.exec())
  4198. return false;
  4199. }
  4200. return true;
  4201. }
  4202. void OBSBasic::on_streamButton_clicked()
  4203. {
  4204. if (outputHandler->StreamingActive()) {
  4205. bool confirm = config_get_bool(GetGlobalConfig(), "BasicWindow",
  4206. "WarnBeforeStoppingStream");
  4207. if (confirm && isVisible()) {
  4208. QMessageBox::StandardButton button =
  4209. OBSMessageBox::question(this,
  4210. QTStr("ConfirmStop.Title"),
  4211. QTStr("ConfirmStop.Text"));
  4212. if (button == QMessageBox::No) {
  4213. ui->streamButton->setChecked(true);
  4214. return;
  4215. }
  4216. }
  4217. StopStreaming();
  4218. } else {
  4219. if (!NoSourcesConfirmation()) {
  4220. ui->streamButton->setChecked(false);
  4221. return;
  4222. }
  4223. bool confirm = config_get_bool(GetGlobalConfig(), "BasicWindow",
  4224. "WarnBeforeStartingStream");
  4225. if (confirm && isVisible()) {
  4226. QMessageBox::StandardButton button =
  4227. OBSMessageBox::question(this,
  4228. QTStr("ConfirmStart.Title"),
  4229. QTStr("ConfirmStart.Text"));
  4230. if (button == QMessageBox::No) {
  4231. ui->streamButton->setChecked(false);
  4232. return;
  4233. }
  4234. }
  4235. StartStreaming();
  4236. }
  4237. }
  4238. void OBSBasic::on_recordButton_clicked()
  4239. {
  4240. if (outputHandler->RecordingActive()) {
  4241. StopRecording();
  4242. } else {
  4243. if (!NoSourcesConfirmation()) {
  4244. ui->recordButton->setChecked(false);
  4245. return;
  4246. }
  4247. StartRecording();
  4248. }
  4249. }
  4250. void OBSBasic::on_settingsButton_clicked()
  4251. {
  4252. on_action_Settings_triggered();
  4253. }
  4254. void OBSBasic::on_actionHelpPortal_triggered()
  4255. {
  4256. QUrl url = QUrl("https://obsproject.com/help", QUrl::TolerantMode);
  4257. QDesktopServices::openUrl(url);
  4258. }
  4259. void OBSBasic::on_actionWebsite_triggered()
  4260. {
  4261. QUrl url = QUrl("https://obsproject.com", QUrl::TolerantMode);
  4262. QDesktopServices::openUrl(url);
  4263. }
  4264. void OBSBasic::on_actionDiscord_triggered()
  4265. {
  4266. QUrl url = QUrl("https://obsproject.com/discord", QUrl::TolerantMode);
  4267. QDesktopServices::openUrl(url);
  4268. }
  4269. void OBSBasic::on_actionShowSettingsFolder_triggered()
  4270. {
  4271. char path[512];
  4272. int ret = GetConfigPath(path, 512, "obs-studio");
  4273. if (ret <= 0)
  4274. return;
  4275. QDesktopServices::openUrl(QUrl::fromLocalFile(path));
  4276. }
  4277. void OBSBasic::on_actionShowProfileFolder_triggered()
  4278. {
  4279. char path[512];
  4280. int ret = GetProfilePath(path, 512, "");
  4281. if (ret <= 0)
  4282. return;
  4283. QDesktopServices::openUrl(QUrl::fromLocalFile(path));
  4284. }
  4285. int OBSBasic::GetTopSelectedSourceItem()
  4286. {
  4287. QModelIndexList selectedItems =
  4288. ui->sources->selectionModel()->selectedIndexes();
  4289. return selectedItems.count() ? selectedItems[0].row() : -1;
  4290. }
  4291. void OBSBasic::on_preview_customContextMenuRequested(const QPoint &pos)
  4292. {
  4293. CreateSourcePopupMenu(GetTopSelectedSourceItem(), true);
  4294. UNUSED_PARAMETER(pos);
  4295. }
  4296. void OBSBasic::on_program_customContextMenuRequested(const QPoint&)
  4297. {
  4298. QMenu popup(this);
  4299. QPointer<QMenu> studioProgramProjector;
  4300. studioProgramProjector = new QMenu(
  4301. QTStr("StudioProgramProjector"));
  4302. AddProjectorMenuMonitors(studioProgramProjector, this,
  4303. SLOT(OpenStudioProgramProjector()));
  4304. popup.addMenu(studioProgramProjector);
  4305. QAction *studioProgramWindow = popup.addAction(
  4306. QTStr("StudioProgramWindow"),
  4307. this, SLOT(OpenStudioProgramWindow()));
  4308. popup.addAction(studioProgramWindow);
  4309. popup.exec(QCursor::pos());
  4310. }
  4311. void OBSBasic::on_previewDisabledLabel_customContextMenuRequested(
  4312. const QPoint &pos)
  4313. {
  4314. QMenu popup(this);
  4315. QPointer<QMenu> previewProjector;
  4316. QAction *action = popup.addAction(
  4317. QTStr("Basic.Main.PreviewConextMenu.Enable"),
  4318. this, SLOT(TogglePreview()));
  4319. action->setCheckable(true);
  4320. action->setChecked(obs_display_enabled(ui->preview->GetDisplay()));
  4321. previewProjector = new QMenu(QTStr("PreviewProjector"));
  4322. AddProjectorMenuMonitors(previewProjector, this,
  4323. SLOT(OpenPreviewProjector()));
  4324. QAction *previewWindow = popup.addAction(
  4325. QTStr("PreviewWindow"),
  4326. this, SLOT(OpenPreviewWindow()));
  4327. popup.addMenu(previewProjector);
  4328. popup.addAction(previewWindow);
  4329. popup.exec(QCursor::pos());
  4330. UNUSED_PARAMETER(pos);
  4331. }
  4332. void OBSBasic::on_actionAlwaysOnTop_triggered()
  4333. {
  4334. #ifndef _WIN32
  4335. /* Make sure all dialogs are safely and successfully closed before
  4336. * switching the always on top mode due to the fact that windows all
  4337. * have to be recreated, so queue the actual toggle to happen after
  4338. * all events related to closing the dialogs have finished */
  4339. CloseDialogs();
  4340. #endif
  4341. QMetaObject::invokeMethod(this, "ToggleAlwaysOnTop",
  4342. Qt::QueuedConnection);
  4343. }
  4344. void OBSBasic::ToggleAlwaysOnTop()
  4345. {
  4346. bool isAlwaysOnTop = IsAlwaysOnTop(this);
  4347. ui->actionAlwaysOnTop->setChecked(!isAlwaysOnTop);
  4348. SetAlwaysOnTop(this, !isAlwaysOnTop);
  4349. show();
  4350. }
  4351. void OBSBasic::GetFPSCommon(uint32_t &num, uint32_t &den) const
  4352. {
  4353. const char *val = config_get_string(basicConfig, "Video", "FPSCommon");
  4354. if (strcmp(val, "10") == 0) {
  4355. num = 10;
  4356. den = 1;
  4357. } else if (strcmp(val, "20") == 0) {
  4358. num = 20;
  4359. den = 1;
  4360. } else if (strcmp(val, "24 NTSC") == 0) {
  4361. num = 24000;
  4362. den = 1001;
  4363. } else if (strcmp(val, "25") == 0) {
  4364. num = 25;
  4365. den = 1;
  4366. } else if (strcmp(val, "29.97") == 0) {
  4367. num = 30000;
  4368. den = 1001;
  4369. } else if (strcmp(val, "48") == 0) {
  4370. num = 48;
  4371. den = 1;
  4372. } else if (strcmp(val, "59.94") == 0) {
  4373. num = 60000;
  4374. den = 1001;
  4375. } else if (strcmp(val, "60") == 0) {
  4376. num = 60;
  4377. den = 1;
  4378. } else {
  4379. num = 30;
  4380. den = 1;
  4381. }
  4382. }
  4383. void OBSBasic::GetFPSInteger(uint32_t &num, uint32_t &den) const
  4384. {
  4385. num = (uint32_t)config_get_uint(basicConfig, "Video", "FPSInt");
  4386. den = 1;
  4387. }
  4388. void OBSBasic::GetFPSFraction(uint32_t &num, uint32_t &den) const
  4389. {
  4390. num = (uint32_t)config_get_uint(basicConfig, "Video", "FPSNum");
  4391. den = (uint32_t)config_get_uint(basicConfig, "Video", "FPSDen");
  4392. }
  4393. void OBSBasic::GetFPSNanoseconds(uint32_t &num, uint32_t &den) const
  4394. {
  4395. num = 1000000000;
  4396. den = (uint32_t)config_get_uint(basicConfig, "Video", "FPSNS");
  4397. }
  4398. void OBSBasic::GetConfigFPS(uint32_t &num, uint32_t &den) const
  4399. {
  4400. uint32_t type = config_get_uint(basicConfig, "Video", "FPSType");
  4401. if (type == 1) //"Integer"
  4402. GetFPSInteger(num, den);
  4403. else if (type == 2) //"Fraction"
  4404. GetFPSFraction(num, den);
  4405. else if (false) //"Nanoseconds", currently not implemented
  4406. GetFPSNanoseconds(num, den);
  4407. else
  4408. GetFPSCommon(num, den);
  4409. }
  4410. config_t *OBSBasic::Config() const
  4411. {
  4412. return basicConfig;
  4413. }
  4414. void OBSBasic::on_actionEditTransform_triggered()
  4415. {
  4416. if (transformWindow)
  4417. transformWindow->close();
  4418. transformWindow = new OBSBasicTransform(this);
  4419. transformWindow->show();
  4420. transformWindow->setAttribute(Qt::WA_DeleteOnClose, true);
  4421. }
  4422. static obs_transform_info copiedTransformInfo;
  4423. static obs_sceneitem_crop copiedCropInfo;
  4424. void OBSBasic::on_actionCopyTransform_triggered()
  4425. {
  4426. auto func = [](obs_scene_t *scene, obs_sceneitem_t *item, void *param)
  4427. {
  4428. if (!obs_sceneitem_selected(item))
  4429. return true;
  4430. obs_sceneitem_defer_update_begin(item);
  4431. obs_sceneitem_get_info(item, &copiedTransformInfo);
  4432. obs_sceneitem_get_crop(item, &copiedCropInfo);
  4433. obs_sceneitem_defer_update_end(item);
  4434. UNUSED_PARAMETER(scene);
  4435. UNUSED_PARAMETER(param);
  4436. return true;
  4437. };
  4438. obs_scene_enum_items(GetCurrentScene(), func, nullptr);
  4439. ui->actionPasteTransform->setEnabled(true);
  4440. }
  4441. void OBSBasic::on_actionPasteTransform_triggered()
  4442. {
  4443. auto func = [](obs_scene_t *scene, obs_sceneitem_t *item, void *param)
  4444. {
  4445. if (!obs_sceneitem_selected(item))
  4446. return true;
  4447. obs_sceneitem_defer_update_begin(item);
  4448. obs_sceneitem_set_info(item, &copiedTransformInfo);
  4449. obs_sceneitem_set_crop(item, &copiedCropInfo);
  4450. obs_sceneitem_defer_update_end(item);
  4451. UNUSED_PARAMETER(scene);
  4452. UNUSED_PARAMETER(param);
  4453. return true;
  4454. };
  4455. obs_scene_enum_items(GetCurrentScene(), func, nullptr);
  4456. }
  4457. static bool reset_tr(obs_scene_t *scene, obs_sceneitem_t *item, void *param)
  4458. {
  4459. if (obs_sceneitem_is_group(item))
  4460. obs_sceneitem_group_enum_items(item, reset_tr, nullptr);
  4461. if (!obs_sceneitem_selected(item))
  4462. return true;
  4463. obs_sceneitem_defer_update_begin(item);
  4464. obs_transform_info info;
  4465. vec2_set(&info.pos, 0.0f, 0.0f);
  4466. vec2_set(&info.scale, 1.0f, 1.0f);
  4467. info.rot = 0.0f;
  4468. info.alignment = OBS_ALIGN_TOP | OBS_ALIGN_LEFT;
  4469. info.bounds_type = OBS_BOUNDS_NONE;
  4470. info.bounds_alignment = OBS_ALIGN_CENTER;
  4471. vec2_set(&info.bounds, 0.0f, 0.0f);
  4472. obs_sceneitem_set_info(item, &info);
  4473. obs_sceneitem_crop crop = {};
  4474. obs_sceneitem_set_crop(item, &crop);
  4475. obs_sceneitem_defer_update_end(item);
  4476. UNUSED_PARAMETER(scene);
  4477. UNUSED_PARAMETER(param);
  4478. return true;
  4479. }
  4480. void OBSBasic::on_actionResetTransform_triggered()
  4481. {
  4482. obs_scene_enum_items(GetCurrentScene(), reset_tr, nullptr);
  4483. }
  4484. static void GetItemBox(obs_sceneitem_t *item, vec3 &tl, vec3 &br)
  4485. {
  4486. matrix4 boxTransform;
  4487. obs_sceneitem_get_box_transform(item, &boxTransform);
  4488. vec3_set(&tl, M_INFINITE, M_INFINITE, 0.0f);
  4489. vec3_set(&br, -M_INFINITE, -M_INFINITE, 0.0f);
  4490. auto GetMinPos = [&] (float x, float y)
  4491. {
  4492. vec3 pos;
  4493. vec3_set(&pos, x, y, 0.0f);
  4494. vec3_transform(&pos, &pos, &boxTransform);
  4495. vec3_min(&tl, &tl, &pos);
  4496. vec3_max(&br, &br, &pos);
  4497. };
  4498. GetMinPos(0.0f, 0.0f);
  4499. GetMinPos(1.0f, 0.0f);
  4500. GetMinPos(0.0f, 1.0f);
  4501. GetMinPos(1.0f, 1.0f);
  4502. }
  4503. static vec3 GetItemTL(obs_sceneitem_t *item)
  4504. {
  4505. vec3 tl, br;
  4506. GetItemBox(item, tl, br);
  4507. return tl;
  4508. }
  4509. static void SetItemTL(obs_sceneitem_t *item, const vec3 &tl)
  4510. {
  4511. vec3 newTL;
  4512. vec2 pos;
  4513. obs_sceneitem_get_pos(item, &pos);
  4514. newTL = GetItemTL(item);
  4515. pos.x += tl.x - newTL.x;
  4516. pos.y += tl.y - newTL.y;
  4517. obs_sceneitem_set_pos(item, &pos);
  4518. }
  4519. static bool RotateSelectedSources(obs_scene_t *scene, obs_sceneitem_t *item,
  4520. void *param)
  4521. {
  4522. if (obs_sceneitem_is_group(item))
  4523. obs_sceneitem_group_enum_items(item, RotateSelectedSources,
  4524. param);
  4525. if (!obs_sceneitem_selected(item))
  4526. return true;
  4527. float rot = *reinterpret_cast<float*>(param);
  4528. vec3 tl = GetItemTL(item);
  4529. rot += obs_sceneitem_get_rot(item);
  4530. if (rot >= 360.0f) rot -= 360.0f;
  4531. else if (rot <= -360.0f) rot += 360.0f;
  4532. obs_sceneitem_set_rot(item, rot);
  4533. obs_sceneitem_force_update_transform(item);
  4534. SetItemTL(item, tl);
  4535. UNUSED_PARAMETER(scene);
  4536. return true;
  4537. };
  4538. void OBSBasic::on_actionRotate90CW_triggered()
  4539. {
  4540. float f90CW = 90.0f;
  4541. obs_scene_enum_items(GetCurrentScene(), RotateSelectedSources, &f90CW);
  4542. }
  4543. void OBSBasic::on_actionRotate90CCW_triggered()
  4544. {
  4545. float f90CCW = -90.0f;
  4546. obs_scene_enum_items(GetCurrentScene(), RotateSelectedSources, &f90CCW);
  4547. }
  4548. void OBSBasic::on_actionRotate180_triggered()
  4549. {
  4550. float f180 = 180.0f;
  4551. obs_scene_enum_items(GetCurrentScene(), RotateSelectedSources, &f180);
  4552. }
  4553. static bool MultiplySelectedItemScale(obs_scene_t *scene, obs_sceneitem_t *item,
  4554. void *param)
  4555. {
  4556. vec2 &mul = *reinterpret_cast<vec2*>(param);
  4557. if (obs_sceneitem_is_group(item))
  4558. obs_sceneitem_group_enum_items(item, MultiplySelectedItemScale,
  4559. param);
  4560. if (!obs_sceneitem_selected(item))
  4561. return true;
  4562. vec3 tl = GetItemTL(item);
  4563. vec2 scale;
  4564. obs_sceneitem_get_scale(item, &scale);
  4565. vec2_mul(&scale, &scale, &mul);
  4566. obs_sceneitem_set_scale(item, &scale);
  4567. obs_sceneitem_force_update_transform(item);
  4568. SetItemTL(item, tl);
  4569. UNUSED_PARAMETER(scene);
  4570. return true;
  4571. }
  4572. void OBSBasic::on_actionFlipHorizontal_triggered()
  4573. {
  4574. vec2 scale;
  4575. vec2_set(&scale, -1.0f, 1.0f);
  4576. obs_scene_enum_items(GetCurrentScene(), MultiplySelectedItemScale,
  4577. &scale);
  4578. }
  4579. void OBSBasic::on_actionFlipVertical_triggered()
  4580. {
  4581. vec2 scale;
  4582. vec2_set(&scale, 1.0f, -1.0f);
  4583. obs_scene_enum_items(GetCurrentScene(), MultiplySelectedItemScale,
  4584. &scale);
  4585. }
  4586. static bool CenterAlignSelectedItems(obs_scene_t *scene, obs_sceneitem_t *item,
  4587. void *param)
  4588. {
  4589. obs_bounds_type boundsType = *reinterpret_cast<obs_bounds_type*>(param);
  4590. if (obs_sceneitem_is_group(item))
  4591. obs_sceneitem_group_enum_items(item, CenterAlignSelectedItems,
  4592. param);
  4593. if (!obs_sceneitem_selected(item))
  4594. return true;
  4595. obs_video_info ovi;
  4596. obs_get_video_info(&ovi);
  4597. obs_transform_info itemInfo;
  4598. vec2_set(&itemInfo.pos, 0.0f, 0.0f);
  4599. vec2_set(&itemInfo.scale, 1.0f, 1.0f);
  4600. itemInfo.alignment = OBS_ALIGN_LEFT | OBS_ALIGN_TOP;
  4601. itemInfo.rot = 0.0f;
  4602. vec2_set(&itemInfo.bounds,
  4603. float(ovi.base_width), float(ovi.base_height));
  4604. itemInfo.bounds_type = boundsType;
  4605. itemInfo.bounds_alignment = OBS_ALIGN_CENTER;
  4606. obs_sceneitem_set_info(item, &itemInfo);
  4607. UNUSED_PARAMETER(scene);
  4608. return true;
  4609. }
  4610. void OBSBasic::on_actionFitToScreen_triggered()
  4611. {
  4612. obs_bounds_type boundsType = OBS_BOUNDS_SCALE_INNER;
  4613. obs_scene_enum_items(GetCurrentScene(), CenterAlignSelectedItems,
  4614. &boundsType);
  4615. }
  4616. void OBSBasic::on_actionStretchToScreen_triggered()
  4617. {
  4618. obs_bounds_type boundsType = OBS_BOUNDS_STRETCH;
  4619. obs_scene_enum_items(GetCurrentScene(), CenterAlignSelectedItems,
  4620. &boundsType);
  4621. }
  4622. static bool center_to_scene(obs_scene_t *, obs_sceneitem_t *item, void *)
  4623. {
  4624. vec3 tl, br, itemCenter, screenCenter, offset;
  4625. obs_video_info ovi;
  4626. if (obs_sceneitem_is_group(item))
  4627. obs_sceneitem_group_enum_items(item, center_to_scene, nullptr);
  4628. if (!obs_sceneitem_selected(item))
  4629. return true;
  4630. obs_get_video_info(&ovi);
  4631. vec3_set(&screenCenter, float(ovi.base_width),
  4632. float(ovi.base_height), 0.0f);
  4633. vec3_mulf(&screenCenter, &screenCenter, 0.5f);
  4634. GetItemBox(item, tl, br);
  4635. vec3_sub(&itemCenter, &br, &tl);
  4636. vec3_mulf(&itemCenter, &itemCenter, 0.5f);
  4637. vec3_add(&itemCenter, &itemCenter, &tl);
  4638. vec3_sub(&offset, &screenCenter, &itemCenter);
  4639. vec3_add(&tl, &tl, &offset);
  4640. SetItemTL(item, tl);
  4641. return true;
  4642. };
  4643. void OBSBasic::on_actionCenterToScreen_triggered()
  4644. {
  4645. obs_scene_enum_items(GetCurrentScene(), center_to_scene, nullptr);
  4646. }
  4647. void OBSBasic::EnablePreviewDisplay(bool enable)
  4648. {
  4649. obs_display_set_enabled(ui->preview->GetDisplay(), enable);
  4650. ui->preview->setVisible(enable);
  4651. ui->previewDisabledLabel->setVisible(!enable);
  4652. }
  4653. void OBSBasic::TogglePreview()
  4654. {
  4655. previewEnabled = !previewEnabled;
  4656. EnablePreviewDisplay(previewEnabled);
  4657. }
  4658. static bool nudge_callback(obs_scene_t*, obs_sceneitem_t *item, void *param)
  4659. {
  4660. if (obs_sceneitem_locked(item))
  4661. return true;
  4662. struct vec2 &offset = *reinterpret_cast<struct vec2*>(param);
  4663. struct vec2 pos;
  4664. if (!obs_sceneitem_selected(item)) {
  4665. if (obs_sceneitem_is_group(item)) {
  4666. struct vec3 offset3;
  4667. vec3_set(&offset3, offset.x, offset.y, 0.0f);
  4668. struct matrix4 matrix;
  4669. obs_sceneitem_get_draw_transform(item, &matrix);
  4670. vec4_set(&matrix.t, 0.0f, 0.0f, 0.0f, 1.0f);
  4671. matrix4_inv(&matrix, &matrix);
  4672. vec3_transform(&offset3, &offset3, &matrix);
  4673. struct vec2 new_offset;
  4674. vec2_set(&new_offset, offset3.x, offset3.y);
  4675. obs_sceneitem_group_enum_items(item, nudge_callback,
  4676. &new_offset);
  4677. }
  4678. return true;
  4679. }
  4680. obs_sceneitem_get_pos(item, &pos);
  4681. vec2_add(&pos, &pos, &offset);
  4682. obs_sceneitem_set_pos(item, &pos);
  4683. return true;
  4684. }
  4685. void OBSBasic::Nudge(int dist, MoveDir dir)
  4686. {
  4687. if (ui->preview->Locked())
  4688. return;
  4689. struct vec2 offset;
  4690. vec2_set(&offset, 0.0f, 0.0f);
  4691. switch (dir) {
  4692. case MoveDir::Up: offset.y = (float)-dist; break;
  4693. case MoveDir::Down: offset.y = (float) dist; break;
  4694. case MoveDir::Left: offset.x = (float)-dist; break;
  4695. case MoveDir::Right: offset.x = (float) dist; break;
  4696. }
  4697. obs_scene_enum_items(GetCurrentScene(), nudge_callback, &offset);
  4698. }
  4699. void OBSBasic::NudgeUp() {Nudge(1, MoveDir::Up);}
  4700. void OBSBasic::NudgeDown() {Nudge(1, MoveDir::Down);}
  4701. void OBSBasic::NudgeLeft() {Nudge(1, MoveDir::Left);}
  4702. void OBSBasic::NudgeRight() {Nudge(1, MoveDir::Right);}
  4703. OBSProjector *OBSBasic::OpenProjector(obs_source_t *source, int monitor,
  4704. QString title, ProjectorType type)
  4705. {
  4706. /* seriously? 10 monitors? */
  4707. if (monitor > 9 || monitor > QGuiApplication::screens().size() - 1)
  4708. return nullptr;
  4709. OBSProjector *projector = new OBSProjector(nullptr, source, monitor,
  4710. title, type);
  4711. if (monitor < 0) {
  4712. for (auto &projPtr : windowProjectors) {
  4713. if (!projPtr) {
  4714. projPtr = projector;
  4715. projector = nullptr;
  4716. }
  4717. }
  4718. if (projector)
  4719. windowProjectors.push_back(projector);
  4720. } else {
  4721. delete projectors[monitor];
  4722. projectors[monitor].clear();
  4723. projectors[monitor] = projector;
  4724. }
  4725. return projector;
  4726. }
  4727. void OBSBasic::OpenStudioProgramProjector()
  4728. {
  4729. int monitor = sender()->property("monitor").toInt();
  4730. OpenProjector(nullptr, monitor, nullptr, ProjectorType::StudioProgram);
  4731. }
  4732. void OBSBasic::OpenPreviewProjector()
  4733. {
  4734. int monitor = sender()->property("monitor").toInt();
  4735. OpenProjector(nullptr, monitor, nullptr, ProjectorType::Preview);
  4736. }
  4737. void OBSBasic::OpenSourceProjector()
  4738. {
  4739. int monitor = sender()->property("monitor").toInt();
  4740. OBSSceneItem item = GetCurrentSceneItem();
  4741. if (!item)
  4742. return;
  4743. OpenProjector(obs_sceneitem_get_source(item), monitor, nullptr,
  4744. ProjectorType::Source);
  4745. }
  4746. void OBSBasic::OpenMultiviewProjector()
  4747. {
  4748. int monitor = sender()->property("monitor").toInt();
  4749. OpenProjector(nullptr, monitor, nullptr, ProjectorType::Multiview);
  4750. }
  4751. void OBSBasic::OpenSceneProjector()
  4752. {
  4753. int monitor = sender()->property("monitor").toInt();
  4754. OBSScene scene = GetCurrentScene();
  4755. if (!scene)
  4756. return;
  4757. OpenProjector(obs_scene_get_source(scene), monitor, nullptr,
  4758. ProjectorType::Scene);
  4759. }
  4760. void OBSBasic::OpenStudioProgramWindow()
  4761. {
  4762. OpenProjector(nullptr, -1, QTStr("StudioProgramWindow"),
  4763. ProjectorType::StudioProgram);
  4764. }
  4765. void OBSBasic::OpenPreviewWindow()
  4766. {
  4767. OpenProjector(nullptr, -1, QTStr("PreviewWindow"),
  4768. ProjectorType::Preview);
  4769. }
  4770. void OBSBasic::OpenSourceWindow()
  4771. {
  4772. OBSSceneItem item = GetCurrentSceneItem();
  4773. if (!item)
  4774. return;
  4775. OBSSource source = obs_sceneitem_get_source(item);
  4776. QString title = QString::fromUtf8(obs_source_get_name(source));
  4777. OpenProjector(obs_sceneitem_get_source(item), -1, title,
  4778. ProjectorType::Source);
  4779. }
  4780. void OBSBasic::OpenMultiviewWindow()
  4781. {
  4782. OpenProjector(nullptr, -1, QTStr("MultiviewWindowed"),
  4783. ProjectorType::Multiview);
  4784. }
  4785. void OBSBasic::OpenSceneWindow()
  4786. {
  4787. OBSScene scene = GetCurrentScene();
  4788. if (!scene)
  4789. return;
  4790. OBSSource source = obs_scene_get_source(scene);
  4791. QString title = QString::fromUtf8(obs_source_get_name(source));
  4792. OpenProjector(obs_scene_get_source(scene), -1, title,
  4793. ProjectorType::Scene);
  4794. }
  4795. void OBSBasic::OpenSavedProjectors()
  4796. {
  4797. for (SavedProjectorInfo *info : savedProjectorsArray) {
  4798. OBSProjector *projector = nullptr;
  4799. switch (info->type) {
  4800. case ProjectorType::Source:
  4801. case ProjectorType::Scene: {
  4802. OBSSource source = obs_get_source_by_name(
  4803. info->name.c_str());
  4804. if (!source)
  4805. continue;
  4806. QString title = nullptr;
  4807. if (info->monitor < 0)
  4808. title = QString::fromUtf8(
  4809. obs_source_get_name(source));
  4810. projector = OpenProjector(source, info->monitor, title,
  4811. info->type);
  4812. obs_source_release(source);
  4813. break;
  4814. }
  4815. case ProjectorType::Preview: {
  4816. projector = OpenProjector(nullptr, info->monitor,
  4817. QTStr("PreviewWindow"),
  4818. ProjectorType::Preview);
  4819. break;
  4820. }
  4821. case ProjectorType::StudioProgram: {
  4822. projector = OpenProjector(nullptr, info->monitor,
  4823. QTStr("StudioProgramWindow"),
  4824. ProjectorType::StudioProgram);
  4825. break;
  4826. }
  4827. case ProjectorType::Multiview: {
  4828. projector = OpenProjector(nullptr, info->monitor,
  4829. QTStr("MultiviewWindowed"),
  4830. ProjectorType::Multiview);
  4831. break;
  4832. }
  4833. }
  4834. if (projector && !info->geometry.empty()) {
  4835. QByteArray byteArray = QByteArray::fromBase64(
  4836. QByteArray(info->geometry.c_str()));
  4837. projector->restoreGeometry(byteArray);
  4838. if (!WindowPositionValid(projector->normalGeometry())) {
  4839. QRect rect = App()->desktop()->geometry();
  4840. projector->setGeometry(QStyle::alignedRect(
  4841. Qt::LeftToRight,
  4842. Qt::AlignCenter, size(), rect));
  4843. }
  4844. }
  4845. }
  4846. }
  4847. void OBSBasic::on_actionFullscreenInterface_triggered()
  4848. {
  4849. if (!fullscreenInterface)
  4850. showFullScreen();
  4851. else
  4852. showNormal();
  4853. fullscreenInterface = !fullscreenInterface;
  4854. }
  4855. void OBSBasic::UpdateTitleBar()
  4856. {
  4857. stringstream name;
  4858. const char *profile = config_get_string(App()->GlobalConfig(),
  4859. "Basic", "Profile");
  4860. const char *sceneCollection = config_get_string(App()->GlobalConfig(),
  4861. "Basic", "SceneCollection");
  4862. name << "OBS ";
  4863. if (previewProgramMode)
  4864. name << "Studio ";
  4865. name << App()->GetVersionString();
  4866. if (App()->IsPortableMode())
  4867. name << " - Portable Mode";
  4868. name << " - " << Str("TitleBar.Profile") << ": " << profile;
  4869. name << " - " << Str("TitleBar.Scenes") << ": " << sceneCollection;
  4870. setWindowTitle(QT_UTF8(name.str().c_str()));
  4871. }
  4872. int OBSBasic::GetProfilePath(char *path, size_t size, const char *file) const
  4873. {
  4874. char profiles_path[512];
  4875. const char *profile = config_get_string(App()->GlobalConfig(),
  4876. "Basic", "ProfileDir");
  4877. int ret;
  4878. if (!profile)
  4879. return -1;
  4880. if (!path)
  4881. return -1;
  4882. if (!file)
  4883. file = "";
  4884. ret = GetConfigPath(profiles_path, 512, "obs-studio/basic/profiles");
  4885. if (ret <= 0)
  4886. return ret;
  4887. if (!*file)
  4888. return snprintf(path, size, "%s/%s", profiles_path, profile);
  4889. return snprintf(path, size, "%s/%s/%s", profiles_path, profile, file);
  4890. }
  4891. void OBSBasic::on_resetUI_triggered()
  4892. {
  4893. restoreState(startingDockLayout);
  4894. #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
  4895. int cx = width();
  4896. int cy = height();
  4897. int cx22_5 = cx * 225 / 1000;
  4898. int cx5 = cx * 5 / 100;
  4899. cy = cy * 225 / 1000;
  4900. int mixerSize = cx - (cx22_5 * 2 + cx5 * 2);
  4901. QList<QDockWidget*> docks {
  4902. ui->scenesDock,
  4903. ui->sourcesDock,
  4904. ui->mixerDock,
  4905. ui->transitionsDock,
  4906. ui->controlsDock
  4907. };
  4908. QList<int> sizes {
  4909. cx22_5,
  4910. cx22_5,
  4911. mixerSize,
  4912. cx5,
  4913. cx5
  4914. };
  4915. ui->scenesDock->setVisible(true);
  4916. ui->sourcesDock->setVisible(true);
  4917. ui->mixerDock->setVisible(true);
  4918. ui->transitionsDock->setVisible(true);
  4919. ui->controlsDock->setVisible(true);
  4920. resizeDocks(docks, {cy, cy, cy, cy, cy}, Qt::Vertical);
  4921. resizeDocks(docks, sizes, Qt::Horizontal);
  4922. #endif
  4923. }
  4924. void OBSBasic::on_lockUI_toggled(bool lock)
  4925. {
  4926. QDockWidget::DockWidgetFeatures features = lock
  4927. ? QDockWidget::NoDockWidgetFeatures
  4928. : QDockWidget::AllDockWidgetFeatures;
  4929. ui->scenesDock->setFeatures(features);
  4930. ui->sourcesDock->setFeatures(features);
  4931. ui->mixerDock->setFeatures(features);
  4932. ui->transitionsDock->setFeatures(features);
  4933. ui->controlsDock->setFeatures(features);
  4934. }
  4935. void OBSBasic::on_toggleListboxToolbars_toggled(bool visible)
  4936. {
  4937. ui->sourcesToolbar->setVisible(visible);
  4938. ui->scenesToolbar->setVisible(visible);
  4939. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  4940. "ShowListboxToolbars", visible);
  4941. }
  4942. void OBSBasic::on_toggleStatusBar_toggled(bool visible)
  4943. {
  4944. ui->statusbar->setVisible(visible);
  4945. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  4946. "ShowStatusBar", visible);
  4947. }
  4948. void OBSBasic::on_actionLockPreview_triggered()
  4949. {
  4950. ui->preview->ToggleLocked();
  4951. ui->actionLockPreview->setChecked(ui->preview->Locked());
  4952. }
  4953. void OBSBasic::on_scalingMenu_aboutToShow()
  4954. {
  4955. obs_video_info ovi;
  4956. obs_get_video_info(&ovi);
  4957. QAction *action = ui->actionScaleCanvas;
  4958. QString text = QTStr("Basic.MainMenu.Edit.Scale.Canvas");
  4959. text = text.arg(QString::number(ovi.base_width),
  4960. QString::number(ovi.base_height));
  4961. action->setText(text);
  4962. action = ui->actionScaleOutput;
  4963. text = QTStr("Basic.MainMenu.Edit.Scale.Output");
  4964. text = text.arg(QString::number(ovi.output_width),
  4965. QString::number(ovi.output_height));
  4966. action->setText(text);
  4967. action->setVisible(!(ovi.output_width == ovi.base_width &&
  4968. ovi.output_height == ovi.base_height));
  4969. UpdatePreviewScalingMenu();
  4970. }
  4971. void OBSBasic::on_actionScaleWindow_triggered()
  4972. {
  4973. ui->preview->SetFixedScaling(false);
  4974. ui->preview->ResetScrollingOffset();
  4975. emit ui->preview->DisplayResized();
  4976. }
  4977. void OBSBasic::on_actionScaleCanvas_triggered()
  4978. {
  4979. ui->preview->SetFixedScaling(true);
  4980. ui->preview->SetScalingLevel(0);
  4981. emit ui->preview->DisplayResized();
  4982. }
  4983. void OBSBasic::on_actionScaleOutput_triggered()
  4984. {
  4985. obs_video_info ovi;
  4986. obs_get_video_info(&ovi);
  4987. ui->preview->SetFixedScaling(true);
  4988. float scalingAmount = float(ovi.output_width) / float(ovi.base_width);
  4989. // log base ZOOM_SENSITIVITY of x = log(x) / log(ZOOM_SENSITIVITY)
  4990. int32_t approxScalingLevel = int32_t(
  4991. round(log(scalingAmount) / log(ZOOM_SENSITIVITY)));
  4992. ui->preview->SetScalingLevel(approxScalingLevel);
  4993. ui->preview->SetScalingAmount(scalingAmount);
  4994. emit ui->preview->DisplayResized();
  4995. }
  4996. void OBSBasic::SetShowing(bool showing)
  4997. {
  4998. if (!showing && isVisible()) {
  4999. config_set_string(App()->GlobalConfig(),
  5000. "BasicWindow", "geometry",
  5001. saveGeometry().toBase64().constData());
  5002. /* hide all visible child dialogs */
  5003. visDlgPositions.clear();
  5004. if (!visDialogs.isEmpty()) {
  5005. for (QDialog *dlg : visDialogs) {
  5006. visDlgPositions.append(dlg->pos());
  5007. dlg->hide();
  5008. }
  5009. }
  5010. if (showHide)
  5011. showHide->setText(QTStr("Basic.SystemTray.Show"));
  5012. QTimer::singleShot(250, this, SLOT(hide()));
  5013. if (previewEnabled)
  5014. EnablePreviewDisplay(false);
  5015. setVisible(false);
  5016. #ifdef __APPLE__
  5017. EnableOSXDockIcon(false);
  5018. #endif
  5019. } else if (showing && !isVisible()) {
  5020. if (showHide)
  5021. showHide->setText(QTStr("Basic.SystemTray.Hide"));
  5022. QTimer::singleShot(250, this, SLOT(show()));
  5023. if (previewEnabled)
  5024. EnablePreviewDisplay(true);
  5025. setVisible(true);
  5026. #ifdef __APPLE__
  5027. EnableOSXDockIcon(true);
  5028. #endif
  5029. /* raise and activate window to ensure it is on top */
  5030. raise();
  5031. activateWindow();
  5032. /* show all child dialogs that was visible earlier */
  5033. if (!visDialogs.isEmpty()) {
  5034. for (int i = 0; i < visDialogs.size(); ++i) {
  5035. QDialog *dlg = visDialogs[i];
  5036. dlg->move(visDlgPositions[i]);
  5037. dlg->show();
  5038. }
  5039. }
  5040. /* Unminimize window if it was hidden to tray instead of task
  5041. * bar. */
  5042. if (sysTrayMinimizeToTray()) {
  5043. Qt::WindowStates state;
  5044. state = windowState() & ~Qt::WindowMinimized;
  5045. state |= Qt::WindowActive;
  5046. setWindowState(state);
  5047. }
  5048. }
  5049. }
  5050. void OBSBasic::ToggleShowHide()
  5051. {
  5052. bool showing = isVisible();
  5053. if (showing) {
  5054. /* check for modal dialogs */
  5055. EnumDialogs();
  5056. if (!modalDialogs.isEmpty() || !visMsgBoxes.isEmpty())
  5057. return;
  5058. }
  5059. SetShowing(!showing);
  5060. }
  5061. void OBSBasic::SystemTrayInit()
  5062. {
  5063. trayIcon.reset(new QSystemTrayIcon(QIcon(":/res/images/obs.png"),
  5064. this));
  5065. trayIcon->setToolTip("OBS Studio");
  5066. showHide = new QAction(QTStr("Basic.SystemTray.Show"),
  5067. trayIcon.data());
  5068. sysTrayStream = new QAction(QTStr("Basic.Main.StartStreaming"),
  5069. trayIcon.data());
  5070. sysTrayRecord = new QAction(QTStr("Basic.Main.StartRecording"),
  5071. trayIcon.data());
  5072. sysTrayReplayBuffer = new QAction(QTStr("Basic.Main.StartReplayBuffer"),
  5073. trayIcon.data());
  5074. exit = new QAction(QTStr("Exit"),
  5075. trayIcon.data());
  5076. if (outputHandler && !outputHandler->replayBuffer)
  5077. sysTrayReplayBuffer->setEnabled(false);
  5078. connect(trayIcon.data(),
  5079. SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
  5080. this,
  5081. SLOT(IconActivated(QSystemTrayIcon::ActivationReason)));
  5082. connect(showHide, SIGNAL(triggered()),
  5083. this, SLOT(ToggleShowHide()));
  5084. connect(sysTrayStream, SIGNAL(triggered()),
  5085. this, SLOT(on_streamButton_clicked()));
  5086. connect(sysTrayRecord, SIGNAL(triggered()),
  5087. this, SLOT(on_recordButton_clicked()));
  5088. connect(sysTrayReplayBuffer.data(), &QAction::triggered,
  5089. this, &OBSBasic::ReplayBufferClicked);
  5090. connect(exit, SIGNAL(triggered()),
  5091. this, SLOT(close()));
  5092. trayMenu = new QMenu;
  5093. }
  5094. void OBSBasic::IconActivated(QSystemTrayIcon::ActivationReason reason)
  5095. {
  5096. if (reason == QSystemTrayIcon::Trigger) {
  5097. ToggleShowHide();
  5098. } else if (reason == QSystemTrayIcon::Context) {
  5099. QMenu *previewProjector = new QMenu(QTStr("PreviewProjector"));
  5100. AddProjectorMenuMonitors(previewProjector, this,
  5101. SLOT(OpenPreviewProjector()));
  5102. QMenu *studioProgramProjector = new QMenu(
  5103. QTStr("StudioProgramProjector"));
  5104. AddProjectorMenuMonitors(studioProgramProjector, this,
  5105. SLOT(OpenStudioProgramProjector()));
  5106. trayMenu->clear();
  5107. trayMenu->addAction(showHide);
  5108. trayMenu->addMenu(previewProjector);
  5109. trayMenu->addMenu(studioProgramProjector);
  5110. trayMenu->addAction(sysTrayStream);
  5111. trayMenu->addAction(sysTrayRecord);
  5112. trayMenu->addAction(sysTrayReplayBuffer);
  5113. trayMenu->addAction(exit);
  5114. trayMenu->popup(QCursor::pos());
  5115. }
  5116. }
  5117. void OBSBasic::SysTrayNotify(const QString &text,
  5118. QSystemTrayIcon::MessageIcon n)
  5119. {
  5120. if (QSystemTrayIcon::supportsMessages()) {
  5121. QSystemTrayIcon::MessageIcon icon =
  5122. QSystemTrayIcon::MessageIcon(n);
  5123. trayIcon->showMessage("OBS Studio", text, icon, 10000);
  5124. }
  5125. }
  5126. void OBSBasic::SystemTray(bool firstStarted)
  5127. {
  5128. if (!QSystemTrayIcon::isSystemTrayAvailable())
  5129. return;
  5130. bool sysTrayWhenStarted = config_get_bool(GetGlobalConfig(),
  5131. "BasicWindow", "SysTrayWhenStarted");
  5132. bool sysTrayEnabled = config_get_bool(GetGlobalConfig(),
  5133. "BasicWindow", "SysTrayEnabled");
  5134. if (firstStarted)
  5135. SystemTrayInit();
  5136. if (!sysTrayWhenStarted && !sysTrayEnabled) {
  5137. trayIcon->hide();
  5138. } else if ((sysTrayWhenStarted && sysTrayEnabled)
  5139. || opt_minimize_tray) {
  5140. trayIcon->show();
  5141. if (firstStarted) {
  5142. QTimer::singleShot(50, this, SLOT(hide()));
  5143. EnablePreviewDisplay(false);
  5144. setVisible(false);
  5145. #ifdef __APPLE__
  5146. EnableOSXDockIcon(false);
  5147. #endif
  5148. opt_minimize_tray = false;
  5149. }
  5150. } else if (sysTrayEnabled) {
  5151. trayIcon->show();
  5152. } else if (!sysTrayEnabled) {
  5153. trayIcon->hide();
  5154. } else if (!sysTrayWhenStarted && sysTrayEnabled) {
  5155. trayIcon->hide();
  5156. }
  5157. if (isVisible())
  5158. showHide->setText(QTStr("Basic.SystemTray.Hide"));
  5159. else
  5160. showHide->setText(QTStr("Basic.SystemTray.Show"));
  5161. }
  5162. bool OBSBasic::sysTrayMinimizeToTray()
  5163. {
  5164. return config_get_bool(GetGlobalConfig(),
  5165. "BasicWindow", "SysTrayMinimizeToTray");
  5166. }
  5167. void OBSBasic::on_actionCopySource_triggered()
  5168. {
  5169. OBSSceneItem item = GetCurrentSceneItem();
  5170. if (!item)
  5171. return;
  5172. on_actionCopyTransform_triggered();
  5173. OBSSource source = obs_sceneitem_get_source(item);
  5174. copyString = obs_source_get_name(source);
  5175. copyVisible = obs_sceneitem_visible(item);
  5176. ui->actionPasteRef->setEnabled(true);
  5177. uint32_t output_flags = obs_source_get_output_flags(source);
  5178. if ((output_flags & OBS_SOURCE_DO_NOT_DUPLICATE) == 0)
  5179. ui->actionPasteDup->setEnabled(true);
  5180. else
  5181. ui->actionPasteDup->setEnabled(false);
  5182. }
  5183. void OBSBasic::on_actionPasteRef_triggered()
  5184. {
  5185. /* do not allow duplicate refs of the same group in the same scene */
  5186. OBSScene scene = GetCurrentScene();
  5187. if (!!obs_scene_get_group(scene, copyString))
  5188. return;
  5189. OBSBasicSourceSelect::SourcePaste(copyString, copyVisible, false);
  5190. on_actionPasteTransform_triggered();
  5191. }
  5192. void OBSBasic::on_actionPasteDup_triggered()
  5193. {
  5194. OBSBasicSourceSelect::SourcePaste(copyString, copyVisible, true);
  5195. on_actionPasteTransform_triggered();
  5196. }
  5197. void OBSBasic::on_actionCopyFilters_triggered()
  5198. {
  5199. OBSSceneItem item = GetCurrentSceneItem();
  5200. if (!item)
  5201. return;
  5202. OBSSource source = obs_sceneitem_get_source(item);
  5203. copyFiltersString = obs_source_get_name(source);
  5204. ui->actionPasteFilters->setEnabled(true);
  5205. }
  5206. void OBSBasic::on_actionPasteFilters_triggered()
  5207. {
  5208. OBSSource source = obs_get_source_by_name(copyFiltersString);
  5209. obs_source_release(source);
  5210. OBSSceneItem sceneItem = GetCurrentSceneItem();
  5211. OBSSource dstSource = obs_sceneitem_get_source(sceneItem);
  5212. if (source == dstSource)
  5213. return;
  5214. obs_source_copy_filters(dstSource, source);
  5215. }
  5216. static void ConfirmColor(SourceTree *sources, const QColor &color,
  5217. QModelIndexList selectedItems)
  5218. {
  5219. for (int x = 0; x < selectedItems.count(); x++) {
  5220. SourceTreeItem *treeItem = sources
  5221. ->GetItemWidget(selectedItems[x].row());
  5222. treeItem->setStyleSheet("background: "
  5223. + color.name(QColor::HexArgb));
  5224. treeItem->style()->unpolish(treeItem);
  5225. treeItem->style()->polish(treeItem);
  5226. OBSSceneItem sceneItem = sources->Get(
  5227. selectedItems[x].row());
  5228. obs_data_t *privData =
  5229. obs_sceneitem_get_private_settings(sceneItem);
  5230. obs_data_set_int(privData, "color-preset", 1);
  5231. obs_data_set_string(privData, "color",
  5232. QT_TO_UTF8(color.name(
  5233. QColor::HexArgb)));
  5234. obs_data_release(privData);
  5235. }
  5236. }
  5237. void OBSBasic::ColorChange()
  5238. {
  5239. QModelIndexList selectedItems =
  5240. ui->sources->selectionModel()->selectedIndexes();
  5241. QAction *action = qobject_cast<QAction*>(sender());
  5242. QPushButton *colorButton = qobject_cast<QPushButton*>(sender());
  5243. if (selectedItems.count() == 0)
  5244. return;
  5245. if (colorButton) {
  5246. int preset = colorButton->property("bgColor").value<int>();
  5247. for (int x = 0; x < selectedItems.count(); x++) {
  5248. SourceTreeItem *treeItem = ui->sources
  5249. ->GetItemWidget(selectedItems[x].row());
  5250. treeItem->setStyleSheet("");
  5251. treeItem->setProperty("bgColor", preset);
  5252. treeItem->style()->unpolish(treeItem);
  5253. treeItem->style()->polish(treeItem);
  5254. OBSSceneItem sceneItem = ui->sources->Get(
  5255. selectedItems[x].row());
  5256. obs_data_t *privData =
  5257. obs_sceneitem_get_private_settings(sceneItem);
  5258. obs_data_set_int(privData, "color-preset", preset + 1);
  5259. obs_data_set_string(privData, "color", "");
  5260. obs_data_release(privData);
  5261. }
  5262. for (int i = 1; i < 9; i++) {
  5263. stringstream button;
  5264. button << "preset" << i;
  5265. QPushButton *cButton = colorButton->parentWidget()
  5266. ->findChild<QPushButton *>(button.str().c_str());
  5267. cButton->setStyleSheet("border: 1px solid black");
  5268. }
  5269. colorButton->setStyleSheet("border: 2px solid black");
  5270. } else if (action) {
  5271. int preset = action->property("bgColor").value<int>();
  5272. if (preset == 1) {
  5273. OBSSceneItem curSceneItem = GetCurrentSceneItem();
  5274. SourceTreeItem *curTreeItem =
  5275. GetItemWidgetFromSceneItem(curSceneItem);
  5276. obs_data_t *curPrivData =
  5277. obs_sceneitem_get_private_settings(curSceneItem);
  5278. int oldPreset = obs_data_get_int(
  5279. curPrivData, "color-preset");
  5280. const QString oldSheet = curTreeItem->styleSheet();
  5281. auto liveChangeColor = [=](const QColor &color) {
  5282. if (color.isValid()) {
  5283. curTreeItem->setStyleSheet(
  5284. "background: "
  5285. + color.name(QColor::HexArgb));
  5286. }
  5287. };
  5288. auto changedColor = [=](const QColor &color) {
  5289. if (color.isValid()) {
  5290. ConfirmColor(ui->sources, color,
  5291. selectedItems);
  5292. }
  5293. };
  5294. auto rejected = [=]() {
  5295. if (oldPreset == 1) {
  5296. curTreeItem->setStyleSheet(oldSheet);
  5297. curTreeItem->setProperty("bgColor", 0);
  5298. } else if (oldPreset == 0) {
  5299. curTreeItem->setStyleSheet(
  5300. "background: none");
  5301. curTreeItem->setProperty("bgColor", 0);
  5302. } else {
  5303. curTreeItem->setStyleSheet("");
  5304. curTreeItem->setProperty("bgColor",
  5305. oldPreset - 1);
  5306. }
  5307. curTreeItem->style()->unpolish(curTreeItem);
  5308. curTreeItem->style()->polish(curTreeItem);
  5309. };
  5310. QColorDialog::ColorDialogOptions options =
  5311. QColorDialog::ShowAlphaChannel;
  5312. const char *oldColor = obs_data_get_string(curPrivData,
  5313. "color");
  5314. const char *customColor = *oldColor != 0 ? oldColor
  5315. : "#55FF0000";
  5316. #ifdef __APPLE__
  5317. options |= QColorDialog::DontUseNativeDialog;
  5318. #endif
  5319. QColorDialog *colorDialog = new QColorDialog(this);
  5320. colorDialog->setOptions(options);
  5321. colorDialog->setCurrentColor(
  5322. QColor(customColor));
  5323. connect(colorDialog, &QColorDialog::currentColorChanged,
  5324. liveChangeColor);
  5325. connect(colorDialog, &QColorDialog::colorSelected,
  5326. changedColor);
  5327. connect(colorDialog, &QColorDialog::rejected,
  5328. rejected);
  5329. colorDialog->open();
  5330. obs_data_release(curPrivData);
  5331. } else {
  5332. for (int x = 0; x < selectedItems.count(); x++) {
  5333. SourceTreeItem *treeItem = ui->sources
  5334. ->GetItemWidget(selectedItems[x].row());
  5335. treeItem->setStyleSheet("background: none");
  5336. treeItem->setProperty("bgColor", preset);
  5337. treeItem->style()->unpolish(treeItem);
  5338. treeItem->style()->polish(treeItem);
  5339. OBSSceneItem sceneItem = ui->sources->Get(
  5340. selectedItems[x].row());
  5341. obs_data_t *privData =
  5342. obs_sceneitem_get_private_settings(
  5343. sceneItem);
  5344. obs_data_set_int(privData, "color-preset",
  5345. preset);
  5346. obs_data_set_string(privData, "color", "");
  5347. obs_data_release(privData);
  5348. }
  5349. }
  5350. }
  5351. }
  5352. SourceTreeItem *OBSBasic::GetItemWidgetFromSceneItem(
  5353. obs_sceneitem_t *sceneItem)
  5354. {
  5355. int i = 0;
  5356. SourceTreeItem *treeItem = ui->sources->GetItemWidget(i);
  5357. OBSSceneItem item = ui->sources->Get(i);
  5358. int64_t id = obs_sceneitem_get_id(sceneItem);
  5359. while (treeItem && obs_sceneitem_get_id(item) != id) {
  5360. i++;
  5361. treeItem = ui->sources->GetItemWidget(i);
  5362. item = ui->sources->Get(i);
  5363. }
  5364. if(treeItem)
  5365. return treeItem;
  5366. return nullptr;
  5367. }
  5368. void OBSBasic::on_autoConfigure_triggered()
  5369. {
  5370. AutoConfig test(this);
  5371. test.setModal(true);
  5372. test.show();
  5373. test.exec();
  5374. }
  5375. void OBSBasic::on_stats_triggered()
  5376. {
  5377. if (!stats.isNull()) {
  5378. stats->show();
  5379. stats->raise();
  5380. return;
  5381. }
  5382. OBSBasicStats *statsDlg;
  5383. statsDlg = new OBSBasicStats(nullptr);
  5384. statsDlg->show();
  5385. stats = statsDlg;
  5386. }
  5387. ColorSelect::ColorSelect(QWidget *parent)
  5388. : QWidget(parent),
  5389. ui(new Ui::ColorSelect)
  5390. {
  5391. ui->setupUi(this);
  5392. }