]> granicus.if.org Git - python/commitdiff
Add build_namelists() to expose the OSS macros SOUND_DEVICE_LABELS and
authorGreg Ward <gward@python.net>
Tue, 31 Dec 2002 03:23:59 +0000 (03:23 +0000)
committerGreg Ward <gward@python.net>
Tue, 31 Dec 2002 03:23:59 +0000 (03:23 +0000)
SOUND_DEVICE_NAMES as 'control_labels' and 'control_names'.

Modules/ossaudiodev.c

index caa5a9f8a4cef3f9e7d525aecfca540353a9f854..9bfd55e78cfd6018d9c63353d6b829ef482dcaa0 100644 (file)
@@ -894,6 +894,46 @@ static PyMethodDef ossaudiodev_methods[] = {
 #define _EXPORT_INT(mod, name) \
   if (PyModule_AddIntConstant(mod, #name, (long) (name)) == -1) return;
 
+
+static char *control_labels[] = SOUND_DEVICE_LABELS;
+static char *control_names[] = SOUND_DEVICE_NAMES;
+
+
+static int
+build_namelists (PyObject *module)
+{
+    PyObject *labels;
+    PyObject *names;
+    PyObject *s;
+    int num_controls;
+    int i;
+
+    num_controls = sizeof(control_labels) / sizeof(control_labels[0]);
+    assert(num_controls == sizeof(control_names) / sizeof(control_names[0]));
+
+    labels = PyList_New(num_controls);
+    names = PyList_New(num_controls);
+    for (i = 0; i < num_controls; i++) {
+        s = PyString_FromString(control_labels[i]);
+        if (s == NULL)
+            return -1;
+        PyList_SET_ITEM(labels, i, s);
+   
+        s = PyString_FromString(control_names[i]);
+        if (s == NULL)
+            return -1;
+        PyList_SET_ITEM(names, i, s);
+    }
+
+    if (PyModule_AddObject(module, "control_labels", labels) == -1)
+        return -1;
+    if (PyModule_AddObject(module, "control_names", names) == -1)
+        return -1;
+
+    return 0;
+}   
+
+
 void
 initossaudiodev(void)
 {
@@ -905,6 +945,11 @@ initossaudiodev(void)
     if (OSSAudioError)
         PyModule_AddObject(m, "error", OSSAudioError);
 
+    /* Build 'control_labels' and 'control_names' lists and add them
+       to the module. */
+    if (build_namelists(m) == -1)       /* XXX what to do here? */
+        return;
+
     /* Expose the audio format numbers -- essential! */
     _EXPORT_INT(m, AFMT_QUERY);
     _EXPORT_INT(m, AFMT_MU_LAW);