/[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 3335 - (hide 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 schoenebeck 2879 /*
2 schoenebeck 3118 * Copyright (c) 2016 - 2017 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     /**
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 schoenebeck 2962 sched_time_t triggerSchedTime; ///< Engine's scheduler time when this note was launched.
37 schoenebeck 2931 /// 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 schoenebeck 3188 float VolumeTime; ///< Transition duration (in seconds) for changes to @c Volume.
41 schoenebeck 2931 float Pitch; ///< as linear frequency ratio (1.0 being neutral)
42 schoenebeck 3188 float PitchTime; ///< Transition duration (in seconds) for changes to @c Pitch.
43 schoenebeck 2931 float Pan; ///< between -1.0 (most left) and +1.0 (most right) and 0.0 being neutral.
44 schoenebeck 3335 float PanTime; ///< Transition duration (in seconds) for changes to @c Pan.
45 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.
46 schoenebeck 2935 float Cutoff; ///< between 0.0 and 1.0
47     float Resonance; ///< between 0.0 and 1.0
48 schoenebeck 2953 float Attack; ///< between 0.0 and 1.0
49     float Decay; ///< between 0.0 and 1.0
50 schoenebeck 3316 float Sustain; ///< between 0.0 and 1.0
51 schoenebeck 2953 float Release; ///< between 0.0 and 1.0
52 schoenebeck 3118 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 schoenebeck 3246 fade_curve_t VolumeCurve;
57     fade_curve_t PitchCurve;
58 schoenebeck 3335 fade_curve_t PanCurve;
59 schoenebeck 3251 int SampleOffset; ///< Where the sample shall start playback in microseconds (otherwise this is -1 for being ignored).
60 schoenebeck 2931 } Override;
61 schoenebeck 2879 /// 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 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).
70 schoenebeck 2879 protected:
71     NoteBase() : hostKey(0), parentNoteID(0), pChildNotes(NULL) {
72 schoenebeck 2931 Override.Volume = 1.f;
73 schoenebeck 3188 Override.VolumeTime = DEFAULT_NOTE_VOLUME_TIME_S;
74 schoenebeck 2931 Override.Pitch = 1.f;
75 schoenebeck 3188 Override.PitchTime = DEFAULT_NOTE_PITCH_TIME_S;
76 schoenebeck 2931 Override.Pan = 0.f;
77 schoenebeck 3335 Override.PanTime = DEFAULT_NOTE_PAN_TIME_S;
78 schoenebeck 2931 Override.PanSources = 0;
79 schoenebeck 2935 Override.Cutoff = 1.f;
80     Override.Resonance = 1.f;
81 schoenebeck 2953 Override.Attack = 1.f;
82     Override.Decay = 1.f;
83 schoenebeck 3316 Override.Sustain = 1.f;
84 schoenebeck 2953 Override.Release = 1.f;
85 schoenebeck 3118 Override.AmpLFODepth = 1.f;
86     Override.AmpLFOFreq = 1.f;
87     Override.PitchLFODepth = 1.f;
88     Override.PitchLFOFreq = 1.f;
89 schoenebeck 3246 Override.VolumeCurve = DEFAULT_FADE_CURVE;
90     Override.PitchCurve = DEFAULT_FADE_CURVE;
91 schoenebeck 3335 Override.PanCurve = DEFAULT_FADE_CURVE;
92 schoenebeck 3251 Override.SampleOffset = -1;
93 schoenebeck 3118
94 schoenebeck 2880 Format = _Format();
95 schoenebeck 3193
96     userPar[0] = 0;
97     userPar[1] = 0;
98     userPar[2] = 0;
99     userPar[3] = 0;
100 schoenebeck 2879 }
101     };
102    
103     /**
104     * Contains the voices caused by one specific note, as well as basic
105 schoenebeck 3188 * information about the note itself. You can see a Note object as one
106 schoenebeck 2938 * 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 schoenebeck 3188 * 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 schoenebeck 2938 *
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 schoenebeck 2879 */
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 schoenebeck 2931 Override.Volume = 1.f;
154 schoenebeck 3188 Override.VolumeTime = DEFAULT_NOTE_VOLUME_TIME_S;
155 schoenebeck 2931 Override.Pitch = 1.f;
156 schoenebeck 3188 Override.PitchTime = DEFAULT_NOTE_PITCH_TIME_S;
157 schoenebeck 2931 Override.Pan = 0.f;
158 schoenebeck 3335 Override.PanTime = DEFAULT_NOTE_PAN_TIME_S;
159 schoenebeck 2931 Override.PanSources = 0;
160 schoenebeck 2935 Override.Cutoff = 1.f;
161     Override.Resonance = 1.f;
162 schoenebeck 2953 Override.Attack = 1.f;
163     Override.Decay = 1.f;
164 schoenebeck 3316 Override.Sustain = 1.f;
165 schoenebeck 2953 Override.Release = 1.f;
166 schoenebeck 3118 Override.AmpLFODepth = 1.f;
167     Override.AmpLFOFreq = 1.f;
168     Override.PitchLFODepth = 1.f;
169     Override.PitchLFOFreq = 1.f;
170 schoenebeck 3246 Override.VolumeCurve = DEFAULT_FADE_CURVE;
171     Override.PitchCurve = DEFAULT_FADE_CURVE;
172 schoenebeck 3335 Override.PanCurve = DEFAULT_FADE_CURVE;
173 schoenebeck 3251 Override.SampleOffset = -1;
174 schoenebeck 2880 Format = _Format();
175 schoenebeck 3193 userPar[0] = 0;
176     userPar[1] = 0;
177     userPar[2] = 0;
178     userPar[3] = 0;
179 schoenebeck 2879 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