Author: grzywacz
Date: Tue Apr 24 22:53:12 2007
New Revision: 17052
URL: http://svn.gna.org/viewcvs/wesnoth?rev=17052&view=rev
Log:
Add a slider which changes volume of sound sources.
Modified:
trunk/src/preferences.cpp
trunk/src/preferences.hpp
trunk/src/preferences_display.cpp
trunk/src/sound.cpp
trunk/src/sound.hpp
Modified: trunk/src/preferences.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/preferences.cpp?rev=17052&r1=17051&r2=17052&view=diff
==============================================================================
--- trunk/src/preferences.cpp (original)
+++ trunk/src/preferences.cpp Tue Apr 24 22:53:12 2007
@@ -67,6 +67,9 @@
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 @@
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 @@
{
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 @@
} 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 @@
{
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 @@
} 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 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 @@
} 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 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 @@
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();
Modified: trunk/src/preferences.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/preferences.hpp?rev=17052&r1=17051&r2=17052&view=diff
==============================================================================
--- trunk/src/preferences.hpp (original)
+++ trunk/src/preferences.hpp Tue Apr 24 22:53:12 2007
@@ -88,6 +88,11 @@
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);
Modified: trunk/src/preferences_display.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/preferences_display.cpp?rev=17052&r1=17051&r2=17052&view=diff
==============================================================================
--- trunk/src/preferences_display.cpp (original)
+++ trunk/src/preferences_display.cpp Tue Apr 24 22:53:12 2007
@@ -221,7 +221,7 @@
//
// 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 @@
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 @@
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 @@
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 @@
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(), ""),
@@ -349,6 +351,13 @@
UI_sound_slider_.set_max(128);
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());
@@ -486,6 +495,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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);
Modified: trunk/src/sound.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/sound.cpp?rev=17052&r1=17051&r2=17052&view=diff
==============================================================================
--- trunk/src/sound.cpp (original)
+++ trunk/src/sound.cpp Tue Apr 24 22:53:12 2007
@@ -346,6 +346,7 @@
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_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 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 @@
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_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
Modified: trunk/src/sound.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/sound.hpp?rev=17052&r1=17051&r2=17052&view=diff
==============================================================================
--- trunk/src/sound.hpp (original)
+++ trunk/src/sound.hpp Tue Apr 24 22:53:12 2007
@@ -35,6 +35,7 @@
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_sound_volume(int vol);
void set_bell_volume(int vol);
void set_UI_volume(int vol);
+void set_sound_sources_volume(int vol);
}
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits