window-basic-main.cpp 220 KB

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