From 567385be06571fdef5f46969e96c28dcc32ec2be Mon Sep 17 00:00:00 2001 From: Pavel Kulik Date: Thu, 9 May 2024 15:25:06 -0700 Subject: [PATCH] Set audio device type via HTTP --- Source/Audio/AudioComponent.cpp | 4 +++- Source/Utils/OpenEphysHttpServer.h | 22 ++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Source/Audio/AudioComponent.cpp b/Source/Audio/AudioComponent.cpp index 8320272d1..ae12ba34a 100644 --- a/Source/Audio/AudioComponent.cpp +++ b/Source/Audio/AudioComponent.cpp @@ -182,6 +182,8 @@ String AudioComponent::getDeviceType() void AudioComponent::setDeviceType(String deviceType) { deviceManager.setCurrentAudioDeviceType(deviceType, true); + + CoreServices::sendStatusMessage("Set device type to " + String(deviceManager.getCurrentDeviceTypeObject()->getTypeName())); } void AudioComponent::connectToProcessorGraph(AudioProcessorGraph* processorGraph) @@ -346,5 +348,5 @@ void AudioComponent::loadStateFromXml(XmlElement* parent) LOGE("Buffer size out of range."); } - std::cout << deviceManager.setAudioDeviceSetup(setup, true) << std::endl; + LOGC(deviceManager.setAudioDeviceSetup(setup, true)); } diff --git a/Source/Utils/OpenEphysHttpServer.h b/Source/Utils/OpenEphysHttpServer.h index df2ac67eb..49ba6b8b3 100644 --- a/Source/Utils/OpenEphysHttpServer.h +++ b/Source/Utils/OpenEphysHttpServer.h @@ -166,6 +166,16 @@ class OpenEphysHttpServer : juce::Thread { return; } + try { + int sample_rate = request_json["sample_rate"]; + LOGD("Found 'sample_rate': ", sample_rate); + const MessageManagerLock mml; + AccessClass::getAudioComponent()->setSampleRate(sample_rate); + } + catch (json::exception& e) { + LOGD("'sample_rate' not specified'"); + } + try { int buffer_size = request_json["buffer_size"]; LOGD("Found 'buffer_size': ", buffer_size); @@ -178,13 +188,13 @@ class OpenEphysHttpServer : juce::Thread { } try { - int sample_rate = request_json["sample_rate"]; - LOGD("Found 'sample_rate': ", sample_rate); + std::string device_type = request_json["device_type"]; + LOGD("Found 'device_type': ", device_type); const MessageManagerLock mml; - AccessClass::getAudioComponent()->setSampleRate(sample_rate); + AccessClass::getAudioComponent()->setDeviceType(String(device_type)); } catch (json::exception& e) { - LOGD("'sample_rate' not specified'"); + LOGD("'device_type' not specified'"); } json ret; @@ -1025,12 +1035,12 @@ class OpenEphysHttpServer : juce::Thread { inline static void audio_info_to_json(const ProcessorGraph* graph, json* ret) { - (*ret)["device"] = AccessClass::getAudioComponent()->getDeviceType().toStdString(); - (*ret)["sample_rate"] = AccessClass::getAudioComponent()->getSampleRate(); (*ret)["buffer_size"] = AccessClass::getAudioComponent()->getBufferSize(); + (*ret)["device_type"] = AccessClass::getAudioComponent()->getDeviceType().toStdString(); + } inline static void recording_info_to_json(const ProcessorGraph* graph, json* ret)