aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/vasp/source/obj_chns.cpp
blob: 1e7dfb67b51d85b6ad5530cbd6fd8fb599dd90be (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
/* 

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.  

*/

#include "main.h"
#include "classes.h"
#include "util.h"
#include "buflib.h"


/*! \class vasp_channel
	\remark \b vasp.channel
	\brief Sets channel index of vasp.
	\since 0.0.8
	\param cmdln.1 int - index of vasp vector
	\param inlet vasp - is stored and indexed vasp vector output
	\param inlet bang - triggers indexed vasp vector output
	\param inlet set - vasp to be stored (and not immediately output)
	\retval outlet modified vasp
*/
class vasp_channel:
	public vasp_tx
{
	FLEXT_HEADER_S(vasp_channel,vasp_tx,Setup)

public:
	vasp_channel(I argc,const t_atom *argv):
		ix(0)
	{
		if(argc >= 1 && CanbeInt(argv[0]))
			ix = GetAInt(argv[0]);
		else if(argc)
			post("%s - Index argument invalid -> set to 0",thisName());

		AddInAnything(2);
		AddOutAnything();
	}

	static V Setup(t_classid c)
	{
		FLEXT_CADDMETHOD(c,1,m_ix);
		FLEXT_CADDATTR_VAR(c,"index",ix,m_ix);
	}

	V m_ix(I i) { ix = i; }

	virtual Vasp *x_work() 
	{ 
		Vasp *ret = new Vasp(ref);
		ret->Channel(ix);
		return ret; 
	}

	virtual V m_help() { post("%s - Set channel index of vectors in vasp",thisName()); }

protected:
	I ix;

private:
	FLEXT_CALLBACK_I(m_ix);
	FLEXT_CALLSET_I(m_ix);
	FLEXT_ATTRGET_I(ix);
};

VASP_LIB_V("vasp.channel vasp.c",vasp_channel)



/*! \class vasp_qc 
	\remark \b vasp.c?
	\brief Gets channel index of a vasp.
	\since 0.0.8
	\param inlet vasp - is stored and output triggered
	\param inlet bang - triggers output
	\param inlet set - vasp to be stored 
	\retval outlet int - channel index of stored vasp

	\note Always returns index of 0th vasp
	\note No output for invalid vasp?
*/
class vasp_qchannel:
	public vasp_op
{
	FLEXT_HEADER(vasp_qchannel,vasp_op)

public:
	vasp_qchannel()
	{
		AddInAnything();
		AddOutInt();
	}

	virtual V m_bang() 
	{ 
		if(ref.Ok()) {
			if(ref.Vectors() > 1)
				post("%s - more vectors in vasp, only considering first",thisName());
			
			ToOutInt(0,ref.Vector(0).Channel()); 
		}
		else
			post("%s - Invalid vasp, no output",thisName());
	}

	virtual V m_help() { post("%s - Get channel index of 0th vector in vasp",thisName()); }
};

VASP_LIB("vasp.channel? vasp.c?",vasp_qchannel)


/*! \class vasp_qchannels
	\remark \b vasp.channels?
	\brief Gets number of channels of a vasp.
	\since 0.1.3
	\param inlet vasp - is stored and output triggered
	\param inlet bang - triggers output
	\param inlet set - vasp to be stored 
	\retval outlet int - channels of stored vasp

	\note No output for invalid vasp?
*/
class vasp_qchannels:
	public vasp_op
{
	FLEXT_HEADER(vasp_qchannels,vasp_op)

public:
	vasp_qchannels()
	{
		AddInAnything();
		AddOutInt();
	}

	virtual V m_bang() 
	{ 
		if(ref.Ok()) {
			if(ref.Vectors() > 1)
				post("%s - more vectors in vasp, only considering first",thisName());
			
			VBuffer *buf = BufLib::Get(ref.Vector(0).Symbol());
			ToOutInt(0,buf->Channels()); 
			delete buf;
		}
		else
			post("%s - Invalid vasp, no output",thisName());
	}

	virtual V m_help() { post("%s - Get channel index of 0th vector in vasp",thisName()); }
};

VASP_LIB("vasp.channels?",vasp_qchannels)