1 //-----------------------------------------------------------------------------
2 // Project : VST SDK
3 //
4 // Category : Examples
5 // Filename : public.sdk/samples/vst/common/voicebase.h
test_bloomfilternull6 // Created by : Steinberg, 02/2010
7 // Description :
8 //
9 //-----------------------------------------------------------------------------
10 // LICENSE
11 // (c) 2018, Steinberg Media Technologies GmbH, All Rights Reserved
12 //-----------------------------------------------------------------------------
13 // Redistribution and use in source and binary forms, with or without modification,
14 // are permitted provided that the following conditions are met:
15 //
16 // * Redistributions of source code must retain the above copyright notice,
17 // this list of conditions and the following disclaimer.
18 // * Redistributions in binary form must reproduce the above copyright notice,
19 // this list of conditions and the following disclaimer in the documentation
20 // and/or other materials provided with the distribution.
21 // * Neither the name of the Steinberg Media Technologies nor the names of its
22 // contributors may be used to endorse or promote products derived from this
23 // software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
26 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
33 // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
34 // OF THE POSSIBILITY OF SUCH DAMAGE.
35 //-----------------------------------------------------------------------------
36
37 #pragma once
38
39 #include "pluginterfaces/vst/vsttypes.h"
40 #include "base/source/fdebug.h"
41
42 #ifdef DEBUG_LOG
43 #undef DEBUG_LOG
44 #endif
45
46 #define DEBUG_LOG DEVELOPMENT
47
48 namespace Steinberg {
49 namespace Vst {
50
51 //-----------------------------------------------------------------------------
52 /** Example Voice class for the Steinberg::Vst::VoiceProcessorImplementation
53
54 Implementation classes need to implement the following additional method:
55 \code
56 bool process (SamplePrecision* outputBuffers[numChannels], int32 numSamples);
57 \endcode
58 */
59 //-----------------------------------------------------------------------------
60 template<uint32 numValues, class SamplePrecision, uint32 numChannels, class GlobalParameterStorage>
61 class VoiceBase
62 {
63 public:
64 /** Returns the current note id of this voice. */
65 int32 getNoteId () const { return noteId; }
66
67 /** Sets a new GlobalParameterStorage. */
68 virtual void setGlobalParameterStorage (GlobalParameterStorage* globalParameters) { this->globalParameters = globalParameters; }
69 /** Sets the sampleRate. */
70 virtual void setSampleRate (ParamValue sampleRate) { this->sampleRate = sampleRate; }
71 /** Returns the sampleRate. */
72 float getSampleRate () const { return (float)sampleRate; }
73
74 virtual void setNoteExpressionValue (int32 index, ParamValue value) { if (index < numValues) values[index] = value; }
75
76 virtual void noteOn (int32 pitch, ParamValue velocity, float tuning, int32 sampleOffset, int32 noteId);
77 virtual void noteOff (ParamValue velocity, int32 sampleOffset);
78
79 virtual void reset ()
80 {
81 noteOnSampleOffset = -1;
82 noteOffSampleOffset = -1;
83 noteId = -1;
84 tuning = 0;
85 }
86
87 //-----------------------------------------------------------------------------
88 protected:
89 VoiceBase ();
90 VoiceBase (const VoiceBase& vb);
91 virtual ~VoiceBase ();
92
93 GlobalParameterStorage* globalParameters;
94
95 int32 noteId;
96 int32 pitch;
97 int32 noteOnSampleOffset;
98 int32 noteOffSampleOffset;
99 float tuning;
100
101 ParamValue sampleRate;
102 ParamValue noteOnVelocity;
103 ParamValue noteOffVelocity;
104 ParamValue values[numValues];
105 };
106
107 //-----------------------------------------------------------------------------
108 template<uint32 numValues, class SamplePrecision, uint32 numChannels, class GlobalParameterStorage>
109 VoiceBase<numValues, SamplePrecision, numChannels, GlobalParameterStorage>::VoiceBase ()
110 : globalParameters (0)
111 , noteId (-1)
112 , pitch (-1)
113 , noteOnSampleOffset (0)
114 , noteOffSampleOffset (0)
115 , sampleRate (44100.)
116 , noteOnVelocity (0.)
117 , noteOffVelocity (0.)
118 {
119 }
120
121 //-----------------------------------------------------------------------------
122 template<uint32 numValues, class SamplePrecision, uint32 numChannels, class GlobalParameterStorage>
123 VoiceBase<numValues, SamplePrecision, numChannels, GlobalParameterStorage>::VoiceBase (const VoiceBase<numValues, SamplePrecision, numChannels, GlobalParameterStorage>& vb)
124 : globalParameters (vb.globalParameters)
125 , noteId (vb.noteId)
126 , pitch (vb.pitch)
127 , noteOnSampleOffset (vb.noteOnSampleOffset)
128 , noteOffSampleOffset (vb.noteOffSampleOffset)
129 , noteOnVelocity (vb.noteOnVelocity)
130 , noteOffVelocity (vb.noteOffVelocity)
131 , sampleRate (vb.sampleRate)
132 , values (0)
133 {
134 for (uint32 i = 0; i < numValues; i++)
135 values[i] = vb.values[i];
136 }
137
138 //-----------------------------------------------------------------------------
139 template<uint32 numValues, class SamplePrecision, uint32 numChannels, class GlobalParameterStorage>
140 VoiceBase<numValues, SamplePrecision, numChannels, GlobalParameterStorage>::~VoiceBase ()
141 {
142 }
143
144 //-----------------------------------------------------------------------------
145 template<uint32 numValues, class SamplePrecision, uint32 numChannels, class GlobalParameterStorage>
146 void VoiceBase<numValues, SamplePrecision, numChannels, GlobalParameterStorage>::noteOn (int32 pitch, ParamValue velocity, float tuning, int32 sampleOffset, int32 nId)
147 {
148 this->pitch = pitch;
149 noteOnVelocity = velocity;
150 noteOnSampleOffset = sampleOffset;
151 noteId = nId;
152 this->tuning = tuning;
153
154 #if DEBUG_LOG
155 FDebugPrint ("NoteOn :%d\n", nId);
156 #endif
157 }
158
159 //-----------------------------------------------------------------------------
160 template<uint32 numValues, class SamplePrecision, uint32 numChannels, class GlobalParameterStorage>
161 void VoiceBase<numValues, SamplePrecision, numChannels, GlobalParameterStorage>::noteOff (ParamValue velocity, int32 sampleOffset)
162 {
163 noteOffVelocity = velocity;
164 noteOffSampleOffset = sampleOffset;
165
166 #if DEBUG_LOG
167 FDebugPrint ("NoteOff:%d\n", this->noteId);
168 #endif
169 }
170
171 //------------------------------------------------------------------------
172 } // namespace Vst
173 } // namespace Steinberg
174