Exemple #1
0
static void
tuple_attach_cdtext(Tuple *tuple, Track *track, int tuple_type, int pti)
{
    Cdtext *cdtext;
    const char *text;

    cdtext = track_get_cdtext(track);
    if (cdtext == NULL)
        return;

    text = cdtext_get(pti, cdtext);
    if (text == NULL)
        return;

    tuple_set_str (tuple, tuple_type, text);
}
Exemple #2
0
QMap<QString, QString> CueFile::getMetadata(int trackno)
{
    QMap<QString, QString> metadata;
    auto set = genSet(metadata);
    Track* track = cd_get_track(cd_, trackno);
    if (track) {
//         metadata["track"] = QString::number(trackno);
        metadata["_cue_offset"] = QString::number(cueLengthToMs(track_get_start(track)));
        Cdtext* cdtext = track_get_cdtext(track);
        if (cdtext) {
            set("artist", cdtext_get(PTI_PERFORMER, cdtext));
            set("title", cdtext_get(PTI_TITLE, cdtext));
            if (metadata["artist"].isEmpty())
                metadata["artist"] = getMetadata().value("album artist");
        }
    }
    return metadata;
}
Exemple #3
0
static char *cue_get_genre(Cd *cd, Track *track)
{
	char *res;

	res = cdtext_get(PTI_GENRE, track_get_cdtext(track));
	if (res && *res)
		return res;
	res = rem_get(REM_GENRE, track_get_rem(track));
	if (res && *res)
		return res;

	res = cdtext_get(PTI_GENRE, cd_get_cdtext(cd));
	if (res && *res)
		return res;
	res = rem_get(REM_GENRE, cd_get_rem(cd));
	if (res && *res)
		return res;
	return NULL;
}
Exemple #4
0
void track_delete(struct Track* track)
{
	if (track != NULL)
	{
		cdtext_delete(track_get_cdtext(track));

		rem_free(track_get_rem(track));

		free(track->isrc);

		free(track->zero_pre.name);

		free(track->zero_post.name);

		free(track->file.name);

		free(track);
	}
}
Exemple #5
0
static char* cue_test()
{
   Cd *cd = cue_parse_string (cue);
   mu_assert ("error parsing CUE", cd != NULL);

   Rem *rem = cd_get_rem (cd);
   mu_assert ("error getting REM", rem != NULL);

   Cdtext *cdtext = cd_get_cdtext (cd);
   mu_assert ("error getting CDTEXT", cdtext != NULL);

   const char *val;
   val = cdtext_get (PTI_PERFORMER, cdtext);
   mu_assert ("error getting CD performer", val != NULL);
   mu_assert ("error validating CD performer", strcmp (val, "Bloc Party") == 0);

   val = cdtext_get (PTI_TITLE, cdtext);
   mu_assert ("error getting CD title", val != NULL);
   mu_assert ("error validating CD title", strcmp (val, "Silent Alarm") == 0);

   int ival = cd_get_ntrack (cd);
   mu_assert ("invalid number of tracks", ival == 2);

   Track *track;
   /* Track 1 */
   track = cd_get_track (cd, 1);
   mu_assert ("error getting track", track != NULL);

   val = track_get_filename (track);
   mu_assert ("error getting track filename", val != NULL);
   mu_assert ("error validating track filename", strcmp (val, "Bloc Party - Silent Alarm.flac") == 0);

   cdtext = track_get_cdtext (track);
   mu_assert ("error getting track CDTEXT", cdtext != NULL);

   val = cdtext_get (PTI_PERFORMER, cdtext);
   mu_assert ("error getting track performer", val != NULL);
   mu_assert ("error validating track performer", strcmp (val, "Bloc Party") == 0);

   val = cdtext_get (PTI_TITLE, cdtext);
   mu_assert ("error getting track title", val != NULL);
   mu_assert ("error validating track title", strcmp (val, "Like Eating Glass") == 0);

   ival = track_get_zero_pre (track);
   mu_assert ("invalid track pre-gap", ival == MSF_TO_F(3,22,70));
   ival = track_get_start (track);
   mu_assert ("invalid track start", ival == MSF_TO_F(3,22,70));
   ival = track_get_length (track);
   mu_assert ("invalid track length", ival == MSF_TO_F(4,19,74));

   ival = track_get_index (track, 0);
   mu_assert ("invalid index", ival == 0);
   ival = track_get_index (track, 1);
   mu_assert ("invalid index", ival == MSF_TO_F(3,22,70));

   /* Track 2 */
   track = cd_get_track (cd, 2);
   mu_assert ("error getting track", track != NULL);

   val = track_get_filename (track);
   mu_assert ("error getting track filename", val != NULL);
   mu_assert ("error validating track filename", strcmp (val, "Bloc Party - Silent Alarm.flac") == 0);

   cdtext = track_get_cdtext (track);
   mu_assert ("error getting track CDTEXT", cdtext != NULL);

   val = cdtext_get (PTI_PERFORMER, cdtext);
   mu_assert ("error getting track performer", val != NULL);
   mu_assert ("error validating track performer", strcmp (val, "Bloc Party") == 0);

   val = cdtext_get (PTI_TITLE, cdtext);
   mu_assert ("error getting track title", val != NULL);
   mu_assert ("error validating track title", strcmp (val, "Helicopter") == 0);

   ival = track_get_zero_pre (track);
   mu_assert ("invalid track pre-gap", ival == MSF_TO_F(0,2,0));
   ival = track_get_start (track);
   mu_assert ("invalid track start", ival == MSF_TO_F(7,44,69));
   ival = track_get_length (track);
   mu_assert ("invalid track length", ival == -1);

   ival = track_get_index (track, 0);
   mu_assert ("invalid index", ival == MSF_TO_F(7,42,69));
   ival = track_get_index (track, 1);
   mu_assert ("invalid index", ival == MSF_TO_F(7,44,69));

   cd_delete (cd);

   return NULL;
}
void cue_print_track (FILE *fp, Track *track, int trackno)
{
	Cdtext *cdtext = track_get_cdtext(track);
	int i; 	/* index */

	if (NULL != track_get_filename(track)) {
		/* 
		 * always print filename for track 1, afterwards only
		 * print filename if it differs from the previous track
		 */
		if (0 != strcmp(track_get_filename(track), filename)) {
			filename = track_get_filename(track);
			fprintf(fp, "FILE \"%s\" ", filename);

			/* NOTE: what to do with other formats (MP3, etc)? */
			if (MODE_AUDIO == track_get_mode(track))
				fprintf(fp, "WAVE\n");
			else
				fprintf(fp, "BINARY\n");
		}
	}

	fprintf(fp, "TRACK %02d ", trackno);
	switch (track_get_mode(track)) {
	case MODE_AUDIO:
		fprintf(fp, "AUDIO\n");
		break;
	case MODE_MODE1:
		fprintf(fp, "MODE1/2048\n");
		break;
	case MODE_MODE1_RAW:
		fprintf(fp, "MODE1/2352\n");
		break;
	case MODE_MODE2:
		fprintf(fp, "MODE2/2048\n");
		break;
	case MODE_MODE2_FORM1:
		fprintf(fp, "MODE2/2336\n");
		break;
	case MODE_MODE2_FORM2:
		fprintf(fp, "MODE2/2324\n");
		break;
	case MODE_MODE2_FORM_MIX:
		fprintf(fp, "MODE2/2336\n");
		break;
	case MODE_MODE2_RAW:
		fprintf(fp, "MODE2/2352\n");
		break;
	}

	cue_print_cdtext(cdtext, fp, 1);

	if (0 != track_is_set_flag(track, FLAG_ANY)) {
		fprintf(fp, "FLAGS");
		if (0 != track_is_set_flag(track, FLAG_PRE_EMPHASIS))
			fprintf(fp, " PRE");
		if (0 != track_is_set_flag(track, FLAG_COPY_PERMITTED))
			fprintf(fp, " DCP");
		if (0 != track_is_set_flag(track, FLAG_FOUR_CHANNEL))
			fprintf(fp, " 4CH");
		if (0 != track_is_set_flag(track, FLAG_SCMS))
			fprintf(fp, " SCMS");
		fprintf(fp, "\n");
	}

	if (NULL != track_get_isrc(track))
		fprintf(fp, "ISRC %s\n", track_get_isrc(track));

	if (0 != track_get_zero_pre(track))
		fprintf (fp, "PREGAP %s\n", time_frame_to_mmssff(track_get_zero_pre(track)));

	/* don't print index 0 if index 1 = 0 */
	if (track_get_index(track, 1) == 0)
		i = 1;
	else
		i = 0;

	for (; i < track_get_nindex(track); i++) {
		fprintf(fp, "INDEX %02d ", i);
		cue_print_index( \
		track_get_index(track, i) \
		+ track_get_start(track) \
		- track_get_zero_pre(track) , fp);
	}

	if (0 != track_get_zero_post(track))
		fprintf (fp, "POSTGAP %s\n", time_frame_to_mmssff(track_get_zero_post(track)));

	prev_length = track_get_length(track);
}
Exemple #7
0
/* Parse playlist and handle its contents */
plp_status_t cue_for_each_item( char *pl_name, void *ctx, plp_func_t f )
{
	/* Load cue sheet */
	FILE *fd = fopen(pl_name, "rt");
	if (!fd)
	{
		logger_error(cue_log, 0, _("cue: failed to load cue sheet %s"), pl_name);
		return PLP_STATUS_FAILED;
	}
	Cd *cd = cue_parse_file(fd, pl_name);
	if (!cd)
	{
		logger_error(cue_log, 0, _("cue: failed to load cue sheet %s"), pl_name);
		fclose(fd);
		return PLP_STATUS_FAILED;
	}
	fclose(fd);

	/* Handle tracks */
	int num_tracks = cd_get_ntrack(cd);
	plp_status_t res = PLP_STATUS_OK;
	for ( int i = 1; i <= num_tracks; ++i )
	{
		Track *track = cd_get_track(cd, i);
		char *filename = track_get_filename(track);
		if (!filename)
			continue;

		song_metadata_t metadata = SONG_METADATA_EMPTY;

		/* Set bounds */
		long start = cue_get_track_begin(track);
		long end = -1;
		if (i < num_tracks)
		{
			Track *next_track = cd_get_track(cd, i + 1);
			char *next_name = track_get_filename(next_track);
			if (next_name && !strcmp(filename, next_name))
				end = cue_get_track_begin(next_track);
		}
		metadata.m_start_time = SECONDS_TO_TIME(start) / 75;
		metadata.m_end_time = (end < 0 ? -1 : SECONDS_TO_TIME(end) / 75);

		/* Set song info */
		song_info_t *si = si_new();
		si_set_album(si, cdtext_get(PTI_TITLE, cd_get_cdtext(cd)));
		si_set_year(si, rem_get(REM_DATE, cd_get_rem(cd)));
		si_set_artist(si, cdtext_get(PTI_PERFORMER, cd_get_cdtext(cd)));
		si_set_name(si, cdtext_get(PTI_TITLE, track_get_cdtext(track)));
		si_set_genre(si, cue_get_genre(cd, track));
		si_set_comments(si, cue_get_comment(cd, track));

		char track_num_str[10];
		snprintf(track_num_str, sizeof(track_num_str), "%02d", i);
		si_set_track(si, track_num_str);
		metadata.m_song_info = si;

		plp_status_t st = f(ctx, filename, &metadata);
		if (st != PLP_STATUS_OK)
		{
			res = st;
			break;
		}
	}

	/* Free memory */
	cd_delete(cd);
	return res;
} /* End of 'cue_for_each_item' function */
Exemple #8
0
void toc_print_track (FILE *fp, Track *track)
{
	Cdtext *cdtext = track_get_cdtext(track);
	int i;	/* index */

	fprintf(fp, "TRACK ");
	switch (track_get_mode(track)) {
	case MODE_AUDIO:
		fprintf(fp, "AUDIO");
	       	break;
	case MODE_MODE1:
		fprintf(fp, "MODE1");
	       	break;
	case MODE_MODE1_RAW:
		fprintf(fp, "MODE1_RAW");
	       	break;
	case MODE_MODE2:
		fprintf(fp, "MODE2");
	       	break;
	case MODE_MODE2_FORM1:
		fprintf(fp, "MODE2_FORM1");
	       	break;
	case MODE_MODE2_FORM2:
		fprintf(fp, "MODE2_FORM2");
	       	break;
	case MODE_MODE2_FORM_MIX:
		fprintf(fp, "MODE2_FORM_MIX");
	       	break;
	}
	fprintf(fp, "\n");

	if (0 != track_is_set_flag(track, FLAG_PRE_EMPHASIS)) {
		fprintf(fp, "PRE_EMPHASIS\n");
	}
	if (0 != track_is_set_flag(track, FLAG_COPY_PERMITTED)) {
		fprintf(fp, "COPY\n");
	}
	if (0 != track_is_set_flag(track, FLAG_FOUR_CHANNEL)) {
		fprintf(fp, "FOUR_CHANNEL_AUDIO\n");
	}

	if (NULL != track_get_isrc(track)) {
		fprintf(fp, "ISRC \"%s\"\n", track_get_isrc(track));
	}

	if (0 != cdtext_is_empty(cdtext)) {
		fprintf(fp, "CD_TEXT {\n");
		fprintf(fp, "\tLANGUAGE 0 {\n");
		toc_print_cdtext(cdtext, fp, 1);
		fprintf(fp, "\t}\n");
		fprintf(fp, "}\n");
	}

	if (0 != track_get_zero_pre(track)) {
		fprintf(fp, "SILENCE ");
		fprintf(fp, "%s", time_frame_to_mmssff(track_get_zero_pre(track)));
		fprintf(fp, "\n");
	}

	fprintf(fp, "FILE ");
	fprintf(fp, "\"%s\" ", track_get_filename(track));
	if (0 == track_get_start(track)) {
		fprintf(fp, "0");
	} else {
		fprintf(fp, "%s", time_frame_to_mmssff(track_get_start(track)));
	}
	if (0 != track_get_length(track)) {
		fprintf(fp, " %s", time_frame_to_mmssff(track_get_length(track)));
	}
	fprintf(fp, "\n");

	if (0 != track_get_zero_post(track)) {
		fprintf(fp, "SILENCE ");
		fprintf(fp, "%s", time_frame_to_mmssff(track_get_zero_post(track)));
		fprintf(fp, "\n");
	}

	if (track_get_index(track, 1) != 0) {
		fprintf(fp, "START ");
		fprintf(fp, "%s\n", time_frame_to_mmssff(track_get_index(track, 1)));
	}

	for (i = 2; i < track_get_nindex(track); i++) {
		fprintf(fp, "INDEX ");
		fprintf(fp, "%s\n", time_frame_to_mmssff(
			// Indices in TOC are relative to the START
			track_get_index(track, i) - track_get_index(track, 1)
		));
	}
}
Exemple #9
0
static char* cue_pregap_test()
{
   Cd *cd = cue_parse_string (cue_pregap);
   mu_assert ("error parsing CUE", cd != NULL);

   Rem *rem = cd_get_rem (cd);
   mu_assert ("error getting REM", rem != NULL);

   Cdtext *cdtext = cd_get_cdtext (cd);
   mu_assert ("error getting CDTEXT", cdtext != NULL);

   const char *val;
   val = cdtext_get (PTI_PERFORMER, cdtext);
   mu_assert ("error validating CD performer", val == NULL);

   val = cdtext_get (PTI_TITLE, cdtext);
   mu_assert ("error validating CD title", val == NULL);

   int ival = cd_get_ntrack (cd);
   mu_assert ("invalid number of tracks", ival == 2);

   Track *track;
   /* Track 1 */
   track = cd_get_track (cd, 1);
   mu_assert ("error getting track", track != NULL);

   val = track_get_filename (track);
   mu_assert ("error getting track filename", val != NULL);
   mu_assert ("error validating track filename", strcmp (val, "The Specials - Singles - 01 - Gangsters.wav") == 0);

   cdtext = track_get_cdtext (track);
   mu_assert ("error getting track CDTEXT", cdtext != NULL);

   val = cdtext_get (PTI_PERFORMER, cdtext);
   mu_assert ("error getting track performer", val != NULL);
   mu_assert ("error validating track performer", strcmp (val, "The Specials") == 0);

   val = cdtext_get (PTI_TITLE, cdtext);
   mu_assert ("error getting track title", val != NULL);
   mu_assert ("error validating track title", strcmp (val, "Gangsters") == 0);

   ival = track_get_start (track);
   mu_assert ("invalid track start", ival == 0);
   ival = track_get_length (track);
   mu_assert ("invalid track length", ival == -1);

   ival = track_get_index (track, 1);
   mu_assert ("invalid index", ival == 0);

   /* Track 2 */
   track = cd_get_track (cd, 2);
   mu_assert ("error getting track", track != NULL);

   val = track_get_filename (track);
   mu_assert ("error getting track filename", val != NULL);
   mu_assert ("error validating track filename", strcmp (val, "The Specials - Singles - 02 - Rudi, A Message To You.wav") == 0);

   cdtext = track_get_cdtext (track);
   mu_assert ("error getting track CDTEXT", cdtext != NULL);

   val = cdtext_get (PTI_PERFORMER, cdtext);
   mu_assert ("error getting track performer", val != NULL);
   mu_assert ("error validating track performer", strcmp (val, "The Specials") == 0);

   val = cdtext_get (PTI_TITLE, cdtext);
   mu_assert ("error getting track title", val != NULL);
   mu_assert ("error validating track title", strcmp (val, "Rudi, A Message To You") == 0);

   ival = track_get_zero_pre (track);
   mu_assert ("invalid track pre-gap", ival == 28);
   ival = track_get_start (track);
   mu_assert ("invalid track start", ival == 0);
   ival = track_get_length (track);
   mu_assert ("invalid track length", ival == -1);

   ival = track_get_index (track, 1);
   mu_assert ("invalid index", ival == 0);

   cd_delete (cd);

   return NULL;
}
void track_field(char *conv, int length, Cd *cd, int trackno, Value *value)
{
	char *c;	/* pointer to conversion character */

	Track *track = NULL;
	Cdtext *cdtext = NULL;

	track = cd_get_track(cd, trackno);
	cdtext = track_get_cdtext(track);

	c = conv + length - 1;

	switch (*c) {
	case 'a':
		value->sval = cdtext_get(PTI_ARRANGER, cdtext);
		*c = 's';
		break;
	case 'c':
		value->sval = cdtext_get(PTI_COMPOSER, cdtext);
		*c = 's';
		break;
	case 'f':
		value->sval = track_get_filename(track);
		*c = 's';
		break;
	case 'g':
		value->sval = cdtext_get(PTI_GENRE, cdtext);
		*c = 's';
		break;
	case 'i':
		value->sval = track_get_isrc(track);
		*c = 's';
		break;
	case 'm':
		value->sval = cdtext_get(PTI_MESSAGE, cdtext);
		*c = 's';
		break;
	case 'n':
		value->ival = trackno;
		*c = 'd';
		break;
	case 'p':
		value->sval = cdtext_get(PTI_PERFORMER, cdtext);
		*c = 's';
		break;
	case 's':
		value->sval = cdtext_get(PTI_SONGWRITER, cdtext);
		*c = 's';
		break;
	case 't':
		value->sval = cdtext_get(PTI_TITLE, cdtext);
		*c = 's';
		break;
	case 'u':
		value->sval = cdtext_get(PTI_UPC_ISRC, cdtext);
		*c = 's';
		break;
	default:
		disc_field(conv, length, cd, value);
		break;
	}

}