3 * sushivision copyright (C) 2006-2007 Monty <monty@xiph.org>
5 * sushivision is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * sushivision is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with sushivision; see the file COPYING. If not, write to the
17 * Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
29 sv_obj_t
**_sv_objective_list
=NULL
;
30 pthread_key_t _sv_obj_key
;
32 static char *objective_axismap
[]={
36 #define map_axes ((int)sizeof(objective_axismap)/(int)sizeof(*objective_axismap))
38 int sv_obj_new(char *name
,
39 void(*function
)(double *,double *),
46 _sv_token
*decl
= _sv_tokenize_declparam(name
);
47 _sv_tokenlist
*in
= NULL
;
48 _sv_tokenlist
*out
= NULL
;
51 fprintf(stderr
,"sushivision: Unable to parse objective declaration \"%s\".\n",name
);
55 if(_sv_objectives
== 0){
57 _sv_objective_list
= calloc (number
+1,sizeof(*_sv_objective_list
));
60 for(number
=0;number
<_sv_objectives
;number
++)
61 if(!_sv_objective_list
[number
])break;
62 if(number
==_sv_objectives
){
63 _sv_objectives
=number
+1;
64 _sv_objective_list
= realloc (_sv_objective_list
,_sv_objectives
* sizeof(*_sv_objective_list
));
68 o
= _sv_objective_list
[number
] = calloc(1, sizeof(**_sv_objective_list
));
69 o
->name
= strdup(decl
->name
);
70 o
->legend
= strdup(decl
->label
);
72 o
->function
= function
;
74 /* parse and sanity check the maps */
75 in
= _sv_tokenize_noparamlist(input_map
);
76 out
= _sv_tokenize_noparamlist(output_map
);
78 /* input dimensions */
80 fprintf(stderr
,"sushivision: Unable to parse objective \"%s\" dimenension list \"%s\".\n",
86 o
->input_dims
= calloc(in
->n
,sizeof(*o
->input_dims
));
88 sv_dim_t
*id
= sv_dim(in
->list
[i
]->name
);
90 fprintf(stderr
,"sushivision: Dimension \"%s\" does not exist in declaration of objective \"%s\".\n",
91 in
->list
[i
]->name
,o
->name
);
94 o
->input_dims
[i
] = id
;
99 o
->output_axes
= malloc(map_axes
* sizeof(*o
->output_axes
));
100 for(i
=0;i
<map_axes
;i
++)
101 o
->output_axes
[i
]=-1;
103 for(i
=0;i
<out
->n
;i
++){
104 char *s
= out
->list
[i
]->name
;
105 if(!s
|| !strcasecmp(s
,"*")){
106 // output unused by objective
109 for(j
=0;j
<map_axes
;j
++){
110 if(!strcasecmp(s
,objective_axismap
[j
])){
112 if(o
->output_axes
[j
] != -1){
113 fprintf(stderr
,"sushivision: Objective \"%s\" declares multiple %s axis outputs.\n",
114 o
->name
,objective_axismap
[j
]);
117 o
->output_axes
[j
] = i
;
121 fprintf(stderr
,"sushivision: No such output axis \"%s\" in declaration of objective \"%s\"\n",
127 pthread_setspecific(_sv_obj_key
, (void *)o
);
129 _sv_token_free(decl
);
130 _sv_tokenlist_free(in
);
131 _sv_tokenlist_free(out
);
141 // XXXX need to recompute after
142 // XXXX need to add scale cloning to compute to make this safe in callbacks
143 int sv_obj_set_scale(sv_scale_t
*scale
){
144 sv_obj_t
*o
= _sv_obj(0);
147 sv_scale_free(o
->scale
); // always a deep copy we own
149 o
->scale
= (sv_scale_t
*)sv_scale_copy(scale
);
156 // XXXX need to recompute after
157 // XXXX need to add scale cloning to compute to make this safe in callbacks
158 int sv_obj_make_scale(char *format
){
159 sv_obj_t
*o
= _sv_obj(0);
163 char *name
=_sv_tokenize_escape(o
->name
);
164 char *label
=_sv_tokenize_escape(o
->legend
);
165 char *arg
=calloc(strlen(name
)+strlen(label
)+2,sizeof(*arg
));
177 scale
= sv_scale_new(arg
,format
);
179 if(!scale
)return errno
;
185 sv_obj_t
*_sv_obj(char *name
){
188 if(name
== NULL
|| name
== 0 || !strcmp(name
,"")){
189 return (sv_obj_t
*)pthread_getspecific(_sv_obj_key
);
192 for(i
=0;i
<_sv_objectives
;i
++){
193 sv_obj_t
*o
=_sv_objective_list
[i
];
194 if(o
&& o
->name
&& !strcmp(name
,o
->name
)){
195 pthread_setspecific(_sv_obj_key
, (void *)o
);
202 int sv_obj(char *name
){
203 sv_obj_t
*o
= _sv_obj(name
);