From e42af67128355bf885ac0d647dfc9dd65c956720 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Sat, 2 Aug 2014 12:42:47 -0700 Subject: [PATCH] (API Change) Split obs_source_gettype Changed: - obs_source_gettype To: - enum obs_source_type obs_source_get_type(obs_source_t source); - const char *obs_source_get_id(obs_source_t source); This function was inconsistent for a number of reasons. First, it returns both the ID and the type of source (input/transition/filter), which is inconsistent with the name of "get type". Secondly, the 'squishy' naming convention which has just turned out to be bad practice and causes inconsistencies. So it's now replaced with two functions that just return the type and the ID. --- libobs/obs-source.c | 11 ++++++----- libobs/obs.c | 4 +--- libobs/obs.h | 8 +++++--- obs/window-basic-main.cpp | 3 --- obs/window-basic-source-select.cpp | 14 +++++--------- 5 files changed, 17 insertions(+), 23 deletions(-) diff --git a/libobs/obs-source.c b/libobs/obs-source.c index 0bbca81e..91d5f5c6 100644 --- a/libobs/obs-source.c +++ b/libobs/obs-source.c @@ -1640,13 +1640,14 @@ void obs_source_setname(obs_source_t source, const char *name) } } -void obs_source_gettype(obs_source_t source, enum obs_source_type *type, - const char **id) +enum obs_source_type obs_source_get_type(obs_source_t source) { - if (!source) return; + return source ? source->info.type : OBS_SOURCE_TYPE_INPUT; +} - if (type) *type = source->info.type; - if (id) *id = source->info.id; +const char *obs_source_get_id(obs_source_t source) +{ + return source ? source->info.id : NULL; } static inline void render_filter_bypass(obs_source_t target, effect_t effect, diff --git a/libobs/obs.c b/libobs/obs.c index d351f5f6..b7bd0d71 100644 --- a/libobs/obs.c +++ b/libobs/obs.c @@ -1204,12 +1204,10 @@ obs_data_t obs_save_source(obs_source_t source) obs_data_t settings = obs_source_getsettings(source); float volume = obs_source_getvolume(source); const char *name = obs_source_getname(source); - const char *id; + const char *id = obs_source_get_id(source); obs_source_save(source); - obs_source_gettype(source, NULL, &id); - obs_data_setstring(source_data, "name", name); obs_data_setstring(source_data, "id", id); obs_data_setobj (source_data, "settings", settings); diff --git a/libobs/obs.h b/libobs/obs.h index b90f881a..2138709f 100644 --- a/libobs/obs.h +++ b/libobs/obs.h @@ -646,9 +646,11 @@ EXPORT const char *obs_source_getname(obs_source_t source); /** Sets the name of a source */ EXPORT void obs_source_setname(obs_source_t source, const char *name); -/** Gets the source type and identifier */ -EXPORT void obs_source_gettype(obs_source_t source, enum obs_source_type *type, - const char **id); +/** Gets the source type */ +EXPORT enum obs_source_type obs_source_get_type(obs_source_t source); + +/** Gets the source identifier */ +EXPORT const char *obs_source_get_id(obs_source_t source); /** Returns the signal handler for a source */ EXPORT signal_handler_t obs_source_signalhandler(obs_source_t source); diff --git a/obs/window-basic-main.cpp b/obs/window-basic-main.cpp index c8c1d0a2..61b44c3e 100644 --- a/obs/window-basic-main.cpp +++ b/obs/window-basic-main.cpp @@ -738,9 +738,6 @@ void OBSBasic::RemoveSceneItem(OBSSceneItem item) void OBSBasic::UpdateSceneSelection(OBSSource source) { if (source) { - obs_source_type type; - obs_source_gettype(source, &type, NULL); - obs_scene_t scene = obs_scene_fromsource(source); const char *name = obs_source_getname(source); diff --git a/obs/window-basic-source-select.cpp b/obs/window-basic-source-select.cpp index 29d44f0b..70d68c3c 100644 --- a/obs/window-basic-source-select.cpp +++ b/obs/window-basic-source-select.cpp @@ -25,9 +25,7 @@ bool OBSBasicSourceSelect::EnumSources(void *data, obs_source_t source) { OBSBasicSourceSelect *window = static_cast(data); const char *name = obs_source_getname(source); - const char *id; - - obs_source_gettype(source, nullptr, &id); + const char *id = obs_source_get_id(source); if (strcmp(id, window->id) == 0) window->ui->sourceList->addItem(QT_UTF8(name)); @@ -55,10 +53,9 @@ void OBSBasicSourceSelect::OBSSourceRemoved(void *data, calldata_t calldata) void OBSBasicSourceSelect::SourceAdded(OBSSource source) { - const char *name = obs_source_getname(source); - const char *sourceId; + const char *name = obs_source_getname(source); + const char *sourceId = obs_source_get_id(source); - obs_source_gettype(source, nullptr, &sourceId); if (strcmp(sourceId, id) != 0) return; @@ -67,10 +64,9 @@ void OBSBasicSourceSelect::SourceAdded(OBSSource source) void OBSBasicSourceSelect::SourceRemoved(OBSSource source) { - const char *name = obs_source_getname(source); - const char *sourceId; + const char *name = obs_source_getname(source); + const char *sourceId = obs_source_get_id(source); - obs_source_gettype(source, nullptr, &sourceId); if (strcmp(sourceId, id) != 0) return; -- GitLab