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.master
parent
cb6c90a02c
commit
3b16477480
|
@ -323,8 +323,30 @@ static void LoadAudioDevice(const char *name, int channel, obs_data_t *parent)
|
||||||
obs_data_release(data);
|
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()
|
void OBSBasic::CreateDefaultScene()
|
||||||
{
|
{
|
||||||
|
bool hasDesktopAudio = HasAudioDevices(App()->OutputAudioSource());
|
||||||
|
bool hasInputAudio = HasAudioDevices(App()->InputAudioSource());
|
||||||
|
|
||||||
obs_scene_t *scene = obs_scene_create(Str("Basic.Scene"));
|
obs_scene_t *scene = obs_scene_create(Str("Basic.Scene"));
|
||||||
obs_source_t *source = obs_scene_get_source(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_set_output_source(0, obs_scene_get_source(scene));
|
||||||
obs_scene_release(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)
|
static void ReorderItemByName(QListWidget *lw, const char *name, int newIndex)
|
||||||
|
@ -414,25 +443,6 @@ void OBSBasic::Load(const char *file)
|
||||||
obs_data_release(data);
|
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"
|
#define SERVICE_PATH "obs-studio/basic/service.json"
|
||||||
|
|
||||||
void OBSBasic::SaveService()
|
void OBSBasic::SaveService()
|
||||||
|
@ -509,9 +519,6 @@ bool OBSBasic::InitService()
|
||||||
|
|
||||||
bool OBSBasic::InitBasicConfigDefaults()
|
bool OBSBasic::InitBasicConfigDefaults()
|
||||||
{
|
{
|
||||||
bool hasDesktopAudio = HasAudioDevices(App()->OutputAudioSource());
|
|
||||||
bool hasInputAudio = HasAudioDevices(App()->InputAudioSource());
|
|
||||||
|
|
||||||
vector<MonitorInfo> monitors;
|
vector<MonitorInfo> monitors;
|
||||||
GetMonitors(monitors);
|
GetMonitors(monitors);
|
||||||
|
|
||||||
|
@ -607,17 +614,6 @@ bool OBSBasic::InitBasicConfigDefaults()
|
||||||
"Stereo");
|
"Stereo");
|
||||||
config_set_default_uint (basicConfig, "Audio", "BufferingTime", 1000);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -744,7 +740,6 @@ void OBSBasic::OBSInit()
|
||||||
InitPrimitives();
|
InitPrimitives();
|
||||||
|
|
||||||
Load(savePath);
|
Load(savePath);
|
||||||
ResetAudioDevices();
|
|
||||||
|
|
||||||
TimedCheckForUpdates();
|
TimedCheckForUpdates();
|
||||||
loaded = true;
|
loaded = true;
|
||||||
|
@ -1905,11 +1900,9 @@ bool OBSBasic::ResetAudio()
|
||||||
return obs_reset_audio(&ai);
|
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 *deviceDesc, int channel)
|
||||||
{
|
{
|
||||||
const char *deviceId = config_get_string(basicConfig, "Audio",
|
|
||||||
deviceName);
|
|
||||||
obs_source_t *source;
|
obs_source_t *source;
|
||||||
obs_data_t *settings;
|
obs_data_t *settings;
|
||||||
bool same = false;
|
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)
|
void OBSBasic::ResizePreview(uint32_t cx, uint32_t cy)
|
||||||
{
|
{
|
||||||
QSize targetSize;
|
QSize targetSize;
|
||||||
|
|
|
@ -243,9 +243,8 @@ public:
|
||||||
|
|
||||||
void ResetOutputs();
|
void ResetOutputs();
|
||||||
|
|
||||||
void ResetAudioDevice(const char *sourceId, const char *deviceName,
|
void ResetAudioDevice(const char *sourceId, const char *deviceId,
|
||||||
const char *deviceDesc, int channel);
|
const char *deviceDesc, int channel);
|
||||||
void ResetAudioDevices();
|
|
||||||
|
|
||||||
void NewProject();
|
void NewProject();
|
||||||
void LoadProject();
|
void LoadProject();
|
||||||
|
|
|
@ -1260,11 +1260,14 @@ static inline void LoadListValue(QComboBox *widget, const char *text,
|
||||||
}
|
}
|
||||||
|
|
||||||
void OBSBasicSettings::LoadListValues(QComboBox *widget, obs_property_t *prop,
|
void OBSBasicSettings::LoadListValues(QComboBox *widget, obs_property_t *prop,
|
||||||
const char *configName)
|
int index)
|
||||||
{
|
{
|
||||||
size_t count = obs_property_list_item_count(prop);
|
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");
|
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)));
|
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)
|
if (idx != -1)
|
||||||
widget->setCurrentIndex(idx);
|
widget->setCurrentIndex(idx);
|
||||||
|
|
||||||
|
obs_source_release(source);
|
||||||
|
obs_data_release(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OBSBasicSettings::LoadAudioDevices()
|
void OBSBasicSettings::LoadAudioDevices()
|
||||||
|
@ -1298,19 +1298,17 @@ void OBSBasicSettings::LoadAudioDevices()
|
||||||
if (input_props) {
|
if (input_props) {
|
||||||
obs_property_t *inputs = obs_properties_get(input_props,
|
obs_property_t *inputs = obs_properties_get(input_props,
|
||||||
"device_id");
|
"device_id");
|
||||||
LoadListValues(ui->auxAudioDevice1, inputs, "AuxDevice1");
|
LoadListValues(ui->auxAudioDevice1, inputs, 3);
|
||||||
LoadListValues(ui->auxAudioDevice2, inputs, "AuxDevice2");
|
LoadListValues(ui->auxAudioDevice2, inputs, 4);
|
||||||
LoadListValues(ui->auxAudioDevice3, inputs, "AuxDevice3");
|
LoadListValues(ui->auxAudioDevice3, inputs, 5);
|
||||||
obs_properties_destroy(input_props);
|
obs_properties_destroy(input_props);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (output_props) {
|
if (output_props) {
|
||||||
obs_property_t *outputs = obs_properties_get(output_props,
|
obs_property_t *outputs = obs_properties_get(output_props,
|
||||||
"device_id");
|
"device_id");
|
||||||
LoadListValues(ui->desktopAudioDevice1, outputs,
|
LoadListValues(ui->desktopAudioDevice1, outputs, 1);
|
||||||
"DesktopDevice1");
|
LoadListValues(ui->desktopAudioDevice2, outputs, 2);
|
||||||
LoadListValues(ui->desktopAudioDevice2, outputs,
|
|
||||||
"DesktopDevice2");
|
|
||||||
obs_properties_destroy(output_props);
|
obs_properties_destroy(output_props);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2072,12 +2070,6 @@ void OBSBasicSettings::SaveAudioSettings()
|
||||||
config_set_string(main->Config(), "Audio", "ChannelSetup",
|
config_set_string(main->Config(), "Audio", "ChannelSetup",
|
||||||
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) {
|
for (auto &audioSource : audioSources) {
|
||||||
auto source = OBSGetStrongRef(get<0>(audioSource));
|
auto source = OBSGetStrongRef(get<0>(audioSource));
|
||||||
if (!source)
|
if (!source)
|
||||||
|
@ -2095,7 +2087,27 @@ void OBSBasicSettings::SaveAudioSettings()
|
||||||
obs_source_set_push_to_talk_delay(source, pttSB->value());
|
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()
|
void OBSBasicSettings::SaveHotkeySettings()
|
||||||
|
|
|
@ -201,8 +201,7 @@ private:
|
||||||
bool enableEncode = false);
|
bool enableEncode = false);
|
||||||
|
|
||||||
/* audio */
|
/* audio */
|
||||||
void LoadListValues(QComboBox *widget, obs_property_t *prop,
|
void LoadListValues(QComboBox *widget, obs_property_t *prop, int index);
|
||||||
const char *configName);
|
|
||||||
void LoadAudioDevices();
|
void LoadAudioDevices();
|
||||||
void LoadAudioSources();
|
void LoadAudioSources();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue