- ///////////////////////////////////////////////////////////////////////////
- // MK_VIII::VoicePlayer::Voice ////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////
-
- class Voice
- {
- public:
-
- /////////////////////////////////////////////////////////////////////////
- // MK_VIII::VoicePlayer::Voice::Element ////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////
-
- class Element
- {
- public:
- bool silence;
-
- virtual inline void play (float volume) {}
- virtual inline void stop () {}
- virtual bool is_playing () = 0;
- virtual inline void set_volume (float volume) {}
- };
-
- /////////////////////////////////////////////////////////////////////////
- // MK_VIII::VoicePlayer::Voice::SampleElement ///////////////////////////
- /////////////////////////////////////////////////////////////////////////
-
- class SampleElement : public Element
- {
- SGSoundSample *_sample;
- float _volume;
-
- public:
- inline SampleElement (SGSoundSample *sample, float volume = 1.0)
- : _sample(sample), _volume(volume) { silence = false; }
-
- virtual inline void play (float volume) { if (_sample && (volume > 0.05)) { set_volume(volume); _sample->play_once(); } }
- virtual inline void stop () { if (_sample) _sample->stop(); }
- virtual inline bool is_playing () { return _sample ? _sample->is_playing() : false; }
- virtual inline void set_volume (float volume) { if (_sample) _sample->set_volume(volume * _volume); }
- };
-
- /////////////////////////////////////////////////////////////////////////
- // MK_VIII::VoicePlayer::Voice::SilenceElement //////////////////////////
- /////////////////////////////////////////////////////////////////////////
-
- class SilenceElement : public Element
- {
- double _duration;
- double start_time;
-
- public:
- inline SilenceElement (double duration)
- : _duration(duration) { silence = true; }
-
- virtual inline void play (float volume) { start_time = globals->get_sim_time_sec(); }
- virtual inline bool is_playing () { return globals->get_sim_time_sec() - start_time < _duration; }
- };
-
- /////////////////////////////////////////////////////////////////////////
- // MK_VIII::VoicePlayer::Voice (continued) //////////////////////////////
- /////////////////////////////////////////////////////////////////////////
-
- Element *element;
-
- inline Voice (VoicePlayer *_player)
- : element(NULL), player(_player), volume(1.0) {}
-
- ~Voice ();
-
- inline void append (Element *_element) { elements.push_back(_element); }
-
- void play ();
- void stop (bool now);
- void set_volume (float _volume);
- void volume_changed ();
- void update ();
-
- private:
- VoicePlayer *player;
-
- float volume;
-
- vector<Element *> elements;
- vector<Element *>::iterator iter;
-
- inline float get_volume () const { return player->volume * player->speaker.volume * volume; }
- };
-
- ///////////////////////////////////////////////////////////////////////////
- // MK_VIII::VoicePlayer (continued) ///////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////
-
- struct
- {
- float volume;
- } conf;
-
- float volume;
-
- Voice *voice;
- Voice *next_voice;
-
- struct
- {
- Voice *application_data_base_failed;
- Voice *bank_angle;
- Voice *bank_angle_bank_angle;
- Voice *bank_angle_bank_angle_3;
- Voice *bank_angle_inop;
- Voice *bank_angle_pause_bank_angle;
- Voice *bank_angle_pause_bank_angle_3;
- Voice *callouts_inop;
- Voice *configuration_type_invalid;
- Voice *dont_sink;
- Voice *dont_sink_pause_dont_sink;
- Voice *five_hundred_above;
- Voice *glideslope;
- Voice *glideslope_inop;
- Voice *gpws_inop;
- Voice *hard_glideslope;
- Voice *minimums;
- Voice *minimums_minimums;
- Voice *pull_up;
- Voice *sink_rate;
- Voice *sink_rate_pause_sink_rate;
- Voice *soft_glideslope;
- Voice *terrain;
- Voice *terrain_pause_terrain;
- Voice *too_low_flaps;
- Voice *too_low_gear;
- Voice *too_low_terrain;
- Voice *altitude_callouts[n_altitude_callouts];
- } voices;
-
- inline VoicePlayer (MK_VIII *device)
- : voice(NULL), next_voice(NULL), mk(device), speaker(this) {}
-
- ~VoicePlayer ();
-
- void init ();
-
- enum
- {
- PLAY_NOW = 1 << 0,
- PLAY_LOOPED = 1 << 1
- };
- void play (Voice *_voice, unsigned int flags = 0);
-
- enum
- {
- STOP_NOW = 1 << 0
- };
- void stop (unsigned int flags = 0);
-
- void set_volume (float _volume);
- void update ();
-
- inline void bind (SGPropertyNode *node) { speaker.bind(node); }
-
- public:
-
- ///////////////////////////////////////////////////////////////////////////
- // MK_VIII::VoicePlayer::Speaker //////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////
-
- class Speaker
- {
- VoicePlayer *player;
-
- double pitch;
-
- template <class T>
- inline void tie (SGPropertyNode *node, const char *name, T *ptr)
- {
- player->mk->properties_handler.tie
- (node, (string("speaker/") + name).c_str(),
- RawValueMethodsData<MK_VIII::VoicePlayer::Speaker,T,T*>
- (*this, ptr,
- &MK_VIII::VoicePlayer::Speaker::get_property,
- &MK_VIII::VoicePlayer::Speaker::set_property));
- }
-
- public:
- template <class T>
- inline void set_property (T *ptr, T value) { *ptr = value; update_configuration(); }
-
- template <class T>
- inline T get_property (T *ptr) const { return *ptr; }
-
- float volume;