/[svn]/linuxsampler/trunk/src/engines/common/Event.h
ViewVC logotype

Annotation of /linuxsampler/trunk/src/engines/common/Event.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2600 - (hide annotations) (download) (as text)
Sat Jun 7 00:16:03 2014 UTC (9 years, 10 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 9267 byte(s)
* Implemented built-in instrument script function "set_controller()".
* Fixed built-in script functions "ignore_event()" and
  "ignore_controller()".
* Added extended instrument script VM for the Gigasampler/GigaStudio format
  sampler engine, which extends the general instrument script VM with Giga
  format specific variables and functions.
* Giga format instrument scripts: added built-in script int constant
  variables $GIG_DIM_CHANNEL, $GIG_DIM_LAYER, $GIG_DIM_VELOCITY,
  $GIG_DIM_AFTERTOUCH, $GIG_DIM_RELEASE, $GIG_DIM_KEYBOARD,
  $GIG_DIM_ROUNDROBIN, $GIG_DIM_RANDOM, $GIG_DIM_SMARTMIDI,
  $GIG_DIM_ROUNDROBINKEY, $GIG_DIM_MODWHEEL, $GIG_DIM_BREATH,
  $GIG_DIM_FOOT, $GIG_DIM_PORTAMENTOTIME, $GIG_DIM_EFFECT1,
  $GIG_DIM_EFFECT2, $GIG_DIM_GENPURPOSE1, $GIG_DIM_GENPURPOSE2,
  $GIG_DIM_GENPURPOSE3, $GIG_DIM_GENPURPOSE4, $GIG_DIM_SUSTAIN,
  $GIG_DIM_PORTAMENTO, $GIG_DIM_SOSTENUTO, $GIG_DIM_SOFT,
  $GIG_DIM_GENPURPOSE5, $GIG_DIM_GENPURPOSE6, $GIG_DIM_GENPURPOSE7,
  $GIG_DIM_GENPURPOSE8, $GIG_DIM_EFFECT1DEPTH, $GIG_DIM_EFFECT2DEPTH,
  $GIG_DIM_EFFECT3DEPTH, $GIG_DIM_EFFECT4DEPTH, $GIG_DIM_EFFECT5DEPTH.
* Giga format instrument scripts: Implemented built-in script function
  "gig_set_dim_zone(event_id, dimension, zone)", which allows to override
  dimension zone(s) for new voices.
* Bumped version (1.0.0.svn45).

1 schoenebeck 53 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5 schoenebeck 56 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 2559 * Copyright (C) 2005 - 2014 Christian Schoenebeck *
7 schoenebeck 53 * *
8     * This program is free software; you can redistribute it and/or modify *
9     * it under the terms of the GNU General Public License as published by *
10     * the Free Software Foundation; either version 2 of the License, or *
11     * (at your option) any later version. *
12     * *
13     * This program is distributed in the hope that it will be useful, *
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16     * GNU General Public License for more details. *
17     * *
18     * You should have received a copy of the GNU General Public License *
19     * along with this program; if not, write to the Free Software *
20     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21     * MA 02111-1307 USA *
22     ***************************************************************************/
23    
24     #ifndef __LS_EVENT_H__
25     #define __LS_EVENT_H__
26    
27     #include "../../common/global.h"
28 schoenebeck 328 #include "../../common/RTMath.h"
29 schoenebeck 890 #include "../EngineChannel.h"
30 schoenebeck 53
31     namespace LinuxSampler {
32    
33     // just symbol prototyping
34     class Event;
35    
36     /**
37     * Generates Event objects and is responsible for resolving the position
38     * in the current audio fragment each Event actually belongs to.
39     */
40     class EventGenerator {
41     public:
42     EventGenerator(uint SampleRate);
43     void UpdateFragmentTime(uint SamplesToProcess);
44     Event CreateEvent();
45 schoenebeck 906 Event CreateEvent(int32_t FragmentPos);
46 schoenebeck 53 protected:
47 schoenebeck 328 typedef RTMath::time_stamp_t time_stamp_t;
48 schoenebeck 293 inline int32_t ToFragmentPos(time_stamp_t TimeStamp) {
49     return int32_t (int32_t(TimeStamp - FragmentTime.begin) * FragmentTime.sample_ratio);
50 schoenebeck 53 }
51     friend class Event;
52     private:
53     uint uiSampleRate;
54     uint uiSamplesProcessed;
55     struct __FragmentTime__ {
56     time_stamp_t begin; ///< Real time stamp of the beginning of this audio fragment cycle.
57     time_stamp_t end; ///< Real time stamp of the end of this audio fragment cycle.
58     float sample_ratio; ///< (Samples per cycle) / (Real time duration of cycle)
59     } FragmentTime;
60     };
61    
62     /**
63     * Events are usually caused by a MIDI source or an internal modulation
64 schoenebeck 906 * controller like LFO or EG. An event should only be created by an
65     * EventGenerator!
66 schoenebeck 53 *
67 schoenebeck 2594 * @see EventGenerator, ScriptEvent
68 schoenebeck 53 */
69     class Event {
70     public:
71     Event(){}
72     enum type_t {
73     type_note_on,
74     type_note_off,
75     type_pitchbend,
76     type_control_change,
77 schoenebeck 244 type_sysex, ///< MIDI system exclusive message
78 schoenebeck 53 type_cancel_release, ///< transformed either from a note-on or sustain-pedal-down event
79 schoenebeck 2559 type_release, ///< transformed either from a note-off or sustain-pedal-up event
80     type_channel_pressure, ///< a.k.a. aftertouch
81     type_note_pressure, ///< polyphonic key pressure (aftertouch)
82 schoenebeck 53 } Type;
83     union {
84 schoenebeck 246 /// Note-on and note-off event specifics
85     struct _Note {
86 schoenebeck 2600 uint8_t Channel; ///< MIDI channel (0..15)
87 schoenebeck 246 uint8_t Key; ///< MIDI key number of note-on / note-off event.
88     uint8_t Velocity; ///< Trigger or release velocity of note-on / note-off event.
89 schoenebeck 250 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).
90     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).
91 persson 2101 void* pRegion; ///< Engine specific pointer to instrument region
92 schoenebeck 246 } Note;
93     /// Control change event specifics
94     struct _CC {
95 schoenebeck 2600 uint8_t Channel; ///< MIDI channel (0..15)
96 schoenebeck 246 uint8_t Controller; ///< MIDI controller number of control change event.
97     uint8_t Value; ///< Controller Value of control change event.
98     } CC;
99     /// Pitchbend event specifics
100     struct _Pitch {
101 schoenebeck 2600 uint8_t Channel; ///< MIDI channel (0..15)
102 schoenebeck 246 int16_t Pitch; ///< Pitch value of pitchbend event.
103     } Pitch;
104     /// MIDI system exclusive event specifics
105     struct _Sysex {
106     uint Size; ///< Data length (in bytes) of MIDI system exclusive message.
107     } Sysex;
108 schoenebeck 2559 /// Channel Pressure (aftertouch) event specifics
109     struct _ChannelPressure {
110 schoenebeck 2600 uint8_t Channel; ///< MIDI channel (0..15)
111 schoenebeck 2559 uint8_t Value; ///< New aftertouch / pressure value for keys on that channel.
112     } ChannelPressure;
113     /// Polyphonic Note Pressure (aftertouch) event specifics
114     struct _NotePressure {
115 schoenebeck 2600 uint8_t Channel; ///< MIDI channel (0..15)
116 schoenebeck 2559 uint8_t Key; ///< MIDI note number where key pressure (polyphonic aftertouch) changed.
117     uint8_t Value; ///< New pressure value for note.
118     } NotePressure;
119 schoenebeck 246 } Param;
120 schoenebeck 2600 /// Sampler format specific informations and variables.
121     union {
122     /// Gigasampler/GigaStudio format specifics.
123     struct _Gig {
124     uint8_t DimMask; ///< May be used to override the Dimension zone to be selected for a new voice: each 1 bit means that respective bit shall be overridden by taking the respective bit from DimBits instead.
125     uint8_t DimBits; ///< Used only in conjunction with DimMask: Dimension bits that shall be selected.
126     } Gig;
127     } Format;
128 schoenebeck 412 EngineChannel* pEngineChannel; ///< Pointer to the EngineChannel where this event occured on, NULL means Engine global event (e.g. SysEx message).
129 schoenebeck 1751 MidiInputPort* pMidiInputPort; ///< Pointer to the MIDI input port on which this event occured (NOTE: currently only for global events, that is SysEx messages)
130 schoenebeck 53
131 schoenebeck 293 inline int32_t FragmentPos() {
132     if (iFragmentPos >= 0) return iFragmentPos;
133     iFragmentPos = pEventGenerator->ToFragmentPos(TimeStamp);
134     if (iFragmentPos < 0) iFragmentPos = 0; // if event arrived shortly before the beginning of current fragment
135     return iFragmentPos;
136 schoenebeck 53 }
137 schoenebeck 293 inline void ResetFragmentPos() {
138     iFragmentPos = -1;
139     }
140 schoenebeck 53 protected:
141     typedef EventGenerator::time_stamp_t time_stamp_t;
142     Event(EventGenerator* pGenerator, EventGenerator::time_stamp_t Time);
143 schoenebeck 906 Event(EventGenerator* pGenerator, int32_t FragmentPos);
144 schoenebeck 53 friend class EventGenerator;
145     private:
146     EventGenerator* pEventGenerator; ///< Creator of the event.
147     time_stamp_t TimeStamp; ///< Time stamp of the event's occurence.
148 schoenebeck 293 int32_t iFragmentPos; ///< Position in the current fragment this event refers to.
149 schoenebeck 53 };
150    
151 schoenebeck 2594 class VMEventHandler;
152     class VMExecContext;
153    
154     /** @brief Real-time instrument script event.
155     *
156     * Encapsulates one execution instance of a real-time instrument script for
157     * exactly one script event handler (script event callback).
158     */
159     class ScriptEvent {
160     public:
161     Event cause; ///< Original external event that triggered this script event (i.e. MIDI note on event, MIDI CC event, etc.).
162 schoenebeck 2598 int id; ///< Unique ID of the external event that triggered this cript event.
163 schoenebeck 2594 VMEventHandler** handlers; ///< The script's event handlers (callbacks) to be processed (NULL terminated list).
164     VMExecContext* execCtx; ///< Script's current execution state (polyphonic variables and execution stack).
165     int currentHandler; ///< Current index in 'handlers' list above.
166     int executionSlices; ///< Amount of times this script event has been executed by the ScriptVM runner class.
167     };
168    
169 schoenebeck 53 } // namespace LinuxSampler
170    
171     #endif // __LS_EVENT_H__

  ViewVC Help
Powered by ViewVC