mirror of
https://github.com/Lorenzooone/cc3dsfs.git
synced 2026-03-22 02:06:22 -05:00
131 lines
3.0 KiB
C++
Executable File
131 lines
3.0 KiB
C++
Executable File
#include "audio_data.hpp"
|
|
|
|
void AudioData::reset() {
|
|
this->volume = 50;
|
|
this->mute = false;
|
|
this->max_audio_latency = 2;
|
|
this->restart_request = false;
|
|
this->text_updated = false;
|
|
}
|
|
|
|
|
|
void AudioData::set_max_audio_latency(int new_value) {
|
|
if(new_value > MAX_MAX_AUDIO_LATENCY)
|
|
new_value = MAX_MAX_AUDIO_LATENCY;
|
|
if(new_value <= 0)
|
|
new_value = 1;
|
|
this->max_audio_latency = new_value;
|
|
}
|
|
|
|
void AudioData::change_audio_volume(bool is_change_positive) {
|
|
bool initial_audio_mute = this->mute;
|
|
int initial_audio_volume = this->volume;
|
|
int volume_change = 5;
|
|
if(!is_change_positive)
|
|
volume_change *= -1;
|
|
this->set_audio_volume(this->volume + volume_change);
|
|
this->set_audio_mute(false);
|
|
if((this->volume != initial_audio_volume) || (initial_audio_mute))
|
|
this->update_text("Volume: " + std::to_string(this->get_final_volume()) + "%");
|
|
}
|
|
|
|
void AudioData::change_audio_mute() {
|
|
this->set_audio_mute(!this->mute);
|
|
if(this->mute)
|
|
this->update_text("Audio muted");
|
|
else
|
|
this->update_text("Volume: " + std::to_string(this->get_final_volume()) + "%");
|
|
}
|
|
|
|
void AudioData::request_audio_restart() {
|
|
this->restart_request = true;
|
|
this->update_text("Restarting audio...");
|
|
}
|
|
|
|
bool AudioData::check_audio_restart_request() {
|
|
bool retval = this->restart_request;
|
|
if(retval)
|
|
this->restart_request = false;
|
|
return retval;
|
|
}
|
|
|
|
void AudioData::update_text(std::string text) {
|
|
this->text = text;
|
|
this->text_updated = true;
|
|
}
|
|
|
|
bool AudioData::has_text_to_print() {
|
|
bool retval = this->text_updated;
|
|
if(retval)
|
|
this->text_updated = false;
|
|
return retval;
|
|
}
|
|
|
|
std::string AudioData::text_to_print() {
|
|
return this->text;
|
|
}
|
|
|
|
int AudioData::get_max_audio_latency() {
|
|
return this->max_audio_latency;
|
|
}
|
|
|
|
int AudioData::get_final_volume() {
|
|
if(this->mute)
|
|
return 0;
|
|
int read_volume = this->volume;
|
|
if(read_volume < 0)
|
|
read_volume = 0;
|
|
if(read_volume > 100)
|
|
read_volume = 100;
|
|
return read_volume;
|
|
}
|
|
|
|
int AudioData::get_real_volume() {
|
|
int read_volume = this->volume;
|
|
if(read_volume < 0)
|
|
read_volume = 0;
|
|
if(read_volume > 100)
|
|
read_volume = 100;
|
|
return read_volume;
|
|
}
|
|
|
|
bool AudioData::get_mute() {
|
|
return this->mute;
|
|
}
|
|
|
|
bool AudioData::load_audio_data(std::string key, std::string value) {
|
|
if (key == this->mute_str) {
|
|
this->set_audio_mute(std::stoi(value));
|
|
return true;
|
|
}
|
|
if (key == this->volume_str) {
|
|
this->set_audio_volume(std::stoi(value));
|
|
return true;
|
|
}
|
|
if (key == this->max_audio_latency_str) {
|
|
this->set_max_audio_latency(std::stoi(value));
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
std::string AudioData::save_audio_data() {
|
|
std::string out_str = "";
|
|
out_str += this->mute_str + "=" + std::to_string(this->mute) + "\n";
|
|
out_str += this->volume_str + "=" + std::to_string(this->volume) + "\n";
|
|
out_str += this->max_audio_latency_str + "=" + std::to_string(this->max_audio_latency) + "\n";
|
|
return out_str;
|
|
}
|
|
|
|
void AudioData::set_audio_volume(int new_volume) {
|
|
if(new_volume < 0)
|
|
new_volume = 0;
|
|
if(new_volume > 100)
|
|
new_volume = 100;
|
|
this->volume = new_volume;
|
|
}
|
|
|
|
void AudioData::set_audio_mute(bool new_mute) {
|
|
this->mute = new_mute;
|
|
}
|