andrew@1
|
1 /**
|
andrew@1
|
2 @file
|
andrew@1
|
3 Bonzo - a max object shell
|
andrew@1
|
4 jeremy bernstein - jeremy@bootsquad.com
|
andrew@1
|
5
|
andrew@1
|
6 @ingroup examples
|
andrew@1
|
7 */
|
andrew@1
|
8
|
andrew@1
|
9 #include "ext.h" // standard Max include, always required
|
andrew@1
|
10 #include "ext_obex.h" // required for new style Max object
|
andrew@1
|
11 //#include "BKeeperlass.h"
|
andrew@1
|
12
|
andrew@1
|
13 ////////////////////////// object struct
|
andrew@1
|
14
|
andrew@1
|
15
|
andrew@1
|
16 typedef struct _Bonzo
|
andrew@1
|
17 {
|
andrew@1
|
18 t_object ob; // the object itself (must be first)
|
andrew@1
|
19 // BonzoClass* bk;
|
andrew@1
|
20 // void* clickclock;
|
andrew@1
|
21 // void* bangOut;
|
andrew@1
|
22 void* tatumEstimateOut;
|
andrew@1
|
23 // void* latencyOut;
|
andrew@1
|
24
|
andrew@1
|
25
|
andrew@1
|
26 } t_Bonzo;
|
andrew@1
|
27
|
andrew@1
|
28 ///////////////////////// function prototypes
|
andrew@1
|
29 //// standard set
|
andrew@1
|
30 void *Bonzo_new(t_symbol *s, long argc, t_atom *argv);
|
andrew@1
|
31 void Bonzo_bang(t_Bonzo *x);
|
andrew@1
|
32 void Bonzo_reset(t_Bonzo *x);
|
andrew@1
|
33 void Bonzo_click(t_Bonzo *x);
|
andrew@1
|
34 void Bonzo_kick(t_Bonzo *x);
|
andrew@1
|
35 void Bonzo_snare(t_Bonzo *x);
|
andrew@1
|
36 void Bonzo_kickstart(t_Bonzo *x, int kicks);
|
andrew@1
|
37 void Bonzo_latency(t_Bonzo *x, int latency);
|
andrew@1
|
38 void Bonzo_fix_latency(t_Bonzo *x, int fix_latency_mode);
|
andrew@1
|
39
|
andrew@1
|
40 void Bonzo_setTatum(t_Bonzo *x, double f);
|
andrew@1
|
41 void Bonzo_free(t_Bonzo *x);
|
andrew@1
|
42 void Bonzo_printtime(t_Bonzo *x);
|
andrew@1
|
43 void Bonzo_assist(t_Bonzo *x, void *b, long m, long a, char *s);
|
andrew@1
|
44
|
andrew@1
|
45 //////////////////////// global class pointer variable
|
andrew@1
|
46 void *Bonzo_class;
|
andrew@1
|
47
|
andrew@1
|
48
|
andrew@1
|
49 int main(void)
|
andrew@1
|
50 {
|
andrew@1
|
51 // object initialization, OLD STYLE
|
andrew@1
|
52 // setup((t_messlist **)&Bonzo_class, (method)Bonzo_new, (method)Bonzo_free, (short)sizeof(t_Bonzo),
|
andrew@1
|
53 // 0L, A_GIMME, 0);
|
andrew@1
|
54 // addmess((method)Bonzo_assist, "assist", A_CANT, 0);
|
andrew@1
|
55
|
andrew@1
|
56 // object initialization, NEW STYLE
|
andrew@1
|
57 t_class *c;
|
andrew@1
|
58
|
andrew@1
|
59 c = class_new("Bonzo", (method)Bonzo_new, (method)Bonzo_free, (long)sizeof(t_Bonzo),
|
andrew@1
|
60 0L /* leave NULL!! */, A_GIMME, 0);
|
andrew@1
|
61
|
andrew@1
|
62 /* you CAN'T call this from the patcher */
|
andrew@1
|
63 class_addmethod(c, (method)Bonzo_assist, "assist", A_CANT, 0);
|
andrew@1
|
64 class_addmethod(c, (method) Bonzo_bang, "bang", 0);
|
andrew@1
|
65 class_addmethod(c, (method) Bonzo_click, "click", 0);
|
andrew@1
|
66 class_addmethod(c, (method) Bonzo_kick, "kick", 0);
|
andrew@1
|
67 class_addmethod(c, (method) Bonzo_snare, "snare", 0);
|
andrew@1
|
68 class_addmethod(c, (method) Bonzo_kickstart, "kickstart", A_LONG, 0);
|
andrew@1
|
69 class_addmethod(c, (method) Bonzo_fix_latency, "fix_latency", A_LONG, 0);
|
andrew@1
|
70 class_addmethod(c, (method) Bonzo_latency, "latency", A_LONG, 0);
|
andrew@1
|
71
|
andrew@1
|
72 class_addmethod(c, (method) Bonzo_setTatum, "set_tatum", A_FLOAT, 0);
|
andrew@1
|
73
|
andrew@1
|
74
|
andrew@1
|
75 class_addmethod(c, (method) Bonzo_reset, "reset", 0);
|
andrew@1
|
76 class_register(CLASS_BOX, c); /* CLASS_NOBOX */
|
andrew@1
|
77 Bonzo_class = c;
|
andrew@1
|
78
|
andrew@2
|
79 post("I am the BONZO max external object");
|
andrew@1
|
80 return 0;
|
andrew@1
|
81 }
|
andrew@1
|
82
|
andrew@1
|
83 void Bonzo_assist(t_Bonzo *x, void *b, long m, long a, char *s)
|
andrew@1
|
84 {
|
andrew@1
|
85 if (m == ASSIST_INLET) { // inlet
|
andrew@1
|
86 sprintf(s, " BONZO Inlet takes messages for click, kick and snare %ld", a);
|
andrew@1
|
87 }
|
andrew@1
|
88 else { // outlet
|
andrew@1
|
89 sprintf(s, "BONZO Outlet is duration of an eighth note in milliseconds required to synchronise the click track to the drum events %ld", a);
|
andrew@1
|
90 }
|
andrew@1
|
91 }
|
andrew@1
|
92
|
andrew@1
|
93 void Bonzo_free(t_Bonzo *x)
|
andrew@1
|
94 {
|
andrew@1
|
95 // object_free(x->clickclock);;
|
andrew@1
|
96 }
|
andrew@1
|
97
|
andrew@1
|
98
|
andrew@1
|
99
|
andrew@1
|
100 void Bonzo_bang(t_Bonzo *x){
|
andrew@1
|
101
|
andrew@1
|
102
|
andrew@1
|
103 object_post((t_object *)x, "Bonzo got banggggg!");
|
andrew@1
|
104 //x->bk->bang(0);
|
andrew@1
|
105
|
andrew@1
|
106
|
andrew@1
|
107 /*
|
andrew@1
|
108 if (x->timer->send_start_bang){
|
andrew@1
|
109 clock_fdelay(x->clickclock, x->timer->start_delay);
|
andrew@1
|
110 x->timer->send_start_bang = false;
|
andrew@1
|
111 }
|
andrew@1
|
112 */
|
andrew@1
|
113 }
|
andrew@1
|
114
|
andrew@1
|
115 void Bonzo_kick(t_Bonzo *x){
|
andrew@1
|
116 // x->bk->bang(0);
|
andrew@1
|
117 post("BONZO kick");
|
andrew@1
|
118 // outlet_float(x->tatumEstimateOut, x->bk->main_tatum_output);
|
andrew@1
|
119 }
|
andrew@1
|
120
|
andrew@1
|
121 void Bonzo_snare(t_Bonzo *x){
|
andrew@1
|
122 // x->bk->bang(2);
|
andrew@1
|
123 post("Bonzo SNARE");
|
andrew@1
|
124 // outlet_float(x->tatumEstimateOut, x->bk->main_tatum_output);
|
andrew@1
|
125 }
|
andrew@1
|
126
|
andrew@1
|
127 void Bonzo_click(t_Bonzo *x){
|
andrew@1
|
128 // x->bk->bang(1);
|
andrew@2
|
129 post("Bonzo Click");
|
andrew@1
|
130 // outlet_float(x->tatumEstimateOut, x->bk->main_tatum_output);
|
andrew@1
|
131 }
|
andrew@1
|
132
|
andrew@1
|
133
|
andrew@1
|
134 void Bonzo_reset(t_Bonzo *x){
|
andrew@1
|
135 // object_post((t_object *)x, "B-Keeper reset!");
|
andrew@1
|
136 // x->bk->reset();
|
andrew@1
|
137 }
|
andrew@1
|
138
|
andrew@1
|
139
|
andrew@1
|
140
|
andrew@1
|
141 void Bonzo_kickstart(t_Bonzo *x, int kicks){
|
andrew@1
|
142 // if (kicks >= 0 && kicks <= 8){
|
andrew@1
|
143 // x->timer->start_index = kicks;
|
andrew@1
|
144 // }
|
andrew@1
|
145 }
|
andrew@1
|
146
|
andrew@1
|
147 void Bonzo_setTatum(t_Bonzo *x, double f){
|
andrew@1
|
148 post("Bonzo set tatum called with arg %f\n", f);
|
andrew@1
|
149 // x->bk->setTatum(f);
|
andrew@1
|
150 }
|
andrew@1
|
151
|
andrew@1
|
152
|
andrew@1
|
153 void Bonzo_latency(t_Bonzo *x, int latency){
|
andrew@1
|
154 //if (latency >= 0 && latency < 100)
|
andrew@1
|
155 // x->timer->latency = latency;
|
andrew@1
|
156 }
|
andrew@1
|
157
|
andrew@1
|
158 void Bonzo_fix_latency(t_Bonzo *x, int fix_latency_mode){
|
andrew@1
|
159 /*
|
andrew@1
|
160 if (fix_latency_mode == 1){
|
andrew@1
|
161 x->timer->saved_latency_mode = true;
|
andrew@1
|
162 x->timer->saved_latency = x->timer->latency;
|
andrew@1
|
163 post("Latency FIXED at %i msec \n", x->timer->latency);
|
andrew@1
|
164 }
|
andrew@1
|
165 else{
|
andrew@1
|
166 x->timer->saved_latency_mode = false;
|
andrew@1
|
167 post("Latency to be calculated from ableton click track arriving...now at %i ms\n", x->timer->latency);
|
andrew@1
|
168 }
|
andrew@1
|
169 */
|
andrew@1
|
170 }
|
andrew@1
|
171
|
andrew@1
|
172 void Bonzo_printtime(t_Bonzo *x)
|
andrew@1
|
173 {
|
andrew@1
|
174 // double time;
|
andrew@1
|
175 // sched_getftime(&time);
|
andrew@1
|
176 // post("instance %lx is executing at time %.2f", x, time);
|
andrew@1
|
177
|
andrew@1
|
178 long timeMillis = gettime();
|
andrew@1
|
179 post("current time is %ld \n", timeMillis);
|
andrew@1
|
180
|
andrew@1
|
181 }
|
andrew@1
|
182
|
andrew@1
|
183 /*
|
andrew@1
|
184 A_GIMME signature =
|
andrew@1
|
185 t_symbol *s objectname
|
andrew@1
|
186 long argc num additonal args
|
andrew@1
|
187 t_atom *argv array of t_atom structs
|
andrew@1
|
188 type = argv->a_type
|
andrew@1
|
189 if (type == A_LONG) ;
|
andrew@1
|
190 else if (type == A_FLOAT) ;
|
andrew@1
|
191 else if (type == A_SYM) ;
|
andrew@1
|
192 */
|
andrew@1
|
193 /*
|
andrew@1
|
194 t_symbol {
|
andrew@1
|
195 char *s_name;
|
andrew@1
|
196 t_object *s_thing;
|
andrew@1
|
197 }
|
andrew@1
|
198 */
|
andrew@1
|
199 void *Bonzo_new(t_symbol *s, long argc, t_atom *argv)
|
andrew@1
|
200 {
|
andrew@1
|
201 t_Bonzo *x = NULL;
|
andrew@1
|
202 //long i;
|
andrew@1
|
203
|
andrew@1
|
204 // object instantiation, OLD STYLE
|
andrew@1
|
205 // if (x = (t_Bonzo *)newobject(Bonzo_class)) {
|
andrew@1
|
206 // ;
|
andrew@1
|
207 // }
|
andrew@1
|
208
|
andrew@1
|
209 // object instantiation, NEW STYLE
|
andrew@1
|
210 if (x = (t_Bonzo *)object_alloc((t_class *) Bonzo_class)) {
|
andrew@1
|
211 //(t_class *) allows this to be a cpp file
|
andrew@1
|
212
|
andrew@1
|
213 // object_post((t_object *)x, "a new %s object was instantiated: 0x%X", s->s_name, x);
|
andrew@1
|
214 // object_post((t_object *)x, "it has %ld arguments", argc);
|
andrew@1
|
215
|
andrew@1
|
216 /*
|
andrew@1
|
217 for (i = 0; i < argc; i++) {
|
andrew@1
|
218 if ((argv + i)->a_type == A_LONG) {
|
andrew@1
|
219 object_post((t_object *)x, "arg %ld: long (%ld)", i, atom_getlong(argv+i));
|
andrew@1
|
220 } else if ((argv + i)->a_type == A_FLOAT) {
|
andrew@1
|
221 object_post((t_object *)x, "arg %ld: float (%f)", i, atom_getfloat(argv+i));
|
andrew@1
|
222 } else if ((argv + i)->a_type == A_SYM) {
|
andrew@1
|
223 object_post((t_object *)x, "arg %ld: symbol (%s)", i, atom_getsym(argv+i)->s_name);
|
andrew@1
|
224 } else {
|
andrew@1
|
225 object_error((t_object *)x, "forbidden argument");
|
andrew@1
|
226 }
|
andrew@1
|
227 }
|
andrew@1
|
228 */
|
andrew@1
|
229
|
andrew@1
|
230
|
andrew@1
|
231 // x->bk = new BonzoClass();//imer = new clicktimer();
|
andrew@1
|
232 // x->clickclock = clock_new((t_object *)x, (method) Bonzo_sendDelayedBang);
|
andrew@1
|
233 // x->latencyOut = intout((t_object *)x);
|
andrew@1
|
234 x->tatumEstimateOut = floatout((t_object *)x);
|
andrew@1
|
235 // x->bangOut = bangout((t_object *)x);
|
andrew@1
|
236 }
|
andrew@1
|
237 return (x);
|
andrew@1
|
238 }
|