mas01mj@567
|
1 #include "m_pd.h"
|
mas01mj@567
|
2 #include <math.h>
|
mas01mj@567
|
3 #include <stdio.h>
|
mas01mj@567
|
4
|
mas01mj@567
|
5 #include <sys/types.h>
|
mas01mj@567
|
6 #include <sys/stat.h>
|
mas01mj@567
|
7 #include <fcntl.h>
|
mas01mj@567
|
8 #include <stdlib.h>
|
mas01cr@576
|
9 #include <unistd.h>
|
mas01mj@567
|
10
|
mas01mj@567
|
11 #include <audioDB_API.h>
|
mas01mj@567
|
12
|
mas01mj@567
|
13 #define ADB_MAXSTR (512U)
|
mas01mj@567
|
14 #define MAXSTR ADB_MAXSTR
|
mas01mj@567
|
15
|
mas01mj@567
|
16 // Query types
|
mas01mj@567
|
17 #define O2_POINT_QUERY (0x4U)
|
mas01mj@567
|
18 #define O2_SEQUENCE_QUERY (0x8U)
|
mas01mj@567
|
19 #define O2_TRACK_QUERY (0x10U)
|
mas01mj@567
|
20 #define O2_N_SEQUENCE_QUERY (0x20U)
|
mas01mj@567
|
21 #define O2_ONE_TO_ONE_N_SEQUENCE_QUERY (0x40U)
|
mas01mj@567
|
22
|
mas01mj@567
|
23 static t_class *adbpd_class; /* so this bit is different */
|
mas01mj@567
|
24
|
mas01mj@567
|
25 typedef struct _adbpd {
|
mas01cr@573
|
26 t_object x_obj;
|
mas01cr@573
|
27 t_outlet *x_key;
|
mas01cr@573
|
28 t_outlet *x_dist;
|
mas01cr@573
|
29 t_outlet *x_qpos;
|
mas01cr@573
|
30 t_outlet *x_spos;
|
mas01mj@569
|
31 t_symbol *x_dbname; //database name
|
mas01cr@573
|
32
|
mas01mj@569
|
33 t_int x_dbquerytype; //sequence, track, etc.
|
mas01mj@569
|
34 t_symbol *x_dbfeature;
|
mas01mj@567
|
35 // t_symbol *x_dbpower;
|
mas01mj@569
|
36 t_symbol *x_dbkey;
|
mas01mj@569
|
37 t_float x_dbqpoint;
|
mas01mj@569
|
38 t_float x_dbnumpoints;
|
mas01mj@569
|
39 t_float x_dbradius;
|
mas01mj@569
|
40 t_float x_dbresultlength;
|
mas01mj@569
|
41 t_float x_dbsequencelength;
|
mas01cr@671
|
42 adb_t *db;
|
mas01mj@567
|
43 } t_adbpd;
|
mas01mj@567
|
44
|
mas01mj@567
|
45
|
mas01cr@578
|
46 static void adbpd_create(t_adbpd *, t_floatarg, t_floatarg, t_floatarg);
|
mas01mj@567
|
47 static void adbpd_open(t_adbpd *x);
|
mas01cr@579
|
48 static void adbpd_close(t_adbpd *x);
|
mas01mj@567
|
49 static void adbpd_setname(t_adbpd *x, t_symbol *s, int argc, t_atom *argv);
|
mas01mj@567
|
50 static void adbpd_status(t_adbpd *x);
|
mas01mj@567
|
51 static void adbpd_l2norm(t_adbpd *x);
|
mas01mj@567
|
52 static void adbpd_power(t_adbpd *x);
|
mas01mj@567
|
53 static void adbpd_setfeatures(t_adbpd *x,t_symbol *s,int argc, t_atom *argv);
|
mas01mj@567
|
54 static void adbpd_setquerytype(t_adbpd *x,t_symbol *s,int argc, t_atom *argv);
|
mas01mj@567
|
55 static void adbpd_setqpoint(t_adbpd *x,t_floatarg f);
|
mas01mj@567
|
56 static void adbpd_setresultlength(t_adbpd *x,t_floatarg f);
|
mas01mj@567
|
57 static void adbpd_setradius(t_adbpd *x,t_floatarg f);
|
mas01mj@567
|
58 static void adbpd_setnumpoints(t_adbpd *x,t_floatarg f);
|
mas01mj@567
|
59 static void adbpd_setsequencelength(t_adbpd *x,t_floatarg f);
|
mas01mj@567
|
60 static void adbpd_doquery(t_adbpd *x);
|
mas01mj@567
|
61 static void adbpd_parameters(t_adbpd *x);
|
mas01mj@567
|
62 static void adbpd_getname(t_adbpd *x);
|
mas01mj@567
|
63
|
mas01mj@567
|
64
|
mas01mj@567
|
65
|
mas01mj@567
|
66 /* input arguments are only used for startup vals */
|
mas01mj@567
|
67 static void *adbpd_new(t_symbol *s) {
|
mas01mj@567
|
68
|
mas01cr@573
|
69 /* some sort of standard declaration line */
|
mas01cr@578
|
70 t_adbpd *x = (t_adbpd *) pd_new(adbpd_class);
|
mas01cr@578
|
71 x->x_dbname = s;
|
mas01cr@573
|
72
|
mas01cr@573
|
73 /* setup some inlets */
|
mas01cr@573
|
74 floatinlet_new(&x->x_obj,&x->x_dbqpoint); /* second inlet */
|
mas01cr@573
|
75 floatinlet_new(&x->x_obj,&x->x_dbnumpoints); /* third inlet */
|
mas01cr@573
|
76 floatinlet_new(&x->x_obj,&x->x_dbradius); /* fourth inlet */
|
mas01cr@573
|
77 floatinlet_new(&x->x_obj,&x->x_dbresultlength); /* fifth inlet */
|
mas01cr@573
|
78 floatinlet_new(&x->x_obj,&x->x_dbsequencelength); /* sixth inlet */
|
mas01cr@573
|
79
|
mas01cr@573
|
80 /* outlets */
|
mas01cr@573
|
81 outlet_new(&x->x_obj, &s_float);
|
mas01cr@573
|
82
|
mas01cr@573
|
83 x->x_key = outlet_new(&x->x_obj, &s_symbol);
|
mas01cr@573
|
84 x->x_dist = outlet_new(&x->x_obj, &s_float);
|
mas01cr@573
|
85 x->x_qpos = outlet_new(&x->x_obj, &s_float);
|
mas01cr@573
|
86 x->x_spos = outlet_new(&x->x_obj, &s_float);
|
mas01mj@567
|
87
|
mas01mj@569
|
88 /* adb defaults. These are the same but we need to init them */
|
mas01mj@569
|
89 x->x_dbquerytype=O2_POINT_QUERY;
|
mas01mj@569
|
90 x->x_dbfeature=gensym("No feature file yet specified");
|
mas01mj@569
|
91 x->x_dbqpoint=1;
|
mas01mj@569
|
92 x->x_dbnumpoints=10;
|
mas01mj@569
|
93 x->x_dbradius=1;
|
mas01mj@569
|
94 x->x_dbresultlength=10;
|
mas01mj@569
|
95 x->x_dbsequencelength=12;
|
mas01cr@573
|
96 return(x);
|
mas01mj@567
|
97 }
|
mas01mj@567
|
98
|
mas01cr@578
|
99 static void adbpd_free(t_adbpd *x) {
|
mas01cr@579
|
100 adbpd_close(x);
|
mas01cr@578
|
101 }
|
mas01cr@578
|
102
|
mas01cr@574
|
103 /* bang executes the defined query */
|
mas01mj@567
|
104 static void adbpd_bang(t_adbpd *x) {
|
mas01mj@569
|
105 adbpd_doquery(x);
|
mas01mj@567
|
106 }
|
mas01mj@567
|
107
|
mas01mj@567
|
108 /* create a database */
|
mas01cr@578
|
109 static void adbpd_create(t_adbpd *x, t_floatarg datasize, t_floatarg ntracks, t_floatarg dim) {
|
mas01cr@579
|
110 adbpd_close(x);
|
mas01cr@579
|
111
|
mas01cr@579
|
112 post("Creating db '%s'", x->x_dbname->s_name);
|
mas01cr@578
|
113 x->db = audiodb_create(x->x_dbname->s_name, datasize, ntracks, dim);
|
mas01mj@569
|
114
|
mas01cr@574
|
115 if (x->db) {
|
mas01cr@578
|
116 post("Created and opened");
|
mas01mj@569
|
117 } else {
|
mas01cr@579
|
118 error("Could not create db '%s'.", x->x_dbname->s_name);
|
mas01mj@569
|
119 }
|
mas01mj@567
|
120 }
|
mas01mj@567
|
121
|
mas01cr@579
|
122 /* open a database, closing an existing one if necessary. */
|
mas01cr@574
|
123 static void adbpd_open(t_adbpd *x) {
|
mas01cr@579
|
124 adbpd_close(x);
|
mas01cr@579
|
125
|
mas01cr@574
|
126 post("Opening db '%s'", x->x_dbname->s_name);
|
mas01cr@579
|
127 if((x->db = audiodb_open(x->x_dbname->s_name, O_RDWR))) {
|
mas01cr@574
|
128 post("Opened");
|
mas01mj@569
|
129 } else {
|
mas01cr@574
|
130 error("Could not open db '%s'.", x->x_dbname->s_name);
|
mas01mj@569
|
131 }
|
mas01mj@567
|
132 }
|
mas01mj@567
|
133
|
mas01cr@579
|
134 static void adbpd_close(t_adbpd *x) {
|
mas01cr@579
|
135 if(x->db) {
|
mas01cr@579
|
136 post("Closing db");
|
mas01cr@579
|
137 audiodb_close(x->db);
|
mas01cr@579
|
138 x->db = NULL;
|
mas01cr@579
|
139 }
|
mas01cr@579
|
140 }
|
mas01cr@579
|
141
|
mas01cr@573
|
142 /* This is accessed via the 'set' message. It sets the name and opens
|
mas01cr@573
|
143 the database. */
|
mas01cr@574
|
144 static void adbpd_setname(t_adbpd *x, t_symbol *s, int argc, t_atom *argv) {
|
mas01cr@573
|
145 /* if we have a properly formed instruction */
|
mas01cr@573
|
146 if (argc == 1 && argv->a_type == A_SYMBOL) {
|
mas01cr@573
|
147 /* make the internal database reference name the same as the name
|
mas01cr@573
|
148 of the database we want. This is stupid. There must be a
|
mas01cr@573
|
149 better way of doing this. */
|
mas01cr@574
|
150 x->x_dbname = gensym(argv->a_w.w_symbol->s_name);
|
mas01cr@574
|
151 post("Name set to '%s'.", x->x_dbname->s_name);
|
mas01cr@573
|
152 }
|
mas01cr@574
|
153 /* now we can open the database as we did with the audiodb_open call
|
mas01cr@574
|
154 above */
|
mas01cr@574
|
155 /* FIXME: well, we _can_, but why is that a good idea? */
|
mas01cr@574
|
156 adbpd_open(x);
|
mas01cr@573
|
157 }
|
mas01cr@573
|
158
|
mas01mj@567
|
159
|
mas01mj@567
|
160 /* this is a status call to the audioDB API */
|
mas01mj@567
|
161 static void adbpd_status(t_adbpd *x){
|
mas01mj@567
|
162
|
mas01mj@569
|
163 adb_status_t mystatus;
|
mas01mj@569
|
164
|
mas01mj@569
|
165 post("Getting Status");
|
mas01cr@573
|
166
|
mas01mj@569
|
167 if (x->db && !(audiodb_status(x->db,&mystatus))){
|
mas01mj@569
|
168 post("numFiles %d",mystatus.numFiles);
|
mas01mj@569
|
169 post("dim %d",mystatus.dim);
|
mas01mj@569
|
170 post("length %d",mystatus.length);
|
mas01mj@569
|
171 post("dudCount %d",mystatus.dudCount);
|
mas01mj@569
|
172 post("numCount %d",mystatus.nullCount);
|
mas01mj@569
|
173 post("flags %d",mystatus.flags);
|
mas01mj@569
|
174 post("Bytes Available %d",mystatus.data_region_size);
|
mas01mj@569
|
175 } else {
|
mas01mj@569
|
176 error("Can't get Status. Have you selected a db?");
|
mas01mj@569
|
177 }
|
mas01mj@567
|
178 }
|
mas01mj@567
|
179
|
mas01mj@567
|
180
|
mas01mj@567
|
181 static void adbpd_doquery(t_adbpd *x){
|
mas01mj@567
|
182
|
mas01mj@569
|
183 adb_datum_t datum = {0};
|
mas01mj@569
|
184 adb_query_id_t qid = {0};
|
mas01mj@569
|
185 adb_query_parameters_t params = {0};
|
mas01mj@569
|
186 adb_query_refine_t refine = {0};
|
mas01cr@576
|
187 adb_query_spec_t spec;
|
mas01mj@569
|
188
|
mas01mj@569
|
189 // Configure the start+length of the query, and zero
|
mas01mj@569
|
190 // the flags initially.
|
mas01mj@569
|
191 qid.datum = &datum;
|
mas01mj@569
|
192 qid.sequence_length = x->x_dbsequencelength;
|
mas01mj@569
|
193 qid.sequence_start = x->x_dbqpoint;
|
mas01mj@569
|
194 qid.flags = 0;
|
mas01mj@567
|
195
|
mas01mj@569
|
196 // We don't specify hopsize (yet) so it defaults to 1.
|
mas01mj@569
|
197 refine.hopsize = 1;
|
mas01mj@569
|
198 refine.flags |= ADB_REFINE_RADIUS;
|
mas01mj@569
|
199 refine.radius = x->x_dbradius;
|
mas01mj@567
|
200
|
mas01mj@569
|
201 spec.qid = qid;
|
mas01mj@569
|
202 spec.params = params;
|
mas01mj@569
|
203 spec.refine = refine;
|
mas01mj@569
|
204
|
mas01mj@569
|
205 int fd;
|
mas01mj@569
|
206 struct stat st;
|
mas01mj@569
|
207
|
mas01mj@569
|
208 // Read in the feature file - note that this code may contain leaks
|
mas01mj@569
|
209 // (the same chunk also exists in audioDB.cpp).
|
mas01mj@569
|
210 fd = open(x->x_dbfeature->s_name, O_RDONLY);
|
mas01mj@569
|
211 if(fd < 0) {
|
mas01mj@569
|
212 error("failed to open feature file", x->x_dbfeature->s_name);
|
mas01mj@569
|
213 return;
|
mas01mj@569
|
214 }
|
mas01mj@569
|
215 fstat(fd, &st);
|
mas01mj@569
|
216 read(fd, &datum.dim, sizeof(uint32_t));
|
mas01mj@569
|
217 datum.nvectors = (st.st_size - sizeof(uint32_t)) / (datum.dim * sizeof(double));
|
mas01mj@569
|
218 datum.data = (double *) malloc(st.st_size - sizeof(uint32_t));
|
mas01mj@569
|
219 read(fd, datum.data, st.st_size - sizeof(uint32_t));
|
mas01mj@569
|
220 close(fd);
|
mas01mj@569
|
221
|
mas01mj@569
|
222 // Set up query spec params depending on the query type.
|
mas01mj@569
|
223 switch(x->x_dbquerytype)
|
mas01cr@573
|
224 {
|
mas01mj@569
|
225 case O2_POINT_QUERY:
|
mas01mj@569
|
226 spec.qid.sequence_length = 1;
|
mas01mj@569
|
227 spec.params.accumulation = ADB_ACCUMULATION_DB;
|
mas01mj@569
|
228 spec.params.distance = ADB_DISTANCE_DOT_PRODUCT;
|
mas01mj@569
|
229 spec.params.npoints = x->x_dbnumpoints;
|
mas01mj@569
|
230 spec.params.ntracks = x->x_dbresultlength;
|
mas01mj@569
|
231 break;
|
mas01mj@569
|
232 case O2_TRACK_QUERY:
|
mas01mj@569
|
233 spec.qid.sequence_length = 1;
|
mas01mj@569
|
234 spec.params.accumulation = ADB_ACCUMULATION_PER_TRACK;
|
mas01mj@569
|
235 spec.params.distance = ADB_DISTANCE_DOT_PRODUCT;
|
mas01mj@569
|
236 spec.params.npoints = x->x_dbnumpoints;
|
mas01mj@569
|
237 spec.params.ntracks = x->x_dbresultlength;
|
mas01mj@569
|
238 case O2_SEQUENCE_QUERY:
|
mas01mj@569
|
239 case O2_N_SEQUENCE_QUERY:
|
mas01mj@569
|
240 spec.params.accumulation = ADB_ACCUMULATION_PER_TRACK;
|
mas01mj@569
|
241 // TODO : Add unit norming param. Defaults to false.
|
mas01cr@573
|
242 //
|
mas01cr@573
|
243 // spec.params.distance = no_unit_norming ?
|
mas01cr@573
|
244 // ADB_DISTANCE_EUCLIDEAN : ADB_DISTANCE_EUCLIDEAN_NORMED;
|
mas01mj@569
|
245 spec.params.distance = ADB_DISTANCE_EUCLIDEAN_NORMED;
|
mas01mj@569
|
246 spec.params.npoints = x->x_dbnumpoints;
|
mas01mj@569
|
247 spec.params.ntracks = x->x_dbresultlength;
|
mas01mj@569
|
248 break;
|
mas01mj@569
|
249 case O2_ONE_TO_ONE_N_SEQUENCE_QUERY:
|
mas01mj@569
|
250 spec.params.accumulation = ADB_ACCUMULATION_ONE_TO_ONE;
|
mas01mj@569
|
251 // TODO : Add unit norming param. Defaults to false.
|
mas01cr@573
|
252 //
|
mas01cr@573
|
253 // spec.params.distance = no_unit_norming ?
|
mas01cr@573
|
254 // ADB_DISTANCE_EUCLIDEAN : ADB_DISTANCE_EUCLIDEAN_NORMED;
|
mas01mj@569
|
255 spec.params.distance =ADB_DISTANCE_EUCLIDEAN_NORMED;
|
mas01mj@569
|
256 spec.params.npoints = 0;
|
mas01mj@569
|
257 spec.params.ntracks = 0;
|
mas01mj@569
|
258 break;
|
mas01mj@569
|
259 default:
|
mas01mj@569
|
260 post("Unsupported query type");
|
mas01mj@569
|
261 }
|
mas01mj@569
|
262
|
mas01mj@569
|
263 adb_query_results_t *rs = audiodb_query_spec(x->db, &spec);
|
mas01mj@569
|
264
|
mas01mj@569
|
265 if(datum.data) {
|
mas01cr@573
|
266 free(datum.data);
|
mas01cr@573
|
267 datum.data = NULL;
|
mas01mj@569
|
268 }
|
mas01mj@569
|
269 if(datum.power) {
|
mas01cr@577
|
270 free(datum.power);
|
mas01cr@577
|
271 datum.power = NULL;
|
mas01mj@569
|
272 }
|
mas01mj@569
|
273 if(datum.times) {
|
mas01cr@577
|
274 free(datum.times);
|
mas01cr@577
|
275 datum.times = NULL;
|
mas01mj@569
|
276 }
|
mas01mj@569
|
277
|
mas01mj@569
|
278 if(rs == NULL)
|
mas01mj@569
|
279 {
|
mas01mj@569
|
280 error("Query failed");
|
mas01mj@569
|
281 return;
|
mas01mj@569
|
282 }
|
mas01mj@569
|
283
|
mas01mj@569
|
284 int size = rs->nresults;
|
mas01mj@569
|
285 post("result size:[%d]",(int)size);
|
mas01mj@569
|
286 int i = 0;
|
mas01mj@569
|
287 for(i=0; i<size; i++){
|
mas01mj@569
|
288 adb_result_t r = rs->results[i];
|
mas01mj@567
|
289
|
mas01mj@569
|
290 outlet_float(x->x_dist,r.dist);
|
mas01mj@569
|
291 outlet_float(x->x_qpos,r.qpos);
|
mas01mj@569
|
292 outlet_float(x->x_spos,r.ipos);
|
mas01mj@567
|
293
|
mas01mj@569
|
294 post("in obj key:%s",r.key);
|
mas01mj@569
|
295 post("in obj Dist:%f", r.dist);
|
mas01mj@569
|
296 post("in obj qpos:%d", r.qpos);
|
mas01mj@569
|
297 post("in obj ipos:%d", r.ipos);
|
mas01mj@569
|
298 }
|
mas01cr@577
|
299 audiodb_query_free_results(x->db, &spec, rs);
|
mas01mj@567
|
300 }
|
mas01mj@567
|
301
|
mas01cr@573
|
302 /* Do I need to set a the power file for this flag to work ?
|
mas01cr@573
|
303 Hmmm. Dunno. Also, should be on/off*/
|
mas01mj@567
|
304 static void adbpd_power(t_adbpd *x){
|
mas01mj@569
|
305 post("power");
|
mas01mj@569
|
306
|
mas01mj@569
|
307 if (x->db && !(audiodb_power(x->db))){
|
mas01mj@569
|
308 post("power successfully set on db");
|
mas01mj@569
|
309 } else {
|
mas01mj@569
|
310 error("power flag not working");
|
mas01mj@569
|
311 }
|
mas01mj@567
|
312 }
|
mas01mj@567
|
313
|
mas01cr@573
|
314 /* works fine but would be better if it took an argument to switch it
|
mas01cr@573
|
315 on and off */
|
mas01mj@567
|
316 static void adbpd_l2norm(t_adbpd *x){
|
mas01mj@569
|
317 post("l2norm");
|
mas01mj@569
|
318
|
mas01mj@569
|
319 if (x->db && !(audiodb_l2norm(x->db))){
|
mas01mj@569
|
320 post("l2norm successfully set on db");
|
mas01mj@569
|
321 } else {
|
mas01mj@569
|
322 error("l2norm flag not working");
|
mas01mj@569
|
323 }
|
mas01mj@567
|
324 }
|
mas01mj@567
|
325
|
mas01mj@567
|
326 /* reports the name of the current db */
|
mas01mj@567
|
327 static void adbpd_getname(t_adbpd *x){
|
mas01mj@569
|
328 post("db name is '%s'", x->x_dbname->s_name);
|
mas01mj@567
|
329 }
|
mas01mj@567
|
330
|
mas01mj@567
|
331 /* this sets the qpoint for the current query*/
|
mas01mj@567
|
332 static void adbpd_setqpoint(t_adbpd *x,t_floatarg f){
|
mas01cr@573
|
333 post("qpoint %.3f",f);
|
mas01mj@569
|
334 x->x_dbqpoint=f;
|
mas01mj@567
|
335 }
|
mas01mj@567
|
336
|
mas01mj@567
|
337 /* This sets the number of points for current query */
|
mas01mj@567
|
338 static void adbpd_setnumpoints(t_adbpd *x,t_floatarg f){
|
mas01cr@573
|
339 post("numpoints %.3f",f);
|
mas01cr@573
|
340 x->x_dbnumpoints=(int)f;
|
mas01mj@567
|
341 }
|
mas01mj@567
|
342
|
mas01mj@567
|
343 /* This sets the radius */
|
mas01mj@567
|
344 static void adbpd_setradius(t_adbpd *x,t_floatarg f){
|
mas01cr@573
|
345 post("radius %.3f",f);
|
mas01cr@573
|
346 x->x_dbradius=f;
|
mas01mj@567
|
347 }
|
mas01mj@567
|
348
|
mas01mj@567
|
349 /* This sets the result length */
|
mas01mj@567
|
350 static void adbpd_setresultlength(t_adbpd *x,t_floatarg f){
|
mas01cr@573
|
351 post("resultlength %.3f",f);
|
mas01cr@573
|
352 x->x_dbresultlength=(int)f;
|
mas01mj@567
|
353 }
|
mas01mj@567
|
354
|
mas01mj@567
|
355 /* This sets the sequence length */
|
mas01mj@567
|
356 static void adbpd_setsequencelength(t_adbpd *x,t_floatarg f){
|
mas01cr@573
|
357 post("sequencelength %.3f",f);
|
mas01cr@573
|
358 x->x_dbsequencelength=(int)f;
|
mas01mj@567
|
359 }
|
mas01mj@567
|
360
|
mas01mj@567
|
361 /* This sets the feature file to use for the query */
|
mas01mj@567
|
362 static void adbpd_setfeatures(t_adbpd *x,t_symbol *s,int argc, t_atom *argv){
|
mas01mj@569
|
363
|
mas01mj@569
|
364 if (argc == 1 && argv->a_type == A_SYMBOL){
|
mas01mj@569
|
365 x->x_dbfeature=gensym(argv->a_w.w_symbol->s_name);
|
mas01mj@569
|
366 post("Features file has been set to '%s'",x->x_dbfeature->s_name);
|
mas01mj@569
|
367 }
|
mas01mj@567
|
368 }
|
mas01mj@567
|
369
|
mas01mj@567
|
370 /* This sets the query type */
|
mas01mj@567
|
371 static void adbpd_setquerytype(t_adbpd *x,t_symbol *s,int argc, t_atom *argv){
|
mas01cr@573
|
372 if (argc == 1 && argv->a_type == A_SYMBOL) {
|
mas01cr@575
|
373 t_symbol *type = atom_getsymbol(argv);
|
mas01cr@575
|
374 if(type == gensym("track")) {
|
mas01mj@569
|
375 x->x_dbquerytype=O2_TRACK_QUERY;
|
mas01cr@575
|
376 } else if(type == gensym("point")) {
|
mas01mj@569
|
377 x->x_dbquerytype=O2_POINT_QUERY;
|
mas01cr@575
|
378 } else if(type == gensym("sequence")) {
|
mas01mj@569
|
379 x->x_dbquerytype=O2_SEQUENCE_QUERY;
|
mas01cr@575
|
380 } else if(type == gensym("nsequence")) {
|
mas01mj@569
|
381 x->x_dbquerytype=O2_N_SEQUENCE_QUERY;
|
mas01cr@575
|
382 } else if(type == gensym("onetoonensequence")) {
|
mas01mj@569
|
383 x->x_dbquerytype=O2_ONE_TO_ONE_N_SEQUENCE_QUERY;
|
mas01cr@575
|
384 } else {
|
mas01cr@575
|
385 error("unsupported query type: '%s'", type->s_name);
|
mas01cr@575
|
386 return;
|
mas01cr@575
|
387 }
|
mas01cr@575
|
388 post("Query type has been set to '%s'", type->s_name);
|
mas01mj@569
|
389 }
|
mas01mj@567
|
390 }
|
mas01mj@567
|
391
|
mas01mj@567
|
392 /* This lists all the parameters */
|
mas01mj@567
|
393
|
mas01mj@567
|
394 static void adbpd_parameters(t_adbpd *x){
|
mas01mj@567
|
395
|
mas01mj@569
|
396 post("dbname %s",x->x_dbname->s_name);
|
mas01mj@569
|
397 post("querytype %d",x->x_dbquerytype);
|
mas01mj@569
|
398 post("features %s",x->x_dbfeature->s_name);
|
mas01mj@569
|
399 post("qpoint %.3f",x->x_dbqpoint);
|
mas01mj@569
|
400 post("numpoints %.3f",x->x_dbnumpoints);
|
mas01mj@569
|
401 post("radius %.3f",x->x_dbradius);
|
mas01mj@569
|
402 post("resultlength %.3f",x->x_dbresultlength);
|
mas01mj@569
|
403 post("sequencelength %.3f",x->x_dbsequencelength);
|
mas01mj@567
|
404 }
|
mas01mj@567
|
405
|
mas01cr@573
|
406 /* THAR SHE BLOWS. This sets up the object, takes the messages with
|
mas01cr@573
|
407 args and maps them to methods. */
|
mas01mj@567
|
408 void adbpd_setup(void) {
|
mas01cr@573
|
409 /* the arguments in this line refer to INPUT ARGUMENTS and not
|
mas01cr@573
|
410 OUTPUTS */
|
mas01cr@578
|
411 adbpd_class =
|
mas01cr@578
|
412 class_new(gensym("adbpd"), (t_newmethod) adbpd_new, (t_method) adbpd_free,
|
mas01cr@578
|
413 sizeof(t_adbpd), CLASS_DEFAULT, A_DEFSYMBOL, 0);
|
mas01cr@575
|
414
|
mas01cr@573
|
415 /* all methods that respond to input must be defined here */
|
mas01cr@573
|
416 class_addbang(adbpd_class, adbpd_bang);
|
mas01cr@573
|
417 class_addfloat(adbpd_class, adbpd_setqpoint);
|
mas01cr@573
|
418 class_addfloat(adbpd_class, adbpd_setnumpoints);
|
mas01cr@573
|
419 class_addfloat(adbpd_class, adbpd_setradius);
|
mas01cr@573
|
420 class_addfloat(adbpd_class, adbpd_setresultlength);
|
mas01cr@573
|
421 class_addfloat(adbpd_class, adbpd_setsequencelength);
|
mas01cr@573
|
422 class_addmethod(adbpd_class, (t_method)adbpd_setname, gensym("set"), A_GIMME, 0);
|
mas01cr@573
|
423 class_addmethod(adbpd_class, (t_method)adbpd_getname, gensym("get"), A_NULL);
|
mas01cr@578
|
424 class_addmethod(adbpd_class, (t_method)adbpd_create, gensym("create"), A_FLOAT, A_FLOAT, A_FLOAT, 0);
|
mas01cr@573
|
425 class_addmethod(adbpd_class, (t_method)adbpd_open, gensym("open"), A_NULL);
|
mas01cr@579
|
426 class_addmethod(adbpd_class, (t_method)adbpd_close, gensym("close"), A_NULL);
|
mas01cr@573
|
427 class_addmethod(adbpd_class, (t_method)adbpd_status, gensym("status"), A_NULL);
|
mas01cr@573
|
428 class_addmethod(adbpd_class, (t_method)adbpd_l2norm, gensym("l2norm"), A_NULL);
|
mas01cr@573
|
429 class_addmethod(adbpd_class, (t_method)adbpd_power, gensym("power"), A_NULL);
|
mas01cr@573
|
430 class_addmethod(adbpd_class, (t_method)adbpd_doquery, gensym("doquery"), A_NULL);
|
mas01mj@569
|
431 class_addmethod(adbpd_class, (t_method)adbpd_setquerytype, gensym("querytype"), A_GIMME, 0);
|
mas01mj@569
|
432 class_addmethod(adbpd_class, (t_method)adbpd_setfeatures, gensym("features"), A_GIMME, 0);
|
mas01cr@573
|
433 class_addmethod(adbpd_class, (t_method)adbpd_parameters, gensym("parameters"), A_NULL);
|
mas01mj@567
|
434 }
|
mas01mj@567
|
435
|