/[svn]/linuxsampler/trunk/src/modulationsystem.h
ViewVC logotype

Diff of /linuxsampler/trunk/src/modulationsystem.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 30 by schoenebeck, Sun Jan 11 16:43:54 2004 UTC revision 38 by schoenebeck, Tue Mar 16 13:25:39 2004 UTC
# Line 25  Line 25 
25    
26  #include "global.h"  #include "global.h"
27    
28    /**
29     * Handles modulation parameters and events for the current audio fragment.
30     *
31     * TODO: class should better be renamed to 'EventSystem' or even better: most of the attributes here could be moved into the engine and everything left would just be class Event (thus -> event.h and event.cpp), but that can wait until we restructe the source tree for multi engine support
32     */
33  class ModulationSystem {  class ModulationSystem {
34      public:      public:
35          enum destination_t {          enum destination_t {
36              destination_vca,   ///< Volume level              destination_vca,   ///< Volume level
37              destination_count  ///< Total number of modulation sources (this has to stay the last element in the enum)              destination_vco,   ///< Pitch depth
38                destination_vcfc,  ///< Filter curoff frequency
39                destination_vcfr,  ///< Filter resonance
40                destination_count  ///< Total number of modulation destinations (this has to stay the last element in the enum)
41          };          };
42          enum source_t {          typedef uint32_t real_time_t; ///< We read the processor's cycle count register as a reference for the real time. These are of course only abstract values with arbitrary time entity, but that's not a problem as we calculate relatively.
43              source_eg1,   ///< Envelope Generator 1          enum event_type_t {
44              source_count  ///< Total number of modulation sources (this has to stay the last element in the enum)              event_type_note_on,
45                event_type_note_off,
46                event_type_pitchbend,
47                event_type_control_change,
48                event_type_cancel_release,  ///< transformed either from a note-on or sustain-pedal-down event
49                event_type_release          ///< transformed either from a note-off or sustain-pedal-up event
50            };
51            class Event {
52                public:
53                    event_type_t Type;
54                    union {
55                        uint8_t Key;          ///< MIDI key number for note-on and note-off events.
56                        uint8_t Controller;   ///< MIDI controller number for control change events.
57                    };
58                    union {
59                        uint8_t Velocity;     ///< Trigger or release velocity for note-on or note-off events.
60                        uint8_t Value;        ///< Value for control change events.
61                    };
62                    int16_t Pitch;            ///< Pitch value for pitchbend events.
63    
64                    Event() {
65                        TimeStamp = ModulationSystem::CreateTimeStamp();
66                        iFragmentPos = -1;
67                    }
68                    inline uint FragmentPos() {
69                        if (iFragmentPos >= 0) return (uint) iFragmentPos;
70                        return (uint) (iFragmentPos = ModulationSystem::ToFragmentPos(TimeStamp));
71                    }
72                private:
73                    real_time_t TimeStamp;    ///< Time stamp of the event's occurence.
74                    int         iFragmentPos; ///< Position in the current fragment this event refers to.
75          };          };
76    
77          static float** pDestinationParameter;          static float** pDestinationParameter;
         //static bool    DestinationParameterModified;  
78    
79          static        void Initialize(uint SampleRate, uint FragmentSize);          static        void  Initialize(uint SampleRate, uint MaxSamplesPerCycle);
80          static        void Close();          static        void  Close();
81          static        void ResetDestinationParameter(ModulationSystem::destination_t dst, float val);          static        void  ResetDestinationParameter(ModulationSystem::destination_t dst, float val);
82          static inline uint GetFragmentSize() { return FragmentSize; };          static        void  UpdateFragmentTime();
83          static inline uint GetSampleRate()   { return SampleRate;   };          static real_time_t  CreateTimeStamp();
84            static inline uint  MaxSamplesPerCycle()                  { return uiMaxSamplesPerCycle; }
85            static inline uint  SampleRate()                          { return uiSampleRate;         }
86            static inline uint  ToFragmentPos(real_time_t time_stamp) {
87                return uint ((time_stamp - FragmentTime.begin) * FragmentTime.sample_ratio);
88            }
89      protected:      protected:
90          static uint FragmentSize;          static uint uiMaxSamplesPerCycle;
91          static uint SampleRate;          static uint uiSampleRate;
92            static struct __FragmentTime__ {
93                real_time_t begin;         ///< Real time stamp of the beginning of this audio fragment cycle.
94                real_time_t end;           ///< Real time stamp of the end of this audio fragment cycle.
95                float       sample_ratio;  ///< (Samples per cycle) / (Real time duration of cycle)
96            } FragmentTime;
97  };  };
98    
99  #endif // __MODULATION_SYSTEM_H__  #endif // __MODULATION_SYSTEM_H__

Legend:
Removed from v.30  
changed lines
  Added in v.38

  ViewVC Help
Powered by ViewVC