Skip to content
This repository has been archived by the owner on May 9, 2024. It is now read-only.

Commit

Permalink
Fix #17 - load audio apis and devices only once
Browse files Browse the repository at this point in the history
  • Loading branch information
pierr3 committed Nov 3, 2022
1 parent 7ee7ea5 commit 33e225b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@
"future": "cpp",
"csignal": "cpp",
"regex": "cpp",
"variant": "cpp"
"variant": "cpp",
"__std_stream": "cpp",
"any": "cpp",
"format": "cpp",
"ranges": "cpp",
"span": "cpp"
}
}
14 changes: 9 additions & 5 deletions include/modals/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ namespace afv_unix::modals {
ImGui::Text("Audio configuration");

if (ImGui::BeginCombo("Sound API", afv_unix::shared::configAudioApi.c_str())) {
for (const auto &item: mClient->GetAudioApis()) {
for (const auto &item: afv_unix::shared::availableAudioAPI) {
if (ImGui::Selectable(item.second.c_str(), afv_unix::shared::mAudioApi == item.first)) {
afv_unix::shared::mAudioApi = item.first;
if (mClient)
if (mClient) {
// set the Audio API and update the available inputs and outputs
mClient->SetAudioApi(afv_unix::shared::mAudioApi);
afv_unix::shared::availableInputDevices = mClient->GetAudioInputDevices(afv_unix::shared::mAudioApi);
afv_unix::shared::availableOutputDevices = mClient->GetAudioOutputDevices(afv_unix::shared::mAudioApi);
}
afv_unix::shared::configAudioApi = item.second;
afv_unix::configuration::config["audio"]["api"] = item.second;
}
Expand All @@ -44,7 +48,7 @@ namespace afv_unix::modals {

if (ImGui::BeginCombo("Input Device", afv_unix::shared::configInputDeviceName.c_str())) {

auto m_audioDrivers = mClient->GetAudioInputDevices(afv_unix::shared::mAudioApi);
auto m_audioDrivers = afv_unix::shared::availableInputDevices;
for(const auto& driver : m_audioDrivers)
{
if (ImGui::Selectable(driver.c_str(), afv_unix::shared::configInputDeviceName == driver)) {
Expand All @@ -58,7 +62,7 @@ namespace afv_unix::modals {

if (ImGui::BeginCombo("Output Device", afv_unix::shared::configOutputDeviceName.c_str())) {

auto m_audioDrivers = mClient->GetAudioOutputDevices(afv_unix::shared::mAudioApi);
auto m_audioDrivers = afv_unix::shared::availableOutputDevices;
for(const auto& driver : m_audioDrivers)
{
if (ImGui::Selectable(driver.c_str(), afv_unix::shared::configOutputDeviceName == driver)) {
Expand All @@ -72,7 +76,7 @@ namespace afv_unix::modals {

if (ImGui::BeginCombo("Speaker Device", afv_unix::shared::configSpeakerDeviceName.c_str())) {

auto m_audioDrivers = mClient->GetAudioOutputDevices(afv_unix::shared::mAudioApi);
auto m_audioDrivers = afv_unix::shared::availableOutputDevices;
for(const auto& driver : m_audioDrivers)
{
if (ImGui::Selectable(driver.c_str(), afv_unix::shared::configSpeakerDeviceName == driver)) {
Expand Down
7 changes: 7 additions & 0 deletions include/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <vector>
#include <SFML/Window/Keyboard.hpp>
#include <afv-native/hardwareType.h>
#include <map>

namespace afv_unix::shared {
struct StationElement {
Expand Down Expand Up @@ -61,6 +62,12 @@ namespace afv_unix::shared {

inline float RadioGain = 1.0f;

// Temp settings for config window
inline std::map<unsigned int, std::string> availableAudioAPI;
inline std::vector<std::string> availableInputDevices;
inline std::vector<std::string> availableOutputDevices;


// Thread unsafe stuff
namespace datafile {
inline int facility = 0;
Expand Down
8 changes: 7 additions & 1 deletion src/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,14 @@ namespace afv_unix::application {
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f);
}

if (ImGui::Button("Settings") && !mClient->IsVoiceConnected())
if (ImGui::Button("Settings") && !mClient->IsVoiceConnected()) {
// Update all available data
afv_unix::shared::availableAudioAPI = mClient->GetAudioApis();
afv_unix::shared::availableInputDevices = mClient->GetAudioInputDevices(afv_unix::shared::mAudioApi);
afv_unix::shared::availableOutputDevices = mClient->GetAudioOutputDevices(afv_unix::shared::mAudioApi);
ImGui::OpenPopup("Settings Panel");
}


if (mClient->IsVoiceConnected()) {
ImGui::PopItemFlag();
Expand Down

0 comments on commit 33e225b

Please sign in to comment.