#include "CdIo.h" VALUE rb_cdio_tracks_init(VALUE obj, VALUE cd) { if (Qtrue != rb_obj_is_instance_of(cd, cCdIoCd)) { rb_raise(rb_eArgError, "Arg 1 must be a CdIo::Cd"); } rb_iv_set(obj, "@cd", cd); VALUE aTracks; aTracks = rb_ary_new(); GET_CDIO(cd, 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(cd, i)); } rb_iv_set(obj, "@tracks", aTracks); return obj; } VALUE rb_cdio_tracks_each(int argc, VALUE * argv, VALUE obj) { VALUE block; int len, i; rb_scan_args(argc, argv, "00&", &block); VALUE aTracks = rb_iv_get(obj, "@tracks"); len = RARRAY(aTracks)->len; for (i = 0; i < len; i++) { rb_yield(rb_ary_entry(aTracks, i)); } return aTracks; } VALUE rb_cdio_tracks_diff(VALUE obj, VALUE a, VALUE b) { int ia, ib, ret; ia = rb_cdio_track_number(a); ib = rb_cdio_track_number(b); if (ia > ib) { ret = 1; } else if (ia < ib) { ret = -1; } else { ret = 0; } return INT2FIX(ret); } VALUE rb_cdio_tracks_index(VALUE obj, VALUE index) { FIXNUM_P(index); return get_track(rb_iv_get(obj, "@cd"), FIX2INT(index)); }