/[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 3193 - (hide annotations) (download) (as text)
Sat May 20 12:28:57 2017 UTC (6 years, 11 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 8113 byte(s)
* NKSP: Added built-in script function "get_event_par()" and implemented
  some of its possible parameter selections.
* NKSP: Added built-in script function "set_event_par()" and implemented
  some of its possible parameter selections.
* NKSP: Fixed (removed) artificial value limit for duration argument of
  built-in script functions "change_vol_time()" and "change_tune_time()".
* Fixed compile error with pre-C++11 compilers.
* Bumped version (2.0.0.svn46).

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

  ViewVC Help
Powered by ViewVC