./ext/CdIo_Tracks.c in rb_cdio-0.1.1 vs ./ext/CdIo_Tracks.c in rb_cdio-0.2.0

- old
+ new

@@ -16,10 +16,11 @@ // 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++) { + // printf("rb_cdio_tracks_init->%d\n",i); rb_ary_push(aTracks, get_track(cd, i)); } rb_iv_set(obj, "@tracks", aTracks); return obj; } @@ -58,9 +59,18 @@ } VALUE rb_cdio_tracks_index(VALUE obj, VALUE index) { - + // ok, this is a very stupid method, but... FIXNUM_P(index); - return get_track(rb_iv_get(obj, "@cd"), FIX2INT(index)); + VALUE aTracks = rb_iv_get(obj, "@tracks"); + long len = RARRAY(aTracks)->len; + long i; + for (i = 0; i < len; i++) { + if (rb_iv_get(rb_ary_entry(aTracks, i), "@number") == index) { + return rb_ary_entry(aTracks, i); + } + } + return Qnil; + // return get_track(rb_iv_get(obj, "@cd"), FIX2INT(index)); }