Debian Codegraph @

test/query2.c

raw
1 /*
2 Audio File Library
3
4 Copyright 1998-2000, Michael Pruett <[email protected]>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24
25 #ifdef __USE_SGI_HEADERS__
26 #include <dmedia/audiofile.h>
27 #include <dmedia/audioutil.h>
28 #else
29 #include <audiofile.h>
30 #include <aupvlist.h>
31 #endif
32
33 #include <stdio.h>
34 #include <stdlib.h>
35
36 const char *paramtypename (int paramtype);
37 void printinstparams (int format);
38
39 #define DEBUG
40
41 #ifdef DEBUG
42 #define DEBG printf
43 #else
44 #define DEBG
45 #endif
46
47 int main (int ac, char **av)
48 {
49 AUpvlist formatlist;
50 int *flist;
51 long lvalue;
52 int i, formatcount;
53
54 formatlist = afQuery(AF_QUERYTYPE_FILEFMT, AF_QUERY_IDS, 0, 0, 0);
55 formatcount = afQueryLong(AF_QUERYTYPE_FILEFMT, AF_QUERY_ID_COUNT, 0, 0, 0);
56
57 DEBG("formatcount = %d\n", formatcount);
58
59 AUpvgetval(formatlist, 0, &flist);
60 AUpvfree(formatlist);
61
62 for (i=0; i<formatcount; i++)
63 {
64 int format;
65 char *formatstring;
66
67 format = flist[i];
68 DEBG("format = %d\n", format);
69 formatstring = afQueryPointer(AF_QUERYTYPE_FILEFMT, AF_QUERY_NAME,
70 format, 0, 0);
71 DEBG("format = %s\n", formatstring);
72
73 lvalue = afQueryLong(AF_QUERYTYPE_INST, AF_QUERY_SUPPORTED,
74 format, 0, 0);
75 DEBG("instrument query: supported: %ld\n", lvalue);
76
77 lvalue = afQueryLong(AF_QUERYTYPE_INST, AF_QUERY_MAX_NUMBER,
78 format, 0, 0);
79 DEBG("instrument query: maximum number: %ld\n", lvalue);
80
81 lvalue = afQueryLong(AF_QUERYTYPE_INSTPARAM, AF_QUERY_SUPPORTED,
82 format, 0, 0);
83 DEBG("instrument parameter query: supported: %ld\n", lvalue);
84
85 /*
86 Print instrument parameter information only if
87 instrument parameters are supported.
88 */
89 if (lvalue)
90 printinstparams(format);
91 }
92 free(flist);
93
94 return 0;
95 }
96
97 void printinstparams (int format)
98 {
99 int i, *iarray;
100 long instParamCount;
101
102 instParamCount = afQueryLong(AF_QUERYTYPE_INSTPARAM, AF_QUERY_ID_COUNT,
103 format, 0, 0);
104 DEBG("instrument parameter query: id count: %ld\n", instParamCount);
105
106 iarray = afQueryPointer(AF_QUERYTYPE_INSTPARAM, AF_QUERY_IDS,
107 format, 0, 0);
108
109 if (iarray == NULL)
110 printf("AF_QUERYTYPE_INSTPARAM failed for format %d\n", format);
111
112 for (i=0; i<instParamCount; i++)
113 {
114 int paramType;
115 AUpvlist defaultValue;
116
117 DEBG("instrument parameter query: id: %d\n", iarray[i]);
118 paramType = afQueryLong(AF_QUERYTYPE_INSTPARAM,
119 AF_QUERY_TYPE, format, iarray[i], 0);
120
121 DEBG("\ttype of parameter: %s\n", paramtypename(paramType));
122 DEBG("\tname of parameter: %s\n",
123 (char *) afQueryPointer(AF_QUERYTYPE_INSTPARAM,
124 AF_QUERY_NAME, format, iarray[i], 0));
125
126 defaultValue = afQuery(AF_QUERYTYPE_INSTPARAM, AF_QUERY_DEFAULT,
127 format, iarray[i], 0);
128
129 if (paramType == AU_PVTYPE_LONG)
130 {
131 long ldefault;
132 AUpvgetval(defaultValue, 0, &ldefault);
133 DEBG("\tdefault value: %ld\n", ldefault);
134 }
135 else if (paramType == AU_PVTYPE_DOUBLE)
136 {
137 double ddefault;
138 AUpvgetval(defaultValue, 0, &ddefault);
139 DEBG("\tdefault value: %f\n", ddefault);
140 }
141 else if (paramType == AU_PVTYPE_PTR)
142 {
143 void *vdefault;
144 AUpvgetval(defaultValue, 0, &vdefault);
145 DEBG("\tdefault value: %p\n", vdefault);
146 }
147
148 AUpvfree(defaultValue);
149 }
150
151 free(iarray);
152 }
153
154 const char *paramtypename (int paramtype)
155 {
156 static const char *longname = "long";
157 static const char *doublename = "double";
158 static const char *pointername = "pointer";
159
160 switch (paramtype)
161 {
162 case AU_PVTYPE_LONG:
163 return longname;
164 case AU_PVTYPE_DOUBLE:
165 return doublename;
166 case AU_PVTYPE_PTR:
167 return pointername;
168 }
169
170 return NULL;
171 }