diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index 9e77a9f32..a227b3881 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -4412,24 +4412,7 @@ bool OBSBasic::ResetAudio() return obs_reset_audio(&ai); } -extern std::string strprintf(const char *format, ...); - -static std::string GetDupName(const char *name) -{ - std::string newName = name; - int inc = 1; - - for (;;) { - OBSSourceAutoRelease existing_source = - obs_get_source_by_name(newName.c_str()); - if (!existing_source) - break; - - newName = strprintf("%s (%d)", name, ++inc); - } - - return newName; -} +extern char *get_new_source_name(const char *name, const char *format); void OBSBasic::ResetAudioDevice(const char *sourceId, const char *deviceId, const char *deviceDesc, int channel) @@ -4454,12 +4437,11 @@ void OBSBasic::ResetAudioDevice(const char *sourceId, const char *deviceId, } } else if (!disable) { - std::string name = GetDupName(deviceDesc); + BPtr name = get_new_source_name(deviceDesc, "%s (%d)"); settings = obs_data_create(); obs_data_set_string(settings, "device_id", deviceId); - source = obs_source_create(sourceId, name.c_str(), settings, - nullptr); + source = obs_source_create(sourceId, name, settings, nullptr); obs_set_output_source(channel, source); } diff --git a/UI/window-basic-source-select.cpp b/UI/window-basic-source-select.cpp index f71e8bbdc..256b9992f 100644 --- a/UI/window-basic-source-select.cpp +++ b/UI/window-basic-source-select.cpp @@ -130,7 +130,7 @@ static void AddSource(void *_data, obs_scene_t *scene) obs_sceneitem_set_visible(sceneitem, data->visible); } -static char *get_new_source_name(const char *name) +char *get_new_source_name(const char *name, const char *format) { struct dstr new_name = {0}; int inc = 0; @@ -143,7 +143,7 @@ static char *get_new_source_name(const char *name) if (!existing_source) break; - dstr_printf(&new_name, "%s %d", name, ++inc + 1); + dstr_printf(&new_name, format, name, ++inc + 1); } return new_name.array; @@ -160,8 +160,8 @@ static void AddExisting(OBSSource source, bool visible, bool duplicate, if (duplicate) { OBSSource from = source; - char *new_name = - get_new_source_name(obs_source_get_name(source)); + char *new_name = get_new_source_name( + obs_source_get_name(source), "%s %d"); source = obs_source_duplicate(from, new_name, false); obs_source_release(source); bfree(new_name);