window-basic-main.cpp 188 KB

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