Add a slider which changes volume of sound sources.

This commit is contained in:
Karol Nowak 2007-04-24 20:53:12 +00:00
parent 593ccf518c
commit 1c58327f0e
5 changed files with 120 additions and 15 deletions

View file

@ -67,6 +67,9 @@ manager::manager()
read(prefs, *stream);
set_music_volume(music_volume());
set_sound_volume(sound_volume());
set_UI_volume(UI_volume());
set_bell_volume(bell_volume());
set_sound_sources_volume(sound_sources_volume());
set_show_haloes(prefs["show_haloes"] != "no");
if(prefs["remember_timer_settings"] != "yes") {
@ -301,6 +304,40 @@ void set_UI_volume(int vol)
sound::set_UI_volume(UI_volume());
}
int sound_sources_volume()
{
return lexical_cast_default<int>(prefs["sound_sources_volume"], 100);
}
void set_sound_sources_volume(int vol)
{
prefs["sound_sources_volume"] = lexical_cast_default<std::string>(vol, "100");
sound::set_sound_sources_volume(sound_sources_volume());
}
bool sound_sources_on()
{
return prefs["sound_sources"] != "no";
}
bool set_sound_sources(bool ison)
{
if(!sound_sources_on() && ison) {
prefs["sound_sources"] = "yes";
if(!sound_on() && !music_on() && !turn_bell() && !UI_sound_on()) {
if(!sound::init_sound()) {
prefs["sound_sources"] = "no";
return false;
}
}
} else if(sound_sources_on() && !ison) {
prefs["sound_sources"] = "no";
sound::stop_sound_sources();
if(!music_on() && !sound_on() && !turn_bell() && !UI_sound_on)
sound::close_sound();
}
return true;
}
bool adjust_gamma()
{
@ -493,7 +530,7 @@ bool set_turn_bell(bool ison)
{
if(!turn_bell() && ison) {
prefs["turn_bell"] = "yes";
if(!music_on() && !sound_on() && !UI_sound_on()) {
if(!music_on() && !sound_on() && !sound_sources_on() && !UI_sound_on()) {
if(!sound::init_sound()) {
prefs["turn_bell"] = "no";
return false;
@ -502,7 +539,7 @@ bool set_turn_bell(bool ison)
} else if(turn_bell() && !ison) {
prefs["turn_bell"] = "no";
sound::stop_bell();
if(!music_on() && !sound_on() && !UI_sound_on())
if(!music_on() && !sound_on() && !sound_sources_on() && !UI_sound_on())
sound::close_sound();
}
return true;
@ -517,7 +554,7 @@ bool set_UI_sound(bool ison)
{
if(!UI_sound_on() && ison) {
prefs["UI_sound"] = "yes";
if(!music_on() && !sound_on() && !turn_bell()) {
if(!music_on() && !sound_on() && !turn_bell() && !sound_sources_on()) {
if(!sound::init_sound()) {
prefs["UI_sound"] = "no";
return false;
@ -526,7 +563,7 @@ bool set_UI_sound(bool ison)
} else if(UI_sound_on() && !ison) {
prefs["UI_sound"] = "no";
sound::stop_UI_sound();
if(!music_on() && !sound_on() && !turn_bell())
if(!music_on() && !sound_on() && !turn_bell() && !sound_sources_on())
sound::close_sound();
}
return true;
@ -549,7 +586,7 @@ bool sound_on() {
bool set_sound(bool ison) {
if(!sound_on() && ison) {
prefs["sound"] = "yes";
if(!music_on() && !turn_bell() && !UI_sound_on()) {
if(!music_on() && !turn_bell() && !UI_sound_on() && !sound_sources_on()) {
if(!sound::init_sound()) {
prefs["sound"] = "no";
return false;
@ -558,7 +595,7 @@ bool set_sound(bool ison) {
} else if(sound_on() && !ison) {
prefs["sound"] = "no";
sound::stop_sound();
if(!music_on() && !turn_bell() && !UI_sound_on())
if(!music_on() && !turn_bell() && !UI_sound_on() && !sound_sources_on())
sound::close_sound();
}
return true;
@ -571,7 +608,7 @@ bool music_on() {
bool set_music(bool ison) {
if(!music_on() && ison) {
prefs["music"] = "yes";
if(!sound_on() && !turn_bell() && !UI_sound_on()) {
if(!sound_on() && !turn_bell() && !UI_sound_on() && !sound_sources_on()) {
if(!sound::init_sound()) {
prefs["music"] = "no";
return false;
@ -581,7 +618,7 @@ bool set_music(bool ison) {
sound::play_music();
} else if(music_on() && !ison) {
prefs["music"] = "no";
if(!sound_on() && !turn_bell() && !UI_sound_on())
if(!sound_on() && !turn_bell() && !UI_sound_on() && !sound_sources_on())
sound::close_sound();
else
sound::stop_music();

View file

@ -89,6 +89,11 @@ namespace preferences {
int UI_volume();
void set_UI_volume(int vol);
bool sound_sources_on();
bool set_sound_sources(bool ison);
int sound_sources_volume();
void set_sound_sources_volume(int vol);
bool music_on();
bool set_music(bool ison);

View file

@ -221,7 +221,7 @@ private:
//
// change
gui::slider music_slider_, sound_slider_, UI_sound_slider_, bell_slider_, scroll_slider_,
gui::slider music_slider_, sound_slider_, UI_sound_slider_, bell_slider_, sound_sources_slider_, scroll_slider_,
gamma_slider_, chat_lines_slider_, buffer_size_slider_;
gui::list_slider<double> turbo_slider_;
gui::button fullscreen_button_, turbo_button_, show_ai_moves_button_, show_grid_button_,
@ -230,9 +230,9 @@ private:
turn_bell_button_, show_team_colours_button_, show_colour_cursors_button_,
show_haloing_button_, video_mode_button_, theme_button_, hotkeys_button_, gamma_button_,
flip_time_button_, advanced_button_, sound_button_, music_button_, chat_timestamp_button_,
advanced_sound_button_, normal_sound_button_, UI_sound_button_,
advanced_sound_button_, normal_sound_button_, UI_sound_button_, sound_sources_button_,
sample_rate_button1_, sample_rate_button2_, sample_rate_button3_, confirm_sound_button_;
gui::label music_label_, sound_label_, UI_sound_label_, bell_label_, scroll_label_,
gui::label music_label_, sound_label_, UI_sound_label_, bell_label_, scroll_label_, sound_sources_label_,
gamma_label_, chat_lines_label_, turbo_slider_label_,
sample_rate_label_, buffer_size_label_;
gui::textbox sample_rate_input_, friends_input_;
@ -254,7 +254,7 @@ private:
preferences_dialog::preferences_dialog(display& disp, const config& game_cfg)
: gui::preview_pane(disp.video()),
music_slider_(disp.video()), sound_slider_(disp.video()), UI_sound_slider_(disp.video()),
bell_slider_(disp.video()),
bell_slider_(disp.video()), sound_sources_slider_(disp.video()),
scroll_slider_(disp.video()), gamma_slider_(disp.video()), chat_lines_slider_(disp.video()),
buffer_size_slider_(disp.video()), turbo_slider_(disp.video()),
@ -291,6 +291,7 @@ preferences_dialog::preferences_dialog(display& disp, const config& game_cfg)
advanced_sound_button_(disp.video(), _("Advanced Mode")),
normal_sound_button_(disp.video(), _("Normal Mode")),
UI_sound_button_(disp.video(), _("User Interface Sounds"), gui::button::TYPE_CHECK),
sound_sources_button_(disp.video(), _("Environmental Sounds"), gui::button::TYPE_CHECK),
sample_rate_button1_(disp.video(), "22050", gui::button::TYPE_CHECK),
sample_rate_button2_(disp.video(), "44100", gui::button::TYPE_CHECK),
sample_rate_button3_(disp.video(), _("Custom"), gui::button::TYPE_CHECK),
@ -299,6 +300,7 @@ preferences_dialog::preferences_dialog(display& disp, const config& game_cfg)
music_label_(disp.video(), _("Music Volume:")), sound_label_(disp.video(), _("SFX Volume:")),
UI_sound_label_(disp.video(), _("UI Sound Volume:")),
bell_label_(disp.video(), _("Bell Volume:")), scroll_label_(disp.video(), _("Scroll Speed:")),
sound_sources_label_(disp.video(), _("Environmental Volume:")),
gamma_label_(disp.video(), _("Gamma:")), chat_lines_label_(disp.video(), ""),
turbo_slider_label_(disp.video(), "", font::SIZE_SMALL ),
sample_rate_label_(disp.video(), _("Sample Rate (Hz):")), buffer_size_label_(disp.video(), ""),
@ -350,6 +352,13 @@ preferences_dialog::preferences_dialog(display& disp, const config& game_cfg)
UI_sound_slider_.set_value(UI_volume());
UI_sound_slider_.set_help_string(_("Change the sound volume for button clicks, etc."));
sound_sources_button_.set_check(sound_sources_on());
sound_sources_button_.set_help_string(_("Turn menu and button environmental sound sources on/off"));
sound_sources_slider_.set_min(0);
sound_sources_slider_.set_max(128);
sound_sources_slider_.set_value(sound_sources_volume());
sound_sources_slider_.set_help_string(_("Change the sound volume for environmental sounds"));
sample_rate_label_.set_help_string(_("Change the sample rate"));
std::string rate = lexical_cast<std::string>(sample_rate());
if (rate == "22050")
@ -486,6 +495,7 @@ handler_vector preferences_dialog::handler_members()
h.push_back(&sound_slider_);
h.push_back(&bell_slider_);
h.push_back(&UI_sound_slider_);
h.push_back(&sound_sources_slider_);
h.push_back(&scroll_slider_);
h.push_back(&gamma_slider_);
h.push_back(&chat_lines_slider_);
@ -511,6 +521,7 @@ handler_vector preferences_dialog::handler_members()
h.push_back(&turn_dialog_button_);
h.push_back(&turn_bell_button_);
h.push_back(&UI_sound_button_);
h.push_back(&sound_sources_button_);
h.push_back(&show_team_colours_button_);
h.push_back(&show_colour_cursors_button_);
h.push_back(&show_haloing_button_);
@ -533,6 +544,7 @@ handler_vector preferences_dialog::handler_members()
h.push_back(&sound_label_);
h.push_back(&bell_label_);
h.push_back(&UI_sound_label_);
h.push_back(&sound_sources_label_);
h.push_back(&scroll_label_);
h.push_back(&gamma_label_);
h.push_back(&turbo_slider_label_);
@ -636,6 +648,15 @@ void preferences_dialog::update_location(SDL_Rect const &rect)
const SDL_Rect UI_sound_rect = {rect.x + slider_label_width_, ypos,
rect.w - slider_label_width_ - right_border, 0 };
UI_sound_slider_.set_location(UI_sound_rect);
ypos += item_interline; //sound sources slider
sound_sources_button_.set_location(rect.x, ypos);
ypos += short_interline;
sound_sources_label_.set_location(rect.x, ypos);
const SDL_Rect sound_sources_rect = {rect.x + slider_label_width_, ypos,
rect.w - slider_label_width_ - right_border, 0 };
sound_sources_slider_.set_location(sound_sources_rect);
advanced_sound_button_.set_location(rect.x, bottom_row_y - advanced_sound_button_.height());
@ -793,9 +814,17 @@ void preferences_dialog::process_event()
UI_sound_slider_.enable(UI_sound_on());
UI_sound_label_.enable(UI_sound_on());
}
if (sound_sources_button_.pressed()) {
if(!set_sound_sources(sound_sources_button_.checked()))
sound_sources_button_.set_check(false);
sound_sources_slider_.enable(sound_sources_on());
sound_sources_label_.enable(sound_sources_on());
}
set_sound_volume(sound_slider_.value());
set_UI_volume(UI_sound_slider_.value());
set_bell_volume(bell_slider_.value());
set_sound_sources_volume(sound_sources_slider_.value());
std::cerr << sound_sources_slider_.value() << std::endl;
if (music_button_.pressed()) {
if(!set_music(music_button_.checked()))
@ -1086,6 +1115,9 @@ void preferences_dialog::set_selection(int index)
UI_sound_button_.hide(hide_sound);
UI_sound_label_.hide(hide_sound);
UI_sound_slider_.hide(hide_sound);
sound_sources_slider_.hide(hide_sound);
sound_sources_label_.hide(hide_sound);
sound_sources_button_.hide(hide_sound);
turn_bell_button_.hide(hide_sound);
bell_label_.hide(hide_sound);
bell_slider_.hide(hide_sound);

View file

@ -346,6 +346,7 @@ bool init_sound() {
set_sound_volume(preferences::sound_volume());
set_UI_volume(preferences::UI_volume());
set_sound_sources_volume(preferences::sound_sources_volume());
set_music_volume(preferences::music_volume());
set_bell_volume(preferences::bell_volume());
@ -464,6 +465,21 @@ void stop_UI_sound() {
}
}
void stop_sound_sources() {
if(mix_ok) {
Mix_HaltGroup(SOUND_SOURCES);
sound_cache_iterator itor = sound_cache.begin();
while(itor != sound_cache.end())
{
if(itor->group == SOUND_SOURCES) {
itor = sound_cache.erase(itor);
} else {
++itor;
}
}
}
}
void think_about_music(void)
{
if (!music_start_time) {
@ -618,8 +634,8 @@ void write_music_play_list(config& snapshot)
void reposition_sound(int id, unsigned int distance)
{
audio_lock lock();
for(int ch = 0; ch < channel_ids.size(); ++ch) {
int& ch_id = channel_ids[ch];
for(unsigned int ch = 0; ch < channel_ids.size(); ++ch) {
int & ch_id = channel_ids[ch];
if(ch_id == id) {
if(distance >= DISTANCE_SILENT) {
Mix_FadeOutChannel(ch, 100);
@ -763,7 +779,8 @@ void set_sound_volume(int vol)
if(vol > MIX_MAX_VOLUME)
vol = MIX_MAX_VOLUME;
// Bell has separate channel which we can't set up from this
// Bell, UI and sound sources have separate channels which we
// can't set up from this
for (unsigned i = 0; i < n_of_channels; i++){
if(i != UI_sound_channel && i != bell_channel) {
Mix_Volume(i, vol);
@ -792,4 +809,16 @@ void set_UI_volume(int vol)
}
}
void set_sound_sources_volume(int vol)
{
if(mix_ok && vol >= 0) {
if(vol > MIX_MAX_VOLUME)
vol = MIX_MAX_VOLUME;
for (unsigned i = source_channel_start; i - source_channel_start < source_channels; i++) {
Mix_Volume(i, vol);
}
}
}
} // end of sound namespace

View file

@ -35,6 +35,7 @@ void stop_music();
void stop_sound();
void stop_UI_sound();
void stop_bell();
void stop_sound_sources();
// Read config entry, alter track list accordingly.
void play_music_config(const config &music);
@ -83,6 +84,7 @@ void set_music_volume(int vol);
void set_sound_volume(int vol);
void set_bell_volume(int vol);
void set_UI_volume(int vol);
void set_sound_sources_volume(int vol);
}