/[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 3188 - (hide annotations) (download) (as text)
Fri May 19 14:23:12 2017 UTC (6 years, 11 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 7695 byte(s)
* NKSP: Implemented built-in script function "change_vol_time()".
* NKSP: Implemented built-in script function "change_tune_time()".
* NKSP: Implemented built-in script function "fade_in()".
* NKSP: Implemented built-in script function "fade_out()".
* NKSP: Fixed acceptance of wrong data type of parameters passed to
  built-in script functions "change_vol()", "change_tune()",
  "change_pan()", "change_cutoff()", "change_reso()",
  "change_attack()", "change_decay()", "change_release()",
  "change_amp_lfo_depth()", "change_amp_lfo_freq()",
  "change_pitch_lfo_depth()" and "change_pitch_lfo_freq()".
* Bumped version (2.0.0.svn45).

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     protected:
62     NoteBase() : hostKey(0), parentNoteID(0), pChildNotes(NULL) {
63 schoenebeck 2931 Override.Volume = 1.f;
64 schoenebeck 3188 Override.VolumeTime = DEFAULT_NOTE_VOLUME_TIME_S;
65 schoenebeck 2931 Override.Pitch = 1.f;
66 schoenebeck 3188 Override.PitchTime = DEFAULT_NOTE_PITCH_TIME_S;
67 schoenebeck 2931 Override.Pan = 0.f;
68     Override.PanSources = 0;
69 schoenebeck 2935 Override.Cutoff = 1.f;
70     Override.Resonance = 1.f;
71 schoenebeck 2953 Override.Attack = 1.f;
72     Override.Decay = 1.f;
73     Override.Release = 1.f;
74 schoenebeck 3118 Override.AmpLFODepth = 1.f;
75     Override.AmpLFOFreq = 1.f;
76     Override.PitchLFODepth = 1.f;
77     Override.PitchLFOFreq = 1.f;
78    
79 schoenebeck 2880 Format = _Format();
80 schoenebeck 2879 }
81     };
82    
83     /**
84     * Contains the voices caused by one specific note, as well as basic
85 schoenebeck 3188 * information about the note itself. You can see a Note object as one
86 schoenebeck 2938 * specific event in time where one or more voices were spawned at the same
87     * time and all those voices due to the same cause.
88     *
89     * For example when you press down and hold the sustain pedal, and then
90     * trigger the same note on the keyboard multiple times, for each key
91 schoenebeck 3188 * strokes a separate Note instance is created. Assuming you have a layered
92     * sound with 4 layers, then for each note that is triggered 4 voices will
93     * be spawned and assigned to the same Note object. By grouping those voices
94     * to one specific Note object, it allows to control the synthesis paramters
95     * of those layered voices simultaniously.
96 schoenebeck 2938 *
97     * If your instrument contains a real-time instrument script, then that
98     * script might also trigger additional voices programmatically (by
99     * calling the built-in script function play_note()). Each time the script
100     * calls play_note() a new Note instance is created and the script may then
101     * further control the voices of specific notes independently from each
102     * other. For example for each key stroke on your keyboard the instrument
103     * script might trigger 3 additional notes programmatically and assign a
104     * different tuning filter parameters for each one of the 3 notes
105     * independently.
106 schoenebeck 2879 */
107     template<class V>
108     class Note : public NoteBase {
109     public:
110     RTList<V>* pActiveVoices; ///< Contains the active voices associated with this note.
111    
112     Note() : NoteBase(), pActiveVoices(NULL) {}
113    
114     virtual ~Note() {
115     if (pChildNotes) delete pChildNotes;
116     if (pActiveVoices) delete pActiveVoices;
117     }
118    
119     void init(Pool<V>* pVoicePool, Pool<note_id_t>* pNoteIDPool) {
120     if (pActiveVoices) delete pActiveVoices;
121     pActiveVoices = new RTList<V>(pVoicePool);
122     if (pChildNotes) delete pChildNotes;
123     pChildNotes = new RTList<note_id_t>(pNoteIDPool);
124     }
125    
126     void reset() {
127     hostKey = 0;
128     parentNoteID = 0;
129     if (pChildNotes)
130     pChildNotes->clear();
131     cause = Event();
132     eventID = 0;
133 schoenebeck 2931 Override.Volume = 1.f;
134 schoenebeck 3188 Override.VolumeTime = DEFAULT_NOTE_VOLUME_TIME_S;
135 schoenebeck 2931 Override.Pitch = 1.f;
136 schoenebeck 3188 Override.PitchTime = DEFAULT_NOTE_PITCH_TIME_S;
137 schoenebeck 2931 Override.Pan = 0.f;
138     Override.PanSources = 0;
139 schoenebeck 2935 Override.Cutoff = 1.f;
140     Override.Resonance = 1.f;
141 schoenebeck 2953 Override.Attack = 1.f;
142     Override.Decay = 1.f;
143     Override.Release = 1.f;
144 schoenebeck 3118 Override.AmpLFODepth = 1.f;
145     Override.AmpLFOFreq = 1.f;
146     Override.PitchLFODepth = 1.f;
147     Override.PitchLFOFreq = 1.f;
148 schoenebeck 2880 Format = _Format();
149 schoenebeck 2879 if (pActiveVoices) {
150     typename RTList<V>::Iterator itVoice = pActiveVoices->first();
151     typename RTList<V>::Iterator itVoicesEnd = pActiveVoices->end();
152     for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key
153     itVoice->VoiceFreed();
154     }
155     pActiveVoices->clear();
156     }
157     }
158     };
159    
160     } // namespace LinuxSampler
161    
162     #endif // LS_NOTE_H

  ViewVC Help
Powered by ViewVC