move inbuilt_filetypes.voiceclip to a separate struct

there are a lot of duplicated voiceclips in the inbuilt_filetypes struct
its already looked up so deduplicate

Change-Id: I7846277d2da308f605d5564e9081d6077e697239
This commit is contained in:
William Wilgus 2022-11-21 22:46:19 -05:00 committed by William Wilgus
parent 2056878e46
commit efdc6feddb
3 changed files with 146 additions and 104 deletions

View file

@ -38,6 +38,7 @@
#include "splash.h" #include "splash.h"
#include "core_alloc.h" #include "core_alloc.h"
#include "icons.h" #include "icons.h"
/*#define LOGF_ENABLE*/
#include "logf.h" #include "logf.h"
/* max filetypes (plugins & icons stored here) */ /* max filetypes (plugins & icons stored here) */
@ -47,103 +48,136 @@
/* a table for the known file types */ /* a table for the known file types */
static const struct filetype inbuilt_filetypes[] = { static const struct filetype inbuilt_filetypes[] = {
{ "mp3", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "mp3", FILE_ATTR_AUDIO },
{ "mp2", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "mp2", FILE_ATTR_AUDIO },
{ "mpa", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "mpa", FILE_ATTR_AUDIO },
{ "mp1", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "mp1", FILE_ATTR_AUDIO },
{ "ogg", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "ogg", FILE_ATTR_AUDIO },
{ "oga", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "oga", FILE_ATTR_AUDIO },
{ "wma", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "wma", FILE_ATTR_AUDIO },
{ "wmv", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "wmv", FILE_ATTR_AUDIO },
{ "asf", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "asf", FILE_ATTR_AUDIO },
{ "wav", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "wav", FILE_ATTR_AUDIO },
{ "flac", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "flac", FILE_ATTR_AUDIO },
{ "ac3", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "ac3", FILE_ATTR_AUDIO },
{ "a52", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "a52", FILE_ATTR_AUDIO },
{ "mpc", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "mpc", FILE_ATTR_AUDIO },
{ "wv", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "wv", FILE_ATTR_AUDIO },
{ "m4a", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "m4a", FILE_ATTR_AUDIO },
{ "m4b", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "m4b", FILE_ATTR_AUDIO },
{ "mp4", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "mp4", FILE_ATTR_AUDIO },
{ "mod", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "mod", FILE_ATTR_AUDIO },
{ "mpga", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "mpga", FILE_ATTR_AUDIO },
{ "shn", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "shn", FILE_ATTR_AUDIO },
{ "aif", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "aif", FILE_ATTR_AUDIO },
{ "aiff", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "aiff", FILE_ATTR_AUDIO },
{ "spx" , FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "spx" , FILE_ATTR_AUDIO },
{ "opus", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "opus", FILE_ATTR_AUDIO },
{ "sid", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "sid", FILE_ATTR_AUDIO },
{ "adx", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "adx", FILE_ATTR_AUDIO },
{ "nsf", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "nsf", FILE_ATTR_AUDIO },
{ "nsfe", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "nsfe", FILE_ATTR_AUDIO },
{ "spc", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "spc", FILE_ATTR_AUDIO },
{ "ape", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "ape", FILE_ATTR_AUDIO },
{ "mac", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "mac", FILE_ATTR_AUDIO },
{ "sap" , FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "sap" , FILE_ATTR_AUDIO },
{ "rm", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "rm", FILE_ATTR_AUDIO },
{ "ra", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "ra", FILE_ATTR_AUDIO },
{ "rmvb", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "rmvb", FILE_ATTR_AUDIO },
{ "cmc", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "cmc", FILE_ATTR_AUDIO },
{ "cm3", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "cm3", FILE_ATTR_AUDIO },
{ "cmr", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "cmr", FILE_ATTR_AUDIO },
{ "cms", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "cms", FILE_ATTR_AUDIO },
{ "dmc", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "dmc", FILE_ATTR_AUDIO },
{ "dlt", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "dlt", FILE_ATTR_AUDIO },
{ "mpt", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "mpt", FILE_ATTR_AUDIO },
{ "mpd", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "mpd", FILE_ATTR_AUDIO },
{ "rmt", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "rmt", FILE_ATTR_AUDIO },
{ "tmc", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "tmc", FILE_ATTR_AUDIO },
{ "tm8", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "tm8", FILE_ATTR_AUDIO },
{ "tm2", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "tm2", FILE_ATTR_AUDIO },
{ "oma", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "oma", FILE_ATTR_AUDIO },
{ "aa3", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "aa3", FILE_ATTR_AUDIO },
{ "at3", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "at3", FILE_ATTR_AUDIO },
{ "mmf", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "mmf", FILE_ATTR_AUDIO },
{ "au", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "au", FILE_ATTR_AUDIO },
{ "snd", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "snd", FILE_ATTR_AUDIO },
{ "vox", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "vox", FILE_ATTR_AUDIO },
{ "w64", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "w64", FILE_ATTR_AUDIO },
{ "tta", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "tta", FILE_ATTR_AUDIO },
{ "ay", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "ay", FILE_ATTR_AUDIO },
{ "vtx", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "vtx", FILE_ATTR_AUDIO },
{ "gbs", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "gbs", FILE_ATTR_AUDIO },
{ "hes", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "hes", FILE_ATTR_AUDIO },
{ "sgc", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "sgc", FILE_ATTR_AUDIO },
{ "vgm", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "vgm", FILE_ATTR_AUDIO },
{ "vgz", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "vgz", FILE_ATTR_AUDIO },
{ "kss", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "kss", FILE_ATTR_AUDIO },
{ "aac", FILE_ATTR_AUDIO, VOICE_EXT_MPA }, { "aac", FILE_ATTR_AUDIO },
{ "m3u", FILE_ATTR_M3U, LANG_PLAYLIST }, { "m3u", FILE_ATTR_M3U },
{ "m3u8", FILE_ATTR_M3U, LANG_PLAYLIST }, { "m3u8", FILE_ATTR_M3U },
{ "cfg", FILE_ATTR_CFG, VOICE_EXT_CFG }, { "cfg", FILE_ATTR_CFG },
{ "wps", FILE_ATTR_WPS, VOICE_EXT_WPS }, { "wps", FILE_ATTR_WPS },
#ifdef HAVE_REMOTE_LCD #ifdef HAVE_REMOTE_LCD
{ "rwps", FILE_ATTR_RWPS, VOICE_EXT_RWPS }, { "rwps", FILE_ATTR_RWPS },
#endif #endif
#if CONFIG_TUNER #if CONFIG_TUNER
{ "fmr", FILE_ATTR_FMR, LANG_FMR }, { "fmr", FILE_ATTR_FMR },
{ "fms", FILE_ATTR_FMS, VOICE_EXT_FMS }, { "fms", FILE_ATTR_FMS },
#endif #endif
{ "lng", FILE_ATTR_LNG, LANG_LANGUAGE }, { "lng", FILE_ATTR_LNG },
{ "rock", FILE_ATTR_ROCK, VOICE_EXT_ROCK }, { "rock", FILE_ATTR_ROCK },
{ "lua", FILE_ATTR_LUA, VOICE_EXT_ROCK }, { "lua", FILE_ATTR_LUA },
{ "opx", FILE_ATTR_OPX, VOICE_EXT_ROCK }, { "opx", FILE_ATTR_OPX },
{ "fnt", FILE_ATTR_FONT, VOICE_EXT_FONT }, { "fnt", FILE_ATTR_FONT },
{ "kbd", FILE_ATTR_KBD, VOICE_EXT_KBD }, { "kbd", FILE_ATTR_KBD },
{ "bmark",FILE_ATTR_BMARK, VOICE_EXT_BMARK }, { "bmark",FILE_ATTR_BMARK },
{ "cue", FILE_ATTR_CUE, VOICE_EXT_CUESHEET }, { "cue", FILE_ATTR_CUE },
{ "sbs", FILE_ATTR_SBS, VOICE_EXT_SBS }, { "sbs", FILE_ATTR_SBS },
#ifdef HAVE_REMOTE_LCD #ifdef HAVE_REMOTE_LCD
{ "rsbs", FILE_ATTR_RSBS, VOICE_EXT_RSBS }, { "rsbs", FILE_ATTR_RSBS },
#if CONFIG_TUNER #if CONFIG_TUNER
{ "rfms", FILE_ATTR_RFMS, VOICE_EXT_RFMS }, { "rfms", FILE_ATTR_RFMS },
#endif #endif
#endif #endif
#ifdef BOOTFILE_EXT #ifdef BOOTFILE_EXT
{ BOOTFILE_EXT, FILE_ATTR_MOD, VOICE_EXT_AJZ }, { BOOTFILE_EXT, FILE_ATTR_MOD },
#endif #endif
#ifdef BOOTFILE_EXT2 #ifdef BOOTFILE_EXT2
{ BOOTFILE_EXT2, FILE_ATTR_MOD, VOICE_EXT_AJZ }, { BOOTFILE_EXT2, FILE_ATTR_MOD },
#endif
};
/* a table for the known file types voice clips */
static const struct fileattr_voice inbuilt_attrvoices[] = {
{ FILE_ATTR_AUDIO, VOICE_EXT_MPA },
{ FILE_ATTR_M3U, LANG_PLAYLIST },
{ FILE_ATTR_CFG, VOICE_EXT_CFG },
{ FILE_ATTR_WPS, VOICE_EXT_WPS },
#ifdef HAVE_REMOTE_LCD
{ FILE_ATTR_RWPS, VOICE_EXT_RWPS },
#endif
#if CONFIG_TUNER
{ FILE_ATTR_FMR, LANG_FMR },
{ FILE_ATTR_FMS, VOICE_EXT_FMS },
#endif
{ FILE_ATTR_LNG, LANG_LANGUAGE },
{ FILE_ATTR_ROCK, VOICE_EXT_ROCK },
{ FILE_ATTR_LUA, VOICE_EXT_ROCK },
{ FILE_ATTR_OPX, VOICE_EXT_ROCK },
{ FILE_ATTR_FONT, VOICE_EXT_FONT },
{ FILE_ATTR_KBD, VOICE_EXT_KBD },
{ FILE_ATTR_BMARK, VOICE_EXT_BMARK },
{ FILE_ATTR_CUE, VOICE_EXT_CUESHEET },
{ FILE_ATTR_SBS, VOICE_EXT_SBS },
#ifdef HAVE_REMOTE_LCD
{ FILE_ATTR_RSBS, VOICE_EXT_RSBS },
#if CONFIG_TUNER
{ FILE_ATTR_RFMS, VOICE_EXT_RFMS },
#endif
#endif
#if defined(BOOTFILE_EXT) || defined(BOOTFILE_EXT2)
{ FILE_ATTR_MOD, VOICE_EXT_AJZ },
#endif #endif
}; };
@ -191,6 +225,25 @@ void tree_get_filetypes(const struct filetype** types, int* count)
*count = sizeof(inbuilt_filetypes) / sizeof(*inbuilt_filetypes); *count = sizeof(inbuilt_filetypes) / sizeof(*inbuilt_filetypes);
} }
long tree_filetype_voiceclip(int attr)
{
logf("%s attr %d", __func__, attr);
int j;
if (global_settings.talk_filetype)
{
int count = sizeof(inbuilt_attrvoices)/sizeof(*inbuilt_attrvoices);
/* try to find a voice ID for the extension, if known */
//attr &= FILE_ATTR_MASK; /* file type */
for (j=0; j<count; j++)
if (attr == inbuilt_attrvoices[j].tree_attr)
{
logf("%s attr %d id %d", __func__, attr, inbuilt_attrvoices[j].voiceclip);
return inbuilt_attrvoices[j].voiceclip;
}
}
return -1;
}
#define ROCK_EXTENSION "rock" #define ROCK_EXTENSION "rock"
struct file_type { struct file_type {

View file

@ -53,10 +53,15 @@
struct filetype { struct filetype {
char* extension; char* extension;
int tree_attr; int tree_attr;
};
struct fileattr_voice {
int tree_attr;
int voiceclip; int voiceclip;
}; };
void tree_get_filetypes(const struct filetype**, int*) INIT_ATTR; void tree_get_filetypes(const struct filetype**, int*) INIT_ATTR;
long tree_filetype_voiceclip(int attr) INIT_ATTR;
/* init the filetypes structs. /* init the filetypes structs.
uses audio buffer for storage, so call early in init... */ uses audio buffer for storage, so call early in init... */

View file

@ -1179,25 +1179,9 @@ bool bookmark_play(char *resume_file, int index, unsigned long elapsed,
return started; return started;
} }
static long filetype_voiceclip(int attr)
{
int j;
if (global_settings.talk_filetype)
{
/* try to find a voice ID for the extension, if known */
attr &= FILE_ATTR_MASK; /* file type */
for (j=0; j<filetypes_count; j++)
if (attr == filetypes[j].tree_attr)
{
return filetypes[j].voiceclip;
}
}
return -1;
}
static void say_filetype(int attr) static void say_filetype(int attr)
{ {
talk_id(filetype_voiceclip(attr), true); talk_id(tree_filetype_voiceclip(attr), true);
} }
static int ft_play_dirname(char* name) static int ft_play_dirname(char* name)
@ -1215,7 +1199,7 @@ static int ft_play_filename(char *dir, char *file, int attr)
file_thumbnail_ext)) file_thumbnail_ext))
/* file has no .talk extension */ /* file has no .talk extension */
return talk_file(dir, NULL, file, file_thumbnail_ext, return talk_file(dir, NULL, file, file_thumbnail_ext,
TALK_IDARRAY(filetype_voiceclip(attr)), false); TALK_IDARRAY(tree_filetype_voiceclip(attr)), false);
/* it already is a .talk file, play this directly, but prefix it. */ /* it already is a .talk file, play this directly, but prefix it. */
return talk_file(dir, NULL, file, NULL, return talk_file(dir, NULL, file, NULL,