X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FInstrumentation%2Fmk_viii.cxx;h=9b0ee2b480428d5d32f0c16010907d18e914071d;hb=d15d2ad2703e0572e3b9a24d238d6089be1ec6b9;hp=065dc232ddf40f22d128408f4c77764a84da0989;hpb=dd7c88b8cb7bfd84dec3ce7dd0699a5652288b2a;p=flightgear.git diff --git a/src/Instrumentation/mk_viii.cxx b/src/Instrumentation/mk_viii.cxx index 065dc232d..9b0ee2b48 100644 --- a/src/Instrumentation/mk_viii.cxx +++ b/src/Instrumentation/mk_viii.cxx @@ -16,7 +16,7 @@ // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software -// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. // /////////////////////////////////////////////////////////////////////////////// // @@ -70,6 +70,7 @@ #include #include #include +#include #include using std::string; @@ -2133,266 +2134,6 @@ MK_VIII::IOHandler::set_present_status (bool value) } -/////////////////////////////////////////////////////////////////////////////// -// FGVoicePlayer ////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// - -void -FGVoicePlayer::PropertiesHandler::unbind () -{ - vector::iterator iter; - - for (iter = tied_properties.begin(); iter != tied_properties.end(); iter++) - (*iter)->untie(); - - tied_properties.clear(); -} - -void -FGVoicePlayer::Speaker::bind (SGPropertyNode *node) -{ - // uses xmlsound property names - tie(node, "volume", &volume); - tie(node, "pitch", &pitch); -} - -void -FGVoicePlayer::Speaker::update_configuration () -{ - map< string, SGSharedPtr >::iterator iter; - for (iter = player->samples.begin(); iter != player->samples.end(); iter++) - { - SGSoundSample *sample = (*iter).second; - - sample->set_pitch(pitch); - } - - if (player->voice) - player->voice->volume_changed(); -} - -FGVoicePlayer::Voice::~Voice () -{ - for (iter = elements.begin(); iter != elements.end(); iter++) - delete *iter; // we owned the element - elements.clear(); -} - -void -FGVoicePlayer::Voice::play () -{ - iter = elements.begin(); - element = *iter; - - element->play(get_volume()); -} - -void -FGVoicePlayer::Voice::stop (bool now) -{ - if (element) - { - if (now || element->silence) - { - element->stop(); - element = NULL; - } - else - iter = elements.end() - 1; // stop after the current element finishes - } -} - -void -FGVoicePlayer::Voice::set_volume (float _volume) -{ - volume = _volume; - volume_changed(); -} - -void -FGVoicePlayer::Voice::volume_changed () -{ - if (element) - element->set_volume(get_volume()); -} - -void -FGVoicePlayer::Voice::update () -{ - if (element) - { - if (! element->is_playing()) - { - if (++iter == elements.end()) - element = NULL; - else - { - element = *iter; - element->play(get_volume()); - } - } - } -} - -FGVoicePlayer::~FGVoicePlayer () -{ - vector::iterator iter1; - for (iter1 = _voices.begin(); iter1 != _voices.end(); iter1++) - delete *iter1; - _voices.clear(); - samples.clear(); -} - -void -FGVoicePlayer::bind (SGPropertyNode *node, const char* default_dir_prefix) -{ - dir_prefix = node->getStringValue("voice/file-prefix", default_dir_prefix); - speaker.bind(node); -} - -void -FGVoicePlayer::init () -{ - SGSoundMgr *smgr = globals->get_soundmgr(); - _sgr = smgr->find("avionics", true); - _sgr->tie_to_listener(); - speaker.update_configuration(); -} - -void -FGVoicePlayer::pause() -{ - if (paused) - return; - - paused = true; - if (voice) - { - voice->stop(true); - } -} - -void -FGVoicePlayer::resume() -{ - if (!paused) - return; - paused = false; - if (voice) - { - voice->play(); - } -} - -SGSoundSample * -FGVoicePlayer::get_sample (const char *name) -{ - string refname; - refname = dev_name + "/" + dir_prefix + name; - - SGSoundSample *sample = _sgr->find(refname); - if (! sample) - { - string filename = dir_prefix + string(name) + ".wav"; - try - { - sample = new SGSoundSample(filename.c_str(), SGPath()); - } - catch (const sg_exception &e) - { - SG_LOG(SG_INSTR, SG_ALERT, "Error loading sound sample \"" + filename + "\": " + e.getFormattedMessage()); - exit(1); - } - - _sgr->add(sample, refname); - samples[refname] = sample; - } - - return sample; -} - -void -FGVoicePlayer::play (Voice *_voice, unsigned int flags) -{ - if (!_voice) - return; - if (test_bits(flags, PLAY_NOW) || ! voice || - (voice->element && voice->element->silence)) - { - if (voice) - voice->stop(true); - - voice = _voice; - looped = test_bits(flags, PLAY_LOOPED); - - next_voice = NULL; - next_looped = false; - - if (!paused) - voice->play(); - } - else - { - next_voice = _voice; - next_looped = test_bits(flags, PLAY_LOOPED); - } -} - -void -FGVoicePlayer::stop (unsigned int flags) -{ - if (voice) - { - voice->stop(test_bits(flags, STOP_NOW)); - if (voice->element) - looped = false; - else - voice = NULL; - next_voice = NULL; - } -} - -void -FGVoicePlayer::set_volume (float _volume) -{ - volume = _volume; - if (voice) - voice->volume_changed(); -} - -void -FGVoicePlayer::update () -{ - if (voice) - { - voice->update(); - - if (next_voice) - { - if (! voice->element || voice->element->silence) - { - voice = next_voice; - looped = next_looped; - - next_voice = NULL; - next_looped = false; - - voice->play(); - } - } - else - { - if (! voice->element) - { - if (looped) - voice->play(); - else - voice = NULL; - } - } - } -} - /////////////////////////////////////////////////////////////////////////////// // MK_VIII::VoicePlayer /////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////