//
// 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.
//
///////////////////////////////////////////////////////////////////////////////
//
}
-///////////////////////////////////////////////////////////////////////////////
-// FGVoicePlayer //////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-
-void
-FGVoicePlayer::PropertiesHandler::unbind ()
-{
- vector<SGPropertyNode_ptr>::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<SGSoundSample> >::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<Voice *>::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 ///////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////