#include "CdIo.h" #define CAP(val,prop,cap,mask) \ rb_hash_aset(val,rb_str_new2(prop),(*cap & mask) ? Qtrue:Qfalse); VALUE get_cap(cdio_drive_read_cap_t * read_cap, cdio_drive_write_cap_t * write_cap, cdio_drive_misc_cap_t * misc_cap) { if (*read_cap & CDIO_DRIVE_CAP_ERROR || *read_cap & CDIO_DRIVE_CAP_UNKNOWN) { rb_raise(rb_eException, "I can't read the caps!"); return Qnil; } VALUE read, write, misc, ret; read = rb_hash_new(); write = rb_hash_new(); misc = rb_hash_new(); ret = rb_hash_new(); rb_hash_aset(ret, rb_str_new2("read"), read); rb_hash_aset(ret, rb_str_new2("write"), write); rb_hash_aset(ret, rb_str_new2("misc"), misc); // read CAP(read, "audio", read_cap, CDIO_DRIVE_CAP_READ_AUDIO); CAP(read, "cd-da", read_cap, CDIO_DRIVE_CAP_READ_CD_DA); CAP(read, "cd+g", read_cap, CDIO_DRIVE_CAP_READ_CD_G); CAP(read, "cd-r", read_cap, CDIO_DRIVE_CAP_READ_CD_R); CAP(read, "cd-rw", read_cap, CDIO_DRIVE_CAP_READ_CD_RW); CAP(read, "dvd-r", read_cap, CDIO_DRIVE_CAP_READ_DVD_R); CAP(read, "dvr+r", read_cap, CDIO_DRIVE_CAP_READ_DVD_PR); CAP(read, "dvd-ram", read_cap, CDIO_DRIVE_CAP_READ_DVD_RAM); CAP(read, "dvd-rom", read_cap, CDIO_DRIVE_CAP_READ_DVD_ROM); CAP(read, "dvd-rw", read_cap, CDIO_DRIVE_CAP_READ_DVD_RW); CAP(read, "dvd+rw", read_cap, CDIO_DRIVE_CAP_READ_DVD_RPW); CAP(read, "c2_errs", read_cap, CDIO_DRIVE_CAP_READ_C2_ERRS); CAP(read, "mode2_form1", read_cap, CDIO_DRIVE_CAP_READ_MODE2_FORM1); CAP(read, "mode2_form2", read_cap, CDIO_DRIVE_CAP_READ_MODE2_FORM2); CAP(read, "mcn", read_cap, CDIO_DRIVE_CAP_READ_MCN); CAP(read, "isrc", read_cap, CDIO_DRIVE_CAP_READ_ISRC); // write CAP(write, "cd-r", write_cap, CDIO_DRIVE_CAP_WRITE_CD_R); CAP(write, "cd-rw", write_cap, CDIO_DRIVE_CAP_WRITE_CD_RW); CAP(write, "dvd-r", write_cap, CDIO_DRIVE_CAP_WRITE_DVD_R); CAP(write, "dvd+r", write_cap, CDIO_DRIVE_CAP_WRITE_DVD_PR); CAP(write, "dvd-ram", write_cap, CDIO_DRIVE_CAP_WRITE_DVD_RAM); CAP(write, "dvd-rw", write_cap, CDIO_DRIVE_CAP_WRITE_DVD_RW); CAP(write, "dvd+rw", write_cap, CDIO_DRIVE_CAP_WRITE_DVD_RPW); CAP(write, "mount_rainier", write_cap, CDIO_DRIVE_CAP_WRITE_MT_RAINIER); CAP(write, "burn_proof", write_cap, CDIO_DRIVE_CAP_WRITE_BURN_PROOF); CAP(write, "cd", write_cap, CDIO_DRIVE_CAP_WRITE_CD); CAP(write, "dvd", write_cap, CDIO_DRIVE_CAP_WRITE_DVD); // misc CAP(misc, "close_tray", misc_cap, CDIO_DRIVE_CAP_MISC_CLOSE_TRAY); CAP(misc, "eject", misc_cap, CDIO_DRIVE_CAP_MISC_EJECT); CAP(misc, "lock", misc_cap, CDIO_DRIVE_CAP_MISC_LOCK); CAP(misc, "select_speed", misc_cap, CDIO_DRIVE_CAP_MISC_SELECT_SPEED); CAP(misc, "select_disk", misc_cap, CDIO_DRIVE_CAP_MISC_SELECT_DISC); CAP(misc, "multi_session", misc_cap, CDIO_DRIVE_CAP_MISC_MULTI_SESSION); CAP(misc, "media_changed", misc_cap, CDIO_DRIVE_CAP_MISC_MEDIA_CHANGED); CAP(misc, "reset", misc_cap, CDIO_DRIVE_CAP_MISC_RESET); CAP(misc, "file", misc_cap, CDIO_DRIVE_CAP_MISC_FILE); return ret; } #undef CAP VALUE get_cdtext(const cdtext_t * cdtext) { if (NULL == cdtext) { return Qnil; } else { VALUE ret; ret = rb_hash_new(); int i; for (i = 0; i < MAX_CDTEXT_FIELDS; i++) { if (cdtext->field[i]) { rb_hash_aset(ret, rb_str_new2(cdtext_field2str(i)), rb_str_new2(cdtext->field[i])); } } return ret; } } /** * true if track is iso */ bool _cdio_cd_is_iso(CdIo * p_cdio, track_t track) { cdio_fs_anal_t fs; cdio_iso_analysis_t iso_analysis; fs = cdio_guess_cd_type(p_cdio, 0, track, &iso_analysis); switch (CDIO_FSTYPE(fs)) { case CDIO_FS_ISO_9660: case CDIO_FS_ISO_9660_INTERACTIVE: case CDIO_FS_ISO_HFS: case CDIO_FS_ISO_UDF: return true; default: return false; } } /** * Returns an object CdIo::Track or a subclass, with an object CdIo::Cd and * a track number * @param CdIo::Cd object * @param track * @return CdIo::Track */ VALUE get_track(VALUE cd, track_t i) { GET_CDIO(cd, p_cdio); // printf("get_track 1:%d\n",i); VALUE track; track_format_t format = cdio_get_track_format(p_cdio, i); VALUE argv[2]; argv[0] = cd; argv[1] = INT2FIX(i); // printf("get_track 2:%d\n",FIX2INT(argv[1])); if (_cdio_cd_is_iso(p_cdio, i)) { return rb_class_new_instance(2, argv, cCdIoTrackIso9660); } else if (TRACK_FORMAT_AUDIO == format) { return rb_class_new_instance(2, argv, cCdIoTrackCdda); } else { return rb_class_new_instance(2, argv, cCdIoTrack); } } void verify_return_code(driver_return_code_t rc) { switch (rc) { case DRIVER_OP_SUCCESS: break; case DRIVER_OP_ERROR: rb_raise(eCdIoError, "Operation returned an error"); break; case DRIVER_OP_UNSUPPORTED: rb_raise(eCdIoUnsupported, "Driver doesn't support feature"); break; case DRIVER_OP_UNINIT: rb_raise(eCdIoUnitit, "driver hasn't been initialized"); break; case DRIVER_OP_NOT_PERMITTED: rb_raise(eCdIoNotPermitted, "Operation not permitted."); break; case DRIVER_OP_BAD_PARAMETER: rb_raise(eCdIoBadParameter, "Bad parameter (library bug, probably)"); break; case DRIVER_OP_BAD_POINTER: rb_raise(eCdIoBadPointer, "Bad pointer (library bug, probably)"); break; case DRIVER_OP_NO_DRIVER: rb_raise(eCdIoNoDriver, "Operaton called on a driver not available on this OS"); break; } }