Audaspace: support the device list returned by the new audaspace library.
authorJörg Müller <nexyon@gmail.com>
Fri, 24 Jul 2015 13:44:17 +0000 (15:44 +0200)
committerJörg Müller <nexyon@gmail.com>
Tue, 28 Jul 2015 12:01:53 +0000 (14:01 +0200)
- use the device names returned from the library.
- system settings UI changed as new audaspace might contain longer and more device names.

release/scripts/startup/bl_ui/space_userpref.py
source/blender/blenkernel/BKE_sound.h
source/blender/blenkernel/intern/sound.c
source/blender/editors/interface/resources.c
source/blender/makesrna/intern/rna_userdef.c
source/creator/creator.c

index f53df6533e028479e9bf9fd791ae65397236bdb1..6be24a8d551a4f048962db751694c553866dbb36 100644 (file)
@@ -411,9 +411,9 @@ class USERPREF_PT_system(Panel):
         col.separator()
 
         col.label(text="Sound:")
-        col.row().prop(system, "audio_device", expand=True)
+        col.row().prop(system, "audio_device", expand=False)
         sub = col.column()
-        sub.active = system.audio_device != 'NONE'
+        sub.active = system.audio_device != 'NONE' and system.audio_device != 'Null'
         #sub.prop(system, "use_preview_images")
         sub.prop(system, "audio_channels", text="Channels")
         sub.prop(system, "audio_mixing_buffer", text="Mixing Buffer")
index fc543b887e41e94c114c0e58a482586d7ce62539..f221f588db3c21bf26b510ccda75cf3dc1fa4c21 100644 (file)
@@ -59,8 +59,7 @@ void BKE_sound_init_main(struct Main *bmain);
 
 void BKE_sound_exit(void);
 
-void BKE_sound_force_device(int device);
-int BKE_sound_define_from_str(const char *str);
+void BKE_sound_force_device(const char *device);
 
 struct bSound *BKE_sound_new_file(struct Main *main, const char *filename);
 
@@ -142,6 +141,8 @@ void *BKE_sound_get_factory(void *sound);
 
 float BKE_sound_get_length(struct bSound *sound);
 
+char** BKE_sound_get_device_names(void);
+
 bool BKE_sound_is_jack_supported(void);
 
 #endif  /* __BKE_SOUND_H__ */
index b81839f80fbae9f3bfe4fa5f5beb73e017a721fa..091498653e68cc049e6d63782aff8e454f1edac3 100644 (file)
@@ -66,8 +66,9 @@
 #include "BKE_scene.h"
 
 #ifdef WITH_AUDASPACE
-/* evil global ;-) */
+/* evil globals ;-) */
 static int sound_cfra;
+static char** audio_device_names = NULL;
 #endif
 
 bSound *BKE_sound_new_file(struct Main *bmain, const char *filename)
@@ -130,7 +131,7 @@ void BKE_sound_free(bSound *sound)
 
 #ifdef WITH_AUDASPACE
 
-static int force_device = -1;
+static const char* force_device = NULL;
 
 #ifdef WITH_JACK
 static void sound_sync_callback(void *data, int mode, float time)
@@ -153,21 +154,7 @@ static void sound_sync_callback(void *data, int mode, float time)
 }
 #endif
 
-int BKE_sound_define_from_str(const char *str)
-{
-       if (BLI_strcaseeq(str, "NULL"))
-               return 0;
-       if (BLI_strcaseeq(str, "SDL"))
-               return 1;
-       if (BLI_strcaseeq(str, "OPENAL"))
-               return 2;
-       if (BLI_strcaseeq(str, "JACK"))
-               return 3;
-
-       return -1;
-}
-
-void BKE_sound_force_device(int device)
+void BKE_sound_force_device(const char *device)
 {
        force_device = device;
 }
@@ -197,24 +184,19 @@ void BKE_sound_init(struct Main *bmain)
        specs.format = U.audioformat;
        specs.rate = U.audiorate;
 
-       if (force_device >= 0)
-               device = force_device;
-
-       switch(device)
+       if (force_device == NULL)
        {
-       case 1:
-               device_name = "SDL";
-               break;
-       case 2:
-               device_name = "OpenAL";
-               break;
-       case 3:
-               device_name = "Jack";
-               break;
-       default:
-               device_name = "Null";
-               break;
+               int i;
+               char** names = BKE_sound_get_device_names();
+               device_name = names[0];
+
+               // make sure device is within the bounds of the array
+               for(i = 0; names[i]; i++)
+                       if(i == device)
+                               device_name = names[i];
        }
