/[svn]/linuxsampler/trunk/src/engines/common/Note.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/engines/common/Note.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3188 - (show annotations) (download) (as text)
Fri May 19 14:23:12 2017 UTC (6 years, 10 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 /*
2 * Copyright (c) 2016 - 2017 Christian Schoenebeck
3 *
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 #define DEFAULT_NOTE_VOLUME_TIME_S 0.013 /* 13ms */
17 #define DEFAULT_NOTE_PITCH_TIME_S 0.013 /* 13ms */
18
19 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 sched_time_t triggerSchedTime; ///< Engine's scheduler time when this note was launched.
35 /// 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 float VolumeTime; ///< Transition duration (in seconds) for changes to @c Volume.
39 float Pitch; ///< as linear frequency ratio (1.0 being neutral)
40 float PitchTime; ///< Transition duration (in seconds) for changes to @c Pitch.
41 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 float Cutoff; ///< between 0.0 and 1.0
44 float Resonance; ///< between 0.0 and 1.0
45 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 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 } Override;
53 /// 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 Override.Volume = 1.f;
64 Override.VolumeTime = DEFAULT_NOTE_VOLUME_TIME_S;
65 Override.Pitch = 1.f;
66 Override.PitchTime = DEFAULT_NOTE_PITCH_TIME_S;
67 Override.Pan = 0.f;
68 Override.PanSources = 0;
69 Override.Cutoff = 1.f;
70 Override.Resonance = 1.f;
71 Override.Attack = 1.f;
72 Override.Decay = 1.f;
73 Override.Release = 1.f;
74 Override.AmpLFODepth = 1.f;
75 Override.AmpLFOFreq = 1.f;
76 Override.PitchLFODepth = 1.f;
77 Override.PitchLFOFreq = 1.f;
78
79 Format = _Format();
80 }
81 };
82
83 /**
84 * Contains the voices caused by one specific note, as well as basic
85 * information about the note itself. You can see a Note object as one
86 * 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 * 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 *
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 */
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 Override.Volume = 1.f;
134 Override.VolumeTime = DEFAULT_NOTE_VOLUME_TIME_S;
135 Override.Pitch = 1.f;
136 Override.PitchTime = DEFAULT_NOTE_PITCH_TIME_S;
137 Override.Pan = 0.f;
138 Override.PanSources = 0;
139 Override.Cutoff = 1.f;
140 Override.Resonance = 1.f;
141 Override.Attack = 1.f;
142 Override.Decay = 1.f;
143 Override.Release = 1.f;
144 Override.AmpLFODepth = 1.f;
145 Override.AmpLFOFreq = 1.f;
146 Override.PitchLFODepth = 1.f;
147 Override.PitchLFOFreq = 1.f;
148 Format = _Format();
149 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