2 * SuperCollider real time audio synthesis system
3 * Copyright (c) 2002 James McCartney. All rights reserved.
4 * Copyright (c) 2011 Tim Blechmann
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "SC_PlugIn.h"
26 // c++ wrapper for Unit struct
31 const float * in(int index
) const
33 const Unit
* unit
= this;
37 const float * zin(int index
) const
39 const Unit
* unit
= this;
43 float const & in0(int index
) const
45 const Unit
* unit
= this;
49 float * out(int index
) const
51 const Unit
* unit
= this;
55 float * zout(int index
) const
57 const Unit
* unit
= this;
61 float & out0(int index
) const
63 const Unit
* unit
= this;
67 int inRate(int index
) const
69 const Unit
* unit
= this;
73 int inBufferSize(int index
) const
75 const Unit
* unit
= this;
76 return INBUFLENGTH(index
);
80 double sampleRate() const
82 const Unit
* unit
= this;
86 double sampleDur() const
88 const Unit
* unit
= this;
92 int bufferSize() const
97 double controlRate() const
99 const Unit
* unit
= this;
103 double controlDur() const
105 const Unit
* unit
= this;
109 double fullSampleRate() const
111 const Unit
* unit
= this;
115 int fullBufferSize() const
117 const Unit
* unit
= this;
118 return FULLBUFLENGTH
;
122 template <typename FloatType
>
123 FloatType
calcSlope(FloatType next
, FloatType prev
) const
125 const Unit
* unit
= this;
126 return CALCSLOPE(next
, prev
);
129 template <typename UnitType
, void (UnitType::*PointerToMember
)(int)>
130 static UnitCalcFunc
make_calc_function(void)
132 return &run_member_function
<UnitType
, PointerToMember
>;
136 /// set calc function & compute initial sample
137 template <typename UnitType
, void (UnitType::*PointerToMember
)(int)>
138 void set_calc_function(void)
140 mCalcFunc
= make_calc_function
<UnitType
, PointerToMember
>();
141 (mCalcFunc
)(this, 1);
144 template <typename UnitType
, void (UnitType::*VectorCalcFunc
)(int), void (UnitType::*ScalarCalcFunc
)(int)>
145 void set_vector_calc_function(void)
147 mCalcFunc
= make_calc_function
<UnitType
, VectorCalcFunc
>();
148 make_calc_function
<UnitType
, ScalarCalcFunc
>()(this, 1);
153 template <typename UnitType
, void (UnitType::*PointerToMember
)(int)>
154 static void run_member_function(struct Unit
* unit
, int inNumSamples
)
156 UnitType
* realUnit
= static_cast<UnitType
*>(unit
);
157 ((realUnit
)->*(PointerToMember
))(inNumSamples
);
161 // define Ctor/Dtor functions
162 #define DEFINE_XTORS(CLASSNAME) \
163 void CLASSNAME##_Ctor(CLASSNAME * unit) \
165 new(unit) CLASSNAME(); \
168 void CLASSNAME##_Dtor(CLASSNAME * unit) \
170 unit->~CLASSNAME(); \
173 #endif /* SC_PLUGIN_HPP */