1 |
/* |
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 |
/// Sampler format specific informations and variables. |
32 |
union _Format { |
33 |
/// Gigasampler/GigaStudio format specifics. |
34 |
struct _Gig { |
35 |
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. |
36 |
uint8_t DimBits; ///< Used only in conjunction with DimMask: Dimension bits that shall be selected. |
37 |
} Gig; |
38 |
} Format; |
39 |
protected: |
40 |
NoteBase() : hostKey(0), parentNoteID(0), pChildNotes(NULL) { |
41 |
Format = _Format(); |
42 |
} |
43 |
}; |
44 |
|
45 |
/** |
46 |
* Contains the voices caused by one specific note, as well as basic |
47 |
* informations about the note itself. |
48 |
*/ |
49 |
template<class V> |
50 |
class Note : public NoteBase { |
51 |
public: |
52 |
RTList<V>* pActiveVoices; ///< Contains the active voices associated with this note. |
53 |
|
54 |
Note() : NoteBase(), pActiveVoices(NULL) {} |
55 |
|
56 |
virtual ~Note() { |
57 |
if (pChildNotes) delete pChildNotes; |
58 |
if (pActiveVoices) delete pActiveVoices; |
59 |
} |
60 |
|
61 |
void init(Pool<V>* pVoicePool, Pool<note_id_t>* pNoteIDPool) { |
62 |
if (pActiveVoices) delete pActiveVoices; |
63 |
pActiveVoices = new RTList<V>(pVoicePool); |
64 |
if (pChildNotes) delete pChildNotes; |
65 |
pChildNotes = new RTList<note_id_t>(pNoteIDPool); |
66 |
} |
67 |
|
68 |
void reset() { |
69 |
hostKey = 0; |
70 |
parentNoteID = 0; |
71 |
if (pChildNotes) |
72 |
pChildNotes->clear(); |
73 |
cause = Event(); |
74 |
eventID = 0; |
75 |
Format = _Format(); |
76 |
if (pActiveVoices) { |
77 |
typename RTList<V>::Iterator itVoice = pActiveVoices->first(); |
78 |
typename RTList<V>::Iterator itVoicesEnd = pActiveVoices->end(); |
79 |
for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key |
80 |
itVoice->VoiceFreed(); |
81 |
} |
82 |
pActiveVoices->clear(); |
83 |
} |
84 |
} |
85 |
}; |
86 |
|
87 |
} // namespace LinuxSampler |
88 |
|
89 |
#endif // LS_NOTE_H |