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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3360 - (show annotations) (download) (as text)
Fri Oct 27 21:19:18 2017 UTC (6 years, 5 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 10036 byte(s)
* NKSP: Added built-in script function "change_cutoff_attack()".
* NKSP: Added built-in script function "change_cutoff_decay()".
* NKSP: Added built-in script function "change_cutoff_sustain()".
* NKSP: Added built-in script function "change_cutoff_release()".
* NKSP: Added built-in script function "change_cutoff_lfo_depth()".
* NKSP: Added built-in script function "change_cutoff_lfo_freq()".
* Bumped version (2.0.0.svn77).

1 /*
2 * Copyright (c) 2016 - 2017 Christian Schoenebeck
3 *
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 #include "Fade.h"
16
17 #define DEFAULT_NOTE_VOLUME_TIME_S 0.013f /* 13ms */
18 #define DEFAULT_NOTE_PITCH_TIME_S 0.013f /* 13ms */
19 #define DEFAULT_NOTE_PAN_TIME_S 0.013f /* 13ms */
20
21 namespace LinuxSampler {
22
23 /**
24 * Abstract base class of its deriving @c Note class, this class (NoteBase)
25 * is not intended to be instantiated directly. It just provides access to
26 * the parts of a Note object which do not depend on any C++ template
27 * parameter.
28 */
29 class NoteBase {
30 public:
31 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!
32 note_id_t parentNoteID; ///< If not null: unique ID of the parent note of this note (see comments of field @c pChildNotes).
33 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.
34 Event cause; ///< Copy of the original event (usually a note-on event) which caused this note.
35 event_id_t eventID; ///< Unique ID of the actual original @c Event which caused this note.
36 sched_time_t triggerSchedTime; ///< Engine's scheduler time when this note was launched.
37 /// Optional synthesis parameters that might be overridden (by calling real-time instrument script functions like change_vol(), change_pitch(), etc.).
38 struct _Override {
39 float Volume; ///< as linear amplification ratio (1.0 being neutral)
40 float VolumeTime; ///< Transition duration (in seconds) for changes to @c Volume.
41 float Pitch; ///< as linear frequency ratio (1.0 being neutral)
42 float PitchTime; ///< Transition duration (in seconds) for changes to @c Pitch.
43 float Pan; ///< between -1.0 (most left) and +1.0 (most right) and 0.0 being neutral.
44 float PanTime; ///< Transition duration (in seconds) for changes to @c Pan.
45 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.
46 float Cutoff; ///< between 0.0 and 1.0
47 float Resonance; ///< between 0.0 and 1.0
48 float Attack; ///< between 0.0 and 1.0
49 float Decay; ///< between 0.0 and 1.0
50 float Sustain; ///< between 0.0 and 1.0
51 float Release; ///< between 0.0 and 1.0
52 float CutoffAttack; ///< between 0.0 and 1.0
53 float CutoffDecay; ///< between 0.0 and 1.0
54 float CutoffSustain;///< between 0.0 and 1.0
55 float CutoffRelease;///< between 0.0 and 1.0
56 float AmpLFODepth; ///< between 0.0 and 1.0
57 float AmpLFOFreq; ///< between 0.0 and 1.0
58 float CutoffLFODepth;///< between 0.0 and 1.0
59 float CutoffLFOFreq; ///< between 0.0 and 1.0
60 float PitchLFODepth; ///< between 0.0 and 1.0
61 float PitchLFOFreq; ///< between 0.0 and 1.0
62 fade_curve_t VolumeCurve;
63 fade_curve_t PitchCurve;
64 fade_curve_t PanCurve;
65 int SampleOffset; ///< Where the sample shall start playback in microseconds (otherwise this is -1 for being ignored).
66 } Override;
67 /// Sampler format specific informations and variables.
68 union _Format {
69 /// Gigasampler/GigaStudio format specifics.
70 struct _Gig {
71 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.
72 uint8_t DimBits; ///< Used only in conjunction with DimMask: Dimension bits that shall be selected.
73 } Gig;
74 } Format;
75 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).
76 protected:
77 NoteBase() : hostKey(0), parentNoteID(0), pChildNotes(NULL) {
78 Override.Volume = 1.f;
79 Override.VolumeTime = DEFAULT_NOTE_VOLUME_TIME_S;
80 Override.Pitch = 1.f;
81 Override.PitchTime = DEFAULT_NOTE_PITCH_TIME_S;
82 Override.Pan = 0.f;
83 Override.PanTime = DEFAULT_NOTE_PAN_TIME_S;
84 Override.PanSources = 0;
85 Override.Cutoff = 1.f;
86 Override.Resonance = 1.f;
87 Override.Attack = 1.f;
88 Override.Decay = 1.f;
89 Override.Sustain = 1.f;
90 Override.Release = 1.f;
91 Override.CutoffAttack = 1.f;
92 Override.CutoffDecay = 1.f;
93 Override.CutoffSustain = 1.f;
94 Override.CutoffRelease = 1.f;
95 Override.AmpLFODepth = 1.f;
96 Override.AmpLFOFreq = 1.f;
97 Override.CutoffLFODepth = 1.f;
98 Override.CutoffLFOFreq = 1.f;
99 Override.PitchLFODepth = 1.f;
100 Override.PitchLFOFreq = 1.f;
101 Override.VolumeCurve = DEFAULT_FADE_CURVE;
102 Override.PitchCurve = DEFAULT_FADE_CURVE;
103 Override.PanCurve = DEFAULT_FADE_CURVE;
104 Override.SampleOffset = -1;
105
106 Format = _Format();
107
108 userPar[0] = 0;
109 userPar[1] = 0;
110 userPar[2] = 0;
111 userPar[3] = 0;
112 }
113 };
114
115 /**
116 * Contains the voices caused by one specific note, as well as basic
117 * information about the note itself. You can see a Note object as one
118 * specific event in time where one or more voices were spawned at the same
119 * time and all those voices due to the same cause.
120 *
121 * For example when you press down and hold the sustain pedal, and then
122 * trigger the same note on the keyboard multiple times, for each key
123 * strokes a separate Note instance is created. Assuming you have a layered
124 * sound with 4 layers, then for each note that is triggered 4 voices will
125 * be spawned and assigned to the same Note object. By grouping those voices
126 * to one specific Note object, it allows to control the synthesis paramters
127 * of those layered voices simultaniously.
128 *
129 * If your instrument contains a real-time instrument script, then that
130 * script might also trigger additional voices programmatically (by
131 * calling the built-in script function play_note()). Each time the script
132 * calls play_note() a new Note instance is created and the script may then
133 * further control the voices of specific notes independently from each
134 * other. For example for each key stroke on your keyboard the instrument
135 * script might trigger 3 additional notes programmatically and assign a
136 * different tuning filter parameters for each one of the 3 notes
137 * independently.
138 */
139 template<class V>
140 class Note : public NoteBase {
141 public:
142 RTList<V>* pActiveVoices; ///< Contains the active voices associated with this note.
143
144 Note() : NoteBase(), pActiveVoices(NULL) {}
145
146 virtual ~Note() {
147 if (pChildNotes) delete pChildNotes;
148 if (pActiveVoices) delete pActiveVoices;
149 }
150
151 void init(Pool<V>* pVoicePool, Pool<note_id_t>* pNoteIDPool) {
152 if (pActiveVoices) delete pActiveVoices;
153 pActiveVoices = new RTList<V>(pVoicePool);
154 if (pChildNotes) delete pChildNotes;
155 pChildNotes = new RTList<note_id_t>(pNoteIDPool);
156 }
157
158 void reset() {
159 hostKey = 0;
160 parentNoteID = 0;
161 if (pChildNotes)
162 pChildNotes->clear();
163 cause = Event();
164 eventID = 0;
165 Override.Volume = 1.f;
166 Override.VolumeTime = DEFAULT_NOTE_VOLUME_TIME_S;
167 Override.Pitch = 1.f;
168 Override.PitchTime = DEFAULT_NOTE_PITCH_TIME_S;
169 Override.Pan = 0.f;
170 Override.PanTime = DEFAULT_NOTE_PAN_TIME_S;
171 Override.PanSources = 0;
172 Override.Cutoff = 1.f;
173 Override.Resonance = 1.f;
174 Override.Attack = 1.f;
175 Override.Decay = 1.f;
176 Override.Sustain = 1.f;
177 Override.Release = 1.f;
178 Override.CutoffAttack = 1.f;
179 Override.CutoffDecay = 1.f;
180 Override.CutoffSustain = 1.f;
181 Override.CutoffRelease = 1.f;
182 Override.AmpLFODepth = 1.f;
183 Override.AmpLFOFreq = 1.f;
184 Override.CutoffLFODepth = 1.f;
185 Override.CutoffLFOFreq = 1.f;
186 Override.PitchLFODepth = 1.f;
187 Override.PitchLFOFreq = 1.f;
188 Override.VolumeCurve = DEFAULT_FADE_CURVE;
189 Override.PitchCurve = DEFAULT_FADE_CURVE;
190 Override.PanCurve = DEFAULT_FADE_CURVE;
191 Override.SampleOffset = -1;
192 Format = _Format();
193 userPar[0] = 0;
194 userPar[1] = 0;
195 userPar[2] = 0;
196 userPar[3] = 0;
197 if (pActiveVoices) {
198 typename RTList<V>::Iterator itVoice = pActiveVoices->first();
199 typename RTList<V>::Iterator itVoicesEnd = pActiveVoices->end();
200 for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key
201 itVoice->VoiceFreed();
202 }
203 pActiveVoices->clear();
204 }
205 }
206 };
207
208 } // namespace LinuxSampler
209
210 #endif // LS_NOTE_H

  ViewVC Help
Powered by ViewVC