/** * Copyright (c) 2005 Claudio Bustos * This code is hereby licensed for public consumption under the * GNU GPL v2. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "CdIo.h" /** * Funci?n extraida de cd-info.c */ VALUE rb_cdio_track_new(VALUE cd, int track) { VALUE argv[2]; argv[0] = cd; argv[1] = INT2FIX(track); return rb_class_new_instance(2, argv, cCdIoTrack); } int rb_cdio_track_number(VALUE obj) { return FIX2INT(rb_iv_get(obj, "@number")); } VALUE rb_cdio_track_green(VALUE obj) { GET_CDIO(rb_iv_get(obj, "@cd"), p_cdio); if (cdio_get_track_green(p_cdio, rb_cdio_track_number(obj))) { return Qtrue; } else { return Qfalse; } } VALUE rb_cdio_track_init(VALUE obj, VALUE cd, VALUE track) { // Verificaci?n de tipos. lsn_t lsn; int i_track; FIXNUM_P(track); if (Qtrue != rb_obj_is_instance_of(cd, cCdIoCd)) { rb_raise(rb_eArgError, "Arg 1 must be a CdIo::Cd"); } GET_CDIO(cd, p_cdio); i_track = FIX2INT(track); // Verify track number track_t min, max; min = cdio_get_first_track_num(p_cdio); max = min + cdio_get_num_tracks(p_cdio) - 1; if (i_track != CDIO_CDROM_LEADOUT_TRACK && (i_track < min || i_track > max)) { char buffer[64]; sprintf(buffer, "The track %d doesn't exists", i_track); rb_raise(rb_eException, buffer); } /** :cd :number :format, :green, :lba,:lsn,:msf,:sec_count*/ rb_iv_set(obj, "@cd", cd); rb_iv_set(obj, "@number", track); rb_iv_set(obj, "@format", INT2FIX(cdio_get_track_format(p_cdio, i_track))); rb_iv_set(obj, "@lba", INT2NUM(cdio_get_track_lba(p_cdio, i_track))); lsn = cdio_get_track_lsn(p_cdio, i_track); rb_iv_set(obj, "@lsn", INT2NUM(lsn)); // msf msf_t msf; char *msf_s; if (cdio_get_track_msf(p_cdio, i_track, &msf)) { msf_s = cdio_msf_to_str(&msf); // printf("C->%d:%d:%d\n",(int)msf.m,(int)msf.s,(int)msf.f); rb_iv_set(obj, "@min", INT2FIX(from_bcd8(msf.m))); rb_iv_set(obj, "@sec", INT2FIX(from_bcd8(msf.s))); rb_iv_set(obj, "@frames", INT2FIX(from_bcd8(msf.f))); rb_iv_set(obj, "@msf", rb_str_new2(msf_s)); free(msf_s); } rb_iv_set(obj, "@sec_count", INT2NUM(cdio_get_track_sec_count(p_cdio, i_track))); // vemos el tipo cdio_fs_anal_t fs; cdio_iso_analysis_t iso_analysis; fs = cdio_guess_cd_type(p_cdio, 0, i_track, &iso_analysis); rb_iv_set(obj, "@track_type", INT2FIX(fs)); rb_iv_set(obj, "@leadout", (i_track == CDIO_CDROM_LEADOUT_TRACK) ? Qtrue : Qfalse); return obj; } VALUE rb_cdio_track_get_cdtext(VALUE obj) { GET_CDIO(rb_iv_get(obj, "@cd"), p_cdio); const cdtext_t *cdtext = cdio_get_cdtext(p_cdio, rb_cdio_track_number(obj)); return get_cdtext(cdtext); }