1 ////////////////////////////////////////////////////////////////////////////////
4 // Author: Guilhem Lavaux
7 // Copyright: (C) 1997, 1998, Guilhem Lavaux
8 // License: wxWindows license
9 ////////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "cdwin.h"
18 #include "wx/wxprec.h"
22 #define WXMMEDIA_INTERNAL
31 wxCDAudioWin::wxCDAudioWin(void)
32 : wxCDAudio(), m_trksize(NULL
), m_trkpos(NULL
), m_ok(TRUE
), m_toc(NULL
)
34 MCI_OPEN_PARMS open_struct
;
35 MCI_SET_PARMS set_struct
;
38 m_internal
= new CDAW_Internal
;
39 open_struct
.lpstrDeviceType
= "cdaudio";
40 ret
= mciSendCommand(NULL
, MCI_OPEN
, MCI_OPEN_TYPE
,
46 m_internal
->dev_id
= open_struct
.wDeviceID
;
48 set_struct
.dwTimeFormat
= MCI_FORMAT_MSF
;
49 ret
= mciSendCommand(m_internal
->dev_id
, MCI_SET
, MCI_SET_TIME_FORMAT
,
50 (DWORD
)(LPVOID
)&set_struct
);
54 set_struct
.dwTimeFormat
= MCI_FORMAT_TMSF
;
55 ret
= mciSendCommand(m_internal
->dev_id
, MCI_SET
, MCI_SET_TIME_FORMAT
,
56 (DWORD
)(LPVOID
)&set_struct
);
59 wxCDAudioWin::~wxCDAudioWin(void)
62 mciSendCommand(m_internal
->dev_id
, MCI_CLOSE
, 0, NULL
);
70 void wxCDAudioWin::PrepareToc(void)
72 MCI_STATUS_PARMS status_struct
;
73 MCI_SET_PARMS set_struct
;
74 wxUint16 i
, nb_m_trksize
;
75 wxCDtime total_time
, *trk
;
81 status_struct
.dwItem
= MCI_STATUS_NUMBER_OF_TRACKS
;
82 ret
= mciSendCommand(m_internal
->dev_id
, MCI_STATUS
, MCI_STATUS_ITEM
,
83 (DWORD
)&status_struct
);
84 nb_m_trksize
= status_struct
.dwReturn
;
86 m_trksize
= new wxCDtime
[nb_m_trksize
+1];
87 m_trkpos
= new wxCDtime
[nb_m_trksize
+1];
89 status_struct
.dwItem
= MCI_STATUS_LENGTH
;
90 ret
= mciSendCommand(m_internal
->dev_id
, MCI_STATUS
, MCI_STATUS_ITEM
,
91 (DWORD
)&status_struct
);
92 total_time
.track
= nb_m_trksize
;
93 tmem
= status_struct
.dwReturn
;
94 total_time
.min
= MCI_MSF_MINUTE(tmem
);
95 total_time
.sec
= MCI_MSF_SECOND(tmem
);
96 total_time
.hour
= total_time
.min
/ 60;
99 for (i
=1;i
<=nb_m_trksize
;i
++) {
100 status_struct
.dwItem
= MCI_STATUS_POSITION
;
101 status_struct
.dwTrack
= i
;
102 ret
= mciSendCommand(m_internal
->dev_id
, MCI_STATUS
,
103 MCI_STATUS_ITEM
| MCI_TRACK
,
104 (DWORD
)(LPVOID
)&status_struct
);
105 tmem
= status_struct
.dwReturn
;
109 trk
->min
= MCI_MSF_MINUTE(tmem
);
110 trk
->sec
= MCI_MSF_SECOND(tmem
);
111 trk
->hour
= trk
->min
/ 60;
114 status_struct
.dwItem
= MCI_STATUS_LENGTH
;
115 status_struct
.dwTrack
= i
;
116 ret
= mciSendCommand(m_internal
->dev_id
, MCI_STATUS
,
117 MCI_STATUS_ITEM
| MCI_TRACK
,
118 (DWORD
)(LPVOID
)&status_struct
);
119 tmem
= status_struct
.dwReturn
;
123 trk
->min
= MCI_MSF_MINUTE(tmem
);
124 trk
->sec
= MCI_MSF_SECOND(tmem
);
125 trk
->hour
= trk
->min
/ 60;
129 m_toc
= new CDtoc(total_time
, m_trksize
, m_trkpos
);
132 bool wxCDAudioWin::Play(const wxCDtime
& beg_time
, const wxCDtime
& end_time
)
135 MCI_PLAY_PARMS play_struct
;
140 tmsf
= MCI_MAKE_TMSF(beg_time
.track
, beg_time
.min
,
142 play_struct
.dwFrom
= tmsf
;
143 tmsf
= MCI_MAKE_TMSF(end_time
.track
, end_time
.min
,
145 play_struct
.dwTo
= tmsf
;
147 mciSendCommand(m_internal
->dev_id
, MCI_PLAY
, 0, (DWORD
)&play_struct
);
151 bool wxCDAudioWin::Pause(void)
156 return (mciSendCommand(m_internal
->dev_id
, MCI_PAUSE
, 0, 0) == 0);
159 bool wxCDAudioWin::Resume(void)
164 return (mciSendCommand(m_internal
->dev_id
, MCI_RESUME
, 0, 0) == 0);
167 wxCDAudio::CDstatus
wxCDAudioWin::GetStatus(void)
169 MCI_STATUS_PARMS status_struct
;
174 status_struct
.dwItem
= MCI_STATUS_MODE
;
175 mciSendCommand(m_internal
->dev_id
, MCI_STATUS
, MCI_STATUS_ITEM
,
176 (DWORD
)&status_struct
);
177 switch (status_struct
.dwReturn
) {
186 wxCDtime
wxCDAudioWin::GetTime(void)
188 MCI_STATUS_PARMS status_struct
;
189 wxCDtime cd_time
= {-1, -1, -1, -1};
194 status_struct
.dwItem
= MCI_STATUS_TIME_FORMAT
;
195 mciSendCommand(m_internal
->dev_id
, MCI_STATUS
, MCI_STATUS_ITEM
,
196 (DWORD
)&status_struct
);
197 cd_time
.track
= MCI_TMSF_TRACK(status_struct
.dwReturn
);
198 cd_time
.min
= MCI_TMSF_MINUTE(status_struct
.dwReturn
);
199 cd_time
.sec
= MCI_TMSF_SECOND(status_struct
.dwReturn
);
200 cd_time
.hour
= cd_time
.min
/ 60;
205 wxCDAudio::CDtoc
& wxCDAudioWin::GetToc(void)