/[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 3335 - (show annotations) (download) (as text)
Sun Jul 30 14:33:15 2017 UTC (6 years, 8 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 9184 byte(s)
* NKSP: Added built-in script function "change_pan_time()".
* NKSP: Added built-in script function "change_pan_curve()".
* Bumped version (2.0.0.svn75).

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 AmpLFODepth; ///< between 0.0 and 1.0
53 float AmpLFOFreq; ///< between 0.0 and 1.0
54 float PitchLFODepth; ///< between 0.0 and 1.0
55 float PitchLFOFreq; ///< between 0.0 and 1.0
56 fade_curve_t VolumeCurve;
57 fade_curve_t PitchCurve;
58 fade_curve_t PanCurve;
59 int SampleOffset; ///< Where the sample shall start playback in microseconds (otherwise this is -1 for being ignored).
60 } Override;
61 /// Sampler format specific informations and variables.
62 union _Format {
63 /// Gigasampler/GigaStudio format specifics.
64 struct _Gig {
65 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.
66 uint8_t DimBits; ///< Used only in conjunction with DimMask: Dimension bits that shall be selected.
67 } Gig;
68 } Format;
69 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).
70 protected:
71 NoteBase() : hostKey(0), parentNoteID(0), pChildNotes(NULL) {
72 Override.Volume = 1.f;
73 Override.VolumeTime = DEFAULT_NOTE_VOLUME_TIME_S;
74 Override.Pitch = 1.f;
75 Override.PitchTime = DEFAULT_NOTE_PITCH_TIME_S;
76 Override.Pan = 0.f;
77 Override.PanTime = DEFAULT_NOTE_PAN_TIME_S;
78 Override.PanSources = 0;
79 Override.Cutoff = 1.f;
80 Override.Resonance = 1.f;
81 Override.Attack = 1.f;
82 Override.Decay = 1.f;
83 Override.Sustain = 1.f;
84 Override.Release = 1.f;
85 Override.AmpLFODepth = 1.f;
86 Override.AmpLFOFreq = 1.f;
87 Override.PitchLFODepth = 1.f;
88 Override.PitchLFOFreq = 1.f;
89 Override.VolumeCurve = DEFAULT_FADE_CURVE;
90 Override.PitchCurve = DEFAULT_FADE_CURVE;
91 Override.PanCurve = DEFAULT_FADE_CURVE;
92 Override.SampleOffset = -1;
93
94 Format = _Format();
95
96 userPar[0] = 0;
97 userPar[1] = 0;
98 userPar[2] = 0;
99 userPar[3] = 0;
100 }
101 };
102
103 /**
104 * Contains the voices caused by one specific note, as well as basic
105 * information about the note itself. You can see a Note object as one
106 * specific event in time where one or more voices were spawned at the same
107 * time and all those voices due to the same cause.
108 *
109 * For example when you press down and hold the sustain pedal, and then
110 * trigger the same note on the keyboard multiple times, for each key
111 * strokes a separate Note instance is created. Assuming you have a layered
112 * sound with 4 layers, then for each note that is triggered 4 voices will
113 * be spawned and assigned to the same Note object. By grouping those voices
114 * to one specific Note object, it allows to control the synthesis paramters
115 * of those layered voices simultaniously.
116 *
117 * If your instrument contains a real-time instrument script, then that
118 * script might also trigger additional voices programmatically (by
119 * calling the built-in script function play_note()). Each time the script
120 * calls play_note() a new Note instance is created and the script may then
121 * further control the voices of specific notes independently from each
122 * other. For example for each key stroke on your keyboard the instrument
123 * script might trigger 3 additional notes programmatically and assign a
124 * different tuning filter parameters for each one of the 3 notes
125 * independently.
126 */
127 template<class V>
128 class Note : public NoteBase {
129 public:
130 RTList<V>* pActiveVoices; ///< Contains the active voices associated with this note.
131
132 Note() : NoteBase(), pActiveVoices(NULL) {}
133
134 virtual ~Note() {
135 if (pChildNotes) delete pChildNotes;
136 if (pActiveVoices) delete pActiveVoices;
137 }
138
139 void init(Pool<V>* pVoicePool, Pool<note_id_t>* pNoteIDPool) {
140 if (pActiveVoices) delete pActiveVoices;
141 pActiveVoices = new RTList<V>(pVoicePool);
142 if (pChildNotes) delete pChildNotes;
143 pChildNotes = new RTList<note_id_t>(pNoteIDPool);
144 }
145
146 void reset() {
147 hostKey = 0;
148 parentNoteID = 0;
149 if (pChildNotes)
150 pChildNotes->clear();
151 cause = Event();
152 eventID = 0;
153 Override.Volume = 1.f;
154 Override.VolumeTime = DEFAULT_NOTE_VOLUME_TIME_S;
155 Override.Pitch = 1.f;
156 Override.PitchTime = DEFAULT_NOTE_PITCH_TIME_S;
157 Override.Pan = 0.f;
158 Override.PanTime = DEFAULT_NOTE_PAN_TIME_S;
159 Override.PanSources = 0;
160 Override.Cutoff = 1.f;
161 Override.Resonance = 1.f;
162 Override.Attack = 1.f;
163 Override.Decay = 1.f;
164 Override.Sustain = 1.f;
165 Override.Release = 1.f;
166 Override.AmpLFODepth = 1.f;
167 Override.AmpLFOFreq = 1.f;
168 Override.PitchLFODepth = 1.f;
169 Override.PitchLFOFreq = 1.f;
170 Override.VolumeCurve = DEFAULT_FADE_CURVE;
171 Override.PitchCurve = DEFAULT_FADE_CURVE;
172 Override.PanCurve = DEFAULT_FADE_CURVE;
173 Override.SampleOffset = -1;
174 Format = _Format();
175 userPar[0] = 0;
176 userPar[1] = 0;
177 userPar[2] = 0;
178 userPar[3] = 0;
179 if (pActiveVoices) {
180 typename RTList<V>::Iterator itVoice = pActiveVoices->first();
181 typename RTList<V>::Iterator itVoicesEnd = pActiveVoices->end();
182 for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key
183 itVoice->VoiceFreed();
184 }
185 pActiveVoices->clear();
186 }
187 }
188 };
189
190 } // namespace LinuxSampler
191
192 #endif // LS_NOTE_H

  ViewVC Help
Powered by ViewVC