summaryrefslogtreecommitdiff
path: root/apps/talk.c
diff options
context:
space:
mode:
authorStéphane Doyon <s.doyon@videotron.ca>2008-07-15 14:55:31 +0000
committerStéphane Doyon <s.doyon@videotron.ca>2008-07-15 14:55:31 +0000
commit3eb76d053db78be1f0b50f70134aa5a3b46ba77d (patch)
tree84caa006d3d69d97a665de17710c3c335bb3afd2 /apps/talk.c
parentd3cb2aca444ab7006dba9379ee0fff1195a7baff (diff)
downloadrockbox-3eb76d053db78be1f0b50f70134aa5a3b46ba77d.tar.gz
rockbox-3eb76d053db78be1f0b50f70134aa5a3b46ba77d.zip
talk.c helper functions to voice a filename, in a more generic way
than from tree.c Voice a file or dir's thumbnail from path components, or spell last path component. Ability to prefix the thumbnail or spelling with some talk ids. This is the talk_file patch from FS#6323, just refactored a bit. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18048 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/talk.c')
-rw-r--r--apps/talk.c110
1 files changed, 109 insertions, 1 deletions
diff --git a/apps/talk.c b/apps/talk.c
index f84ecd0ef5..601b7b4b88 100644
--- a/apps/talk.c
+++ b/apps/talk.c
@@ -655,7 +655,9 @@ void talk_force_enqueue_next(void)
655} 655}
656 656
657/* play a thumbnail from file */ 657/* play a thumbnail from file */
658int talk_file(const char* filename, bool enqueue) 658/* Returns size of spoken thumbnail, so >0 means something is spoken,
659 <=0 means something went wrong. */
660static int _talk_file(const char* filename, long *prefix_ids, bool enqueue)
659{ 661{
660 int fd; 662 int fd;
661 int size; 663 int size;
@@ -713,6 +715,11 @@ int talk_file(const char* filename, bool enqueue)
713#if CONFIG_CODEC != SWCODEC && !defined(SIMULATOR) 715#if CONFIG_CODEC != SWCODEC && !defined(SIMULATOR)
714 bitswap(p_thumbnail, size); 716 bitswap(p_thumbnail, size);
715#endif 717#endif
718 if(prefix_ids)
719 /* prefix thumbnail by speaking these ids, but only now
720 that we know there's actually a thumbnail to be
721 spoken. */
722 talk_idarray(prefix_ids, true);
716 talk_queue_lock(); 723 talk_queue_lock();
717 thumbnail_buf_used = thumb_used +size; 724 thumbnail_buf_used = thumb_used +size;
718 talk_queue_unlock(); 725 talk_queue_unlock();
@@ -722,6 +729,105 @@ int talk_file(const char* filename, bool enqueue)
722 return size; 729 return size;
723} 730}
724 731
732int
733talk_file(const char *root, const char *dir, const char *file,
734 const char *ext, long *prefix_ids, bool enqueue)
735/* Play a thumbnail file */
736{
737 char buf[MAX_PATH];
738 /* Does root end with a slash */
739 char *slash = (root && root[0]
740 && root[strlen(root)-1] != '/') ? "/" : "";
741 snprintf(buf, MAX_PATH, "%s%s%s%s%s%s",
742 root ? root : "", slash,
743 dir ? dir : "", dir ? "/" : "",
744 file ? file : "",
745 ext ? ext : "");
746 return _talk_file(buf, prefix_ids, enqueue);
747}
748
749static int
750talk_spell_basename(const char *path,
751 long *prefix_ids, bool enqueue)
752{
753 if(prefix_ids)
754 {
755 talk_idarray(prefix_ids, enqueue);
756 enqueue = true;
757 }
758 char buf[MAX_PATH];
759 /* Spell only the path component after the last slash */
760 strncpy(buf, path, MAX_PATH);
761 if(strlen(buf) >1 && buf[strlen(buf)-1] == '/')
762 /* strip trailing slash */
763 buf[strlen(buf)-1] = '\0';
764 char *ptr = strrchr(buf, '/');
765 if(ptr && strlen(buf) >1)
766 ++ptr;
767 else ptr = buf;
768 return talk_spell(ptr, enqueue);
769}
770
771/* Play a file's .talk thumbnail, fallback to spelling the filename, or
772 go straight to spelling depending on settings. */
773int talk_file_or_spell(const char *dirname, const char *filename,
774 long *prefix_ids, bool enqueue)
775{
776 if (global_settings.talk_file_clip)
777 { /* .talk clips enabled */
778 if(talk_file(dirname, NULL, filename, file_thumbnail_ext,
779 prefix_ids, enqueue) >0)
780 return 0;
781 }
782 if (global_settings.talk_file == 2)
783 /* Either .talk clips are disabled, or as a fallback */
784 return talk_spell_basename(filename, prefix_ids, enqueue);
785 return 0;
786}
787
788/* Play a directory's .talk thumbnail, fallback to spelling the filename, or
789 go straight to spelling depending on settings. */
790int talk_dir_or_spell(const char* dirname,
791 long *prefix_ids, bool enqueue)
792{
793 if (global_settings.talk_dir_clip)
794 { /* .talk clips enabled */
795 if(talk_file(dirname, NULL, dir_thumbnail_name, NULL,
796 prefix_ids, enqueue) >0)
797 return 0;
798 }
799 if (global_settings.talk_dir == 2)
800 /* Either .talk clips disabled or as a fallback */
801 return talk_spell_basename(dirname, prefix_ids, enqueue);
802 return 0;
803}
804
805/* Speak thumbnail for each component of a full path, again falling
806 back or going straight to spelling depending on settings. */
807int talk_fullpath(const char* path, bool enqueue)
808{
809 if (!enqueue)
810 talk_shutup();
811 if(path[0] != '/')
812 /* path ought to start with /... */
813 return talk_spell(path, true);
814 talk_id(VOICE_CHAR_SLASH, true);
815 char buf[MAX_PATH];
816 strncpy(buf, path, MAX_PATH);
817 char *start = buf+1; /* start of current component */
818 char *ptr = strchr(start, '/'); /* end of current component */
819 while(ptr) { /* There are more slashes ahead */
820 /* temporarily poke a NULL at end of component to truncate string */
821 *ptr = '\0';
822 talk_dir_or_spell(buf, NULL, true);
823 *ptr = '/'; /* restore string */
824 talk_id(VOICE_CHAR_SLASH, true);
825 start = ptr+1; /* setup for next component */
826 ptr = strchr(start, '/');
827 }
828 /* no more slashes, final component is a filename */
829 return talk_file_or_spell(NULL, buf, NULL, true);
830}
725 831
726/* say a numeric value, this word ordering works for english, 832/* say a numeric value, this word ordering works for english,
727 but not necessarily for other languages (e.g. german) */ 833 but not necessarily for other languages (e.g. german) */
@@ -964,6 +1070,8 @@ int talk_spell(const char* spell, bool enqueue)
964 talk_id(VOICE_DOT, true); 1070 talk_id(VOICE_DOT, true);
965 else if (c == ' ') 1071 else if (c == ' ')
966 talk_id(VOICE_PAUSE, true); 1072 talk_id(VOICE_PAUSE, true);
1073 else if (c == '/')
1074 talk_id(VOICE_CHAR_SLASH, true);
967 } 1075 }
968 1076
969 return 0; 1077 return 0;