Sha256: 8c57cd54203d86d9f00090de385a997199fa841f2bdb0da87acc43be7a5e589d

Contents?: true

Size: 1.95 KB

Versions: 4

Compression:

Stored size: 1.95 KB

Contents

#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++) {
	// printf("rb_cdio_tracks_init->%d\n",i);
	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)
{
    // ok, this is a very stupid method, but...
    FIXNUM_P(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));
}

Version data entries

4 entries across 2 versions & 1 rubygems

Version Path
rb_cdio-0.2.0 ./ext/CdIo_Tracks.c
rb_cdio-0.2.0 ext/CdIo_Tracks.c
rb_cdio-0.2.1 ext/CdIo_Tracks.c
rb_cdio-0.2.1 ./ext/CdIo_Tracks.c