aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/vasp/source/vasp.h
blob: 0cc80be8018bf7f3033a7d2cab35fc6d19185955 (plain)
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
/* 

VASP modular - vector assembling signal processor / objects for Max/MSP and PD

Copyright (c) 2002 Thomas Grill (xovo@gmx.net)
For information on usage and redistribution, and for a DISCLAIMER OF ALL
WARRANTIES, see the file, "license.txt," in this distribution.  

*/

#ifndef __VASP__H
#define __VASP__H

#include "vbuffer.h"

class Vasp:
    public flext
{
public:
    class Ref:
        public flext
    {
	public:
		Ref(): sym(NULL) {}
		Ref(VBuffer &b);
		Ref(VSymbol &s,I c,I o);
		Ref(const Ref &r) { operator =(r); }
		~Ref();

		Ref &operator =(const Ref &r);

		V Clear() { sym.Clear(); }
		BL Ok() const { return sym.Ok(); }

		VSymbol &Symbol() { return sym; }
		const VSymbol &Symbol() const { return sym; }
		V Symbol(const VSymbol &s);
		I Channel() const { return chn; }
		V Channel(I c) { chn = c; }
		I Offset() const { return offs; }
		V Offset(I o) { offs = o; }
		V OffsetD(I o) { offs += o; }

	protected:
		VSymbol sym;
		I chn;
		I offs; // counted in frames
	};

	Vasp();
	Vasp(I argc,const t_atom *argv);
	Vasp(const Vasp &v);
	Vasp(I frames,const Ref &r);
	~Vasp();

	static BL ChkArgs(I argc,const t_atom *argv);

	const C *thisName() const { return typeid(*this).name(); }

	// check if vasp reference is valid
	BL Check() const;

	Vasp &operator =(const Vasp &v);
	Vasp &operator ()(I argc,const t_atom *argv /*,BL withvasp = false*/);

	// set used channels to 0
	Vasp &Clear();

	// used vectors
	I Vectors() const { return chns; }

	// length of the vasp (in frames)
	I Frames() const { return frames; }
	// set frame count
	V Frames(I fr) { frames = fr; }
	// set frame count differentially
	V FramesD(I frd) { if(frames >= 0) frames += frd; }
	// set frame count 
	V FramesM(R f) { if(frames >= 0) frames = (int)(frames*f); }
	// set frame count 
	V FramesR(R f) { if(f) FramesM(1./f); else Frames(0); }

	// set buffer sizes
	V Size(I fr,BL keep = true,BL zero = true);
	// set frame count differentially
	V SizeD(I frd,BL keep = true,BL zero = true);
	// set frame count 
	V SizeM(R f,BL keep = true,BL zero = true);
	// set frame count 
	V SizeR(R f,BL keep = true,BL zero = true) { if(f) SizeM(1./f,keep,zero); else Size(0,false); }

	// actual length of the vasp (in frames)
	I ChkFrames() const;

	// set offset(s)
	V Offset(I fr);
	// set offset(s) differentially
	V OffsetD(I fr);

	// set channel(s)
	V Channel(I ch);

	BL Ok() const { return ref && Vectors() > 0; }
	BL IsComplex() const { return ref && Vectors() >= 2 && ref[1].Ok(); }

	// get any vector - test if in range 0..Vectors()-1!
	const Ref &Vector(I ix) const { return ref[ix]; }
	Ref &Vector(I ix) { return ref[ix]; }

	// get real part - be sure that Ok!
	const Ref &Real() const { return Vector(0); }
	Ref &Real() { return Vector(0); }

	// get imaginary part - be sure that Complex!
	const Ref &Imag() const { return Vector(1); }
	Ref &Imag() { return Vector(1); }

	// get buffer associated to a channel
	VBuffer *Buffer(I ix) const;

	// add another vector
	Vasp &AddVector(const Ref &r);

	// Real/Complex
	VBuffer *ReBuffer() const { return Buffer(0); }
	VBuffer *ImBuffer() const { return Buffer(1); }

	// prepare and reference t_atom list for output
	V MakeList(flext::AtomList &ret,BL withvasp = true) const;
	// prepare and reference t_atom list for output
	flext::AtomList *MakeList(BL withvasp = true) const;

	// make a graphical update of all buffers in vasp
	V Refresh();
	
protected:
	I frames; // length counted in frames
	I chns; // used channels
	I refs; // allocated channels (>= chns)
	Ref *ref;

	V Resize(I rcnt);
};

/*! \brief Checked vasp
	\remark Only use that for immediate operation!
*/
class CVasp:
	public Vasp
{
public:
	CVasp();
	CVasp(const Vasp &v);

	// add vectors of another vasp
	CVasp &operator +=(const CVasp &v);

};


#endif