window-basic-main.cpp 158 KB

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