X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FInstrumentation%2Fmk_viii.hxx;h=25b50c3e4f08464cd3febe3c28d61a72490a70d4;hb=fe0a703a192a37b96aa4f6048c8e542c24671705;hp=053b53d051a4016ffdb69e4c1f3b343a572e0642;hpb=dd7c88b8cb7bfd84dec3ce7dd0699a5652288b2a;p=flightgear.git diff --git a/src/Instrumentation/mk_viii.hxx b/src/Instrumentation/mk_viii.hxx index 053b53d05..25b50c3e4 100644 --- a/src/Instrumentation/mk_viii.hxx +++ b/src/Instrumentation/mk_viii.hxx @@ -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. #ifndef __INSTRUMENTS_MK_VIII_HXX @@ -29,9 +29,8 @@ #include #include -#include +#include #include - using std::vector; using std::deque; using std::map; @@ -41,300 +40,13 @@ class SGSampleGroup; #include #include #include
+#include #ifdef _MSC_VER # pragma warning( push ) # pragma warning( disable: 4355 ) #endif -///////////////////////////////////////////////////////////////////////////// -// FGVoicePlayer ///////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// - -class FGVoicePlayer -{ -public: - - ///////////////////////////////////////////////////////////////////////////// - // MK::RawValueMethodsData ///////////////////////////////////////////// - ///////////////////////////////////////////////////////////////////////////// - - template - class RawValueMethodsData : public SGRawValue - { - public: - typedef VT (C::*getter_t) (DT) const; - typedef void (C::*setter_t) (DT, VT); - - RawValueMethodsData (C &obj, DT data, getter_t getter = 0, setter_t setter = 0) - : _obj(obj), _data(data), _getter(getter), _setter(setter) {} - - virtual VT getValue () const - { - if (_getter) - return (_obj.*_getter)(_data); - else - return SGRawValue::DefaultValue(); - } - virtual bool setValue (VT value) - { - if (_setter) - { - (_obj.*_setter)(_data, value); - return true; - } - else - return false; - } - virtual SGRawValue *clone () const - { - return new RawValueMethodsData(_obj, _data, _getter, _setter); - } - - private: - C &_obj; - DT _data; - getter_t _getter; - setter_t _setter; - }; - - class PropertiesHandler - { - public: - vector tied_properties; - - template - inline void tie (SGPropertyNode *node, const SGRawValue &raw_value) - { - node->tie(raw_value); - tied_properties.push_back(node); - } - - template - inline void tie (SGPropertyNode *node, - const char *relative_path, - const SGRawValue &raw_value) - { - tie(node->getNode(relative_path, true), raw_value); - } - - PropertiesHandler() {}; - - void unbind (); - }; - - /////////////////////////////////////////////////////////////////////////// - // FGVoicePlayer::Voice //////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////// - - class Voice - { - public: - - ///////////////////////////////////////////////////////////////////////// - // FGVoicePlayer::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) {} - }; - - ///////////////////////////////////////////////////////////////////////// - // FGVoicePlayer::Voice::SampleElement /////////////////////////// - ///////////////////////////////////////////////////////////////////////// - - class SampleElement : public Element - { - SGSharedPtr _sample; - float _volume; - - public: - inline SampleElement (SGSharedPtr 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); } - }; - - ///////////////////////////////////////////////////////////////////////// - // FGVoicePlayer::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; } - }; - - ///////////////////////////////////////////////////////////////////////// - // FGVoicePlayer::Voice (continued) ////////////////////////////// - ///////////////////////////////////////////////////////////////////////// - - Element *element; - - inline Voice (FGVoicePlayer *_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: - FGVoicePlayer *player; - - float volume; - - vector elements; - vector::iterator iter; - - inline float get_volume () const { return player->volume * player->speaker.volume * volume; } - }; - - /////////////////////////////////////////////////////////////////////////// - // FGVoicePlayer (continued) /////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////// - - struct - { - float volume; - } conf; - - float volume; - - Voice *voice; - Voice *next_voice; - bool paused; - string dev_name; - string dir_prefix; - - inline FGVoicePlayer (PropertiesHandler* properties_handler, string _dev_name) - : volume(1.0), voice(NULL), next_voice(NULL), paused(false), - dev_name(_dev_name), dir_prefix(""), - speaker(this,properties_handler) {} - - ~FGVoicePlayer (); - - void init (); - void pause(); - void resume(); - bool is_playing() { return (voice!=NULL);} - - 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 (); - - void bind (SGPropertyNode *node, const char* default_dir_prefix); - -public: - - /////////////////////////////////////////////////////////////////////////// - // FGVoicePlayer::Speaker ////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////// - - class Speaker - { - FGVoicePlayer *player; - PropertiesHandler* properties_handler; - - double pitch; - - template - inline void tie (SGPropertyNode *node, const char *name, T *ptr) - { - properties_handler->tie - (node, (string("speaker/") + name).c_str(), - RawValueMethodsData - (*this, ptr, - &FGVoicePlayer::Speaker::get_property, - &FGVoicePlayer::Speaker::set_property)); - } - - public: - template - inline void set_property (T *ptr, T value) { *ptr = value; update_configuration(); } - - template - inline T get_property (T *ptr) const { return *ptr; } - - float volume; - - inline Speaker (FGVoicePlayer *_player,PropertiesHandler* _properties_handler) - : player(_player), - properties_handler(_properties_handler), - pitch(1), - volume(1) - { - } - - void bind (SGPropertyNode *node); - void update_configuration (); - }; - -protected: - /////////////////////////////////////////////////////////////////////////// - // FGVoicePlayer (continued) /////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////// - - SGSharedPtr _sgr; - Speaker speaker; - - map< string, SGSharedPtr > samples; - vector _voices; - - bool looped; - bool next_looped; - - SGSoundSample *get_sample (const char *name); - - inline void append (Voice *voice, Voice::Element *element) { voice->append(element); } - inline void append (Voice *voice, const char *sample_name) { voice->append(new Voice::SampleElement(get_sample(sample_name))); } - inline void append (Voice *voice, double silence) { voice->append(new Voice::SilenceElement(silence)); } - - inline void make_voice (Voice **voice) { *voice = new Voice(this); _voices.push_back(*voice); } - - template - inline void make_voice (Voice **voice, T1 e1) { make_voice(voice); append(*voice, e1); } - template - inline void make_voice (Voice **voice, T1 e1, T2 e2) { make_voice(voice, e1); append(*voice, e2); } - template - inline void make_voice (Voice **voice, T1 e1, T2 e2, T3 e3) { make_voice(voice, e1, e2); append(*voice, e3); } - template - inline void make_voice (Voice **voice, T1 e1, T2 e2, T3 e3, T4 e4) { make_voice(voice, e1, e2, e3); append(*voice, e4); } -}; /////////////////////////////////////////////////////////////////////////////// // MK_VIII ////////////////////////////////////////////////////////////////////