1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
/************************************************************************
************************************************************************
FAUST compiler
Copyright (C) 2003-2018 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
************************************************************************
************************************************************************/
#include "sigIdentity.hh"
#include <stdlib.h>
#include <cstdlib>
#include "Text.hh"
#include "global.hh"
#include "ppsig.hh"
#include "signals.hh"
using namespace std;
//-------------------------SignalIdentity-------------------------------
// An identity transformation on signals. Can be used to test
// that everything works, and as a pattern for real transformations.
//----------------------------------------------------------------------
void SignalIdentity::traceEnter(Tree t)
{
tab(fIndent, cerr);
cerr << fMessage << ": " << ppsig(t, MAX_ERROR_SIZE) << endl;
}
void SignalIdentity::traceExit(Tree t, Tree r)
{
tab(fIndent, cerr);
cerr << fMessage << ": " << ppsig(t, MAX_ERROR_SIZE) << " => " << ppsig(r, MAX_ERROR_SIZE)
<< endl;
}
Tree SignalIdentity::transformation(Tree sig)
{
int i;
int64_t i64;
double r;
Tree c, sel, w, x, y, z, u, v, var, le, label, ff, largs, type, name, file, sf;
if (getUserData(sig)) {
vector<Tree> newBranches;
for (Tree b : sig->branches()) {
newBranches.push_back(self(b));
}
return tree(sig->node(), newBranches);
} else if (isSigInt(sig, &i)) {
return sig;
} else if (isSigInt64(sig, &i64)) {
return sig;
} else if (isSigReal(sig, &r)) {
return sig;
} else if (isSigWaveform(sig)) {
return sig;
} else if (isSigInput(sig, &i)) {
return sig;
} else if (isSigOutput(sig, &i, x)) {
return sigOutput(i, self(x));
} else if (isSigDelay1(sig, x)) {
return sigDelay1(self(x));
} else if (isSigDelay(sig, x, y)) {
return sigDelay(self(x), self(y));
} else if (isSigPrefix(sig, x, y)) {
return sigPrefix(self(x), self(y));
} else if (isSigBinOp(sig, &i, x, y)) {
return sigBinOp(i, self(x), self(y));
}
// Foreign functions
else if (isSigFFun(sig, ff, largs)) {
return sigFFun(ff, mapself(largs));
} else if (isSigFConst(sig, type, name, file)) {
return sig;
} else if (isSigFVar(sig, type, name, file)) {
return sig;
}
// Tables
else if (isSigWRTbl(sig, w, x, y, z)) {
if (y == gGlobal->nil) {
// rdtable
return sigWRTbl(self(w), self(x));
} else {
// rwtable
return sigWRTbl(self(w), self(x), self(y), self(z));
}
} else if (isSigRDTbl(sig, x, y)) {
return sigRDTbl(self(x), self(y));
}
// Doc
else if (isSigDocConstantTbl(sig, x, y)) {
return sigDocConstantTbl(self(x), self(y));
} else if (isSigDocWriteTbl(sig, x, y, u, v)) {
return sigDocWriteTbl(self(x), self(y), self(u), self(v));
} else if (isSigDocAccessTbl(sig, x, y)) {
return sigDocAccessTbl(self(x), self(y));
}
// Select2 and Select3
else if (isSigSelect2(sig, sel, x, y)) {
return sigSelect2(self(sel), self(x), self(y));
}
// Table sigGen
else if (isSigGen(sig, x)) {
if (fVisitGen) {
return sigGen(self(x));
} else {
return sig;
}
}
// recursive signals
else if (isProj(sig, &i, x)) {
return sigProj(i, self(x));
} else if (isRec(sig, var, le)) {
if (isNil(le)) {
// we are already visiting this recursive group
return sig;
} else {
// first visit
rec(var, gGlobal->nil); // to avoid infinite recursions
return rec(var, mapselfRec(le));
}
}
// Int and Float Cast
else if (isSigIntCast(sig, x)) {
return sigIntCast(self(x));
} else if (isSigBitCast(sig, x)) {
return sigBitCast(self(x));
} else if (isSigFloatCast(sig, x)) {
return sigFloatCast(self(x));
}
// UI
else if (isSigButton(sig, label)) {
return sig;
} else if (isSigCheckbox(sig, label)) {
return sig;
} else if (isSigVSlider(sig, label, c, x, y, z)) {
return sigVSlider(label, self(c), self(x), self(y), self(z));
} else if (isSigHSlider(sig, label, c, x, y, z)) {
return sigHSlider(label, self(c), self(x), self(y), self(z));
} else if (isSigNumEntry(sig, label, c, x, y, z)) {
return sigNumEntry(label, self(c), self(x), self(y), self(z));
} else if (isSigVBargraph(sig, label, x, y, z)) {
return sigVBargraph(label, self(x), self(y), self(z));
} else if (isSigHBargraph(sig, label, x, y, z)) {
return sigHBargraph(label, self(x), self(y), self(z));
}
// Soundfile length, rate, buffer
else if (isSigSoundfile(sig, label)) {
return sig;
} else if (isSigSoundfileLength(sig, sf, x)) {
return sigSoundfileLength(self(sf), self(x));
} else if (isSigSoundfileRate(sig, sf, x)) {
return sigSoundfileRate(self(sf), self(x));
} else if (isSigSoundfileBuffer(sig, sf, x, y, z)) {
return sigSoundfileBuffer(self(sf), self(x), self(y), self(z));
}
// Attach, Enable, Control
else if (isSigAttach(sig, x, y)) {
return sigAttach(self(x), self(y));
} else if (isSigEnable(sig, x, y)) {
return sigEnable(self(x), self(y));
} else if (isSigControl(sig, x, y)) {
return sigControl(self(x), self(y));
}
// Signal interval annotation
else if (isSigAssertBounds(sig, x, y, z)) {
return sigAssertBounds(self(x), self(y), self(z));
} else if (isSigLowest(sig, x)) {
return sigLowest(self(x));
} else if (isSigHighest(sig, x)) {
return sigHighest(self(x));
}
else if (isSigRegister(sig, &i, x)) {
return sigRegister(i, self(x));
}
else {
cerr << "ASSERT : unrecognized signal : " << *sig << endl;
faustassert(false);
}
return 0;
}
|