comparison src/vorbis/vorbis.c @ 1433:d557d987e42d

vorbis: new tuple API
author William Pitcock <nenolod@atheme-project.org>
date Fri, 10 Aug 2007 08:19:40 -0500
parents 59f2c23810bc
children 195b5657303e
comparison
equal deleted inserted replaced
1429:b274ac478607 1433:d557d987e42d
54 54
55 #include "audacious/plugin.h" 55 #include "audacious/plugin.h"
56 #include "audacious/output.h" 56 #include "audacious/output.h"
57 #include "audacious/util.h" 57 #include "audacious/util.h"
58 #include "audacious/configdb.h" 58 #include "audacious/configdb.h"
59 #include "audacious/titlestring.h" 59 #include "audacious/main.h"
60 #include <audacious/i18n.h> 60 #include <audacious/i18n.h>
61 #include <audacious/strings.h> 61 #include <audacious/strings.h>
62 62
63 #include "vorbis.h" 63 #include "vorbis.h"
64 64
65 extern vorbis_config_t vorbis_cfg; 65 extern vorbis_config_t vorbis_cfg;
66 66
67 static TitleInput *get_song_tuple(gchar *filename); 67 static Tuple *get_song_tuple(gchar *filename);
68 static int vorbis_check_file(char *filename); 68 static int vorbis_check_file(char *filename);
69 static int vorbis_check_fd(char *filename, VFSFile *stream); 69 static int vorbis_check_fd(char *filename, VFSFile *stream);
70 static void vorbis_play(InputPlayback *data); 70 static void vorbis_play(InputPlayback *data);
71 static void vorbis_stop(InputPlayback *data); 71 static void vorbis_stop(InputPlayback *data);
72 static void vorbis_pause(InputPlayback *data, short p); 72 static void vorbis_pause(InputPlayback *data, short p);
602 } 602 }
603 603
604 static void 604 static void
605 vorbis_get_song_info(char *filename, char **title, int *length) 605 vorbis_get_song_info(char *filename, char **title, int *length)
606 { 606 {
607 TitleInput *tuple = get_song_tuple(filename); 607 Tuple *tuple = get_song_tuple(filename);
608 608
609 *length = tuple->length; 609 *length = tuple_get_int(tuple, "length");
610 *title = xmms_get_titlestring(vorbis_cfg.tag_override ? 610 *title = tuple_formatter_process_string(tuple, vorbis_cfg.tag_override ?
611 vorbis_cfg.tag_format : 611 vorbis_cfg.tag_format : cfg.gentitle_format);
612 xmms_get_gentitle_format(), 612
613 tuple); 613 mowgli_object_unref(tuple);
614
615 bmp_title_input_free(tuple);
616 } 614 }
617 615
618 static const gchar * 616 static const gchar *
619 get_extension(const gchar * filename) 617 get_extension(const gchar * filename)
620 { 618 {
729 } 727 }
730 728
731 return 2 * ch * samples; 729 return 2 * ch * samples;
732 } 730 }
733 731
732 static void _tuple_associate_string(Tuple *tuple, const gchar *field, const gchar *string)
733 {
734 gchar *str = str_to_utf8(string);
735
736 tuple_associate_string(tuple, field, str);
737
738 g_free(str);
739 }
740
734 /* 741 /*
735 * Ok, nhjm449! Are you *happy* now?! -nenolod 742 * Ok, nhjm449! Are you *happy* now?! -nenolod
736 */ 743 */
737 static TitleInput * 744 static Tuple *
738 get_tuple_for_vorbisfile(OggVorbis_File * vorbisfile, gchar *filename, gboolean is_stream) 745 get_tuple_for_vorbisfile(OggVorbis_File * vorbisfile, gchar *filename, gboolean is_stream)
739 { 746 {
740 TitleInput *tuple = NULL; 747 Tuple *tuple = NULL;
741 vorbis_comment *comment; 748 vorbis_comment *comment;
742 gchar *realfn = NULL; 749 gchar *realfn = NULL;
743 tuple = bmp_title_input_new(); 750 tuple = tuple_new_from_filename(filename);
744
745 realfn = g_filename_from_uri(filename, NULL, NULL);
746 tuple->file_name = g_path_get_basename(realfn ? realfn : filename);
747 tuple->file_ext = get_extension(realfn ? realfn : filename);
748 tuple->file_path = g_path_get_dirname(realfn ? realfn : filename);
749 g_free(realfn); realfn = NULL;
750 751
751 /* Retrieve the length */ 752 /* Retrieve the length */
752 if (is_stream == FALSE) 753 if (is_stream == FALSE)
753 tuple->length = ov_time_total(vorbisfile, -1) * 1000; 754 tuple_associate_int(tuple, "length", ov_time_total(vorbisfile, -1) * 1000);
754 else 755 else
755 tuple->length = -1; 756 tuple_associate_int(tuple, "length", -1);
756 757
757 if ((comment = ov_comment(vorbisfile, -1))) { 758 if ((comment = ov_comment(vorbisfile, -1))) {
758 tuple->track_name = 759 _tuple_associate_string(tuple, "title", vorbis_comment_query(comment, "title", 0));
759 str_to_utf8(vorbis_comment_query(comment, "title", 0)); 760 _tuple_associate_string(tuple, "artist", vorbis_comment_query(comment, "artist", 0));
760 tuple->performer = 761 _tuple_associate_string(tuple, "album", vorbis_comment_query(comment, "album", 0));
761 str_to_utf8(vorbis_comment_query(comment, "artist", 0)); 762 _tuple_associate_string(tuple, "date", vorbis_comment_query(comment, "date", 0));
762 tuple->album_name = 763 _tuple_associate_string(tuple, "genre", vorbis_comment_query(comment, "genre", 0));
763 str_to_utf8(vorbis_comment_query(comment, "album", 0)); 764 _tuple_associate_string(tuple, "comment", vorbis_comment_query(comment, "comment", 0));
764 765
765 if (vorbis_comment_query(comment, "tracknumber", 0) != NULL) 766 if (vorbis_comment_query(comment, "tracknumber", 0) != NULL)
766 tuple->track_number = 767 tuple_associate_int(tuple, "track-number",
767 atoi(vorbis_comment_query(comment, "tracknumber", 0)); 768 atoi(vorbis_comment_query(comment, "tracknumber", 0)));
768 769
769 tuple->date = str_to_utf8(vorbis_comment_query(comment, "date", 0)); 770 tuple_associate_string(tuple, "quality", "lossy");
770 tuple->genre = str_to_utf8(vorbis_comment_query(comment, "genre", 0)); 771 if (comment && comment->vendor)
771 tuple->comment = 772 {
772 str_to_utf8(vorbis_comment_query(comment, "comment", 0)); 773 gchar *codec = g_strdup_printf("Ogg Vorbis [%s]", comment->vendor);
773 774 tuple_associate_string(tuple, "codec", codec);
774 /* remove any blank tags */ 775 g_free(codec);
775 REMOVE_NONEXISTANT_TAG(tuple->performer); 776 }
776 REMOVE_NONEXISTANT_TAG(tuple->album_name); 777 else
777 REMOVE_NONEXISTANT_TAG(tuple->track_name); 778 tuple_associate_string(tuple, "codec", "Ogg Vorbis");
778 REMOVE_NONEXISTANT_TAG(tuple->genre);
779 REMOVE_NONEXISTANT_TAG(tuple->comment);
780 } 779 }
781 780
782 return tuple; 781 return tuple;
783 } 782 }
784 783
785 static TitleInput * 784 static Tuple *
786 get_song_tuple(gchar *filename) 785 get_song_tuple(gchar *filename)
787 { 786 {
788 VFSFile *stream = NULL; 787 VFSFile *stream = NULL;
789 OggVorbis_File vfile; /* avoid thread interaction */ 788 OggVorbis_File vfile; /* avoid thread interaction */
790 TitleInput *tuple = NULL; 789 Tuple *tuple = NULL;
791 gboolean is_stream = FALSE; 790 gboolean is_stream = FALSE;
792 VFSVorbisFile *fd = NULL; 791 VFSVorbisFile *fd = NULL;
793 792
794 if ((stream = vfs_fopen(filename, "r")) == NULL) 793 if ((stream = vfs_fopen(filename, "r")) == NULL)
795 return NULL; 794 return NULL;
822 static gchar * 821 static gchar *
823 vorbis_generate_title(OggVorbis_File * vorbisfile, gchar * filename) 822 vorbis_generate_title(OggVorbis_File * vorbisfile, gchar * filename)
824 { 823 {
825 /* Caller should hold vf_mutex */ 824 /* Caller should hold vf_mutex */
826 gchar *displaytitle = NULL; 825 gchar *displaytitle = NULL;
827 TitleInput *input; 826 Tuple *input;
828 gchar *tmp; 827 gchar *tmp;
829 828
830 input = get_tuple_for_vorbisfile(vorbisfile, filename, vorbis_is_streaming); 829 input = get_tuple_for_vorbisfile(vorbisfile, filename, vorbis_is_streaming);
831 830
832 if (!(displaytitle = xmms_get_titlestring(vorbis_cfg.tag_override ? 831 displaytitle = tuple_formatter_process_string(input, vorbis_cfg.tag_override ?
833 vorbis_cfg.tag_format : 832 vorbis_cfg.tag_format : cfg.gentitle_format);
834 xmms_get_gentitle_format(),
835 input))) {
836 displaytitle = g_strdup(input->file_name);
837 }
838 833
839 if ((tmp = vfs_get_metadata(((VFSVorbisFile *) vorbisfile->datasource)->fd, "stream-name")) != NULL) 834 if ((tmp = vfs_get_metadata(((VFSVorbisFile *) vorbisfile->datasource)->fd, "stream-name")) != NULL)
840 { 835 {
841 gchar *old = displaytitle; 836 gchar *old = displaytitle;
842 displaytitle = g_strdup_printf("%s (%s)", displaytitle, tmp); 837
838 tuple_associate_string(input, "stream", tmp);
839 tuple_associate_string(input, "title", old);
840
841 displaytitle = tuple_formatter_process_string(input, "${?title:${title}}${?stream: (${stream})}");
843 842
844 g_free(old); 843 g_free(old);
845 g_free(tmp); 844 g_free(tmp);
846 } 845 }
847 846
848 bmp_title_input_free(input); 847 mowgli_object_unref(input);
849 848
850 return displaytitle; 849 return displaytitle;
851 } 850 }
852 851
853 static void 852 static void
854 vorbis_aboutbox() 853 vorbis_aboutbox(void)
855 { 854 {
856 static GtkWidget *about_window; 855 static GtkWidget *about_window;
857 856
858 if (about_window) 857 if (about_window)
859 gdk_window_raise(about_window->window); 858 gdk_window_raise(about_window->window);