1 ////////////////////////////////////////////////////////////////////////////////
4 // Author: Guilhem Lavaux
7 // Copyright: (C) 1997, 1998, Guilhem Lavaux
8 // License: wxWindows license
9 ////////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "cdwin.h"
14 #include "wx/wxprec.h"
26 // ---------------------------------------------------------------------------
28 // ---------------------------------------------------------------------------
34 // ---------------------------------------------------------------------------
36 // ---------------------------------------------------------------------------
38 #define WXMMEDIA_INTERNAL
39 #include "wx/mmedia/cdbase.h"
40 #include "wx/mmedia/cdwin.h"
42 // ---------------------------------------------------------------------------
44 // ---------------------------------------------------------------------------
46 IMPLEMENT_DYNAMIC_CLASS(wxCDAudioWin
, wxCDAudio
)
48 wxCDAudioWin::wxCDAudioWin(void)
49 : wxCDAudio(), m_trksize(NULL
), m_trkpos(NULL
), m_toc(NULL
), m_ok(TRUE
)
51 MCI_OPEN_PARMS open_struct
;
52 MCI_SET_PARMS set_struct
;
54 m_internal
= new CDAW_Internal
;
55 open_struct
.lpstrDeviceType
= _T("cdaudio");
56 DWORD ret
= mciSendCommand((MCIDEVICEID
)NULL
, MCI_OPEN
, MCI_OPEN_TYPE
,
62 m_internal
->dev_id
= open_struct
.wDeviceID
;
64 set_struct
.dwTimeFormat
= MCI_FORMAT_MSF
;
65 mciSendCommand(m_internal
->dev_id
, MCI_SET
, MCI_SET_TIME_FORMAT
,
66 (DWORD
)(LPVOID
)&set_struct
);
70 set_struct
.dwTimeFormat
= MCI_FORMAT_TMSF
;
71 mciSendCommand(m_internal
->dev_id
, MCI_SET
, MCI_SET_TIME_FORMAT
,
72 (DWORD
)(LPVOID
)&set_struct
);
75 wxCDAudioWin::~wxCDAudioWin(void)
78 mciSendCommand(m_internal
->dev_id
, MCI_CLOSE
, 0,(DWORD_PTR
)NULL
);
86 void wxCDAudioWin::PrepareToc(void)
88 MCI_STATUS_PARMS status_struct
;
89 wxUint16 i
, nb_m_trksize
;
90 wxCDtime total_time
, *trk
;
96 status_struct
.dwItem
= MCI_STATUS_NUMBER_OF_TRACKS
;
97 mciSendCommand(m_internal
->dev_id
, MCI_STATUS
, MCI_STATUS_ITEM
,
98 (DWORD
)&status_struct
);
99 nb_m_trksize
= status_struct
.dwReturn
;
101 m_trksize
= new wxCDtime
[nb_m_trksize
+1];
102 m_trkpos
= new wxCDtime
[nb_m_trksize
+1];
104 status_struct
.dwItem
= MCI_STATUS_LENGTH
;
105 mciSendCommand(m_internal
->dev_id
, MCI_STATUS
, MCI_STATUS_ITEM
,
106 (DWORD
)&status_struct
);
107 total_time
.track
= nb_m_trksize
;
108 tmem
= status_struct
.dwReturn
;
109 total_time
.min
= MCI_MSF_MINUTE(tmem
);
110 total_time
.sec
= MCI_MSF_SECOND(tmem
);
111 total_time
.hour
= total_time
.min
/ 60;
112 total_time
.min
%= 60;
114 for (i
=1;i
<=nb_m_trksize
;i
++) {
115 status_struct
.dwItem
= MCI_STATUS_POSITION
;
116 status_struct
.dwTrack
= i
;
117 mciSendCommand(m_internal
->dev_id
, MCI_STATUS
,
118 MCI_STATUS_ITEM
| MCI_TRACK
,
119 (DWORD
)(LPVOID
)&status_struct
);
120 tmem
= status_struct
.dwReturn
;
124 trk
->min
= MCI_MSF_MINUTE(tmem
);
125 trk
->sec
= MCI_MSF_SECOND(tmem
);
126 trk
->hour
= trk
->min
/ 60;
129 status_struct
.dwItem
= MCI_STATUS_LENGTH
;
130 status_struct
.dwTrack
= i
;
131 mciSendCommand(m_internal
->dev_id
, MCI_STATUS
,
132 MCI_STATUS_ITEM
| MCI_TRACK
,
133 (DWORD
)(LPVOID
)&status_struct
);
134 tmem
= status_struct
.dwReturn
;
138 trk
->min
= MCI_MSF_MINUTE(tmem
);
139 trk
->sec
= MCI_MSF_SECOND(tmem
);
140 trk
->hour
= trk
->min
/ 60;
144 m_toc
= new CDtoc(total_time
, m_trksize
, m_trkpos
);
147 bool wxCDAudioWin::Play(const wxCDtime
& beg_time
, const wxCDtime
& end_time
)
150 MCI_PLAY_PARMS play_struct
;
155 tmsf
= MCI_MAKE_TMSF(beg_time
.track
, beg_time
.min
,
157 play_struct
.dwFrom
= tmsf
;
158 tmsf
= MCI_MAKE_TMSF(end_time
.track
, end_time
.min
,
160 play_struct
.dwTo
= tmsf
;
162 mciSendCommand(m_internal
->dev_id
, MCI_PLAY
, 0, (DWORD
)&play_struct
);
166 bool wxCDAudioWin::Pause(void)
171 return (mciSendCommand(m_internal
->dev_id
, MCI_PAUSE
, 0, 0) == 0);
174 bool wxCDAudioWin::Resume(void)
179 return (mciSendCommand(m_internal
->dev_id
, MCI_RESUME
, 0, 0) == 0);
182 wxCDAudio::CDstatus
wxCDAudioWin::GetStatus(void)
184 MCI_STATUS_PARMS status_struct
;
189 status_struct
.dwItem
= MCI_STATUS_MODE
;
190 mciSendCommand(m_internal
->dev_id
, MCI_STATUS
, MCI_STATUS_ITEM
,
191 (DWORD
)&status_struct
);
192 switch (status_struct
.dwReturn
) {
201 wxCDtime
wxCDAudioWin::GetTime(void)
203 MCI_STATUS_PARMS status_struct
;
204 wxCDtime cd_time
= {0,0,0,0};
209 status_struct
.dwItem
= MCI_STATUS_TIME_FORMAT
;
210 mciSendCommand(m_internal
->dev_id
, MCI_STATUS
, MCI_STATUS_ITEM
,
211 (DWORD
)&status_struct
);
212 cd_time
.track
= MCI_TMSF_TRACK(status_struct
.dwReturn
);
213 cd_time
.min
= MCI_TMSF_MINUTE(status_struct
.dwReturn
);
214 cd_time
.sec
= MCI_TMSF_SECOND(status_struct
.dwReturn
);
215 cd_time
.hour
= cd_time
.min
/ 60;
220 const wxCDAudio::CDtoc
& wxCDAudioWin::GetToc(void)