Audaspace: support the device list returned by the new audaspace library.

- use the device names returned from the library.
- system settings UI changed as new audaspace might contain longer and more device names.
This commit is contained in:
Joerg Mueller 2015-07-24 15:44:17 +02:00
parent a0cbebf404
commit 29ebb56f4d
6 changed files with 69 additions and 40 deletions

View 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")

View 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__ */

View 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)) {}

View 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 */

View 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);

View 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;
}