aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/vasp/source/env.h
blob: 11ad68ab3f492ad76f59c937e9e63ad4349252f3 (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
/* 

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_ENV_H
#define __VASP_ENV_H

#include "vasp.h"

class Env:
    public flext
{
public:
	Env(): cnt(0),pos(NULL),val(NULL) {}
	Env(I argc,const t_atom *argv);
//	Env(const Env &p);
	~Env();

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

	V MakeList(flext::AtomList &ret) const;

	V Clear();

	BL Ok() const { return cnt && pos != NULL && val != NULL; }

//	friend class Iter;

	class Iter 
	{
	public:
		Iter(const Env &e);
		V Init(R p);

		R ValFwd(R p) 
		{
			if(p > npt) UpdateFwd(p);
			return pvl+k*(p-ppt);
		}

		R ValBwd(R p) 
		{
			if(p < ppt) UpdateBwd(p);
			return pvl+k*(p-ppt);
		}

	protected:
		V UpdateFwd(R p);
		V UpdateBwd(R p);

		const Env &bp;
		I ix;
		R ppt,npt;
		R pvl,nvl;
		R k;
	};

	I Count() const { return cnt; }
	const R *Pos() const { return pos; }
	const R *Val() const { return val; }
	R Pos(I ix) const { return pos[ix]; }
	R Val(I ix) const { return val[ix]; }

protected:
	I cnt;
	R *pos,*val;
};

#endif