/[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 3251 - (hide annotations) (download) (as text)
Mon May 29 22:19:19 2017 UTC (6 years, 10 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 8639 byte(s)
* NKSP: built-in "play_note()" function now supports a sample playback
  start offset with argument 3, where special value -1 means to use the
  regular sample offset as defined by the instrument file.
* Bumped version (2.0.0.svn55).

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

  ViewVC Help
Powered by ViewVC