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 refine.flags |= ADB_REFINE_RADIUS;
|
mas01mj@569
|
197 refine.radius = x->x_dbradius;
|
mas01mj@567
|
198
|
mas01mj@569
|
199 spec.qid = qid;
|
mas01mj@569
|
200 spec.params = params;
|
mas01mj@569
|
201 spec.refine = refine;
|
mas01mj@569
|
202
|
mas01mj@569
|
203 int fd;
|
mas01mj@569
|
204 struct stat st;
|
mas01mj@569
|
205
|
mas01mj@569
|
206 // Read in the feature file - note that this code may contain leaks
|
mas01mj@569
|
207 // (the same chunk also exists in audioDB.cpp).
|
mas01mj@569
|
208 fd = open(x->x_dbfeature->s_name, O_RDONLY);
|
mas01mj@569
|
209 if(fd < 0) {
|
mas01mj@569
|
210 error("failed to open feature file", x->x_dbfeature->s_name);
|
mas01mj@569
|
211 return;
|
mas01mj@569
|
212 }
|
mas01mj@569
|
213 fstat(fd, &st);
|
mas01mj@569
|
214 read(fd, &datum.dim, sizeof(uint32_t));
|
mas01mj@569
|
215 datum.nvectors = (st.st_size - sizeof(uint32_t)) / (datum.dim * sizeof(double));
|
mas01mj@569
|
216 datum.data = (double *) malloc(st.st_size - sizeof(uint32_t));
|
mas01mj@569
|
217 read(fd, datum.data, st.st_size - sizeof(uint32_t));
|
mas01mj@569
|
218 close(fd);
|
mas01mj@569
|
219
|
mas01mj@569
|
220 // Set up query spec params depending on the query type.
|
mas01mj@569
|
221 switch(x->x_dbquerytype)
|
mas01cr@573
|
222 {
|
mas01mj@569
|
223 case O2_POINT_QUERY:
|
mas01mj@569
|
224 spec.qid.sequence_length = 1;
|
mas01mj@569
|
225 spec.params.accumulation = ADB_ACCUMULATION_DB;
|
mas01mj@569
|
226 spec.params.distance = ADB_DISTANCE_DOT_PRODUCT;
|
mas01mj@569
|
227 spec.params.npoints = x->x_dbnumpoints;
|
mas01mj@569
|
228 spec.params.ntracks = x->x_dbresultlength;
|
mas01mj@569
|
229 break;
|
mas01mj@569
|
230 case O2_TRACK_QUERY:
|
mas01mj@569
|
231 spec.qid.sequence_length = 1;
|
mas01mj@569
|
232 spec.params.accumulation = ADB_ACCUMULATION_PER_TRACK;
|
mas01mj@569
|
233 spec.params.distance = ADB_DISTANCE_DOT_PRODUCT;
|
mas01mj@569
|
234 spec.params.npoints = x->x_dbnumpoints;
|
mas01mj@569
|
235 spec.params.ntracks = x->x_dbresultlength;
|
mas01mj@569
|
236 case O2_SEQUENCE_QUERY:
|
mas01mj@569
|
237 case O2_N_SEQUENCE_QUERY:
|
mas01mj@569
|
238 spec.params.accumulation = ADB_ACCUMULATION_PER_TRACK;
|
mas01mj@569
|
239 // TODO : Add unit norming param. Defaults to false.
|
mas01cr@573
|
240 //
|
mas01cr@573
|
241 // spec.params.distance = no_unit_norming ?
|
mas01cr@573
|
242 // ADB_DISTANCE_EUCLIDEAN : ADB_DISTANCE_EUCLIDEAN_NORMED;
|
mas01mj@569
|
243 spec.params.distance = ADB_DISTANCE_EUCLIDEAN_NORMED;
|
mas01mj@569
|
244 spec.params.npoints = x->x_dbnumpoints;
|
mas01mj@569
|
245 spec.params.ntracks = x->x_dbresultlength;
|
mas01mj@569
|
246 break;
|
mas01mj@569
|
247 case O2_ONE_TO_ONE_N_SEQUENCE_QUERY:
|
mas01mj@569
|
248 spec.params.accumulation = ADB_ACCUMULATION_ONE_TO_ONE;
|
mas01mj@569
|
249 // TODO : Add unit norming param. Defaults to false.
|
mas01cr@573
|
250 //
|
mas01cr@573
|
251 // spec.params.distance = no_unit_norming ?
|
mas01cr@573
|
252 // ADB_DISTANCE_EUCLIDEAN : ADB_DISTANCE_EUCLIDEAN_NORMED;
|
mas01mj@569
|
253 spec.params.distance =ADB_DISTANCE_EUCLIDEAN_NORMED;
|
mas01mj@569
|
254 spec.params.npoints = 0;
|
mas01mj@569
|
255 spec.params.ntracks = 0;
|
mas01mj@569
|
256 break;
|
mas01mj@569
|
257 default:
|
mas01mj@569
|
258 post("Unsupported query type");
|
mas01mj@569
|
259 }
|
mas01mj@569
|
260
|
mas01mj@569
|
261 adb_query_results_t *rs = audiodb_query_spec(x->db, &spec);
|
mas01mj@569
|
262
|
mas01mj@569
|
263 if(datum.data) {
|
mas01cr@573
|
264 free(datum.data);
|
mas01cr@573
|
265 datum.data = NULL;
|
mas01mj@569
|
266 }
|
mas01mj@569
|
267 if(datum.power) {
|
mas01cr@577
|
268 free(datum.power);
|
mas01cr@577
|
269 datum.power = NULL;
|
mas01mj@569
|
270 }
|
mas01mj@569
|
271 if(datum.times) {
|
mas01cr@577
|
272 free(datum.times);
|
mas01cr@577
|
273 datum.times = NULL;
|
mas01mj@569
|
274 }
|
mas01mj@569
|
275
|
mas01mj@569
|
276 if(rs == NULL)
|
mas01mj@569
|
277 {
|
mas01mj@569
|
278 error("Query failed");
|
mas01mj@569
|
279 return;
|
mas01mj@569
|
280 }
|
mas01mj@569
|
281
|
mas01mj@569
|
282 int size = rs->nresults;
|
mas01mj@569
|
283 post("result size:[%d]",(int)size);
|
mas01mj@569
|
284 int i = 0;
|
mas01mj@569
|
285 for(i=0; i<size; i++){
|
mas01mj@569
|
286 adb_result_t r = rs->results[i];
|
mas01mj@567
|
287
|
mas01mj@569
|
288 outlet_float(x->x_dist,r.dist);
|
mas01mj@569
|
289 outlet_float(x->x_qpos,r.qpos);
|
mas01mj@569
|
290 outlet_float(x->x_spos,r.ipos);
|
mas01mj@567
|
291
|
mas01cr@672
|
292 post("in obj ikey:%s",r.ikey);
|
mas01mj@569
|
293 post("in obj Dist:%f", r.dist);
|
mas01mj@569
|
294 post("in obj qpos:%d", r.qpos);
|
mas01mj@569
|
295 post("in obj ipos:%d", r.ipos);
|
mas01mj@569
|
296 }
|
mas01cr@577
|
297 audiodb_query_free_results(x->db, &spec, rs);
|
mas01mj@567
|
298 }
|
mas01mj@567
|
299
|
mas01cr@573
|
300 /* Do I need to set a the power file for this flag to work ?
|
mas01cr@573
|
301 Hmmm. Dunno. Also, should be on/off*/
|
mas01mj@567
|
302 static void adbpd_power(t_adbpd *x){
|
mas01mj@569
|
303 post("power");
|
mas01mj@569
|
304
|
mas01mj@569
|
305 if (x->db && !(audiodb_power(x->db))){
|
mas01mj@569
|
306 post("power successfully set on db");
|
mas01mj@569
|
307 } else {
|
mas01mj@569
|
308 error("power flag not working");
|
mas01mj@569
|
309 }
|
mas01mj@567
|
310 }
|
mas01mj@567
|
311
|
mas01cr@573
|
312 /* works fine but would be better if it took an argument to switch it
|
mas01cr@573
|
313 on and off */
|
mas01mj@567
|
314 static void adbpd_l2norm(t_adbpd *x){
|
mas01mj@569
|
315 post("l2norm");
|
mas01mj@569
|
316
|
mas01mj@569
|
317 if (x->db && !(audiodb_l2norm(x->db))){
|
mas01mj@569
|
318 post("l2norm successfully set on db");
|
mas01mj@569
|
319 } else {
|
mas01mj@569
|
320 error("l2norm flag not working");
|
mas01mj@569
|
321 }
|
mas01mj@567
|
322 }
|
mas01mj@567
|
323
|
mas01mj@567
|
324 /* reports the name of the current db */
|
mas01mj@567
|
325 static void adbpd_getname(t_adbpd *x){
|
mas01mj@569
|
326 post("db name is '%s'", x->x_dbname->s_name);
|
mas01mj@567
|
327 }
|
mas01mj@567
|
328
|
mas01mj@567
|
329 /* this sets the qpoint for the current query*/
|
mas01mj@567
|
330 static void adbpd_setqpoint(t_adbpd *x,t_floatarg f){
|
mas01cr@573
|
331 post("qpoint %.3f",f);
|
mas01mj@569
|
332 x->x_dbqpoint=f;
|
mas01mj@567
|
333 }
|
mas01mj@567
|
334
|
mas01mj@567
|
335 /* This sets the number of points for current query */
|
mas01mj@567
|
336 static void adbpd_setnumpoints(t_adbpd *x,t_floatarg f){
|
mas01cr@573
|
337 post("numpoints %.3f",f);
|
mas01cr@573
|
338 x->x_dbnumpoints=(int)f;
|
mas01mj@567
|
339 }
|
mas01mj@567
|
340
|
mas01mj@567
|
341 /* This sets the radius */
|
mas01mj@567
|
342 static void adbpd_setradius(t_adbpd *x,t_floatarg f){
|
mas01cr@573
|
343 post("radius %.3f",f);
|
mas01cr@573
|
344 x->x_dbradius=f;
|
mas01mj@567
|
345 }
|
mas01mj@567
|
346
|
mas01mj@567
|
347 /* This sets the result length */
|
mas01mj@567
|
348 static void adbpd_setresultlength(t_adbpd *x,t_floatarg f){
|
mas01cr@573
|
349 post("resultlength %.3f",f);
|
mas01cr@573
|
350 x->x_dbresultlength=(int)f;
|
mas01mj@567
|
351 }
|
mas01mj@567
|
352
|
mas01mj@567
|
353 /* This sets the sequence length */
|
mas01mj@567
|
354 static void adbpd_setsequencelength(t_adbpd *x,t_floatarg f){
|
mas01cr@573
|
355 post("sequencelength %.3f",f);
|
mas01cr@573
|
356 x->x_dbsequencelength=(int)f;
|
mas01mj@567
|
357 }
|
mas01mj@567
|
358
|
mas01mj@567
|
359 /* This sets the feature file to use for the query */
|
mas01mj@567
|
360 static void adbpd_setfeatures(t_adbpd *x,t_symbol *s,int argc, t_atom *argv){
|
mas01mj@569
|
361
|
mas01mj@569
|
362 if (argc == 1 && argv->a_type == A_SYMBOL){
|
mas01mj@569
|
363 x->x_dbfeature=gensym(argv->a_w.w_symbol->s_name);
|
mas01mj@569
|
364 post("Features file has been set to '%s'",x->x_dbfeature->s_name);
|
mas01mj@569
|
365 }
|
mas01mj@567
|
366 }
|
mas01mj@567
|
367
|
mas01mj@567
|
368 /* This sets the query type */
|
mas01mj@567
|
369 static void adbpd_setquerytype(t_adbpd *x,t_symbol *s,int argc, t_atom *argv){
|
mas01cr@573
|
370 if (argc == 1 && argv->a_type == A_SYMBOL) {
|
mas01cr@575
|
371 t_symbol *type = atom_getsymbol(argv);
|
mas01cr@575
|
372 if(type == gensym("track")) {
|
mas01mj@569
|
373 x->x_dbquerytype=O2_TRACK_QUERY;
|
mas01cr@575
|
374 } else if(type == gensym("point")) {
|
mas01mj@569
|
375 x->x_dbquerytype=O2_POINT_QUERY;
|
mas01cr@575
|
376 } else if(type == gensym("sequence")) {
|
mas01mj@569
|
377 x->x_dbquerytype=O2_SEQUENCE_QUERY;
|
mas01cr@575
|
378 } else if(type == gensym("nsequence")) {
|
mas01mj@569
|
379 x->x_dbquerytype=O2_N_SEQUENCE_QUERY;
|
mas01cr@575
|
380 } else if(type == gensym("onetoonensequence")) {
|
mas01mj@569
|
381 x->x_dbquerytype=O2_ONE_TO_ONE_N_SEQUENCE_QUERY;
|
mas01cr@575
|
382 } else {
|
mas01cr@575
|
383 error("unsupported query type: '%s'", type->s_name);
|
mas01cr@575
|
384 return;
|
mas01cr@575
|
385 }
|
mas01cr@575
|
386 post("Query type has been set to '%s'", type->s_name);
|
mas01mj@569
|
387 }
|
mas01mj@567
|
388 }
|
mas01mj@567
|
389
|
mas01mj@567
|
390 /* This lists all the parameters */
|
mas01mj@567
|
391
|
mas01mj@567
|
392 static void adbpd_parameters(t_adbpd *x){
|
mas01mj@567
|
393
|
mas01mj@569
|
394 post("dbname %s",x->x_dbname->s_name);
|
mas01mj@569
|
395 post("querytype %d",x->x_dbquerytype);
|
mas01mj@569
|
396 post("features %s",x->x_dbfeature->s_name);
|
mas01mj@569
|
397 post("qpoint %.3f",x->x_dbqpoint);
|
mas01mj@569
|
398 post("numpoints %.3f",x->x_dbnumpoints);
|
mas01mj@569
|
399 post("radius %.3f",x->x_dbradius);
|
mas01mj@569
|
400 post("resultlength %.3f",x->x_dbresultlength);
|
mas01mj@569
|
401 post("sequencelength %.3f",x->x_dbsequencelength);
|
mas01mj@567
|
402 }
|
mas01mj@567
|
403
|
mas01cr@573
|
404 /* THAR SHE BLOWS. This sets up the object, takes the messages with
|
mas01cr@573
|
405 args and maps them to methods. */
|
mas01mj@567
|
406 void adbpd_setup(void) {
|
mas01cr@573
|
407 /* the arguments in this line refer to INPUT ARGUMENTS and not
|
mas01cr@573
|
408 OUTPUTS */
|
mas01cr@578
|
409 adbpd_class =
|
mas01cr@578
|
410 class_new(gensym("adbpd"), (t_newmethod) adbpd_new, (t_method) adbpd_free,
|
mas01cr@578
|
411 sizeof(t_adbpd), CLASS_DEFAULT, A_DEFSYMBOL, 0);
|
mas01cr@575
|
412
|
mas01cr@573
|
413 /* all methods that respond to input must be defined here */
|
mas01cr@573
|
414 class_addbang(adbpd_class, adbpd_bang);
|
mas01cr@573
|
415 class_addfloat(adbpd_class, adbpd_setqpoint);
|
mas01cr@573
|
416 class_addfloat(adbpd_class, adbpd_setnumpoints);
|
mas01cr@573
|
417 class_addfloat(adbpd_class, adbpd_setradius);
|
mas01cr@573
|
418 class_addfloat(adbpd_class, adbpd_setresultlength);
|
mas01cr@573
|
419 class_addfloat(adbpd_class, adbpd_setsequencelength);
|
mas01cr@573
|
420 class_addmethod(adbpd_class, (t_method)adbpd_setname, gensym("set"), A_GIMME, 0);
|
mas01cr@573
|
421 class_addmethod(adbpd_class, (t_method)adbpd_getname, gensym("get"), A_NULL);
|
mas01cr@578
|
422 class_addmethod(adbpd_class, (t_method)adbpd_create, gensym("create"), A_FLOAT, A_FLOAT, A_FLOAT, 0);
|
mas01cr@573
|
423 class_addmethod(adbpd_class, (t_method)adbpd_open, gensym("open"), A_NULL);
|
mas01cr@579
|
424 class_addmethod(adbpd_class, (t_method)adbpd_close, gensym("close"), A_NULL);
|
mas01cr@573
|
425 class_addmethod(adbpd_class, (t_method)adbpd_status, gensym("status"), A_NULL);
|
mas01cr@573
|
426 class_addmethod(adbpd_class, (t_method)adbpd_l2norm, gensym("l2norm"), A_NULL);
|
mas01cr@573
|
427 class_addmethod(adbpd_class, (t_method)adbpd_power, gensym("power"), A_NULL);
|
mas01cr@573
|
428 class_addmethod(adbpd_class, (t_method)adbpd_doquery, gensym("doquery"), A_NULL);
|
mas01mj@569
|
429 class_addmethod(adbpd_class, (t_method)adbpd_setquerytype, gensym("querytype"), A_GIMME, 0);
|
mas01mj@569
|
430 class_addmethod(adbpd_class, (t_method)adbpd_setfeatures, gensym("features"), A_GIMME, 0);
|
mas01cr@573
|
431 class_addmethod(adbpd_class, (t_method)adbpd_parameters, gensym("parameters"), A_NULL);
|
mas01mj@567
|
432 }
|
mas01mj@567
|
433
|