window-basic-main.cpp 191 KB

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