source: trunk/third/audiofile/libaudiofile/aupv.c @ 17099

Revision 17099, 5.5 KB checked in by ghudson, 23 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r17098, which included commits to RCS files with non-trunk default branches.
Line 
1/*
2        Audio File Library
3        Copyright (C) 1998-2000, Michael Pruett <michael@68k.org>
4
5        This library is free software; you can redistribute it and/or
6        modify it under the terms of the GNU Library General Public
7        License as published by the Free Software Foundation; either
8        version 2 of the License, or (at your option) any later version.
9
10        This library 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 GNU
13        Library General Public License for more details.
14
15        You should have received a copy of the GNU Library General Public
16        License along with this library; if not, write to the
17        Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18        Boston, MA  02111-1307  USA.
19*/
20
21/*
22        aupv.c
23
24        This file contains an implementation of SGI's Audio Library parameter
25        value list functions.
26*/
27
28#include <sys/types.h>
29#include <stdlib.h>
30#include <string.h>
31#include <assert.h>
32
33#include "aupvinternal.h"
34#include "aupvlist.h"
35
36AUpvlist AUpvnew (int maxitems)
37{
38        AUpvlist        aupvlist;
39        int             i;
40
41        if (maxitems <= 0)
42                return AU_NULL_PVLIST;
43
44        aupvlist = (AUpvlist) malloc(sizeof (struct _AUpvlist));
45        assert(aupvlist);
46        if (aupvlist == NULL)
47                return AU_NULL_PVLIST;
48
49        aupvlist->items = calloc(maxitems, sizeof (struct _AUpvitem));
50
51        assert(aupvlist->items);
52        if (aupvlist->items == NULL)
53        {
54                free(aupvlist);
55                return AU_NULL_PVLIST;
56        }
57
58        /* Initialize the items in the list. */
59        for (i=0; i<maxitems; i++)
60        {
61                aupvlist->items[i].valid = _AU_VALID_PVITEM;
62                aupvlist->items[i].type = AU_PVTYPE_LONG;
63                aupvlist->items[i].parameter = 0;
64                memset(&aupvlist->items[i].value, 0, sizeof (aupvlist->items[i].value));
65        }
66
67        aupvlist->valid = _AU_VALID_PVLIST;
68        aupvlist->count = maxitems;
69
70        return aupvlist;
71}
72
73int AUpvgetmaxitems (AUpvlist list)
74{
75        assert(list);
76
77        if (list == AU_NULL_PVLIST)
78                return AU_BAD_PVLIST;
79        if (list->valid != _AU_VALID_PVLIST)
80                return AU_BAD_PVLIST;
81
82        return list->count;
83}
84
85int AUpvfree (AUpvlist list)
86{
87        assert(list);
88        assert(list->items);
89
90        if (list == AU_NULL_PVLIST)
91                return AU_BAD_PVLIST;
92        if (list->valid != _AU_VALID_PVLIST)
93                return AU_BAD_PVLIST;
94
95        if ((list->items != _AU_NULL_PVITEM) &&
96                (list->items[0].valid == _AU_VALID_PVITEM))
97        {
98                free(list->items);
99        }
100
101        free(list);
102
103        return _AU_SUCCESS;
104}
105
106int AUpvsetparam (AUpvlist list, int item, int param)
107{
108        assert(list);
109        assert(list->items);
110        assert(item >= 0);
111        assert(item < list->count);
112
113        if (list == AU_NULL_PVLIST)
114                return AU_BAD_PVLIST;
115        if (list->valid != _AU_VALID_PVLIST)
116                return AU_BAD_PVLIST;
117        if ((item < 0) || (item > list->count - 1))
118                return AU_BAD_PVITEM;
119        if (list->items[item].valid != _AU_VALID_PVITEM)
120                return AU_BAD_PVLIST;
121
122        list->items[item].parameter = param;
123        return _AU_SUCCESS;
124}
125
126int AUpvsetvaltype (AUpvlist list, int item, int type)
127{
128        assert(list);
129        assert(list->items);
130        assert(item >= 0);
131        assert(item < list->count);
132
133        if (list == AU_NULL_PVLIST)
134                return AU_BAD_PVLIST;
135        if (list->valid != _AU_VALID_PVLIST)
136                return AU_BAD_PVLIST;
137        if ((item < 0) || (item > list->count - 1))
138                return AU_BAD_PVITEM;
139        if (list->items[item].valid != _AU_VALID_PVITEM)
140                return AU_BAD_PVLIST;
141
142        list->items[item].type = type;
143        return _AU_SUCCESS;
144}
145
146int AUpvsetval (AUpvlist list, int item, void *val)
147{
148        assert(list);
149        assert(list->items);
150        assert(item >= 0);
151        assert(item < list->count);
152
153        if (list == AU_NULL_PVLIST)
154                return AU_BAD_PVLIST;
155        if (list->valid != _AU_VALID_PVLIST)
156                return AU_BAD_PVLIST;
157        if ((item < 0) || (item > list->count - 1))
158                return AU_BAD_PVITEM;
159        if (list->items[item].valid != _AU_VALID_PVITEM)
160                return AU_BAD_PVLIST;
161
162        switch (list->items[item].type)
163        {
164                case AU_PVTYPE_LONG:
165                        list->items[item].value.l = *((long *) val);
166                        break;
167                case AU_PVTYPE_DOUBLE:
168                        list->items[item].value.d = *((double *) val);
169                        break;
170                case AU_PVTYPE_PTR:
171                        list->items[item].value.v = *((void **) val);
172                        break;
173                default:
174                        assert(0);
175                        return AU_BAD_PVLIST;
176        }
177
178        return _AU_SUCCESS;
179}
180
181int AUpvgetparam (AUpvlist list, int item, int *param)
182{
183        assert(list);
184        assert(list->items);
185        assert(item >= 0);
186        assert(item < list->count);
187
188        if (list == AU_NULL_PVLIST)
189                return AU_BAD_PVLIST;
190        if (list->valid != _AU_VALID_PVLIST)
191                return AU_BAD_PVLIST;
192        if ((item < 0) || (item > list->count - 1))
193                return AU_BAD_PVITEM;
194        if (list->items[item].valid != _AU_VALID_PVITEM)
195                return AU_BAD_PVLIST;
196
197        *param = list->items[item].parameter;
198        return _AU_SUCCESS;
199}
200
201int AUpvgetvaltype (AUpvlist list, int item, int *type)
202{
203        assert(list);
204        assert(list->items);
205        assert(item >= 0);
206        assert(item < list->count);
207
208        if (list == AU_NULL_PVLIST)
209                return AU_BAD_PVLIST;
210        if (list->valid != _AU_VALID_PVLIST)
211                return AU_BAD_PVLIST;
212        if ((item < 0) || (item > list->count - 1))
213                return AU_BAD_PVITEM;
214        if (list->items[item].valid != _AU_VALID_PVITEM)
215                return AU_BAD_PVLIST;
216
217        *type = list->items[item].type;
218        return _AU_SUCCESS;
219}
220
221int AUpvgetval (AUpvlist list, int item, void *val)
222{
223        assert(list);
224        assert(list->items);
225        assert(item >= 0);
226        assert(item < list->count);
227
228        if (list == AU_NULL_PVLIST)
229                return AU_BAD_PVLIST;
230        if (list->valid != _AU_VALID_PVLIST)
231                return AU_BAD_PVLIST;
232        if ((item < 0) || (item > list->count - 1))
233                return AU_BAD_PVITEM;
234        if (list->items[item].valid != _AU_VALID_PVITEM)
235                return AU_BAD_PVLIST;
236
237        switch (list->items[item].type)
238        {
239                case AU_PVTYPE_LONG:
240                        *((long *) val) = list->items[item].value.l;
241                        break;
242                case AU_PVTYPE_DOUBLE:
243                        *((double *) val) = list->items[item].value.d;
244                        break;
245                case AU_PVTYPE_PTR:
246                        *((void **) val) = list->items[item].value.v;
247                        break;
248        }
249
250        return _AU_SUCCESS;
251}
Note: See TracBrowser for help on using the repository browser.