"Post Window" -> "Post window" prevents it being seen as two separate
[supercollider.git] / include / plugin_interface / SC_PlugIn.hpp
blob8a43ff54a3b2a1dfde2ac546f587dfea7eaf2c93
1 /*
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
21 #ifndef SC_PLUGIN_HPP
22 #define SC_PLUGIN_HPP
24 #include "SC_PlugIn.h"
26 // c++ wrapper for Unit struct
27 class SCUnit:
28 public Unit
30 public:
31 const float * in(int index) const
33 const Unit * unit = this;
34 return IN(index);
37 const float * zin(int index) const
39 const Unit * unit = this;
40 return ZIN(index);
43 float const & in0(int index) const
45 const Unit * unit = this;
46 return IN0(index);
49 float * out(int index) const
51 const Unit * unit = this;
52 return OUT(index);
55 float * zout(int index) const
57 const Unit * unit = this;
58 return ZOUT(index);
61 float & out0(int index) const
63 const Unit * unit = this;
64 return OUT0(index);
67 int inRate(int index) const
69 const Unit * unit = this;
70 return INRATE(index);
73 int inBufferSize(int index) const
75 const Unit * unit = this;
76 return INBUFLENGTH(index);
79 /// @{
80 double sampleRate() const
82 const Unit * unit = this;
83 return SAMPLERATE;
86 double sampleDur() const
88 const Unit * unit = this;
89 return SAMPLEDUR;
92 int bufferSize() const
94 return mBufLength;
97 double controlRate() const
99 const Unit * unit = this;
100 return BUFRATE;
103 double controlDur() const
105 const Unit * unit = this;
106 return BUFDUR;
109 double fullSampleRate() const
111 const Unit * unit = this;
112 return FULLRATE;
115 int fullBufferSize() const
117 const Unit * unit = this;
118 return FULLBUFLENGTH;
120 /// @}
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>;
135 /// @{
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);
150 /// @}
152 private:
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 */