SCDoc: Use proper static string constants instead of comparing string literals.
[supercollider.git] / include / plugin_interface / SC_DemandUnit.h
blobcccce02fd6e7c87ea83b131a667308268ad81398
1 /*
2 SuperCollider real time audio synthesis system
3 Copyright (c) 2002 James McCartney. All rights reserved.
4 http://www.audiosynth.com
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_DemandUnit_
22 #define _SC_DemandUnit_
24 #include "SC_Unit.h"
25 #include "SC_Wire.h"
27 // demand rate unit support.
29 inline bool IsDemandInput(Unit* unit, int index)
31 Unit* fromUnit = unit->mInput[index]->mFromUnit;
32 return fromUnit && fromUnit->mCalcRate == calc_DemandRate;
35 inline float DemandInput(Unit* unit, int index)
37 Unit* fromUnit = unit->mInput[index]->mFromUnit;
38 if (fromUnit && fromUnit->mCalcRate == calc_DemandRate)
39 (fromUnit->mCalcFunc)(fromUnit, 1);
40 return IN0(index);
43 // support for audio rate input to demand UGens
44 // offset comes in as inNumSamples, so is in the range 1..size ! inNumSamples = 0 has a special meaning (reset).
45 // it is converted to a buffer index here.
47 inline float DemandInputA(Unit* unit, int index, int offset)
49 Unit* fromUnit = unit->mInput[index]->mFromUnit;
50 if(!fromUnit) { return IN0(index); }
51 if (fromUnit->mCalcRate == calc_DemandRate) {
52 (fromUnit->mCalcFunc)(fromUnit, offset);
53 return IN0(index);
54 } else if (fromUnit->mCalcRate == calc_FullRate) {
55 return IN(index)[offset - 1];
56 } else {
57 return IN0(index);
61 inline void ResetInput(Unit* unit, int index)
63 Unit* fromUnit = unit->mInput[index]->mFromUnit;
64 if (fromUnit && fromUnit->mCalcRate == calc_DemandRate)
65 (fromUnit->mCalcFunc)(fromUnit, 0);
68 #define ISDEMANDINPUT(index) IsDemandInput(unit, (index))
69 #define DEMANDINPUT(index) DemandInput(unit, (index))
70 #define DEMANDINPUT_A(index, offset) DemandInputA(unit, (index), (offset))
71 #define RESETINPUT(index) ResetInput(unit, (index))
73 #endif