From 3b16477480934fabc28e5b0c4d7b7fed0af21653 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Tue, 23 Jun 2015 18:47:22 -0700 Subject: [PATCH] UI: Store global audio sources in scenes file only Right now, information about global audio sources is stored in both scene files and in the config. These must be separated; there's no need to store them in both when they can just be stored in the scenes file. --- obs/window-basic-main.cpp | 81 +++++++++++++---------------------- obs/window-basic-main.hpp | 3 +- obs/window-basic-settings.cpp | 58 +++++++++++++++---------- obs/window-basic-settings.hpp | 3 +- 4 files changed, 67 insertions(+), 78 deletions(-) diff --git a/obs/window-basic-main.cpp b/obs/window-basic-main.cpp index 84639973f..004e57ea4 100644 --- a/obs/window-basic-main.cpp +++ b/obs/window-basic-main.cpp @@ -323,8 +323,30 @@ static void LoadAudioDevice(const char *name, int channel, obs_data_t *parent) obs_data_release(data); } +static inline bool HasAudioDevices(const char *source_id) +{ + const char *output_id = source_id; + obs_properties_t *props = obs_get_source_properties( + OBS_SOURCE_TYPE_INPUT, output_id); + size_t count = 0; + + if (!props) + return false; + + obs_property_t *devices = obs_properties_get(props, "device_id"); + if (devices) + count = obs_property_list_item_count(devices); + + obs_properties_destroy(props); + + return count != 0; +} + void OBSBasic::CreateDefaultScene() { + bool hasDesktopAudio = HasAudioDevices(App()->OutputAudioSource()); + bool hasInputAudio = HasAudioDevices(App()->InputAudioSource()); + obs_scene_t *scene = obs_scene_create(Str("Basic.Scene")); obs_source_t *source = obs_scene_get_source(scene); @@ -343,6 +365,13 @@ void OBSBasic::CreateDefaultScene() obs_set_output_source(0, obs_scene_get_source(scene)); obs_scene_release(scene); + + if (hasDesktopAudio) + ResetAudioDevice(App()->OutputAudioSource(), "default", + Str("Basic.DesktopDevice1"), 1); + if (hasInputAudio) + ResetAudioDevice(App()->InputAudioSource(), "default", + Str("Basic.AuxDevice1"), 3); } static void ReorderItemByName(QListWidget *lw, const char *name, int newIndex) @@ -414,25 +443,6 @@ void OBSBasic::Load(const char *file) obs_data_release(data); } -static inline bool HasAudioDevices(const char *source_id) -{ - const char *output_id = source_id; - obs_properties_t *props = obs_get_source_properties( - OBS_SOURCE_TYPE_INPUT, output_id); - size_t count = 0; - - if (!props) - return false; - - obs_property_t *devices = obs_properties_get(props, "device_id"); - if (devices) - count = obs_property_list_item_count(devices); - - obs_properties_destroy(props); - - return count != 0; -} - #define SERVICE_PATH "obs-studio/basic/service.json" void OBSBasic::SaveService() @@ -509,9 +519,6 @@ bool OBSBasic::InitService() bool OBSBasic::InitBasicConfigDefaults() { - bool hasDesktopAudio = HasAudioDevices(App()->OutputAudioSource()); - bool hasInputAudio = HasAudioDevices(App()->InputAudioSource()); - vector monitors; GetMonitors(monitors); @@ -607,17 +614,6 @@ bool OBSBasic::InitBasicConfigDefaults() "Stereo"); config_set_default_uint (basicConfig, "Audio", "BufferingTime", 1000); - config_set_default_string(basicConfig, "Audio", "DesktopDevice1", - hasDesktopAudio ? "default" : "disabled"); - config_set_default_string(basicConfig, "Audio", "DesktopDevice2", - "disabled"); - config_set_default_string(basicConfig, "Audio", "AuxDevice1", - hasInputAudio ? "default" : "disabled"); - config_set_default_string(basicConfig, "Audio", "AuxDevice2", - "disabled"); - config_set_default_string(basicConfig, "Audio", "AuxDevice3", - "disabled"); - return true; } @@ -744,7 +740,6 @@ void OBSBasic::OBSInit() InitPrimitives(); Load(savePath); - ResetAudioDevices(); TimedCheckForUpdates(); loaded = true; @@ -1905,11 +1900,9 @@ bool OBSBasic::ResetAudio() return obs_reset_audio(&ai); } -void OBSBasic::ResetAudioDevice(const char *sourceId, const char *deviceName, +void OBSBasic::ResetAudioDevice(const char *sourceId, const char *deviceId, const char *deviceDesc, int channel) { - const char *deviceId = config_get_string(basicConfig, "Audio", - deviceName); obs_source_t *source; obs_data_t *settings; bool same = false; @@ -1940,20 +1933,6 @@ void OBSBasic::ResetAudioDevice(const char *sourceId, const char *deviceName, } } -void OBSBasic::ResetAudioDevices() -{ - ResetAudioDevice(App()->OutputAudioSource(), "DesktopDevice1", - Str("Basic.DesktopDevice1"), 1); - ResetAudioDevice(App()->OutputAudioSource(), "DesktopDevice2", - Str("Basic.DesktopDevice2"), 2); - ResetAudioDevice(App()->InputAudioSource(), "AuxDevice1", - Str("Basic.AuxDevice1"), 3); - ResetAudioDevice(App()->InputAudioSource(), "AuxDevice2", - Str("Basic.AuxDevice2"), 4); - ResetAudioDevice(App()->InputAudioSource(), "AuxDevice3", - Str("Basic.AuxDevice3"), 5); -} - void OBSBasic::ResizePreview(uint32_t cx, uint32_t cy) { QSize targetSize; diff --git a/obs/window-basic-main.hpp b/obs/window-basic-main.hpp index 20e2df402..6d8e50176 100644 --- a/obs/window-basic-main.hpp +++ b/obs/window-basic-main.hpp @@ -243,9 +243,8 @@ public: void ResetOutputs(); - void ResetAudioDevice(const char *sourceId, const char *deviceName, + void ResetAudioDevice(const char *sourceId, const char *deviceId, const char *deviceDesc, int channel); - void ResetAudioDevices(); void NewProject(); void LoadProject(); diff --git a/obs/window-basic-settings.cpp b/obs/window-basic-settings.cpp index d5497ec9e..4890f3ada 100644 --- a/obs/window-basic-settings.cpp +++ b/obs/window-basic-settings.cpp @@ -1260,11 +1260,14 @@ static inline void LoadListValue(QComboBox *widget, const char *text, } void OBSBasicSettings::LoadListValues(QComboBox *widget, obs_property_t *prop, - const char *configName) + int index) { size_t count = obs_property_list_item_count(prop); - const char *deviceId = config_get_string(main->Config(), "Audio", - configName); + + obs_source_t *source = obs_get_output_source(index); + obs_data_t *settings = obs_source_get_settings(source); + + const char *deviceId = obs_data_get_string(settings, "device_id"); widget->addItem(QTStr("Disabled"), "disabled"); @@ -1275,14 +1278,11 @@ void OBSBasicSettings::LoadListValues(QComboBox *widget, obs_property_t *prop, } int idx = widget->findData(QVariant(QT_UTF8(deviceId))); - if (idx == -1) { - deviceId = config_get_default_string(main->Config(), "Audio", - configName); - idx = widget->findData(QVariant(QT_UTF8(deviceId))); - } - if (idx != -1) widget->setCurrentIndex(idx); + + obs_source_release(source); + obs_data_release(settings); } void OBSBasicSettings::LoadAudioDevices() @@ -1298,19 +1298,17 @@ void OBSBasicSettings::LoadAudioDevices() if (input_props) { obs_property_t *inputs = obs_properties_get(input_props, "device_id"); - LoadListValues(ui->auxAudioDevice1, inputs, "AuxDevice1"); - LoadListValues(ui->auxAudioDevice2, inputs, "AuxDevice2"); - LoadListValues(ui->auxAudioDevice3, inputs, "AuxDevice3"); + LoadListValues(ui->auxAudioDevice1, inputs, 3); + LoadListValues(ui->auxAudioDevice2, inputs, 4); + LoadListValues(ui->auxAudioDevice3, inputs, 5); obs_properties_destroy(input_props); } if (output_props) { obs_property_t *outputs = obs_properties_get(output_props, "device_id"); - LoadListValues(ui->desktopAudioDevice1, outputs, - "DesktopDevice1"); - LoadListValues(ui->desktopAudioDevice2, outputs, - "DesktopDevice2"); + LoadListValues(ui->desktopAudioDevice1, outputs, 1); + LoadListValues(ui->desktopAudioDevice2, outputs, 2); obs_properties_destroy(output_props); } } @@ -2072,12 +2070,6 @@ void OBSBasicSettings::SaveAudioSettings() config_set_string(main->Config(), "Audio", "ChannelSetup", channelSetup); - SaveComboData(ui->desktopAudioDevice1, "Audio", "DesktopDevice1"); - SaveComboData(ui->desktopAudioDevice2, "Audio", "DesktopDevice2"); - SaveComboData(ui->auxAudioDevice1, "Audio", "AuxDevice1"); - SaveComboData(ui->auxAudioDevice2, "Audio", "AuxDevice2"); - SaveComboData(ui->auxAudioDevice3, "Audio", "AuxDevice3"); - for (auto &audioSource : audioSources) { auto source = OBSGetStrongRef(get<0>(audioSource)); if (!source) @@ -2095,7 +2087,27 @@ void OBSBasicSettings::SaveAudioSettings() obs_source_set_push_to_talk_delay(source, pttSB->value()); } - main->ResetAudioDevices(); + auto UpdateAudioDevice = [this](bool input, QComboBox *combo, + const char *name, int index) + { + main->ResetAudioDevice( + input ? App()->InputAudioSource() + : App()->OutputAudioSource(), + QT_TO_UTF8(GetComboData(combo)), + Str(name), index); + }; + + UpdateAudioDevice(false, ui->desktopAudioDevice1, + "Basic.DesktopDevice1", 1); + UpdateAudioDevice(false, ui->desktopAudioDevice2, + "Basic.DesktopDevice2", 2); + UpdateAudioDevice(true, ui->auxAudioDevice1, + "Basic.AuxDevice1", 3); + UpdateAudioDevice(true, ui->auxAudioDevice2, + "Basic.AuxDevice2", 4); + UpdateAudioDevice(true, ui->auxAudioDevice3, + "Basic.AuxDevice3", 5); + main->SaveProject(); } void OBSBasicSettings::SaveHotkeySettings() diff --git a/obs/window-basic-settings.hpp b/obs/window-basic-settings.hpp index 2666cdf72..200eea07b 100644 --- a/obs/window-basic-settings.hpp +++ b/obs/window-basic-settings.hpp @@ -201,8 +201,7 @@ private: bool enableEncode = false); /* audio */ - void LoadListValues(QComboBox *widget, obs_property_t *prop, - const char *configName); + void LoadListValues(QComboBox *widget, obs_property_t *prop, int index); void LoadAudioDevices(); void LoadAudioSources();