annotate src/cdaudio-ng/cdaudio-ng.c @ 1048:a42f95563c98 trunk

[svn] Added cdaudio-ng
author zither
date Mon, 21 May 2007 15:28:07 -0700
parents
children 334afe46961c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1048
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
1
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
2 /*
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
3 todo:
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
4 - if any cdio_* returns an error, stop playing immediately
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
5 */
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
6
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
7 #include <string.h>
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
8 #include <stdlib.h>
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
9 #include <unistd.h>
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
10 #include <errno.h>
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
11 #include <libgen.h>
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
12
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
13 #include <cdio/cdio.h>
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
14 #include <cdio/cdtext.h>
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
15 #include <cdio/track.h>
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
16 #include <cdio/cdda.h>
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
17 #include <cdio/audio.h>
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
18 #include <cdio/sector.h>
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
19 #include <cdio/cd_types.h>
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
20
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
21 #include <glib.h>
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
22
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
23 #include <audacious/i18n.h>
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
24 #include <audacious/configdb.h>
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
25 #include <audacious/util.h>
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
26 #include <audacious/titlestring.h>
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
27 #include <audacious/output.h>
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
28
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
29 #define DEF_STRING_LEN 256
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
30
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
31
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
32 typedef struct {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
33
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
34 char performer[DEF_STRING_LEN];
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
35 char name[DEF_STRING_LEN];
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
36 char genre[DEF_STRING_LEN];
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
37 int startlsn;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
38 int endlsn;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
39
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
40 } trackinfo_t;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
41
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
42
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
43 static int firsttrackno = -1;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
44 static int lasttrackno = -1;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
45 static cdrom_drive_t *pcdrom_drive = NULL;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
46 static trackinfo_t *trackinfo = NULL;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
47 static char album_name[DEF_STRING_LEN];
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
48 static gboolean use_dao = FALSE;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
49 static gboolean is_paused = FALSE;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
50 static int playing_track = -1;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
51
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
52
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
53 static void cdaudio_init();
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
54 static void cdaudio_about();
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
55 static void cdaudio_configure();
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
56 static gint cdaudio_is_our_file(gchar *filename);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
57 static GList *cdaudio_scan_dir(gchar *dirname);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
58 static void cdaudio_play_file(InputPlayback *pinputplayback);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
59 static void cdaudio_stop(InputPlayback *pinputplayback);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
60 static void cdaudio_pause(InputPlayback *pinputplayback, gshort paused);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
61 static void cdaudio_seek(InputPlayback *pinputplayback, gint time);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
62 static gint cdaudio_get_time(InputPlayback *pinputplayback);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
63 static gint cdaudio_get_volume(gint *l, gint *r);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
64 static gint cdaudio_set_volume(gint l, gint r);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
65 static void cdaudio_cleanup();
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
66 static void cdaudio_get_song_info(gchar *filename, gchar **title, gint *length);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
67 static void cdaudio_file_info_box(gchar *filename);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
68 static TitleInput *cdaudio_get_song_tuple(gchar *filename);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
69
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
70 static int calculate_track_length(int startlsn, int endlsn);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
71 static int find_trackno_from_filename(char *filename);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
72
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
73 /*
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
74 static int calculate_digit_sum(int n);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
75 static unsigned long calculate_cddb_discid();
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
76 */
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
77
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
78
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
79 static InputPlugin inputplugin = {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
80 NULL,
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
81 NULL,
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
82 NULL,
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
83 cdaudio_init,
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
84 cdaudio_about,
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
85 cdaudio_configure,
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
86 cdaudio_is_our_file,
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
87 cdaudio_scan_dir,
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
88 cdaudio_play_file,
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
89 cdaudio_stop,
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
90 cdaudio_pause,
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
91 cdaudio_seek,
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
92 NULL,
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
93 cdaudio_get_time,
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
94 cdaudio_get_volume,
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
95 cdaudio_set_volume,
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
96 cdaudio_cleanup,
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
97 NULL,
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
98 NULL,
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
99 NULL,
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
100 NULL,
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
101 cdaudio_get_song_info,
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
102 cdaudio_file_info_box,
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
103 NULL,
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
104 cdaudio_get_song_tuple
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
105 };
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
106
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
107
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
108 InputPlugin *get_iplugin_info(void)
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
109 {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
110 inputplugin.description = g_strdup_printf("Zither's CD Audio Plugin");
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
111 return &inputplugin;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
112 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
113
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
114
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
115 void cdaudio_init()
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
116 {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
117 cdio_init();
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
118 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
119
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
120 void cdaudio_about()
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
121 {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
122 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
123
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
124 void cdaudio_configure()
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
125 {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
126 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
127
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
128 gint cdaudio_is_our_file(gchar *filename)
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
129 {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
130 printf("is_our_file(\"%s\")\n", filename);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
131 if ((filename != NULL) && strlen(filename) > 4 && (!strcasecmp(filename + strlen(filename) - 4, ".cda"))) {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
132 if (pcdrom_drive == NULL) { /* no CD information yet */
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
133 printf("No CD information, rescanning\n");
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
134 cdaudio_scan_dir("/mnt/cdrom"); // todo: :)
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
135 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
136
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
137 if (cdio_get_media_changed(pcdrom_drive->p_cdio)) {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
138 printf("CD changed, rescanning\n");
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
139 cdaudio_scan_dir("/mnt/cdrom"); // todo: change the hardcoded path
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
140 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
141
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
142 return 1;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
143 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
144 else
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
145 return 0;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
146 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
147
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
148 GList *cdaudio_scan_dir(gchar *dirname)
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
149 {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
150 printf("scan_dir(\"%s\")\n", dirname);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
151
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
152 if (strstr(dirname, "/mnt/cdrom") == NULL) // todo: replace this with a more standardised string
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
153 return NULL;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
154
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
155 /* find the first available, audio capable, cd drive */
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
156 char **ppcd_drives = cdio_get_devices_with_cap(NULL, CDIO_FS_AUDIO, false);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
157 if (ppcd_drives != NULL) { /* we have at least one audio capable cd drive */
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
158 pcdrom_drive = cdio_cddap_identify(*ppcd_drives, 1, NULL);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
159 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
160 else {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
161 printf("Unable find or access a CD-ROM drive with an audio CD in it.\n");
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
162 return NULL;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
163 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
164 cdio_free_device_list(ppcd_drives);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
165
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
166 /* get track information */
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
167 firsttrackno = cdio_get_first_track_num(pcdrom_drive->p_cdio);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
168 lasttrackno = cdio_get_last_track_num(pcdrom_drive->p_cdio);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
169
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
170 /* add track "file" names to the list */
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
171 GList *list = NULL;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
172 if (trackinfo != NULL)
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
173 free(trackinfo);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
174 trackinfo = (trackinfo_t *) malloc(sizeof(trackinfo_t) * (lasttrackno + 1));
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
175 int trackno;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
176 for (trackno = firsttrackno; trackno <= lasttrackno; trackno++) {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
177 list = g_list_append(list, g_strdup_printf("track%02u.cda", trackno));
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
178 cdtext_t *pcdtext = cdio_get_cdtext(pcdrom_drive->p_cdio, trackno);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
179
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
180 if (pcdtext != NULL) {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
181 strcpy(trackinfo[trackno].performer, pcdtext->field[CDTEXT_PERFORMER] != NULL ? pcdtext->field[CDTEXT_PERFORMER] : "");
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
182 strcpy(trackinfo[trackno].name, pcdtext->field[CDTEXT_TITLE] != NULL ? pcdtext->field[CDTEXT_TITLE] : "");
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
183 strcpy(trackinfo[trackno].genre, pcdtext->field[CDTEXT_GENRE] != NULL ? pcdtext->field[CDTEXT_GENRE] : "");
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
184 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
185 else {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
186 strcpy(trackinfo[trackno].performer, "");
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
187 strcpy(trackinfo[trackno].name, "");
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
188 strcpy(trackinfo[trackno].genre, "");
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
189 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
190
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
191 if (strlen(trackinfo[trackno].name) == 0)
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
192 sprintf(trackinfo[trackno].name, "CD Audio Track %02u", trackno);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
193
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
194 trackinfo[trackno].startlsn = cdio_get_track_lsn(pcdrom_drive->p_cdio, trackno);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
195 trackinfo[trackno].endlsn = cdio_get_track_last_lsn(pcdrom_drive->p_cdio, trackno);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
196 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
197
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
198 return list;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
199 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
200
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
201 void cdaudio_play_file(InputPlayback *pinputplayback)
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
202 {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
203 printf("play_file(\"%s\")\n", pinputplayback->filename);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
204
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
205 if (trackinfo == NULL) {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
206 printf("No CD information, rescanning\n");
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
207 cdaudio_scan_dir("/mnt/cdrom"); // todo: change the hardcoded path
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
208 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
209
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
210 if (cdio_get_media_changed(pcdrom_drive->p_cdio)) {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
211 printf("CD changed, rescanning\n");
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
212 cdaudio_scan_dir("/mnt/cdrom"); // todo: change the hardcoded path
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
213 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
214
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
215 int trackno = find_trackno_from_filename(pinputplayback->filename);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
216 if (trackno < firsttrackno || trackno > lasttrackno)
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
217 return;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
218
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
219 msf_t startmsf, endmsf;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
220 cdio_lsn_to_msf(trackinfo[trackno].startlsn, &startmsf);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
221 cdio_lsn_to_msf(trackinfo[trackno].endlsn, &endmsf);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
222 cdio_audio_play_msf(pcdrom_drive->p_cdio, &startmsf, &endmsf);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
223
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
224 pinputplayback->playing = TRUE;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
225 playing_track = trackno;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
226
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
227 char title[DEF_STRING_LEN];
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
228
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
229 if (strlen(trackinfo[trackno].performer) > 0) {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
230 strcpy(title, trackinfo[trackno].performer);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
231 strcat(title, " - ");
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
232 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
233 else
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
234 strcpy(title, "");
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
235 strcat(title, trackinfo[trackno].name);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
236
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
237 inputplugin.set_info(title, calculate_track_length(trackinfo[trackno].startlsn, trackinfo[trackno].endlsn), 128000, 44100, 2);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
238 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
239
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
240 void cdaudio_stop(InputPlayback *pinputplayback)
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
241 {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
242 printf("stop(\"%s\")\n", pinputplayback->filename);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
243
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
244 cdio_audio_stop(pcdrom_drive->p_cdio);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
245 pinputplayback->playing = FALSE;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
246 playing_track = -1;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
247 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
248
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
249 void cdaudio_pause(InputPlayback *pinputplayback, gshort paused)
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
250 {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
251 if (!is_paused) {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
252 is_paused = TRUE;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
253 cdio_audio_pause(pcdrom_drive->p_cdio);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
254 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
255 else {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
256 is_paused = FALSE;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
257 cdio_audio_resume(pcdrom_drive->p_cdio);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
258 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
259 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
260
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
261 void cdaudio_seek(InputPlayback *pinputplayback, gint time)
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
262 {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
263 printf("seek(%d)\n", time);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
264 if (playing_track == -1)
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
265 return;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
266
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
267 int lsnoffs = (time * 75);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
268 int startlsn = trackinfo[playing_track].startlsn + lsnoffs;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
269
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
270 msf_t startmsf, endmsf;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
271 cdio_lsn_to_msf(startlsn, &startmsf);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
272 cdio_lsn_to_msf(trackinfo[playing_track].endlsn, &endmsf);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
273 cdio_audio_play_msf(pcdrom_drive->p_cdio, &startmsf, &endmsf);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
274 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
275
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
276 gint cdaudio_get_time(InputPlayback *pinputplayback)
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
277 {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
278 if (playing_track == -1)
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
279 return -1;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
280
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
281 cdio_subchannel_t subchannel;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
282 cdio_audio_read_subchannel(pcdrom_drive->p_cdio, &subchannel);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
283 int currentlsn = cdio_msf_to_lsn(&subchannel.abs_addr);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
284
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
285 /* check to see if we have reached the end of the song */
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
286 if (currentlsn == trackinfo[playing_track].endlsn) {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
287 cdaudio_stop(pinputplayback);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
288 return -1;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
289 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
290
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
291 int seconds = calculate_track_length(trackinfo[playing_track].startlsn, currentlsn);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
292 // printf("%d\n", seconds);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
293 return seconds;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
294 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
295
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
296 gint cdaudio_get_volume(gint *l, gint *r)
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
297 {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
298 // printf("get_volume()\n");
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
299
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
300 cdio_audio_volume_t volume;;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
301 cdio_audio_set_volume(pcdrom_drive->p_cdio, &volume);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
302 *l = volume.level[0];
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
303 *r = volume.level[1];
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
304
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
305 return 0;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
306 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
307
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
308 gint cdaudio_set_volume(gint l, gint r)
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
309 {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
310 printf("set_volume(%d, %d)\n", l, r);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
311
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
312 cdio_audio_volume_t volume = {{l, r, 0, 0}};
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
313 cdio_audio_set_volume(pcdrom_drive->p_cdio, &volume);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
314
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
315 return 0;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
316 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
317
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
318 void cdaudio_cleanup()
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
319 {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
320 cdio_destroy(pcdrom_drive->p_cdio);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
321 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
322
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
323 void cdaudio_get_song_info(gchar *filename, gchar **title, gint *length)
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
324 {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
325 printf("get_song_info(\"%s\")\n", filename);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
326 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
327
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
328 void cdaudio_file_info_box(gchar *filename)
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
329 {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
330
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
331 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
332
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
333 TitleInput *cdaudio_get_song_tuple(gchar *filename)
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
334 {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
335 printf("get_song_tuple(\"%s\")\n", filename);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
336
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
337 TitleInput *tuple = bmp_title_input_new();
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
338
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
339 /* return information about the requested track */
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
340 int trackno = find_trackno_from_filename(filename);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
341 if (trackno < firsttrackno || trackno > lasttrackno)
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
342 return NULL;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
343
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
344 tuple->performer = strlen(trackinfo[trackno].performer) > 0 ? g_strdup(trackinfo[trackno].performer) : NULL;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
345 tuple->album_name = strlen(album_name) > 0 ? g_strdup(album_name) : NULL;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
346 tuple->track_name = strlen(trackinfo[trackno].name) > 0 ? g_strdup(trackinfo[trackno].name) : NULL;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
347 tuple->track_number = trackno;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
348 tuple->file_name = g_strdup(basename(filename));
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
349 tuple->file_path = g_strdup(basename(filename));
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
350 tuple->file_ext = g_strdup("cda");
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
351 tuple->length = calculate_track_length(trackinfo[trackno].startlsn, trackinfo[trackno].endlsn);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
352 tuple->genre = strlen(trackinfo[trackno].genre) > 0 ? g_strdup(trackinfo[trackno].genre) : NULL;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
353 //tuple->year = 0; todo: set the year
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
354
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
355 return tuple;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
356 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
357
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
358
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
359 /* auxiliar functions */
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
360
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
361 /*
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
362 static int calculate_digit_sum(int n)
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
363 {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
364 int ret = 0;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
365
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
366 while (1) {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
367 ret += n % 10;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
368 n = n / 10;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
369 if (n == 0)
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
370 return ret;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
371 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
372 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
373 */
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
374
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
375 /*
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
376 static unsigned long calculate_cddb_discid()
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
377 {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
378 int trackno, t, n = 0;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
379 msf_t startmsf;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
380 msf_t msf;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
381
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
382 for (trackno = firsttrackno; trackno <= lasttrackno; trackno++) {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
383 cdio_get_track_msf(pcdrom_drive->p_cdio, trackno, &msf);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
384 n += calculate_digit_sum(cdio_audio_get_msf_seconds(&msf));
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
385 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
386
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
387 cdio_get_track_msf(pcdrom_drive->p_cdio, 1, &startmsf);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
388 cdio_get_track_msf(pcdrom_drive->p_cdio, CDIO_CDROM_LEADOUT_TRACK, &msf);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
389
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
390 t = cdio_audio_get_msf_seconds(&msf) - cdio_audio_get_msf_seconds(&startmsf);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
391
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
392 return ((n % 0xFF) << 24 | t << 8 | (lasttrackno - firsttrackno + 1));
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
393 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
394 */
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
395
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
396 int calculate_track_length(int startlsn, int endlsn)
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
397 {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
398 return ((endlsn - startlsn + 1) * 1000) / 75;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
399 }
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
400
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
401 int find_trackno_from_filename(char *filename)
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
402 {
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
403 if ((filename == NULL) || strlen(filename) <= 6)
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
404 return -1;
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
405
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
406 char tracknostr[3];
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
407 strncpy(tracknostr, filename + strlen(filename) - 6, 2);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
408 tracknostr[2] = '\0';
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
409 return strtol(tracknostr, NULL, 10);
a42f95563c98 [svn] Added cdaudio-ng
zither
parents:
diff changeset
410 }