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 wxCDAudioWin::wxCDAudioWin(void)
47 : wxCDAudio(), m_trksize(NULL
), m_trkpos(NULL
), m_ok(TRUE
), m_toc(NULL
)
49 MCI_OPEN_PARMS open_struct
;
50 MCI_SET_PARMS set_struct
;
53 m_internal
= new CDAW_Internal
;
54 open_struct
.lpstrDeviceType
= "cdaudio";
55 ret
= mciSendCommand(NULL
, MCI_OPEN
, MCI_OPEN_TYPE
,
61 m_internal
->dev_id
= open_struct
.wDeviceID
;
63 set_struct
.dwTimeFormat
= MCI_FORMAT_MSF
;
64 ret
= mciSendCommand(m_internal
->dev_id
, MCI_SET
, MCI_SET_TIME_FORMAT
,
65 (DWORD
)(LPVOID
)&set_struct
);
69 set_struct
.dwTimeFormat
= MCI_FORMAT_TMSF
;
70 ret
= mciSendCommand(m_internal
->dev_id
, MCI_SET
, MCI_SET_TIME_FORMAT
,
71 (DWORD
)(LPVOID
)&set_struct
);
74 wxCDAudioWin::~wxCDAudioWin(void)
77 mciSendCommand(m_internal
->dev_id
, MCI_CLOSE
, 0, NULL
);
85 void wxCDAudioWin::PrepareToc(void)
87 MCI_STATUS_PARMS status_struct
;
88 wxUint16 i
, nb_m_trksize
;
89 wxCDtime total_time
, *trk
;
95 status_struct
.dwItem
= MCI_STATUS_NUMBER_OF_TRACKS
;
96 ret
= mciSendCommand(m_internal
->dev_id
, MCI_STATUS
, MCI_STATUS_ITEM
,
97 (DWORD
)&status_struct
);
98 nb_m_trksize
= status_struct
.dwReturn
;
100 m_trksize
= new wxCDtime
[nb_m_trksize
+1];
101 m_trkpos
= new wxCDtime
[nb_m_trksize
+1];
103 status_struct
.dwItem
= MCI_STATUS_LENGTH
;
104 ret
= mciSendCommand(m_internal
->dev_id
, MCI_STATUS
, MCI_STATUS_ITEM
,
105 (DWORD
)&status_struct
);
106 total_time
.track
= nb_m_trksize
;
107 tmem
= status_struct
.dwReturn
;
108 total_time
.min
= MCI_MSF_MINUTE(tmem
);
109 total_time
.sec
= MCI_MSF_SECOND(tmem
);
110 total_time
.hour
= total_time
.min
/ 60;
111 total_time
.min
%= 60;
113 for (i
=1;i
<=nb_m_trksize
;i
++) {
114 status_struct
.dwItem
= MCI_STATUS_POSITION
;
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;
128 status_struct
.dwItem
= MCI_STATUS_LENGTH
;
129 status_struct
.dwTrack
= i
;
130 ret
= mciSendCommand(m_internal
->dev_id
, MCI_STATUS
,
131 MCI_STATUS_ITEM
| MCI_TRACK
,
132 (DWORD
)(LPVOID
)&status_struct
);
133 tmem
= status_struct
.dwReturn
;
137 trk
->min
= MCI_MSF_MINUTE(tmem
);
138 trk
->sec
= MCI_MSF_SECOND(tmem
);
139 trk
->hour
= trk
->min
/ 60;
143 m_toc
= new CDtoc(total_time
, m_trksize
, m_trkpos
);
146 bool wxCDAudioWin::Play(const wxCDtime
& beg_time
, const wxCDtime
& end_time
)
149 MCI_PLAY_PARMS play_struct
;
154 tmsf
= MCI_MAKE_TMSF(beg_time
.track
, beg_time
.min
,
156 play_struct
.dwFrom
= tmsf
;
157 tmsf
= MCI_MAKE_TMSF(end_time
.track
, end_time
.min
,
159 play_struct
.dwTo
= tmsf
;
161 mciSendCommand(m_internal
->dev_id
, MCI_PLAY
, 0, (DWORD
)&play_struct
);
165 bool wxCDAudioWin::Pause(void)
170 return (mciSendCommand(m_internal
->dev_id
, MCI_PAUSE
, 0, 0) == 0);
173 bool wxCDAudioWin::Resume(void)
178 return (mciSendCommand(m_internal
->dev_id
, MCI_RESUME
, 0, 0) == 0);
181 wxCDAudio::CDstatus
wxCDAudioWin::GetStatus(void)
183 MCI_STATUS_PARMS status_struct
;
188 status_struct
.dwItem
= MCI_STATUS_MODE
;
189 mciSendCommand(m_internal
->dev_id
, MCI_STATUS
, MCI_STATUS_ITEM
,
190 (DWORD
)&status_struct
);
191 switch (status_struct
.dwReturn
) {
200 wxCDtime
wxCDAudioWin::GetTime(void)
202 MCI_STATUS_PARMS status_struct
;
203 wxCDtime cd_time
= {-1, -1, -1, -1};
208 status_struct
.dwItem
= MCI_STATUS_TIME_FORMAT
;
209 mciSendCommand(m_internal
->dev_id
, MCI_STATUS
, MCI_STATUS_ITEM
,
210 (DWORD
)&status_struct
);
211 cd_time
.track
= MCI_TMSF_TRACK(status_struct
.dwReturn
);
212 cd_time
.min
= MCI_TMSF_MINUTE(status_struct
.dwReturn
);
213 cd_time
.sec
= MCI_TMSF_SECOND(status_struct
.dwReturn
);
214 cd_time
.hour
= cd_time
.min
/ 60;
219 const wxCDAudio::CDtoc
& wxCDAudioWin::GetToc(void)