window-basic-main.cpp 110 KB

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