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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3452 - (hide annotations) (download) (as text)
Thu Jan 3 12:08:48 2019 UTC (5 years, 3 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 11304 byte(s)
* Fixed potential endless recursion introduced by SVN r3444
  (patch by Ivan Maguidhir).
* Bumped version (2.1.0.svn4).

1 schoenebeck 2879 /*
2 schoenebeck 3444 * Copyright (c) 2016 - 2018 Christian Schoenebeck
3 schoenebeck 2879 *
4     * http://www.linuxsampler.org
5     *
6     * This file is part of LinuxSampler and released under the same terms.
7     * See README file for details.
8     */
9    
10     #ifndef LS_NOTE_H
11     #define LS_NOTE_H
12    
13     #include "../../common/Pool.h"
14     #include "Event.h"
15 schoenebeck 3246 #include "Fade.h"
16 schoenebeck 2879
17 schoenebeck 3218 #define DEFAULT_NOTE_VOLUME_TIME_S 0.013f /* 13ms */
18     #define DEFAULT_NOTE_PITCH_TIME_S 0.013f /* 13ms */
19 schoenebeck 3335 #define DEFAULT_NOTE_PAN_TIME_S 0.013f /* 13ms */
20 schoenebeck 3188
21 schoenebeck 2879 namespace LinuxSampler {
22    
23 schoenebeck 3444 /// Whether release trigger sample(s) should be played and if yes under which circumstance(s). Options are bit flags to be able to combine them bitwise.
24     enum release_trigger_t {
25     release_trigger_none = 0, ///< Don't play release trigger sample.
26     release_trigger_noteoff = 1, ///< Play release trigger sample on MIDI note-off event.
27     release_trigger_sustain_maxvelocity = (1 << 1), ///< Play release trigger sample on sustain pedal up, use 127 as MIDI velocity.
28     release_trigger_sustain_keyvelocity = (1 << 2) ///< Play release trigger sample on sustain pedal up, use latest MIDI note-on velocity on key.
29     };
30    
31     /// convenience macro for checking playing release trigger sample by sustain pedal in general
32     #define release_trigger_sustain \
33     (release_trigger_sustain_maxvelocity | release_trigger_sustain_keyvelocity)
34    
35     // remove strictness of C++ regarding raw bitwise operations (on type release_trigger_t)
36     inline release_trigger_t operator|(release_trigger_t a, release_trigger_t b) {
37 schoenebeck 3452 return (release_trigger_t) ((int)a | (int)b);
38 schoenebeck 3444 }
39     inline release_trigger_t& operator|=(release_trigger_t& a, release_trigger_t b) {
40 schoenebeck 3452 a = (release_trigger_t) ((int)a | (int)b);
41 schoenebeck 3444 return a;
42     }
43    
44 schoenebeck 2879 /**
45     * Abstract base class of its deriving @c Note class, this class (NoteBase)
46     * is not intended to be instantiated directly. It just provides access to
47     * the parts of a Note object which do not depend on any C++ template
48     * parameter.
49     */
50     class NoteBase {
51     public:
52     int hostKey; ///< Key on which this is @c Note is allocated on. This is usually the note-on event's note number, however in case of a child note this will rather be the parent note's key instead!
53     note_id_t parentNoteID; ///< If not null: unique ID of the parent note of this note (see comments of field @c pChildNotes).
54     RTList<note_id_t>* pChildNotes; ///< Note ID list of "child" notes of this note. These are special notes that must be released once this note gets released.
55     Event cause; ///< Copy of the original event (usually a note-on event) which caused this note.
56     event_id_t eventID; ///< Unique ID of the actual original @c Event which caused this note.
57 schoenebeck 2962 sched_time_t triggerSchedTime; ///< Engine's scheduler time when this note was launched.
58 schoenebeck 2931 /// Optional synthesis parameters that might be overridden (by calling real-time instrument script functions like change_vol(), change_pitch(), etc.).
59     struct _Override {
60     float Volume; ///< as linear amplification ratio (1.0 being neutral)
61 schoenebeck 3188 float VolumeTime; ///< Transition duration (in seconds) for changes to @c Volume.
62 schoenebeck 2931 float Pitch; ///< as linear frequency ratio (1.0 being neutral)
63 schoenebeck 3188 float PitchTime; ///< Transition duration (in seconds) for changes to @c Pitch.
64 schoenebeck 2931 float Pan; ///< between -1.0 (most left) and +1.0 (most right) and 0.0 being neutral.
65 schoenebeck 3335 float PanTime; ///< Transition duration (in seconds) for changes to @c Pan.
66 schoenebeck 2931 int64_t PanSources; ///< Might be used for calculating an average pan value in differential way: amount of times the Pan value had been changed and shall be calculated relatively upon.
67 schoenebeck 2935 float Cutoff; ///< between 0.0 and 1.0
68     float Resonance; ///< between 0.0 and 1.0
69 schoenebeck 2953 float Attack; ///< between 0.0 and 1.0
70     float Decay; ///< between 0.0 and 1.0
71 schoenebeck 3316 float Sustain; ///< between 0.0 and 1.0
72 schoenebeck 2953 float Release; ///< between 0.0 and 1.0
73 schoenebeck 3360 float CutoffAttack; ///< between 0.0 and 1.0
74     float CutoffDecay; ///< between 0.0 and 1.0
75     float CutoffSustain;///< between 0.0 and 1.0
76     float CutoffRelease;///< between 0.0 and 1.0
77 schoenebeck 3118 float AmpLFODepth; ///< between 0.0 and 1.0
78     float AmpLFOFreq; ///< between 0.0 and 1.0
79 schoenebeck 3360 float CutoffLFODepth;///< between 0.0 and 1.0
80     float CutoffLFOFreq; ///< between 0.0 and 1.0
81 schoenebeck 3118 float PitchLFODepth; ///< between 0.0 and 1.0
82     float PitchLFOFreq; ///< between 0.0 and 1.0
83 schoenebeck 3246 fade_curve_t VolumeCurve;
84     fade_curve_t PitchCurve;
85 schoenebeck 3335 fade_curve_t PanCurve;
86 schoenebeck 3251 int SampleOffset; ///< Where the sample shall start playback in microseconds (otherwise this is -1 for being ignored).
87 schoenebeck 2931 } Override;
88 schoenebeck 2879 /// Sampler format specific informations and variables.
89     union _Format {
90     /// Gigasampler/GigaStudio format specifics.
91     struct _Gig {
92     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.
93     uint8_t DimBits; ///< Used only in conjunction with DimMask: Dimension bits that shall be selected.
94     } Gig;
95     } Format;
96 schoenebeck 3193 int userPar[4]; ///< Used only for real-time instrument script functions set_event_par() and get_event_par() to store script author's user specific data ($EVENT_PAR_0 to $EVENT_PAR_3).
97 schoenebeck 2879 protected:
98     NoteBase() : hostKey(0), parentNoteID(0), pChildNotes(NULL) {
99 schoenebeck 2931 Override.Volume = 1.f;
100 schoenebeck 3188 Override.VolumeTime = DEFAULT_NOTE_VOLUME_TIME_S;
101 schoenebeck 2931 Override.Pitch = 1.f;
102 schoenebeck 3188 Override.PitchTime = DEFAULT_NOTE_PITCH_TIME_S;
103 schoenebeck 2931 Override.Pan = 0.f;
104 schoenebeck 3335 Override.PanTime = DEFAULT_NOTE_PAN_TIME_S;
105 schoenebeck 2931 Override.PanSources = 0;
106 schoenebeck 2935 Override.Cutoff = 1.f;
107     Override.Resonance = 1.f;
108 schoenebeck 2953 Override.Attack = 1.f;
109     Override.Decay = 1.f;
110 schoenebeck 3316 Override.Sustain = 1.f;
111 schoenebeck 2953 Override.Release = 1.f;
112 schoenebeck 3360 Override.CutoffAttack = 1.f;
113     Override.CutoffDecay = 1.f;
114     Override.CutoffSustain = 1.f;
115     Override.CutoffRelease = 1.f;
116 schoenebeck 3118 Override.AmpLFODepth = 1.f;
117     Override.AmpLFOFreq = 1.f;
118 schoenebeck 3360 Override.CutoffLFODepth = 1.f;
119     Override.CutoffLFOFreq = 1.f;
120 schoenebeck 3118 Override.PitchLFODepth = 1.f;
121     Override.PitchLFOFreq = 1.f;
122 schoenebeck 3246 Override.VolumeCurve = DEFAULT_FADE_CURVE;
123     Override.PitchCurve = DEFAULT_FADE_CURVE;
124 schoenebeck 3335 Override.PanCurve = DEFAULT_FADE_CURVE;
125 schoenebeck 3251 Override.SampleOffset = -1;
126 schoenebeck 3118
127 schoenebeck 2880 Format = _Format();
128 schoenebeck 3193
129     userPar[0] = 0;
130     userPar[1] = 0;
131     userPar[2] = 0;
132     userPar[3] = 0;
133 schoenebeck 2879 }
134     };
135    
136     /**
137     * Contains the voices caused by one specific note, as well as basic
138 schoenebeck 3188 * information about the note itself. You can see a Note object as one
139 schoenebeck 2938 * specific event in time where one or more voices were spawned at the same
140     * time and all those voices due to the same cause.
141     *
142     * For example when you press down and hold the sustain pedal, and then
143     * trigger the same note on the keyboard multiple times, for each key
144 schoenebeck 3188 * strokes a separate Note instance is created. Assuming you have a layered
145     * sound with 4 layers, then for each note that is triggered 4 voices will
146     * be spawned and assigned to the same Note object. By grouping those voices
147     * to one specific Note object, it allows to control the synthesis paramters
148     * of those layered voices simultaniously.
149 schoenebeck 2938 *
150     * If your instrument contains a real-time instrument script, then that
151     * script might also trigger additional voices programmatically (by
152     * calling the built-in script function play_note()). Each time the script
153     * calls play_note() a new Note instance is created and the script may then
154     * further control the voices of specific notes independently from each
155     * other. For example for each key stroke on your keyboard the instrument
156     * script might trigger 3 additional notes programmatically and assign a
157     * different tuning filter parameters for each one of the 3 notes
158     * independently.
159 schoenebeck 2879 */
160     template<class V>
161     class Note : public NoteBase {
162     public:
163     RTList<V>* pActiveVoices; ///< Contains the active voices associated with this note.
164    
165     Note() : NoteBase(), pActiveVoices(NULL) {}
166    
167     virtual ~Note() {
168     if (pChildNotes) delete pChildNotes;
169     if (pActiveVoices) delete pActiveVoices;
170     }
171    
172     void init(Pool<V>* pVoicePool, Pool<note_id_t>* pNoteIDPool) {
173     if (pActiveVoices) delete pActiveVoices;
174     pActiveVoices = new RTList<V>(pVoicePool);
175     if (pChildNotes) delete pChildNotes;
176     pChildNotes = new RTList<note_id_t>(pNoteIDPool);
177     }
178    
179     void reset() {
180     hostKey = 0;
181     parentNoteID = 0;
182     if (pChildNotes)
183     pChildNotes->clear();
184     cause = Event();
185     eventID = 0;
186 schoenebeck 2931 Override.Volume = 1.f;
187 schoenebeck 3188 Override.VolumeTime = DEFAULT_NOTE_VOLUME_TIME_S;
188 schoenebeck 2931 Override.Pitch = 1.f;
189 schoenebeck 3188 Override.PitchTime = DEFAULT_NOTE_PITCH_TIME_S;
190 schoenebeck 2931 Override.Pan = 0.f;
191 schoenebeck 3335 Override.PanTime = DEFAULT_NOTE_PAN_TIME_S;
192 schoenebeck 2931 Override.PanSources = 0;
193 schoenebeck 2935 Override.Cutoff = 1.f;
194     Override.Resonance = 1.f;
195 schoenebeck 2953 Override.Attack = 1.f;
196     Override.Decay = 1.f;
197 schoenebeck 3316 Override.Sustain = 1.f;
198 schoenebeck 2953 Override.Release = 1.f;
199 schoenebeck 3360 Override.CutoffAttack = 1.f;
200     Override.CutoffDecay = 1.f;
201     Override.CutoffSustain = 1.f;
202     Override.CutoffRelease = 1.f;
203 schoenebeck 3118 Override.AmpLFODepth = 1.f;
204     Override.AmpLFOFreq = 1.f;
205 schoenebeck 3360 Override.CutoffLFODepth = 1.f;
206     Override.CutoffLFOFreq = 1.f;
207 schoenebeck 3118 Override.PitchLFODepth = 1.f;
208     Override.PitchLFOFreq = 1.f;
209 schoenebeck 3246 Override.VolumeCurve = DEFAULT_FADE_CURVE;
210     Override.PitchCurve = DEFAULT_FADE_CURVE;
211 schoenebeck 3335 Override.PanCurve = DEFAULT_FADE_CURVE;
212 schoenebeck 3251 Override.SampleOffset = -1;
213 schoenebeck 2880 Format = _Format();
214 schoenebeck 3193 userPar[0] = 0;
215     userPar[1] = 0;
216     userPar[2] = 0;
217     userPar[3] = 0;
218 schoenebeck 2879 if (pActiveVoices) {
219     typename RTList<V>::Iterator itVoice = pActiveVoices->first();
220     typename RTList<V>::Iterator itVoicesEnd = pActiveVoices->end();
221     for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key
222     itVoice->VoiceFreed();
223     }
224     pActiveVoices->clear();
225     }
226     }
227     };
228    
229     } // namespace LinuxSampler
230    
231     #endif // LS_NOTE_H

  ViewVC Help
Powered by ViewVC