window-basic-main.cpp 205 KB

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