/[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 2953 - (hide annotations) (download) (as text)
Sat Jul 16 11:24:39 2016 UTC (7 years, 9 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 6166 byte(s)
* NKSP: Implemented built-in script function "change_attack()".
* NKSP: Implemented built-in script function "change_decay()".
* NKSP: Implemented built-in script function "change_release()".
* Bumped version (2.0.0.svn19).

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

  ViewVC Help
Powered by ViewVC