--- linuxsampler/trunk/src/engines/common/Event.h 2004/09/17 01:01:11 244 +++ linuxsampler/trunk/src/engines/common/Event.h 2005/02/26 22:44:51 412 @@ -24,6 +24,8 @@ #define __LS_EVENT_H__ #include "../../common/global.h" +#include "../../common/RTMath.h" +#include "EngineChannel.h" namespace LinuxSampler { @@ -40,9 +42,9 @@ void UpdateFragmentTime(uint SamplesToProcess); Event CreateEvent(); protected: - typedef uint32_t time_stamp_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. - inline uint ToFragmentPos(time_stamp_t TimeStamp) { - return uint ((TimeStamp - FragmentTime.begin) * FragmentTime.sample_ratio); + typedef RTMath::time_stamp_t time_stamp_t; + inline int32_t ToFragmentPos(time_stamp_t TimeStamp) { + return int32_t (int32_t(TimeStamp - FragmentTime.begin) * FragmentTime.sample_ratio); } friend class Event; private: @@ -53,7 +55,6 @@ time_stamp_t end; ///< Real time stamp of the end of this audio fragment cycle. float sample_ratio; ///< (Samples per cycle) / (Real time duration of cycle) } FragmentTime; - time_stamp_t CreateTimeStamp(); }; /** @@ -83,21 +84,37 @@ destination_count ///< Total number of modulation destinations (this has to stay the last element in the enum) }; union { - uint8_t Key; ///< MIDI key number for note-on and note-off events. - uint8_t Controller; ///< MIDI controller number for control change events. - }; - union { - uint8_t Velocity; ///< Trigger or release velocity for note-on or note-off events. - uint8_t Value; ///< Value for control change events. - }; - union { - int16_t Pitch; ///< Pitch value for pitchbend events. - uint Size; ///< Data length (in bytes) for MIDI system exclusive messages. - }; - - inline uint FragmentPos() { - if (iFragmentPos >= 0) return (uint) iFragmentPos; - return (uint) (iFragmentPos = pEventGenerator->ToFragmentPos(TimeStamp)); + /// Note-on and note-off event specifics + struct _Note { + uint8_t Key; ///< MIDI key number of note-on / note-off event. + uint8_t Velocity; ///< Trigger or release velocity of note-on / note-off event. + int8_t Layer; ///< Layer index (usually only used if a note-on event has to be postponed, e.g. due to shortage of free voices). + int8_t ReleaseTrigger; ///< If new voice should be a release triggered voice (actually boolean field and usually only used if a note-on event has to be postponed, e.g. due to shortage of free voices). + } Note; + /// Control change event specifics + struct _CC { + uint8_t Controller; ///< MIDI controller number of control change event. + uint8_t Value; ///< Controller Value of control change event. + } CC; + /// Pitchbend event specifics + struct _Pitch { + int16_t Pitch; ///< Pitch value of pitchbend event. + } Pitch; + /// MIDI system exclusive event specifics + struct _Sysex { + uint Size; ///< Data length (in bytes) of MIDI system exclusive message. + } Sysex; + } Param; + EngineChannel* pEngineChannel; ///< Pointer to the EngineChannel where this event occured on, NULL means Engine global event (e.g. SysEx message). + + inline int32_t FragmentPos() { + if (iFragmentPos >= 0) return iFragmentPos; + iFragmentPos = pEventGenerator->ToFragmentPos(TimeStamp); + if (iFragmentPos < 0) iFragmentPos = 0; // if event arrived shortly before the beginning of current fragment + return iFragmentPos; + } + inline void ResetFragmentPos() { + iFragmentPos = -1; } protected: typedef EventGenerator::time_stamp_t time_stamp_t; @@ -106,7 +123,7 @@ private: EventGenerator* pEventGenerator; ///< Creator of the event. time_stamp_t TimeStamp; ///< Time stamp of the event's occurence. - int iFragmentPos; ///< Position in the current fragment this event refers to. + int32_t iFragmentPos; ///< Position in the current fragment this event refers to. }; } // namespace LinuxSampler