1 |
/*************************************************************************** |
2 |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
5 |
* Copyright (C) 2011 Grigor Iliev * |
6 |
* * |
7 |
* This program is free software; you can redistribute it and/or modify * |
8 |
* it under the terms of the GNU General Public License as published by * |
9 |
* the Free Software Foundation; either version 2 of the License, or * |
10 |
* (at your option) any later version. * |
11 |
* * |
12 |
* This program is distributed in the hope that it will be useful, * |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
15 |
* GNU General Public License for more details. * |
16 |
* * |
17 |
* You should have received a copy of the GNU General Public License * |
18 |
* along with this program; if not, write to the Free Software * |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
20 |
* MA 02111-1307 USA * |
21 |
***************************************************************************/ |
22 |
|
23 |
#ifndef __LS_SIGNALUNITRACK_H__ |
24 |
#define __LS_SIGNALUNITRACK_H__ |
25 |
|
26 |
#include "Event.h" |
27 |
#include "SignalUnit.h" |
28 |
#include "../../common/Pool.h" |
29 |
|
30 |
|
31 |
namespace LinuxSampler { |
32 |
|
33 |
template<typename T> |
34 |
class FixedArray { |
35 |
public: |
36 |
FixedArray(int capacity) { |
37 |
iSize = 0; |
38 |
iCapacity = capacity; |
39 |
pData = new T[iCapacity]; |
40 |
} |
41 |
|
42 |
~FixedArray() { |
43 |
delete pData; |
44 |
pData = NULL; |
45 |
} |
46 |
|
47 |
inline int size() { return iSize; } |
48 |
inline int capacity() { return iCapacity; } |
49 |
|
50 |
void add(T element) { |
51 |
if (iSize >= iCapacity) throw Exception("Array out of bounds"); |
52 |
pData[iSize++] = element; |
53 |
} |
54 |
|
55 |
|
56 |
T increment() { |
57 |
if (iSize >= iCapacity) throw Exception("Array out of bounds"); |
58 |
return pData[iSize++]; |
59 |
} |
60 |
|
61 |
void clear() { iSize = 0; } |
62 |
|
63 |
inline T& operator[](int idx) { |
64 |
return pData[idx]; |
65 |
} |
66 |
|
67 |
private: |
68 |
T* pData; |
69 |
int iSize; |
70 |
int iCapacity; |
71 |
}; |
72 |
|
73 |
class SignalUnitRack { |
74 |
protected: |
75 |
uint CurrentStep; // The current time step |
76 |
|
77 |
public: |
78 |
FixedArray<SignalUnit*> Units; // A list of all signal units in this rack |
79 |
|
80 |
/** |
81 |
* @param maxUnitCount We are using fixed size array because of the real-time safe requirements. |
82 |
*/ |
83 |
SignalUnitRack(int maxUnitCount): CurrentStep(0), Units(maxUnitCount) { } |
84 |
|
85 |
uint GetCurrentStep() { return CurrentStep; } |
86 |
|
87 |
virtual EndpointSignalUnit* GetEndpointUnit() = 0; |
88 |
|
89 |
virtual void EnterFadeOutStage() = 0; |
90 |
|
91 |
/** |
92 |
* Will be called to increment the time with one sample point. |
93 |
* Each unit should recalculate its current level on every call of this function. |
94 |
*/ |
95 |
virtual void Increment() { |
96 |
CurrentStep++; |
97 |
|
98 |
for (int i = 0; i < Units.size(); i++) { |
99 |
Units[i]->Increment(); |
100 |
} |
101 |
} |
102 |
|
103 |
virtual void ProcessCCEvent(RTList<Event>::Iterator& itEvent) { |
104 |
if ( !(itEvent->Type == Event::type_control_change && itEvent->Param.CC.Controller) ) return; |
105 |
for (int i = 0; i < Units.size(); i++) { |
106 |
Units[i]->ProcessCCEvent(itEvent->Param.CC.Controller, itEvent->Param.CC.Value); |
107 |
} |
108 |
} |
109 |
|
110 |
/** Initializes and triggers the rack. */ |
111 |
virtual void Trigger() { |
112 |
CurrentStep = 0; |
113 |
for (int i = 0; i < Units.size(); i++) { |
114 |
Units[i]->Trigger(); |
115 |
} |
116 |
} |
117 |
|
118 |
/** |
119 |
* When the rack belongs to a voice, this method is |
120 |
* called when the voice enter the release stage. |
121 |
*/ |
122 |
virtual void EnterReleaseStage() { |
123 |
for (int i = 0; i < Units.size(); i++) { |
124 |
Units[i]->EnterReleaseStage(); |
125 |
} |
126 |
} |
127 |
|
128 |
/** |
129 |
* When the rack belongs to a voice, this method is |
130 |
* called when the voice is of type which ignore note off. |
131 |
*/ |
132 |
virtual void CancelRelease() { |
133 |
for (int i = 0; i < Units.size(); i++) { |
134 |
Units[i]->CancelRelease(); |
135 |
} |
136 |
} |
137 |
}; |
138 |
} // namespace LinuxSampler |
139 |
|
140 |
#endif /* __LS_SIGNALUNITRACK_H__ */ |