window-basic-main.cpp 112 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307
  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 <QMessageBox>
  19. #include <QShowEvent>
  20. #include <QDesktopServices>
  21. #include <QFileDialog>
  22. #include <QDesktopWidget>
  23. #include <util/dstr.h>
  24. #include <util/util.hpp>
  25. #include <util/platform.h>
  26. #include <util/profiler.hpp>
  27. #include <graphics/math-defs.h>
  28. #include "obs-app.hpp"
  29. #include "platform.hpp"
  30. #include "visibility-item-widget.hpp"
  31. #include "item-widget-helpers.hpp"
  32. #include "window-basic-settings.hpp"
  33. #include "window-namedialog.hpp"
  34. #include "window-basic-source-select.hpp"
  35. #include "window-basic-main.hpp"
  36. #include "window-basic-main-outputs.hpp"
  37. #include "window-basic-properties.hpp"
  38. #include "window-log-reply.hpp"
  39. #include "window-projector.hpp"
  40. #include "window-remux.hpp"
  41. #include "qt-wrappers.hpp"
  42. #include "display-helpers.hpp"
  43. #include "volume-control.hpp"
  44. #include "remote-text.hpp"
  45. #include "ui_OBSBasic.h"
  46. #include <fstream>
  47. #include <sstream>
  48. #include <QScreen>
  49. #include <QWindow>
  50. using namespace std;
  51. namespace {
  52. template <typename OBSRef>
  53. struct SignalContainer {
  54. OBSRef ref;
  55. vector<shared_ptr<OBSSignal>> handlers;
  56. };
  57. }
  58. Q_DECLARE_METATYPE(OBSScene);
  59. Q_DECLARE_METATYPE(OBSSceneItem);
  60. Q_DECLARE_METATYPE(OBSSource);
  61. Q_DECLARE_METATYPE(obs_order_movement);
  62. Q_DECLARE_METATYPE(SignalContainer<OBSScene>);
  63. template <typename T>
  64. static T GetOBSRef(QListWidgetItem *item)
  65. {
  66. return item->data(static_cast<int>(QtDataRole::OBSRef)).value<T>();
  67. }
  68. template <typename T>
  69. static void SetOBSRef(QListWidgetItem *item, T &&val)
  70. {
  71. item->setData(static_cast<int>(QtDataRole::OBSRef),
  72. QVariant::fromValue(val));
  73. }
  74. static void AddExtraModulePaths()
  75. {
  76. char base_module_dir[512];
  77. int ret = GetConfigPath(base_module_dir, sizeof(base_module_dir),
  78. "obs-studio/plugins/%module%");
  79. if (ret <= 0)
  80. return;
  81. string path = (char*)base_module_dir;
  82. #if defined(__APPLE__)
  83. obs_add_module_path((path + "/bin").c_str(), (path + "/data").c_str());
  84. #elif ARCH_BITS == 64
  85. obs_add_module_path((path + "/bin/64bit").c_str(),
  86. (path + "/data").c_str());
  87. #else
  88. obs_add_module_path((path + "/bin/32bit").c_str(),
  89. (path + "/data").c_str());
  90. #endif
  91. }
  92. static QList<QKeySequence> DeleteKeys;
  93. OBSBasic::OBSBasic(QWidget *parent)
  94. : OBSMainWindow (parent),
  95. ui (new Ui::OBSBasic)
  96. {
  97. ui->setupUi(this);
  98. ui->previewDisabledLabel->setVisible(false);
  99. copyActionsDynamicProperties();
  100. ui->sources->setItemDelegate(new VisibilityItemDelegate(ui->sources));
  101. int width = config_get_int(App()->GlobalConfig(), "BasicWindow", "cx");
  102. // Check if no values are saved (new installation).
  103. if (width != 0) {
  104. int height = config_get_int(App()->GlobalConfig(),
  105. "BasicWindow", "cy");
  106. int posx = config_get_int(App()->GlobalConfig(), "BasicWindow",
  107. "posx");
  108. int posy = config_get_int(App()->GlobalConfig(), "BasicWindow",
  109. "posy");
  110. if (!WindowPositionValid(posx, posy)) {
  111. QRect rect = App()->desktop()->availableGeometry();
  112. setGeometry(QStyle::alignedRect(
  113. Qt::LeftToRight,
  114. Qt::AlignCenter,
  115. size(), rect));
  116. } else {
  117. setGeometry(posx, posy, width, height);
  118. }
  119. }
  120. char styleSheetPath[512];
  121. int ret = GetProfilePath(styleSheetPath, sizeof(styleSheetPath),
  122. "stylesheet.qss");
  123. if (ret > 0) {
  124. if (QFile::exists(styleSheetPath)) {
  125. QString path = QString("file:///") +
  126. QT_UTF8(styleSheetPath);
  127. App()->setStyleSheet(path);
  128. }
  129. }
  130. qRegisterMetaType<OBSScene> ("OBSScene");
  131. qRegisterMetaType<OBSSceneItem>("OBSSceneItem");
  132. qRegisterMetaType<OBSSource> ("OBSSource");
  133. qRegisterMetaType<obs_hotkey_id>("obs_hotkey_id");
  134. qRegisterMetaTypeStreamOperators<
  135. std::vector<std::shared_ptr<OBSSignal>>>(
  136. "std::vector<std::shared_ptr<OBSSignal>>");
  137. qRegisterMetaTypeStreamOperators<OBSScene>("OBSScene");
  138. qRegisterMetaTypeStreamOperators<OBSSceneItem>("OBSSceneItem");
  139. ui->scenes->setAttribute(Qt::WA_MacShowFocusRect, false);
  140. ui->sources->setAttribute(Qt::WA_MacShowFocusRect, false);
  141. auto displayResize = [this]() {
  142. struct obs_video_info ovi;
  143. if (obs_get_video_info(&ovi))
  144. ResizePreview(ovi.base_width, ovi.base_height);
  145. };
  146. connect(windowHandle(), &QWindow::screenChanged, displayResize);
  147. connect(ui->preview, &OBSQTDisplay::DisplayResized, displayResize);
  148. installEventFilter(CreateShortcutFilter());
  149. stringstream name;
  150. name << "OBS " << App()->GetVersionString();
  151. blog(LOG_INFO, "%s", name.str().c_str());
  152. blog(LOG_INFO, "---------------------------------");
  153. UpdateTitleBar();
  154. connect(ui->scenes->itemDelegate(),
  155. SIGNAL(closeEditor(QWidget*,
  156. QAbstractItemDelegate::EndEditHint)),
  157. this,
  158. SLOT(SceneNameEdited(QWidget*,
  159. QAbstractItemDelegate::EndEditHint)));
  160. connect(ui->sources->itemDelegate(),
  161. SIGNAL(closeEditor(QWidget*,
  162. QAbstractItemDelegate::EndEditHint)),
  163. this,
  164. SLOT(SceneItemNameEdited(QWidget*,
  165. QAbstractItemDelegate::EndEditHint)));
  166. cpuUsageInfo = os_cpu_usage_info_start();
  167. cpuUsageTimer = new QTimer(this);
  168. connect(cpuUsageTimer, SIGNAL(timeout()),
  169. ui->statusbar, SLOT(UpdateCPUUsage()));
  170. cpuUsageTimer->start(3000);
  171. DeleteKeys =
  172. #ifdef __APPLE__
  173. QList<QKeySequence>{{Qt::Key_Backspace}} <<
  174. #endif
  175. QKeySequence::keyBindings(QKeySequence::Delete);
  176. #ifdef __APPLE__
  177. ui->actionRemoveSource->setShortcuts(DeleteKeys);
  178. ui->actionRemoveScene->setShortcuts(DeleteKeys);
  179. ui->action_Settings->setMenuRole(QAction::PreferencesRole);
  180. ui->actionE_xit->setMenuRole(QAction::QuitRole);
  181. #endif
  182. auto addNudge = [this](const QKeySequence &seq, const char *s)
  183. {
  184. QAction *nudge = new QAction(ui->preview);
  185. nudge->setShortcut(seq);
  186. nudge->setShortcutContext(Qt::WidgetShortcut);
  187. ui->preview->addAction(nudge);
  188. connect(nudge, SIGNAL(triggered()), this, s);
  189. };
  190. addNudge(Qt::Key_Up, SLOT(NudgeUp()));
  191. addNudge(Qt::Key_Down, SLOT(NudgeDown()));
  192. addNudge(Qt::Key_Left, SLOT(NudgeLeft()));
  193. addNudge(Qt::Key_Right, SLOT(NudgeRight()));
  194. }
  195. static void SaveAudioDevice(const char *name, int channel, obs_data_t *parent,
  196. vector<OBSSource> &audioSources)
  197. {
  198. obs_source_t *source = obs_get_output_source(channel);
  199. if (!source)
  200. return;
  201. audioSources.push_back(source);
  202. obs_data_t *data = obs_save_source(source);
  203. obs_data_set_obj(parent, name, data);
  204. obs_data_release(data);
  205. obs_source_release(source);
  206. }
  207. static obs_data_t *GenerateSaveData(obs_data_array_t *sceneOrder,
  208. obs_data_array_t *quickTransitionData, int transitionDuration,
  209. obs_data_array_t *transitions,
  210. OBSScene &scene, OBSSource &curProgramScene)
  211. {
  212. obs_data_t *saveData = obs_data_create();
  213. vector<OBSSource> audioSources;
  214. audioSources.reserve(5);
  215. SaveAudioDevice(DESKTOP_AUDIO_1, 1, saveData, audioSources);
  216. SaveAudioDevice(DESKTOP_AUDIO_2, 2, saveData, audioSources);
  217. SaveAudioDevice(AUX_AUDIO_1, 3, saveData, audioSources);
  218. SaveAudioDevice(AUX_AUDIO_2, 4, saveData, audioSources);
  219. SaveAudioDevice(AUX_AUDIO_3, 5, saveData, audioSources);
  220. auto FilterAudioSources = [&](obs_source_t *source)
  221. {
  222. return find(begin(audioSources), end(audioSources), source) ==
  223. end(audioSources);
  224. };
  225. using FilterAudioSources_t = decltype(FilterAudioSources);
  226. obs_data_array_t *sourcesArray = obs_save_sources_filtered(
  227. [](void *data, obs_source_t *source)
  228. {
  229. return (*static_cast<FilterAudioSources_t*>(data))(source);
  230. }, static_cast<void*>(&FilterAudioSources));
  231. obs_source_t *transition = obs_get_output_source(0);
  232. obs_source_t *currentScene = obs_scene_get_source(scene);
  233. const char *sceneName = obs_source_get_name(currentScene);
  234. const char *programName = obs_source_get_name(curProgramScene);
  235. const char *sceneCollection = config_get_string(App()->GlobalConfig(),
  236. "Basic", "SceneCollection");
  237. obs_data_set_string(saveData, "current_scene", sceneName);
  238. obs_data_set_string(saveData, "current_program_scene", programName);
  239. obs_data_set_array(saveData, "scene_order", sceneOrder);
  240. obs_data_set_string(saveData, "name", sceneCollection);
  241. obs_data_set_array(saveData, "sources", sourcesArray);
  242. obs_data_set_array(saveData, "quick_transitions", quickTransitionData);
  243. obs_data_set_array(saveData, "transitions", transitions);
  244. obs_data_array_release(sourcesArray);
  245. obs_data_set_string(saveData, "current_transition",
  246. obs_source_get_name(transition));
  247. obs_data_set_int(saveData, "transition_duration", transitionDuration);
  248. obs_source_release(transition);
  249. return saveData;
  250. }
  251. void OBSBasic::copyActionsDynamicProperties()
  252. {
  253. // Themes need the QAction dynamic properties
  254. for (QAction *x : ui->scenesToolbar->actions()) {
  255. QWidget* temp = ui->scenesToolbar->widgetForAction(x);
  256. for (QByteArray &y : x->dynamicPropertyNames()) {
  257. temp->setProperty(y, x->property(y));
  258. }
  259. }
  260. for (QAction *x : ui->sourcesToolbar->actions()) {
  261. QWidget* temp = ui->sourcesToolbar->widgetForAction(x);
  262. for (QByteArray &y : x->dynamicPropertyNames()) {
  263. temp->setProperty(y, x->property(y));
  264. }
  265. }
  266. }
  267. void OBSBasic::ClearVolumeControls()
  268. {
  269. VolControl *control;
  270. for (size_t i = 0; i < volumes.size(); i++) {
  271. control = volumes[i];
  272. delete control;
  273. }
  274. volumes.clear();
  275. }
  276. obs_data_array_t *OBSBasic::SaveSceneListOrder()
  277. {
  278. obs_data_array_t *sceneOrder = obs_data_array_create();
  279. for (int i = 0; i < ui->scenes->count(); i++) {
  280. obs_data_t *data = obs_data_create();
  281. obs_data_set_string(data, "name",
  282. QT_TO_UTF8(ui->scenes->item(i)->text()));
  283. obs_data_array_push_back(sceneOrder, data);
  284. obs_data_release(data);
  285. }
  286. return sceneOrder;
  287. }
  288. void OBSBasic::Save(const char *file)
  289. {
  290. OBSScene scene = GetCurrentScene();
  291. OBSSource curProgramScene = OBSGetStrongRef(programScene);
  292. if (!curProgramScene)
  293. curProgramScene = obs_scene_get_source(scene);
  294. obs_data_array_t *sceneOrder = SaveSceneListOrder();
  295. obs_data_array_t *transitions = SaveTransitions();
  296. obs_data_array_t *quickTrData = SaveQuickTransitions();
  297. obs_data_t *saveData = GenerateSaveData(sceneOrder, quickTrData,
  298. ui->transitionDuration->value(), transitions,
  299. scene, curProgramScene);
  300. if (!obs_data_save_json_safe(saveData, file, "tmp", "bak"))
  301. blog(LOG_ERROR, "Could not save scene data to %s", file);
  302. obs_data_release(saveData);
  303. obs_data_array_release(sceneOrder);
  304. obs_data_array_release(quickTrData);
  305. obs_data_array_release(transitions);
  306. }
  307. static void LoadAudioDevice(const char *name, int channel, obs_data_t *parent)
  308. {
  309. obs_data_t *data = obs_data_get_obj(parent, name);
  310. if (!data)
  311. return;
  312. obs_source_t *source = obs_load_source(data);
  313. if (source) {
  314. obs_set_output_source(channel, source);
  315. obs_source_release(source);
  316. }
  317. obs_data_release(data);
  318. }
  319. static inline bool HasAudioDevices(const char *source_id)
  320. {
  321. const char *output_id = source_id;
  322. obs_properties_t *props = obs_get_source_properties(output_id);
  323. size_t count = 0;
  324. if (!props)
  325. return false;
  326. obs_property_t *devices = obs_properties_get(props, "device_id");
  327. if (devices)
  328. count = obs_property_list_item_count(devices);
  329. obs_properties_destroy(props);
  330. return count != 0;
  331. }
  332. void OBSBasic::CreateFirstRunSources()
  333. {
  334. bool hasDesktopAudio = HasAudioDevices(App()->OutputAudioSource());
  335. bool hasInputAudio = HasAudioDevices(App()->InputAudioSource());
  336. if (hasDesktopAudio)
  337. ResetAudioDevice(App()->OutputAudioSource(), "default",
  338. Str("Basic.DesktopDevice1"), 1);
  339. if (hasInputAudio)
  340. ResetAudioDevice(App()->InputAudioSource(), "default",
  341. Str("Basic.AuxDevice1"), 3);
  342. }
  343. void OBSBasic::CreateDefaultScene(bool firstStart)
  344. {
  345. disableSaving++;
  346. ClearSceneData();
  347. InitDefaultTransitions();
  348. CreateDefaultQuickTransitions();
  349. ui->transitionDuration->setValue(300);
  350. SetTransition(fadeTransition);
  351. obs_scene_t *scene = obs_scene_create(Str("Basic.Scene"));
  352. if (firstStart)
  353. CreateFirstRunSources();
  354. AddScene(obs_scene_get_source(scene));
  355. SetCurrentScene(scene, true);
  356. obs_scene_release(scene);
  357. disableSaving--;
  358. }
  359. static void ReorderItemByName(QListWidget *lw, const char *name, int newIndex)
  360. {
  361. for (int i = 0; i < lw->count(); i++) {
  362. QListWidgetItem *item = lw->item(i);
  363. if (strcmp(name, QT_TO_UTF8(item->text())) == 0) {
  364. if (newIndex != i) {
  365. item = lw->takeItem(i);
  366. lw->insertItem(newIndex, item);
  367. }
  368. break;
  369. }
  370. }
  371. }
  372. void OBSBasic::LoadSceneListOrder(obs_data_array_t *array)
  373. {
  374. size_t num = obs_data_array_count(array);
  375. for (size_t i = 0; i < num; i++) {
  376. obs_data_t *data = obs_data_array_item(array, i);
  377. const char *name = obs_data_get_string(data, "name");
  378. ReorderItemByName(ui->scenes, name, (int)i);
  379. obs_data_release(data);
  380. }
  381. }
  382. void OBSBasic::Load(const char *file)
  383. {
  384. if (!file || !os_file_exists(file)) {
  385. blog(LOG_INFO, "No scene file found, creating default scene");
  386. CreateDefaultScene(true);
  387. SaveProject();
  388. return;
  389. }
  390. disableSaving++;
  391. obs_data_t *data = obs_data_create_from_json_file_safe(file, "bak");
  392. if (!data) {
  393. disableSaving--;
  394. blog(LOG_ERROR, "Failed to load '%s', creating default scene",
  395. file);
  396. CreateDefaultScene(true);
  397. SaveProject();
  398. return;
  399. }
  400. ClearSceneData();
  401. InitDefaultTransitions();
  402. obs_data_array_t *sceneOrder = obs_data_get_array(data, "scene_order");
  403. obs_data_array_t *sources = obs_data_get_array(data, "sources");
  404. obs_data_array_t *transitions= obs_data_get_array(data, "transitions");
  405. const char *sceneName = obs_data_get_string(data,
  406. "current_scene");
  407. const char *programSceneName = obs_data_get_string(data,
  408. "current_program_scene");
  409. const char *transitionName = obs_data_get_string(data,
  410. "current_transition");
  411. if (!opt_starting_scene.empty()) {
  412. programSceneName = opt_starting_scene.c_str();
  413. if (!IsPreviewProgramMode())
  414. sceneName = opt_starting_scene.c_str();
  415. }
  416. int newDuration = obs_data_get_int(data, "transition_duration");
  417. if (!newDuration)
  418. newDuration = 300;
  419. if (!transitionName)
  420. transitionName = obs_source_get_name(fadeTransition);
  421. const char *curSceneCollection = config_get_string(
  422. App()->GlobalConfig(), "Basic", "SceneCollection");
  423. obs_data_set_default_string(data, "name", curSceneCollection);
  424. const char *name = obs_data_get_string(data, "name");
  425. obs_source_t *curScene;
  426. obs_source_t *curProgramScene;
  427. obs_source_t *curTransition;
  428. if (!name || !*name)
  429. name = curSceneCollection;
  430. LoadAudioDevice(DESKTOP_AUDIO_1, 1, data);
  431. LoadAudioDevice(DESKTOP_AUDIO_2, 2, data);
  432. LoadAudioDevice(AUX_AUDIO_1, 3, data);
  433. LoadAudioDevice(AUX_AUDIO_2, 4, data);
  434. LoadAudioDevice(AUX_AUDIO_3, 5, data);
  435. obs_load_sources(sources, OBSBasic::SourceLoaded, this);
  436. if (transitions)
  437. LoadTransitions(transitions);
  438. if (sceneOrder)
  439. LoadSceneListOrder(sceneOrder);
  440. obs_data_array_release(transitions);
  441. curTransition = FindTransition(transitionName);
  442. if (!curTransition)
  443. curTransition = fadeTransition;
  444. ui->transitionDuration->setValue(newDuration);
  445. SetTransition(curTransition);
  446. retryScene:
  447. curScene = obs_get_source_by_name(sceneName);
  448. curProgramScene = obs_get_source_by_name(programSceneName);
  449. /* if the starting scene command line parameter is bad at all,
  450. * fall back to original settings */
  451. if (!opt_starting_scene.empty() && (!curScene || !curProgramScene)) {
  452. sceneName = obs_data_get_string(data, "current_scene");
  453. programSceneName = obs_data_get_string(data,
  454. "current_program_scene");
  455. obs_source_release(curScene);
  456. obs_source_release(curProgramScene);
  457. opt_starting_scene.clear();
  458. goto retryScene;
  459. }
  460. if (!curProgramScene) {
  461. curProgramScene = curScene;
  462. obs_source_addref(curScene);
  463. }
  464. SetCurrentScene(curScene, true);
  465. if (IsPreviewProgramMode())
  466. TransitionToScene(curProgramScene, true);
  467. obs_source_release(curScene);
  468. obs_source_release(curProgramScene);
  469. obs_data_array_release(sources);
  470. obs_data_array_release(sceneOrder);
  471. std::string file_base = strrchr(file, '/') + 1;
  472. file_base.erase(file_base.size() - 5, 5);
  473. config_set_string(App()->GlobalConfig(), "Basic", "SceneCollection",
  474. name);
  475. config_set_string(App()->GlobalConfig(), "Basic", "SceneCollectionFile",
  476. file_base.c_str());
  477. obs_data_array_t *quickTransitionData = obs_data_get_array(data,
  478. "quick_transitions");
  479. LoadQuickTransitions(quickTransitionData);
  480. obs_data_array_release(quickTransitionData);
  481. RefreshQuickTransitions();
  482. obs_data_release(data);
  483. if (!opt_starting_scene.empty())
  484. opt_starting_scene.clear();
  485. if (opt_start_streaming) {
  486. QMetaObject::invokeMethod(this, "StartStreaming",
  487. Qt::QueuedConnection);
  488. opt_start_streaming = false;
  489. }
  490. if (opt_start_recording) {
  491. QMetaObject::invokeMethod(this, "StartRecording",
  492. Qt::QueuedConnection);
  493. opt_start_recording = false;
  494. }
  495. disableSaving--;
  496. }
  497. #define SERVICE_PATH "service.json"
  498. void OBSBasic::SaveService()
  499. {
  500. if (!service)
  501. return;
  502. char serviceJsonPath[512];
  503. int ret = GetProfilePath(serviceJsonPath, sizeof(serviceJsonPath),
  504. SERVICE_PATH);
  505. if (ret <= 0)
  506. return;
  507. obs_data_t *data = obs_data_create();
  508. obs_data_t *settings = obs_service_get_settings(service);
  509. obs_data_set_string(data, "type", obs_service_get_type(service));
  510. obs_data_set_obj(data, "settings", settings);
  511. if (!obs_data_save_json_safe(data, serviceJsonPath, "tmp", "bak"))
  512. blog(LOG_WARNING, "Failed to save service");
  513. obs_data_release(settings);
  514. obs_data_release(data);
  515. }
  516. bool OBSBasic::LoadService()
  517. {
  518. const char *type;
  519. char serviceJsonPath[512];
  520. int ret = GetProfilePath(serviceJsonPath, sizeof(serviceJsonPath),
  521. SERVICE_PATH);
  522. if (ret <= 0)
  523. return false;
  524. obs_data_t *data = obs_data_create_from_json_file_safe(serviceJsonPath,
  525. "bak");
  526. obs_data_set_default_string(data, "type", "rtmp_common");
  527. type = obs_data_get_string(data, "type");
  528. obs_data_t *settings = obs_data_get_obj(data, "settings");
  529. obs_data_t *hotkey_data = obs_data_get_obj(data, "hotkeys");
  530. service = obs_service_create(type, "default_service", settings,
  531. hotkey_data);
  532. obs_service_release(service);
  533. obs_data_release(hotkey_data);
  534. obs_data_release(settings);
  535. obs_data_release(data);
  536. return !!service;
  537. }
  538. bool OBSBasic::InitService()
  539. {
  540. ProfileScope("OBSBasic::InitService");
  541. if (LoadService())
  542. return true;
  543. service = obs_service_create("rtmp_common", "default_service", nullptr,
  544. nullptr);
  545. if (!service)
  546. return false;
  547. obs_service_release(service);
  548. return true;
  549. }
  550. static const double scaled_vals[] =
  551. {
  552. 1.0,
  553. 1.25,
  554. (1.0/0.75),
  555. 1.5,
  556. (1.0/0.6),
  557. 1.75,
  558. 2.0,
  559. 2.25,
  560. 2.5,
  561. 2.75,
  562. 3.0,
  563. 0.0
  564. };
  565. bool OBSBasic::InitBasicConfigDefaults()
  566. {
  567. vector<MonitorInfo> monitors;
  568. GetMonitors(monitors);
  569. if (!monitors.size()) {
  570. OBSErrorBox(NULL, "There appears to be no monitors. Er, this "
  571. "technically shouldn't be possible.");
  572. return false;
  573. }
  574. uint32_t cx = monitors[0].cx;
  575. uint32_t cy = monitors[0].cy;
  576. /* ----------------------------------------------------- */
  577. /* move over mixer values in advanced if older config */
  578. if (config_has_user_value(basicConfig, "AdvOut", "RecTrackIndex") &&
  579. !config_has_user_value(basicConfig, "AdvOut", "RecTracks")) {
  580. uint64_t track = config_get_uint(basicConfig, "AdvOut",
  581. "RecTrackIndex");
  582. track = 1ULL << (track - 1);
  583. config_set_uint(basicConfig, "AdvOut", "RecTracks", track);
  584. config_remove_value(basicConfig, "AdvOut", "RecTrackIndex");
  585. config_save_safe(basicConfig, "tmp", nullptr);
  586. }
  587. /* ----------------------------------------------------- */
  588. config_set_default_string(basicConfig, "Output", "Mode", "Simple");
  589. config_set_default_string(basicConfig, "SimpleOutput", "FilePath",
  590. GetDefaultVideoSavePath().c_str());
  591. config_set_default_string(basicConfig, "SimpleOutput", "RecFormat",
  592. "flv");
  593. config_set_default_uint (basicConfig, "SimpleOutput", "VBitrate",
  594. 2500);
  595. config_set_default_string(basicConfig, "SimpleOutput", "StreamEncoder",
  596. SIMPLE_ENCODER_X264);
  597. config_set_default_uint (basicConfig, "SimpleOutput", "ABitrate", 160);
  598. config_set_default_bool (basicConfig, "SimpleOutput", "UseAdvanced",
  599. false);
  600. config_set_default_bool (basicConfig, "SimpleOutput", "EnforceBitrate",
  601. true);
  602. config_set_default_string(basicConfig, "SimpleOutput", "Preset",
  603. "veryfast");
  604. config_set_default_string(basicConfig, "SimpleOutput", "RecQuality",
  605. "Stream");
  606. config_set_default_string(basicConfig, "SimpleOutput", "RecEncoder",
  607. SIMPLE_ENCODER_X264);
  608. config_set_default_bool (basicConfig, "AdvOut", "ApplyServiceSettings",
  609. true);
  610. config_set_default_bool (basicConfig, "AdvOut", "UseRescale", false);
  611. config_set_default_uint (basicConfig, "AdvOut", "TrackIndex", 1);
  612. config_set_default_string(basicConfig, "AdvOut", "Encoder", "obs_x264");
  613. config_set_default_string(basicConfig, "AdvOut", "RecType", "Standard");
  614. config_set_default_string(basicConfig, "AdvOut", "RecFilePath",
  615. GetDefaultVideoSavePath().c_str());
  616. config_set_default_string(basicConfig, "AdvOut", "RecFormat", "flv");
  617. config_set_default_bool (basicConfig, "AdvOut", "RecUseRescale",
  618. false);
  619. config_set_default_uint (basicConfig, "AdvOut", "RecTracks", (1<<0));
  620. config_set_default_string(basicConfig, "AdvOut", "RecEncoder",
  621. "none");
  622. config_set_default_bool (basicConfig, "AdvOut", "FFOutputToFile",
  623. true);
  624. config_set_default_string(basicConfig, "AdvOut", "FFFilePath",
  625. GetDefaultVideoSavePath().c_str());
  626. config_set_default_string(basicConfig, "AdvOut", "FFExtension", "mp4");
  627. config_set_default_uint (basicConfig, "AdvOut", "FFVBitrate", 2500);
  628. config_set_default_bool (basicConfig, "AdvOut", "FFUseRescale",
  629. false);
  630. config_set_default_uint (basicConfig, "AdvOut", "FFABitrate", 160);
  631. config_set_default_uint (basicConfig, "AdvOut", "FFAudioTrack", 1);
  632. config_set_default_uint (basicConfig, "AdvOut", "Track1Bitrate", 160);
  633. config_set_default_uint (basicConfig, "AdvOut", "Track2Bitrate", 160);
  634. config_set_default_uint (basicConfig, "AdvOut", "Track3Bitrate", 160);
  635. config_set_default_uint (basicConfig, "AdvOut", "Track4Bitrate", 160);
  636. config_set_default_uint (basicConfig, "Video", "BaseCX", cx);
  637. config_set_default_uint (basicConfig, "Video", "BaseCY", cy);
  638. config_set_default_string(basicConfig, "Output", "FilenameFormatting",
  639. "%CCYY-%MM-%DD %hh-%mm-%ss");
  640. config_set_default_bool (basicConfig, "Output", "DelayEnable", false);
  641. config_set_default_uint (basicConfig, "Output", "DelaySec", 20);
  642. config_set_default_bool (basicConfig, "Output", "DelayPreserve", true);
  643. config_set_default_bool (basicConfig, "Output", "Reconnect", true);
  644. config_set_default_uint (basicConfig, "Output", "RetryDelay", 10);
  645. config_set_default_uint (basicConfig, "Output", "MaxRetries", 20);
  646. int i = 0;
  647. uint32_t scale_cx = cx;
  648. uint32_t scale_cy = cy;
  649. /* use a default scaled resolution that has a pixel count no higher
  650. * than 1280x720 */
  651. while (((scale_cx * scale_cy) > (1280 * 720)) && scaled_vals[i] > 0.0) {
  652. double scale = scaled_vals[i++];
  653. scale_cx = uint32_t(double(cx) / scale);
  654. scale_cy = uint32_t(double(cy) / scale);
  655. }
  656. config_set_default_uint (basicConfig, "Video", "OutputCX", scale_cx);
  657. config_set_default_uint (basicConfig, "Video", "OutputCY", scale_cy);
  658. config_set_default_uint (basicConfig, "Video", "FPSType", 0);
  659. config_set_default_string(basicConfig, "Video", "FPSCommon", "30");
  660. config_set_default_uint (basicConfig, "Video", "FPSInt", 30);
  661. config_set_default_uint (basicConfig, "Video", "FPSNum", 30);
  662. config_set_default_uint (basicConfig, "Video", "FPSDen", 1);
  663. config_set_default_string(basicConfig, "Video", "ScaleType", "bicubic");
  664. config_set_default_string(basicConfig, "Video", "ColorFormat", "NV12");
  665. config_set_default_string(basicConfig, "Video", "ColorSpace", "601");
  666. config_set_default_string(basicConfig, "Video", "ColorRange",
  667. "Partial");
  668. config_set_default_uint (basicConfig, "Audio", "SampleRate", 44100);
  669. config_set_default_string(basicConfig, "Audio", "ChannelSetup",
  670. "Stereo");
  671. return true;
  672. }
  673. bool OBSBasic::InitBasicConfig()
  674. {
  675. ProfileScope("OBSBasic::InitBasicConfig");
  676. char configPath[512];
  677. int ret = GetProfilePath(configPath, sizeof(configPath), "");
  678. if (ret <= 0) {
  679. OBSErrorBox(nullptr, "Failed to get profile path");
  680. return false;
  681. }
  682. if (os_mkdir(configPath) == MKDIR_ERROR) {
  683. OBSErrorBox(nullptr, "Failed to create profile path");
  684. return false;
  685. }
  686. ret = GetProfilePath(configPath, sizeof(configPath), "basic.ini");
  687. if (ret <= 0) {
  688. OBSErrorBox(nullptr, "Failed to get base.ini path");
  689. return false;
  690. }
  691. int code = basicConfig.Open(configPath, CONFIG_OPEN_ALWAYS);
  692. if (code != CONFIG_SUCCESS) {
  693. OBSErrorBox(NULL, "Failed to open basic.ini: %d", code);
  694. return false;
  695. }
  696. if (config_get_string(basicConfig, "General", "Name") == nullptr) {
  697. const char *curName = config_get_string(App()->GlobalConfig(),
  698. "Basic", "Profile");
  699. config_set_string(basicConfig, "General", "Name", curName);
  700. basicConfig.SaveSafe("tmp");
  701. }
  702. return InitBasicConfigDefaults();
  703. }
  704. void OBSBasic::InitOBSCallbacks()
  705. {
  706. ProfileScope("OBSBasic::InitOBSCallbacks");
  707. signalHandlers.reserve(signalHandlers.size() + 6);
  708. signalHandlers.emplace_back(obs_get_signal_handler(), "source_remove",
  709. OBSBasic::SourceRemoved, this);
  710. signalHandlers.emplace_back(obs_get_signal_handler(), "source_activate",
  711. OBSBasic::SourceActivated, this);
  712. signalHandlers.emplace_back(obs_get_signal_handler(), "source_deactivate",
  713. OBSBasic::SourceDeactivated, this);
  714. signalHandlers.emplace_back(obs_get_signal_handler(), "source_rename",
  715. OBSBasic::SourceRenamed, this);
  716. }
  717. void OBSBasic::InitPrimitives()
  718. {
  719. ProfileScope("OBSBasic::InitPrimitives");
  720. obs_enter_graphics();
  721. gs_render_start(true);
  722. gs_vertex2f(0.0f, 0.0f);
  723. gs_vertex2f(0.0f, 1.0f);
  724. gs_vertex2f(1.0f, 1.0f);
  725. gs_vertex2f(1.0f, 0.0f);
  726. gs_vertex2f(0.0f, 0.0f);
  727. box = gs_render_save();
  728. gs_render_start(true);
  729. gs_vertex2f(0.0f, 0.0f);
  730. gs_vertex2f(0.0f, 1.0f);
  731. boxLeft = gs_render_save();
  732. gs_render_start(true);
  733. gs_vertex2f(0.0f, 0.0f);
  734. gs_vertex2f(1.0f, 0.0f);
  735. boxTop = gs_render_save();
  736. gs_render_start(true);
  737. gs_vertex2f(1.0f, 0.0f);
  738. gs_vertex2f(1.0f, 1.0f);
  739. boxRight = gs_render_save();
  740. gs_render_start(true);
  741. gs_vertex2f(0.0f, 1.0f);
  742. gs_vertex2f(1.0f, 1.0f);
  743. boxBottom = gs_render_save();
  744. gs_render_start(true);
  745. for (int i = 0; i <= 360; i += (360/20)) {
  746. float pos = RAD(float(i));
  747. gs_vertex2f(cosf(pos), sinf(pos));
  748. }
  749. circle = gs_render_save();
  750. obs_leave_graphics();
  751. }
  752. void OBSBasic::ResetOutputs()
  753. {
  754. ProfileScope("OBSBasic::ResetOutputs");
  755. const char *mode = config_get_string(basicConfig, "Output", "Mode");
  756. bool advOut = astrcmpi(mode, "Advanced") == 0;
  757. if (!outputHandler || !outputHandler->Active()) {
  758. outputHandler.reset();
  759. outputHandler.reset(advOut ?
  760. CreateAdvancedOutputHandler(this) :
  761. CreateSimpleOutputHandler(this));
  762. } else {
  763. outputHandler->Update();
  764. }
  765. }
  766. #define MAIN_SEPARATOR \
  767. "====================================================================="
  768. void OBSBasic::OBSInit()
  769. {
  770. ProfileScope("OBSBasic::OBSInit");
  771. const char *sceneCollection = config_get_string(App()->GlobalConfig(),
  772. "Basic", "SceneCollectionFile");
  773. char savePath[512];
  774. char fileName[512];
  775. int ret;
  776. if (!sceneCollection)
  777. throw "Failed to get scene collection name";
  778. ret = snprintf(fileName, 512, "obs-studio/basic/scenes/%s.json",
  779. sceneCollection);
  780. if (ret <= 0)
  781. throw "Failed to create scene collection file name";
  782. ret = GetConfigPath(savePath, sizeof(savePath), fileName);
  783. if (ret <= 0)
  784. throw "Failed to get scene collection json file path";
  785. if (!InitBasicConfig())
  786. throw "Failed to load basic.ini";
  787. if (!ResetAudio())
  788. throw "Failed to initialize audio";
  789. ret = ResetVideo();
  790. switch (ret) {
  791. case OBS_VIDEO_MODULE_NOT_FOUND:
  792. throw "Failed to initialize video: Graphics module not found";
  793. case OBS_VIDEO_NOT_SUPPORTED:
  794. throw "Failed to initialize video: Required graphics API "
  795. "functionality not found on these drivers or "
  796. "unavailable on this equipment";
  797. case OBS_VIDEO_INVALID_PARAM:
  798. throw "Failed to initialize video: Invalid parameters";
  799. default:
  800. if (ret != OBS_VIDEO_SUCCESS)
  801. throw "Failed to initialize video: Unspecified error";
  802. }
  803. InitOBSCallbacks();
  804. InitHotkeys();
  805. AddExtraModulePaths();
  806. obs_load_all_modules();
  807. blog(LOG_INFO, MAIN_SEPARATOR);
  808. ResetOutputs();
  809. CreateHotkeys();
  810. if (!InitService())
  811. throw "Failed to initialize service";
  812. InitPrimitives();
  813. sceneDuplicationMode = config_get_bool(App()->GlobalConfig(),
  814. "BasicWindow", "SceneDuplicationMode");
  815. swapScenesMode = config_get_bool(App()->GlobalConfig(),
  816. "BasicWindow", "SwapScenesMode");
  817. editPropertiesMode = config_get_bool(App()->GlobalConfig(),
  818. "BasicWindow", "EditPropertiesMode");
  819. SetPreviewProgramMode(config_get_bool(App()->GlobalConfig(),
  820. "BasicWindow", "PreviewProgramMode"));
  821. #define SET_VISIBILITY(name, control) \
  822. do { \
  823. if (config_has_user_value(App()->GlobalConfig(), \
  824. "BasicWindow", name)) { \
  825. bool visible = config_get_bool(App()->GlobalConfig(), \
  826. "BasicWindow", name); \
  827. ui->control->setChecked(visible); \
  828. } \
  829. } while (false)
  830. SET_VISIBILITY("ShowTransitions", toggleSceneTransitions);
  831. SET_VISIBILITY("ShowListboxToolbars", toggleListboxToolbars);
  832. SET_VISIBILITY("ShowStatusBar", toggleStatusBar);
  833. #undef SET_VISIBILITY
  834. {
  835. ProfileScope("OBSBasic::Load");
  836. disableSaving--;
  837. Load(savePath);
  838. disableSaving++;
  839. }
  840. TimedCheckForUpdates();
  841. loaded = true;
  842. previewEnabled = config_get_bool(App()->GlobalConfig(),
  843. "BasicWindow", "PreviewEnabled");
  844. if (!previewEnabled && !IsPreviewProgramMode())
  845. QMetaObject::invokeMethod(this, "EnablePreviewDisplay",
  846. Qt::QueuedConnection,
  847. Q_ARG(bool, previewEnabled));
  848. #ifdef _WIN32
  849. uint32_t winVer = GetWindowsVersion();
  850. if (winVer > 0 && winVer < 0x602) {
  851. bool disableAero = config_get_bool(basicConfig, "Video",
  852. "DisableAero");
  853. SetAeroEnabled(!disableAero);
  854. }
  855. #endif
  856. RefreshSceneCollections();
  857. RefreshProfiles();
  858. disableSaving--;
  859. auto addDisplay = [this] (OBSQTDisplay *window)
  860. {
  861. obs_display_add_draw_callback(window->GetDisplay(),
  862. OBSBasic::RenderMain, this);
  863. struct obs_video_info ovi;
  864. if (obs_get_video_info(&ovi))
  865. ResizePreview(ovi.base_width, ovi.base_height);
  866. };
  867. connect(ui->preview, &OBSQTDisplay::DisplayCreated, addDisplay);
  868. #ifdef _WIN32
  869. show();
  870. #endif
  871. bool alwaysOnTop = config_get_bool(App()->GlobalConfig(), "BasicWindow",
  872. "AlwaysOnTop");
  873. if (alwaysOnTop) {
  874. SetAlwaysOnTop(this, true);
  875. ui->actionAlwaysOnTop->setChecked(true);
  876. }
  877. #ifndef _WIN32
  878. show();
  879. #endif
  880. QList<int> defSizes;
  881. int top = config_get_int(App()->GlobalConfig(), "BasicWindow",
  882. "splitterTop");
  883. int bottom = config_get_int(App()->GlobalConfig(), "BasicWindow",
  884. "splitterBottom");
  885. if (!top || !bottom) {
  886. defSizes = ui->mainSplitter->sizes();
  887. int total = defSizes[0] + defSizes[1];
  888. defSizes[0] = total * 75 / 100;
  889. defSizes[1] = total - defSizes[0];
  890. } else {
  891. defSizes.push_back(top);
  892. defSizes.push_back(bottom);
  893. }
  894. ui->mainSplitter->setSizes(defSizes);
  895. }
  896. void OBSBasic::InitHotkeys()
  897. {
  898. ProfileScope("OBSBasic::InitHotkeys");
  899. struct obs_hotkeys_translations t = {};
  900. t.insert = Str("Hotkeys.Insert");
  901. t.del = Str("Hotkeys.Delete");
  902. t.home = Str("Hotkeys.Home");
  903. t.end = Str("Hotkeys.End");
  904. t.page_up = Str("Hotkeys.PageUp");
  905. t.page_down = Str("Hotkeys.PageDown");
  906. t.num_lock = Str("Hotkeys.NumLock");
  907. t.scroll_lock = Str("Hotkeys.ScrollLock");
  908. t.caps_lock = Str("Hotkeys.CapsLock");
  909. t.backspace = Str("Hotkeys.Backspace");
  910. t.tab = Str("Hotkeys.Tab");
  911. t.print = Str("Hotkeys.Print");
  912. t.pause = Str("Hotkeys.Pause");
  913. t.left = Str("Hotkeys.Left");
  914. t.right = Str("Hotkeys.Right");
  915. t.up = Str("Hotkeys.Up");
  916. t.down = Str("Hotkeys.Down");
  917. #ifdef _WIN32
  918. t.meta = Str("Hotkeys.Windows");
  919. #else
  920. t.meta = Str("Hotkeys.Super");
  921. #endif
  922. t.menu = Str("Hotkeys.Menu");
  923. t.space = Str("Hotkeys.Space");
  924. t.numpad_num = Str("Hotkeys.NumpadNum");
  925. t.numpad_multiply = Str("Hotkeys.NumpadMultiply");
  926. t.numpad_divide = Str("Hotkeys.NumpadDivide");
  927. t.numpad_plus = Str("Hotkeys.NumpadAdd");
  928. t.numpad_minus = Str("Hotkeys.NumpadSubtract");
  929. t.numpad_decimal = Str("Hotkeys.NumpadDecimal");
  930. t.apple_keypad_num = Str("Hotkeys.AppleKeypadNum");
  931. t.apple_keypad_multiply = Str("Hotkeys.AppleKeypadMultiply");
  932. t.apple_keypad_divide = Str("Hotkeys.AppleKeypadDivide");
  933. t.apple_keypad_plus = Str("Hotkeys.AppleKeypadAdd");
  934. t.apple_keypad_minus = Str("Hotkeys.AppleKeypadSubtract");
  935. t.apple_keypad_decimal = Str("Hotkeys.AppleKeypadDecimal");
  936. t.apple_keypad_equal = Str("Hotkeys.AppleKeypadEqual");
  937. t.mouse_num = Str("Hotkeys.MouseButton");
  938. obs_hotkeys_set_translations(&t);
  939. obs_hotkeys_set_audio_hotkeys_translations(Str("Mute"), Str("Unmute"),
  940. Str("Push-to-mute"), Str("Push-to-talk"));
  941. obs_hotkeys_set_sceneitem_hotkeys_translations(
  942. Str("SceneItemShow"), Str("SceneItemHide"));
  943. obs_hotkey_enable_callback_rerouting(true);
  944. obs_hotkey_set_callback_routing_func(OBSBasic::HotkeyTriggered, this);
  945. }
  946. void OBSBasic::ProcessHotkey(obs_hotkey_id id, bool pressed)
  947. {
  948. obs_hotkey_trigger_routed_callback(id, pressed);
  949. }
  950. void OBSBasic::HotkeyTriggered(void *data, obs_hotkey_id id, bool pressed)
  951. {
  952. OBSBasic &basic = *static_cast<OBSBasic*>(data);
  953. QMetaObject::invokeMethod(&basic, "ProcessHotkey",
  954. Q_ARG(obs_hotkey_id, id), Q_ARG(bool, pressed));
  955. }
  956. void OBSBasic::CreateHotkeys()
  957. {
  958. ProfileScope("OBSBasic::CreateHotkeys");
  959. auto LoadHotkeyData = [&](const char *name) -> OBSData
  960. {
  961. const char *info = config_get_string(basicConfig,
  962. "Hotkeys", name);
  963. if (!info)
  964. return {};
  965. obs_data_t *data = obs_data_create_from_json(info);
  966. if (!data)
  967. return {};
  968. OBSData res = data;
  969. obs_data_release(data);
  970. return res;
  971. };
  972. auto LoadHotkey = [&](obs_hotkey_id id, const char *name)
  973. {
  974. obs_data_array_t *array =
  975. obs_data_get_array(LoadHotkeyData(name), "bindings");
  976. obs_hotkey_load(id, array);
  977. obs_data_array_release(array);
  978. };
  979. auto LoadHotkeyPair = [&](obs_hotkey_pair_id id, const char *name0,
  980. const char *name1)
  981. {
  982. obs_data_array_t *array0 =
  983. obs_data_get_array(LoadHotkeyData(name0), "bindings");
  984. obs_data_array_t *array1 =
  985. obs_data_get_array(LoadHotkeyData(name1), "bindings");
  986. obs_hotkey_pair_load(id, array0, array1);
  987. obs_data_array_release(array0);
  988. obs_data_array_release(array1);
  989. };
  990. #define MAKE_CALLBACK(pred, method) \
  991. [](void *data, obs_hotkey_pair_id, obs_hotkey_t*, bool pressed) \
  992. { \
  993. OBSBasic &basic = *static_cast<OBSBasic*>(data); \
  994. if (pred && pressed) { \
  995. method(); \
  996. return true; \
  997. } \
  998. return false; \
  999. }
  1000. streamingHotkeys = obs_hotkey_pair_register_frontend(
  1001. "OBSBasic.StartStreaming",
  1002. Str("Basic.Hotkeys.StartStreaming"),
  1003. "OBSBasic.StopStreaming",
  1004. Str("Basic.Hotkeys.StopStreaming"),
  1005. MAKE_CALLBACK(!basic.outputHandler->StreamingActive(),
  1006. basic.StartStreaming),
  1007. MAKE_CALLBACK(basic.outputHandler->StreamingActive(),
  1008. basic.StopStreaming),
  1009. this, this);
  1010. LoadHotkeyPair(streamingHotkeys,
  1011. "OBSBasic.StartStreaming", "OBSBasic.StopStreaming");
  1012. auto cb = [] (void *data, obs_hotkey_id, obs_hotkey_t*, bool pressed)
  1013. {
  1014. OBSBasic &basic = *static_cast<OBSBasic*>(data);
  1015. if (basic.outputHandler->StreamingActive() && pressed) {
  1016. basic.ForceStopStreaming();
  1017. }
  1018. };
  1019. forceStreamingStopHotkey = obs_hotkey_register_frontend(
  1020. "OBSBasic.ForceStopStreaming",
  1021. Str("Basic.Main.ForceStopStreaming"),
  1022. cb, this);
  1023. LoadHotkey(forceStreamingStopHotkey,
  1024. "OBSBasic.ForceStopStreaming");
  1025. recordingHotkeys = obs_hotkey_pair_register_frontend(
  1026. "OBSBasic.StartRecording",
  1027. Str("Basic.Hotkeys.StartRecording"),
  1028. "OBSBasic.StopRecording",
  1029. Str("Basic.Hotkeys.StopRecording"),
  1030. MAKE_CALLBACK(!basic.outputHandler->RecordingActive(),
  1031. basic.StartRecording),
  1032. MAKE_CALLBACK(basic.outputHandler->RecordingActive(),
  1033. basic.StopRecording),
  1034. this, this);
  1035. LoadHotkeyPair(recordingHotkeys,
  1036. "OBSBasic.StartRecording", "OBSBasic.StopRecording");
  1037. #undef MAKE_CALLBACK
  1038. auto togglePreviewProgram = [] (void *data, obs_hotkey_id,
  1039. obs_hotkey_t*, bool pressed)
  1040. {
  1041. if (pressed)
  1042. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  1043. "on_modeSwitch_clicked",
  1044. Qt::QueuedConnection);
  1045. };
  1046. togglePreviewProgramHotkey = obs_hotkey_register_frontend(
  1047. "OBSBasic.TogglePreviewProgram",
  1048. Str("Basic.TogglePreviewProgramMode"),
  1049. togglePreviewProgram, this);
  1050. LoadHotkey(togglePreviewProgramHotkey, "OBSBasic.TogglePreviewProgram");
  1051. auto transition = [] (void *data, obs_hotkey_id, obs_hotkey_t*,
  1052. bool pressed)
  1053. {
  1054. if (pressed)
  1055. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  1056. "TransitionClicked",
  1057. Qt::QueuedConnection);
  1058. };
  1059. transitionHotkey = obs_hotkey_register_frontend(
  1060. "OBSBasic.Transition",
  1061. Str("Transition"), transition, this);
  1062. LoadHotkey(transitionHotkey, "OBSBasic.Transition");
  1063. }
  1064. void OBSBasic::ClearHotkeys()
  1065. {
  1066. obs_hotkey_pair_unregister(streamingHotkeys);
  1067. obs_hotkey_pair_unregister(recordingHotkeys);
  1068. obs_hotkey_unregister(forceStreamingStopHotkey);
  1069. obs_hotkey_unregister(togglePreviewProgramHotkey);
  1070. obs_hotkey_unregister(transitionHotkey);
  1071. }
  1072. OBSBasic::~OBSBasic()
  1073. {
  1074. delete programOptions;
  1075. delete program;
  1076. /* XXX: any obs data must be released before calling obs_shutdown.
  1077. * currently, we can't automate this with C++ RAII because of the
  1078. * delicate nature of obs_shutdown needing to be freed before the UI
  1079. * can be freed, and we have no control over the destruction order of
  1080. * the Qt UI stuff, so we have to manually clear any references to
  1081. * libobs. */
  1082. delete cpuUsageTimer;
  1083. os_cpu_usage_info_destroy(cpuUsageInfo);
  1084. obs_hotkey_set_callback_routing_func(nullptr, nullptr);
  1085. ClearHotkeys();
  1086. service = nullptr;
  1087. outputHandler.reset();
  1088. if (interaction)
  1089. delete interaction;
  1090. if (properties)
  1091. delete properties;
  1092. if (filters)
  1093. delete filters;
  1094. if (transformWindow)
  1095. delete transformWindow;
  1096. if (advAudioWindow)
  1097. delete advAudioWindow;
  1098. obs_display_remove_draw_callback(ui->preview->GetDisplay(),
  1099. OBSBasic::RenderMain, this);
  1100. obs_enter_graphics();
  1101. gs_vertexbuffer_destroy(box);
  1102. gs_vertexbuffer_destroy(boxLeft);
  1103. gs_vertexbuffer_destroy(boxTop);
  1104. gs_vertexbuffer_destroy(boxRight);
  1105. gs_vertexbuffer_destroy(boxBottom);
  1106. gs_vertexbuffer_destroy(circle);
  1107. obs_leave_graphics();
  1108. /* When shutting down, sometimes source references can get in to the
  1109. * event queue, and if we don't forcibly process those events they
  1110. * won't get processed until after obs_shutdown has been called. I
  1111. * really wish there were a more elegant way to deal with this via C++,
  1112. * but Qt doesn't use C++ in a normal way, so you can't really rely on
  1113. * normal C++ behavior for your data to be freed in the order that you
  1114. * expect or want it to. */
  1115. QApplication::sendPostedEvents(this);
  1116. config_set_int(App()->GlobalConfig(), "General", "LastVersion",
  1117. LIBOBS_API_VER);
  1118. QRect lastGeom = normalGeometry();
  1119. QList<int> splitterSizes = ui->mainSplitter->sizes();
  1120. bool alwaysOnTop = IsAlwaysOnTop(this);
  1121. config_set_int(App()->GlobalConfig(), "BasicWindow", "cx",
  1122. lastGeom.width());
  1123. config_set_int(App()->GlobalConfig(), "BasicWindow", "cy",
  1124. lastGeom.height());
  1125. config_set_int(App()->GlobalConfig(), "BasicWindow", "posx",
  1126. lastGeom.x());
  1127. config_set_int(App()->GlobalConfig(), "BasicWindow", "posy",
  1128. lastGeom.y());
  1129. config_set_int(App()->GlobalConfig(), "BasicWindow", "splitterTop",
  1130. splitterSizes[0]);
  1131. config_set_int(App()->GlobalConfig(), "BasicWindow", "splitterBottom",
  1132. splitterSizes[1]);
  1133. config_set_bool(App()->GlobalConfig(), "BasicWindow", "PreviewEnabled",
  1134. previewEnabled);
  1135. config_set_bool(App()->GlobalConfig(), "BasicWindow", "AlwaysOnTop",
  1136. alwaysOnTop);
  1137. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  1138. "SceneDuplicationMode", sceneDuplicationMode);
  1139. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  1140. "SwapScenesMode", swapScenesMode);
  1141. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  1142. "EditPropertiesMode", editPropertiesMode);
  1143. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  1144. "PreviewProgramMode", IsPreviewProgramMode());
  1145. config_save_safe(App()->GlobalConfig(), "tmp", nullptr);
  1146. #ifdef _WIN32
  1147. uint32_t winVer = GetWindowsVersion();
  1148. if (winVer > 0 && winVer < 0x602) {
  1149. bool disableAero = config_get_bool(basicConfig, "Video",
  1150. "DisableAero");
  1151. if (disableAero) {
  1152. SetAeroEnabled(true);
  1153. }
  1154. }
  1155. #endif
  1156. }
  1157. void OBSBasic::SaveProjectNow()
  1158. {
  1159. if (disableSaving)
  1160. return;
  1161. projectChanged = true;
  1162. SaveProjectDeferred();
  1163. }
  1164. void OBSBasic::SaveProject()
  1165. {
  1166. if (disableSaving)
  1167. return;
  1168. projectChanged = true;
  1169. QMetaObject::invokeMethod(this, "SaveProjectDeferred",
  1170. Qt::QueuedConnection);
  1171. }
  1172. void OBSBasic::SaveProjectDeferred()
  1173. {
  1174. if (disableSaving)
  1175. return;
  1176. if (!projectChanged)
  1177. return;
  1178. projectChanged = false;
  1179. const char *sceneCollection = config_get_string(App()->GlobalConfig(),
  1180. "Basic", "SceneCollectionFile");
  1181. char savePath[512];
  1182. char fileName[512];
  1183. int ret;
  1184. if (!sceneCollection)
  1185. return;
  1186. ret = snprintf(fileName, 512, "obs-studio/basic/scenes/%s.json",
  1187. sceneCollection);
  1188. if (ret <= 0)
  1189. return;
  1190. ret = GetConfigPath(savePath, sizeof(savePath), fileName);
  1191. if (ret <= 0)
  1192. return;
  1193. Save(savePath);
  1194. }
  1195. OBSScene OBSBasic::GetCurrentScene()
  1196. {
  1197. QListWidgetItem *item = ui->scenes->currentItem();
  1198. return item ? GetOBSRef<OBSScene>(item) : nullptr;
  1199. }
  1200. OBSSceneItem OBSBasic::GetSceneItem(QListWidgetItem *item)
  1201. {
  1202. return item ? GetOBSRef<OBSSceneItem>(item) : nullptr;
  1203. }
  1204. OBSSceneItem OBSBasic::GetCurrentSceneItem()
  1205. {
  1206. return GetSceneItem(GetTopSelectedSourceItem());
  1207. }
  1208. void OBSBasic::UpdateSources(OBSScene scene)
  1209. {
  1210. ClearListItems(ui->sources);
  1211. obs_scene_enum_items(scene,
  1212. [] (obs_scene_t *scene, obs_sceneitem_t *item, void *p)
  1213. {
  1214. OBSBasic *window = static_cast<OBSBasic*>(p);
  1215. window->InsertSceneItem(item);
  1216. UNUSED_PARAMETER(scene);
  1217. return true;
  1218. }, this);
  1219. }
  1220. void OBSBasic::InsertSceneItem(obs_sceneitem_t *item)
  1221. {
  1222. QListWidgetItem *listItem = new QListWidgetItem();
  1223. SetOBSRef(listItem, OBSSceneItem(item));
  1224. ui->sources->insertItem(0, listItem);
  1225. ui->sources->setCurrentRow(0, QItemSelectionModel::ClearAndSelect);
  1226. SetupVisibilityItem(ui->sources, listItem, item);
  1227. }
  1228. void OBSBasic::CreateInteractionWindow(obs_source_t *source)
  1229. {
  1230. if (interaction)
  1231. interaction->close();
  1232. interaction = new OBSBasicInteraction(this, source);
  1233. interaction->Init();
  1234. interaction->setAttribute(Qt::WA_DeleteOnClose, true);
  1235. }
  1236. void OBSBasic::CreatePropertiesWindow(obs_source_t *source)
  1237. {
  1238. if (properties)
  1239. properties->close();
  1240. properties = new OBSBasicProperties(this, source);
  1241. properties->Init();
  1242. properties->setAttribute(Qt::WA_DeleteOnClose, true);
  1243. }
  1244. void OBSBasic::CreateFiltersWindow(obs_source_t *source)
  1245. {
  1246. if (filters)
  1247. filters->close();
  1248. filters = new OBSBasicFilters(this, source);
  1249. filters->Init();
  1250. filters->setAttribute(Qt::WA_DeleteOnClose, true);
  1251. }
  1252. /* Qt callbacks for invokeMethod */
  1253. void OBSBasic::AddScene(OBSSource source)
  1254. {
  1255. const char *name = obs_source_get_name(source);
  1256. obs_scene_t *scene = obs_scene_from_source(source);
  1257. QListWidgetItem *item = new QListWidgetItem(QT_UTF8(name));
  1258. SetOBSRef(item, OBSScene(scene));
  1259. ui->scenes->addItem(item);
  1260. obs_hotkey_register_source(source, "OBSBasic.SelectScene",
  1261. Str("Basic.Hotkeys.SelectScene"),
  1262. [](void *data,
  1263. obs_hotkey_id, obs_hotkey_t*, bool pressed)
  1264. {
  1265. OBSBasic *main =
  1266. reinterpret_cast<OBSBasic*>(App()->GetMainWindow());
  1267. auto potential_source = static_cast<obs_source_t*>(data);
  1268. auto source = obs_source_get_ref(potential_source);
  1269. if (source && pressed)
  1270. main->SetCurrentScene(source);
  1271. obs_source_release(source);
  1272. }, static_cast<obs_source_t*>(source));
  1273. signal_handler_t *handler = obs_source_get_signal_handler(source);
  1274. SignalContainer<OBSScene> container;
  1275. container.ref = scene;
  1276. container.handlers.assign({
  1277. std::make_shared<OBSSignal>(handler, "item_add",
  1278. OBSBasic::SceneItemAdded, this),
  1279. std::make_shared<OBSSignal>(handler, "item_remove",
  1280. OBSBasic::SceneItemRemoved, this),
  1281. std::make_shared<OBSSignal>(handler, "item_select",
  1282. OBSBasic::SceneItemSelected, this),
  1283. std::make_shared<OBSSignal>(handler, "item_deselect",
  1284. OBSBasic::SceneItemDeselected, this),
  1285. std::make_shared<OBSSignal>(handler, "reorder",
  1286. OBSBasic::SceneReordered, this),
  1287. });
  1288. item->setData(static_cast<int>(QtDataRole::OBSSignals),
  1289. QVariant::fromValue(container));
  1290. /* if the scene already has items (a duplicated scene) add them */
  1291. auto addSceneItem = [this] (obs_sceneitem_t *item)
  1292. {
  1293. AddSceneItem(item);
  1294. };
  1295. using addSceneItem_t = decltype(addSceneItem);
  1296. obs_scene_enum_items(scene,
  1297. [] (obs_scene_t*, obs_sceneitem_t *item, void *param)
  1298. {
  1299. addSceneItem_t *func;
  1300. func = reinterpret_cast<addSceneItem_t*>(param);
  1301. (*func)(item);
  1302. return true;
  1303. }, &addSceneItem);
  1304. SaveProject();
  1305. }
  1306. void OBSBasic::RemoveScene(OBSSource source)
  1307. {
  1308. obs_scene_t *scene = obs_scene_from_source(source);
  1309. QListWidgetItem *sel = nullptr;
  1310. int count = ui->scenes->count();
  1311. for (int i = 0; i < count; i++) {
  1312. auto item = ui->scenes->item(i);
  1313. auto cur_scene = GetOBSRef<OBSScene>(item);
  1314. if (cur_scene != scene)
  1315. continue;
  1316. sel = item;
  1317. break;
  1318. }
  1319. if (sel != nullptr) {
  1320. if (sel == ui->scenes->currentItem())
  1321. ClearListItems(ui->sources);
  1322. delete sel;
  1323. }
  1324. SaveProject();
  1325. }
  1326. void OBSBasic::AddSceneItem(OBSSceneItem item)
  1327. {
  1328. obs_scene_t *scene = obs_sceneitem_get_scene(item);
  1329. if (GetCurrentScene() == scene)
  1330. InsertSceneItem(item);
  1331. SaveProject();
  1332. }
  1333. void OBSBasic::RemoveSceneItem(OBSSceneItem item)
  1334. {
  1335. obs_scene_t *scene = obs_sceneitem_get_scene(item);
  1336. if (GetCurrentScene() == scene) {
  1337. for (int i = 0; i < ui->sources->count(); i++) {
  1338. QListWidgetItem *listItem = ui->sources->item(i);
  1339. if (GetOBSRef<OBSSceneItem>(listItem) == item) {
  1340. DeleteListItem(ui->sources, listItem);
  1341. break;
  1342. }
  1343. }
  1344. }
  1345. SaveProject();
  1346. }
  1347. void OBSBasic::UpdateSceneSelection(OBSSource source)
  1348. {
  1349. if (source) {
  1350. obs_scene_t *scene = obs_scene_from_source(source);
  1351. const char *name = obs_source_get_name(source);
  1352. if (!scene)
  1353. return;
  1354. QList<QListWidgetItem*> items =
  1355. ui->scenes->findItems(QT_UTF8(name), Qt::MatchExactly);
  1356. if (items.count()) {
  1357. sceneChanging = true;
  1358. ui->scenes->setCurrentItem(items.first());
  1359. sceneChanging = false;
  1360. UpdateSources(scene);
  1361. }
  1362. }
  1363. }
  1364. static void RenameListValues(QListWidget *listWidget, const QString &newName,
  1365. const QString &prevName)
  1366. {
  1367. QList<QListWidgetItem*> items =
  1368. listWidget->findItems(prevName, Qt::MatchExactly);
  1369. for (int i = 0; i < items.count(); i++)
  1370. items[i]->setText(newName);
  1371. }
  1372. void OBSBasic::RenameSources(QString newName, QString prevName)
  1373. {
  1374. RenameListValues(ui->scenes, newName, prevName);
  1375. for (size_t i = 0; i < volumes.size(); i++) {
  1376. if (volumes[i]->GetName().compare(prevName) == 0)
  1377. volumes[i]->SetName(newName);
  1378. }
  1379. SaveProject();
  1380. }
  1381. void OBSBasic::SelectSceneItem(OBSScene scene, OBSSceneItem item, bool select)
  1382. {
  1383. SignalBlocker sourcesSignalBlocker(ui->sources);
  1384. if (scene != GetCurrentScene() || ignoreSelectionUpdate)
  1385. return;
  1386. for (int i = 0; i < ui->sources->count(); i++) {
  1387. QListWidgetItem *witem = ui->sources->item(i);
  1388. QVariant data =
  1389. witem->data(static_cast<int>(QtDataRole::OBSRef));
  1390. if (!data.canConvert<OBSSceneItem>())
  1391. continue;
  1392. if (item != data.value<OBSSceneItem>())
  1393. continue;
  1394. witem->setSelected(select);
  1395. break;
  1396. }
  1397. }
  1398. void OBSBasic::GetAudioSourceFilters()
  1399. {
  1400. QAction *action = reinterpret_cast<QAction*>(sender());
  1401. VolControl *vol = action->property("volControl").value<VolControl*>();
  1402. obs_source_t *source = vol->GetSource();
  1403. CreateFiltersWindow(source);
  1404. }
  1405. void OBSBasic::GetAudioSourceProperties()
  1406. {
  1407. QAction *action = reinterpret_cast<QAction*>(sender());
  1408. VolControl *vol = action->property("volControl").value<VolControl*>();
  1409. obs_source_t *source = vol->GetSource();
  1410. CreatePropertiesWindow(source);
  1411. }
  1412. void OBSBasic::VolControlContextMenu()
  1413. {
  1414. VolControl *vol = reinterpret_cast<VolControl*>(sender());
  1415. QAction filtersAction(QTStr("Filters"), this);
  1416. QAction propertiesAction(QTStr("Properties"), this);
  1417. connect(&filtersAction, &QAction::triggered,
  1418. this, &OBSBasic::GetAudioSourceFilters,
  1419. Qt::DirectConnection);
  1420. connect(&propertiesAction, &QAction::triggered,
  1421. this, &OBSBasic::GetAudioSourceProperties,
  1422. Qt::DirectConnection);
  1423. filtersAction.setProperty("volControl",
  1424. QVariant::fromValue<VolControl*>(vol));
  1425. propertiesAction.setProperty("volControl",
  1426. QVariant::fromValue<VolControl*>(vol));
  1427. QMenu popup(this);
  1428. popup.addAction(&filtersAction);
  1429. popup.addAction(&propertiesAction);
  1430. popup.exec(QCursor::pos());
  1431. }
  1432. void OBSBasic::ActivateAudioSource(OBSSource source)
  1433. {
  1434. VolControl *vol = new VolControl(source, true);
  1435. connect(vol, &VolControl::ConfigClicked,
  1436. this, &OBSBasic::VolControlContextMenu);
  1437. volumes.push_back(vol);
  1438. ui->volumeWidgets->layout()->addWidget(vol);
  1439. }
  1440. void OBSBasic::DeactivateAudioSource(OBSSource source)
  1441. {
  1442. for (size_t i = 0; i < volumes.size(); i++) {
  1443. if (volumes[i]->GetSource() == source) {
  1444. delete volumes[i];
  1445. volumes.erase(volumes.begin() + i);
  1446. break;
  1447. }
  1448. }
  1449. }
  1450. bool OBSBasic::QueryRemoveSource(obs_source_t *source)
  1451. {
  1452. const char *name = obs_source_get_name(source);
  1453. QString text = QTStr("ConfirmRemove.Text");
  1454. text.replace("$1", QT_UTF8(name));
  1455. QMessageBox remove_source(this);
  1456. remove_source.setText(text);
  1457. QAbstractButton *Yes = remove_source.addButton(QTStr("Yes"),
  1458. QMessageBox::YesRole);
  1459. remove_source.addButton(QTStr("No"), QMessageBox::NoRole);
  1460. remove_source.setIcon(QMessageBox::Question);
  1461. remove_source.setWindowTitle(QTStr("ConfirmRemove.Title"));
  1462. remove_source.exec();
  1463. return Yes == remove_source.clickedButton();
  1464. }
  1465. #define UPDATE_CHECK_INTERVAL (60*60*24*4) /* 4 days */
  1466. #ifdef UPDATE_SPARKLE
  1467. void init_sparkle_updater(bool update_to_undeployed);
  1468. void trigger_sparkle_update();
  1469. #endif
  1470. void OBSBasic::TimedCheckForUpdates()
  1471. {
  1472. #ifdef UPDATE_SPARKLE
  1473. init_sparkle_updater(config_get_bool(App()->GlobalConfig(), "General",
  1474. "UpdateToUndeployed"));
  1475. #else
  1476. long long lastUpdate = config_get_int(App()->GlobalConfig(), "General",
  1477. "LastUpdateCheck");
  1478. uint32_t lastVersion = config_get_int(App()->GlobalConfig(), "General",
  1479. "LastVersion");
  1480. if (lastVersion < LIBOBS_API_VER) {
  1481. lastUpdate = 0;
  1482. config_set_int(App()->GlobalConfig(), "General",
  1483. "LastUpdateCheck", 0);
  1484. }
  1485. long long t = (long long)time(nullptr);
  1486. long long secs = t - lastUpdate;
  1487. if (secs > UPDATE_CHECK_INTERVAL)
  1488. CheckForUpdates();
  1489. #endif
  1490. }
  1491. void OBSBasic::CheckForUpdates()
  1492. {
  1493. #ifdef UPDATE_SPARKLE
  1494. trigger_sparkle_update();
  1495. #else
  1496. ui->actionCheckForUpdates->setEnabled(false);
  1497. if (updateCheckThread) {
  1498. updateCheckThread->wait();
  1499. delete updateCheckThread;
  1500. }
  1501. RemoteTextThread *thread = new RemoteTextThread(
  1502. "https://obsproject.com/obs2_update/basic.json");
  1503. updateCheckThread = thread;
  1504. connect(thread, &RemoteTextThread::Result,
  1505. this, &OBSBasic::updateFileFinished);
  1506. updateCheckThread->start();
  1507. #endif
  1508. }
  1509. #ifdef __APPLE__
  1510. #define VERSION_ENTRY "mac"
  1511. #elif _WIN32
  1512. #define VERSION_ENTRY "windows"
  1513. #else
  1514. #define VERSION_ENTRY "other"
  1515. #endif
  1516. void OBSBasic::updateFileFinished(const QString &text, const QString &error)
  1517. {
  1518. ui->actionCheckForUpdates->setEnabled(true);
  1519. if (text.isEmpty()) {
  1520. blog(LOG_WARNING, "Update check failed: %s", QT_TO_UTF8(error));
  1521. return;
  1522. }
  1523. obs_data_t *returnData = obs_data_create_from_json(QT_TO_UTF8(text));
  1524. obs_data_t *versionData = obs_data_get_obj(returnData, VERSION_ENTRY);
  1525. const char *description = obs_data_get_string(returnData,
  1526. "description");
  1527. const char *download = obs_data_get_string(versionData, "download");
  1528. if (returnData && versionData && description && download) {
  1529. long major = obs_data_get_int(versionData, "major");
  1530. long minor = obs_data_get_int(versionData, "minor");
  1531. long patch = obs_data_get_int(versionData, "patch");
  1532. long version = MAKE_SEMANTIC_VERSION(major, minor, patch);
  1533. blog(LOG_INFO, "Update check: last known remote version "
  1534. "is %ld.%ld.%ld",
  1535. major, minor, patch);
  1536. if (version > LIBOBS_API_VER) {
  1537. QString str = QTStr("UpdateAvailable.Text");
  1538. QMessageBox messageBox(this);
  1539. str = str.arg(QString::number(major),
  1540. QString::number(minor),
  1541. QString::number(patch),
  1542. download);
  1543. messageBox.setWindowTitle(QTStr("UpdateAvailable"));
  1544. messageBox.setTextFormat(Qt::RichText);
  1545. messageBox.setText(str);
  1546. messageBox.setInformativeText(QT_UTF8(description));
  1547. messageBox.exec();
  1548. long long t = (long long)time(nullptr);
  1549. config_set_int(App()->GlobalConfig(), "General",
  1550. "LastUpdateCheck", t);
  1551. config_save_safe(App()->GlobalConfig(), "tmp", nullptr);
  1552. }
  1553. } else {
  1554. blog(LOG_WARNING, "Bad JSON file received from server");
  1555. }
  1556. obs_data_release(versionData);
  1557. obs_data_release(returnData);
  1558. }
  1559. void OBSBasic::DuplicateSelectedScene()
  1560. {
  1561. OBSScene curScene = GetCurrentScene();
  1562. if (!curScene)
  1563. return;
  1564. OBSSource curSceneSource = obs_scene_get_source(curScene);
  1565. QString format{obs_source_get_name(curSceneSource)};
  1566. format += " %1";
  1567. int i = 2;
  1568. QString placeHolderText = format.arg(i);
  1569. obs_source_t *source = nullptr;
  1570. while ((source = obs_get_source_by_name(QT_TO_UTF8(placeHolderText)))) {
  1571. obs_source_release(source);
  1572. placeHolderText = format.arg(++i);
  1573. }
  1574. for (;;) {
  1575. string name;
  1576. bool accepted = NameDialog::AskForName(this,
  1577. QTStr("Basic.Main.AddSceneDlg.Title"),
  1578. QTStr("Basic.Main.AddSceneDlg.Text"),
  1579. name,
  1580. placeHolderText);
  1581. if (!accepted)
  1582. return;
  1583. if (name.empty()) {
  1584. QMessageBox::information(this,
  1585. QTStr("NoNameEntered.Title"),
  1586. QTStr("NoNameEntered.Text"));
  1587. continue;
  1588. }
  1589. obs_source_t *source = obs_get_source_by_name(name.c_str());
  1590. if (source) {
  1591. QMessageBox::information(this,
  1592. QTStr("NameExists.Title"),
  1593. QTStr("NameExists.Text"));
  1594. obs_source_release(source);
  1595. continue;
  1596. }
  1597. obs_scene_t *scene = obs_scene_duplicate(curScene,
  1598. name.c_str(), OBS_SCENE_DUP_REFS);
  1599. source = obs_scene_get_source(scene);
  1600. AddScene(source);
  1601. SetCurrentScene(source, true);
  1602. obs_scene_release(scene);
  1603. break;
  1604. }
  1605. }
  1606. void OBSBasic::RemoveSelectedScene()
  1607. {
  1608. OBSScene scene = GetCurrentScene();
  1609. if (scene) {
  1610. obs_source_t *source = obs_scene_get_source(scene);
  1611. if (QueryRemoveSource(source))
  1612. obs_source_remove(source);
  1613. }
  1614. }
  1615. void OBSBasic::RemoveSelectedSceneItem()
  1616. {
  1617. OBSSceneItem item = GetCurrentSceneItem();
  1618. if (item) {
  1619. obs_source_t *source = obs_sceneitem_get_source(item);
  1620. if (QueryRemoveSource(source))
  1621. obs_sceneitem_remove(item);
  1622. }
  1623. }
  1624. struct ReorderInfo {
  1625. int idx = 0;
  1626. OBSBasic *window;
  1627. inline ReorderInfo(OBSBasic *window_) : window(window_) {}
  1628. };
  1629. void OBSBasic::ReorderSceneItem(obs_sceneitem_t *item, size_t idx)
  1630. {
  1631. int count = ui->sources->count();
  1632. int idx_inv = count - (int)idx - 1;
  1633. for (int i = 0; i < count; i++) {
  1634. QListWidgetItem *listItem = ui->sources->item(i);
  1635. OBSSceneItem sceneItem = GetOBSRef<OBSSceneItem>(listItem);
  1636. if (sceneItem == item) {
  1637. if ((int)idx_inv != i) {
  1638. bool sel = (ui->sources->currentRow() == i);
  1639. listItem = TakeListItem(ui->sources, i);
  1640. if (listItem) {
  1641. ui->sources->insertItem(idx_inv,
  1642. listItem);
  1643. SetupVisibilityItem(ui->sources,
  1644. listItem, item);
  1645. if (sel)
  1646. ui->sources->setCurrentRow(
  1647. idx_inv);
  1648. }
  1649. }
  1650. break;
  1651. }
  1652. }
  1653. }
  1654. void OBSBasic::ReorderSources(OBSScene scene)
  1655. {
  1656. ReorderInfo info(this);
  1657. if (scene != GetCurrentScene() || ui->sources->IgnoreReorder())
  1658. return;
  1659. obs_scene_enum_items(scene,
  1660. [] (obs_scene_t*, obs_sceneitem_t *item, void *p)
  1661. {
  1662. ReorderInfo *info =
  1663. reinterpret_cast<ReorderInfo*>(p);
  1664. info->window->ReorderSceneItem(item,
  1665. info->idx++);
  1666. return true;
  1667. }, &info);
  1668. SaveProject();
  1669. }
  1670. /* OBS Callbacks */
  1671. void OBSBasic::SceneReordered(void *data, calldata_t *params)
  1672. {
  1673. OBSBasic *window = static_cast<OBSBasic*>(data);
  1674. obs_scene_t *scene = (obs_scene_t*)calldata_ptr(params, "scene");
  1675. QMetaObject::invokeMethod(window, "ReorderSources",
  1676. Q_ARG(OBSScene, OBSScene(scene)));
  1677. }
  1678. void OBSBasic::SceneItemAdded(void *data, calldata_t *params)
  1679. {
  1680. OBSBasic *window = static_cast<OBSBasic*>(data);
  1681. obs_sceneitem_t *item = (obs_sceneitem_t*)calldata_ptr(params, "item");
  1682. QMetaObject::invokeMethod(window, "AddSceneItem",
  1683. Q_ARG(OBSSceneItem, OBSSceneItem(item)));
  1684. }
  1685. void OBSBasic::SceneItemRemoved(void *data, calldata_t *params)
  1686. {
  1687. OBSBasic *window = static_cast<OBSBasic*>(data);
  1688. obs_sceneitem_t *item = (obs_sceneitem_t*)calldata_ptr(params, "item");
  1689. QMetaObject::invokeMethod(window, "RemoveSceneItem",
  1690. Q_ARG(OBSSceneItem, OBSSceneItem(item)));
  1691. }
  1692. void OBSBasic::SceneItemSelected(void *data, calldata_t *params)
  1693. {
  1694. OBSBasic *window = static_cast<OBSBasic*>(data);
  1695. obs_scene_t *scene = (obs_scene_t*)calldata_ptr(params, "scene");
  1696. obs_sceneitem_t *item = (obs_sceneitem_t*)calldata_ptr(params, "item");
  1697. QMetaObject::invokeMethod(window, "SelectSceneItem",
  1698. Q_ARG(OBSScene, scene), Q_ARG(OBSSceneItem, item),
  1699. Q_ARG(bool, true));
  1700. }
  1701. void OBSBasic::SceneItemDeselected(void *data, calldata_t *params)
  1702. {
  1703. OBSBasic *window = static_cast<OBSBasic*>(data);
  1704. obs_scene_t *scene = (obs_scene_t*)calldata_ptr(params, "scene");
  1705. obs_sceneitem_t *item = (obs_sceneitem_t*)calldata_ptr(params, "item");
  1706. QMetaObject::invokeMethod(window, "SelectSceneItem",
  1707. Q_ARG(OBSScene, scene), Q_ARG(OBSSceneItem, item),
  1708. Q_ARG(bool, false));
  1709. }
  1710. void OBSBasic::SourceLoaded(void *data, obs_source_t *source)
  1711. {
  1712. OBSBasic *window = static_cast<OBSBasic*>(data);
  1713. if (obs_scene_from_source(source) != NULL)
  1714. QMetaObject::invokeMethod(window,
  1715. "AddScene",
  1716. Q_ARG(OBSSource, OBSSource(source)));
  1717. }
  1718. void OBSBasic::SourceRemoved(void *data, calldata_t *params)
  1719. {
  1720. obs_source_t *source = (obs_source_t*)calldata_ptr(params, "source");
  1721. if (obs_scene_from_source(source) != NULL)
  1722. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  1723. "RemoveScene",
  1724. Q_ARG(OBSSource, OBSSource(source)));
  1725. }
  1726. void OBSBasic::SourceActivated(void *data, calldata_t *params)
  1727. {
  1728. obs_source_t *source = (obs_source_t*)calldata_ptr(params, "source");
  1729. uint32_t flags = obs_source_get_output_flags(source);
  1730. if (flags & OBS_SOURCE_AUDIO)
  1731. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  1732. "ActivateAudioSource",
  1733. Q_ARG(OBSSource, OBSSource(source)));
  1734. }
  1735. void OBSBasic::SourceDeactivated(void *data, calldata_t *params)
  1736. {
  1737. obs_source_t *source = (obs_source_t*)calldata_ptr(params, "source");
  1738. uint32_t flags = obs_source_get_output_flags(source);
  1739. if (flags & OBS_SOURCE_AUDIO)
  1740. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  1741. "DeactivateAudioSource",
  1742. Q_ARG(OBSSource, OBSSource(source)));
  1743. }
  1744. void OBSBasic::SourceRenamed(void *data, calldata_t *params)
  1745. {
  1746. const char *newName = calldata_string(params, "new_name");
  1747. const char *prevName = calldata_string(params, "prev_name");
  1748. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  1749. "RenameSources",
  1750. Q_ARG(QString, QT_UTF8(newName)),
  1751. Q_ARG(QString, QT_UTF8(prevName)));
  1752. }
  1753. void OBSBasic::DrawBackdrop(float cx, float cy)
  1754. {
  1755. if (!box)
  1756. return;
  1757. gs_effect_t *solid = obs_get_base_effect(OBS_EFFECT_SOLID);
  1758. gs_eparam_t *color = gs_effect_get_param_by_name(solid, "color");
  1759. gs_technique_t *tech = gs_effect_get_technique(solid, "Solid");
  1760. vec4 colorVal;
  1761. vec4_set(&colorVal, 0.0f, 0.0f, 0.0f, 1.0f);
  1762. gs_effect_set_vec4(color, &colorVal);
  1763. gs_technique_begin(tech);
  1764. gs_technique_begin_pass(tech, 0);
  1765. gs_matrix_push();
  1766. gs_matrix_identity();
  1767. gs_matrix_scale3f(float(cx), float(cy), 1.0f);
  1768. gs_load_vertexbuffer(box);
  1769. gs_draw(GS_TRISTRIP, 0, 0);
  1770. gs_matrix_pop();
  1771. gs_technique_end_pass(tech);
  1772. gs_technique_end(tech);
  1773. gs_load_vertexbuffer(nullptr);
  1774. }
  1775. void OBSBasic::RenderMain(void *data, uint32_t cx, uint32_t cy)
  1776. {
  1777. OBSBasic *window = static_cast<OBSBasic*>(data);
  1778. obs_video_info ovi;
  1779. obs_get_video_info(&ovi);
  1780. window->previewCX = int(window->previewScale * float(ovi.base_width));
  1781. window->previewCY = int(window->previewScale * float(ovi.base_height));
  1782. gs_viewport_push();
  1783. gs_projection_push();
  1784. /* --------------------------------------- */
  1785. gs_ortho(0.0f, float(ovi.base_width), 0.0f, float(ovi.base_height),
  1786. -100.0f, 100.0f);
  1787. gs_set_viewport(window->previewX, window->previewY,
  1788. window->previewCX, window->previewCY);
  1789. window->DrawBackdrop(float(ovi.base_width), float(ovi.base_height));
  1790. if (window->IsPreviewProgramMode()) {
  1791. OBSScene scene = window->GetCurrentScene();
  1792. obs_source_t *source = obs_scene_get_source(scene);
  1793. if (source)
  1794. obs_source_video_render(source);
  1795. } else {
  1796. obs_render_main_view();
  1797. }
  1798. gs_load_vertexbuffer(nullptr);
  1799. /* --------------------------------------- */
  1800. QSize previewSize = GetPixelSize(window->ui->preview);
  1801. float right = float(previewSize.width()) - window->previewX;
  1802. float bottom = float(previewSize.height()) - window->previewY;
  1803. gs_ortho(-window->previewX, right,
  1804. -window->previewY, bottom,
  1805. -100.0f, 100.0f);
  1806. gs_reset_viewport();
  1807. window->ui->preview->DrawSceneEditing();
  1808. /* --------------------------------------- */
  1809. gs_projection_pop();
  1810. gs_viewport_pop();
  1811. UNUSED_PARAMETER(cx);
  1812. UNUSED_PARAMETER(cy);
  1813. }
  1814. /* Main class functions */
  1815. obs_service_t *OBSBasic::GetService()
  1816. {
  1817. if (!service) {
  1818. service = obs_service_create("rtmp_common", NULL, NULL,
  1819. nullptr);
  1820. obs_service_release(service);
  1821. }
  1822. return service;
  1823. }
  1824. void OBSBasic::SetService(obs_service_t *newService)
  1825. {
  1826. if (newService)
  1827. service = newService;
  1828. }
  1829. bool OBSBasic::StreamingActive() const
  1830. {
  1831. if (!outputHandler)
  1832. return false;
  1833. return outputHandler->StreamingActive();
  1834. }
  1835. bool OBSBasic::Active() const
  1836. {
  1837. if (!outputHandler)
  1838. return false;
  1839. return outputHandler->Active();
  1840. }
  1841. #ifdef _WIN32
  1842. #define IS_WIN32 1
  1843. #else
  1844. #define IS_WIN32 0
  1845. #endif
  1846. static inline int AttemptToResetVideo(struct obs_video_info *ovi)
  1847. {
  1848. return obs_reset_video(ovi);
  1849. }
  1850. static inline enum obs_scale_type GetScaleType(ConfigFile &basicConfig)
  1851. {
  1852. const char *scaleTypeStr = config_get_string(basicConfig,
  1853. "Video", "ScaleType");
  1854. if (astrcmpi(scaleTypeStr, "bilinear") == 0)
  1855. return OBS_SCALE_BILINEAR;
  1856. else if (astrcmpi(scaleTypeStr, "lanczos") == 0)
  1857. return OBS_SCALE_LANCZOS;
  1858. else
  1859. return OBS_SCALE_BICUBIC;
  1860. }
  1861. static inline enum video_format GetVideoFormatFromName(const char *name)
  1862. {
  1863. if (astrcmpi(name, "I420") == 0)
  1864. return VIDEO_FORMAT_I420;
  1865. else if (astrcmpi(name, "NV12") == 0)
  1866. return VIDEO_FORMAT_NV12;
  1867. else if (astrcmpi(name, "I444") == 0)
  1868. return VIDEO_FORMAT_I444;
  1869. #if 0 //currently unsupported
  1870. else if (astrcmpi(name, "YVYU") == 0)
  1871. return VIDEO_FORMAT_YVYU;
  1872. else if (astrcmpi(name, "YUY2") == 0)
  1873. return VIDEO_FORMAT_YUY2;
  1874. else if (astrcmpi(name, "UYVY") == 0)
  1875. return VIDEO_FORMAT_UYVY;
  1876. #endif
  1877. else
  1878. return VIDEO_FORMAT_RGBA;
  1879. }
  1880. int OBSBasic::ResetVideo()
  1881. {
  1882. ProfileScope("OBSBasic::ResetVideo");
  1883. struct obs_video_info ovi;
  1884. int ret;
  1885. GetConfigFPS(ovi.fps_num, ovi.fps_den);
  1886. const char *colorFormat = config_get_string(basicConfig, "Video",
  1887. "ColorFormat");
  1888. const char *colorSpace = config_get_string(basicConfig, "Video",
  1889. "ColorSpace");
  1890. const char *colorRange = config_get_string(basicConfig, "Video",
  1891. "ColorRange");
  1892. ovi.graphics_module = App()->GetRenderModule();
  1893. ovi.base_width = (uint32_t)config_get_uint(basicConfig,
  1894. "Video", "BaseCX");
  1895. ovi.base_height = (uint32_t)config_get_uint(basicConfig,
  1896. "Video", "BaseCY");
  1897. ovi.output_width = (uint32_t)config_get_uint(basicConfig,
  1898. "Video", "OutputCX");
  1899. ovi.output_height = (uint32_t)config_get_uint(basicConfig,
  1900. "Video", "OutputCY");
  1901. ovi.output_format = GetVideoFormatFromName(colorFormat);
  1902. ovi.colorspace = astrcmpi(colorSpace, "601") == 0 ?
  1903. VIDEO_CS_601 : VIDEO_CS_709;
  1904. ovi.range = astrcmpi(colorRange, "Full") == 0 ?
  1905. VIDEO_RANGE_FULL : VIDEO_RANGE_PARTIAL;
  1906. ovi.adapter = 0;
  1907. ovi.gpu_conversion = true;
  1908. ovi.scale_type = GetScaleType(basicConfig);
  1909. if (ovi.base_width == 0 || ovi.base_height == 0) {
  1910. ovi.base_width = 1920;
  1911. ovi.base_height = 1080;
  1912. config_set_uint(basicConfig, "Video", "BaseCX", 1920);
  1913. config_set_uint(basicConfig, "Video", "BaseCY", 1080);
  1914. }
  1915. if (ovi.output_width == 0 || ovi.output_height == 0) {
  1916. ovi.output_width = ovi.base_width;
  1917. ovi.output_height = ovi.base_height;
  1918. config_set_uint(basicConfig, "Video", "OutputCX",
  1919. ovi.base_width);
  1920. config_set_uint(basicConfig, "Video", "OutputCY",
  1921. ovi.base_height);
  1922. }
  1923. ret = AttemptToResetVideo(&ovi);
  1924. if (IS_WIN32 && ret != OBS_VIDEO_SUCCESS) {
  1925. /* Try OpenGL if DirectX fails on windows */
  1926. if (astrcmpi(ovi.graphics_module, DL_OPENGL) != 0) {
  1927. blog(LOG_WARNING, "Failed to initialize obs video (%d) "
  1928. "with graphics_module='%s', retrying "
  1929. "with graphics_module='%s'",
  1930. ret, ovi.graphics_module,
  1931. DL_OPENGL);
  1932. ovi.graphics_module = DL_OPENGL;
  1933. ret = AttemptToResetVideo(&ovi);
  1934. }
  1935. } else if (ret == OBS_VIDEO_SUCCESS) {
  1936. ResizePreview(ovi.base_width, ovi.base_height);
  1937. if (program)
  1938. ResizeProgram(ovi.base_width, ovi.base_height);
  1939. }
  1940. return ret;
  1941. }
  1942. bool OBSBasic::ResetAudio()
  1943. {
  1944. ProfileScope("OBSBasic::ResetAudio");
  1945. struct obs_audio_info ai;
  1946. ai.samples_per_sec = config_get_uint(basicConfig, "Audio",
  1947. "SampleRate");
  1948. const char *channelSetupStr = config_get_string(basicConfig,
  1949. "Audio", "ChannelSetup");
  1950. if (strcmp(channelSetupStr, "Mono") == 0)
  1951. ai.speakers = SPEAKERS_MONO;
  1952. else
  1953. ai.speakers = SPEAKERS_STEREO;
  1954. return obs_reset_audio(&ai);
  1955. }
  1956. void OBSBasic::ResetAudioDevice(const char *sourceId, const char *deviceId,
  1957. const char *deviceDesc, int channel)
  1958. {
  1959. obs_source_t *source;
  1960. obs_data_t *settings;
  1961. bool same = false;
  1962. source = obs_get_output_source(channel);
  1963. if (source) {
  1964. settings = obs_source_get_settings(source);
  1965. const char *curId = obs_data_get_string(settings, "device_id");
  1966. same = (strcmp(curId, deviceId) == 0);
  1967. obs_data_release(settings);
  1968. obs_source_release(source);
  1969. }
  1970. if (!same)
  1971. obs_set_output_source(channel, nullptr);
  1972. if (!same && strcmp(deviceId, "disabled") != 0) {
  1973. obs_data_t *settings = obs_data_create();
  1974. obs_data_set_string(settings, "device_id", deviceId);
  1975. source = obs_source_create(sourceId, deviceDesc, settings,
  1976. nullptr);
  1977. obs_data_release(settings);
  1978. obs_set_output_source(channel, source);
  1979. obs_source_release(source);
  1980. }
  1981. }
  1982. void OBSBasic::ResizePreview(uint32_t cx, uint32_t cy)
  1983. {
  1984. QSize targetSize;
  1985. /* resize preview panel to fix to the top section of the window */
  1986. targetSize = GetPixelSize(ui->preview);
  1987. GetScaleAndCenterPos(int(cx), int(cy),
  1988. targetSize.width() - PREVIEW_EDGE_SIZE * 2,
  1989. targetSize.height() - PREVIEW_EDGE_SIZE * 2,
  1990. previewX, previewY, previewScale);
  1991. previewX += float(PREVIEW_EDGE_SIZE);
  1992. previewY += float(PREVIEW_EDGE_SIZE);
  1993. }
  1994. void OBSBasic::CloseDialogs()
  1995. {
  1996. QList<QDialog*> childDialogs = this->findChildren<QDialog *>();
  1997. if (!childDialogs.isEmpty()) {
  1998. for (int i = 0; i < childDialogs.size(); ++i) {
  1999. childDialogs.at(i)->close();
  2000. }
  2001. }
  2002. for (QPointer<QWidget> &projector : projectors) {
  2003. delete projector;
  2004. projector.clear();
  2005. }
  2006. }
  2007. void OBSBasic::ClearSceneData()
  2008. {
  2009. disableSaving++;
  2010. CloseDialogs();
  2011. ClearVolumeControls();
  2012. ClearListItems(ui->scenes);
  2013. ClearListItems(ui->sources);
  2014. ClearQuickTransitions();
  2015. ui->transitions->clear();
  2016. obs_set_output_source(0, nullptr);
  2017. obs_set_output_source(1, nullptr);
  2018. obs_set_output_source(2, nullptr);
  2019. obs_set_output_source(3, nullptr);
  2020. obs_set_output_source(4, nullptr);
  2021. obs_set_output_source(5, nullptr);
  2022. lastScene = nullptr;
  2023. swapScene = nullptr;
  2024. programScene = nullptr;
  2025. auto cb = [](void *unused, obs_source_t *source)
  2026. {
  2027. obs_source_remove(source);
  2028. UNUSED_PARAMETER(unused);
  2029. return true;
  2030. };
  2031. obs_enum_sources(cb, nullptr);
  2032. disableSaving--;
  2033. blog(LOG_INFO, "All scene data cleared");
  2034. blog(LOG_INFO, "------------------------------------------------");
  2035. }
  2036. void OBSBasic::closeEvent(QCloseEvent *event)
  2037. {
  2038. if (outputHandler && outputHandler->Active()) {
  2039. QMessageBox::StandardButton button = QMessageBox::question(
  2040. this, QTStr("ConfirmExit.Title"),
  2041. QTStr("ConfirmExit.Text"));
  2042. if (button == QMessageBox::No) {
  2043. event->ignore();
  2044. return;
  2045. }
  2046. }
  2047. QWidget::closeEvent(event);
  2048. if (!event->isAccepted())
  2049. return;
  2050. if (updateCheckThread)
  2051. updateCheckThread->wait();
  2052. if (logUploadThread)
  2053. logUploadThread->wait();
  2054. signalHandlers.clear();
  2055. SaveProjectNow();
  2056. disableSaving++;
  2057. /* Clear all scene data (dialogs, widgets, widget sub-items, scenes,
  2058. * sources, etc) so that all references are released before shutdown */
  2059. ClearSceneData();
  2060. }
  2061. void OBSBasic::changeEvent(QEvent *event)
  2062. {
  2063. /* TODO */
  2064. UNUSED_PARAMETER(event);
  2065. }
  2066. void OBSBasic::on_actionShow_Recordings_triggered()
  2067. {
  2068. const char *mode = config_get_string(basicConfig, "Output", "Mode");
  2069. const char *path = strcmp(mode, "Advanced") ?
  2070. config_get_string(basicConfig, "SimpleOutput", "FilePath") :
  2071. config_get_string(basicConfig, "AdvOut", "RecFilePath");
  2072. QDesktopServices::openUrl(QUrl::fromLocalFile(path));
  2073. }
  2074. void OBSBasic::on_actionRemux_triggered()
  2075. {
  2076. const char *mode = config_get_string(basicConfig, "Output", "Mode");
  2077. const char *path = strcmp(mode, "Advanced") ?
  2078. config_get_string(basicConfig, "SimpleOutput", "FilePath") :
  2079. config_get_string(basicConfig, "AdvOut", "RecFilePath");
  2080. OBSRemux remux(path, this);
  2081. remux.exec();
  2082. }
  2083. void OBSBasic::on_action_Settings_triggered()
  2084. {
  2085. OBSBasicSettings settings(this);
  2086. settings.exec();
  2087. }
  2088. void OBSBasic::on_actionAdvAudioProperties_triggered()
  2089. {
  2090. if (advAudioWindow != nullptr) {
  2091. advAudioWindow->raise();
  2092. return;
  2093. }
  2094. advAudioWindow = new OBSBasicAdvAudio(this);
  2095. advAudioWindow->show();
  2096. advAudioWindow->setAttribute(Qt::WA_DeleteOnClose, true);
  2097. connect(advAudioWindow, SIGNAL(destroyed()),
  2098. this, SLOT(on_advAudioProps_destroyed()));
  2099. }
  2100. void OBSBasic::on_advAudioProps_clicked()
  2101. {
  2102. on_actionAdvAudioProperties_triggered();
  2103. }
  2104. void OBSBasic::on_advAudioProps_destroyed()
  2105. {
  2106. advAudioWindow = nullptr;
  2107. }
  2108. void OBSBasic::on_scenes_currentItemChanged(QListWidgetItem *current,
  2109. QListWidgetItem *prev)
  2110. {
  2111. obs_source_t *source = NULL;
  2112. if (sceneChanging)
  2113. return;
  2114. if (current) {
  2115. obs_scene_t *scene;
  2116. scene = GetOBSRef<OBSScene>(current);
  2117. source = obs_scene_get_source(scene);
  2118. }
  2119. SetCurrentScene(source);
  2120. UNUSED_PARAMETER(prev);
  2121. }
  2122. void OBSBasic::EditSceneName()
  2123. {
  2124. QListWidgetItem *item = ui->scenes->currentItem();
  2125. Qt::ItemFlags flags = item->flags();
  2126. item->setFlags(flags | Qt::ItemIsEditable);
  2127. ui->scenes->editItem(item);
  2128. item->setFlags(flags);
  2129. }
  2130. static void AddProjectorMenuMonitors(QMenu *parent, QObject *target,
  2131. const char *slot)
  2132. {
  2133. QAction *action;
  2134. std::vector<MonitorInfo> monitors;
  2135. GetMonitors(monitors);
  2136. for (int i = 0; (size_t)i < monitors.size(); i++) {
  2137. const MonitorInfo &monitor = monitors[i];
  2138. QString str = QString("%1 %2: %3x%4 @ %5,%6").
  2139. arg(QTStr("Display"),
  2140. QString::number(i),
  2141. QString::number((int)monitor.cx),
  2142. QString::number((int)monitor.cy),
  2143. QString::number((int)monitor.x),
  2144. QString::number((int)monitor.y));
  2145. action = parent->addAction(str, target, slot);
  2146. action->setProperty("monitor", i);
  2147. }
  2148. }
  2149. void OBSBasic::on_scenes_customContextMenuRequested(const QPoint &pos)
  2150. {
  2151. QListWidgetItem *item = ui->scenes->itemAt(pos);
  2152. QPointer<QMenu> sceneProjectorMenu;
  2153. QMenu popup(this);
  2154. QMenu order(QTStr("Basic.MainMenu.Edit.Order"), this);
  2155. popup.addAction(QTStr("Add"),
  2156. this, SLOT(on_actionAddScene_triggered()));
  2157. if (item) {
  2158. popup.addSeparator();
  2159. popup.addAction(QTStr("Duplicate"),
  2160. this, SLOT(DuplicateSelectedScene()));
  2161. popup.addAction(QTStr("Rename"),
  2162. this, SLOT(EditSceneName()));
  2163. popup.addAction(QTStr("Remove"),
  2164. this, SLOT(RemoveSelectedScene()),
  2165. DeleteKeys.front());
  2166. popup.addSeparator();
  2167. order.addAction(QTStr("Basic.MainMenu.Edit.Order.MoveUp"),
  2168. this, SLOT(on_actionSceneUp_triggered()));
  2169. order.addAction(QTStr("Basic.MainMenu.Edit.Order.MoveDown"),
  2170. this, SLOT(on_actionSceneDown_triggered()));
  2171. order.addSeparator();
  2172. order.addAction(QTStr("Basic.MainMenu.Edit.Order.MoveToTop"),
  2173. this, SLOT(MoveSceneToTop()));
  2174. order.addAction(QTStr("Basic.MainMenu.Edit.Order.MoveToBottom"),
  2175. this, SLOT(MoveSceneToBottom()));
  2176. popup.addMenu(&order);
  2177. popup.addSeparator();
  2178. sceneProjectorMenu = new QMenu(QTStr("SceneProjector"));
  2179. AddProjectorMenuMonitors(sceneProjectorMenu, this,
  2180. SLOT(OpenSceneProjector()));
  2181. popup.addMenu(sceneProjectorMenu);
  2182. popup.addSeparator();
  2183. popup.addAction(QTStr("Filters"), this,
  2184. SLOT(OpenSceneFilters()));
  2185. }
  2186. popup.exec(QCursor::pos());
  2187. }
  2188. void OBSBasic::on_actionAddScene_triggered()
  2189. {
  2190. string name;
  2191. QString format{QTStr("Basic.Main.DefaultSceneName.Text")};
  2192. int i = 1;
  2193. QString placeHolderText = format.arg(i);
  2194. obs_source_t *source = nullptr;
  2195. while ((source = obs_get_source_by_name(QT_TO_UTF8(placeHolderText)))) {
  2196. obs_source_release(source);
  2197. placeHolderText = format.arg(++i);
  2198. }
  2199. bool accepted = NameDialog::AskForName(this,
  2200. QTStr("Basic.Main.AddSceneDlg.Title"),
  2201. QTStr("Basic.Main.AddSceneDlg.Text"),
  2202. name,
  2203. placeHolderText);
  2204. if (accepted) {
  2205. if (name.empty()) {
  2206. QMessageBox::information(this,
  2207. QTStr("NoNameEntered.Title"),
  2208. QTStr("NoNameEntered.Text"));
  2209. on_actionAddScene_triggered();
  2210. return;
  2211. }
  2212. obs_source_t *source = obs_get_source_by_name(name.c_str());
  2213. if (source) {
  2214. QMessageBox::information(this,
  2215. QTStr("NameExists.Title"),
  2216. QTStr("NameExists.Text"));
  2217. obs_source_release(source);
  2218. on_actionAddScene_triggered();
  2219. return;
  2220. }
  2221. obs_scene_t *scene = obs_scene_create(name.c_str());
  2222. source = obs_scene_get_source(scene);
  2223. AddScene(source);
  2224. SetCurrentScene(source);
  2225. obs_scene_release(scene);
  2226. }
  2227. }
  2228. void OBSBasic::on_actionRemoveScene_triggered()
  2229. {
  2230. OBSScene scene = GetCurrentScene();
  2231. obs_source_t *source = obs_scene_get_source(scene);
  2232. if (source && QueryRemoveSource(source))
  2233. obs_source_remove(source);
  2234. }
  2235. void OBSBasic::ChangeSceneIndex(bool relative, int offset, int invalidIdx)
  2236. {
  2237. int idx = ui->scenes->currentRow();
  2238. if (idx == -1 || idx == invalidIdx)
  2239. return;
  2240. sceneChanging = true;
  2241. QListWidgetItem *item = ui->scenes->takeItem(idx);
  2242. if (!relative)
  2243. idx = 0;
  2244. ui->scenes->insertItem(idx + offset, item);
  2245. ui->scenes->setCurrentRow(idx + offset);
  2246. item->setSelected(true);
  2247. sceneChanging = false;
  2248. }
  2249. void OBSBasic::on_actionSceneUp_triggered()
  2250. {
  2251. ChangeSceneIndex(true, -1, 0);
  2252. }
  2253. void OBSBasic::on_actionSceneDown_triggered()
  2254. {
  2255. ChangeSceneIndex(true, 1, ui->scenes->count() - 1);
  2256. }
  2257. void OBSBasic::MoveSceneToTop()
  2258. {
  2259. ChangeSceneIndex(false, 0, 0);
  2260. }
  2261. void OBSBasic::MoveSceneToBottom()
  2262. {
  2263. ChangeSceneIndex(false, ui->scenes->count() - 1,
  2264. ui->scenes->count() - 1);
  2265. }
  2266. void OBSBasic::on_sources_itemSelectionChanged()
  2267. {
  2268. SignalBlocker sourcesSignalBlocker(ui->sources);
  2269. auto updateItemSelection = [&]()
  2270. {
  2271. ignoreSelectionUpdate = true;
  2272. for (int i = 0; i < ui->sources->count(); i++)
  2273. {
  2274. QListWidgetItem *wItem = ui->sources->item(i);
  2275. OBSSceneItem item = GetOBSRef<OBSSceneItem>(wItem);
  2276. obs_sceneitem_select(item, wItem->isSelected());
  2277. }
  2278. ignoreSelectionUpdate = false;
  2279. };
  2280. using updateItemSelection_t = decltype(updateItemSelection);
  2281. obs_scene_atomic_update(GetCurrentScene(),
  2282. [](void *data, obs_scene_t *)
  2283. {
  2284. (*static_cast<updateItemSelection_t*>(data))();
  2285. }, static_cast<void*>(&updateItemSelection));
  2286. }
  2287. void OBSBasic::EditSceneItemName()
  2288. {
  2289. QListWidgetItem *item = GetTopSelectedSourceItem();
  2290. Qt::ItemFlags flags = item->flags();
  2291. OBSSceneItem sceneItem= GetOBSRef<OBSSceneItem>(item);
  2292. obs_source_t *source = obs_sceneitem_get_source(sceneItem);
  2293. const char *name = obs_source_get_name(source);
  2294. item->setText(QT_UTF8(name));
  2295. item->setFlags(flags | Qt::ItemIsEditable);
  2296. ui->sources->removeItemWidget(item);
  2297. ui->sources->editItem(item);
  2298. item->setFlags(flags);
  2299. }
  2300. void OBSBasic::SetDeinterlacingMode()
  2301. {
  2302. QAction *action = reinterpret_cast<QAction*>(sender());
  2303. obs_deinterlace_mode mode =
  2304. (obs_deinterlace_mode)action->property("mode").toInt();
  2305. OBSSceneItem sceneItem = GetCurrentSceneItem();
  2306. obs_source_t *source = obs_sceneitem_get_source(sceneItem);
  2307. obs_source_set_deinterlace_mode(source, mode);
  2308. }
  2309. void OBSBasic::SetDeinterlacingOrder()
  2310. {
  2311. QAction *action = reinterpret_cast<QAction*>(sender());
  2312. obs_deinterlace_field_order order =
  2313. (obs_deinterlace_field_order)action->property("order").toInt();
  2314. OBSSceneItem sceneItem = GetCurrentSceneItem();
  2315. obs_source_t *source = obs_sceneitem_get_source(sceneItem);
  2316. obs_source_set_deinterlace_field_order(source, order);
  2317. }
  2318. QMenu *OBSBasic::AddDeinterlacingMenu(obs_source_t *source)
  2319. {
  2320. QMenu *menu = new QMenu(QTStr("Deinterlacing"));
  2321. obs_deinterlace_mode deinterlaceMode =
  2322. obs_source_get_deinterlace_mode(source);
  2323. obs_deinterlace_field_order deinterlaceOrder =
  2324. obs_source_get_deinterlace_field_order(source);
  2325. QAction *action;
  2326. #define ADD_MODE(name, mode) \
  2327. action = menu->addAction(QTStr("" name), this, \
  2328. SLOT(SetDeinterlacingMode())); \
  2329. action->setProperty("mode", (int)mode); \
  2330. action->setCheckable(true); \
  2331. action->setChecked(deinterlaceMode == mode);
  2332. ADD_MODE("Disable", OBS_DEINTERLACE_MODE_DISABLE);
  2333. ADD_MODE("Deinterlacing.Discard", OBS_DEINTERLACE_MODE_DISCARD);
  2334. ADD_MODE("Deinterlacing.Retro", OBS_DEINTERLACE_MODE_RETRO);
  2335. ADD_MODE("Deinterlacing.Blend", OBS_DEINTERLACE_MODE_BLEND);
  2336. ADD_MODE("Deinterlacing.Blend2x", OBS_DEINTERLACE_MODE_BLEND_2X);
  2337. ADD_MODE("Deinterlacing.Linear", OBS_DEINTERLACE_MODE_LINEAR);
  2338. ADD_MODE("Deinterlacing.Linear2x", OBS_DEINTERLACE_MODE_LINEAR_2X);
  2339. ADD_MODE("Deinterlacing.Yadif", OBS_DEINTERLACE_MODE_YADIF);
  2340. ADD_MODE("Deinterlacing.Yadif2x", OBS_DEINTERLACE_MODE_YADIF_2X);
  2341. #undef ADD_MODE
  2342. menu->addSeparator();
  2343. #define ADD_ORDER(name, order) \
  2344. action = menu->addAction(QTStr("Deinterlacing." name), this, \
  2345. SLOT(SetDeinterlacingOrder())); \
  2346. action->setProperty("order", (int)order); \
  2347. action->setCheckable(true); \
  2348. action->setChecked(deinterlaceOrder == order);
  2349. ADD_ORDER("TopFieldFirst", OBS_DEINTERLACE_FIELD_ORDER_TOP);
  2350. ADD_ORDER("BottomFieldFirst", OBS_DEINTERLACE_FIELD_ORDER_BOTTOM);
  2351. #undef ADD_ORDER
  2352. return menu;
  2353. }
  2354. void OBSBasic::SetScaleFilter()
  2355. {
  2356. QAction *action = reinterpret_cast<QAction*>(sender());
  2357. obs_scale_type mode = (obs_scale_type)action->property("mode").toInt();
  2358. OBSSceneItem sceneItem = GetCurrentSceneItem();
  2359. obs_sceneitem_set_scale_filter(sceneItem, mode);
  2360. }
  2361. QMenu *OBSBasic::AddScaleFilteringMenu(obs_sceneitem_t *item)
  2362. {
  2363. QMenu *menu = new QMenu(QTStr("ScaleFiltering"));
  2364. obs_scale_type scaleFilter = obs_sceneitem_get_scale_filter(item);
  2365. QAction *action;
  2366. #define ADD_MODE(name, mode) \
  2367. action = menu->addAction(QTStr("" name), this, \
  2368. SLOT(SetScaleFilter())); \
  2369. action->setProperty("mode", (int)mode); \
  2370. action->setCheckable(true); \
  2371. action->setChecked(scaleFilter == mode);
  2372. ADD_MODE("Disable", OBS_SCALE_DISABLE);
  2373. ADD_MODE("ScaleFiltering.Point", OBS_SCALE_POINT);
  2374. ADD_MODE("ScaleFiltering.Bilinear", OBS_SCALE_BILINEAR);
  2375. ADD_MODE("ScaleFiltering.Bicubic", OBS_SCALE_BICUBIC);
  2376. ADD_MODE("ScaleFiltering.Lanczos", OBS_SCALE_LANCZOS);
  2377. #undef ADD_MODE
  2378. return menu;
  2379. }
  2380. void OBSBasic::CreateSourcePopupMenu(QListWidgetItem *item, bool preview)
  2381. {
  2382. QMenu popup(this);
  2383. QPointer<QMenu> previewProjector;
  2384. QPointer<QMenu> sourceProjector;
  2385. if (preview) {
  2386. QAction *action = popup.addAction(
  2387. QTStr("Basic.Main.PreviewConextMenu.Enable"),
  2388. this, SLOT(TogglePreview()));
  2389. action->setCheckable(true);
  2390. action->setChecked(
  2391. obs_display_enabled(ui->preview->GetDisplay()));
  2392. if (IsPreviewProgramMode())
  2393. action->setEnabled(false);
  2394. previewProjector = new QMenu(QTStr("PreviewProjector"));
  2395. AddProjectorMenuMonitors(previewProjector, this,
  2396. SLOT(OpenPreviewProjector()));
  2397. popup.addMenu(previewProjector);
  2398. popup.addSeparator();
  2399. }
  2400. QPointer<QMenu> addSourceMenu = CreateAddSourcePopupMenu();
  2401. if (addSourceMenu)
  2402. popup.addMenu(addSourceMenu);
  2403. if (item) {
  2404. if (addSourceMenu)
  2405. popup.addSeparator();
  2406. OBSSceneItem sceneItem = GetSceneItem(item);
  2407. obs_source_t *source = obs_sceneitem_get_source(sceneItem);
  2408. uint32_t flags = obs_source_get_output_flags(source);
  2409. bool isAsyncVideo = (flags & OBS_SOURCE_ASYNC_VIDEO) ==
  2410. OBS_SOURCE_ASYNC_VIDEO;
  2411. QAction *action;
  2412. popup.addAction(QTStr("Rename"), this,
  2413. SLOT(EditSceneItemName()));
  2414. popup.addAction(QTStr("Remove"), this,
  2415. SLOT(on_actionRemoveSource_triggered()),
  2416. DeleteKeys.front());
  2417. popup.addSeparator();
  2418. popup.addMenu(ui->orderMenu);
  2419. popup.addMenu(ui->transformMenu);
  2420. sourceProjector = new QMenu(QTStr("SourceProjector"));
  2421. AddProjectorMenuMonitors(sourceProjector, this,
  2422. SLOT(OpenSourceProjector()));
  2423. popup.addSeparator();
  2424. if (isAsyncVideo) {
  2425. popup.addMenu(AddDeinterlacingMenu(source));
  2426. popup.addSeparator();
  2427. }
  2428. popup.addMenu(AddScaleFilteringMenu(sceneItem));
  2429. popup.addSeparator();
  2430. popup.addMenu(sourceProjector);
  2431. popup.addSeparator();
  2432. action = popup.addAction(QTStr("Interact"), this,
  2433. SLOT(on_actionInteract_triggered()));
  2434. action->setEnabled(obs_source_get_output_flags(source) &
  2435. OBS_SOURCE_INTERACTION);
  2436. popup.addAction(QTStr("Filters"), this,
  2437. SLOT(OpenFilters()));
  2438. popup.addAction(QTStr("Properties"), this,
  2439. SLOT(on_actionSourceProperties_triggered()));
  2440. }
  2441. popup.exec(QCursor::pos());
  2442. }
  2443. void OBSBasic::on_sources_customContextMenuRequested(const QPoint &pos)
  2444. {
  2445. if (ui->scenes->count())
  2446. CreateSourcePopupMenu(ui->sources->itemAt(pos), false);
  2447. }
  2448. void OBSBasic::on_sources_itemDoubleClicked(QListWidgetItem *witem)
  2449. {
  2450. if (!witem)
  2451. return;
  2452. OBSSceneItem item = GetSceneItem(witem);
  2453. OBSSource source = obs_sceneitem_get_source(item);
  2454. if (source)
  2455. CreatePropertiesWindow(source);
  2456. }
  2457. void OBSBasic::AddSource(const char *id)
  2458. {
  2459. if (id && *id) {
  2460. OBSBasicSourceSelect sourceSelect(this, id);
  2461. sourceSelect.exec();
  2462. if (sourceSelect.newSource)
  2463. CreatePropertiesWindow(sourceSelect.newSource);
  2464. }
  2465. }
  2466. QMenu *OBSBasic::CreateAddSourcePopupMenu()
  2467. {
  2468. const char *type;
  2469. bool foundValues = false;
  2470. size_t idx = 0;
  2471. QMenu *popup = new QMenu(QTStr("Add"), this);
  2472. auto addSource = [this, popup] (const char *type, const char *name) {
  2473. QAction *popupItem = new QAction(QT_UTF8(name), this);
  2474. popupItem->setData(QT_UTF8(type));
  2475. connect(popupItem, SIGNAL(triggered(bool)),
  2476. this, SLOT(AddSourceFromAction()));
  2477. popup->addAction(popupItem);
  2478. };
  2479. while (obs_enum_input_types(idx++, &type)) {
  2480. const char *name = obs_source_get_display_name(type);
  2481. addSource(type, name);
  2482. foundValues = true;
  2483. }
  2484. addSource("scene", Str("Basic.Scene"));
  2485. if (!foundValues) {
  2486. delete popup;
  2487. popup = nullptr;
  2488. }
  2489. return popup;
  2490. }
  2491. void OBSBasic::AddSourceFromAction()
  2492. {
  2493. QAction *action = qobject_cast<QAction*>(sender());
  2494. if (!action)
  2495. return;
  2496. AddSource(QT_TO_UTF8(action->data().toString()));
  2497. }
  2498. void OBSBasic::AddSourcePopupMenu(const QPoint &pos)
  2499. {
  2500. if (!GetCurrentScene()) {
  2501. // Tell the user he needs a scene first (help beginners).
  2502. QMessageBox::information(this,
  2503. QTStr("Basic.Main.AddSourceHelp.Title"),
  2504. QTStr("Basic.Main.AddSourceHelp.Text"));
  2505. return;
  2506. }
  2507. QPointer<QMenu> popup = CreateAddSourcePopupMenu();
  2508. if (popup)
  2509. popup->exec(pos);
  2510. }
  2511. void OBSBasic::on_actionAddSource_triggered()
  2512. {
  2513. AddSourcePopupMenu(QCursor::pos());
  2514. }
  2515. void OBSBasic::on_actionRemoveSource_triggered()
  2516. {
  2517. vector<OBSSceneItem> items;
  2518. auto func = [] (obs_scene_t *, obs_sceneitem_t *item, void *param)
  2519. {
  2520. vector<OBSSceneItem> &items =
  2521. *reinterpret_cast<vector<OBSSceneItem>*>(param);
  2522. if (obs_sceneitem_selected(item))
  2523. items.emplace_back(item);
  2524. return true;
  2525. };
  2526. obs_scene_enum_items(GetCurrentScene(), func, &items);
  2527. if (!items.size())
  2528. return;
  2529. auto removeMultiple = [this] (size_t count)
  2530. {
  2531. QString text = QTStr("ConfirmRemove.TextMultiple")
  2532. .arg(QString::number(count));
  2533. QMessageBox remove_items(this);
  2534. remove_items.setText(text);
  2535. QAbstractButton *Yes = remove_items.addButton(QTStr("Yes"),
  2536. QMessageBox::YesRole);
  2537. remove_items.addButton(QTStr("No"), QMessageBox::NoRole);
  2538. remove_items.setIcon(QMessageBox::Question);
  2539. remove_items.setWindowTitle(QTStr("ConfirmRemove.Title"));
  2540. remove_items.exec();
  2541. return Yes == remove_items.clickedButton();
  2542. };
  2543. if (items.size() == 1) {
  2544. OBSSceneItem &item = items[0];
  2545. obs_source_t *source = obs_sceneitem_get_source(item);
  2546. if (source && QueryRemoveSource(source))
  2547. obs_sceneitem_remove(item);
  2548. } else {
  2549. if (removeMultiple(items.size())) {
  2550. for (auto &item : items)
  2551. obs_sceneitem_remove(item);
  2552. }
  2553. }
  2554. }
  2555. void OBSBasic::on_actionInteract_triggered()
  2556. {
  2557. OBSSceneItem item = GetCurrentSceneItem();
  2558. OBSSource source = obs_sceneitem_get_source(item);
  2559. if (source)
  2560. CreateInteractionWindow(source);
  2561. }
  2562. void OBSBasic::on_actionSourceProperties_triggered()
  2563. {
  2564. OBSSceneItem item = GetCurrentSceneItem();
  2565. OBSSource source = obs_sceneitem_get_source(item);
  2566. if (source)
  2567. CreatePropertiesWindow(source);
  2568. }
  2569. void OBSBasic::on_actionSourceUp_triggered()
  2570. {
  2571. OBSSceneItem item = GetCurrentSceneItem();
  2572. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_UP);
  2573. }
  2574. void OBSBasic::on_actionSourceDown_triggered()
  2575. {
  2576. OBSSceneItem item = GetCurrentSceneItem();
  2577. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_DOWN);
  2578. }
  2579. void OBSBasic::on_actionMoveUp_triggered()
  2580. {
  2581. OBSSceneItem item = GetCurrentSceneItem();
  2582. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_UP);
  2583. }
  2584. void OBSBasic::on_actionMoveDown_triggered()
  2585. {
  2586. OBSSceneItem item = GetCurrentSceneItem();
  2587. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_DOWN);
  2588. }
  2589. void OBSBasic::on_actionMoveToTop_triggered()
  2590. {
  2591. OBSSceneItem item = GetCurrentSceneItem();
  2592. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_TOP);
  2593. }
  2594. void OBSBasic::on_actionMoveToBottom_triggered()
  2595. {
  2596. OBSSceneItem item = GetCurrentSceneItem();
  2597. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_BOTTOM);
  2598. }
  2599. static BPtr<char> ReadLogFile(const char *log)
  2600. {
  2601. char logDir[512];
  2602. if (GetConfigPath(logDir, sizeof(logDir), "obs-studio/logs") <= 0)
  2603. return nullptr;
  2604. string path = (char*)logDir;
  2605. path += "/";
  2606. path += log;
  2607. BPtr<char> file = os_quick_read_utf8_file(path.c_str());
  2608. if (!file)
  2609. blog(LOG_WARNING, "Failed to read log file %s", path.c_str());
  2610. return file;
  2611. }
  2612. void OBSBasic::UploadLog(const char *file)
  2613. {
  2614. BPtr<char> fileString{ReadLogFile(file)};
  2615. if (!fileString)
  2616. return;
  2617. if (!*fileString)
  2618. return;
  2619. ui->menuLogFiles->setEnabled(false);
  2620. auto data_deleter = [](obs_data_t *d) { obs_data_release(d); };
  2621. using data_t = unique_ptr<struct obs_data, decltype(data_deleter)>;
  2622. data_t content{obs_data_create(), data_deleter};
  2623. data_t files{obs_data_create(), data_deleter};
  2624. data_t request{obs_data_create(), data_deleter};
  2625. obs_data_set_string(content.get(), "content", fileString);
  2626. obs_data_set_obj(files.get(), file, content.get());
  2627. stringstream ss;
  2628. ss << "OBS " << App()->GetVersionString()
  2629. << " log file uploaded at " << CurrentDateTimeString();
  2630. obs_data_set_string(request.get(), "description", ss.str().c_str());
  2631. obs_data_set_bool(request.get(), "public", false);
  2632. obs_data_set_obj(request.get(), "files", files.get());
  2633. const char *json = obs_data_get_json(request.get());
  2634. if (!json) {
  2635. blog(LOG_ERROR, "Failed to get JSON data for log upload");
  2636. return;
  2637. }
  2638. QBuffer *postData = new QBuffer();
  2639. postData->setData(json, (int) strlen(json));
  2640. if (logUploadThread) {
  2641. logUploadThread->wait();
  2642. delete logUploadThread;
  2643. }
  2644. RemoteTextThread *thread = new RemoteTextThread(
  2645. "https://api.github.com/gists",
  2646. "application/json", json);
  2647. logUploadThread = thread;
  2648. connect(thread, &RemoteTextThread::Result,
  2649. this, &OBSBasic::logUploadFinished);
  2650. logUploadThread->start();
  2651. }
  2652. void OBSBasic::on_actionShowLogs_triggered()
  2653. {
  2654. char logDir[512];
  2655. if (GetConfigPath(logDir, sizeof(logDir), "obs-studio/logs") <= 0)
  2656. return;
  2657. QUrl url = QUrl::fromLocalFile(QT_UTF8(logDir));
  2658. QDesktopServices::openUrl(url);
  2659. }
  2660. void OBSBasic::on_actionUploadCurrentLog_triggered()
  2661. {
  2662. UploadLog(App()->GetCurrentLog());
  2663. }
  2664. void OBSBasic::on_actionUploadLastLog_triggered()
  2665. {
  2666. UploadLog(App()->GetLastLog());
  2667. }
  2668. void OBSBasic::on_actionViewCurrentLog_triggered()
  2669. {
  2670. char logDir[512];
  2671. if (GetConfigPath(logDir, sizeof(logDir), "obs-studio/logs") <= 0)
  2672. return;
  2673. const char* log = App()->GetCurrentLog();
  2674. string path = (char*)logDir;
  2675. path += "/";
  2676. path += log;
  2677. QUrl url = QUrl::fromLocalFile(QT_UTF8(path.c_str()));
  2678. QDesktopServices::openUrl(url);
  2679. }
  2680. void OBSBasic::on_actionCheckForUpdates_triggered()
  2681. {
  2682. CheckForUpdates();
  2683. }
  2684. void OBSBasic::logUploadFinished(const QString &text, const QString &error)
  2685. {
  2686. ui->menuLogFiles->setEnabled(true);
  2687. if (text.isEmpty()) {
  2688. QMessageBox::information(this,
  2689. QTStr("LogReturnDialog.ErrorUploadingLog"),
  2690. error);
  2691. return;
  2692. }
  2693. obs_data_t *returnData = obs_data_create_from_json(QT_TO_UTF8(text));
  2694. QString logURL = obs_data_get_string(returnData, "html_url");
  2695. obs_data_release(returnData);
  2696. OBSLogReply logDialog(this, logURL);
  2697. logDialog.exec();
  2698. }
  2699. static void RenameListItem(OBSBasic *parent, QListWidget *listWidget,
  2700. obs_source_t *source, const string &name)
  2701. {
  2702. const char *prevName = obs_source_get_name(source);
  2703. if (name == prevName)
  2704. return;
  2705. obs_source_t *foundSource = obs_get_source_by_name(name.c_str());
  2706. QListWidgetItem *listItem = listWidget->currentItem();
  2707. if (foundSource || name.empty()) {
  2708. listItem->setText(QT_UTF8(prevName));
  2709. if (foundSource) {
  2710. QMessageBox::information(parent,
  2711. QTStr("NameExists.Title"),
  2712. QTStr("NameExists.Text"));
  2713. } else if (name.empty()) {
  2714. QMessageBox::information(parent,
  2715. QTStr("NoNameEntered.Title"),
  2716. QTStr("NoNameEntered.Text"));
  2717. }
  2718. obs_source_release(foundSource);
  2719. } else {
  2720. listItem->setText(QT_UTF8(name.c_str()));
  2721. obs_source_set_name(source, name.c_str());
  2722. }
  2723. }
  2724. void OBSBasic::SceneNameEdited(QWidget *editor,
  2725. QAbstractItemDelegate::EndEditHint endHint)
  2726. {
  2727. OBSScene scene = GetCurrentScene();
  2728. QLineEdit *edit = qobject_cast<QLineEdit*>(editor);
  2729. string text = QT_TO_UTF8(edit->text().trimmed());
  2730. if (!scene)
  2731. return;
  2732. obs_source_t *source = obs_scene_get_source(scene);
  2733. RenameListItem(this, ui->scenes, source, text);
  2734. UNUSED_PARAMETER(endHint);
  2735. }
  2736. void OBSBasic::SceneItemNameEdited(QWidget *editor,
  2737. QAbstractItemDelegate::EndEditHint endHint)
  2738. {
  2739. OBSSceneItem item = GetCurrentSceneItem();
  2740. QLineEdit *edit = qobject_cast<QLineEdit*>(editor);
  2741. string text = QT_TO_UTF8(edit->text().trimmed());
  2742. if (!item)
  2743. return;
  2744. obs_source_t *source = obs_sceneitem_get_source(item);
  2745. RenameListItem(this, ui->sources, source, text);
  2746. QListWidgetItem *listItem = ui->sources->currentItem();
  2747. listItem->setText(QString());
  2748. SetupVisibilityItem(ui->sources, listItem, item);
  2749. UNUSED_PARAMETER(endHint);
  2750. }
  2751. void OBSBasic::OpenFilters()
  2752. {
  2753. OBSSceneItem item = GetCurrentSceneItem();
  2754. OBSSource source = obs_sceneitem_get_source(item);
  2755. CreateFiltersWindow(source);
  2756. }
  2757. void OBSBasic::OpenSceneFilters()
  2758. {
  2759. OBSScene scene = GetCurrentScene();
  2760. OBSSource source = obs_scene_get_source(scene);
  2761. CreateFiltersWindow(source);
  2762. }
  2763. #define RECORDING_START \
  2764. "==== Recording Start ==============================================="
  2765. #define RECORDING_STOP \
  2766. "==== Recording Stop ================================================"
  2767. #define STREAMING_START \
  2768. "==== Streaming Start ==============================================="
  2769. #define STREAMING_STOP \
  2770. "==== Streaming Stop ================================================"
  2771. void OBSBasic::StartStreaming()
  2772. {
  2773. SaveProject();
  2774. ui->streamButton->setEnabled(false);
  2775. ui->streamButton->setText(QTStr("Basic.Main.Connecting"));
  2776. if (!outputHandler->StartStreaming(service)) {
  2777. ui->streamButton->setText(QTStr("Basic.Main.StartStreaming"));
  2778. ui->streamButton->setEnabled(true);
  2779. }
  2780. bool recordWhenStreaming = config_get_bool(GetGlobalConfig(),
  2781. "BasicWindow", "RecordWhenStreaming");
  2782. if (recordWhenStreaming)
  2783. StartRecording();
  2784. }
  2785. #ifdef _WIN32
  2786. static inline void UpdateProcessPriority()
  2787. {
  2788. const char *priority = config_get_string(App()->GlobalConfig(),
  2789. "General", "ProcessPriority");
  2790. if (priority && strcmp(priority, "Normal") != 0)
  2791. SetProcessPriority(priority);
  2792. }
  2793. static inline void ClearProcessPriority()
  2794. {
  2795. const char *priority = config_get_string(App()->GlobalConfig(),
  2796. "General", "ProcessPriority");
  2797. if (priority && strcmp(priority, "Normal") != 0)
  2798. SetProcessPriority("Normal");
  2799. }
  2800. #else
  2801. #define UpdateProcessPriority() do {} while(false)
  2802. #define ClearProcessPriority() do {} while(false)
  2803. #endif
  2804. void OBSBasic::StopStreaming()
  2805. {
  2806. SaveProject();
  2807. if (outputHandler->StreamingActive())
  2808. outputHandler->StopStreaming();
  2809. if (!outputHandler->Active() && !ui->profileMenu->isEnabled()) {
  2810. ui->profileMenu->setEnabled(true);
  2811. App()->DecrementSleepInhibition();
  2812. ClearProcessPriority();
  2813. }
  2814. bool recordWhenStreaming = config_get_bool(GetGlobalConfig(),
  2815. "BasicWindow", "RecordWhenStreaming");
  2816. bool keepRecordingWhenStreamStops = config_get_bool(GetGlobalConfig(),
  2817. "BasicWindow", "KeepRecordingWhenStreamStops");
  2818. if (recordWhenStreaming && !keepRecordingWhenStreamStops)
  2819. StopRecording();
  2820. }
  2821. void OBSBasic::ForceStopStreaming()
  2822. {
  2823. SaveProject();
  2824. if (outputHandler->StreamingActive())
  2825. outputHandler->ForceStopStreaming();
  2826. if (!outputHandler->Active() && !ui->profileMenu->isEnabled()) {
  2827. ui->profileMenu->setEnabled(true);
  2828. App()->DecrementSleepInhibition();
  2829. ClearProcessPriority();
  2830. }
  2831. bool recordWhenStreaming = config_get_bool(GetGlobalConfig(),
  2832. "BasicWindow", "RecordWhenStreaming");
  2833. bool keepRecordingWhenStreamStops = config_get_bool(GetGlobalConfig(),
  2834. "BasicWindow", "KeepRecordingWhenStreamStops");
  2835. if (recordWhenStreaming && !keepRecordingWhenStreamStops)
  2836. StopRecording();
  2837. }
  2838. void OBSBasic::StreamDelayStarting(int sec)
  2839. {
  2840. ui->streamButton->setText(QTStr("Basic.Main.StopStreaming"));
  2841. ui->streamButton->setEnabled(true);
  2842. if (!startStreamMenu.isNull())
  2843. startStreamMenu->deleteLater();
  2844. startStreamMenu = new QMenu();
  2845. startStreamMenu->addAction(QTStr("Basic.Main.StopStreaming"),
  2846. this, SLOT(StopStreaming()));
  2847. startStreamMenu->addAction(QTStr("Basic.Main.ForceStopStreaming"),
  2848. this, SLOT(ForceStopStreaming()));
  2849. ui->streamButton->setMenu(startStreamMenu);
  2850. ui->statusbar->StreamDelayStarting(sec);
  2851. if (ui->profileMenu->isEnabled()) {
  2852. ui->profileMenu->setEnabled(false);
  2853. App()->IncrementSleepInhibition();
  2854. UpdateProcessPriority();
  2855. }
  2856. }
  2857. void OBSBasic::StreamDelayStopping(int sec)
  2858. {
  2859. ui->streamButton->setText(QTStr("Basic.Main.StartStreaming"));
  2860. ui->streamButton->setEnabled(true);
  2861. if (!startStreamMenu.isNull())
  2862. startStreamMenu->deleteLater();
  2863. startStreamMenu = new QMenu();
  2864. startStreamMenu->addAction(QTStr("Basic.Main.StartStreaming"),
  2865. this, SLOT(StartStreaming()));
  2866. startStreamMenu->addAction(QTStr("Basic.Main.ForceStopStreaming"),
  2867. this, SLOT(ForceStopStreaming()));
  2868. ui->streamButton->setMenu(startStreamMenu);
  2869. ui->statusbar->StreamDelayStopping(sec);
  2870. }
  2871. void OBSBasic::StreamingStart()
  2872. {
  2873. ui->streamButton->setText(QTStr("Basic.Main.StopStreaming"));
  2874. ui->streamButton->setEnabled(true);
  2875. ui->statusbar->StreamStarted(outputHandler->streamOutput);
  2876. if (ui->profileMenu->isEnabled()) {
  2877. ui->profileMenu->setEnabled(false);
  2878. App()->IncrementSleepInhibition();
  2879. UpdateProcessPriority();
  2880. }
  2881. blog(LOG_INFO, STREAMING_START);
  2882. }
  2883. void OBSBasic::StreamStopping()
  2884. {
  2885. ui->streamButton->setText(QTStr("Basic.Main.StoppingStreaming"));
  2886. }
  2887. void OBSBasic::StreamingStop(int code)
  2888. {
  2889. const char *errorMessage;
  2890. switch (code) {
  2891. case OBS_OUTPUT_BAD_PATH:
  2892. errorMessage = Str("Output.ConnectFail.BadPath");
  2893. break;
  2894. case OBS_OUTPUT_CONNECT_FAILED:
  2895. errorMessage = Str("Output.ConnectFail.ConnectFailed");
  2896. break;
  2897. case OBS_OUTPUT_INVALID_STREAM:
  2898. errorMessage = Str("Output.ConnectFail.InvalidStream");
  2899. break;
  2900. default:
  2901. case OBS_OUTPUT_ERROR:
  2902. errorMessage = Str("Output.ConnectFail.Error");
  2903. break;
  2904. case OBS_OUTPUT_DISCONNECTED:
  2905. /* doesn't happen if output is set to reconnect. note that
  2906. * reconnects are handled in the output, not in the UI */
  2907. errorMessage = Str("Output.ConnectFail.Disconnected");
  2908. }
  2909. ui->statusbar->StreamStopped();
  2910. ui->streamButton->setText(QTStr("Basic.Main.StartStreaming"));
  2911. ui->streamButton->setEnabled(true);
  2912. if (!outputHandler->Active() && !ui->profileMenu->isEnabled()) {
  2913. ui->profileMenu->setEnabled(true);
  2914. App()->DecrementSleepInhibition();
  2915. ClearProcessPriority();
  2916. }
  2917. blog(LOG_INFO, STREAMING_STOP);
  2918. if (code != OBS_OUTPUT_SUCCESS)
  2919. QMessageBox::information(this,
  2920. QTStr("Output.ConnectFail.Title"),
  2921. QT_UTF8(errorMessage));
  2922. if (!startStreamMenu.isNull()) {
  2923. ui->streamButton->setMenu(nullptr);
  2924. startStreamMenu->deleteLater();
  2925. startStreamMenu = nullptr;
  2926. }
  2927. }
  2928. void OBSBasic::StartRecording()
  2929. {
  2930. if (outputHandler->RecordingActive())
  2931. return;
  2932. SaveProject();
  2933. outputHandler->StartRecording();
  2934. }
  2935. void OBSBasic::RecordStopping()
  2936. {
  2937. ui->recordButton->setText(QTStr("Basic.Main.StoppingRecording"));
  2938. }
  2939. void OBSBasic::StopRecording()
  2940. {
  2941. SaveProject();
  2942. if (outputHandler->RecordingActive())
  2943. outputHandler->StopRecording();
  2944. if (!outputHandler->Active() && !ui->profileMenu->isEnabled()) {
  2945. ui->profileMenu->setEnabled(true);
  2946. App()->DecrementSleepInhibition();
  2947. ClearProcessPriority();
  2948. }
  2949. }
  2950. void OBSBasic::RecordingStart()
  2951. {
  2952. ui->statusbar->RecordingStarted(outputHandler->fileOutput);
  2953. ui->recordButton->setText(QTStr("Basic.Main.StopRecording"));
  2954. if (ui->profileMenu->isEnabled()) {
  2955. ui->profileMenu->setEnabled(false);
  2956. App()->IncrementSleepInhibition();
  2957. UpdateProcessPriority();
  2958. }
  2959. blog(LOG_INFO, RECORDING_START);
  2960. }
  2961. void OBSBasic::RecordingStop(int code)
  2962. {
  2963. ui->statusbar->RecordingStopped();
  2964. ui->recordButton->setText(QTStr("Basic.Main.StartRecording"));
  2965. blog(LOG_INFO, RECORDING_STOP);
  2966. if (code == OBS_OUTPUT_UNSUPPORTED) {
  2967. QMessageBox::information(this,
  2968. QTStr("Output.RecordFail.Title"),
  2969. QTStr("Output.RecordFail.Unsupported"));
  2970. } else if (code == OBS_OUTPUT_NO_SPACE) {
  2971. QMessageBox::information(this,
  2972. QTStr("Output.RecordNoSpace.Title"),
  2973. QTStr("Output.RecordNoSpace.Msg"));
  2974. } else if (code != OBS_OUTPUT_SUCCESS) {
  2975. QMessageBox::information(this,
  2976. QTStr("Output.RecordError.Title"),
  2977. QTStr("Output.RecordError.Msg"));
  2978. }
  2979. if (!outputHandler->Active() && !ui->profileMenu->isEnabled()) {
  2980. ui->profileMenu->setEnabled(true);
  2981. App()->DecrementSleepInhibition();
  2982. ClearProcessPriority();
  2983. }
  2984. }
  2985. void OBSBasic::on_streamButton_clicked()
  2986. {
  2987. if (outputHandler->StreamingActive()) {
  2988. bool confirm = config_get_bool(GetGlobalConfig(), "BasicWindow",
  2989. "WarnBeforeStoppingStream");
  2990. if (confirm) {
  2991. QMessageBox::StandardButton button =
  2992. QMessageBox::question(this,
  2993. QTStr("ConfirmStop.Title"),
  2994. QTStr("ConfirmStop.Text"));
  2995. if (button == QMessageBox::No)
  2996. return;
  2997. }
  2998. StopStreaming();
  2999. } else {
  3000. bool confirm = config_get_bool(GetGlobalConfig(), "BasicWindow",
  3001. "WarnBeforeStartingStream");
  3002. if (confirm) {
  3003. QMessageBox::StandardButton button =
  3004. QMessageBox::question(this,
  3005. QTStr("ConfirmStart.Title"),
  3006. QTStr("ConfirmStart.Text"));
  3007. if (button == QMessageBox::No)
  3008. return;
  3009. }
  3010. StartStreaming();
  3011. }
  3012. }
  3013. void OBSBasic::on_recordButton_clicked()
  3014. {
  3015. if (outputHandler->RecordingActive())
  3016. StopRecording();
  3017. else
  3018. StartRecording();
  3019. }
  3020. void OBSBasic::on_settingsButton_clicked()
  3021. {
  3022. OBSBasicSettings settings(this);
  3023. settings.exec();
  3024. }
  3025. void OBSBasic::on_actionWebsite_triggered()
  3026. {
  3027. QUrl url = QUrl("https://obsproject.com", QUrl::TolerantMode);
  3028. QDesktopServices::openUrl(url);
  3029. }
  3030. void OBSBasic::on_actionShowSettingsFolder_triggered()
  3031. {
  3032. char path[512];
  3033. int ret = GetConfigPath(path, 512, "obs-studio");
  3034. if (ret <= 0)
  3035. return;
  3036. QDesktopServices::openUrl(QUrl::fromLocalFile(path));
  3037. }
  3038. void OBSBasic::on_actionShowProfileFolder_triggered()
  3039. {
  3040. char path[512];
  3041. int ret = GetProfilePath(path, 512, "");
  3042. if (ret <= 0)
  3043. return;
  3044. QDesktopServices::openUrl(QUrl::fromLocalFile(path));
  3045. }
  3046. QListWidgetItem *OBSBasic::GetTopSelectedSourceItem()
  3047. {
  3048. QList<QListWidgetItem*> selectedItems = ui->sources->selectedItems();
  3049. QListWidgetItem *topItem = nullptr;
  3050. if (selectedItems.size() != 0)
  3051. topItem = selectedItems[0];
  3052. return topItem;
  3053. }
  3054. void OBSBasic::on_preview_customContextMenuRequested(const QPoint &pos)
  3055. {
  3056. CreateSourcePopupMenu(GetTopSelectedSourceItem(), true);
  3057. UNUSED_PARAMETER(pos);
  3058. }
  3059. void OBSBasic::on_previewDisabledLabel_customContextMenuRequested(
  3060. const QPoint &pos)
  3061. {
  3062. QMenu popup(this);
  3063. QPointer<QMenu> previewProjector;
  3064. QAction *action = popup.addAction(
  3065. QTStr("Basic.Main.PreviewConextMenu.Enable"),
  3066. this, SLOT(TogglePreview()));
  3067. action->setCheckable(true);
  3068. action->setChecked(obs_display_enabled(ui->preview->GetDisplay()));
  3069. previewProjector = new QMenu(QTStr("PreviewProjector"));
  3070. AddProjectorMenuMonitors(previewProjector, this,
  3071. SLOT(OpenPreviewProjector()));
  3072. popup.addMenu(previewProjector);
  3073. popup.exec(QCursor::pos());
  3074. UNUSED_PARAMETER(pos);
  3075. }
  3076. void OBSBasic::on_actionAlwaysOnTop_triggered()
  3077. {
  3078. CloseDialogs();
  3079. /* Make sure all dialogs are safely and successfully closed before
  3080. * switching the always on top mode due to the fact that windows all
  3081. * have to be recreated, so queue the actual toggle to happen after
  3082. * all events related to closing the dialogs have finished */
  3083. QMetaObject::invokeMethod(this, "ToggleAlwaysOnTop",
  3084. Qt::QueuedConnection);
  3085. }
  3086. void OBSBasic::ToggleAlwaysOnTop()
  3087. {
  3088. bool isAlwaysOnTop = IsAlwaysOnTop(this);
  3089. ui->actionAlwaysOnTop->setChecked(!isAlwaysOnTop);
  3090. SetAlwaysOnTop(this, !isAlwaysOnTop);
  3091. show();
  3092. }
  3093. void OBSBasic::GetFPSCommon(uint32_t &num, uint32_t &den) const
  3094. {
  3095. const char *val = config_get_string(basicConfig, "Video", "FPSCommon");
  3096. if (strcmp(val, "10") == 0) {
  3097. num = 10;
  3098. den = 1;
  3099. } else if (strcmp(val, "20") == 0) {
  3100. num = 20;
  3101. den = 1;
  3102. } else if (strcmp(val, "25") == 0) {
  3103. num = 25;
  3104. den = 1;
  3105. } else if (strcmp(val, "29.97") == 0) {
  3106. num = 30000;
  3107. den = 1001;
  3108. } else if (strcmp(val, "48") == 0) {
  3109. num = 48;
  3110. den = 1;
  3111. } else if (strcmp(val, "59.94") == 0) {
  3112. num = 60000;
  3113. den = 1001;
  3114. } else if (strcmp(val, "60") == 0) {
  3115. num = 60;
  3116. den = 1;
  3117. } else {
  3118. num = 30;
  3119. den = 1;
  3120. }
  3121. }
  3122. void OBSBasic::GetFPSInteger(uint32_t &num, uint32_t &den) const
  3123. {
  3124. num = (uint32_t)config_get_uint(basicConfig, "Video", "FPSInt");
  3125. den = 1;
  3126. }
  3127. void OBSBasic::GetFPSFraction(uint32_t &num, uint32_t &den) const
  3128. {
  3129. num = (uint32_t)config_get_uint(basicConfig, "Video", "FPSNum");
  3130. den = (uint32_t)config_get_uint(basicConfig, "Video", "FPSDen");
  3131. }
  3132. void OBSBasic::GetFPSNanoseconds(uint32_t &num, uint32_t &den) const
  3133. {
  3134. num = 1000000000;
  3135. den = (uint32_t)config_get_uint(basicConfig, "Video", "FPSNS");
  3136. }
  3137. void OBSBasic::GetConfigFPS(uint32_t &num, uint32_t &den) const
  3138. {
  3139. uint32_t type = config_get_uint(basicConfig, "Video", "FPSType");
  3140. if (type == 1) //"Integer"
  3141. GetFPSInteger(num, den);
  3142. else if (type == 2) //"Fraction"
  3143. GetFPSFraction(num, den);
  3144. else if (false) //"Nanoseconds", currently not implemented
  3145. GetFPSNanoseconds(num, den);
  3146. else
  3147. GetFPSCommon(num, den);
  3148. }
  3149. config_t *OBSBasic::Config() const
  3150. {
  3151. return basicConfig;
  3152. }
  3153. void OBSBasic::on_actionEditTransform_triggered()
  3154. {
  3155. if (transformWindow)
  3156. transformWindow->close();
  3157. transformWindow = new OBSBasicTransform(this);
  3158. transformWindow->show();
  3159. transformWindow->setAttribute(Qt::WA_DeleteOnClose, true);
  3160. }
  3161. void OBSBasic::on_actionResetTransform_triggered()
  3162. {
  3163. auto func = [] (obs_scene_t *scene, obs_sceneitem_t *item, void *param)
  3164. {
  3165. if (!obs_sceneitem_selected(item))
  3166. return true;
  3167. obs_sceneitem_defer_update_begin(item);
  3168. obs_transform_info info;
  3169. vec2_set(&info.pos, 0.0f, 0.0f);
  3170. vec2_set(&info.scale, 1.0f, 1.0f);
  3171. info.rot = 0.0f;
  3172. info.alignment = OBS_ALIGN_TOP | OBS_ALIGN_LEFT;
  3173. info.bounds_type = OBS_BOUNDS_NONE;
  3174. info.bounds_alignment = OBS_ALIGN_CENTER;
  3175. vec2_set(&info.bounds, 0.0f, 0.0f);
  3176. obs_sceneitem_set_info(item, &info);
  3177. obs_sceneitem_crop crop = {};
  3178. obs_sceneitem_set_crop(item, &crop);
  3179. obs_sceneitem_defer_update_end(item);
  3180. UNUSED_PARAMETER(scene);
  3181. UNUSED_PARAMETER(param);
  3182. return true;
  3183. };
  3184. obs_scene_enum_items(GetCurrentScene(), func, nullptr);
  3185. }
  3186. static void GetItemBox(obs_sceneitem_t *item, vec3 &tl, vec3 &br)
  3187. {
  3188. matrix4 boxTransform;
  3189. obs_sceneitem_get_box_transform(item, &boxTransform);
  3190. vec3_set(&tl, M_INFINITE, M_INFINITE, 0.0f);
  3191. vec3_set(&br, -M_INFINITE, -M_INFINITE, 0.0f);
  3192. auto GetMinPos = [&] (float x, float y)
  3193. {
  3194. vec3 pos;
  3195. vec3_set(&pos, x, y, 0.0f);
  3196. vec3_transform(&pos, &pos, &boxTransform);
  3197. vec3_min(&tl, &tl, &pos);
  3198. vec3_max(&br, &br, &pos);
  3199. };
  3200. GetMinPos(0.0f, 0.0f);
  3201. GetMinPos(1.0f, 0.0f);
  3202. GetMinPos(0.0f, 1.0f);
  3203. GetMinPos(1.0f, 1.0f);
  3204. }
  3205. static vec3 GetItemTL(obs_sceneitem_t *item)
  3206. {
  3207. vec3 tl, br;
  3208. GetItemBox(item, tl, br);
  3209. return tl;
  3210. }
  3211. static void SetItemTL(obs_sceneitem_t *item, const vec3 &tl)
  3212. {
  3213. vec3 newTL;
  3214. vec2 pos;
  3215. obs_sceneitem_get_pos(item, &pos);
  3216. newTL = GetItemTL(item);
  3217. pos.x += tl.x - newTL.x;
  3218. pos.y += tl.y - newTL.y;
  3219. obs_sceneitem_set_pos(item, &pos);
  3220. }
  3221. static bool RotateSelectedSources(obs_scene_t *scene, obs_sceneitem_t *item,
  3222. void *param)
  3223. {
  3224. if (!obs_sceneitem_selected(item))
  3225. return true;
  3226. float rot = *reinterpret_cast<float*>(param);
  3227. vec3 tl = GetItemTL(item);
  3228. rot += obs_sceneitem_get_rot(item);
  3229. if (rot >= 360.0f) rot -= 360.0f;
  3230. else if (rot <= -360.0f) rot += 360.0f;
  3231. obs_sceneitem_set_rot(item, rot);
  3232. SetItemTL(item, tl);
  3233. UNUSED_PARAMETER(scene);
  3234. UNUSED_PARAMETER(param);
  3235. return true;
  3236. };
  3237. void OBSBasic::on_actionRotate90CW_triggered()
  3238. {
  3239. float f90CW = 90.0f;
  3240. obs_scene_enum_items(GetCurrentScene(), RotateSelectedSources, &f90CW);
  3241. }
  3242. void OBSBasic::on_actionRotate90CCW_triggered()
  3243. {
  3244. float f90CCW = -90.0f;
  3245. obs_scene_enum_items(GetCurrentScene(), RotateSelectedSources, &f90CCW);
  3246. }
  3247. void OBSBasic::on_actionRotate180_triggered()
  3248. {
  3249. float f180 = 180.0f;
  3250. obs_scene_enum_items(GetCurrentScene(), RotateSelectedSources, &f180);
  3251. }
  3252. static bool MultiplySelectedItemScale(obs_scene_t *scene, obs_sceneitem_t *item,
  3253. void *param)
  3254. {
  3255. vec2 &mul = *reinterpret_cast<vec2*>(param);
  3256. if (!obs_sceneitem_selected(item))
  3257. return true;
  3258. vec3 tl = GetItemTL(item);
  3259. vec2 scale;
  3260. obs_sceneitem_get_scale(item, &scale);
  3261. vec2_mul(&scale, &scale, &mul);
  3262. obs_sceneitem_set_scale(item, &scale);
  3263. SetItemTL(item, tl);
  3264. UNUSED_PARAMETER(scene);
  3265. return true;
  3266. }
  3267. void OBSBasic::on_actionFlipHorizontal_triggered()
  3268. {
  3269. vec2 scale;
  3270. vec2_set(&scale, -1.0f, 1.0f);
  3271. obs_scene_enum_items(GetCurrentScene(), MultiplySelectedItemScale,
  3272. &scale);
  3273. }
  3274. void OBSBasic::on_actionFlipVertical_triggered()
  3275. {
  3276. vec2 scale;
  3277. vec2_set(&scale, 1.0f, -1.0f);
  3278. obs_scene_enum_items(GetCurrentScene(), MultiplySelectedItemScale,
  3279. &scale);
  3280. }
  3281. static bool CenterAlignSelectedItems(obs_scene_t *scene, obs_sceneitem_t *item,
  3282. void *param)
  3283. {
  3284. obs_bounds_type boundsType = *reinterpret_cast<obs_bounds_type*>(param);
  3285. if (!obs_sceneitem_selected(item))
  3286. return true;
  3287. obs_video_info ovi;
  3288. obs_get_video_info(&ovi);
  3289. obs_transform_info itemInfo;
  3290. vec2_set(&itemInfo.pos, 0.0f, 0.0f);
  3291. vec2_set(&itemInfo.scale, 1.0f, 1.0f);
  3292. itemInfo.alignment = OBS_ALIGN_LEFT | OBS_ALIGN_TOP;
  3293. itemInfo.rot = 0.0f;
  3294. vec2_set(&itemInfo.bounds,
  3295. float(ovi.base_width), float(ovi.base_height));
  3296. itemInfo.bounds_type = boundsType;
  3297. itemInfo.bounds_alignment = OBS_ALIGN_CENTER;
  3298. obs_sceneitem_set_info(item, &itemInfo);
  3299. UNUSED_PARAMETER(scene);
  3300. return true;
  3301. }
  3302. void OBSBasic::on_actionFitToScreen_triggered()
  3303. {
  3304. obs_bounds_type boundsType = OBS_BOUNDS_SCALE_INNER;
  3305. obs_scene_enum_items(GetCurrentScene(), CenterAlignSelectedItems,
  3306. &boundsType);
  3307. }
  3308. void OBSBasic::on_actionStretchToScreen_triggered()
  3309. {
  3310. obs_bounds_type boundsType = OBS_BOUNDS_STRETCH;
  3311. obs_scene_enum_items(GetCurrentScene(), CenterAlignSelectedItems,
  3312. &boundsType);
  3313. }
  3314. void OBSBasic::on_actionCenterToScreen_triggered()
  3315. {
  3316. auto func = [] (obs_scene_t *scene, obs_sceneitem_t *item, void *param)
  3317. {
  3318. vec3 tl, br, itemCenter, screenCenter, offset;
  3319. obs_video_info ovi;
  3320. if (!obs_sceneitem_selected(item))
  3321. return true;
  3322. obs_get_video_info(&ovi);
  3323. vec3_set(&screenCenter, float(ovi.base_width),
  3324. float(ovi.base_height), 0.0f);
  3325. vec3_mulf(&screenCenter, &screenCenter, 0.5f);
  3326. GetItemBox(item, tl, br);
  3327. vec3_sub(&itemCenter, &br, &tl);
  3328. vec3_mulf(&itemCenter, &itemCenter, 0.5f);
  3329. vec3_add(&itemCenter, &itemCenter, &tl);
  3330. vec3_sub(&offset, &screenCenter, &itemCenter);
  3331. vec3_add(&tl, &tl, &offset);
  3332. SetItemTL(item, tl);
  3333. UNUSED_PARAMETER(scene);
  3334. UNUSED_PARAMETER(param);
  3335. return true;
  3336. };
  3337. obs_scene_enum_items(GetCurrentScene(), func, nullptr);
  3338. }
  3339. void OBSBasic::EnablePreviewDisplay(bool enable)
  3340. {
  3341. obs_display_set_enabled(ui->preview->GetDisplay(), enable);
  3342. ui->preview->setVisible(enable);
  3343. ui->previewDisabledLabel->setVisible(!enable);
  3344. }
  3345. void OBSBasic::TogglePreview()
  3346. {
  3347. previewEnabled = !previewEnabled;
  3348. EnablePreviewDisplay(previewEnabled);
  3349. }
  3350. void OBSBasic::Nudge(int dist, MoveDir dir)
  3351. {
  3352. struct MoveInfo {
  3353. float dist;
  3354. MoveDir dir;
  3355. } info = {(float)dist, dir};
  3356. auto func = [] (obs_scene_t*, obs_sceneitem_t *item, void *param)
  3357. {
  3358. MoveInfo *info = reinterpret_cast<MoveInfo*>(param);
  3359. struct vec2 dir;
  3360. struct vec2 pos;
  3361. vec2_set(&dir, 0.0f, 0.0f);
  3362. if (!obs_sceneitem_selected(item))
  3363. return true;
  3364. switch (info->dir) {
  3365. case MoveDir::Up: dir.y = -info->dist; break;
  3366. case MoveDir::Down: dir.y = info->dist; break;
  3367. case MoveDir::Left: dir.x = -info->dist; break;
  3368. case MoveDir::Right: dir.x = info->dist; break;
  3369. }
  3370. obs_sceneitem_get_pos(item, &pos);
  3371. vec2_add(&pos, &pos, &dir);
  3372. obs_sceneitem_set_pos(item, &pos);
  3373. return true;
  3374. };
  3375. obs_scene_enum_items(GetCurrentScene(), func, &info);
  3376. }
  3377. void OBSBasic::NudgeUp() {Nudge(1, MoveDir::Up);}
  3378. void OBSBasic::NudgeDown() {Nudge(1, MoveDir::Down);}
  3379. void OBSBasic::NudgeLeft() {Nudge(1, MoveDir::Left);}
  3380. void OBSBasic::NudgeRight() {Nudge(1, MoveDir::Right);}
  3381. void OBSBasic::OpenProjector(obs_source_t *source, int monitor)
  3382. {
  3383. /* seriously? 10 monitors? */
  3384. if (monitor > 9)
  3385. return;
  3386. delete projectors[monitor];
  3387. projectors[monitor].clear();
  3388. OBSProjector *projector = new OBSProjector(nullptr, source);
  3389. projector->Init(monitor);
  3390. projectors[monitor] = projector;
  3391. }
  3392. void OBSBasic::OpenPreviewProjector()
  3393. {
  3394. int monitor = sender()->property("monitor").toInt();
  3395. OpenProjector(nullptr, monitor);
  3396. }
  3397. void OBSBasic::OpenSourceProjector()
  3398. {
  3399. int monitor = sender()->property("monitor").toInt();
  3400. OBSSceneItem item = GetCurrentSceneItem();
  3401. if (!item)
  3402. return;
  3403. OpenProjector(obs_sceneitem_get_source(item), monitor);
  3404. }
  3405. void OBSBasic::OpenSceneProjector()
  3406. {
  3407. int monitor = sender()->property("monitor").toInt();
  3408. OBSScene scene = GetCurrentScene();
  3409. if (!scene)
  3410. return;
  3411. OpenProjector(obs_scene_get_source(scene), monitor);
  3412. }
  3413. void OBSBasic::UpdateTitleBar()
  3414. {
  3415. stringstream name;
  3416. const char *profile = config_get_string(App()->GlobalConfig(),
  3417. "Basic", "Profile");
  3418. const char *sceneCollection = config_get_string(App()->GlobalConfig(),
  3419. "Basic", "SceneCollection");
  3420. name << "OBS ";
  3421. if (previewProgramMode)
  3422. name << "Studio ";
  3423. name << App()->GetVersionString();
  3424. name << " - " << Str("TitleBar.Profile") << ": " << profile;
  3425. name << " - " << Str("TitleBar.Scenes") << ": " << sceneCollection;
  3426. setWindowTitle(QT_UTF8(name.str().c_str()));
  3427. }
  3428. int OBSBasic::GetProfilePath(char *path, size_t size, const char *file) const
  3429. {
  3430. char profiles_path[512];
  3431. const char *profile = config_get_string(App()->GlobalConfig(),
  3432. "Basic", "ProfileDir");
  3433. int ret;
  3434. if (!profile)
  3435. return -1;
  3436. if (!path)
  3437. return -1;
  3438. if (!file)
  3439. file = "";
  3440. ret = GetConfigPath(profiles_path, 512, "obs-studio/basic/profiles");
  3441. if (ret <= 0)
  3442. return ret;
  3443. if (!*file)
  3444. return snprintf(path, size, "%s/%s", profiles_path, profile);
  3445. return snprintf(path, size, "%s/%s/%s", profiles_path, profile, file);
  3446. }
  3447. void OBSBasic::on_toggleSceneTransitions_toggled(bool visible)
  3448. {
  3449. ui->sceneTransitionsLabel->setVisible(visible);
  3450. ui->transitionsContainer->setVisible(visible);
  3451. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  3452. "ShowTransitions", visible);
  3453. }
  3454. void OBSBasic::on_toggleListboxToolbars_toggled(bool visible)
  3455. {
  3456. ui->sourcesToolbar->setVisible(visible);
  3457. ui->scenesToolbar->setVisible(visible);
  3458. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  3459. "ShowListboxToolbars", visible);
  3460. }
  3461. void OBSBasic::on_toggleStatusBar_toggled(bool visible)
  3462. {
  3463. ui->statusbar->setVisible(visible);
  3464. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  3465. "ShowStatusBar", visible);
  3466. }