~ubuntu-branches/ubuntu/saucy/faust/saucy

« back to all changes in this revision

Viewing changes to compiler/signals/sigtype.hh

  • Committer: Package Import Robot
  • Author(s): Mario Lang
  • Date: 2012-04-04 13:52:01 UTC
  • mfrom: (1.1.6) (3.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20120404135201-hpsrk87x3hga94tc
Tags: 0.9.46-2
* Fix "ftbfs with GCC-4.7":
  - debian/patches/unistd: Include <unistd.h> where necessary.
    (Closes: #667163)

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include <vector>
28
28
#include <string>
29
29
#include <iostream>
 
30
#include "tree.hh"
30
31
#include "smartpointer.hh"
31
32
#include "interval.hh"
32
33
 
80
81
 */
81
82
class AudioType
82
83
{
 
84
  public:
 
85
    static int  gAllocationCount;
83
86
  protected:
84
87
        int             fNature;                        ///< the kind of data represented
85
88
        int             fVariability;           ///< how fast values change
88
91
    int                 fBoolean;           ///< when a signal stands for a boolean value
89
92
    
90
93
    interval    fInterval;                      ///< Minimal and maximal values the signal can take
 
94
    Tree        fCode;              ///< Tree representation (for memoization purposes)
91
95
 
92
96
        
93
97
  public :                
94
98
        AudioType(int n, int v, int c, int vec = kVect, int b = kNum, interval i=interval()) 
95
99
                  : fNature(n), fVariability(v), fComputability(c), 
96
100
                    fVectorability(vec), fBoolean(b), 
97
 
                    fInterval(i) {}                                                                     ///< constructs an abstract audio type  
 
101
            fInterval(i), fCode(0) {}                           ///< constructs an abstract audio type
98
102
        virtual ~AudioType()                                                                    {}      ///< not really useful here, but make compiler happier
99
103
        
100
104
        int     nature()                const   { return fNature;               }       ///< returns the kind of values (integre or floating point)
103
107
        int     vectorability() const   { return fVectorability;}       ///< returns when a signal can be vectorized
104
108
        int     boolean()               const   { return fBoolean; }            ///< returns when a signal stands for a boolean value
105
109
        
106
 
        interval getInterval()  const   { return fInterval; }           ///< returns the interval (min dn max values) of a signal
 
110
    interval getInterval()      const   { return fInterval; }           ///< returns the interval (min dn max values) of a signal
 
111
 
 
112
    void    setCode(Tree code)      { fCode = code; }           ///< returns the interval (min dn max values) of a signal
 
113
    Tree    getCode()               { return fCode; }           ///< returns the interval (min dn max values) of a signal
107
114
 
108
115
        
109
116
        virtual AudioType* promoteNature(int n)         = 0;                    ///< promote the nature of a type
110
 
        virtual AudioType* promoteVariability(int n)    = 0;                    ///< promote the variability of a type
111
 
        virtual AudioType* promoteComputability(int n)  = 0;                    ///< promote the computability of a type
112
 
    virtual AudioType* promoteVectorability(int n)      = 0;                    ///< promote the vectorability of a type
 
117
    virtual AudioType* promoteVariability(int n)        = 0;            ///< promote the variability of a type
 
118
    virtual AudioType* promoteComputability(int n)      = 0;            ///< promote the computability of a type
 
119
    virtual AudioType* promoteVectorability(int n)      = 0;            ///< promote the vectorability of a type
113
120
        virtual AudioType* promoteBoolean(int n)        = 0;                    ///< promote the booleanity of a type
114
121
        //virtual AudioType* promoteInterval(const interval& i) = 0;            ///< promote the interval of a type
115
122
 
116
123
        
117
 
        virtual ostream& print(ostream& dst) const              = 0;                    ///< print nicely a type
 
124
    virtual ostream& print(ostream& dst) const          = 0;            ///< print nicely a type
 
125
    virtual bool    isMaximal() const               = 0;        ///< true when type is maximal (and therefore can't change depending of hypothesis)
118
126
        
119
127
  protected:    
120
128
        void            setInterval(const interval& r)  { fInterval = r;}
210
218
}
211
219
 
212
220
 
213
 
 
 
221
AudioType* makeSimpleType(int n, int v, int c, int vec, int b, const interval& i);
 
222
 
 
223
AudioType* makeTableType(const Type& ct);
 
224
AudioType* makeTableType(const Type& ct, int n, int v, int c, int vec);
 
225
AudioType* makeTableType(const Type& ct, int n, int v, int c, int vec, int b, const interval& i);
 
226
 
 
227
 
 
228
AudioType* makeTupletType(const vector<Type>& vt);
 
229
AudioType* makeTupletType(const vector<Type>& vt, int n, int v, int c, int vec, int b, const interval& i);
214
230
 
215
231
/**
216
232
 * The type of a simple numeric audio signal.
225
241
        SimpleType(int n, int v, int c, int vec, int b, const interval& i) : AudioType(n,v,c,vec,b,i) {
226
242
                //cerr << "new simple type " << i << " -> " << *this << endl;
227
243
        }                       ///< constructs a SimpleType from a nature a variability and a computability
228
 
                        
 
244
 
229
245
        virtual ostream& print(ostream& dst) const;                                             ///< print a SimpleType
230
 
        
231
 
        virtual AudioType* promoteNature(int n)                         { return new SimpleType(n|fNature, fVariability, fComputability, fVectorability, fBoolean, fInterval); }                ///< promote the nature of a type
232
 
        virtual AudioType* promoteVariability(int v)                    { return new SimpleType(fNature, v|fVariability, fComputability, fVectorability, fBoolean, fInterval); }                ///< promote the variability of a type
233
 
        virtual AudioType* promoteComputability(int c)                  { return new SimpleType(fNature, fVariability, c|fComputability, fVectorability, fBoolean, fInterval); }                ///< promote the computability of a type
234
 
        virtual AudioType* promoteVectorability(int vec)                { return new SimpleType(fNature, fVariability, fComputability, vec|fVectorability, fBoolean, fInterval); }      ///< promote the vectorability of a type
235
 
        virtual AudioType* promoteBoolean(int b)                        { return new SimpleType(fNature, fVariability, fComputability, fVectorability, b|fBoolean, fInterval); }                ///< promote the booleanity of a type
 
246
 
 
247
 
 
248
 
 
249
    virtual AudioType* promoteNature(int n)                             { return makeSimpleType(n|fNature, fVariability, fComputability, fVectorability, fBoolean, fInterval); }                ///< promote the nature of a type
 
250
    virtual AudioType* promoteVariability(int v)                        { return makeSimpleType(fNature, v|fVariability, fComputability, fVectorability, fBoolean, fInterval); }                ///< promote the variability of a type
 
251
    virtual AudioType* promoteComputability(int c)                      { return makeSimpleType(fNature, fVariability, c|fComputability, fVectorability, fBoolean, fInterval); }                ///< promote the computability of a type
 
252
    virtual AudioType* promoteVectorability(int vec)            { return makeSimpleType(fNature, fVariability, fComputability, vec|fVectorability, fBoolean, fInterval); }      ///< promote the vectorability of a type
 
253
    virtual AudioType* promoteBoolean(int b)                    { return makeSimpleType(fNature, fVariability, fComputability, fVectorability, b|fBoolean, fInterval); }                ///< promote the booleanity of a type
236
254
//      virtual AudioType* promoteInterval(const interval& i)   { 
237
255
//              cerr << "promote to Interval " << i  << endl; 
238
256
//              cerr << "for type : " << *this << endl;
239
 
//              Type t = new SimpleType(fNature, fVariability, fComputability, fVectorability, fBoolean, i);                            ///< promote the interval of a type
 
257
//              Type t = makeSimpleType(fNature, fVariability, fComputability, fVectorability, fBoolean, i);                            ///< promote the interval of a type
240
258
//              cerr << "gives type " << *t << endl;
241
259
//              return t;
242
260
//      }
243
261
 
244
262
 
 
263
    virtual bool    isMaximal() const;                              ///< true when type is maximal (and therefore can't change depending of hypothesis)
 
264
 
 
265
 
 
266
 
245
267
};
246
268
 
247
 
inline Type intCast (Type t)    { return new SimpleType(kInt, t->variability(), t->computability(), t->vectorability(), t->boolean(), t->getInterval()); }
248
 
inline Type floatCast (Type t)  { return new SimpleType(kReal, t->variability(), t->computability(), t->vectorability(), t->boolean(), t->getInterval()); }
249
 
inline Type sampCast (Type t)   { return new SimpleType(t->nature(), kSamp, t->computability(), t->vectorability(), t->boolean(), t->getInterval()); }
250
 
inline Type boolCast (Type t)   { return new SimpleType(t->nature(), t->variability(), t->computability(), t->vectorability(), kBool, t->getInterval()); }
251
 
inline Type numCast (Type t)    { return new SimpleType(t->nature(), t->variability(), t->computability(), t->vectorability(), kNum, t->getInterval()); }
252
 
inline Type vecCast (Type t)    { return new SimpleType(t->nature(), t->variability(), t->computability(), kVect, t->boolean(), t->getInterval()); }
253
 
inline Type scalCast (Type t)   { return new SimpleType(t->nature(), t->variability(), t->computability(), kScal, t->boolean(), t->getInterval()); }
254
 
inline Type truescalCast (Type t){ return new SimpleType(t->nature(), t->variability(), t->computability(), kTrueScal, t->boolean(), t->getInterval()); }
 
269
inline Type intCast (Type t)    { return makeSimpleType(kInt, t->variability(), t->computability(), t->vectorability(), t->boolean(), t->getInterval()); }
 
270
inline Type floatCast (Type t)  { return makeSimpleType(kReal, t->variability(), t->computability(), t->vectorability(), t->boolean(), t->getInterval()); }
 
271
inline Type sampCast (Type t)   { return makeSimpleType(t->nature(), kSamp, t->computability(), t->vectorability(), t->boolean(), t->getInterval()); }
 
272
inline Type boolCast (Type t)   { return makeSimpleType(t->nature(), t->variability(), t->computability(), t->vectorability(), kBool, t->getInterval()); }
 
273
inline Type numCast (Type t)    { return makeSimpleType(t->nature(), t->variability(), t->computability(), t->vectorability(), kNum, t->getInterval()); }
 
274
inline Type vecCast (Type t)    { return makeSimpleType(t->nature(), t->variability(), t->computability(), kVect, t->boolean(), t->getInterval()); }
 
275
inline Type scalCast (Type t)   { return makeSimpleType(t->nature(), t->variability(), t->computability(), kScal, t->boolean(), t->getInterval()); }
 
276
inline Type truescalCast (Type t){ return makeSimpleType(t->nature(), t->variability(), t->computability(), kTrueScal, t->boolean(), t->getInterval()); }
255
277
 
256
278
inline Type castInterval (Type t, const interval& i)    
257
279
258
 
        return new SimpleType(t->nature(), t->variability(), t->computability(), t->vectorability(), t->boolean(), i); 
 
280
    return makeSimpleType(t->nature(), t->variability(), t->computability(), t->vectorability(), t->boolean(), i);
259
281
}
260
282
 
261
283
/**
272
294
        TableType(const Type& t) : 
273
295
                  AudioType(t->nature(), t->variability(), t->computability(), t->vectorability(), t->boolean()), 
274
296
                  fContent(t) {}                ///< construct a TableType with a content of a type t
275
 
 
 
297
#if 0
276
298
        TableType(const Type& t, int v, int c) : 
277
299
                  AudioType(t->nature(), t->variability()|v, t->computability()|c, t->vectorability(), t->boolean()), 
278
300
                  fContent(t) {}                ///< construct a TableType with a content of a type t, promoting variability and computability
281
303
                  AudioType(t->nature()|n, t->variability()|v, t->computability()|c, t->vectorability(), t->boolean()), 
282
304
                  fContent(t) {}                ///< construct a TableType with a content of a type t, promoting nature, variability and computability
283
305
 
284
 
        TableType(const Type& t, int n, int v, int c, int vec) :
285
 
                  AudioType(t->nature()|n, t->variability()|v, t->computability()|c, t->vectorability()|vec, t->boolean()),
286
 
                  fContent(t) {}                ///< construct a TableType with a content of a type t, promoting nature, variability, computability and vectorability
287
 
 
288
306
        TableType(const Type& t, int n, int v, int c, int vec, int b) :
289
307
                  AudioType(t->nature()|n, t->variability()|v, t->computability()|c, t->vectorability()|vec, t->boolean()|b),
290
308
                  fContent(t) {}                ///< construct a TableType with a content of a type t, promoting nature, variability, computability, vectorability and booleanity
291
 
 
292
 
        TableType(const Type& t, int n, int v, int c, int vec, int b, const interval& i) :
293
 
                  AudioType(t->nature()|n, t->variability()|v, t->computability()|c, t->vectorability()|vec, t->boolean()|b, i),
294
 
                  fContent(t) {}                ///< construct a TableType with a content of a type t, promoting nature, variability, computability, vectorability and booleanity
295
 
 
296
 
  
 
309
#endif
 
310
 
 
311
    TableType(const Type& t, int n, int v, int c, int vec, int b, const interval& i) :
 
312
          AudioType(t->nature()|n, t->variability()|v, t->computability()|c, t->vectorability()|vec, t->boolean()|b, i),
 
313
          fContent(t) {}                ///< construct a TableType with a content of a type t, promoting nature, variability, computability, vectorability and booleanity
 
314
 
 
315
    TableType(const Type& t, int n, int v, int c, int vec) :
 
316
          AudioType(t->nature()|n, t->variability()|v, t->computability()|c, t->vectorability()|vec, t->boolean()),
 
317
          fContent(t) {}                ///< construct a TableType with a content of a type t, promoting nature, variability, computability and vectorability
 
318
 
297
319
 
298
320
        Type content() const                            { return fContent;      }               ///< return the type of data store in the table
299
321
        virtual ostream& print(ostream& dst) const;                                             ///< print a TableType
300
322
        
301
 
        virtual AudioType* promoteNature(int n)                         { return new TableType(fContent, n|fNature, fVariability, fComputability, fVectorability, fBoolean, fInterval); }       ///< promote the nature of a type
302
 
        virtual AudioType* promoteVariability(int v)                    { return new TableType(fContent, fNature, v|fVariability, fComputability, fVectorability, fBoolean, fInterval); }       ///< promote the variability of a type
303
 
        virtual AudioType* promoteComputability(int c)                  { return new TableType(fContent, fNature, fVariability, c|fComputability, fVectorability, fBoolean, fInterval); }       ///< promote the computability of a type
304
 
        virtual AudioType* promoteVectorability(int vec)                { return new TableType(fContent, fNature, fVariability, fComputability, vec|fVectorability, fBoolean, fInterval);}///< promote the vectorability of a type
305
 
        virtual AudioType* promoteBoolean(int b)                        { return new TableType(fContent, fNature, fVariability, fComputability, fVectorability, b|fBoolean, fInterval); }       ///< promote the booleanity of a type
306
 
        //virtual AudioType* promoteInterval(const interval& i) { return new TableType(fContent, fNature, fVariability, fComputability, fVectorability, fBoolean, i); }                 ///< promote the interval of a type
 
323
    virtual AudioType* promoteNature(int n)                             { return makeTableType(fContent, n|fNature, fVariability, fComputability, fVectorability, fBoolean, fInterval); }       ///< promote the nature of a type
 
324
    virtual AudioType* promoteVariability(int v)                        { return makeTableType(fContent, fNature, v|fVariability, fComputability, fVectorability, fBoolean, fInterval); }       ///< promote the variability of a type
 
325
    virtual AudioType* promoteComputability(int c)                      { return makeTableType(fContent, fNature, fVariability, c|fComputability, fVectorability, fBoolean, fInterval); }       ///< promote the computability of a type
 
326
    virtual AudioType* promoteVectorability(int vec)            { return makeTableType(fContent, fNature, fVariability, fComputability, vec|fVectorability, fBoolean, fInterval);}///< promote the vectorability of a type
 
327
    virtual AudioType* promoteBoolean(int b)                    { return makeTableType(fContent, fNature, fVariability, fComputability, fVectorability, b|fBoolean, fInterval); }       ///< promote the booleanity of a type
 
328
    //virtual AudioType* promoteInterval(const interval& i)     { return makeTableType(fContent, fNature, fVariability, fComputability, fVectorability, fBoolean, i); }                 ///< promote the interval of a type
307
329
 
 
330
    virtual bool    isMaximal() const;                              ///< true when type is maximal (and therefore can't change depending of hypothesis)
308
331
};
309
332
 
310
333
 
320
343
        vector<Type> fComponents;
321
344
        
322
345
  public:
323
 
        TupletType(const vector<Type>& vt) : 
324
 
                  AudioType(mergenature(vt),mergevariability(vt),mergecomputability(vt),mergevectorability(vt),mergeboolean(vt), mergeinterval(vt)), 
325
 
                  fComponents(vt) {}
326
 
 
327
 
        TupletType(const vector<Type>& vt, int n, int v, int c) : 
328
 
                  AudioType(n|mergenature(vt), v|mergevariability(vt), c|mergecomputability(vt),mergevectorability(vt),mergeboolean(vt), interval()), 
329
 
                  fComponents(vt) {}
330
 
 
331
 
        TupletType(const vector<Type>& vt, int n, int v, int c, int vec) :
332
 
                  AudioType(n|mergenature(vt), v|mergevariability(vt), c|mergecomputability(vt), vec|mergevectorability(vt), mergeboolean(vt), interval()),
333
 
                  fComponents(vt) {}
 
346
    TupletType() :
 
347
          AudioType(0,0,0)
 
348
          {}
 
349
 
 
350
    TupletType(const vector<Type>& vt) :
 
351
          AudioType(mergenature(vt),mergevariability(vt),mergecomputability(vt),mergevectorability(vt),mergeboolean(vt), mergeinterval(vt)),
 
352
          fComponents(vt) {}
334
353
 
335
354
        TupletType(const vector<Type>& vt, int n, int v, int c, int vec, int b, const interval& i) :
336
355
                  AudioType(n|mergenature(vt), v|mergevariability(vt), c|mergecomputability(vt), vec|mergevectorability(vt), b|mergeboolean(vt), i),
347
366
        virtual AudioType* promoteBoolean(int b)                        { return new TupletType(fComponents, fNature, fVariability, fComputability, fVectorability, b|fBoolean, fInterval);  }  ///< promote the booleanity of a type
348
367
        //virtual AudioType* promoteInterval(const interval& i) { return new TupletType(fComponents, fNature, fVariability, fComputability, fVectorability, fBoolean, i);  }                    ///< promote the interval of a type
349
368
  
 
369
    virtual bool    isMaximal() const;                              ///< true when type is maximal (and therefore can't change depending of hypothesis)
350
370
 
351
371
};
352
372
 
377
397
 
378
398
extern Type TINPUT;
379
399
extern Type TGUI;
 
400
extern Type TGUI01;
380
401
extern Type INT_TGUI;
381
402
extern Type TREC;
382
403
 
437
458
 
438
459
string cType (Type t);
439
460
 
 
461
Tree codeAudioType(AudioType* t);   ///< Code an audio type as a tree (memoization)
 
462
 
440
463
 
441
464
#endif