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