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
;
31 static char *objective_axismap
[]={
35 #define map_axes ((int)sizeof(objective_axismap)/(int)sizeof(*objective_axismap))
37 int sv_obj_new(char *name
,
38 void(*function
)(double *,double *),
45 _sv_token
*decl
= _sv_tokenize_declparam(name
);
46 _sv_tokenlist
*in
= NULL
;
47 _sv_tokenlist
*out
= NULL
;
50 fprintf(stderr
,"sushivision: Unable to parse objective declaration \"%s\".\n",name
);
54 if(_sv_objectives
== 0){
56 _sv_objective_list
= calloc (number
+1,sizeof(*_sv_objective_list
));
59 for(number
=0;number
<_sv_objectives
;number
++)
60 if(!_sv_objective_list
[number
])break;
61 if(number
==_sv_objectives
){
62 _sv_objectives
=number
+1;
63 _sv_objective_list
= realloc (_sv_objective_list
,_sv_objectives
* sizeof(*_sv_objective_list
));
67 o
= _sv_objective_list
[number
] = calloc(1, sizeof(**_sv_objective_list
));
68 o
->name
= strdup(decl
->name
);
69 o
->legend
= strdup(decl
->label
);
71 o
->function
= function
;
73 /* parse and sanity check the maps */
74 in
= _sv_tokenize_noparamlist(input_map
);
75 out
= _sv_tokenize_noparamlist(output_map
);
77 /* input dimensions */
79 fprintf(stderr
,"sushivision: Unable to parse objective \"%s\" dimenension list \"%s\".\n",
85 o
->input_dims
= calloc(in
->n
,sizeof(*o
->input_dims
));
87 sv_dim_t
*id
= sv_dim(in
->list
[i
]->name
);
89 fprintf(stderr
,"sushivision: Dimension \"%s\" does not exist in declaration of objective \"%s\".\n",
90 in
->list
[i
]->name
,o
->name
);
93 o
->input_dims
[i
] = id
;
98 o
->output_axes
= malloc(map_axes
* sizeof(*o
->output_axes
));
99 for(i
=0;i
<map_axes
;i
++)
100 o
->output_axes
[i
]=-1;
102 for(i
=0;i
<out
->n
;i
++){
103 char *s
= out
->list
[i
]->name
;
104 if(!s
|| !strcasecmp(s
,"*")){
105 // output unused by objective
108 for(j
=0;j
<map_axes
;j
++){
109 if(!strcasecmp(s
,objective_axismap
[j
])){
111 if(o
->output_axes
[j
] != -1){
112 fprintf(stderr
,"sushivision: Objective \"%s\" declares multiple %s axis outputs.\n",
113 o
->name
,objective_axismap
[j
]);
116 o
->output_axes
[j
] = i
;
120 fprintf(stderr
,"sushivision: No such output axis \"%s\" in declaration of objective \"%s\"\n",
126 pthread_setspecific(_sv_obj_key
, (void *)o
);
128 _sv_token_free(decl
);
129 _sv_tokenlist_free(in
);
130 _sv_tokenlist_free(out
);
140 // XXXX need to recompute after
141 // XXXX need to add scale cloning to compute to make this safe in callbacks
142 int sv_obj_set_scale(sv_scale_t
*scale
){
143 sv_obj_t
*o
= _sv_obj(0);
146 sv_scale_free(o
->scale
); // always a deep copy we own
148 o
->scale
= (sv_scale_t
*)sv_scale_copy(scale
);
155 // XXXX need to recompute after
156 // XXXX need to add scale cloning to compute to make this safe in callbacks
157 int sv_obj_make_scale(char *format
){
158 sv_obj_t
*o
= _sv_obj(0);
162 char *name
=_sv_tokenize_escape(o
->name
);
163 char *label
=_sv_tokenize_escape(o
->legend
);
164 char *arg
=calloc(strlen(name
)+strlen(label
)+2,sizeof(*arg
));
176 scale
= sv_scale_new(arg
,format
);
178 if(!scale
)return errno
;
184 sv_obj_t
*_sv_obj(char *name
){
187 if(name
== NULL
|| name
== 0 || !strcmp(name
,"")){
188 return (sv_obj_t
*)pthread_getspecific(_sv_obj_key
);
191 for(i
=0;i
<_sv_objectives
;i
++){
192 sv_obj_t
*o
=_sv_objective_list
[i
];
193 if(o
&& o
->name
&& !strcmp(name
,o
->name
)){
194 pthread_setspecific(_sv_obj_key
, (void *)o
);
201 int sv_obj(char *name
){
202 sv_obj_t
*o
= _sv_obj(name
);