• R/O
  • SSH
  • HTTPS

qrobosdk: コミット


コミットメタ情報

リビジョン1964 (tree)
日時2011-08-13 04:16:24
作者satofumi

ログメッセージ

added setMute method

変更サマリ

差分

--- trunk/libs/audio/sdl_mixer/Audio.cpp (revision 1963)
+++ trunk/libs/audio/sdl_mixer/Audio.cpp (revision 1964)
@@ -26,6 +26,13 @@
2626 }
2727
2828
29+ static pImpl* singleton_object(void)
30+ {
31+ static pImpl object_;
32+ return &object_;
33+ }
34+
35+
2936 bool initialize(void)
3037 {
3138 return SdlMixerInit::initialize();
@@ -39,7 +46,7 @@
3946 };
4047
4148
42-Audio::Audio(void) : pimpl(new pImpl)
49+Audio::Audio(void) : pimpl(pImpl::singleton_object())
4350 {
4451 }
4552
--- trunk/libs/audio/sdl_mixer/BackMusic.cpp (revision 1963)
+++ trunk/libs/audio/sdl_mixer/BackMusic.cpp (revision 1964)
@@ -13,8 +13,6 @@
1313 #include <map>
1414 #include <string>
1515
16-#include <cstdio>
17-
1816 using namespace qrk;
1917 using namespace std;
2018
@@ -29,27 +27,28 @@
2927
3028 Audio audio_;
3129 Musics musics_;
30+ bool is_mute_;
31+ int mix_volume_;
3232
3333
34- pImpl(void)
34+ pImpl(void) : is_mute_(false), mix_volume_(0)
3535 {
3636 Mix_HookMusicFinished(music_finished_callback);
3737 }
3838
3939
40-#if 0
41- // !!! 必要ならば musics_ を解放する
42- // !!! valgrind で警告がでなかったら、解放しなくてもよいことにしたい
4340 ~pImpl(void)
4441 {
42+ for (Musics::iterator it = musics_.begin(); it != musics_.end(); ++it) {
43+ Mix_FreeMusic(it->second);
44+ }
4545 }
46-#endif
4746
4847
49- static pImpl* object(void)
48+ static pImpl* singleton_object(void)
5049 {
51- static pImpl singleton_object;
52- return &singleton_object;
50+ static pImpl object_;
51+ return &object_;
5352 }
5453
5554
@@ -109,7 +108,7 @@
109108 int BackMusic::pImpl::next_play_times_ = 0;
110109
111110
112-BackMusic::BackMusic(void) : pimpl(pImpl::object())
111+BackMusic::BackMusic(void) : pimpl(pImpl::singleton_object())
113112 {
114113 }
115114
@@ -119,6 +118,26 @@
119118 }
120119
121120
121+void BackMusic::setMute(bool is_mute)
122+{
123+ pimpl->is_mute_ = is_mute;
124+ if (is_mute) {
125+ int saved_mix_volume = pimpl->mix_volume_;
126+ setVolume(0);
127+ pimpl->mix_volume_ = saved_mix_volume;
128+ } else {
129+ // ミュートする前の音量で再生を再開する
130+ setVolume(pimpl->mix_volume_);
131+ }
132+}
133+
134+
135+bool BackMusic::isMute(void) const
136+{
137+ return pimpl->is_mute_;
138+}
139+
140+
122141 void BackMusic::free_music_resource(const char* file_path)
123142 {
124143 if (!pimpl->audio_.isInitialized()) {
@@ -139,8 +158,10 @@
139158 return;
140159 }
141160
142- int mix_volume = static_cast<int>(MIX_MAX_VOLUME * percent / 100.0);
143- Mix_VolumeMusic(mix_volume);
161+ pimpl->mix_volume_ = static_cast<int>(MIX_MAX_VOLUME * percent / 100.0);
162+ if (!pimpl->is_mute_) {
163+ Mix_VolumeMusic(pimpl->mix_volume_);
164+ }
144165 }
145166
146167
--- trunk/libs/audio/sdl_mixer/SoundEffect.cpp (revision 1963)
+++ trunk/libs/audio/sdl_mixer/SoundEffect.cpp (revision 1964)
@@ -37,6 +37,7 @@
3737 static bool initialized_;
3838 static Channels channels_;
3939 static size_t master_percent_;
40+ static bool is_mute_;
4041 static ChunkMap mix_chunks_;
4142
4243 Audio audio_;
@@ -115,7 +116,7 @@
115116 (percent_ / 100.0) *
116117 (master_percent_ / 100.0));
117118 first_mix_volume_ = mix_volume;
118- if (isPlaying()) {
119+ if (isPlaying() && !is_mute_) {
119120 Mix_Volume(channel_id_, mix_volume);
120121 }
121122 }
@@ -125,6 +126,7 @@
125126 Channels SoundEffect::pImpl::channels_;
126127 ChunkMap SoundEffect::pImpl::mix_chunks_;
127128 size_t SoundEffect::pImpl::master_percent_ = DefaultVolumePercent;
129+bool SoundEffect::pImpl::is_mute_ = false;
128130
129131
130132 SoundEffect::SoundEffect(const char* play_file) : pimpl(new pImpl(play_file))
@@ -137,6 +139,24 @@
137139 }
138140
139141
142+void SoundEffect::setMute(bool is_mute)
143+{
144+ pimpl->is_mute_ = is_mute;
145+ if (is_mute) {
146+ Mix_Volume(-1, 0);
147+ } else {
148+ // ミュートする前の音量で再生を再開する
149+ setMasterVolume(pimpl->master_percent_);
150+ }
151+}
152+
153+
154+bool SoundEffect::isMute(void) const
155+{
156+ return pimpl->is_mute_;
157+}
158+
159+
140160 void SoundEffect::setMasterVolume(size_t percent)
141161 {
142162 pimpl->master_percent_ = min(percent, static_cast<size_t>(100));
--- trunk/libs/audio/BackMusic.h (revision 1963)
+++ trunk/libs/audio/BackMusic.h (revision 1964)
@@ -26,6 +26,9 @@
2626 BackMusic(void);
2727 ~BackMusic(void);
2828
29+ void setMute(bool is_mute);
30+ bool isMute(void) const;
31+
2932 void free_music_resource(const char* file_path);
3033
3134 void setVolume(size_t percent);
--- trunk/libs/audio/SoundEffect.h (revision 1963)
+++ trunk/libs/audio/SoundEffect.h (revision 1964)
@@ -23,6 +23,9 @@
2323 explicit SoundEffect(const char* play_file);
2424 ~SoundEffect(void);
2525
26+ void setMute(bool is_mute);
27+ bool isMute(void) const;
28+
2629 void setMasterVolume(size_t percent);
2730
2831 /*!
旧リポジトリブラウザで表示