window-basic-main.cpp 158 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044
  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, 0);
  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_int(data, "saved_studio_preview_projectors",
  376. studioProgramProjectorArray.at(i));
  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_int(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. popup.addSeparator();
  2799. QMenu *transitionMenu = CreatePerSceneTransitionMenu();
  2800. popup.addMenu(transitionMenu);
  2801. }
  2802. popup.exec(QCursor::pos());
  2803. }
  2804. void OBSBasic::on_actionAddScene_triggered()
  2805. {
  2806. string name;
  2807. QString format{QTStr("Basic.Main.DefaultSceneName.Text")};
  2808. int i = 2;
  2809. QString placeHolderText = format.arg(i);
  2810. obs_source_t *source = nullptr;
  2811. while ((source = obs_get_source_by_name(QT_TO_UTF8(placeHolderText)))) {
  2812. obs_source_release(source);
  2813. placeHolderText = format.arg(++i);
  2814. }
  2815. bool accepted = NameDialog::AskForName(this,
  2816. QTStr("Basic.Main.AddSceneDlg.Title"),
  2817. QTStr("Basic.Main.AddSceneDlg.Text"),
  2818. name,
  2819. placeHolderText);
  2820. if (accepted) {
  2821. if (name.empty()) {
  2822. OBSMessageBox::information(this,
  2823. QTStr("NoNameEntered.Title"),
  2824. QTStr("NoNameEntered.Text"));
  2825. on_actionAddScene_triggered();
  2826. return;
  2827. }
  2828. obs_source_t *source = obs_get_source_by_name(name.c_str());
  2829. if (source) {
  2830. OBSMessageBox::information(this,
  2831. QTStr("NameExists.Title"),
  2832. QTStr("NameExists.Text"));
  2833. obs_source_release(source);
  2834. on_actionAddScene_triggered();
  2835. return;
  2836. }
  2837. obs_scene_t *scene = obs_scene_create(name.c_str());
  2838. source = obs_scene_get_source(scene);
  2839. AddScene(source);
  2840. SetCurrentScene(source);
  2841. obs_scene_release(scene);
  2842. }
  2843. }
  2844. void OBSBasic::on_actionRemoveScene_triggered()
  2845. {
  2846. OBSScene scene = GetCurrentScene();
  2847. obs_source_t *source = obs_scene_get_source(scene);
  2848. if (source && QueryRemoveSource(source))
  2849. obs_source_remove(source);
  2850. }
  2851. void OBSBasic::ChangeSceneIndex(bool relative, int offset, int invalidIdx)
  2852. {
  2853. int idx = ui->scenes->currentRow();
  2854. if (idx == -1 || idx == invalidIdx)
  2855. return;
  2856. sceneChanging = true;
  2857. QListWidgetItem *item = ui->scenes->takeItem(idx);
  2858. if (!relative)
  2859. idx = 0;
  2860. ui->scenes->insertItem(idx + offset, item);
  2861. ui->scenes->setCurrentRow(idx + offset);
  2862. item->setSelected(true);
  2863. sceneChanging = false;
  2864. }
  2865. void OBSBasic::on_actionSceneUp_triggered()
  2866. {
  2867. ChangeSceneIndex(true, -1, 0);
  2868. }
  2869. void OBSBasic::on_actionSceneDown_triggered()
  2870. {
  2871. ChangeSceneIndex(true, 1, ui->scenes->count() - 1);
  2872. }
  2873. void OBSBasic::MoveSceneToTop()
  2874. {
  2875. ChangeSceneIndex(false, 0, 0);
  2876. }
  2877. void OBSBasic::MoveSceneToBottom()
  2878. {
  2879. ChangeSceneIndex(false, ui->scenes->count() - 1,
  2880. ui->scenes->count() - 1);
  2881. }
  2882. void OBSBasic::on_sources_itemSelectionChanged()
  2883. {
  2884. SignalBlocker sourcesSignalBlocker(ui->sources);
  2885. auto updateItemSelection = [&]()
  2886. {
  2887. ignoreSelectionUpdate = true;
  2888. for (int i = 0; i < ui->sources->count(); i++)
  2889. {
  2890. QListWidgetItem *wItem = ui->sources->item(i);
  2891. OBSSceneItem item = GetOBSRef<OBSSceneItem>(wItem);
  2892. obs_sceneitem_select(item, wItem->isSelected());
  2893. }
  2894. ignoreSelectionUpdate = false;
  2895. };
  2896. using updateItemSelection_t = decltype(updateItemSelection);
  2897. obs_scene_atomic_update(GetCurrentScene(),
  2898. [](void *data, obs_scene_t *)
  2899. {
  2900. (*static_cast<updateItemSelection_t*>(data))();
  2901. }, static_cast<void*>(&updateItemSelection));
  2902. }
  2903. void OBSBasic::EditSceneItemName()
  2904. {
  2905. QListWidgetItem *item = GetTopSelectedSourceItem();
  2906. Qt::ItemFlags flags = item->flags();
  2907. OBSSceneItem sceneItem= GetOBSRef<OBSSceneItem>(item);
  2908. obs_source_t *source = obs_sceneitem_get_source(sceneItem);
  2909. const char *name = obs_source_get_name(source);
  2910. item->setText(QT_UTF8(name));
  2911. item->setFlags(flags | Qt::ItemIsEditable);
  2912. ui->sources->removeItemWidget(item);
  2913. ui->sources->editItem(item);
  2914. item->setFlags(flags);
  2915. }
  2916. void OBSBasic::SetDeinterlacingMode()
  2917. {
  2918. QAction *action = reinterpret_cast<QAction*>(sender());
  2919. obs_deinterlace_mode mode =
  2920. (obs_deinterlace_mode)action->property("mode").toInt();
  2921. OBSSceneItem sceneItem = GetCurrentSceneItem();
  2922. obs_source_t *source = obs_sceneitem_get_source(sceneItem);
  2923. obs_source_set_deinterlace_mode(source, mode);
  2924. }
  2925. void OBSBasic::SetDeinterlacingOrder()
  2926. {
  2927. QAction *action = reinterpret_cast<QAction*>(sender());
  2928. obs_deinterlace_field_order order =
  2929. (obs_deinterlace_field_order)action->property("order").toInt();
  2930. OBSSceneItem sceneItem = GetCurrentSceneItem();
  2931. obs_source_t *source = obs_sceneitem_get_source(sceneItem);
  2932. obs_source_set_deinterlace_field_order(source, order);
  2933. }
  2934. QMenu *OBSBasic::AddDeinterlacingMenu(obs_source_t *source)
  2935. {
  2936. QMenu *menu = new QMenu(QTStr("Deinterlacing"));
  2937. obs_deinterlace_mode deinterlaceMode =
  2938. obs_source_get_deinterlace_mode(source);
  2939. obs_deinterlace_field_order deinterlaceOrder =
  2940. obs_source_get_deinterlace_field_order(source);
  2941. QAction *action;
  2942. #define ADD_MODE(name, mode) \
  2943. action = menu->addAction(QTStr("" name), this, \
  2944. SLOT(SetDeinterlacingMode())); \
  2945. action->setProperty("mode", (int)mode); \
  2946. action->setCheckable(true); \
  2947. action->setChecked(deinterlaceMode == mode);
  2948. ADD_MODE("Disable", OBS_DEINTERLACE_MODE_DISABLE);
  2949. ADD_MODE("Deinterlacing.Discard", OBS_DEINTERLACE_MODE_DISCARD);
  2950. ADD_MODE("Deinterlacing.Retro", OBS_DEINTERLACE_MODE_RETRO);
  2951. ADD_MODE("Deinterlacing.Blend", OBS_DEINTERLACE_MODE_BLEND);
  2952. ADD_MODE("Deinterlacing.Blend2x", OBS_DEINTERLACE_MODE_BLEND_2X);
  2953. ADD_MODE("Deinterlacing.Linear", OBS_DEINTERLACE_MODE_LINEAR);
  2954. ADD_MODE("Deinterlacing.Linear2x", OBS_DEINTERLACE_MODE_LINEAR_2X);
  2955. ADD_MODE("Deinterlacing.Yadif", OBS_DEINTERLACE_MODE_YADIF);
  2956. ADD_MODE("Deinterlacing.Yadif2x", OBS_DEINTERLACE_MODE_YADIF_2X);
  2957. #undef ADD_MODE
  2958. menu->addSeparator();
  2959. #define ADD_ORDER(name, order) \
  2960. action = menu->addAction(QTStr("Deinterlacing." name), this, \
  2961. SLOT(SetDeinterlacingOrder())); \
  2962. action->setProperty("order", (int)order); \
  2963. action->setCheckable(true); \
  2964. action->setChecked(deinterlaceOrder == order);
  2965. ADD_ORDER("TopFieldFirst", OBS_DEINTERLACE_FIELD_ORDER_TOP);
  2966. ADD_ORDER("BottomFieldFirst", OBS_DEINTERLACE_FIELD_ORDER_BOTTOM);
  2967. #undef ADD_ORDER
  2968. return menu;
  2969. }
  2970. void OBSBasic::SetScaleFilter()
  2971. {
  2972. QAction *action = reinterpret_cast<QAction*>(sender());
  2973. obs_scale_type mode = (obs_scale_type)action->property("mode").toInt();
  2974. OBSSceneItem sceneItem = GetCurrentSceneItem();
  2975. obs_sceneitem_set_scale_filter(sceneItem, mode);
  2976. }
  2977. QMenu *OBSBasic::AddScaleFilteringMenu(obs_sceneitem_t *item)
  2978. {
  2979. QMenu *menu = new QMenu(QTStr("ScaleFiltering"));
  2980. obs_scale_type scaleFilter = obs_sceneitem_get_scale_filter(item);
  2981. QAction *action;
  2982. #define ADD_MODE(name, mode) \
  2983. action = menu->addAction(QTStr("" name), this, \
  2984. SLOT(SetScaleFilter())); \
  2985. action->setProperty("mode", (int)mode); \
  2986. action->setCheckable(true); \
  2987. action->setChecked(scaleFilter == mode);
  2988. ADD_MODE("Disable", OBS_SCALE_DISABLE);
  2989. ADD_MODE("ScaleFiltering.Point", OBS_SCALE_POINT);
  2990. ADD_MODE("ScaleFiltering.Bilinear", OBS_SCALE_BILINEAR);
  2991. ADD_MODE("ScaleFiltering.Bicubic", OBS_SCALE_BICUBIC);
  2992. ADD_MODE("ScaleFiltering.Lanczos", OBS_SCALE_LANCZOS);
  2993. #undef ADD_MODE
  2994. return menu;
  2995. }
  2996. void OBSBasic::CreateSourcePopupMenu(QListWidgetItem *item, bool preview)
  2997. {
  2998. QMenu popup(this);
  2999. QPointer<QMenu> previewProjector;
  3000. QPointer<QMenu> sourceProjector;
  3001. if (preview) {
  3002. QAction *action = popup.addAction(
  3003. QTStr("Basic.Main.PreviewConextMenu.Enable"),
  3004. this, SLOT(TogglePreview()));
  3005. action->setCheckable(true);
  3006. action->setChecked(
  3007. obs_display_enabled(ui->preview->GetDisplay()));
  3008. if (IsPreviewProgramMode())
  3009. action->setEnabled(false);
  3010. popup.addAction(ui->actionLockPreview);
  3011. popup.addMenu(ui->scalingMenu);
  3012. const char *slot = IsPreviewProgramMode()
  3013. ? SLOT(OpenStudioProgramProjector())
  3014. : SLOT(OpenPreviewProjector());
  3015. previewProjector = new QMenu(QTStr("PreviewProjector"));
  3016. AddProjectorMenuMonitors(previewProjector, this,
  3017. slot);
  3018. popup.addMenu(previewProjector);
  3019. slot = IsPreviewProgramMode()
  3020. ? SLOT(OpenStudioProgramWindow())
  3021. : SLOT(OpenPreviewWindow());
  3022. QAction *previewWindow = popup.addAction(
  3023. QTStr("PreviewWindow"),
  3024. this, slot);
  3025. popup.addAction(previewWindow);
  3026. popup.addSeparator();
  3027. }
  3028. QPointer<QMenu> addSourceMenu = CreateAddSourcePopupMenu();
  3029. if (addSourceMenu)
  3030. popup.addMenu(addSourceMenu);
  3031. ui->actionCopyFilters->setEnabled(false);
  3032. popup.addSeparator();
  3033. popup.addAction(ui->actionCopySource);
  3034. popup.addAction(ui->actionPasteRef);
  3035. popup.addAction(ui->actionPasteDup);
  3036. popup.addSeparator();
  3037. popup.addSeparator();
  3038. popup.addAction(ui->actionCopyFilters);
  3039. popup.addAction(ui->actionPasteFilters);
  3040. popup.addSeparator();
  3041. if (item) {
  3042. if (addSourceMenu)
  3043. popup.addSeparator();
  3044. OBSSceneItem sceneItem = GetSceneItem(item);
  3045. obs_source_t *source = obs_sceneitem_get_source(sceneItem);
  3046. uint32_t flags = obs_source_get_output_flags(source);
  3047. bool isAsyncVideo = (flags & OBS_SOURCE_ASYNC_VIDEO) ==
  3048. OBS_SOURCE_ASYNC_VIDEO;
  3049. bool hasAudio = (flags & OBS_SOURCE_AUDIO) ==
  3050. OBS_SOURCE_AUDIO;
  3051. QAction *action;
  3052. popup.addAction(QTStr("Rename"), this,
  3053. SLOT(EditSceneItemName()));
  3054. popup.addAction(QTStr("Remove"), this,
  3055. SLOT(on_actionRemoveSource_triggered()),
  3056. DeleteKeys.front());
  3057. popup.addSeparator();
  3058. popup.addMenu(ui->orderMenu);
  3059. popup.addMenu(ui->transformMenu);
  3060. sourceProjector = new QMenu(QTStr("SourceProjector"));
  3061. AddProjectorMenuMonitors(sourceProjector, this,
  3062. SLOT(OpenSourceProjector()));
  3063. QAction *sourceWindow = popup.addAction(
  3064. QTStr("SourceWindow"),
  3065. this, SLOT(OpenSourceWindow()));
  3066. popup.addAction(sourceWindow);
  3067. popup.addSeparator();
  3068. if (hasAudio) {
  3069. QAction *actionHideMixer = popup.addAction(
  3070. QTStr("HideMixer"),
  3071. this, SLOT(ToggleHideMixer()));
  3072. actionHideMixer->setCheckable(true);
  3073. actionHideMixer->setChecked(SourceMixerHidden(source));
  3074. }
  3075. if (isAsyncVideo) {
  3076. popup.addMenu(AddDeinterlacingMenu(source));
  3077. popup.addSeparator();
  3078. }
  3079. popup.addMenu(AddScaleFilteringMenu(sceneItem));
  3080. popup.addSeparator();
  3081. popup.addMenu(sourceProjector);
  3082. popup.addAction(sourceWindow);
  3083. popup.addSeparator();
  3084. action = popup.addAction(QTStr("Interact"), this,
  3085. SLOT(on_actionInteract_triggered()));
  3086. action->setEnabled(obs_source_get_output_flags(source) &
  3087. OBS_SOURCE_INTERACTION);
  3088. popup.addAction(QTStr("Filters"), this,
  3089. SLOT(OpenFilters()));
  3090. popup.addAction(QTStr("Properties"), this,
  3091. SLOT(on_actionSourceProperties_triggered()));
  3092. ui->actionCopyFilters->setEnabled(true);
  3093. }
  3094. popup.exec(QCursor::pos());
  3095. }
  3096. void OBSBasic::on_sources_customContextMenuRequested(const QPoint &pos)
  3097. {
  3098. if (ui->scenes->count())
  3099. CreateSourcePopupMenu(ui->sources->itemAt(pos), false);
  3100. }
  3101. void OBSBasic::on_sources_itemDoubleClicked(QListWidgetItem *witem)
  3102. {
  3103. if (!witem)
  3104. return;
  3105. OBSSceneItem item = GetSceneItem(witem);
  3106. OBSSource source = obs_sceneitem_get_source(item);
  3107. if (source)
  3108. CreatePropertiesWindow(source);
  3109. }
  3110. void OBSBasic::on_scenes_itemDoubleClicked(QListWidgetItem *witem)
  3111. {
  3112. if (!witem)
  3113. return;
  3114. if (IsPreviewProgramMode()) {
  3115. bool doubleClickSwitch = config_get_bool(App()->GlobalConfig(),
  3116. "BasicWindow", "TransitionOnDoubleClick");
  3117. if (doubleClickSwitch) {
  3118. OBSScene scene = GetCurrentScene();
  3119. if (scene)
  3120. SetCurrentScene(scene, false, true);
  3121. }
  3122. }
  3123. }
  3124. void OBSBasic::AddSource(const char *id)
  3125. {
  3126. if (id && *id) {
  3127. OBSBasicSourceSelect sourceSelect(this, id);
  3128. sourceSelect.exec();
  3129. if (sourceSelect.newSource)
  3130. CreatePropertiesWindow(sourceSelect.newSource);
  3131. }
  3132. }
  3133. QMenu *OBSBasic::CreateAddSourcePopupMenu()
  3134. {
  3135. const char *type;
  3136. bool foundValues = false;
  3137. bool foundDeprecated = false;
  3138. size_t idx = 0;
  3139. QMenu *popup = new QMenu(QTStr("Add"), this);
  3140. QMenu *deprecated = new QMenu(QTStr("Deprecated"), popup);
  3141. auto getActionAfter = [] (QMenu *menu, const QString &name)
  3142. {
  3143. QList<QAction*> actions = menu->actions();
  3144. for (QAction *menuAction : actions) {
  3145. if (menuAction->text().compare(name) >= 0)
  3146. return menuAction;
  3147. }
  3148. return (QAction*)nullptr;
  3149. };
  3150. auto addSource = [this, getActionAfter] (QMenu *popup,
  3151. const char *type, const char *name)
  3152. {
  3153. QString qname = QT_UTF8(name);
  3154. QAction *popupItem = new QAction(qname, this);
  3155. popupItem->setData(QT_UTF8(type));
  3156. connect(popupItem, SIGNAL(triggered(bool)),
  3157. this, SLOT(AddSourceFromAction()));
  3158. QAction *after = getActionAfter(popup, qname);
  3159. popup->insertAction(after, popupItem);
  3160. };
  3161. while (obs_enum_input_types(idx++, &type)) {
  3162. const char *name = obs_source_get_display_name(type);
  3163. uint32_t caps = obs_get_source_output_flags(type);
  3164. if ((caps & OBS_SOURCE_DEPRECATED) == 0) {
  3165. addSource(popup, type, name);
  3166. } else {
  3167. addSource(deprecated, type, name);
  3168. foundDeprecated = true;
  3169. }
  3170. foundValues = true;
  3171. }
  3172. addSource(popup, "scene", Str("Basic.Scene"));
  3173. if (!foundDeprecated) {
  3174. delete deprecated;
  3175. deprecated = nullptr;
  3176. }
  3177. if (!foundValues) {
  3178. delete popup;
  3179. popup = nullptr;
  3180. } else if (foundDeprecated) {
  3181. popup->addMenu(deprecated);
  3182. }
  3183. return popup;
  3184. }
  3185. void OBSBasic::AddSourceFromAction()
  3186. {
  3187. QAction *action = qobject_cast<QAction*>(sender());
  3188. if (!action)
  3189. return;
  3190. AddSource(QT_TO_UTF8(action->data().toString()));
  3191. }
  3192. void OBSBasic::AddSourcePopupMenu(const QPoint &pos)
  3193. {
  3194. if (!GetCurrentScene()) {
  3195. // Tell the user he needs a scene first (help beginners).
  3196. OBSMessageBox::information(this,
  3197. QTStr("Basic.Main.AddSourceHelp.Title"),
  3198. QTStr("Basic.Main.AddSourceHelp.Text"));
  3199. return;
  3200. }
  3201. QPointer<QMenu> popup = CreateAddSourcePopupMenu();
  3202. if (popup)
  3203. popup->exec(pos);
  3204. }
  3205. void OBSBasic::on_actionAddSource_triggered()
  3206. {
  3207. AddSourcePopupMenu(QCursor::pos());
  3208. }
  3209. void OBSBasic::on_actionRemoveSource_triggered()
  3210. {
  3211. vector<OBSSceneItem> items;
  3212. auto func = [] (obs_scene_t *, obs_sceneitem_t *item, void *param)
  3213. {
  3214. vector<OBSSceneItem> &items =
  3215. *reinterpret_cast<vector<OBSSceneItem>*>(param);
  3216. if (obs_sceneitem_selected(item))
  3217. items.emplace_back(item);
  3218. return true;
  3219. };
  3220. obs_scene_enum_items(GetCurrentScene(), func, &items);
  3221. if (!items.size())
  3222. return;
  3223. auto removeMultiple = [this] (size_t count)
  3224. {
  3225. QString text = QTStr("ConfirmRemove.TextMultiple")
  3226. .arg(QString::number(count));
  3227. QMessageBox remove_items(this);
  3228. remove_items.setText(text);
  3229. QAbstractButton *Yes = remove_items.addButton(QTStr("Yes"),
  3230. QMessageBox::YesRole);
  3231. remove_items.addButton(QTStr("No"), QMessageBox::NoRole);
  3232. remove_items.setIcon(QMessageBox::Question);
  3233. remove_items.setWindowTitle(QTStr("ConfirmRemove.Title"));
  3234. remove_items.exec();
  3235. return Yes == remove_items.clickedButton();
  3236. };
  3237. if (items.size() == 1) {
  3238. OBSSceneItem &item = items[0];
  3239. obs_source_t *source = obs_sceneitem_get_source(item);
  3240. if (source && QueryRemoveSource(source))
  3241. obs_sceneitem_remove(item);
  3242. } else {
  3243. if (removeMultiple(items.size())) {
  3244. for (auto &item : items)
  3245. obs_sceneitem_remove(item);
  3246. }
  3247. }
  3248. }
  3249. void OBSBasic::on_actionInteract_triggered()
  3250. {
  3251. OBSSceneItem item = GetCurrentSceneItem();
  3252. OBSSource source = obs_sceneitem_get_source(item);
  3253. if (source)
  3254. CreateInteractionWindow(source);
  3255. }
  3256. void OBSBasic::on_actionSourceProperties_triggered()
  3257. {
  3258. OBSSceneItem item = GetCurrentSceneItem();
  3259. OBSSource source = obs_sceneitem_get_source(item);
  3260. if (source)
  3261. CreatePropertiesWindow(source);
  3262. }
  3263. void OBSBasic::on_actionSourceUp_triggered()
  3264. {
  3265. OBSSceneItem item = GetCurrentSceneItem();
  3266. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_UP);
  3267. }
  3268. void OBSBasic::on_actionSourceDown_triggered()
  3269. {
  3270. OBSSceneItem item = GetCurrentSceneItem();
  3271. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_DOWN);
  3272. }
  3273. void OBSBasic::on_actionMoveUp_triggered()
  3274. {
  3275. OBSSceneItem item = GetCurrentSceneItem();
  3276. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_UP);
  3277. }
  3278. void OBSBasic::on_actionMoveDown_triggered()
  3279. {
  3280. OBSSceneItem item = GetCurrentSceneItem();
  3281. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_DOWN);
  3282. }
  3283. void OBSBasic::on_actionMoveToTop_triggered()
  3284. {
  3285. OBSSceneItem item = GetCurrentSceneItem();
  3286. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_TOP);
  3287. }
  3288. void OBSBasic::on_actionMoveToBottom_triggered()
  3289. {
  3290. OBSSceneItem item = GetCurrentSceneItem();
  3291. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_BOTTOM);
  3292. }
  3293. static BPtr<char> ReadLogFile(const char *log)
  3294. {
  3295. char logDir[512];
  3296. if (GetConfigPath(logDir, sizeof(logDir), "obs-studio/logs") <= 0)
  3297. return nullptr;
  3298. string path = (char*)logDir;
  3299. path += "/";
  3300. path += log;
  3301. BPtr<char> file = os_quick_read_utf8_file(path.c_str());
  3302. if (!file)
  3303. blog(LOG_WARNING, "Failed to read log file %s", path.c_str());
  3304. return file;
  3305. }
  3306. void OBSBasic::UploadLog(const char *file)
  3307. {
  3308. BPtr<char> fileString{ReadLogFile(file)};
  3309. if (!fileString)
  3310. return;
  3311. if (!*fileString)
  3312. return;
  3313. ui->menuLogFiles->setEnabled(false);
  3314. auto data_deleter = [](obs_data_t *d) { obs_data_release(d); };
  3315. using data_t = unique_ptr<struct obs_data, decltype(data_deleter)>;
  3316. data_t content{obs_data_create(), data_deleter};
  3317. data_t files{obs_data_create(), data_deleter};
  3318. data_t request{obs_data_create(), data_deleter};
  3319. obs_data_set_string(content.get(), "content", fileString);
  3320. obs_data_set_obj(files.get(), file, content.get());
  3321. stringstream ss;
  3322. ss << "OBS " << App()->GetVersionString()
  3323. << " log file uploaded at " << CurrentDateTimeString();
  3324. obs_data_set_string(request.get(), "description", ss.str().c_str());
  3325. obs_data_set_bool(request.get(), "public", false);
  3326. obs_data_set_obj(request.get(), "files", files.get());
  3327. const char *json = obs_data_get_json(request.get());
  3328. if (!json) {
  3329. blog(LOG_ERROR, "Failed to get JSON data for log upload");
  3330. return;
  3331. }
  3332. QBuffer *postData = new QBuffer();
  3333. postData->setData(json, (int) strlen(json));
  3334. if (logUploadThread) {
  3335. logUploadThread->wait();
  3336. delete logUploadThread;
  3337. }
  3338. RemoteTextThread *thread = new RemoteTextThread(
  3339. "https://api.github.com/gists",
  3340. "application/json", json);
  3341. logUploadThread = thread;
  3342. connect(thread, &RemoteTextThread::Result,
  3343. this, &OBSBasic::logUploadFinished);
  3344. logUploadThread->start();
  3345. }
  3346. void OBSBasic::on_actionShowLogs_triggered()
  3347. {
  3348. char logDir[512];
  3349. if (GetConfigPath(logDir, sizeof(logDir), "obs-studio/logs") <= 0)
  3350. return;
  3351. QUrl url = QUrl::fromLocalFile(QT_UTF8(logDir));
  3352. QDesktopServices::openUrl(url);
  3353. }
  3354. void OBSBasic::on_actionUploadCurrentLog_triggered()
  3355. {
  3356. UploadLog(App()->GetCurrentLog());
  3357. }
  3358. void OBSBasic::on_actionUploadLastLog_triggered()
  3359. {
  3360. UploadLog(App()->GetLastLog());
  3361. }
  3362. void OBSBasic::on_actionViewCurrentLog_triggered()
  3363. {
  3364. char logDir[512];
  3365. if (GetConfigPath(logDir, sizeof(logDir), "obs-studio/logs") <= 0)
  3366. return;
  3367. const char* log = App()->GetCurrentLog();
  3368. string path = (char*)logDir;
  3369. path += "/";
  3370. path += log;
  3371. QUrl url = QUrl::fromLocalFile(QT_UTF8(path.c_str()));
  3372. QDesktopServices::openUrl(url);
  3373. }
  3374. void OBSBasic::on_actionCheckForUpdates_triggered()
  3375. {
  3376. CheckForUpdates(true);
  3377. }
  3378. void OBSBasic::logUploadFinished(const QString &text, const QString &error)
  3379. {
  3380. ui->menuLogFiles->setEnabled(true);
  3381. if (text.isEmpty()) {
  3382. OBSMessageBox::information(this,
  3383. QTStr("LogReturnDialog.ErrorUploadingLog"),
  3384. error);
  3385. return;
  3386. }
  3387. obs_data_t *returnData = obs_data_create_from_json(QT_TO_UTF8(text));
  3388. QString logURL = obs_data_get_string(returnData, "html_url");
  3389. obs_data_release(returnData);
  3390. OBSLogReply logDialog(this, logURL);
  3391. logDialog.exec();
  3392. }
  3393. static void RenameListItem(OBSBasic *parent, QListWidget *listWidget,
  3394. obs_source_t *source, const string &name)
  3395. {
  3396. const char *prevName = obs_source_get_name(source);
  3397. if (name == prevName)
  3398. return;
  3399. obs_source_t *foundSource = obs_get_source_by_name(name.c_str());
  3400. QListWidgetItem *listItem = listWidget->currentItem();
  3401. if (foundSource || name.empty()) {
  3402. listItem->setText(QT_UTF8(prevName));
  3403. if (foundSource) {
  3404. OBSMessageBox::information(parent,
  3405. QTStr("NameExists.Title"),
  3406. QTStr("NameExists.Text"));
  3407. } else if (name.empty()) {
  3408. OBSMessageBox::information(parent,
  3409. QTStr("NoNameEntered.Title"),
  3410. QTStr("NoNameEntered.Text"));
  3411. }
  3412. obs_source_release(foundSource);
  3413. } else {
  3414. listItem->setText(QT_UTF8(name.c_str()));
  3415. obs_source_set_name(source, name.c_str());
  3416. }
  3417. }
  3418. void OBSBasic::SceneNameEdited(QWidget *editor,
  3419. QAbstractItemDelegate::EndEditHint endHint)
  3420. {
  3421. OBSScene scene = GetCurrentScene();
  3422. QLineEdit *edit = qobject_cast<QLineEdit*>(editor);
  3423. string text = QT_TO_UTF8(edit->text().trimmed());
  3424. if (!scene)
  3425. return;
  3426. obs_source_t *source = obs_scene_get_source(scene);
  3427. RenameListItem(this, ui->scenes, source, text);
  3428. if (api)
  3429. api->on_event(OBS_FRONTEND_EVENT_SCENE_LIST_CHANGED);
  3430. UNUSED_PARAMETER(endHint);
  3431. }
  3432. void OBSBasic::SceneItemNameEdited(QWidget *editor,
  3433. QAbstractItemDelegate::EndEditHint endHint)
  3434. {
  3435. OBSSceneItem item = GetCurrentSceneItem();
  3436. QLineEdit *edit = qobject_cast<QLineEdit*>(editor);
  3437. string text = QT_TO_UTF8(edit->text().trimmed());
  3438. if (!item)
  3439. return;
  3440. obs_source_t *source = obs_sceneitem_get_source(item);
  3441. RenameListItem(this, ui->sources, source, text);
  3442. QListWidgetItem *listItem = ui->sources->currentItem();
  3443. listItem->setText(QString());
  3444. SetupVisibilityItem(ui->sources, listItem, item);
  3445. UNUSED_PARAMETER(endHint);
  3446. }
  3447. void OBSBasic::OpenFilters()
  3448. {
  3449. OBSSceneItem item = GetCurrentSceneItem();
  3450. OBSSource source = obs_sceneitem_get_source(item);
  3451. CreateFiltersWindow(source);
  3452. }
  3453. void OBSBasic::OpenSceneFilters()
  3454. {
  3455. OBSScene scene = GetCurrentScene();
  3456. OBSSource source = obs_scene_get_source(scene);
  3457. CreateFiltersWindow(source);
  3458. }
  3459. #define RECORDING_START \
  3460. "==== Recording Start ==============================================="
  3461. #define RECORDING_STOP \
  3462. "==== Recording Stop ================================================"
  3463. #define REPLAY_BUFFER_START \
  3464. "==== Replay Buffer Start ==========================================="
  3465. #define REPLAY_BUFFER_STOP \
  3466. "==== Replay Buffer Stop ============================================"
  3467. #define STREAMING_START \
  3468. "==== Streaming Start ==============================================="
  3469. #define STREAMING_STOP \
  3470. "==== Streaming Stop ================================================"
  3471. void OBSBasic::StartStreaming()
  3472. {
  3473. if (outputHandler->StreamingActive())
  3474. return;
  3475. if (disableOutputsRef)
  3476. return;
  3477. if (api)
  3478. api->on_event(OBS_FRONTEND_EVENT_STREAMING_STARTING);
  3479. SaveProject();
  3480. ui->streamButton->setEnabled(false);
  3481. ui->streamButton->setText(QTStr("Basic.Main.Connecting"));
  3482. if (sysTrayStream) {
  3483. sysTrayStream->setEnabled(false);
  3484. sysTrayStream->setText(ui->streamButton->text());
  3485. }
  3486. if (!outputHandler->StartStreaming(service)) {
  3487. ui->streamButton->setText(QTStr("Basic.Main.StartStreaming"));
  3488. ui->streamButton->setEnabled(true);
  3489. ui->streamButton->setChecked(false);
  3490. if (sysTrayStream) {
  3491. sysTrayStream->setText(ui->streamButton->text());
  3492. sysTrayStream->setEnabled(true);
  3493. }
  3494. QMessageBox::critical(this,
  3495. QTStr("Output.StartStreamFailed"),
  3496. QTStr("Output.StartFailedGeneric"));
  3497. return;
  3498. }
  3499. bool recordWhenStreaming = config_get_bool(GetGlobalConfig(),
  3500. "BasicWindow", "RecordWhenStreaming");
  3501. if (recordWhenStreaming)
  3502. StartRecording();
  3503. bool replayBufferWhileStreaming = config_get_bool(GetGlobalConfig(),
  3504. "BasicWindow", "ReplayBufferWhileStreaming");
  3505. if (replayBufferWhileStreaming)
  3506. StartReplayBuffer();
  3507. }
  3508. #ifdef _WIN32
  3509. static inline void UpdateProcessPriority()
  3510. {
  3511. const char *priority = config_get_string(App()->GlobalConfig(),
  3512. "General", "ProcessPriority");
  3513. if (priority && strcmp(priority, "Normal") != 0)
  3514. SetProcessPriority(priority);
  3515. }
  3516. static inline void ClearProcessPriority()
  3517. {
  3518. const char *priority = config_get_string(App()->GlobalConfig(),
  3519. "General", "ProcessPriority");
  3520. if (priority && strcmp(priority, "Normal") != 0)
  3521. SetProcessPriority("Normal");
  3522. }
  3523. #else
  3524. #define UpdateProcessPriority() do {} while(false)
  3525. #define ClearProcessPriority() do {} while(false)
  3526. #endif
  3527. inline void OBSBasic::OnActivate()
  3528. {
  3529. if (ui->profileMenu->isEnabled()) {
  3530. ui->profileMenu->setEnabled(false);
  3531. ui->autoConfigure->setEnabled(false);
  3532. App()->IncrementSleepInhibition();
  3533. UpdateProcessPriority();
  3534. if (trayIcon)
  3535. trayIcon->setIcon(QIcon(":/res/images/tray_active.png"));
  3536. }
  3537. }
  3538. inline void OBSBasic::OnDeactivate()
  3539. {
  3540. if (!outputHandler->Active() && !ui->profileMenu->isEnabled()) {
  3541. ui->profileMenu->setEnabled(true);
  3542. ui->autoConfigure->setEnabled(true);
  3543. App()->DecrementSleepInhibition();
  3544. ClearProcessPriority();
  3545. if (trayIcon)
  3546. trayIcon->setIcon(QIcon(":/res/images/obs.png"));
  3547. }
  3548. }
  3549. void OBSBasic::StopStreaming()
  3550. {
  3551. SaveProject();
  3552. if (outputHandler->StreamingActive())
  3553. outputHandler->StopStreaming(streamingStopping);
  3554. OnDeactivate();
  3555. bool recordWhenStreaming = config_get_bool(GetGlobalConfig(),
  3556. "BasicWindow", "RecordWhenStreaming");
  3557. bool keepRecordingWhenStreamStops = config_get_bool(GetGlobalConfig(),
  3558. "BasicWindow", "KeepRecordingWhenStreamStops");
  3559. if (recordWhenStreaming && !keepRecordingWhenStreamStops)
  3560. StopRecording();
  3561. bool replayBufferWhileStreaming = config_get_bool(GetGlobalConfig(),
  3562. "BasicWindow", "ReplayBufferWhileStreaming");
  3563. bool keepReplayBufferStreamStops = config_get_bool(GetGlobalConfig(),
  3564. "BasicWindow", "KeepReplayBufferStreamStops");
  3565. if (replayBufferWhileStreaming && !keepReplayBufferStreamStops)
  3566. StopReplayBuffer();
  3567. }
  3568. void OBSBasic::ForceStopStreaming()
  3569. {
  3570. SaveProject();
  3571. if (outputHandler->StreamingActive())
  3572. outputHandler->StopStreaming(true);
  3573. OnDeactivate();
  3574. bool recordWhenStreaming = config_get_bool(GetGlobalConfig(),
  3575. "BasicWindow", "RecordWhenStreaming");
  3576. bool keepRecordingWhenStreamStops = config_get_bool(GetGlobalConfig(),
  3577. "BasicWindow", "KeepRecordingWhenStreamStops");
  3578. if (recordWhenStreaming && !keepRecordingWhenStreamStops)
  3579. StopRecording();
  3580. bool replayBufferWhileStreaming = config_get_bool(GetGlobalConfig(),
  3581. "BasicWindow", "ReplayBufferWhileStreaming");
  3582. bool keepReplayBufferStreamStops = config_get_bool(GetGlobalConfig(),
  3583. "BasicWindow", "KeepReplayBufferStreamStops");
  3584. if (replayBufferWhileStreaming && !keepReplayBufferStreamStops)
  3585. StopReplayBuffer();
  3586. }
  3587. void OBSBasic::StreamDelayStarting(int sec)
  3588. {
  3589. ui->streamButton->setText(QTStr("Basic.Main.StopStreaming"));
  3590. ui->streamButton->setEnabled(true);
  3591. ui->streamButton->setChecked(true);
  3592. if (sysTrayStream) {
  3593. sysTrayStream->setText(ui->streamButton->text());
  3594. sysTrayStream->setEnabled(true);
  3595. }
  3596. if (!startStreamMenu.isNull())
  3597. startStreamMenu->deleteLater();
  3598. startStreamMenu = new QMenu();
  3599. startStreamMenu->addAction(QTStr("Basic.Main.StopStreaming"),
  3600. this, SLOT(StopStreaming()));
  3601. startStreamMenu->addAction(QTStr("Basic.Main.ForceStopStreaming"),
  3602. this, SLOT(ForceStopStreaming()));
  3603. ui->streamButton->setMenu(startStreamMenu);
  3604. ui->statusbar->StreamDelayStarting(sec);
  3605. OnActivate();
  3606. }
  3607. void OBSBasic::StreamDelayStopping(int sec)
  3608. {
  3609. ui->streamButton->setText(QTStr("Basic.Main.StartStreaming"));
  3610. ui->streamButton->setEnabled(true);
  3611. ui->streamButton->setChecked(false);
  3612. if (sysTrayStream) {
  3613. sysTrayStream->setText(ui->streamButton->text());
  3614. sysTrayStream->setEnabled(true);
  3615. }
  3616. if (!startStreamMenu.isNull())
  3617. startStreamMenu->deleteLater();
  3618. startStreamMenu = new QMenu();
  3619. startStreamMenu->addAction(QTStr("Basic.Main.StartStreaming"),
  3620. this, SLOT(StartStreaming()));
  3621. startStreamMenu->addAction(QTStr("Basic.Main.ForceStopStreaming"),
  3622. this, SLOT(ForceStopStreaming()));
  3623. ui->streamButton->setMenu(startStreamMenu);
  3624. ui->statusbar->StreamDelayStopping(sec);
  3625. }
  3626. void OBSBasic::StreamingStart()
  3627. {
  3628. ui->streamButton->setText(QTStr("Basic.Main.StopStreaming"));
  3629. ui->streamButton->setEnabled(true);
  3630. ui->streamButton->setChecked(true);
  3631. ui->statusbar->StreamStarted(outputHandler->streamOutput);
  3632. if (sysTrayStream) {
  3633. sysTrayStream->setText(ui->streamButton->text());
  3634. sysTrayStream->setEnabled(true);
  3635. }
  3636. if (api)
  3637. api->on_event(OBS_FRONTEND_EVENT_STREAMING_STARTED);
  3638. OnActivate();
  3639. blog(LOG_INFO, STREAMING_START);
  3640. }
  3641. void OBSBasic::StreamStopping()
  3642. {
  3643. ui->streamButton->setText(QTStr("Basic.Main.StoppingStreaming"));
  3644. if (sysTrayStream)
  3645. sysTrayStream->setText(ui->streamButton->text());
  3646. streamingStopping = true;
  3647. if (api)
  3648. api->on_event(OBS_FRONTEND_EVENT_STREAMING_STOPPING);
  3649. }
  3650. void OBSBasic::StreamingStop(int code, QString last_error)
  3651. {
  3652. const char *errorDescription;
  3653. DStr errorMessage;
  3654. bool use_last_error = false;
  3655. switch (code) {
  3656. case OBS_OUTPUT_BAD_PATH:
  3657. errorDescription = Str("Output.ConnectFail.BadPath");
  3658. break;
  3659. case OBS_OUTPUT_CONNECT_FAILED:
  3660. use_last_error = true;
  3661. errorDescription = Str("Output.ConnectFail.ConnectFailed");
  3662. break;
  3663. case OBS_OUTPUT_INVALID_STREAM:
  3664. errorDescription = Str("Output.ConnectFail.InvalidStream");
  3665. break;
  3666. default:
  3667. case OBS_OUTPUT_ERROR:
  3668. use_last_error = true;
  3669. errorDescription = Str("Output.ConnectFail.Error");
  3670. break;
  3671. case OBS_OUTPUT_DISCONNECTED:
  3672. /* doesn't happen if output is set to reconnect. note that
  3673. * reconnects are handled in the output, not in the UI */
  3674. use_last_error = true;
  3675. errorDescription = Str("Output.ConnectFail.Disconnected");
  3676. }
  3677. if (use_last_error && !last_error.isEmpty())
  3678. dstr_printf(errorMessage, "%s\n\n%s", errorDescription,
  3679. QT_TO_UTF8(last_error));
  3680. else
  3681. dstr_copy(errorMessage, errorDescription);
  3682. ui->statusbar->StreamStopped();
  3683. ui->streamButton->setText(QTStr("Basic.Main.StartStreaming"));
  3684. ui->streamButton->setEnabled(true);
  3685. ui->streamButton->setChecked(false);
  3686. if (sysTrayStream) {
  3687. sysTrayStream->setText(ui->streamButton->text());
  3688. sysTrayStream->setEnabled(true);
  3689. }
  3690. streamingStopping = false;
  3691. if (api)
  3692. api->on_event(OBS_FRONTEND_EVENT_STREAMING_STOPPED);
  3693. OnDeactivate();
  3694. blog(LOG_INFO, STREAMING_STOP);
  3695. if (code != OBS_OUTPUT_SUCCESS && isVisible()) {
  3696. OBSMessageBox::information(this,
  3697. QTStr("Output.ConnectFail.Title"),
  3698. QT_UTF8(errorMessage));
  3699. } else if (code != OBS_OUTPUT_SUCCESS && !isVisible()) {
  3700. SysTrayNotify(QT_UTF8(errorDescription), QSystemTrayIcon::Warning);
  3701. }
  3702. if (!startStreamMenu.isNull()) {
  3703. ui->streamButton->setMenu(nullptr);
  3704. startStreamMenu->deleteLater();
  3705. startStreamMenu = nullptr;
  3706. }
  3707. }
  3708. void OBSBasic::StartRecording()
  3709. {
  3710. if (outputHandler->RecordingActive())
  3711. return;
  3712. if (disableOutputsRef)
  3713. return;
  3714. if (api)
  3715. api->on_event(OBS_FRONTEND_EVENT_RECORDING_STARTING);
  3716. SaveProject();
  3717. outputHandler->StartRecording();
  3718. }
  3719. void OBSBasic::RecordStopping()
  3720. {
  3721. ui->recordButton->setText(QTStr("Basic.Main.StoppingRecording"));
  3722. if (sysTrayRecord)
  3723. sysTrayRecord->setText(ui->recordButton->text());
  3724. recordingStopping = true;
  3725. if (api)
  3726. api->on_event(OBS_FRONTEND_EVENT_RECORDING_STOPPING);
  3727. }
  3728. void OBSBasic::StopRecording()
  3729. {
  3730. SaveProject();
  3731. if (outputHandler->RecordingActive())
  3732. outputHandler->StopRecording(recordingStopping);
  3733. OnDeactivate();
  3734. }
  3735. void OBSBasic::RecordingStart()
  3736. {
  3737. ui->statusbar->RecordingStarted(outputHandler->fileOutput);
  3738. ui->recordButton->setText(QTStr("Basic.Main.StopRecording"));
  3739. ui->recordButton->setChecked(true);
  3740. if (sysTrayRecord)
  3741. sysTrayRecord->setText(ui->recordButton->text());
  3742. recordingStopping = false;
  3743. if (api)
  3744. api->on_event(OBS_FRONTEND_EVENT_RECORDING_STARTED);
  3745. OnActivate();
  3746. blog(LOG_INFO, RECORDING_START);
  3747. }
  3748. void OBSBasic::RecordingStop(int code)
  3749. {
  3750. ui->statusbar->RecordingStopped();
  3751. ui->recordButton->setText(QTStr("Basic.Main.StartRecording"));
  3752. ui->recordButton->setChecked(false);
  3753. if (sysTrayRecord)
  3754. sysTrayRecord->setText(ui->recordButton->text());
  3755. blog(LOG_INFO, RECORDING_STOP);
  3756. if (code == OBS_OUTPUT_UNSUPPORTED && isVisible()) {
  3757. OBSMessageBox::information(this,
  3758. QTStr("Output.RecordFail.Title"),
  3759. QTStr("Output.RecordFail.Unsupported"));
  3760. } else if (code == OBS_OUTPUT_NO_SPACE && isVisible()) {
  3761. OBSMessageBox::information(this,
  3762. QTStr("Output.RecordNoSpace.Title"),
  3763. QTStr("Output.RecordNoSpace.Msg"));
  3764. } else if (code != OBS_OUTPUT_SUCCESS && isVisible()) {
  3765. OBSMessageBox::information(this,
  3766. QTStr("Output.RecordError.Title"),
  3767. QTStr("Output.RecordError.Msg"));
  3768. } else if (code == OBS_OUTPUT_UNSUPPORTED && !isVisible()) {
  3769. SysTrayNotify(QTStr("Output.RecordFail.Unsupported"),
  3770. QSystemTrayIcon::Warning);
  3771. } else if (code == OBS_OUTPUT_NO_SPACE && !isVisible()) {
  3772. SysTrayNotify(QTStr("Output.RecordNoSpace.Msg"),
  3773. QSystemTrayIcon::Warning);
  3774. } else if (code != OBS_OUTPUT_SUCCESS && !isVisible()) {
  3775. SysTrayNotify(QTStr("Output.RecordError.Msg"),
  3776. QSystemTrayIcon::Warning);
  3777. }
  3778. if (api)
  3779. api->on_event(OBS_FRONTEND_EVENT_RECORDING_STOPPED);
  3780. OnDeactivate();
  3781. }
  3782. #define RP_NO_HOTKEY_TITLE QTStr("Output.ReplayBuffer.NoHotkey.Title")
  3783. #define RP_NO_HOTKEY_TEXT QTStr("Output.ReplayBuffer.NoHotkey.Msg")
  3784. void OBSBasic::StartReplayBuffer()
  3785. {
  3786. if (!outputHandler || !outputHandler->replayBuffer)
  3787. return;
  3788. if (outputHandler->ReplayBufferActive())
  3789. return;
  3790. if (disableOutputsRef)
  3791. return;
  3792. obs_output_t *output = outputHandler->replayBuffer;
  3793. obs_data_t *hotkeys = obs_hotkeys_save_output(output);
  3794. obs_data_array_t *bindings = obs_data_get_array(hotkeys,
  3795. "ReplayBuffer.Save");
  3796. size_t count = obs_data_array_count(bindings);
  3797. obs_data_array_release(bindings);
  3798. obs_data_release(hotkeys);
  3799. if (!count) {
  3800. OBSMessageBox::information(this,
  3801. RP_NO_HOTKEY_TITLE,
  3802. RP_NO_HOTKEY_TEXT);
  3803. return;
  3804. }
  3805. if (api)
  3806. api->on_event(OBS_FRONTEND_EVENT_REPLAY_BUFFER_STARTING);
  3807. SaveProject();
  3808. outputHandler->StartReplayBuffer();
  3809. }
  3810. void OBSBasic::ReplayBufferStopping()
  3811. {
  3812. if (!outputHandler || !outputHandler->replayBuffer)
  3813. return;
  3814. replayBufferButton->setText(QTStr("Basic.Main.StoppingReplayBuffer"));
  3815. if (sysTrayReplayBuffer)
  3816. sysTrayReplayBuffer->setText(replayBufferButton->text());
  3817. replayBufferStopping = true;
  3818. if (api)
  3819. api->on_event(OBS_FRONTEND_EVENT_REPLAY_BUFFER_STOPPING);
  3820. }
  3821. void OBSBasic::StopReplayBuffer()
  3822. {
  3823. if (!outputHandler || !outputHandler->replayBuffer)
  3824. return;
  3825. SaveProject();
  3826. if (outputHandler->ReplayBufferActive())
  3827. outputHandler->StopReplayBuffer(replayBufferStopping);
  3828. OnDeactivate();
  3829. }
  3830. void OBSBasic::ReplayBufferStart()
  3831. {
  3832. if (!outputHandler || !outputHandler->replayBuffer)
  3833. return;
  3834. replayBufferButton->setText(QTStr("Basic.Main.StopReplayBuffer"));
  3835. if (sysTrayReplayBuffer)
  3836. sysTrayReplayBuffer->setText(replayBufferButton->text());
  3837. replayBufferStopping = false;
  3838. if (api)
  3839. api->on_event(OBS_FRONTEND_EVENT_REPLAY_BUFFER_STARTED);
  3840. OnActivate();
  3841. blog(LOG_INFO, REPLAY_BUFFER_START);
  3842. }
  3843. void OBSBasic::ReplayBufferSave()
  3844. {
  3845. if (!outputHandler || !outputHandler->replayBuffer)
  3846. return;
  3847. if (!outputHandler->ReplayBufferActive())
  3848. return;
  3849. calldata_t cd = {0};
  3850. proc_handler_t *ph = obs_output_get_proc_handler(
  3851. outputHandler->replayBuffer);
  3852. proc_handler_call(ph, "save", &cd);
  3853. calldata_free(&cd);
  3854. }
  3855. void OBSBasic::ReplayBufferStop(int code)
  3856. {
  3857. if (!outputHandler || !outputHandler->replayBuffer)
  3858. return;
  3859. replayBufferButton->setText(QTStr("Basic.Main.StartReplayBuffer"));
  3860. if (sysTrayReplayBuffer)
  3861. sysTrayReplayBuffer->setText(replayBufferButton->text());
  3862. blog(LOG_INFO, REPLAY_BUFFER_STOP);
  3863. if (code == OBS_OUTPUT_UNSUPPORTED && isVisible()) {
  3864. OBSMessageBox::information(this,
  3865. QTStr("Output.RecordFail.Title"),
  3866. QTStr("Output.RecordFail.Unsupported"));
  3867. } else if (code == OBS_OUTPUT_NO_SPACE && isVisible()) {
  3868. OBSMessageBox::information(this,
  3869. QTStr("Output.RecordNoSpace.Title"),
  3870. QTStr("Output.RecordNoSpace.Msg"));
  3871. } else if (code != OBS_OUTPUT_SUCCESS && isVisible()) {
  3872. OBSMessageBox::information(this,
  3873. QTStr("Output.RecordError.Title"),
  3874. QTStr("Output.RecordError.Msg"));
  3875. } else if (code == OBS_OUTPUT_UNSUPPORTED && !isVisible()) {
  3876. SysTrayNotify(QTStr("Output.RecordFail.Unsupported"),
  3877. QSystemTrayIcon::Warning);
  3878. } else if (code == OBS_OUTPUT_NO_SPACE && !isVisible()) {
  3879. SysTrayNotify(QTStr("Output.RecordNoSpace.Msg"),
  3880. QSystemTrayIcon::Warning);
  3881. } else if (code != OBS_OUTPUT_SUCCESS && !isVisible()) {
  3882. SysTrayNotify(QTStr("Output.RecordError.Msg"),
  3883. QSystemTrayIcon::Warning);
  3884. }
  3885. if (api)
  3886. api->on_event(OBS_FRONTEND_EVENT_REPLAY_BUFFER_STOPPED);
  3887. OnDeactivate();
  3888. }
  3889. void OBSBasic::on_streamButton_clicked()
  3890. {
  3891. if (outputHandler->StreamingActive()) {
  3892. bool confirm = config_get_bool(GetGlobalConfig(), "BasicWindow",
  3893. "WarnBeforeStoppingStream");
  3894. if (confirm && isVisible()) {
  3895. QMessageBox::StandardButton button =
  3896. OBSMessageBox::question(this,
  3897. QTStr("ConfirmStop.Title"),
  3898. QTStr("ConfirmStop.Text"));
  3899. if (button == QMessageBox::No)
  3900. return;
  3901. }
  3902. StopStreaming();
  3903. } else {
  3904. bool confirm = config_get_bool(GetGlobalConfig(), "BasicWindow",
  3905. "WarnBeforeStartingStream");
  3906. if (confirm && isVisible()) {
  3907. QMessageBox::StandardButton button =
  3908. OBSMessageBox::question(this,
  3909. QTStr("ConfirmStart.Title"),
  3910. QTStr("ConfirmStart.Text"));
  3911. if (button == QMessageBox::No)
  3912. return;
  3913. }
  3914. StartStreaming();
  3915. }
  3916. }
  3917. void OBSBasic::on_recordButton_clicked()
  3918. {
  3919. if (outputHandler->RecordingActive())
  3920. StopRecording();
  3921. else
  3922. StartRecording();
  3923. }
  3924. void OBSBasic::on_settingsButton_clicked()
  3925. {
  3926. on_action_Settings_triggered();
  3927. }
  3928. void OBSBasic::on_actionWebsite_triggered()
  3929. {
  3930. QUrl url = QUrl("https://obsproject.com", QUrl::TolerantMode);
  3931. QDesktopServices::openUrl(url);
  3932. }
  3933. void OBSBasic::on_actionShowSettingsFolder_triggered()
  3934. {
  3935. char path[512];
  3936. int ret = GetConfigPath(path, 512, "obs-studio");
  3937. if (ret <= 0)
  3938. return;
  3939. QDesktopServices::openUrl(QUrl::fromLocalFile(path));
  3940. }
  3941. void OBSBasic::on_actionShowProfileFolder_triggered()
  3942. {
  3943. char path[512];
  3944. int ret = GetProfilePath(path, 512, "");
  3945. if (ret <= 0)
  3946. return;
  3947. QDesktopServices::openUrl(QUrl::fromLocalFile(path));
  3948. }
  3949. QListWidgetItem *OBSBasic::GetTopSelectedSourceItem()
  3950. {
  3951. QList<QListWidgetItem*> selectedItems = ui->sources->selectedItems();
  3952. QListWidgetItem *topItem = nullptr;
  3953. if (selectedItems.size() != 0)
  3954. topItem = selectedItems[0];
  3955. return topItem;
  3956. }
  3957. void OBSBasic::on_preview_customContextMenuRequested(const QPoint &pos)
  3958. {
  3959. CreateSourcePopupMenu(GetTopSelectedSourceItem(), true);
  3960. UNUSED_PARAMETER(pos);
  3961. }
  3962. void OBSBasic::on_program_customContextMenuRequested(const QPoint&)
  3963. {
  3964. QMenu popup(this);
  3965. QPointer<QMenu> studioProgramProjector;
  3966. studioProgramProjector = new QMenu(
  3967. QTStr("StudioProgramProjector"));
  3968. AddProjectorMenuMonitors(studioProgramProjector, this,
  3969. SLOT(OpenPreviewProjector()));
  3970. popup.addMenu(studioProgramProjector);
  3971. QAction *studioProgramWindow = popup.addAction(
  3972. QTStr("StudioProgramWindow"),
  3973. this, SLOT(OpenPreviewWindow()));
  3974. popup.addAction(studioProgramWindow);
  3975. popup.exec(QCursor::pos());
  3976. }
  3977. void OBSBasic::on_previewDisabledLabel_customContextMenuRequested(
  3978. const QPoint &pos)
  3979. {
  3980. QMenu popup(this);
  3981. QPointer<QMenu> previewProjector;
  3982. QAction *action = popup.addAction(
  3983. QTStr("Basic.Main.PreviewConextMenu.Enable"),
  3984. this, SLOT(TogglePreview()));
  3985. action->setCheckable(true);
  3986. action->setChecked(obs_display_enabled(ui->preview->GetDisplay()));
  3987. previewProjector = new QMenu(QTStr("PreviewProjector"));
  3988. AddProjectorMenuMonitors(previewProjector, this,
  3989. SLOT(OpenPreviewProjector()));
  3990. QAction *previewWindow = popup.addAction(
  3991. QTStr("PreviewWindow"),
  3992. this, SLOT(OpenPreviewWindow()));
  3993. popup.addMenu(previewProjector);
  3994. popup.addAction(previewWindow);
  3995. popup.exec(QCursor::pos());
  3996. UNUSED_PARAMETER(pos);
  3997. }
  3998. void OBSBasic::on_actionAlwaysOnTop_triggered()
  3999. {
  4000. CloseDialogs();
  4001. /* Make sure all dialogs are safely and successfully closed before
  4002. * switching the always on top mode due to the fact that windows all
  4003. * have to be recreated, so queue the actual toggle to happen after
  4004. * all events related to closing the dialogs have finished */
  4005. QMetaObject::invokeMethod(this, "ToggleAlwaysOnTop",
  4006. Qt::QueuedConnection);
  4007. }
  4008. void OBSBasic::ToggleAlwaysOnTop()
  4009. {
  4010. bool isAlwaysOnTop = IsAlwaysOnTop(this);
  4011. ui->actionAlwaysOnTop->setChecked(!isAlwaysOnTop);
  4012. SetAlwaysOnTop(this, !isAlwaysOnTop);
  4013. show();
  4014. }
  4015. void OBSBasic::GetFPSCommon(uint32_t &num, uint32_t &den) const
  4016. {
  4017. const char *val = config_get_string(basicConfig, "Video", "FPSCommon");
  4018. if (strcmp(val, "10") == 0) {
  4019. num = 10;
  4020. den = 1;
  4021. } else if (strcmp(val, "20") == 0) {
  4022. num = 20;
  4023. den = 1;
  4024. } else if (strcmp(val, "24 NTSC") == 0) {
  4025. num = 24000;
  4026. den = 1001;
  4027. } else if (strcmp(val, "25") == 0) {
  4028. num = 25;
  4029. den = 1;
  4030. } else if (strcmp(val, "29.97") == 0) {
  4031. num = 30000;
  4032. den = 1001;
  4033. } else if (strcmp(val, "48") == 0) {
  4034. num = 48;
  4035. den = 1;
  4036. } else if (strcmp(val, "59.94") == 0) {
  4037. num = 60000;
  4038. den = 1001;
  4039. } else if (strcmp(val, "60") == 0) {
  4040. num = 60;
  4041. den = 1;
  4042. } else {
  4043. num = 30;
  4044. den = 1;
  4045. }
  4046. }
  4047. void OBSBasic::GetFPSInteger(uint32_t &num, uint32_t &den) const
  4048. {
  4049. num = (uint32_t)config_get_uint(basicConfig, "Video", "FPSInt");
  4050. den = 1;
  4051. }
  4052. void OBSBasic::GetFPSFraction(uint32_t &num, uint32_t &den) const
  4053. {
  4054. num = (uint32_t)config_get_uint(basicConfig, "Video", "FPSNum");
  4055. den = (uint32_t)config_get_uint(basicConfig, "Video", "FPSDen");
  4056. }
  4057. void OBSBasic::GetFPSNanoseconds(uint32_t &num, uint32_t &den) const
  4058. {
  4059. num = 1000000000;
  4060. den = (uint32_t)config_get_uint(basicConfig, "Video", "FPSNS");
  4061. }
  4062. void OBSBasic::GetConfigFPS(uint32_t &num, uint32_t &den) const
  4063. {
  4064. uint32_t type = config_get_uint(basicConfig, "Video", "FPSType");
  4065. if (type == 1) //"Integer"
  4066. GetFPSInteger(num, den);
  4067. else if (type == 2) //"Fraction"
  4068. GetFPSFraction(num, den);
  4069. else if (false) //"Nanoseconds", currently not implemented
  4070. GetFPSNanoseconds(num, den);
  4071. else
  4072. GetFPSCommon(num, den);
  4073. }
  4074. config_t *OBSBasic::Config() const
  4075. {
  4076. return basicConfig;
  4077. }
  4078. void OBSBasic::on_actionEditTransform_triggered()
  4079. {
  4080. if (transformWindow)
  4081. transformWindow->close();
  4082. transformWindow = new OBSBasicTransform(this);
  4083. transformWindow->show();
  4084. transformWindow->setAttribute(Qt::WA_DeleteOnClose, true);
  4085. }
  4086. static obs_transform_info copiedTransformInfo;
  4087. static obs_sceneitem_crop copiedCropInfo;
  4088. void OBSBasic::on_actionCopyTransform_triggered()
  4089. {
  4090. auto func = [](obs_scene_t *scene, obs_sceneitem_t *item, void *param)
  4091. {
  4092. if (!obs_sceneitem_selected(item))
  4093. return true;
  4094. obs_sceneitem_defer_update_begin(item);
  4095. obs_sceneitem_get_info(item, &copiedTransformInfo);
  4096. obs_sceneitem_get_crop(item, &copiedCropInfo);
  4097. obs_sceneitem_defer_update_end(item);
  4098. UNUSED_PARAMETER(scene);
  4099. UNUSED_PARAMETER(param);
  4100. return true;
  4101. };
  4102. obs_scene_enum_items(GetCurrentScene(), func, nullptr);
  4103. ui->actionPasteTransform->setEnabled(true);
  4104. }
  4105. void OBSBasic::on_actionPasteTransform_triggered()
  4106. {
  4107. auto func = [](obs_scene_t *scene, obs_sceneitem_t *item, void *param)
  4108. {
  4109. if (!obs_sceneitem_selected(item))
  4110. return true;
  4111. obs_sceneitem_defer_update_begin(item);
  4112. obs_sceneitem_set_info(item, &copiedTransformInfo);
  4113. obs_sceneitem_set_crop(item, &copiedCropInfo);
  4114. obs_sceneitem_defer_update_end(item);
  4115. UNUSED_PARAMETER(scene);
  4116. UNUSED_PARAMETER(param);
  4117. return true;
  4118. };
  4119. obs_scene_enum_items(GetCurrentScene(), func, nullptr);
  4120. }
  4121. void OBSBasic::on_actionResetTransform_triggered()
  4122. {
  4123. auto func = [] (obs_scene_t *scene, obs_sceneitem_t *item, void *param)
  4124. {
  4125. if (!obs_sceneitem_selected(item))
  4126. return true;
  4127. obs_sceneitem_defer_update_begin(item);
  4128. obs_transform_info info;
  4129. vec2_set(&info.pos, 0.0f, 0.0f);
  4130. vec2_set(&info.scale, 1.0f, 1.0f);
  4131. info.rot = 0.0f;
  4132. info.alignment = OBS_ALIGN_TOP | OBS_ALIGN_LEFT;
  4133. info.bounds_type = OBS_BOUNDS_NONE;
  4134. info.bounds_alignment = OBS_ALIGN_CENTER;
  4135. vec2_set(&info.bounds, 0.0f, 0.0f);
  4136. obs_sceneitem_set_info(item, &info);
  4137. obs_sceneitem_crop crop = {};
  4138. obs_sceneitem_set_crop(item, &crop);
  4139. obs_sceneitem_defer_update_end(item);
  4140. UNUSED_PARAMETER(scene);
  4141. UNUSED_PARAMETER(param);
  4142. return true;
  4143. };
  4144. obs_scene_enum_items(GetCurrentScene(), func, nullptr);
  4145. }
  4146. static void GetItemBox(obs_sceneitem_t *item, vec3 &tl, vec3 &br)
  4147. {
  4148. matrix4 boxTransform;
  4149. obs_sceneitem_get_box_transform(item, &boxTransform);
  4150. vec3_set(&tl, M_INFINITE, M_INFINITE, 0.0f);
  4151. vec3_set(&br, -M_INFINITE, -M_INFINITE, 0.0f);
  4152. auto GetMinPos = [&] (float x, float y)
  4153. {
  4154. vec3 pos;
  4155. vec3_set(&pos, x, y, 0.0f);
  4156. vec3_transform(&pos, &pos, &boxTransform);
  4157. vec3_min(&tl, &tl, &pos);
  4158. vec3_max(&br, &br, &pos);
  4159. };
  4160. GetMinPos(0.0f, 0.0f);
  4161. GetMinPos(1.0f, 0.0f);
  4162. GetMinPos(0.0f, 1.0f);
  4163. GetMinPos(1.0f, 1.0f);
  4164. }
  4165. static vec3 GetItemTL(obs_sceneitem_t *item)
  4166. {
  4167. vec3 tl, br;
  4168. GetItemBox(item, tl, br);
  4169. return tl;
  4170. }
  4171. static void SetItemTL(obs_sceneitem_t *item, const vec3 &tl)
  4172. {
  4173. vec3 newTL;
  4174. vec2 pos;
  4175. obs_sceneitem_get_pos(item, &pos);
  4176. newTL = GetItemTL(item);
  4177. pos.x += tl.x - newTL.x;
  4178. pos.y += tl.y - newTL.y;
  4179. obs_sceneitem_set_pos(item, &pos);
  4180. }
  4181. static bool RotateSelectedSources(obs_scene_t *scene, obs_sceneitem_t *item,
  4182. void *param)
  4183. {
  4184. if (!obs_sceneitem_selected(item))
  4185. return true;
  4186. float rot = *reinterpret_cast<float*>(param);
  4187. vec3 tl = GetItemTL(item);
  4188. rot += obs_sceneitem_get_rot(item);
  4189. if (rot >= 360.0f) rot -= 360.0f;
  4190. else if (rot <= -360.0f) rot += 360.0f;
  4191. obs_sceneitem_set_rot(item, rot);
  4192. SetItemTL(item, tl);
  4193. UNUSED_PARAMETER(scene);
  4194. UNUSED_PARAMETER(param);
  4195. return true;
  4196. };
  4197. void OBSBasic::on_actionRotate90CW_triggered()
  4198. {
  4199. float f90CW = 90.0f;
  4200. obs_scene_enum_items(GetCurrentScene(), RotateSelectedSources, &f90CW);
  4201. }
  4202. void OBSBasic::on_actionRotate90CCW_triggered()
  4203. {
  4204. float f90CCW = -90.0f;
  4205. obs_scene_enum_items(GetCurrentScene(), RotateSelectedSources, &f90CCW);
  4206. }
  4207. void OBSBasic::on_actionRotate180_triggered()
  4208. {
  4209. float f180 = 180.0f;
  4210. obs_scene_enum_items(GetCurrentScene(), RotateSelectedSources, &f180);
  4211. }
  4212. static bool MultiplySelectedItemScale(obs_scene_t *scene, obs_sceneitem_t *item,
  4213. void *param)
  4214. {
  4215. vec2 &mul = *reinterpret_cast<vec2*>(param);
  4216. if (!obs_sceneitem_selected(item))
  4217. return true;
  4218. vec3 tl = GetItemTL(item);
  4219. vec2 scale;
  4220. obs_sceneitem_get_scale(item, &scale);
  4221. vec2_mul(&scale, &scale, &mul);
  4222. obs_sceneitem_set_scale(item, &scale);
  4223. SetItemTL(item, tl);
  4224. UNUSED_PARAMETER(scene);
  4225. return true;
  4226. }
  4227. void OBSBasic::on_actionFlipHorizontal_triggered()
  4228. {
  4229. vec2 scale;
  4230. vec2_set(&scale, -1.0f, 1.0f);
  4231. obs_scene_enum_items(GetCurrentScene(), MultiplySelectedItemScale,
  4232. &scale);
  4233. }
  4234. void OBSBasic::on_actionFlipVertical_triggered()
  4235. {
  4236. vec2 scale;
  4237. vec2_set(&scale, 1.0f, -1.0f);
  4238. obs_scene_enum_items(GetCurrentScene(), MultiplySelectedItemScale,
  4239. &scale);
  4240. }
  4241. static bool CenterAlignSelectedItems(obs_scene_t *scene, obs_sceneitem_t *item,
  4242. void *param)
  4243. {
  4244. obs_bounds_type boundsType = *reinterpret_cast<obs_bounds_type*>(param);
  4245. if (!obs_sceneitem_selected(item))
  4246. return true;
  4247. obs_video_info ovi;
  4248. obs_get_video_info(&ovi);
  4249. obs_transform_info itemInfo;
  4250. vec2_set(&itemInfo.pos, 0.0f, 0.0f);
  4251. vec2_set(&itemInfo.scale, 1.0f, 1.0f);
  4252. itemInfo.alignment = OBS_ALIGN_LEFT | OBS_ALIGN_TOP;
  4253. itemInfo.rot = 0.0f;
  4254. vec2_set(&itemInfo.bounds,
  4255. float(ovi.base_width), float(ovi.base_height));
  4256. itemInfo.bounds_type = boundsType;
  4257. itemInfo.bounds_alignment = OBS_ALIGN_CENTER;
  4258. obs_sceneitem_set_info(item, &itemInfo);
  4259. UNUSED_PARAMETER(scene);
  4260. return true;
  4261. }
  4262. void OBSBasic::on_actionFitToScreen_triggered()
  4263. {
  4264. obs_bounds_type boundsType = OBS_BOUNDS_SCALE_INNER;
  4265. obs_scene_enum_items(GetCurrentScene(), CenterAlignSelectedItems,
  4266. &boundsType);
  4267. }
  4268. void OBSBasic::on_actionStretchToScreen_triggered()
  4269. {
  4270. obs_bounds_type boundsType = OBS_BOUNDS_STRETCH;
  4271. obs_scene_enum_items(GetCurrentScene(), CenterAlignSelectedItems,
  4272. &boundsType);
  4273. }
  4274. void OBSBasic::on_actionCenterToScreen_triggered()
  4275. {
  4276. auto func = [] (obs_scene_t *scene, obs_sceneitem_t *item, void *param)
  4277. {
  4278. vec3 tl, br, itemCenter, screenCenter, offset;
  4279. obs_video_info ovi;
  4280. if (!obs_sceneitem_selected(item))
  4281. return true;
  4282. obs_get_video_info(&ovi);
  4283. vec3_set(&screenCenter, float(ovi.base_width),
  4284. float(ovi.base_height), 0.0f);
  4285. vec3_mulf(&screenCenter, &screenCenter, 0.5f);
  4286. GetItemBox(item, tl, br);
  4287. vec3_sub(&itemCenter, &br, &tl);
  4288. vec3_mulf(&itemCenter, &itemCenter, 0.5f);
  4289. vec3_add(&itemCenter, &itemCenter, &tl);
  4290. vec3_sub(&offset, &screenCenter, &itemCenter);
  4291. vec3_add(&tl, &tl, &offset);
  4292. SetItemTL(item, tl);
  4293. UNUSED_PARAMETER(scene);
  4294. UNUSED_PARAMETER(param);
  4295. return true;
  4296. };
  4297. obs_scene_enum_items(GetCurrentScene(), func, nullptr);
  4298. }
  4299. void OBSBasic::EnablePreviewDisplay(bool enable)
  4300. {
  4301. obs_display_set_enabled(ui->preview->GetDisplay(), enable);
  4302. ui->preview->setVisible(enable);
  4303. ui->previewDisabledLabel->setVisible(!enable);
  4304. }
  4305. void OBSBasic::TogglePreview()
  4306. {
  4307. previewEnabled = !previewEnabled;
  4308. EnablePreviewDisplay(previewEnabled);
  4309. }
  4310. void OBSBasic::Nudge(int dist, MoveDir dir)
  4311. {
  4312. if (ui->preview->Locked())
  4313. return;
  4314. struct MoveInfo {
  4315. float dist;
  4316. MoveDir dir;
  4317. } info = {(float)dist, dir};
  4318. auto func = [] (obs_scene_t*, obs_sceneitem_t *item, void *param)
  4319. {
  4320. if (obs_sceneitem_locked(item))
  4321. return true;
  4322. MoveInfo *info = reinterpret_cast<MoveInfo*>(param);
  4323. struct vec2 dir;
  4324. struct vec2 pos;
  4325. vec2_set(&dir, 0.0f, 0.0f);
  4326. if (!obs_sceneitem_selected(item))
  4327. return true;
  4328. switch (info->dir) {
  4329. case MoveDir::Up: dir.y = -info->dist; break;
  4330. case MoveDir::Down: dir.y = info->dist; break;
  4331. case MoveDir::Left: dir.x = -info->dist; break;
  4332. case MoveDir::Right: dir.x = info->dist; break;
  4333. }
  4334. obs_sceneitem_get_pos(item, &pos);
  4335. vec2_add(&pos, &pos, &dir);
  4336. obs_sceneitem_set_pos(item, &pos);
  4337. return true;
  4338. };
  4339. obs_scene_enum_items(GetCurrentScene(), func, &info);
  4340. }
  4341. void OBSBasic::NudgeUp() {Nudge(1, MoveDir::Up);}
  4342. void OBSBasic::NudgeDown() {Nudge(1, MoveDir::Down);}
  4343. void OBSBasic::NudgeLeft() {Nudge(1, MoveDir::Left);}
  4344. void OBSBasic::NudgeRight() {Nudge(1, MoveDir::Right);}
  4345. void OBSBasic::OpenProjector(obs_source_t *source, int monitor, bool window,
  4346. QString title, bool studioProgram)
  4347. {
  4348. /* seriously? 10 monitors? */
  4349. if (monitor > 9 || monitor > QGuiApplication::screens().size() - 1)
  4350. return;
  4351. bool isPreview = false;
  4352. if (source == nullptr)
  4353. isPreview = true;
  4354. if (!window) {
  4355. delete projectors[monitor];
  4356. projectors[monitor].clear();
  4357. RemoveSavedProjectors(monitor);
  4358. }
  4359. OBSProjector *projector = new OBSProjector(nullptr, source, !!window);
  4360. const char *name = obs_source_get_name(source);
  4361. if (!window) {
  4362. if (studioProgram) {
  4363. studioProgramProjectorArray.at((size_t)monitor) = 1;
  4364. } else if (isPreview) {
  4365. previewProjectorArray.at((size_t)monitor) = 1;
  4366. } else {
  4367. projectorArray.at((size_t)monitor) = name;
  4368. }
  4369. }
  4370. if (!window) {
  4371. projector->Init(monitor, false, nullptr, studioProgram);
  4372. projectors[monitor] = projector;
  4373. } else {
  4374. projector->Init(monitor, true, title, studioProgram);
  4375. for (auto &projPtr : windowProjectors) {
  4376. if (!projPtr) {
  4377. projPtr = projector;
  4378. projector = nullptr;
  4379. }
  4380. }
  4381. if (projector)
  4382. windowProjectors.push_back(projector);
  4383. }
  4384. }
  4385. void OBSBasic::OpenStudioProgramProjector()
  4386. {
  4387. int monitor = sender()->property("monitor").toInt();
  4388. OpenProjector(nullptr, 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. OpenProjector(nullptr, monitor, true, title, true);
  4416. }
  4417. void OBSBasic::OpenPreviewWindow()
  4418. {
  4419. int monitor = sender()->property("monitor").toInt();
  4420. QString title = QTStr("PreviewWindow");
  4421. OpenProjector(nullptr, monitor, true, title);
  4422. }
  4423. void OBSBasic::OpenSourceWindow()
  4424. {
  4425. int monitor = sender()->property("monitor").toInt();
  4426. OBSSceneItem item = GetCurrentSceneItem();
  4427. OBSSource source = obs_sceneitem_get_source(item);
  4428. QString text = QString::fromUtf8(obs_source_get_name(source));
  4429. QString title = QTStr("SourceWindow") + " - " + text;
  4430. if (!item)
  4431. return;
  4432. OpenProjector(obs_sceneitem_get_source(item), monitor, true, title);
  4433. }
  4434. void OBSBasic::OpenSceneWindow()
  4435. {
  4436. int monitor = sender()->property("monitor").toInt();
  4437. OBSScene scene = GetCurrentScene();
  4438. OBSSource source = obs_scene_get_source(scene);
  4439. QString text = QString::fromUtf8(obs_source_get_name(source));
  4440. QString title = QTStr("SceneWindow") + " - " + text;
  4441. if (!scene)
  4442. return;
  4443. OpenProjector(obs_scene_get_source(scene), monitor, true, title);
  4444. }
  4445. void OBSBasic::OpenSavedProjectors()
  4446. {
  4447. bool projectorSave = config_get_bool(GetGlobalConfig(),
  4448. "BasicWindow", "SaveProjectors");
  4449. if (projectorSave) {
  4450. for (size_t i = 0; i < projectorArray.size(); i++) {
  4451. if (projectorArray.at(i).empty() == false) {
  4452. OBSSource source = obs_get_source_by_name(
  4453. projectorArray.at(i).c_str());
  4454. if (!source) {
  4455. RemoveSavedProjectors((int)i);
  4456. obs_source_release(source);
  4457. continue;
  4458. }
  4459. OpenProjector(source, (int)i, false);
  4460. obs_source_release(source);
  4461. }
  4462. }
  4463. for (size_t i = 0; i < studioProgramProjectorArray.size(); i++) {
  4464. if (studioProgramProjectorArray.at(i) == 1) {
  4465. OpenProjector(nullptr, (int)i, false, nullptr,
  4466. true);
  4467. }
  4468. }
  4469. for (size_t i = 0; i < previewProjectorArray.size(); i++) {
  4470. if (previewProjectorArray.at(i) == 1) {
  4471. OpenProjector(nullptr, (int)i, false);
  4472. }
  4473. }
  4474. }
  4475. }
  4476. void OBSBasic::RemoveSavedProjectors(int monitor)
  4477. {
  4478. studioProgramProjectorArray.at((size_t)monitor) = 0;
  4479. previewProjectorArray.at((size_t)monitor) = 0;
  4480. projectorArray.at((size_t)monitor) = "";
  4481. }
  4482. void OBSBasic::on_actionFullscreenInterface_triggered()
  4483. {
  4484. if (!fullscreenInterface)
  4485. showFullScreen();
  4486. else
  4487. showNormal();
  4488. fullscreenInterface = !fullscreenInterface;
  4489. }
  4490. void OBSBasic::UpdateTitleBar()
  4491. {
  4492. stringstream name;
  4493. const char *profile = config_get_string(App()->GlobalConfig(),
  4494. "Basic", "Profile");
  4495. const char *sceneCollection = config_get_string(App()->GlobalConfig(),
  4496. "Basic", "SceneCollection");
  4497. name << "OBS ";
  4498. if (previewProgramMode)
  4499. name << "Studio ";
  4500. name << App()->GetVersionString();
  4501. if (App()->IsPortableMode())
  4502. name << " - Portable Mode";
  4503. name << " - " << Str("TitleBar.Profile") << ": " << profile;
  4504. name << " - " << Str("TitleBar.Scenes") << ": " << sceneCollection;
  4505. setWindowTitle(QT_UTF8(name.str().c_str()));
  4506. }
  4507. int OBSBasic::GetProfilePath(char *path, size_t size, const char *file) const
  4508. {
  4509. char profiles_path[512];
  4510. const char *profile = config_get_string(App()->GlobalConfig(),
  4511. "Basic", "ProfileDir");
  4512. int ret;
  4513. if (!profile)
  4514. return -1;
  4515. if (!path)
  4516. return -1;
  4517. if (!file)
  4518. file = "";
  4519. ret = GetConfigPath(profiles_path, 512, "obs-studio/basic/profiles");
  4520. if (ret <= 0)
  4521. return ret;
  4522. if (!*file)
  4523. return snprintf(path, size, "%s/%s", profiles_path, profile);
  4524. return snprintf(path, size, "%s/%s/%s", profiles_path, profile, file);
  4525. }
  4526. void OBSBasic::on_resetUI_triggered()
  4527. {
  4528. restoreState(startingDockLayout);
  4529. #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
  4530. int cx = width();
  4531. int cy = height();
  4532. int cx22_5 = cx * 225 / 1000;
  4533. int cx5 = cx * 5 / 100;
  4534. cy = cy * 225 / 1000;
  4535. int mixerSize = cx - (cx22_5 * 2 + cx5 * 2);
  4536. QList<QDockWidget*> docks {
  4537. ui->scenesDock,
  4538. ui->sourcesDock,
  4539. ui->mixerDock,
  4540. ui->transitionsDock,
  4541. ui->controlsDock
  4542. };
  4543. QList<int> sizes {
  4544. cx22_5,
  4545. cx22_5,
  4546. mixerSize,
  4547. cx5,
  4548. cx5
  4549. };
  4550. ui->scenesDock->setVisible(true);
  4551. ui->sourcesDock->setVisible(true);
  4552. ui->mixerDock->setVisible(true);
  4553. ui->transitionsDock->setVisible(true);
  4554. ui->controlsDock->setVisible(true);
  4555. resizeDocks(docks, {cy, cy, cy, cy, cy}, Qt::Vertical);
  4556. resizeDocks(docks, sizes, Qt::Horizontal);
  4557. #endif
  4558. }
  4559. void OBSBasic::on_lockUI_toggled(bool lock)
  4560. {
  4561. QDockWidget::DockWidgetFeatures features = lock
  4562. ? QDockWidget::NoDockWidgetFeatures
  4563. : QDockWidget::AllDockWidgetFeatures;
  4564. ui->scenesDock->setFeatures(features);
  4565. ui->sourcesDock->setFeatures(features);
  4566. ui->mixerDock->setFeatures(features);
  4567. ui->transitionsDock->setFeatures(features);
  4568. ui->controlsDock->setFeatures(features);
  4569. }
  4570. void OBSBasic::on_toggleListboxToolbars_toggled(bool visible)
  4571. {
  4572. ui->sourcesToolbar->setVisible(visible);
  4573. ui->scenesToolbar->setVisible(visible);
  4574. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  4575. "ShowListboxToolbars", visible);
  4576. }
  4577. void OBSBasic::on_toggleStatusBar_toggled(bool visible)
  4578. {
  4579. ui->statusbar->setVisible(visible);
  4580. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  4581. "ShowStatusBar", visible);
  4582. }
  4583. void OBSBasic::on_actionLockPreview_triggered()
  4584. {
  4585. ui->preview->ToggleLocked();
  4586. ui->actionLockPreview->setChecked(ui->preview->Locked());
  4587. }
  4588. void OBSBasic::on_scalingMenu_aboutToShow()
  4589. {
  4590. obs_video_info ovi;
  4591. obs_get_video_info(&ovi);
  4592. QAction *action = ui->actionScaleCanvas;
  4593. QString text = QTStr("Basic.MainMenu.Edit.Scale.Canvas");
  4594. text = text.arg(QString::number(ovi.base_width),
  4595. QString::number(ovi.base_height));
  4596. action->setText(text);
  4597. action = ui->actionScaleOutput;
  4598. text = QTStr("Basic.MainMenu.Edit.Scale.Output");
  4599. text = text.arg(QString::number(ovi.output_width),
  4600. QString::number(ovi.output_height));
  4601. action->setText(text);
  4602. action->setVisible(!(ovi.output_width == ovi.base_width &&
  4603. ovi.output_height == ovi.base_height));
  4604. UpdatePreviewScalingMenu();
  4605. }
  4606. void OBSBasic::on_actionScaleWindow_triggered()
  4607. {
  4608. ui->preview->SetFixedScaling(false);
  4609. ui->preview->ResetScrollingOffset();
  4610. emit ui->preview->DisplayResized();
  4611. }
  4612. void OBSBasic::on_actionScaleCanvas_triggered()
  4613. {
  4614. ui->preview->SetFixedScaling(true);
  4615. ui->preview->SetScalingLevel(0);
  4616. emit ui->preview->DisplayResized();
  4617. }
  4618. void OBSBasic::on_actionScaleOutput_triggered()
  4619. {
  4620. obs_video_info ovi;
  4621. obs_get_video_info(&ovi);
  4622. ui->preview->SetFixedScaling(true);
  4623. float scalingAmount = float(ovi.output_width) / float(ovi.base_width);
  4624. // log base ZOOM_SENSITIVITY of x = log(x) / log(ZOOM_SENSITIVITY)
  4625. int32_t approxScalingLevel = int32_t(
  4626. round(log(scalingAmount) / log(ZOOM_SENSITIVITY)));
  4627. ui->preview->SetScalingLevel(approxScalingLevel);
  4628. ui->preview->SetScalingAmount(scalingAmount);
  4629. emit ui->preview->DisplayResized();
  4630. }
  4631. void OBSBasic::SetShowing(bool showing)
  4632. {
  4633. if (!showing && isVisible()) {
  4634. config_set_string(App()->GlobalConfig(),
  4635. "BasicWindow", "geometry",
  4636. saveGeometry().toBase64().constData());
  4637. /* hide all visible child dialogs */
  4638. visDlgPositions.clear();
  4639. if (!visDialogs.isEmpty()) {
  4640. for (QDialog *dlg : visDialogs) {
  4641. visDlgPositions.append(dlg->pos());
  4642. dlg->hide();
  4643. }
  4644. }
  4645. if (showHide)
  4646. showHide->setText(QTStr("Basic.SystemTray.Show"));
  4647. QTimer::singleShot(250, this, SLOT(hide()));
  4648. if (previewEnabled)
  4649. EnablePreviewDisplay(false);
  4650. setVisible(false);
  4651. } else if (showing && !isVisible()) {
  4652. if (showHide)
  4653. showHide->setText(QTStr("Basic.SystemTray.Hide"));
  4654. QTimer::singleShot(250, this, SLOT(show()));
  4655. if (previewEnabled)
  4656. EnablePreviewDisplay(true);
  4657. setVisible(true);
  4658. /* show all child dialogs that was visible earlier */
  4659. if (!visDialogs.isEmpty()) {
  4660. for (int i = 0; i < visDialogs.size(); ++i) {
  4661. QDialog *dlg = visDialogs[i];
  4662. dlg->move(visDlgPositions[i]);
  4663. dlg->show();
  4664. }
  4665. }
  4666. /* Unminimize window if it was hidden to tray instead of task
  4667. * bar. */
  4668. if (sysTrayMinimizeToTray()) {
  4669. Qt::WindowStates state;
  4670. state = windowState() & ~Qt::WindowMinimized;
  4671. state |= Qt::WindowActive;
  4672. setWindowState(state);
  4673. }
  4674. }
  4675. }
  4676. void OBSBasic::ToggleShowHide()
  4677. {
  4678. bool showing = isVisible();
  4679. if (showing) {
  4680. /* check for modal dialogs */
  4681. EnumDialogs();
  4682. if (!modalDialogs.isEmpty() || !visMsgBoxes.isEmpty())
  4683. return;
  4684. }
  4685. SetShowing(!showing);
  4686. }
  4687. void OBSBasic::SystemTrayInit()
  4688. {
  4689. trayIcon = new QSystemTrayIcon(QIcon(":/res/images/obs.png"),
  4690. this);
  4691. trayIcon->setToolTip("OBS Studio");
  4692. showHide = new QAction(QTStr("Basic.SystemTray.Show"),
  4693. trayIcon);
  4694. sysTrayStream = new QAction(QTStr("Basic.Main.StartStreaming"),
  4695. trayIcon);
  4696. sysTrayRecord = new QAction(QTStr("Basic.Main.StartRecording"),
  4697. trayIcon);
  4698. sysTrayReplayBuffer = new QAction(QTStr("Basic.Main.StartReplayBuffer"),
  4699. trayIcon);
  4700. exit = new QAction(QTStr("Exit"),
  4701. trayIcon);
  4702. if (outputHandler && !outputHandler->replayBuffer)
  4703. sysTrayReplayBuffer->setEnabled(false);
  4704. connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
  4705. this,
  4706. SLOT(IconActivated(QSystemTrayIcon::ActivationReason)));
  4707. connect(showHide, SIGNAL(triggered()),
  4708. this, SLOT(ToggleShowHide()));
  4709. connect(sysTrayStream, SIGNAL(triggered()),
  4710. this, SLOT(on_streamButton_clicked()));
  4711. connect(sysTrayRecord, SIGNAL(triggered()),
  4712. this, SLOT(on_recordButton_clicked()));
  4713. connect(sysTrayReplayBuffer.data(), &QAction::triggered,
  4714. this, &OBSBasic::ReplayBufferClicked);
  4715. connect(exit, SIGNAL(triggered()),
  4716. this, SLOT(close()));
  4717. QMenu *previewProjector = new QMenu(QTStr("PreviewProjector"));
  4718. AddProjectorMenuMonitors(previewProjector, this,
  4719. SLOT(OpenPreviewProjector()));
  4720. QMenu *studioProgramProjector = new QMenu(
  4721. QTStr("StudioProgramProjector"));
  4722. AddProjectorMenuMonitors(studioProgramProjector, this,
  4723. SLOT(OpenStudioProgramProjector()));
  4724. trayMenu = new QMenu;
  4725. trayMenu->addAction(showHide);
  4726. trayMenu->addMenu(previewProjector);
  4727. trayMenu->addMenu(studioProgramProjector);
  4728. trayMenu->addAction(sysTrayStream);
  4729. trayMenu->addAction(sysTrayRecord);
  4730. trayMenu->addAction(sysTrayReplayBuffer);
  4731. trayMenu->addAction(exit);
  4732. trayIcon->setContextMenu(trayMenu);
  4733. }
  4734. void OBSBasic::IconActivated(QSystemTrayIcon::ActivationReason reason)
  4735. {
  4736. if (reason == QSystemTrayIcon::Trigger)
  4737. ToggleShowHide();
  4738. }
  4739. void OBSBasic::SysTrayNotify(const QString &text,
  4740. QSystemTrayIcon::MessageIcon n)
  4741. {
  4742. if (QSystemTrayIcon::supportsMessages()) {
  4743. QSystemTrayIcon::MessageIcon icon =
  4744. QSystemTrayIcon::MessageIcon(n);
  4745. trayIcon->showMessage("OBS Studio", text, icon, 10000);
  4746. }
  4747. }
  4748. void OBSBasic::SystemTray(bool firstStarted)
  4749. {
  4750. if (!QSystemTrayIcon::isSystemTrayAvailable())
  4751. return;
  4752. bool sysTrayWhenStarted = config_get_bool(GetGlobalConfig(),
  4753. "BasicWindow", "SysTrayWhenStarted");
  4754. bool sysTrayEnabled = config_get_bool(GetGlobalConfig(),
  4755. "BasicWindow", "SysTrayEnabled");
  4756. if (firstStarted)
  4757. SystemTrayInit();
  4758. if (!sysTrayWhenStarted && !sysTrayEnabled) {
  4759. trayIcon->hide();
  4760. } else if ((sysTrayWhenStarted && sysTrayEnabled)
  4761. || opt_minimize_tray) {
  4762. trayIcon->show();
  4763. if (firstStarted) {
  4764. QTimer::singleShot(50, this, SLOT(hide()));
  4765. EnablePreviewDisplay(false);
  4766. setVisible(false);
  4767. opt_minimize_tray = false;
  4768. }
  4769. } else if (sysTrayEnabled) {
  4770. trayIcon->show();
  4771. } else if (!sysTrayEnabled) {
  4772. trayIcon->hide();
  4773. } else if (!sysTrayWhenStarted && sysTrayEnabled) {
  4774. trayIcon->hide();
  4775. }
  4776. if (isVisible())
  4777. showHide->setText(QTStr("Basic.SystemTray.Hide"));
  4778. else
  4779. showHide->setText(QTStr("Basic.SystemTray.Show"));
  4780. }
  4781. bool OBSBasic::sysTrayMinimizeToTray()
  4782. {
  4783. return config_get_bool(GetGlobalConfig(),
  4784. "BasicWindow", "SysTrayMinimizeToTray");
  4785. }
  4786. void OBSBasic::on_actionCopySource_triggered()
  4787. {
  4788. on_actionCopyTransform_triggered();
  4789. OBSSceneItem item = GetCurrentSceneItem();
  4790. if (!item)
  4791. return;
  4792. OBSSource source = obs_sceneitem_get_source(item);
  4793. copyString = obs_source_get_name(source);
  4794. copyVisible = obs_sceneitem_visible(item);
  4795. ui->actionPasteRef->setEnabled(true);
  4796. uint32_t output_flags = obs_source_get_output_flags(source);
  4797. if ((output_flags & OBS_SOURCE_DO_NOT_DUPLICATE) == 0)
  4798. ui->actionPasteDup->setEnabled(true);
  4799. else
  4800. ui->actionPasteDup->setEnabled(false);
  4801. }
  4802. void OBSBasic::on_actionPasteRef_triggered()
  4803. {
  4804. OBSBasicSourceSelect::SourcePaste(copyString, copyVisible, false);
  4805. on_actionPasteTransform_triggered();
  4806. }
  4807. void OBSBasic::on_actionPasteDup_triggered()
  4808. {
  4809. OBSBasicSourceSelect::SourcePaste(copyString, copyVisible, true);
  4810. on_actionPasteTransform_triggered();
  4811. }
  4812. void OBSBasic::on_actionCopyFilters_triggered()
  4813. {
  4814. OBSSceneItem item = GetCurrentSceneItem();
  4815. if (!item)
  4816. return;
  4817. OBSSource source = obs_sceneitem_get_source(item);
  4818. copyFiltersString = obs_source_get_name(source);
  4819. ui->actionPasteFilters->setEnabled(true);
  4820. }
  4821. void OBSBasic::on_actionPasteFilters_triggered()
  4822. {
  4823. OBSSource source = obs_get_source_by_name(copyFiltersString);
  4824. OBSSceneItem sceneItem = GetCurrentSceneItem();
  4825. OBSSource dstSource = obs_sceneitem_get_source(sceneItem);
  4826. if (source == dstSource)
  4827. return;
  4828. obs_source_copy_filters(dstSource, source);
  4829. }
  4830. void OBSBasic::on_autoConfigure_triggered()
  4831. {
  4832. AutoConfig test(this);
  4833. test.setModal(true);
  4834. test.show();
  4835. test.exec();
  4836. }
  4837. void OBSBasic::on_stats_triggered()
  4838. {
  4839. if (!stats.isNull()) {
  4840. stats->show();
  4841. stats->raise();
  4842. return;
  4843. }
  4844. OBSBasicStats *statsDlg;
  4845. statsDlg = new OBSBasicStats(nullptr);
  4846. statsDlg->show();
  4847. stats = statsDlg;
  4848. }