comparison src/adplug/adplug-xmms.cc @ 1556:16b2bc9b9763

Add a tuple builder. With thanks to ccr for the fallback logic; I hate C++.
author Tony Vroon <chainsaw@gentoo.org>
date Sun, 02 Sep 2007 03:13:17 +0100
parents da1aa3c38cda
children 98c9257d0a80 d158ce84fda7
comparison
equal deleted inserted replaced
1555:c3b8dedeedc5 1556:16b2bc9b9763
29 #include <gtk/gtk.h> 29 #include <gtk/gtk.h>
30 #include "adplug.h" 30 #include "adplug.h"
31 #include "emuopl.h" 31 #include "emuopl.h"
32 #include "silentopl.h" 32 #include "silentopl.h"
33 #include "players.h" 33 #include "players.h"
34 #include "audacious/i18n.h"
35 extern "C"
36 {
37 #include "audacious/configdb.h"
34 #include "audacious/plugin.h" 38 #include "audacious/plugin.h"
39 #include "audacious/output.h"
35 #include "audacious/util.h" 40 #include "audacious/util.h"
36 #include "audacious/configdb.h"
37 #include <audacious/i18n.h>
38 extern "C"
39 {
40 #include "audacious/output.h"
41 } 41 }
42 42
43 43
44 /***** Defines *****/ 44 /***** Defines *****/
45 45
677 delete p; 677 delete p;
678 } 678 }
679 679
680 /***** Main player (!! threaded !!) *****/ 680 /***** Main player (!! threaded !!) *****/
681 681
682 static Tuple*
683 adplug_get_tuple (char *filename)
684 {
685 CSilentopl tmpopl;
686 VFSFile *fd = vfs_buffered_file_new_from_uri (filename);
687
688 if (!fd)
689 return NULL;
690
691 CPlayer *p = factory (fd, &tmpopl);
692
693 if (p)
694 {
695 Tuple *ti = tuple_new_from_filename(filename);
696 if (! p->getauthor().empty())
697 tuple_associate_string(ti, "artist", p->getauthor().c_str());
698 if (! p->gettitle().empty())
699 tuple_associate_string(ti, "title", p->gettitle().c_str());
700 else if (! p->getdesc().empty())
701 tuple_associate_string(ti, "title", p->getdesc().c_str());
702 else
703 tuple_associate_string(ti, "title", g_path_get_basename(filename));
704 tuple_associate_string(ti, "codec", p->gettype().c_str());
705 tuple_associate_string(ti, "quality", "sequenced");
706 tuple_associate_int(ti, "length", p->songlength (plr.subsong));
707 delete p;
708 return ti;
709 }
710
711 return NULL;
712 }
713
714 static char* format_and_free_ti( Tuple* ti, int* length )
715 {
716 char* result = tuple_formatter_make_title_string(ti, get_gentitle_format());
717 if ( result )
718 *length = tuple_get_int(ti, "length");
719 tuple_free((void *) ti);
720
721 return result;
722 }
723
682 static void 724 static void
683 update_infobox (void) 725 update_infobox (void)
684 { 726 {
685 std::ostringstream infotext; 727 std::ostringstream infotext;
686 728
709 char *filename = (char *) playback->filename; 751 char *filename = (char *) playback->filename;
710 dbg_printf ("play_loop(\"%s\"): ", filename); 752 dbg_printf ("play_loop(\"%s\"): ", filename);
711 CEmuopl opl (cfg.freq, cfg.bit16, cfg.stereo); 753 CEmuopl opl (cfg.freq, cfg.bit16, cfg.stereo);
712 long toadd = 0, i, towrite; 754 long toadd = 0, i, towrite;
713 char *sndbuf, *sndbufpos; 755 char *sndbuf, *sndbufpos;
756 int songlength;
714 bool playing = true, // Song self-end indicator. 757 bool playing = true, // Song self-end indicator.
715 bit16 = cfg.bit16, // Duplicate config, so it doesn't affect us if 758 bit16 = cfg.bit16, // Duplicate config, so it doesn't affect us if
716 stereo = cfg.stereo; // the user changes it while we're playing. 759 stereo = cfg.stereo; // the user changes it while we're playing.
717 unsigned long freq = cfg.freq; 760 unsigned long freq = cfg.freq;
718 761
735 // MessageBox("AdPlug :: Error", "File could not be opened!", "Ok"); 778 // MessageBox("AdPlug :: Error", "File could not be opened!", "Ok");
736 plr.playing = false; 779 plr.playing = false;
737 return (NULL); 780 return (NULL);
738 } 781 }
739 782
740 // Cache song length 783 // cache song title & length from tuple
741 dbg_printf ("length, ");
742 plr.songlength = plr.p->songlength (plr.subsong);
743
744 // cache song title
745 dbg_printf ("title, "); 784 dbg_printf ("title, ");
746 if (!plr.p->gettitle ().empty ()) 785 Tuple* ti = adplug_get_tuple(filename);
747 { 786 if (ti)
748 plr.songtitle = (char *) malloc (plr.p->gettitle ().length () + 1); 787 {
749 strcpy (plr.songtitle, plr.p->gettitle ().c_str ()); 788 plr.songtitle = format_and_free_ti( ti, &songlength );
750 } 789 }
790 plr.songlength = songlength;
751 791
752 // reset to first subsong on new file 792 // reset to first subsong on new file
753 dbg_printf ("subsong, "); 793 dbg_printf ("subsong, ");
754 if (strcmp (filename, plr.filename)) 794 if (strcmp (filename, plr.filename))
755 { 795 {
919 } 959 }
920 960
921 static void 961 static void
922 adplug_song_info (char *filename, char **title, int *length) 962 adplug_song_info (char *filename, char **title, int *length)
923 { 963 {
924 CSilentopl tmpopl; 964 *length = -1;
925 VFSFile *fd = vfs_buffered_file_new_from_uri (filename); 965 *title = NULL;
926 966
927 if (!fd) 967 Tuple* ti = adplug_get_tuple( filename );
928 return; 968 if ( ti )
929 969 *title = format_and_free_ti( ti, length );
930 CPlayer *p = factory (fd, &tmpopl);
931
932 dbg_printf ("adplug_song_info(\"%s\", \"%s\", %d): ", filename, *title,
933 *length);
934
935 if (p)
936 {
937 // allocate and set title string
938 if (p->gettitle ().empty ())
939 *title = 0;
940 else
941 {
942 *title = (char *) malloc (p->gettitle ().length () + 1);
943 strcpy (*title, p->gettitle ().c_str ());
944 }
945
946 // get song length
947 *length = p->songlength (plr.subsong);
948
949 // delete temporary player object
950 delete p;
951 }
952
953 dbg_printf ("title = \"%s\", length = %d\n", *title, *length);
954 } 970 }
955 971
956 /***** Player control *****/ 972 /***** Player control *****/
957 973
958 static void 974 static void
1136 NULL, // OBSOLETE - DO NOT USE! 1152 NULL, // OBSOLETE - DO NOT USE!
1137 NULL, // add_vis_pcm (filled by XMMS) 1153 NULL, // add_vis_pcm (filled by XMMS)
1138 NULL, // set_info (filled by XMMS) 1154 NULL, // set_info (filled by XMMS)
1139 NULL, // set_info_text (filled by XMMS) 1155 NULL, // set_info_text (filled by XMMS)
1140 adplug_song_info, 1156 adplug_song_info,
1141 adplug_info_box, // adplug_info_box was here (but it used deprecated GTK+ functions) 1157 adplug_info_box,
1142 NULL, // output plugin (filled by XMMS) 1158 NULL, // output plugin (filled by XMMS)
1143 NULL, 1159 adplug_get_tuple,
1144 NULL, 1160 NULL,
1145 NULL, 1161 NULL,
1146 adplug_is_our_fd, 1162 adplug_is_our_fd,
1147 NULL, 1163 NULL,
1148 }; 1164 };
1149 1165
1150 InputPlugin *adplug_iplist[] = { &adplug_ip, NULL }; 1166 InputPlugin *adplug_iplist[] = { &adplug_ip, NULL };
1151 1167
1152 DECLARE_PLUGIN(adplug, NULL, NULL, adplug_iplist, NULL, NULL, NULL, NULL,NULL); 1168 DECLARE_PLUGIN(adplug, NULL, NULL, adplug_iplist, NULL, NULL, NULL, NULL,NULL);
1169