window-basic-main.cpp 205 KB

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