mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-06-30 06:17:49 +02:00
Moved menus to their own respective files
This commit is contained in:
139
core/src/gui/menus/audio.cpp
Normal file
139
core/src/gui/menus/audio.cpp
Normal file
@ -0,0 +1,139 @@
|
||||
#include <gui/menus/audio.h>
|
||||
#include <gui/bandplan.h>
|
||||
#include <gui/gui.h>
|
||||
#include <core.h>
|
||||
#include <signal_path/audio.h>
|
||||
|
||||
namespace audiomenu {
|
||||
// Note: Those are supposed to be the ones from the volume slider
|
||||
std::string audioStreamName;
|
||||
float* volume;
|
||||
|
||||
void loadAudioConfig(std::string name) {
|
||||
json audioSettings = core::configManager.conf["audio"][name];
|
||||
std::string devName = audioSettings["device"];
|
||||
auto _devIt = std::find(audio::streams[name]->audio->deviceNames.begin(), audio::streams[name]->audio->deviceNames.end(), devName);
|
||||
|
||||
// If audio device doesn't exist anymore
|
||||
if (_devIt == audio::streams[name]->audio->deviceNames.end()) {
|
||||
audio::streams[name]->audio->setToDefault();
|
||||
int deviceId = audio::streams[name]->audio->getDeviceId();
|
||||
audio::setAudioDevice(name, deviceId, audio::streams[name]->audio->devices[deviceId].sampleRates[0]);
|
||||
audio::streams[name]->sampleRateId = 0;
|
||||
audio::streams[name]->volume = audioSettings["volume"];
|
||||
audio::streams[name]->audio->setVolume(audio::streams[name]->volume);
|
||||
return;
|
||||
}
|
||||
int deviceId = std::distance(audio::streams[name]->audio->deviceNames.begin(), _devIt);
|
||||
float sr = audioSettings["sampleRate"];
|
||||
auto _srIt = std::find(audio::streams[name]->audio->devices[deviceId].sampleRates.begin(), audio::streams[name]->audio->devices[deviceId].sampleRates.end(), sr);
|
||||
|
||||
// If sample rate doesn't exist anymore
|
||||
if (_srIt == audio::streams[name]->audio->devices[deviceId].sampleRates.end()) {
|
||||
audio::streams[name]->sampleRateId = 0;
|
||||
audio::setAudioDevice(name, deviceId, audio::streams[name]->audio->devices[deviceId].sampleRates[0]);
|
||||
audio::streams[name]->volume = audioSettings["volume"];
|
||||
audio::streams[name]->audio->setVolume(audio::streams[name]->volume);
|
||||
return;
|
||||
}
|
||||
|
||||
int samplerateId = std::distance(audio::streams[name]->audio->devices[deviceId].sampleRates.begin(), _srIt);
|
||||
audio::streams[name]->sampleRateId = samplerateId;
|
||||
audio::setAudioDevice(name, deviceId, audio::streams[name]->audio->devices[deviceId].sampleRates[samplerateId]);
|
||||
audio::streams[name]->deviceId = deviceId;
|
||||
audio::streams[name]->volume = audioSettings["volume"];
|
||||
audio::streams[name]->audio->setVolume(audio::streams[name]->volume);
|
||||
}
|
||||
|
||||
void saveAudioConfig(std::string name) {
|
||||
core::configManager.conf["audio"][name]["device"] = audio::streams[name]->audio->deviceNames[audio::streams[name]->deviceId];
|
||||
core::configManager.conf["audio"][name]["volume"] = audio::streams[name]->volume;
|
||||
core::configManager.conf["audio"][name]["sampleRate"] = audio::streams[name]->sampleRate;
|
||||
}
|
||||
|
||||
void init() {
|
||||
for (auto [name, stream] : audio::streams) {
|
||||
if (core::configManager.conf["audio"].contains(name)) {
|
||||
bool running = audio::streams[name]->running;
|
||||
audio::stopStream(name);
|
||||
loadAudioConfig(name);
|
||||
if (running) {
|
||||
audio::startStream(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
audioStreamName = audio::getNameFromVFO(gui::waterfall.selectedVFO);
|
||||
if (audioStreamName != "") {
|
||||
volume = &audio::streams[audioStreamName]->volume;
|
||||
}
|
||||
}
|
||||
|
||||
void draw(void* ctx) {
|
||||
float menuColumnWidth = ImGui::GetContentRegionAvailWidth();
|
||||
int count = 0;
|
||||
int maxCount = audio::streams.size();
|
||||
for (auto const& [name, stream] : audio::streams) {
|
||||
int deviceId;
|
||||
float vol = 1.0f;
|
||||
deviceId = stream->audio->getDeviceId();
|
||||
|
||||
ImGui::SetCursorPosX((menuColumnWidth / 2.0f) - (ImGui::CalcTextSize(name.c_str()).x / 2.0f));
|
||||
ImGui::Text(name.c_str());
|
||||
|
||||
ImGui::PushItemWidth(menuColumnWidth);
|
||||
bool running = stream->running;
|
||||
if (ImGui::Combo(("##_audio_dev_0_"+ name).c_str(), &stream->deviceId, stream->audio->devTxtList.c_str())) {
|
||||
audio::stopStream(name);
|
||||
audio::setAudioDevice(name, stream->deviceId, stream->audio->devices[deviceId].sampleRates[0]);
|
||||
if (running) {
|
||||
audio::startStream(name);
|
||||
}
|
||||
stream->sampleRateId = 0;
|
||||
|
||||
// Create config if it doesn't exist
|
||||
core::configManager.aquire();
|
||||
if (!core::configManager.conf["audio"].contains(name)) {
|
||||
saveAudioConfig(name);
|
||||
}
|
||||
core::configManager.conf["audio"][name]["device"] = stream->audio->deviceNames[stream->deviceId];
|
||||
core::configManager.conf["audio"][name]["sampleRate"] = stream->audio->devices[stream->deviceId].sampleRates[0];
|
||||
core::configManager.release(true);
|
||||
}
|
||||
if (ImGui::Combo(("##_audio_sr_0_" + name).c_str(), &stream->sampleRateId, stream->audio->devices[deviceId].txtSampleRates.c_str())) {
|
||||
audio::stopStream(name);
|
||||
audio::setSampleRate(name, stream->audio->devices[deviceId].sampleRates[stream->sampleRateId]);
|
||||
if (running) {
|
||||
audio::startStream(name);
|
||||
}
|
||||
|
||||
// Create config if it doesn't exist
|
||||
core::configManager.aquire();
|
||||
if (!core::configManager.conf["audio"].contains(name)) {
|
||||
saveAudioConfig(name);
|
||||
}
|
||||
core::configManager.conf["audio"][name]["sampleRate"] = stream->audio->devices[deviceId].sampleRates[stream->sampleRateId];
|
||||
core::configManager.release(true);
|
||||
}
|
||||
if (ImGui::SliderFloat(("##_audio_vol_0_" + name).c_str(), &stream->volume, 0.0f, 1.0f, "")) {
|
||||
stream->audio->setVolume(stream->volume);
|
||||
|
||||
// Create config if it doesn't exist
|
||||
core::configManager.aquire();
|
||||
if (!core::configManager.conf["audio"].contains(name)) {
|
||||
saveAudioConfig(name);
|
||||
}
|
||||
core::configManager.conf["audio"][name]["volume"] = stream->volume;
|
||||
core::configManager.release(true);
|
||||
}
|
||||
ImGui::PopItemWidth();
|
||||
count++;
|
||||
if (count < maxCount) {
|
||||
ImGui::Spacing();
|
||||
ImGui::Separator();
|
||||
}
|
||||
ImGui::Spacing();
|
||||
}
|
||||
ImGui::Spacing();
|
||||
}
|
||||
};
|
6
core/src/gui/menus/audio.h
Normal file
6
core/src/gui/menus/audio.h
Normal file
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
namespace audiomenu {
|
||||
void init();
|
||||
void draw(void* ctx);
|
||||
};
|
52
core/src/gui/menus/bandplan.cpp
Normal file
52
core/src/gui/menus/bandplan.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
#include <gui/menus/bandplan.h>
|
||||
#include <gui/bandplan.h>
|
||||
#include <gui/gui.h>
|
||||
#include <core.h>
|
||||
|
||||
namespace bandplanmenu {
|
||||
int bandplanId;
|
||||
bool bandPlanEnabled;
|
||||
|
||||
void init() {
|
||||
// todo: check if the bandplan wasn't removed
|
||||
if (bandplan::bandplanNames.size() == 0) {
|
||||
gui::waterfall.hideBandplan();
|
||||
return;
|
||||
}
|
||||
|
||||
if (bandplan::bandplans.find(core::configManager.conf["bandPlan"]) != bandplan::bandplans.end()) {
|
||||
std::string name = core::configManager.conf["bandPlan"];
|
||||
bandplanId = std::distance(bandplan::bandplanNames.begin(), std::find(bandplan::bandplanNames.begin(),
|
||||
bandplan::bandplanNames.end(), name));
|
||||
gui::waterfall.bandplan = &bandplan::bandplans[name];
|
||||
}
|
||||
else {
|
||||
gui::waterfall.bandplan = &bandplan::bandplans[bandplan::bandplanNames[0]];
|
||||
}
|
||||
|
||||
bandPlanEnabled = core::configManager.conf["bandPlanEnabled"];
|
||||
bandPlanEnabled ? gui::waterfall.showBandplan() : gui::waterfall.hideBandplan();
|
||||
}
|
||||
|
||||
void draw(void* ctx) {
|
||||
float menuColumnWidth = ImGui::GetContentRegionAvailWidth();
|
||||
ImGui::PushItemWidth(menuColumnWidth);
|
||||
if (ImGui::Combo("##_4_", &bandplanId, bandplan::bandplanNameTxt.c_str())) {
|
||||
gui::waterfall.bandplan = &bandplan::bandplans[bandplan::bandplanNames[bandplanId]];
|
||||
core::configManager.aquire();
|
||||
core::configManager.conf["bandPlan"] = bandplan::bandplanNames[bandplanId];
|
||||
core::configManager.release(true);
|
||||
}
|
||||
ImGui::PopItemWidth();
|
||||
if (ImGui::Checkbox("Enabled", &bandPlanEnabled)) {
|
||||
bandPlanEnabled ? gui::waterfall.showBandplan() : gui::waterfall.hideBandplan();
|
||||
core::configManager.aquire();
|
||||
core::configManager.conf["bandPlanEnabled"] = bandPlanEnabled;
|
||||
core::configManager.release(true);
|
||||
}
|
||||
bandplan::BandPlan_t plan = bandplan::bandplans[bandplan::bandplanNames[bandplanId]];
|
||||
ImGui::Text("Country: %s (%s)", plan.countryName.c_str(), plan.countryCode.c_str());
|
||||
ImGui::Text("Author: %s", plan.authorName.c_str());
|
||||
ImGui::Spacing();
|
||||
}
|
||||
};
|
6
core/src/gui/menus/bandplan.h
Normal file
6
core/src/gui/menus/bandplan.h
Normal file
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
namespace bandplanmenu {
|
||||
void init();
|
||||
void draw(void* ctx);
|
||||
};
|
23
core/src/gui/menus/display.cpp
Normal file
23
core/src/gui/menus/display.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include <gui/menus/display.h>
|
||||
#include <imgui.h>
|
||||
#include <gui/gui.h>
|
||||
#include <core.h>
|
||||
|
||||
namespace displaymenu {
|
||||
bool showWaterfall;
|
||||
|
||||
void init() {
|
||||
showWaterfall = core::configManager.conf["showWaterfall"];
|
||||
showWaterfall ? gui::waterfall.showWaterfall() : gui::waterfall.hideWaterfall();
|
||||
}
|
||||
|
||||
void draw(void* ctx) {
|
||||
if (ImGui::Checkbox("Show Waterfall", &showWaterfall)) {
|
||||
showWaterfall ? gui::waterfall.showWaterfall() : gui::waterfall.hideWaterfall();
|
||||
core::configManager.aquire();
|
||||
core::configManager.conf["showWaterfall"] = showWaterfall;
|
||||
core::configManager.release(true);
|
||||
}
|
||||
ImGui::Spacing();
|
||||
}
|
||||
}
|
6
core/src/gui/menus/display.h
Normal file
6
core/src/gui/menus/display.h
Normal file
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
namespace displaymenu {
|
||||
void init();
|
||||
void draw(void* ctx);
|
||||
}
|
11
core/src/gui/menus/source.cpp
Normal file
11
core/src/gui/menus/source.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include <gui/menus/source.h>
|
||||
|
||||
namespace sourecmenu {
|
||||
void init() {
|
||||
|
||||
}
|
||||
|
||||
void draw(void* ctx) {
|
||||
|
||||
}
|
||||
}
|
6
core/src/gui/menus/source.h
Normal file
6
core/src/gui/menus/source.h
Normal file
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
namespace sourecmenu {
|
||||
void init();
|
||||
void draw(void* ctx);
|
||||
}
|
Reference in New Issue
Block a user