1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
/* --------------------------------------------------------------------------
MusicBrainz -- The Internet music metadatabase
Copyright (C) 2000 Robert Kaye
Copyright (C) 1998 Jukka Poikolainen
Copyright (C) 1999 Marc E E van Woerkom
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: mb_os2.cpp,v 1.2 2000/09/22 14:15:03 robert Exp $
----------------------------------------------------------------------------*/
#include <os2mm.h>
#include <stdio.h>
#include <memory.h>
#include <shellapi.h>
#include "diskid.h"
MUSICBRAINZ_DEVICE DEFAULT_DEVICE = "0";
int ReadTOCHeader(int fd,
int& first,
int& last)
{
return 0;
}
int ReadTOCEntry(int fd,
int track,
int& lba)
{
return 0;
}
bool DiskId::ReadTOC(MUSICBRAINZ_DEVICE device,
MUSICBRAINZ_CDINFO& cdinfo)
{
UINT wDeviceID;
DWORD i;
MCI_OPEN_PARMS mciOpenParms;
MCI_SET_PARMS mciSetParms;
char err[256];
MCI_STATUS_PARMS mciStatusParms;
memset(&cdinfo, 0, sizeof(cdinfo));
if (device == NULL) {
mciOpenParms.lpstrDeviceType = "cdaudio";
if (mciSendCommand(NULL,
MCI_OPEN,
MCI_OPEN_TYPE,
(DWORD)(LPVOID) &mciOpenParms))
ReportError("Cannot open cdaudio device.");
return false;
}
else {
mciOpenParms.lpstrDeviceType = (LPSTR) MAKELONG(MCI_DEVTYPE_CD_AUDIO, atoi(device));
if (mciSendCommand(NULL,
MCI_OPEN,
MCI_OPEN_TYPE_ID | MCI_OPEN_TYPE,
(DWORD)(LPVOID) &mciOpenParms)) {
sprintf(err, "Cannot open device id %d.", atoi(device));
ReportError(err);
return false;
}
}
wDeviceID = mciOpenParms.wDeviceID;
mciSetParms.dwTimeFormat = MCI_FORMAT_MSF;
if (mciSendCommand(wDeviceID,
MCI_SET,
MCI_SET_TIME_FORMAT,
(DWORD)(LPVOID) &mciSetParms)) {
mciSendCommand(wDeviceID,
MCI_CLOSE,
0,
NULL);
ReportError("Cannot set time format for cd drive.");
return false;
}
mciStatusParms.dwItem = MCI_STATUS_NUMBER_OF_TRACKS;
if (mciSendCommand(wDeviceID,
MCI_STATUS,
MCI_STATUS_ITEM,
(DWORD)(LPVOID) &mciStatusParms)) {
mciSendCommand(wDeviceID,
MCI_CLOSE,
0,
NULL);
ReportError("Cannot get the cd drive status.");
return false;
}
cdinfo.FirstTrack = 1;
cdinfo.LastTrack = (BYTE) mciStatusParms.dwReturn;
for(i = 1; i <= cdinfo.LastTrack; i++) {
mciStatusParms.dwItem = MCI_STATUS_POSITION;
mciStatusParms.dwTrack = i;
if (mciSendCommand(wDeviceID,
MCI_STATUS,
MCI_STATUS_ITEM | MCI_TRACK,
(DWORD)(LPVOID) &mciStatusParms)) {
mciSendCommand(wDeviceID,
MCI_CLOSE,
0,
NULL);
ReportError("Cannot read table of contents.");
return false;
}
cdinfo.FrameOffset[i] = (DWORD) MCI_MSF_MINUTE(mciStatusParms.dwReturn) * 4500 +
(DWORD) MCI_MSF_SECOND(mciStatusParms.dwReturn) * 75 +
(DWORD) MCI_MSF_FRAME(mciStatusParms.dwReturn);
}
mciStatusParms.dwItem = MCI_STATUS_LENGTH;
mciStatusParms.dwTrack = cdinfo.LastTrack;
if (mciSendCommand(wDeviceID,
MCI_STATUS,
MCI_STATUS_ITEM | MCI_TRACK,
(DWORD) (LPVOID) &mciStatusParms)) {
mciSendCommand(wDeviceID,
MCI_CLOSE,
0,
NULL);
ReportError("Cannot read table of contents.");
return false;
}
cdinfo.FrameOffset[0] = cdinfo.FrameOffset[cdinfo.LastTrack] +
(DWORD) MCI_MSF_MINUTE(mciStatusParms.dwReturn) * 4500 +
(DWORD) MCI_MSF_SECOND(mciStatusParms.dwReturn) * 75 +
(DWORD) MCI_MSF_FRAME(mciStatusParms.dwReturn) + 1;
mciSendCommand(wDeviceID,
MCI_CLOSE,
0,
NULL);
return true;
}
|