/[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 3316 - (show annotations) (download) (as text)
Thu Jul 20 12:05:53 2017 UTC (6 years, 9 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 8774 byte(s)
* NKSP: Implemented built-in script function "change_sustain()".
* Bumped version (2.0.0.svn72).

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

  ViewVC Help
Powered by ViewVC