Skip to content

Commit

Permalink
frontend: Use OBSBasic::Get() in all places
Browse files Browse the repository at this point in the history
This reduces duplicated code when getting the OBSBasic context.
  • Loading branch information
cg2121 committed Feb 3, 2025
1 parent 3911f11 commit 32d547b
Show file tree
Hide file tree
Showing 25 changed files with 75 additions and 78 deletions.
6 changes: 3 additions & 3 deletions frontend/OBSApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@ bool OBSApp::notify(QObject *receiver, QEvent *e)

if (windowType == Qt::WindowType::Dialog || windowType == Qt::WindowType::Window ||
windowType == Qt::WindowType::Tool) {
OBSBasic *main = reinterpret_cast<OBSBasic *>(GetMainWindow());
OBSBasic *main = OBSBasic::Get();
if (main)
main->SetDisplayAffinity(window);
}
Expand Down Expand Up @@ -1355,7 +1355,7 @@ string GetFormatExt(const char *container)

string GetOutputFilename(const char *path, const char *container, bool noSpace, bool overwrite, const char *format)
{
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
OBSBasic *main = OBSBasic::Get();

os_dir_t *dir = path && path[0] ? os_opendir(path) : nullptr;

Expand Down Expand Up @@ -1558,7 +1558,7 @@ void OBSApp::ProcessSigInt(void)
char tmp;
recv(sigintFd[1], &tmp, sizeof(tmp), 0);

OBSBasic *main = reinterpret_cast<OBSBasic *>(GetMainWindow());
OBSBasic *main = OBSBasic::Get();
if (main)
main->close();
#endif
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/OBSAdvAudioCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ OBSAdvAudioCtrl::OBSAdvAudioCtrl(QGridLayout *, obs_source_t *source_) : source(
labelL->setText("L");
labelR->setText("R");

OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
OBSBasic *main = OBSBasic::Get();

QIcon sourceIcon = main->GetSourceIcon(obs_source_get_id(source));
QPixmap pixmap = sourceIcon.pixmap(QSize(16, 16));
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/SourceToolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void SourceToolbar::SetUndoProperties(obs_source_t *source, bool repeatable)
return;
}

OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
OBSBasic *main = OBSBasic::Get();

OBSSource currentSceneSource = main->GetCurrentSceneSource();
if (!currentSceneSource)
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/SourceTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

static inline OBSScene GetCurrentScene()
{
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
OBSBasic *main = OBSBasic::Get();
return main->GetCurrentScene();
}

Expand Down Expand Up @@ -560,7 +560,7 @@ bool SourceTree::GroupedItemsSelected() const

void SourceTree::Remove(OBSSceneItem item, OBSScene scene)
{
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
OBSBasic *main = OBSBasic::Get();
GetStm()->Remove(item);
main->SaveProject();

Expand Down
8 changes: 4 additions & 4 deletions frontend/components/SourceTreeItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

static inline OBSScene GetCurrentScene()
{
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
OBSBasic *main = OBSBasic::Get();
return main->GetCurrentScene();
}

Expand All @@ -40,7 +40,7 @@ SourceTreeItem::SourceTreeItem(SourceTree *tree_, OBSSceneItem sceneitem_) : tre
setStyleSheet("background: none");
}

OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
OBSBasic *main = OBSBasic::Get();
const char *id = obs_source_get_id(source);

bool sourceVisible = obs_sceneitem_visible(sceneitem);
Expand Down Expand Up @@ -268,7 +268,7 @@ void SourceTreeItem::mouseDoubleClickEvent(QMouseEvent *event)
expand->setChecked(!expand->isChecked());
} else {
obs_source_t *source = obs_sceneitem_get_source(sceneitem);
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
OBSBasic *main = OBSBasic::Get();
if (obs_source_configurable(source)) {
main->CreatePropertiesWindow(source);
}
Expand Down Expand Up @@ -337,7 +337,7 @@ void SourceTreeItem::ExitEditModeInternal(bool save)
return;
}

OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
OBSBasic *main = OBSBasic::Get();
OBSScene scene = main->GetCurrentScene();

