*** empty log message ***
[chuck-blob.git] / v1 / chuck_ugen.h
blob6fa79a41a4469fc9f2366b381e61914bad095454
1 /*----------------------------------------------------------------------------
2 ChucK Concurrent, On-the-fly Audio Programming Language
3 Compiler and Virtual Machine
5 Copyright (c) 2004 Ge Wang and Perry R. Cook. All rights reserved.
6 http://chuck.cs.princeton.edu/
7 http://soundlab.cs.princeton.edu/
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 U.S.A.
23 -----------------------------------------------------------------------------*/
25 //-----------------------------------------------------------------------------
26 // name: chuck_ugen.h
27 // desc: chuck unit generator interface
29 // authors: Ge Wang (gewang@cs.princeton.edu)
30 // Perry R. Cook (prc@cs.princeton.edu)
31 // date: Spring 2004
32 //-----------------------------------------------------------------------------
33 #ifndef __CHUCK_UGEN_H__
34 #define __CHUCK_UGEN_H__
36 #include "chuck_def.h"
37 #include "chuck_oo.h"
38 #include <string>
39 #include <vector>
40 #include <map>
43 // forward reference
44 struct Chuck_UGen;
45 struct Chuck_UGen_Info;
46 struct Chuck_Info_Param;
47 class Chuck_VM_Shred;
50 // dynamic linking unit generator interface prototypes
51 extern "C" {
52 typedef void * (* f_ctor)( t_CKTIME now );
53 typedef void (* f_dtor)( t_CKTIME now, void * data );
54 typedef t_CKBOOL (* f_tick)( t_CKTIME now, void * data, SAMPLE in, SAMPLE * out );
55 typedef void (* f_ctrl)( t_CKTIME now, void * data, void * value );
56 typedef f_ctrl f_cget;
57 typedef t_CKBOOL (* f_pmsg)( t_CKTIME now, void * data, const char * msg, void * value );
63 //-----------------------------------------------------------------------------
64 // name: struct Chuck_Info_Param
65 // dsec: ugen info param
66 //-----------------------------------------------------------------------------
67 struct Chuck_Info_Param
69 std::string type; // see above
70 std::string name; // name of param
71 f_ctrl ctrl_addr; // set addr
72 f_cget cget_addr; // get addr
74 // constructor
75 Chuck_Info_Param( const std::string & t = "", const std::string & n = "",
76 f_ctrl a = NULL, f_cget g = NULL )
77 { type = t; name = n; ctrl_addr = a; cget_addr = g; }
79 // copy constructor
80 Chuck_Info_Param( const Chuck_Info_Param & p )
81 : type(p.type), name(p.name), ctrl_addr(p.ctrl_addr), cget_addr(p.cget_addr) { }
87 //-----------------------------------------------------------------------------
88 // name: struct Chuck_UGen_Info
89 // dsec: ugen info
90 //-----------------------------------------------------------------------------
91 struct Chuck_UGen_Info
93 // info
94 std::string name;
95 std::vector<Chuck_Info_Param> param_list;
96 std::map<std::string, Chuck_Info_Param> param_map;
97 f_ctor ctor;
98 f_dtor dtor;
99 f_tick tick;
100 f_pmsg pmsg;
102 // optional
103 std::string parent;
104 t_CKUINT min_src;
105 t_CKUINT max_src;
106 int linepos;
108 // set
109 void set( f_ctor c, f_dtor d, f_tick t, f_pmsg p )
110 { ctor = c; dtor = d; tick = t; pmsg = p; }
112 // add
113 void add( f_ctrl c, f_cget g, const std::string & t, const std::string & n )
114 { param_list.push_back( Chuck_Info_Param( t, n, c, g ) );
115 param_map[n] = param_list[param_list.size()-1]; }
117 //XXX - pld inherit
118 void inherit( Chuck_UGen_Info * parentInfo )
120 parent = parentInfo->name;
121 //inherit functions ...
122 ctor = parentInfo->ctor;
123 dtor = parentInfo->dtor;
124 tick = parentInfo->tick;
125 pmsg = parentInfo->pmsg;
127 for ( unsigned int i=0; i < parentInfo->param_list.size(); i++)
129 //inherit parent class's functions
130 //(functions added subsequently will overwrite entries in param_map)
131 add( parentInfo->param_list[i].ctrl_addr,
132 parentInfo->param_list[i].cget_addr,
133 parentInfo->param_list[i].type,
134 parentInfo->param_list[i].name );
138 // constructor
139 Chuck_UGen_Info( const std::string & n = "[invalid]", t_CKUINT min = 0, t_CKUINT max = 0xffffffff )
141 name = n;
142 parent = "";
143 min_src = min;
144 max_src = max;
145 set( NULL, NULL, NULL, NULL );
146 linepos = 0;
151 // op mode
152 #define UGEN_OP_PASS -1
153 #define UGEN_OP_STOP 0
154 #define UGEN_OP_TICK 1
157 //-----------------------------------------------------------------------------
158 // name: class Chuck_UGen
159 // dsec: ugen base
160 //-----------------------------------------------------------------------------
161 struct Chuck_UGen : public Chuck_Object
163 public:
164 Chuck_UGen( );
165 virtual ~Chuck_UGen( );
166 virtual void init();
167 virtual void done();
169 public: // src
170 t_CKBOOL add( Chuck_UGen * src );
171 t_CKBOOL remove( Chuck_UGen * src );
172 void remove_all( );
173 t_CKBOOL set_max_src( t_CKUINT num );
174 t_CKUINT get_num_src( );
175 t_CKUINT disconnect( t_CKBOOL recursive );
176 t_CKUINT system_tick( t_CKTIME now );
178 protected:
179 void add_by( Chuck_UGen * dest );
180 void remove_by( Chuck_UGen * dest );
182 public: // interface
183 f_ctor ctor;
184 f_dtor dtor;
185 f_tick tick;
186 f_pmsg pmsg;
188 public: // data
189 std::vector<Chuck_UGen *> m_src_list;
190 std::vector<Chuck_UGen *> m_dest_list;
191 t_CKUINT m_num_src;
192 t_CKUINT m_num_dest;
193 t_CKUINT m_max_src;
194 t_CKTIME m_time;
195 t_CKBOOL m_valid;
196 SAMPLE m_sum;
197 SAMPLE m_current;
198 SAMPLE m_last;
199 SAMPLE m_gain;
200 t_CKINT m_op;
201 Chuck_VM_Shred * shred;
203 public: // dynamic linking client data
204 void * state;
210 #endif