00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _SigType_
00025 #define _SigType_
00026
00027 #include <vector>
00028 #include <string>
00029 #include <iostream>
00030 #include "smartpointer.hh"
00031 #include "interval.hh"
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 enum { kInt = 0, kReal = 1 };
00054 enum { kNum = 0 , kBool = 1};
00055 enum { kKonst = 0, kBlock = 1, kSamp = 3 };
00056 enum { kComp = 0, kInit = 1, kExec = 3 };
00057 enum { kVect = 0, kScal = 1, kTrueScal = 3};
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 using namespace std;
00070
00071 class AudioType;
00072
00073 typedef P<AudioType> Type;
00074
00081 class AudioType
00082 {
00083 protected:
00084 int fNature;
00085 int fVariability;
00086 int fComputability;
00087 int fVectorability;
00088 int fBoolean;
00089
00090 interval fInterval;
00091
00092
00093 public :
00094 AudioType(int n, int v, int c, int vec = kVect, int b = kNum, interval i=interval())
00095 : fNature(n), fVariability(v), fComputability(c),
00096 fVectorability(vec), fBoolean(b),
00097 fInterval(i) {}
00098 virtual ~AudioType() {}
00099
00100 int nature() const { return fNature; }
00101 int variability() const { return fVariability; }
00102 int computability() const { return fComputability;}
00103 int vectorability() const { return fVectorability;}
00104 int boolean() const { return fBoolean; }
00105
00106 interval getInterval() const { return fInterval; }
00107
00108
00109 virtual AudioType* promoteNature(int n) = 0;
00110 virtual AudioType* promoteVariability(int n) = 0;
00111 virtual AudioType* promoteComputability(int n) = 0;
00112 virtual AudioType* promoteVectorability(int n) = 0;
00113 virtual AudioType* promoteBoolean(int n) = 0;
00114
00115
00116
00117 virtual ostream& print(ostream& dst) const = 0;
00118
00119 protected:
00120 void setInterval(const interval& r) { fInterval = r;}
00121
00122 };
00123
00124
00125 inline ostream& operator << (ostream& s, const AudioType& n) { return n.print(s); }
00126
00127
00131 inline int mergenature(const vector<Type>& v)
00132 {
00133 int r = 0;
00134 for (unsigned int i = 0; i < v.size(); i++) r |= v[i]->nature();
00135 return r;
00136 }
00137
00138
00139
00143 inline int mergevariability(const vector<Type>& v)
00144 {
00145 int r = 0;
00146 for (unsigned int i = 0; i < v.size(); i++) r |= v[i]->variability();
00147 return r;
00148 }
00149
00150
00151
00155 inline int mergecomputability(const vector<Type>& v)
00156 {
00157 int r = 0;
00158 for (unsigned int i = 0; i < v.size(); i++) r |= v[i]->computability();
00159 return r;
00160 }
00161
00162
00163
00167 inline int mergevectorability(const vector<Type>& v)
00168 {
00169 int r = 0;
00170 for (unsigned int i = 0; i < v.size(); i++) r |= v[i]->vectorability();
00171 return r;
00172 }
00173
00174
00175
00179 inline int mergeboolean(const vector<Type>& v)
00180 {
00181 int r = 0;
00182 for (unsigned int i = 0; i < v.size(); i++) r |= v[i]->boolean();
00183 return r;
00184 }
00185
00186
00187
00191 inline interval mergeinterval(const vector<Type>& v)
00192 {
00193 if (v.size()==0) {
00194 return interval();
00195 } else {
00196 double lo=0, hi=0;
00197 for (unsigned int i = 0; i < v.size(); i++) {
00198 interval r = v[i]->getInterval();
00199 if (!r.valid) return r;
00200 if (i==0) {
00201 lo = r.lo;
00202 hi = r.hi;
00203 } else {
00204 lo = min(lo,r.lo);
00205 hi = max(hi,r.hi);
00206 }
00207 }
00208 return interval(lo, hi);
00209 }
00210 }
00211
00212
00213
00214
00221 class SimpleType : public AudioType
00222 {
00223 public :
00224
00225 SimpleType(int n, int v, int c, int vec, int b, const interval& i) : AudioType(n,v,c,vec,b,i) {
00226
00227 }
00228
00229 virtual ostream& print(ostream& dst) const;
00230
00231 virtual AudioType* promoteNature(int n) { return new SimpleType(n|fNature, fVariability, fComputability, fVectorability, fBoolean, fInterval); }
00232 virtual AudioType* promoteVariability(int v) { return new SimpleType(fNature, v|fVariability, fComputability, fVectorability, fBoolean, fInterval); }
00233 virtual AudioType* promoteComputability(int c) { return new SimpleType(fNature, fVariability, c|fComputability, fVectorability, fBoolean, fInterval); }
00234 virtual AudioType* promoteVectorability(int vec) { return new SimpleType(fNature, fVariability, fComputability, vec|fVectorability, fBoolean, fInterval); }
00235 virtual AudioType* promoteBoolean(int b) { return new SimpleType(fNature, fVariability, fComputability, fVectorability, b|fBoolean, fInterval); }
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245 };
00246
00247 inline Type intCast (Type t) { return new SimpleType(kInt, t->variability(), t->computability(), t->vectorability(), t->boolean(), t->getInterval()); }
00248 inline Type floatCast (Type t) { return new SimpleType(kReal, t->variability(), t->computability(), t->vectorability(), t->boolean(), t->getInterval()); }
00249 inline Type sampCast (Type t) { return new SimpleType(t->nature(), kSamp, t->computability(), t->vectorability(), t->boolean(), t->getInterval()); }
00250 inline Type boolCast (Type t) { return new SimpleType(t->nature(), t->variability(), t->computability(), t->vectorability(), kBool, t->getInterval()); }
00251 inline Type numCast (Type t) { return new SimpleType(t->nature(), t->variability(), t->computability(), t->vectorability(), kNum, t->getInterval()); }
00252 inline Type vecCast (Type t) { return new SimpleType(t->nature(), t->variability(), t->computability(), kVect, t->boolean(), t->getInterval()); }
00253 inline Type scalCast (Type t) { return new SimpleType(t->nature(), t->variability(), t->computability(), kScal, t->boolean(), t->getInterval()); }
00254 inline Type truescalCast (Type t){ return new SimpleType(t->nature(), t->variability(), t->computability(), kTrueScal, t->boolean(), t->getInterval()); }
00255
00256 inline Type castInterval (Type t, const interval& i)
00257 {
00258 return new SimpleType(t->nature(), t->variability(), t->computability(), t->vectorability(), t->boolean(), i);
00259 }
00260
00266 class TableType : public AudioType
00267 {
00268 protected :
00269 const Type fContent;
00270
00271 public :
00272 TableType(const Type& t) :
00273 AudioType(t->nature(), t->variability(), t->computability(), t->vectorability(), t->boolean()),
00274 fContent(t) {}
00275
00276 TableType(const Type& t, int v, int c) :
00277 AudioType(t->nature(), t->variability()|v, t->computability()|c, t->vectorability(), t->boolean()),
00278 fContent(t) {}
00279
00280 TableType(const Type& t, int n, int v, int c) :
00281 AudioType(t->nature()|n, t->variability()|v, t->computability()|c, t->vectorability(), t->boolean()),
00282 fContent(t) {}
00283
00284 TableType(const Type& t, int n, int v, int c, int vec) :
00285 AudioType(t->nature()|n, t->variability()|v, t->computability()|c, t->vectorability()|vec, t->boolean()),
00286 fContent(t) {}
00287
00288 TableType(const Type& t, int n, int v, int c, int vec, int b) :
00289 AudioType(t->nature()|n, t->variability()|v, t->computability()|c, t->vectorability()|vec, t->boolean()|b),
00290 fContent(t) {}
00291
00292 TableType(const Type& t, int n, int v, int c, int vec, int b, const interval& i) :
00293 AudioType(t->nature()|n, t->variability()|v, t->computability()|c, t->vectorability()|vec, t->boolean()|b, i),
00294 fContent(t) {}
00295
00296
00297
00298 Type content() const { return fContent; }
00299 virtual ostream& print(ostream& dst) const;
00300
00301 virtual AudioType* promoteNature(int n) { return new TableType(fContent, n|fNature, fVariability, fComputability, fVectorability, fBoolean, fInterval); }
00302 virtual AudioType* promoteVariability(int v) { return new TableType(fContent, fNature, v|fVariability, fComputability, fVectorability, fBoolean, fInterval); }
00303 virtual AudioType* promoteComputability(int c) { return new TableType(fContent, fNature, fVariability, c|fComputability, fVectorability, fBoolean, fInterval); }
00304 virtual AudioType* promoteVectorability(int vec) { return new TableType(fContent, fNature, fVariability, fComputability, vec|fVectorability, fBoolean, fInterval);}
00305 virtual AudioType* promoteBoolean(int b) { return new TableType(fContent, fNature, fVariability, fComputability, fVectorability, b|fBoolean, fInterval); }
00306
00307
00308 };
00309
00310
00311
00317 class TupletType : public AudioType
00318 {
00319 protected:
00320 vector<Type> fComponents;
00321
00322 public:
00323 TupletType(const vector<Type>& vt) :
00324 AudioType(mergenature(vt),mergevariability(vt),mergecomputability(vt),mergevectorability(vt),mergeboolean(vt), mergeinterval(vt)),
00325 fComponents(vt) {}
00326
00327 TupletType(const vector<Type>& vt, int n, int v, int c) :
00328 AudioType(n|mergenature(vt), v|mergevariability(vt), c|mergecomputability(vt),mergevectorability(vt),mergeboolean(vt), interval()),
00329 fComponents(vt) {}
00330
00331 TupletType(const vector<Type>& vt, int n, int v, int c, int vec) :
00332 AudioType(n|mergenature(vt), v|mergevariability(vt), c|mergecomputability(vt), vec|mergevectorability(vt), mergeboolean(vt), interval()),
00333 fComponents(vt) {}
00334
00335 TupletType(const vector<Type>& vt, int n, int v, int c, int vec, int b, const interval& i) :
00336 AudioType(n|mergenature(vt), v|mergevariability(vt), c|mergecomputability(vt), vec|mergevectorability(vt), b|mergeboolean(vt), i),
00337 fComponents(vt) {}
00338
00339 int arity() const { return fComponents.size(); }
00340 Type operator[](unsigned int i) const { return fComponents[i]; }
00341 virtual ostream& print(ostream& dst) const;
00342
00343 virtual AudioType* promoteNature(int n) { return new TupletType(fComponents, n|fNature, fVariability, fComputability, fVectorability, fBoolean, fInterval); }
00344 virtual AudioType* promoteVariability(int v) { return new TupletType(fComponents, fNature, v|fVariability, fComputability, fVectorability, fBoolean, fInterval); }
00345 virtual AudioType* promoteComputability(int c) { return new TupletType(fComponents, fNature, fVariability, c|fComputability, fVectorability, fBoolean, fInterval); }
00346 virtual AudioType* promoteVectorability(int vec) { return new TupletType(fComponents, fNature, fVariability, fComputability, vec|fVectorability, fBoolean, fInterval);}
00347 virtual AudioType* promoteBoolean(int b) { return new TupletType(fComponents, fNature, fVariability, fComputability, fVectorability, b|fBoolean, fInterval); }
00348
00349
00350
00351 };
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367 extern Type TINT;
00368 extern Type TREAL;
00369
00370 extern Type TKONST;
00371 extern Type TBLOCK;
00372 extern Type TSAMP;
00373
00374 extern Type TCOMP;
00375 extern Type TINIT;
00376 extern Type TEXEC;
00377
00378 extern Type TINPUT;
00379 extern Type TGUI;
00380 extern Type INT_TGUI;
00381 extern Type TREC;
00382
00383
00384
00385
00386
00387 Type table (const Type& t);
00388 Type operator| (const Type& t1, const Type& t2);
00389 Type operator* (const Type& t1, const Type& t2);
00390
00391
00392
00393
00394
00395 bool operator==(const Type& t1, const Type& t2);
00396 bool operator<=(const Type& t1, const Type& t2);
00397
00398 inline bool operator!=(const Type& t1, const Type& t2) { return !(t1==t2); }
00399 inline bool operator< (const Type& t1, const Type& t2) { return t1<=t2 && t1!=t2; }
00400 inline bool operator> (const Type& t1, const Type& t2) { return t2<t1; }
00401 inline bool operator>=(const Type& t1, const Type& t2) { return t2<=t1; }
00402
00403
00404
00405
00406
00407 SimpleType* isSimpleType (AudioType* t);
00408 TableType* isTableType (AudioType* t);
00409 TupletType* isTupletType (AudioType* t);
00410
00411
00412
00413
00414
00415 ostream& operator<<(ostream& dst, const SimpleType& t);
00416 ostream& operator<<(ostream& dst, const Type& t);
00417 ostream& operator<<(ostream& dst, const TableType& t);
00418 ostream& operator<<(ostream& dst, const TupletType& t);
00419
00420
00421
00422
00423
00424 Type checkInt(Type t);
00425 Type checkKonst(Type t);
00426 Type checkInit(Type t);
00427
00428 Type checkIntParam(Type t);
00429
00430 Type checkWRTbl(Type tbl, Type wr);
00431
00432 int checkDelayInterval(Type t);
00433
00434
00435
00436
00437
00438 string cType (Type t);
00439
00440
00441 #endif