newName = QT_TO_UTF8(editor->text());
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/SourceTreeModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

static inline OBSScene GetCurrentScene()
{
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
OBSBasic *main = OBSBasic::Get();
return main->GetCurrentScene();
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/dialogs/OBSBasicAdvAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ OBSBasicAdvAudio::OBSBasicAdvAudio(QWidget *parent) : QDialog(parent), ui(new Ui

OBSBasicAdvAudio::~OBSBasicAdvAudio()
{
OBSBasic *main = reinterpret_cast<OBSBasic *>(parent());
OBSBasic *main = OBSBasic::Get();

for (size_t i = 0; i < controls.size(); ++i)
delete controls[i];
Expand Down
25 changes: 11 additions & 14 deletions frontend/dialogs/OBSBasicFilters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ OBSBasicFilters::OBSBasicFilters(QWidget *parent, OBSSource source_)
renameSourceSignal(obs_source_get_signal_handler(source), "rename", OBSBasicFilters::SourceRenamed, this),
noPreviewMargin(13)
{
main = reinterpret_cast<OBSBasic *>(parent);
main = OBSBasic::Get();

setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);

Expand Down Expand Up @@ -248,7 +248,7 @@ void OBSBasicFilters::UpdatePropertiesView(int row, bool async)
OBSDataAutoRelease settings = obs_source_get_settings(filter);

auto disabled_undo = [](void *vp, obs_data_t *settings) {
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
OBSBasic *main = OBSBasic::Get();
main->undo_s.disable();
obs_source_t *source = reinterpret_cast<obs_source_t *>(vp);
obs_source_update(source, settings);
Expand Down Expand Up @@ -542,8 +542,7 @@ void OBSBasicFilters::AddNewFilter(const char *id)
}

std::string parent_uuid(obs_source_get_uuid(source));
std::string scene_uuid = obs_source_get_uuid(
reinterpret_cast<OBSBasic *>(App()->GetMainWindow())->GetCurrentSceneSource());
std::string scene_uuid = obs_source_get_uuid(OBSBasic::Get()->GetCurrentSceneSource());
/* In order to ensure that the UUID persists through undo/redo,
* we save the source data rather than just recreating the
* source from scratch. */
Expand All @@ -556,7 +555,7 @@ void OBSBasicFilters::AddNewFilter(const char *id)

auto undo = [scene_uuid](const std::string &data) {
OBSSourceAutoRelease ssource = obs_get_source_by_uuid(scene_uuid.c_str());
reinterpret_cast<OBSBasic *>(App()->GetMainWindow())->SetCurrentScene(ssource.Get(), true);
OBSBasic::Get()->SetCurrentScene(ssource.Get(), true);

OBSDataAutoRelease dat = obs_data_create_from_json(data.c_str());
OBSSourceAutoRelease source = obs_get_source_by_uuid(obs_data_get_string(dat, "suuid"));
Expand All @@ -567,7 +566,7 @@ void OBSBasicFilters::AddNewFilter(const char *id)

auto redo = [scene_uuid](const std::string &data) {
OBSSourceAutoRelease ssource = obs_get_source_by_uuid(scene_uuid.c_str());
reinterpret_cast<OBSBasic *>(App()->GetMainWindow())->SetCurrentScene(ssource.Get(), true);
OBSBasic::Get()->SetCurrentScene(ssource.Get(), true);

OBSDataAutoRelease dat = obs_data_create_from_json(data.c_str());
OBSSourceAutoRelease source = obs_get_source_by_uuid(obs_data_get_string(dat, "undo_uuid"));
Expand Down Expand Up @@ -971,19 +970,18 @@ void OBSBasicFilters::FilterNameEdited(QWidget *editor, QListWidget *list)
listItem->setText(QT_UTF8(name.c_str()));
obs_source_set_name(filter, name.c_str());

std::string scene_uuid = obs_source_get_uuid(
reinterpret_cast<OBSBasic *>(App()->GetMainWindow())->GetCurrentSceneSource());
std::string scene_uuid = obs_source_get_uuid(OBSBasic::Get()->GetCurrentSceneSource());
auto undo = [scene_uuid, prev = std::string(prevName), name](const std::string &uuid) {
OBSSourceAutoRelease ssource = obs_get_source_by_uuid(scene_uuid.c_str());
reinterpret_cast<OBSBasic *>(App()->GetMainWindow())->SetCurrentScene(ssource.Get(), true);
OBSBasic::Get()->SetCurrentScene(ssource.Get(), true);

OBSSourceAutoRelease filter = obs_get_source_by_uuid(uuid.c_str());
obs_source_set_name(filter, prev.c_str());
};

auto redo = [scene_uuid, prev = std::string(prevName), name](const std::string &uuid) {
OBSSourceAutoRelease ssource = obs_get_source_by_uuid(scene_uuid.c_str());
reinterpret_cast<OBSBasic *>(App()->GetMainWindow())->SetCurrentScene(ssource.Get(), true);
OBSBasic::Get()->SetCurrentScene(ssource.Get(), true);

OBSSourceAutoRelease filter = obs_get_source_by_uuid(uuid.c_str());
obs_source_set_name(filter, name.c_str());
Expand Down Expand Up @@ -1069,11 +1067,10 @@ void OBSBasicFilters::delete_filter(OBSSource filter)
std::string parent_uuid(obs_source_get_uuid(source));
obs_data_set_string(wrapper, "undo_uuid", parent_uuid.c_str());

std::string scene_uuid =
obs_source_get_uuid(reinterpret_cast<OBSBasic *>(App()->GetMainWindow())->GetCurrentSceneSource());
std::string scene_uuid = obs_source_get_uuid(OBSBasic::Get()->GetCurrentSceneSource());
auto undo = [scene_uuid](const std::string &data) {
OBSSourceAutoRelease ssource = obs_get_source_by_uuid(scene_uuid.c_str());
reinterpret_cast<OBSBasic *>(App()->GetMainWindow())->SetCurrentScene(ssource.Get(), true);
OBSBasic::Get()->SetCurrentScene(ssource.Get(), true);

OBSDataAutoRelease dat = obs_data_create_from_json(data.c_str());
OBSSourceAutoRelease source = obs_get_source_by_uuid(obs_data_get_string(dat, "undo_uuid"));
Expand All @@ -1086,7 +1083,7 @@ void OBSBasicFilters::delete_filter(OBSSource filter)
obs_data_set_string(rwrapper, "suuid", parent_uuid.c_str());
auto redo = [scene_uuid](const std::string &data) {
OBSSourceAutoRelease ssource = obs_get_source_by_uuid(scene_uuid.c_str());
reinterpret_cast<OBSBasic *>(App()->GetMainWindow())->SetCurrentScene(ssource.Get(), true);
OBSBasic::Get()->SetCurrentScene(ssource.Get(), true);

OBSDataAutoRelease dat = obs_data_create_from_json(data.c_str());
OBSSourceAutoRelease source = obs_get_source_by_uuid(obs_data_get_string(dat, "suuid"));
Expand Down
10 changes: 5 additions & 5 deletions frontend/dialogs/OBSBasicSourceSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ bool OBSBasicSourceSelect::EnumGroups(void *data, obs_source_t *source)
const char *id = obs_source_get_unversioned_id(source);

if (strcmp(id, window->id) == 0) {
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
OBSBasic *main = OBSBasic::Get();
OBSScene scene = main->GetCurrentScene();

obs_sceneitem_t *existing = obs_scene_get_group(scene, name);
Expand Down Expand Up @@ -152,7 +152,7 @@ char *get_new_source_name(const char *name, const char *format)
static void AddExisting(OBSSource source, bool visible, bool duplicate, obs_transform_info *transform,
obs_sceneitem_crop *crop, obs_blending_method *blend_method, obs_blending_type *blend_mode)
{
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
OBSBasic *main = OBSBasic::Get();
OBSScene scene = main->GetCurrentScene();
if (!scene)
return;
Expand Down Expand Up @@ -193,7 +193,7 @@ static void AddExisting(const char *name, bool visible, bool duplicate, obs_tran
bool AddNew(QWidget *parent, const char *id, const char *name, const bool visible, OBSSource &newSource,
OBSSceneItem &newSceneItem)
{
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
OBSBasic *main = OBSBasic::Get();
OBSScene scene = main->GetCurrentScene();
bool success = false;
if (!scene)
Expand Down Expand Up @@ -245,7 +245,7 @@ void OBSBasicSourceSelect::on_buttonBox_accepted()
QString source_name = item->text();
AddExisting(QT_TO_UTF8(source_name), visible, false, nullptr, nullptr, nullptr, nullptr);

OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
OBSBasic *main = OBSBasic::Get();
const char *scene_name = obs_source_get_name(main->GetCurrentSceneSource());

auto undo = [scene_name, main](const std::string &) {
Expand Down Expand Up @@ -377,7 +377,7 @@ OBSBasicSourceSelect::OBSBasicSourceSelect(OBSBasic *parent, const char *id_, un
});

if (strcmp(id_, "scene") == 0) {
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
OBSBasic *main = OBSBasic::Get();
OBSSource curSceneSource = main->GetCurrentSceneSource();

ui->selectExisting->setChecked(true);
Expand Down
2 changes: 1 addition & 1 deletion frontend/dialogs/OBSBasicTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ OBSBasicTransform::~OBSBasicTransform()
auto undo_redo = [](const std::string &data) {
OBSDataAutoRelease dat = obs_data_create_from_json(data.c_str());
OBSSourceAutoRelease source = obs_get_source_by_uuid(obs_data_get_string(dat, "scene_uuid"));
reinterpret_cast<OBSBasic *>(App()->GetMainWindow())->SetCurrentScene(source.Get(), true);
OBSBasic::Get()->SetCurrentScene(source.Get(), true);
obs_scene_load_transform_states(data.c_str());
};

Expand Down
2 changes: 1 addition & 1 deletion frontend/importer/OBSImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void OBSImporter::browseImport()

bool GetUnusedName(std::string &name)
{
OBSBasic *basic = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
OBSBasic *basic = OBSBasic::Get();

if (!basic->GetSceneCollectionByName(name)) {
return false;
Expand Down
4 changes: 2 additions & 2 deletions frontend/settings/OBSBasicSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1852,7 +1852,7 @@ OBSPropertiesView *OBSBasicSettings::CreateEncoderPropertyView(const char *encod
OBSPropertiesView *view;

if (path) {
const OBSBasic *basic = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
const OBSBasic *basic = OBSBasic::Get();
const OBSProfile &currentProfile = basic->GetCurrentProfile();

const std::filesystem::path jsonFilePath = currentProfile.path / std::filesystem::u8path(path);
Expand Down Expand Up @@ -3233,7 +3233,7 @@ static void WriteJsonData(OBSPropertiesView *view, const char *path)
if (!view || !WidgetChanged(view))
return;

const OBSBasic *basic = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
const OBSBasic *basic = OBSBasic::Get();
const OBSProfile &currentProfile = basic->GetCurrentProfile();

const std::filesystem::path jsonFilePath = currentProfile.path / std::filesystem::u8path(path);
Expand Down
2 changes: 1 addition & 1 deletion frontend/utility/AdvancedOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using namespace std;

static OBSData GetDataFromJsonFile(const char *jsonFile)
{
const OBSBasic *basic = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
const OBSBasic *basic = OBSBasic::Get();

const OBSProfile &currentProfile = basic->GetCurrentProfile();

Expand Down
2 changes: 1 addition & 1 deletion frontend/utility/MissingFilesModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ QVariant MissingFilesModel::data(const QModelIndex &index, int role) const
break;
}
} else if (role == Qt::DecorationRole && index.column() == MissingFilesColumn::Source) {
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
OBSBasic *main = OBSBasic::Get();
OBSSourceAutoRelease source = obs_get_source_by_name(files[index.row()].source.toStdString().c_str());

if (source) {
Expand Down
Loading

0 comments on commit 32d547b

Please sign in to comment.