1 ////////////////////////////////////////////////////////////////////////////////
4 // Author: Guilhem Lavaux
7 // Copyright: (C) 1997, 1998, Guilhem Lavaux
8 // License: wxWindows license
9 ////////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "cdwin.h"
17 #include "wx/wxprec.h"
18 #define WXMMEDIA_INTERNAL
26 wxCDAudioWin::wxCDAudioWin(void)
27 : wxCDAudio(), m_trksize(NULL
), m_trkpos(NULL
), m_ok(TRUE
), m_toc(NULL
)
29 MCI_OPEN_PARMS open_struct
;
30 MCI_SET_PARMS set_struct
;
33 m_internal
= new CDAW_Internal
;
34 open_struct
.lpstrDeviceType
= "cdaudio";
35 ret
= mciSendCommand(NULL
, MCI_OPEN
, MCI_OPEN_TYPE
,
41 m_internal
->dev_id
= open_struct
.wDeviceID
;
43 set_struct
.dwTimeFormat
= MCI_FORMAT_MSF
;
44 ret
= mciSendCommand(m_internal
->dev_id
, MCI_SET
, MCI_SET_TIME_FORMAT
,
45 (DWORD
)(LPVOID
)&set_struct
);
49 set_struct
.dwTimeFormat
= MCI_FORMAT_TMSF
;
50 ret
= mciSendCommand(m_internal
->dev_id
, MCI_SET
, MCI_SET_TIME_FORMAT
,
51 (DWORD
)(LPVOID
)&set_struct
);
54 wxCDAudioWin::~wxCDAudioWin(void)
57 mciSendCommand(m_internal
->dev_id
, MCI_CLOSE
, 0, NULL
);
65 void wxCDAudioWin::PrepareToc(void)
67 MCI_STATUS_PARMS status_struct
;
68 wxUint16 i
, nb_m_trksize
;
69 wxCDtime total_time
, *trk
;
75 status_struct
.dwItem
= MCI_STATUS_NUMBER_OF_TRACKS
;
76 ret
= mciSendCommand(m_internal
->dev_id
, MCI_STATUS
, MCI_STATUS_ITEM
,
77 (DWORD
)&status_struct
);
78 nb_m_trksize
= status_struct
.dwReturn
;
80 m_trksize
= new wxCDtime
[nb_m_trksize
+1];
81 m_trkpos
= new wxCDtime
[nb_m_trksize
+1];
83 status_struct
.dwItem
= MCI_STATUS_LENGTH
;
84 ret
= mciSendCommand(m_internal
->dev_id
, MCI_STATUS
, MCI_STATUS_ITEM
,
85 (DWORD
)&status_struct
);
86 total_time
.track
= nb_m_trksize
;
87 tmem
= status_struct
.dwReturn
;
88 total_time
.min
= MCI_MSF_MINUTE(tmem
);
89 total_time
.sec
= MCI_MSF_SECOND(tmem
);
90 total_time
.hour
= total_time
.min
/ 60;
93 for (i
=1;i
<=nb_m_trksize
;i
++) {
94 status_struct
.dwItem
= MCI_STATUS_POSITION
;
95 status_struct
.dwTrack
= i
;
96 ret
= mciSendCommand(m_internal
->dev_id
, MCI_STATUS
,
97 MCI_STATUS_ITEM
| MCI_TRACK
,
98 (DWORD
)(LPVOID
)&status_struct
);
99 tmem
= status_struct
.dwReturn
;
103 trk
->min
= MCI_MSF_MINUTE(tmem
);
104 trk
->sec
= MCI_MSF_SECOND(tmem
);
105 trk
->hour
= trk
->min
/ 60;
108 status_struct
.dwItem
= MCI_STATUS_LENGTH
;
109 status_struct
.dwTrack
= i
;
110 ret
= mciSendCommand(m_internal
->dev_id
, MCI_STATUS
,
111 MCI_STATUS_ITEM
| MCI_TRACK
,
112 (DWORD
)(LPVOID
)&status_struct
);
113 tmem
= status_struct
.dwReturn
;
117 trk
->min
= MCI_MSF_MINUTE(tmem
);
118 trk
->sec
= MCI_MSF_SECOND(tmem
);
119 trk
->hour
= trk
->min
/ 60;
123 m_toc
= new CDtoc(total_time
, m_trksize
, m_trkpos
);
126 bool wxCDAudioWin::Play(const wxCDtime
& beg_time
, const wxCDtime
& end_time
)
129 MCI_PLAY_PARMS play_struct
;
134 tmsf
= MCI_MAKE_TMSF(beg_time
.track
, beg_time
.min
,
136 play_struct
.dwFrom
= tmsf
;
137 tmsf
= MCI_MAKE_TMSF(end_time
.track
, end_time
.min
,
139 play_struct
.dwTo
= tmsf
;
141 mciSendCommand(m_internal
->dev_id
, MCI_PLAY
, 0, (DWORD
)&play_struct
);
145 bool wxCDAudioWin::Pause(void)
150 return (mciSendCommand(m_internal
->dev_id
, MCI_PAUSE
, 0, 0) == 0);
153 bool wxCDAudioWin::Resume(void)
158 return (mciSendCommand(m_internal
->dev_id
, MCI_RESUME
, 0, 0) == 0);
161 wxCDAudio::CDstatus
wxCDAudioWin::GetStatus(void)
163 MCI_STATUS_PARMS status_struct
;
168 status_struct
.dwItem
= MCI_STATUS_MODE
;
169 mciSendCommand(m_internal
->dev_id
, MCI_STATUS
, MCI_STATUS_ITEM
,
170 (DWORD
)&status_struct
);
171 switch (status_struct
.dwReturn
) {
180 wxCDtime
wxCDAudioWin::GetTime(void)
182 MCI_STATUS_PARMS status_struct
;
183 wxCDtime cd_time
= {-1, -1, -1, -1};
188 status_struct
.dwItem
= MCI_STATUS_TIME_FORMAT
;
189 mciSendCommand(m_internal
->dev_id
, MCI_STATUS
, MCI_STATUS_ITEM
,
190 (DWORD
)&status_struct
);
191 cd_time
.track
= MCI_TMSF_TRACK(status_struct
.dwReturn
);
192 cd_time
.min
= MCI_TMSF_MINUTE(status_struct
.dwReturn
);
193 cd_time
.sec
= MCI_TMSF_SECOND(status_struct
.dwReturn
);
194 cd_time
.hour
= cd_time
.min
/ 60;
199 const wxCDAudio::CDtoc
& wxCDAudioWin::GetToc(void)