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_ok(TRUE
), m_toc(NULL
)
51 MCI_OPEN_PARMS open_struct
;
52 MCI_SET_PARMS set_struct
;
55 m_internal
= new CDAW_Internal
;
56 open_struct
.lpstrDeviceType
= "cdaudio";
57 ret
= mciSendCommand(NULL
, MCI_OPEN
, MCI_OPEN_TYPE
,
63 m_internal
->dev_id
= open_struct
.wDeviceID
;
65 set_struct
.dwTimeFormat
= MCI_FORMAT_MSF
;
66 ret
= mciSendCommand(m_internal
->dev_id
, MCI_SET
, MCI_SET_TIME_FORMAT
,
67 (DWORD
)(LPVOID
)&set_struct
);
71 set_struct
.dwTimeFormat
= MCI_FORMAT_TMSF
;
72 ret
= mciSendCommand(m_internal
->dev_id
, MCI_SET
, MCI_SET_TIME_FORMAT
,
73 (DWORD
)(LPVOID
)&set_struct
);
76 wxCDAudioWin::~wxCDAudioWin(void)
79 mciSendCommand(m_internal
->dev_id
, MCI_CLOSE
, 0, NULL
);
87 void wxCDAudioWin::PrepareToc(void)
89 MCI_STATUS_PARMS status_struct
;
90 wxUint16 i
, nb_m_trksize
;
91 wxCDtime total_time
, *trk
;
97 status_struct
.dwItem
= MCI_STATUS_NUMBER_OF_TRACKS
;
98 ret
= mciSendCommand(m_internal
->dev_id
, MCI_STATUS
, MCI_STATUS_ITEM
,
99 (DWORD
)&status_struct
);
100 nb_m_trksize
= status_struct
.dwReturn
;
102 m_trksize
= new wxCDtime
[nb_m_trksize
+1];
103 m_trkpos
= new wxCDtime
[nb_m_trksize
+1];
105 status_struct
.dwItem
= MCI_STATUS_LENGTH
;
106 ret
= mciSendCommand(m_internal
->dev_id
, MCI_STATUS
, MCI_STATUS_ITEM
,
107 (DWORD
)&status_struct
);
108 total_time
.track
= nb_m_trksize
;
109 tmem
= status_struct
.dwReturn
;
110 total_time
.min
= MCI_MSF_MINUTE(tmem
);
111 total_time
.sec
= MCI_MSF_SECOND(tmem
);
112 total_time
.hour
= total_time
.min
/ 60;
113 total_time
.min
%= 60;
115 for (i
=1;i
<=nb_m_trksize
;i
++) {
116 status_struct
.dwItem
= MCI_STATUS_POSITION
;
117 status_struct
.dwTrack
= i
;
118 ret
= mciSendCommand(m_internal
->dev_id
, MCI_STATUS
,
119 MCI_STATUS_ITEM
| MCI_TRACK
,
120 (DWORD
)(LPVOID
)&status_struct
);
121 tmem
= status_struct
.dwReturn
;
125 trk
->min
= MCI_MSF_MINUTE(tmem
);
126 trk
->sec
= MCI_MSF_SECOND(tmem
);
127 trk
->hour
= trk
->min
/ 60;
130 status_struct
.dwItem
= MCI_STATUS_LENGTH
;
131 status_struct
.dwTrack
= i
;
132 ret
= mciSendCommand(m_internal
->dev_id
, MCI_STATUS
,
133 MCI_STATUS_ITEM
| MCI_TRACK
,
134 (DWORD
)(LPVOID
)&status_struct
);
135 tmem
= status_struct
.dwReturn
;
139 trk
->min
= MCI_MSF_MINUTE(tmem
);
140 trk
->sec
= MCI_MSF_SECOND(tmem
);
141 trk
->hour
= trk
->min
/ 60;
145 m_toc
= new CDtoc(total_time
, m_trksize
, m_trkpos
);
148 bool wxCDAudioWin::Play(const wxCDtime
& beg_time
, const wxCDtime
& end_time
)
151 MCI_PLAY_PARMS play_struct
;
156 tmsf
= MCI_MAKE_TMSF(beg_time
.track
, beg_time
.min
,
158 play_struct
.dwFrom
= tmsf
;
159 tmsf
= MCI_MAKE_TMSF(end_time
.track
, end_time
.min
,
161 play_struct
.dwTo
= tmsf
;
163 mciSendCommand(m_internal
->dev_id
, MCI_PLAY
, 0, (DWORD
)&play_struct
);
167 bool wxCDAudioWin::Pause(void)
172 return (mciSendCommand(m_internal
->dev_id
, MCI_PAUSE
, 0, 0) == 0);
175 bool wxCDAudioWin::Resume(void)
180 return (mciSendCommand(m_internal
->dev_id
, MCI_RESUME
, 0, 0) == 0);
183 wxCDAudio::CDstatus
wxCDAudioWin::GetStatus(void)
185 MCI_STATUS_PARMS status_struct
;
190 status_struct
.dwItem
= MCI_STATUS_MODE
;
191 mciSendCommand(m_internal
->dev_id
, MCI_STATUS
, MCI_STATUS_ITEM
,
192 (DWORD
)&status_struct
);
193 switch (status_struct
.dwReturn
) {
202 wxCDtime
wxCDAudioWin::GetTime(void)
204 MCI_STATUS_PARMS status_struct
;
205 wxCDtime cd_time
= {-1, -1, -1, -1};
210 status_struct
.dwItem
= MCI_STATUS_TIME_FORMAT
;
211 mciSendCommand(m_internal
->dev_id
, MCI_STATUS
, MCI_STATUS_ITEM
,
212 (DWORD
)&status_struct
);
213 cd_time
.track
= MCI_TMSF_TRACK(status_struct
.dwReturn
);
214 cd_time
.min
= MCI_TMSF_MINUTE(status_struct
.dwReturn
);
215 cd_time
.sec
= MCI_TMSF_SECOND(status_struct
.dwReturn
);
216 cd_time
.hour
= cd_time
.min
/ 60;
221 const wxCDAudio::CDtoc
& wxCDAudioWin::GetToc(void)