--- linuxsampler/trunk/src/engines/common/Event.h 2005/02/26 22:44:51 412 +++ linuxsampler/trunk/src/engines/common/Event.h 2014/06/06 12:38:54 2598 @@ -3,6 +3,7 @@ * LinuxSampler - modular, streaming capable sampler * * * * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * + * Copyright (C) 2005 - 2014 Christian Schoenebeck * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -25,7 +26,7 @@ #include "../../common/global.h" #include "../../common/RTMath.h" -#include "EngineChannel.h" +#include "../EngineChannel.h" namespace LinuxSampler { @@ -41,6 +42,7 @@ EventGenerator(uint SampleRate); void UpdateFragmentTime(uint SamplesToProcess); Event CreateEvent(); + Event CreateEvent(int32_t FragmentPos); protected: typedef RTMath::time_stamp_t time_stamp_t; inline int32_t ToFragmentPos(time_stamp_t TimeStamp) { @@ -59,10 +61,10 @@ /** * Events are usually caused by a MIDI source or an internal modulation - * controller like LFO or EG. An event can only be created by an - * EventGenerator. + * controller like LFO or EG. An event should only be created by an + * EventGenerator! * - * @see EventGenerator + * @see EventGenerator, ScriptEvent */ class Event { public: @@ -74,38 +76,49 @@ type_control_change, type_sysex, ///< MIDI system exclusive message type_cancel_release, ///< transformed either from a note-on or sustain-pedal-down event - type_release ///< transformed either from a note-off or sustain-pedal-up event + type_release, ///< transformed either from a note-off or sustain-pedal-up event + type_channel_pressure, ///< a.k.a. aftertouch + type_note_pressure, ///< polyphonic key pressure (aftertouch) } Type; - enum destination_t { - destination_vca, ///< Volume level - destination_vco, ///< Pitch depth - destination_vcfc, ///< Filter curoff frequency - destination_vcfr, ///< Filter resonance - destination_count ///< Total number of modulation destinations (this has to stay the last element in the enum) - }; union { /// 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. + uint8_t Channel; ///< MIDI channel (0..15) 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). + void* pRegion; ///< Engine specific pointer to instrument region } 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. + uint8_t Channel; ///< MIDI channel (0..15) } CC; /// Pitchbend event specifics struct _Pitch { int16_t Pitch; ///< Pitch value of pitchbend event. + uint8_t Channel; ///< MIDI channel (0..15) } Pitch; /// MIDI system exclusive event specifics struct _Sysex { uint Size; ///< Data length (in bytes) of MIDI system exclusive message. } Sysex; + /// Channel Pressure (aftertouch) event specifics + struct _ChannelPressure { + uint8_t Value; ///< New aftertouch / pressure value for keys on that channel. + uint8_t Channel; ///< MIDI channel (0..15) + } ChannelPressure; + /// Polyphonic Note Pressure (aftertouch) event specifics + struct _NotePressure { + uint8_t Key; ///< MIDI note number where key pressure (polyphonic aftertouch) changed. + uint8_t Value; ///< New pressure value for note. + uint8_t Channel; ///< MIDI channel (0..15) + } NotePressure; } Param; EngineChannel* pEngineChannel; ///< Pointer to the EngineChannel where this event occured on, NULL means Engine global event (e.g. SysEx message). + MidiInputPort* pMidiInputPort; ///< Pointer to the MIDI input port on which this event occured (NOTE: currently only for global events, that is SysEx messages) inline int32_t FragmentPos() { if (iFragmentPos >= 0) return iFragmentPos; @@ -119,6 +132,7 @@ protected: typedef EventGenerator::time_stamp_t time_stamp_t; Event(EventGenerator* pGenerator, EventGenerator::time_stamp_t Time); + Event(EventGenerator* pGenerator, int32_t FragmentPos); friend class EventGenerator; private: EventGenerator* pEventGenerator; ///< Creator of the event. @@ -126,6 +140,24 @@ int32_t iFragmentPos; ///< Position in the current fragment this event refers to. }; + class VMEventHandler; + class VMExecContext; + + /** @brief Real-time instrument script event. + * + * Encapsulates one execution instance of a real-time instrument script for + * exactly one script event handler (script event callback). + */ + class ScriptEvent { + public: + Event cause; ///< Original external event that triggered this script event (i.e. MIDI note on event, MIDI CC event, etc.). + int id; ///< Unique ID of the external event that triggered this cript event. + VMEventHandler** handlers; ///< The script's event handlers (callbacks) to be processed (NULL terminated list). + VMExecContext* execCtx; ///< Script's current execution state (polyphonic variables and execution stack). + int currentHandler; ///< Current index in 'handlers' list above. + int executionSlices; ///< Amount of times this script event has been executed by the ScriptVM runner class. + }; + } // namespace LinuxSampler #endif // __LS_EVENT_H__