Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add $track->get_track_isrc. Commit changes to return array ref or arr…

…ay based on wantarray. DeviceList_t maps to returning an array reference rather than an array. Change all due to jerry geiger.
  • Loading branch information...
commit 66b12c85556a0d0671442ed7a8c32d4e1bf6d769 1 parent 4d6e00f
R. Bernstein authored
2  THANKS
View
@@ -10,7 +10,9 @@ Many thanks to Jerry G Geiger for resurrecting this project from the dead. He ad
- get_disk_cdtext
- get_joliet_level
- get_track_cdtext
+- get_track_isrc
- is_tray_open
+- example/checkcd.pl to show CD characteristics
He also fixed Build.PL so it works again and added many corrections to
my faulty C interface code.;
3  examples/README
View
@@ -9,6 +9,9 @@ audio.pl show mostly audio (analog) controls. Can be used to play
cdchange.pl: A program to test if a CD has been changed since the last
change test.
+checkcd.pl: A program to show properties of a CD such as the CD type
+ (audio CD, ISO 9660, UDF).
+
device.pl A program to show drive capabilities..
Various drives on various OS/s may or may not report
information correctly. (Perhaps someday libcdio will figure
17 examples/checkcd.pl
View
@@ -134,24 +134,17 @@
$fst_track->set_track($i)->get_lba;
$secs = int($secs/75);
my $ctrack = $fst_track->set_track($i);
- # printf " (%d:%02d)\n %d channels, %s, copy: %s, ISRC: %s\n",
- printf " (%d:%02d)\n %d channels, %s, copy: %s\n",
+ printf " (%d:%02d)\n %d channels, %s, copy: %s, ISRC: %s\n",
int($secs/60),$secs%60,
$ctrack->get_audio_channels,
$ctrack->get_preemphasis,
- #perlcdio::get_track_preemphasis($dev->{cd}, $i)?'pre-emphasis':'',
- $ctrack->get_copy_permit?'yes':'no'
- ;
- # FIXME:
- # ,
- # $ctrack->get_track_isrc;
+ $ctrack->get_copy_permit?'yes':'no',
+ $ctrack->get_track_isrc;
}
next if $hash->{cdio_fs_t}==1;
- # FIXME:
- # printf " %s ISRC: %s\n", $fst_track->set_track($i)->is_track_green,
- # $fst_track->set_track($i)->get_track_isrc;
- printf " %s\n", $fst_track->set_track($i)->is_track_green;
+ printf " %s ISRC: %s\n", $fst_track->set_track($i)->is_track_green,
+ $fst_track->set_track($i)->get_track_isrc;
foreach my $k ('cdio_fs_t','isofs_size', 'iso_label','UDFVerMajor',
'UDFVerMinor') {
26 lib/Device/Cdio.pm
View
@@ -24,9 +24,9 @@ can use this library.
use Device::Cdio;
use Device::Cdio::Device;
- @cd_drives = Device::Cdio::get_devices($perlcdio::DRIVER_DEVICE);
- @cd_drives = Device::Cdio::get_devices_with_cap($perlcdio::FS_AUDIO, 0);
- foreach my $drive (@cd_drives) {
+ $cd_drives = Device::Cdio::get_devices($perlcdio::DRIVER_DEVICE);
+ $cd_drives = Device::Cdio::get_devices_with_cap($perlcdio::FS_AUDIO, 0);
+ foreach my $drive (@$cd_drives) {
print "Drive $drive\n";
}
foreach my $driver_name (sort keys(%Device::Cdio::drivers)) {
@@ -232,7 +232,7 @@ sub get_default_device_driver {
=head2 get_devices
-get_devices(driver_id=$Cdio::DRIVER_UNKNOWN)->@devices
+$revices = get_devices(driver_id=$Cdio::DRIVER_UNKNOWN);
Return an array of device names. If you want a specific devices for a
driver, give that device. If you want hardware devices, give
@@ -251,7 +251,8 @@ sub get_devices {
my($driver_id, @args) = _rearrange(['DRIVER_ID'], @p);
return undef if _extra_args(@args);
$driver_id = $perlcdio::DRIVER_DEVICE if !defined($driver_id);
- return perlcdio::get_devices($driver_id);
+ my $ret = perlcdio::get_devices($driver_id);
+ return wantarray ? @$ret : $ret;
}
=pod
@@ -273,14 +274,15 @@ sub get_devices_ret {
my($driver_id, @args) = _rearrange(['DRIVER_ID'], @p);
return undef if _extra_args(@args);
$driver_id = $perlcdio::DRIVER_DEVICE if !defined($driver_id);
- return perlcdio::get_devices_ret($driver_id);
+ my $ret = perlcdio::get_devices_ret($driver_id);
+ return wantarray ? @$ret : $ret;
}
=pod
=head2 get_devices_with_cap
-get_devices_with_cap($capabilities, $any)->@devices
+$devices = get_devices_with_cap($capabilities, $any);
Get an array of device names in search_devices that have at least
the capabilities listed by the capabilities parameter.
@@ -303,7 +305,8 @@ sub get_devices_with_cap {
my($cap, $any, @args) = _rearrange(['CAPABILITIES', 'ANY'], @p);
return undef if _extra_args(@args);
$any = 1 if !defined($any);
- return perlcdio::get_devices_with_cap($cap, $any);
+ my $ret = perlcdio::get_devices_with_cap($cap, $any);
+ return wantarray ? @$ret : $ret;
}
=pod
@@ -322,11 +325,8 @@ sub get_devices_with_cap_ret {
my($cap, $any, @args) = _rearrange(['CAPABILITIES', 'ANY'], @p);
return undef if _extra_args(@args);
$any = 1 if !defined($any);
- # There's a bug in the swig code in that the input parameters
- # are left on the stack
- my @ret = perlcdio::get_devices_with_cap($cap, $any);
- shift @ret; shift @ret;
- return @ret;
+ my $ret = perlcdio::get_devices_with_cap($cap, $any);
+ return wantarray ? @$ret : $ret;
}
=pod
11 lib/Device/Cdio/Device.pm
View
@@ -384,12 +384,8 @@ An exception is raised if we had an error.
sub get_hwinfo {
my($self,@p) = @_;
return $perlcdio::BAD_PARAMETER if !_check_arg_count($#_, 0);
- # There's a bug I don't understand where p_cdio gets returned
- # and it shouldn't. So we just ignore that below.
- # changed by jerry to overwrite the argument $self->{cd}
- my ($vendor, $model, $release, $drc) =
- perlcdio::get_hwinfo($self->{cd});
- return ($vendor, $model, $release, $drc);
+ my ($hwinfo, $drc) = perlcdio::get_hwinfo($self->{cd});
+ return (@$hwinfo, $drc);
}
=pod
@@ -407,8 +403,7 @@ See perlcdio::driver_errmsg($rc) if $rc.
sub audio_get_volume {
my($self,@p) = @_;
my ($vol,$drc) = perlcdio::audio_get_volume_levels($self->{cd});
- return ($vol,$drc) if wantarray;
- return $drc;
+ return wantarray ? ($vol,$drc) : $drc;
}
=pod
37 lib/Device/Cdio/Track.pm
View
@@ -1,7 +1,6 @@
package Device::Cdio::Track;
require 5.8.6;
#
-# $Id$
# See end for copyright and license.
### CD Input and control track class
@@ -224,11 +223,11 @@ sub get_preemphasis {
my ($self, @p) = @_;
return 0 if !_check_arg_count($#_, 0);
my $rc = perlcdio::get_track_preemphasis($self->{device}, $self->{track});
- if ($rc == $perlcdio::TRACK_FLAG_FALSE) {
- return 'none';
- } elsif ($rc == $perlcdio::TRACK_FLAG_TRUE) {
- return 'preemphasis';
- } elsif ($rc == $perlcdio::TRACK_FLAG_UNKNOWN) {
+ if ($rc == $perlcdio::CDIO_TRACK_FLAG_FALSE) {
+ return 'no pre-emphasis';
+ } elsif ($rc == $perlcdio::CDIO_TRACK_FLAG_TRUE) {
+ return 'pre-emphasis';
+ } elsif ($rc == $perlcdio::CDIO_TRACK_FLAG_UNKNOWN) {
return 'unknown';
} else {
return 'invalid';
@@ -275,6 +274,32 @@ sub is_track_green {
return perlcdio::is_track_green($self->{device}, $self->{track});
}
+=pod
+
+=head2 get_track_isrc
+
+$isrc = $track->get_track_isrc;
+
+Returns an empty string or the International Standard Recording Code.
+Which is presented in 4 hyphen seperated substrings: "CC-XXX-YY-NNNNN"
+
+"CC" two-character ISO 3166-1 alpha-2 country code
+"XXX" is a three character alphanumeric registrant code
+"YY" is the last two digits of the year of registration
+ (NB not necessarily the date the recording was made)
+"NNNNN" is a unique 5-digit number identifying the particular sound recording.
+
+=cut
+
+sub get_track_isrc {
+ my ($self, @p) = @_;
+ my $isrc = perlcdioc::cdio_get_track_isrc($self->{device}, $self->{track});
+ if(!$isrc) {
+ $isrc = perlmmcc::mmc_get_isrc($self->{device}, $self->{track});
+ }
+ $isrc =~ s/(\w\w)(\w\w\w)(\w\w)(\w+)/$1-$2-$3-$4/; #"CC-XXX-YY-NNNNN"
+ return $isrc;
+}
=pod
=head2 set_track
114 swig/device.swg
View
@@ -28,40 +28,40 @@ typedef char ** DeviceList_t;
%}
%typemap(out) DeviceList_t {
- // $1 is of type DeviceList_t
- char **p = result;
- unsigned int num = 0;
-
- if (!result) goto out;
-
- /* Figure out how many items in the array */
- for (p = $1; *p; p++) {
- num++;
- }
-
- if (num+argvi >= items) {
- /* Extend the stack by (num - items) objects */
- EXTEND(sp, num-items);
- }
- /* For each element in the array of strings, create a new
- * mortalscalar, and stuff it into the above array. */
- for (num=0,p = $1; *p; p++) {
- /* Have perl compute the length of the string using strlen() */
- //PUSHs(sv_2mortal(newSVpv(*p, 0))); // uses SP, modified by dSP (XS)
- ST(num++)=(sv_2mortal(newSVpv(*p, 0)));
- }
- /* FIXME: the + 1 is because p_cdio is still on the stack. */
- argvi += num; // fixed ??
- /* For each element in the array of strings, create a new
- * mortalscalar, and stuff it into the above array.
- for (p = $1; *p; p++) {
- Have perl compute the length of the string using strlen()
- XPUSHs(sv_2mortal(newSVpv(*p, 0)));
- }
- argvi = num;
+ /* char ** to array SVp*/
+ /*
+ AV *myav;
+ SV **svs;
+ int i = 0,len = 0;
+ */
+ /* Figure out how many elements we have */
+ /*
+ while ($1[len])
+ len++;
+ svs = (SV **) malloc(len*sizeof(SV *));
+ for (i = 0; i < len ; i++) {
+ svs[i] = sv_newmortal();
+ sv_setpv((SV*)svs[i],$1[i]);
+ //svs[i] = sv_2mortal((SV*)newSVpv($1[i], 0));
+ };
+ myav = av_make(len,svs);
+ free(svs);
+ $result = newRV_noinc((SV*)myav);
+ sv_2mortal($result);
*/
+ // or: shorter version
+ AV *myav;
+ int i =0;
+ myav = newAV();
+ char **p = $1;
+ while (*p) {
+ av_store(myav, i, (SV*)newSVpv(*p, 0));
+ i++;p++;
+ }
+ $result = newRV_noinc((SV*)myav);
+ sv_2mortal($result);
+ argvi++;
cdio_free_device_list($1);
- out: ;
}
/*
@@ -262,8 +262,6 @@ DeviceList_t get_devices_with_cap (unsigned int capabilities, bool b_any);
%inline %{
DeviceList_t
get_devices_with_cap (unsigned int capabilities, bool b_any) {
- /* FIXME: ? libcdio allows one to specify a list (char **) of devices
- to search. Don't know how to do that via SWIG though. */
return cdio_get_devices_with_cap (NULL, (cdio_fs_anal_t) capabilities,
b_any);
}
@@ -282,8 +280,6 @@ DeviceList_t get_devices_with_cap_ret (unsigned int capabilities, bool b_any,
DeviceList_t
get_devices_with_cap_ret (unsigned int capabilities, bool b_any,
driver_id_t *p_out_driver_id) {
- /* FIXME: ? libcdio allows one to specify a list (char **) of devices
- to search. Don't know how to do that via SWIG though. */
return cdio_get_devices_with_cap_ret (NULL,
(cdio_fs_anal_t) capabilities, b_any,
p_out_driver_id);
@@ -430,31 +426,29 @@ int cdio_get_media_changed(CdIo_t *p_cdio);
%inline %{
typedef char ** HWInfo_t;
%}
-
-%typemap(out) HWInfo_t { // All functions returning char **
- // get this typemap
- // $1 is of type char **
- char **p = $1;
- unsigned int num = 0;
-
- /* Figure out how many items in the array */
- for (p = $1; *p; p++) {
- num++;
- }
-
- if (num+argvi >= items) {
- /* Extend the stack by (num - items) objects */
- EXTEND(sp, num-items);
- }
- /* For each element in the array of strings, create a new
- * mortalscalar, and stuff it into the above array. */
- for (num=0,p = $1; *p; p++) {
- /* Have perl compute the length of the string using strlen() */
- //PUSHs(sv_2mortal(newSVpv(*p, 0))); // uses SP, modified by dSP (XS)
- ST(num++)=(sv_2mortal(newSVpv(*p, 0)));
+%typemap(out) HWInfo_t {
+ /* char ** to array SVp*/
+ AV *myav;
+ SV **svs;
+ int i = 0,len = 0;
+ /* no test
+ if(!$1) {
+ $result = newSV(0);
}
- /* FIXME: the + 1 is because p_cdio is still on the stack. */
- argvi += num; // fixed ??
+ */
+ /* Figure out how many elements we have */
+ while ($1[len])
+ len++;
+ svs = (SV **) malloc(len*sizeof(SV *));
+ for (i = 0; i < len ; i++) {
+ svs[i] = sv_newmortal();
+ sv_setpv((SV*)svs[i],$1[i]);
+ };
+ myav = av_make(len,svs);
+ free(svs);
+ $result = newRV_noinc((SV*)myav);
+ sv_2mortal($result);
+ argvi++;
}
/*
15 swig/perlmmc.swg
View
@@ -481,6 +481,21 @@ int mmc_start_stop_unit (const CdIo_t *p_cdio);
to eject media / open tray. mmc_eject_media sometimes does not work.");
int mmc_close_tray(CdIo_t *p_cdio);
+
+char * mmc_get_isrc(const CdIo_t *p_cdio, track_t track);
+%inline %{
+char * mmc_get_isrc(const CdIo_t *p_cdio, track_t track) {
+ static cdio_isrc_t isrc;
+ bzero(isrc, sizeof(isrc));
+ int status;
+
+ status = mmc_isrc_track_read_subchannel (p_cdio, track, isrc);
+ if(status != DRIVER_OP_SUCCESS)
+ *isrc = '\0';
+ return isrc;
+}
+%}
+
%perlcode %{
import Device::Cdio::VERSION;
3  swig/track.swg
View
@@ -204,4 +204,5 @@ const char
}
%}
-
+char * cdio_get_track_isrc(const CdIo_t *p_cdio, track_t i_track);
+
Please sign in to comment.
Something went wrong with that request. Please try again.