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
23 -----------------------------------------------------------------------------*/
25 //-----------------------------------------------------------------------------
27 // desc: chuck unit generator interface
29 // authors: Ge Wang (gewang@cs.princeton.edu)
30 // Perry R. Cook (prc@cs.princeton.edu)
32 //-----------------------------------------------------------------------------
33 #ifndef __CHUCK_UGEN_H__
34 #define __CHUCK_UGEN_H__
36 #include "chuck_def.h"
45 struct Chuck_UGen_Info
;
46 struct Chuck_Info_Param
;
50 // dynamic linking unit generator interface prototypes
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
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
; }
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
90 //-----------------------------------------------------------------------------
91 struct Chuck_UGen_Info
95 std::vector
<Chuck_Info_Param
> param_list
;
96 std::map
<std::string
, Chuck_Info_Param
> param_map
;
109 void set( f_ctor c
, f_dtor d
, f_tick t
, f_pmsg p
)
110 { ctor
= c
; dtor
= d
; tick
= t
; pmsg
= p
; }
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]; }
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
);
139 Chuck_UGen_Info( const std::string
& n
= "[invalid]", t_CKUINT min
= 0, t_CKUINT max
= 0xffffffff )
145 set( NULL
, NULL
, NULL
, NULL
);
152 #define UGEN_OP_PASS -1
153 #define UGEN_OP_STOP 0
154 #define UGEN_OP_TICK 1
157 //-----------------------------------------------------------------------------
158 // name: class Chuck_UGen
160 //-----------------------------------------------------------------------------
161 struct Chuck_UGen
: public Chuck_Object
165 virtual ~Chuck_UGen( );
170 t_CKBOOL
add( Chuck_UGen
* src
);
171 t_CKBOOL
remove( Chuck_UGen
* src
);
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
);
179 void add_by( Chuck_UGen
* dest
);
180 void remove_by( Chuck_UGen
* dest
);
189 std::vector
<Chuck_UGen
*> m_src_list
;
190 std::vector
<Chuck_UGen
*> m_dest_list
;
201 Chuck_VM_Shred
* shred
;
203 public: // dynamic linking client data