]> git.mxchange.org Git - flightgear.git/blob - src/Sound/fg_sound.hxx
This is step "1" of probably "many" in the process of separating out the
[flightgear.git] / src / Sound / fg_sound.hxx
1 // fg_sound.hxx -- Sound class implementation
2 //
3 // Started by Erik Hofman, February 2002
4 //
5 // Copyright (C) 2002  Erik Hofman - erik@ehofman.com
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23 #ifndef __FGSOUND_HXX
24 #define __FGSOUND_HXX 1
25
26 #ifdef HAVE_CONFIG_H
27 #  include <config.h>
28 #endif
29
30 #include <simgear/compiler.h>
31 #include <simgear/props/condition.hxx>
32
33 #include <Main/fgfs.hxx>
34 #include <Main/globals.hxx>
35
36 #include "soundmgr.hxx"
37
38 static const double MAX_TRANSIT_TIME = 0.1;     // 100 ms.
39
40
41 /**
42  * Class for handling one sound event.
43  *
44  */
45 class FGSound
46 {
47
48 public:
49
50   FGSound();
51   virtual ~FGSound();
52
53   virtual void init (SGPropertyNode *);
54   virtual void bind ();
55   virtual void unbind ();
56   virtual void update (double dt);
57
58   void stop();
59
60 protected:
61
62   enum { MAXPROP=5 };
63   enum { ONCE=0, LOOPED, IN_TRANSIT };
64   enum { LEVEL=0, INVERTED, FLIPFLOP };
65
66   // Sound properties
67   typedef struct {
68         SGPropertyNode * prop;
69         double (*fn)(double);
70         double *intern;
71         double factor;
72         double offset;
73         double min;
74         double max;
75         bool subtract;
76   } _snd_prop;
77
78 private:
79
80   FGSoundMgr * _mgr;
81   FGSimpleSound * _sample;
82
83   FGCondition * _condition;
84   SGPropertyNode * _property;
85
86   bool _active;
87   string _name;
88   int _mode;
89   double _prev_value;
90   double _dt_play;
91   double _dt_stop;
92   double _stopping;     // time after the sound should have stopped.
93                         // This is usefull for lost packets in in-trasit mode.
94
95   vector<_snd_prop> _volume;
96   vector<_snd_prop> _pitch;
97
98 };
99
100 #endif