./ext/CdIo_Cd.c in rb_cdio-0.1.1 vs ./ext/CdIo_Cd.c in rb_cdio-0.2.0
- old
+ new
@@ -25,64 +25,11 @@
*/
cdio_destroy(p);
}
-
-
-
-
/**
-* CDDB
-* Extraido desde cd-info.
-**/
-
-static int
-cddb_dec_digit_sum(int n)
-{
- int ret = 0;
-
- for (;;) {
- ret += n % 10;
- n = n / 10;
- if (!n)
- return ret;
- }
-}
-
-/*
- * Return the number of seconds (discarding frame portion) of an MSF
- */
-static inline unsigned int
-msf_seconds(msf_t * msf)
-{
- return from_bcd8(msf->m) * 60 + from_bcd8(msf->s);
-}
-
-static unsigned long
-cddb_discid(CdIo * p_cdio, int i_tracks)
-{
- int i,
- t,
- n = 0;
- msf_t start_msf;
- msf_t msf;
-
- for (i = 1; i <= i_tracks; i++) {
- cdio_get_track_msf(p_cdio, i, &msf);
- n += cddb_dec_digit_sum(msf_seconds(&msf));
- }
-
- cdio_get_track_msf(p_cdio, 1, &start_msf);
- cdio_get_track_msf(p_cdio, CDIO_CDROM_LEADOUT_TRACK, &msf);
-
- t = msf_seconds(&msf) - msf_seconds(&start_msf);
-
- return ((n % 0xff) << 24 | t << 8 | i_tracks);
-}
-
-/**
Create a new Cd::CdIo object.
The first argument is an String for a device or a cue/bin/toc/nrg file
The seconf argument is the constant for a Driver (default CdIo::DRIVER_UNKNOWN)
* CdIo::Cd.new()
* CdIo::Cd.new("/dev/cdrom")
@@ -115,11 +62,12 @@
}
}
p_cdio = cdio_open(device, driver);
if (p_cdio == NULL) {
- rb_raise(rb_eException, "I can't create a pointer");
+ rb_raise(eCdIoError,
+ "I can't create the object. Please, verify the media");
return Qnil;
} else {
VALUE c_argv[2];
VALUE tdata =
Data_Wrap_Struct(class, 0, _cdio_cd_destroy, p_cdio);
@@ -167,45 +115,38 @@
rb_iv_set(self, "@mcn", rb_str_new2(mcn));
free(mcn);
}
}
// stat_size
- rb_iv_set(self, "@stat_size", INT2NUM(cdio_stat_size(p_cdio)));
- // si es un disco de audio, calculo su cddb
+ rb_iv_set(self, "@last_lsn", INT2NUM(cdio_get_disc_last_lsn(p_cdio)));
+ rb_iv_set(self, "@joliet_level",
+ INT2NUM(cdio_get_joliet_level(p_cdio)));
+
+ // si es un disco de audio, lo extiendo con las funciones
+ // del módulo Cdda
if (CDIO_DISC_MODE_CD_DA == discmode) {
- char cddb[8];
- sprintf(cddb, "%08lx", cddb_discid(p_cdio, nt));
- rb_iv_set(self, "@cddb_id", rb_str_new2(cddb));
+ rb_extend_object(self, mCdIoCdda);
}
+
return self;
}
/**
* Returns an array with the tracks of the cd
* cd.get_tracks #=> [<CdIo::Track>,<CdIo::Track>]
*/
VALUE
rb_cdio_cd_get_tracks(VALUE self)
{
- VALUE argv[1];
- argv[0] = self;
- return rb_class_new_instance(1, argv, cCdIoTracks);
- VALUE aTracks;
- aTracks = rb_ary_new();
- GET_CDIO(self, p_cdio);
- track_t first_track_num;
- track_t num_tracks;
- first_track_num = cdio_get_first_track_num(p_cdio);
- num_tracks = cdio_get_num_tracks(p_cdio);
- // printf("C->Primera pista: %d\n",first_track_num);
- // printf("C->Numero pistas: %d\n",num_tracks);
- int j,
- i = first_track_num;
- for (j = 0; j < num_tracks; i++, j++) {
- rb_ary_push(aTracks, get_track(self, i));
+ VALUE tracks = rb_iv_get(self, "@tracks");
+ if (tracks == Qnil) {
+ VALUE argv[1];
+ argv[0] = self;
+ tracks = rb_class_new_instance(1, argv, cCdIoTracks);
+ rb_iv_set(self, "@tracks", tracks);
}
- return aTracks;
+ return tracks;
}
/**
* CdIo::Cd.get_first_track
*/
@@ -231,34 +172,36 @@
*/
VALUE
rb_cdio_cd_is_cd(VALUE obj)
{
GET_CDIO(obj, p_cdio);
- return (discmode_is_cd(cdio_get_discmode(p_cdio))) ? Qtrue : Qfalse;
+ return (cdio_is_discmode_cdrom(cdio_get_discmode(p_cdio))) ? Qtrue :
+ Qfalse;
}
/**
* CdIo::Cd.is_dvd?
*/
VALUE
rb_cdio_cd_is_dvd(VALUE obj)
{
GET_CDIO(obj, p_cdio);
- return (discmode_is_dvd(cdio_get_discmode(p_cdio))) ? Qtrue : Qfalse;
+ return (cdio_is_discmode_dvd(cdio_get_discmode(p_cdio))) ? Qtrue :
+ Qfalse;
}
-static VALUE
+static VALUE
_get_freedb(VALUE obj)
{
rb_require("freedb");
VALUE cFreeDb =
rb_const_get(rb_mKernel, rb_intern("Freedb"));
return rb_funcall(cFreeDb, rb_intern("new"), 1,
rb_iv_get(obj, "@device"));
}
-static VALUE
+static VALUE
_get_freedb_error(VALUE obj, VALUE error_info)
{
rb_raise(rb_eLoadError,
"Please, install ruby-freedb to use this function");
return Qnil;
@@ -323,6 +266,16 @@
rb_cdio_cd_get_cdtext(VALUE obj)
{
GET_CDIO(obj, p_cdio);
const cdtext_t *cdtext = cdio_get_cdtext(p_cdio, 0);
return get_cdtext(cdtext);
+}
+
+VALUE
+rb_cdio_cd_eject(VALUE obj)
+{
+ GET_CDIO(obj, p_cdio);
+ verify_return_code(cdio_eject_media(&p_cdio));
+ rb_gc_start();
+ obj = Qnil;
+ return Qtrue;
}