예제 #1
0
파일: cdda.c 프로젝트: kfihihc/xmms2-devel
static gboolean
get_disc_ids (const gchar *device, gchar **disc_id,
              gchar **cddb_id, track_t *tracks)
{
	DiscId *disc = discid_new ();
	g_return_val_if_fail (disc, FALSE);

	if (discid_read_sparse (disc, device, 0) == 0) {
		xmms_log_error ("Could not read disc: %s", discid_get_error_msg (disc));
		discid_free (disc);
		return FALSE;
	}

	*disc_id = g_strdup (discid_get_id (disc));
	if (tracks) {
		*tracks = discid_get_last_track_num (disc);
	}

	if (cddb_id) {
		*cddb_id = g_strdup (discid_get_freedb_id (disc));
	}

	discid_free (disc);

	return TRUE;
}
예제 #2
0
/**
 * call-seq:
 *  tracks() -> array
 *  tracks() {|offset, length| block }
 * 
 * Returns an array of <tt>[offset, length]</tt> tuples for each track.
 * 
 * Offset and length are both integer values representing sectors.
 * If a block is given this method returns +nil+ and instead iterates over the
 * block calling the block with two arguments <tt>|offset, length|</tt>.
 *
 * Returns always +nil+ if no ID was yet read. The block won't be called in
 * this case.
 *
 * You may want to use the method track_details instead of this method to
 * retrieve more detailed information about the tracks.
 */
static VALUE mb_discid_tracks(VALUE self)
{
	if (rb_iv_get(self, "@read") == Qfalse)
		return Qnil;
	else
	{
		DiscId *disc; /* Pointer to the disc struct */
		VALUE result = rb_ary_new(); /* Array of all [offset, length] tuples */
		VALUE tuple; /* Array to store one [offset, length] tuple. */
		int track;   /* Counter for the track number to process. */
		
		Data_Get_Struct(self, DiscId, disc);
		
		track = discid_get_first_track_num(disc); /* First track number */
		while (track <= discid_get_last_track_num(disc))
		{
			tuple = rb_ary_new3(2,
				INT2FIX(discid_get_track_offset(disc, track)),
				INT2FIX(discid_get_track_length(disc, track)) );
			
			if (rb_block_given_p())
				rb_yield(tuple);
			else
				rb_ary_push(result, tuple);
				
			track++;
		}
		
		if (rb_block_given_p())
			return Qnil;
		else
			return result;
	}
}
예제 #3
0
/**
 * call-seq:
 *  last_track_num() -> int or nil
 * 
 * Return the number of the last track on this disc.
 * 
 * Returns +nil+ if no ID was yet read.
 */
static VALUE mb_discid_last_track_num(VALUE self)
{
	if (rb_iv_get(self, "@read") == Qfalse)
		return Qnil;
	else
	{
		DiscId *disc;
		Data_Get_Struct(self, DiscId, disc);
		
		return INT2FIX(discid_get_last_track_num(disc));
	}
}
예제 #4
0
파일: discid.c 프로젝트: Zastai/libdiscid
int main(int argc, char *argv[]) {
	int i, first_track, last_track;
	char *device = NULL;
	char time_str[14];
	int sectors;
	DiscId *disc;

	disc = discid_new();

	/* If we have an argument, use it as the device name */
	if (argc > 1) {
		device = argv[1];
	} else {
		/* this will use discid_get_default_device() internally */
		device = NULL;
	}

	if (discid_read_sparse(disc, device, 0) == 0) {
		fprintf(stderr, "Error: %s\n", discid_get_error_msg(disc));
		discid_free(disc);
		return 1;
	}

	printf("DiscID        : %s\n", discid_get_id(disc));
	printf("FreeDB DiscID : %s\n", discid_get_freedb_id(disc));

	first_track = discid_get_first_track_num(disc);
	last_track = discid_get_last_track_num(disc);
	printf("First track   : %d\n", first_track);
	printf("Last track    : %d\n", last_track);

	sectors = discid_get_sectors(disc);
	sectors_to_time(sectors, ROUND_SECONDS, time_str, sizeof time_str);
	printf("Length        : %d sectors (%s)\n", sectors, time_str);

	for ( i = first_track; i <= last_track; i++ ) {
		sectors = discid_get_track_length(disc, i);
		sectors_to_time(sectors, ROUND_SECONDS,
				time_str, sizeof time_str);
		printf("Track %-2d      : %8d %8d (%s)\n",
				i, discid_get_track_offset(disc, i),
				sectors, time_str);
	}

	printf("Submit via    : %s\n", discid_get_submission_url(disc));

	discid_free(disc);

	return 0;
}