- if (WIFEXITED($status)) {
- if (($status = WEXITSTATUS($status)) != 0) {
- die("$command exited with status $status");
+ my $mb = MusicBrainz::Client->new;
+ defined($device) and $mb->set_device($device);
+
+ $mb->query(MBQ_GetCDTOC) or die($mb->get_query_error);
+
+ open(my $fh, '>cue') or die("open('>cue'): $!");
+ print($fh "FILE \"dummy.wav\" WAVE\n");
+ print($fh " TRACK 01 AUDIO\n");
+ print($fh " INDEX 01 00:00:00\n");
+
+ my $first = $mb->get_result_data(MBE_TOCGetFirstTrack) + 1;
+ $trackcount = min($trackcount, $mb->get_result_data(MBE_TOCGetLastTrack));
+ # There is frequently (always?) an offset of 150 sectors, so
+ # we'll subtract this offset from each track offset.
+ my $something = $mb->get_result_data1(MBE_TOCGetTrackSectorOffset, 2);
+
+ for my $track ($first .. $trackcount) {
+ my $off = $mb->get_result_data1(MBE_TOCGetTrackSectorOffset, $track+1);
+ $off -= $something;
+
+ my ($minutes,$seconds)=(0,0);
+ my $sectors = $off % 75;
+ if ($off >= 75) {
+ $seconds = $off / 75;
+ if ($seconds >= 60) {
+ $minutes = $seconds / 60;
+ $seconds = $seconds % 60;
+ }