window-basic-main.cpp 174 KB

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