+       else
+               device_name = force_device;
 
        if (buffersize < 128)
                buffersize = 1024;
@@ -254,6 +236,17 @@ void BKE_sound_exit_once(void)
        AUD_exit(sound_device);
        sound_device = NULL;
        AUD_exitOnce();
+
+#ifdef WITH_SYSTEM_AUDASPACE
+       if(audio_device_names != NULL)
+       {
+               int i;
+               for(i = 0; audio_device_names[i]; i++)
+                       free(audio_device_names[i]);
+               free(audio_device_names);
+               audio_device_names = NULL;
+       }
+#endif
 }
 
 /* XXX unused currently */
@@ -841,6 +834,23 @@ float BKE_sound_get_length(bSound *sound)
        return info.length;
 }
 
+char** BKE_sound_get_device_names(void)
+{
+       if(audio_device_names == NULL)
+       {
+#ifdef WITH_SYSTEM_AUDASPACE
+               audio_device_names = AUD_getDeviceNames();
+#else
+               static const char* names[] = {
+                       "Null", "SDL", "OpenAL", "Jack"
+               };
+               audio_device_names = (char**)names;
+#endif
+       }
+
+       return audio_device_names;
+}
+
 bool BKE_sound_is_jack_supported(void)
 {
 #ifdef WITH_SYSTEM_AUDASPACE
@@ -854,7 +864,6 @@ bool BKE_sound_is_jack_supported(void)
 
 #include "BLI_utildefines.h"
 
-int BKE_sound_define_from_str(const char *UNUSED(str)) { return -1; }
 void BKE_sound_force_device(int UNUSED(device)) {}
 void BKE_sound_init_once(void) {}
 void BKE_sound_init(struct Main *UNUSED(bmain)) {}
index e8311443123606b1864aa2d5c679fde92c70a69e..a7eb33561b4dc7f838c06c840d5951ef4d61985c 100644 (file)
@@ -2641,6 +2641,12 @@ void init_userdef_do_versions(void)
        if (U.image_draw_method == 0)
                U.image_draw_method = IMAGE_DRAW_METHOD_2DTEXTURE;
        
+       // keep the following until the new audaspace is default to be built with
+#ifdef WITH_SYSTEM_AUDASPACE
+       // we default to the first audio device
+       U.audiodevice = 0;
+#endif
+
        /* funny name, but it is GE stuff, moves userdef stuff to engine */
 // XXX space_set_commmandline_options();
        /* this timer uses U */
index b2af13aa106a4b6dbd7da3ea5dff02536d0f5fb1..1392009a30d03ffbf7980e1eeba0de084881fd18 100644 (file)
@@ -127,6 +127,7 @@ EnumPropertyItem navigation_mode_items[] = {
 #  include "sdlew.h"
 #endif
 
+
 static void rna_userdef_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *UNUSED(ptr))
 {
        WM_main_add_notifier(NC_WINDOW, NULL);
@@ -610,6 +611,17 @@ static EnumPropertyItem *rna_userdef_audio_device_itemf(bContext *UNUSED(C), Poi
        int totitem = 0;
        EnumPropertyItem *item = NULL;
 
+#ifdef WITH_SYSTEM_AUDASPACE
+       int i;
+
+       char** names = BKE_sound_get_device_names();
+
+       for(i = 0; names[i]; i++)
+       {
+               EnumPropertyItem new_item = {i, names[i], 0, names[i], names[i]};
+               RNA_enum_item_add(&item, &totitem, &new_item);
+       }
+#else
        /* NONE */
        RNA_enum_item_add(&item, &totitem, &audio_device_items[index++]);
 
@@ -632,6 +644,7 @@ static EnumPropertyItem *rna_userdef_audio_device_itemf(bContext *UNUSED(C), Poi
                RNA_enum_item_add(&item, &totitem, &audio_device_items[index]);
        }
        index++;
+#endif
 #endif
 
        RNA_enum_item_end(&item, &totitem);
index 37e767b2eb185f95bde3a16bb7b981993a34f6da..e1c777f8136767d6c0e1aadb391c07381563a09b 100644 (file)
@@ -824,7 +824,7 @@ static int no_glsl(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(dat
 
 static int no_audio(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
 {
-       BKE_sound_force_device(0);
+       BKE_sound_force_device("Null");
        return 0;
 }
 
@@ -835,7 +835,7 @@ static int set_audio(int argc, const char **argv, void *UNUSED(data))
                exit(1);
        }
 
-       BKE_sound_force_device(BKE_sound_define_from_str(argv[1]));
+       BKE_sound_force_device(argv[1]);
        return 1;
 }