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