00001 #include "audiere.h"
00002 #include "internal.h"
00003 #include "mci_device.h"
00004 #include "utility.h"
00005
00006
00007 namespace audiere {
00008
00009 class CDDeviceWin32 : public RefImplementation<CDDevice>, public MCIDevice {
00010 public:
00011 CDDeviceWin32(const char* name)
00012 : MCIDevice(std::string(name) + "\\")
00013 {
00014 m_name = name;
00015
00016 sendCommand("open", "type cdaudio");
00017
00018
00019 sendCommand("set", "time format tmsf");
00020 }
00021
00022 ~CDDeviceWin32() {
00023 stop();
00024 }
00025
00026 const char* ADR_CALL getName() {
00027 return m_name.c_str();
00028 }
00029
00030 int ADR_CALL getTrackCount() {
00031 return atoi(sendCommand("status", "number of tracks").c_str());
00032 }
00033
00034 void ADR_CALL play(int track) {
00035 char from[1000];
00036 char to[1000];
00037 sprintf(from, "%d:00:00:00", track + 1);
00038 sprintf(to, "%d:00:00:00", track + 2);
00039
00040 sendCommand("play", std::string("from ") + from + " to " + to);
00041 }
00042
00043 void ADR_CALL stop() {
00044 sendCommand("stop");
00045 sendCommand("seek", "to start");
00046 }
00047
00048 void ADR_CALL pause() {
00049 sendCommand("pause");
00050 }
00051
00052 void ADR_CALL resume() {
00053 sendCommand("resume");
00054 }
00055
00056 bool ADR_CALL isPlaying() {
00057 std::string status = sendCommand("status", "mode");
00058 return strcmp_case(status.c_str(), "playing") == 0;
00059 }
00060
00061 bool ADR_CALL containsCD() {
00062 std::string status = sendCommand("status", "media present");
00063 return strcmp_case(status.c_str(), "true") == 0;
00064 }
00065
00066 bool ADR_CALL isDoorOpen() {
00067 std::string status = sendCommand("status", "mode");
00068 return strcmp_case(status.c_str(), "open") == 0;
00069 }
00070
00071 void ADR_CALL openDoor() {
00072 sendCommand("set", "door open");
00073 }
00074
00075 void ADR_CALL closeDoor() {
00076 sendCommand("set", "door closed");
00077 }
00078
00079 private:
00080 std::string m_name;
00081 };
00082
00083
00084 namespace hidden {
00085
00086 ADR_EXPORT(const char*) AdrEnumerateCDDevices() {
00087
00088 static char devices[26 * 3];
00089 char* out = devices;
00090
00091 for (char device = 'A'; device <= 'Z'; ++device) {
00092 char name[] = {device, ':', 0};
00093 UINT type = GetDriveType(name);
00094 if (type == DRIVE_CDROM) {
00095 *out++ = device;
00096 *out++ = ':';
00097 *out++ = 0;
00098 }
00099 }
00100
00101 return devices;
00102 }
00103
00104 ADR_EXPORT(CDDevice*) AdrOpenCDDevice(const char* name) {
00105 if (GetDriveType(name) == DRIVE_CDROM) {
00106 return new CDDeviceWin32(name);
00107 } else {
00108 return 0;
00109 }
00110 }
00111
00112 }
00113
00114 }