1 ////////////////////////////////////////////////////////////////////////////////
4 // Author: Guilhem Lavaux
7 // Copyright: (C) 1997, 1998, Guilhem Lavaux
8 // License: wxWindows license
9 ////////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
23 // ---------------------------------------------------------------------------
25 // ---------------------------------------------------------------------------
31 // ---------------------------------------------------------------------------
33 // ---------------------------------------------------------------------------
35 #define WXMMEDIA_INTERNAL
36 #include "wx/mmedia/cdbase.h"
37 #include "wx/mmedia/cdwin.h"
39 // ---------------------------------------------------------------------------
41 // ---------------------------------------------------------------------------
43 IMPLEMENT_DYNAMIC_CLASS(wxCDAudioWin
, wxCDAudio
)
45 wxCDAudioWin::wxCDAudioWin(void)
46 : wxCDAudio(), m_trksize(NULL
), m_trkpos(NULL
), m_toc(NULL
), m_ok(true)
48 MCI_OPEN_PARMS open_struct
;
49 MCI_SET_PARMS set_struct
;
51 m_internal
= new CDAW_Internal
;
52 open_struct
.lpstrDeviceType
= _T("cdaudio");
53 DWORD ret
= mciSendCommand((MCIDEVICEID
)NULL
, MCI_OPEN
, MCI_OPEN_TYPE
,
59 m_internal
->dev_id
= open_struct
.wDeviceID
;
61 set_struct
.dwTimeFormat
= MCI_FORMAT_MSF
;
62 mciSendCommand(m_internal
->dev_id
, MCI_SET
, MCI_SET_TIME_FORMAT
,
63 (DWORD
)(LPVOID
)&set_struct
);
67 set_struct
.dwTimeFormat
= MCI_FORMAT_TMSF
;
68 mciSendCommand(m_internal
->dev_id
, MCI_SET
, MCI_SET_TIME_FORMAT
,
69 (DWORD
)(LPVOID
)&set_struct
);
72 wxCDAudioWin::~wxCDAudioWin(void)
75 mciSendCommand(m_internal
->dev_id
, MCI_CLOSE
, 0,(DWORD_PTR
)NULL
);
83 void wxCDAudioWin::PrepareToc(void)
85 MCI_STATUS_PARMS status_struct
;
86 wxUint16 i
, nb_m_trksize
;
87 wxCDtime total_time
, *trk
;
93 status_struct
.dwItem
= MCI_STATUS_NUMBER_OF_TRACKS
;
94 mciSendCommand(m_internal
->dev_id
, MCI_STATUS
, MCI_STATUS_ITEM
,
95 (DWORD
)&status_struct
);
96 nb_m_trksize
= status_struct
.dwReturn
;
98 m_trksize
= new wxCDtime
[nb_m_trksize
+1];
99 m_trkpos
= new wxCDtime
[nb_m_trksize
+1];
101 status_struct
.dwItem
= MCI_STATUS_LENGTH
;
102 mciSendCommand(m_internal
->dev_id
, MCI_STATUS
, MCI_STATUS_ITEM
,
103 (DWORD
)&status_struct
);
104 total_time
.track
= nb_m_trksize
;
105 tmem
= status_struct
.dwReturn
;
106 total_time
.min
= MCI_MSF_MINUTE(tmem
);
107 total_time
.sec
= MCI_MSF_SECOND(tmem
);
108 total_time
.hour
= total_time
.min
/ 60;
109 total_time
.min
%= 60;
111 for (i
=1;i
<=nb_m_trksize
;i
++) {
112 status_struct
.dwItem
= MCI_STATUS_POSITION
;
113 status_struct
.dwTrack
= i
;
114 mciSendCommand(m_internal
->dev_id
, MCI_STATUS
,
115 MCI_STATUS_ITEM
| MCI_TRACK
,
116 (DWORD
)(LPVOID
)&status_struct
);
117 tmem
= status_struct
.dwReturn
;
121 trk
->min
= MCI_MSF_MINUTE(tmem
);
122 trk
->sec
= MCI_MSF_SECOND(tmem
);
123 trk
->hour
= trk
->min
/ 60;
126 status_struct
.dwItem
= MCI_STATUS_LENGTH
;
127 status_struct
.dwTrack
= i
;
128 mciSendCommand(m_internal
->dev_id
, MCI_STATUS
,
129 MCI_STATUS_ITEM
| MCI_TRACK
,
130 (DWORD
)(LPVOID
)&status_struct
);
131 tmem
= status_struct
.dwReturn
;
135 trk
->min
= MCI_MSF_MINUTE(tmem
);
136 trk
->sec
= MCI_MSF_SECOND(tmem
);
137 trk
->hour
= trk
->min
/ 60;
141 m_toc
= new CDtoc(total_time
, m_trksize
, m_trkpos
);
144 bool wxCDAudioWin::Play(const wxCDtime
& beg_time
, const wxCDtime
& end_time
)
147 MCI_PLAY_PARMS play_struct
;
152 tmsf
= MCI_MAKE_TMSF(beg_time
.track
, beg_time
.min
,
154 play_struct
.dwFrom
= tmsf
;
155 tmsf
= MCI_MAKE_TMSF(end_time
.track
, end_time
.min
,
157 play_struct
.dwTo
= tmsf
;
159 mciSendCommand(m_internal
->dev_id
, MCI_PLAY
, 0, (DWORD
)&play_struct
);
163 bool wxCDAudioWin::Pause(void)
168 return (mciSendCommand(m_internal
->dev_id
, MCI_PAUSE
, 0, 0) == 0);
171 bool wxCDAudioWin::Resume(void)
176 return (mciSendCommand(m_internal
->dev_id
, MCI_RESUME
, 0, 0) == 0);
179 wxCDAudio::CDstatus
wxCDAudioWin::GetStatus(void)
181 MCI_STATUS_PARMS status_struct
;
186 status_struct
.dwItem
= MCI_STATUS_MODE
;
187 mciSendCommand(m_internal
->dev_id
, MCI_STATUS
, MCI_STATUS_ITEM
,
188 (DWORD
)&status_struct
);
189 switch (status_struct
.dwReturn
) {
198 wxCDtime
wxCDAudioWin::GetTime(void)
200 MCI_STATUS_PARMS status_struct
;
201 wxCDtime cd_time
= {0,0,0,0};
206 status_struct
.dwItem
= MCI_STATUS_TIME_FORMAT
;
207 mciSendCommand(m_internal
->dev_id
, MCI_STATUS
, MCI_STATUS_ITEM
,
208 (DWORD
)&status_struct
);
209 cd_time
.track
= MCI_TMSF_TRACK(status_struct
.dwReturn
);
210 cd_time
.min
= MCI_TMSF_MINUTE(status_struct
.dwReturn
);
211 cd_time
.sec
= MCI_TMSF_SECOND(status_struct
.dwReturn
);
212 cd_time
.hour
= cd_time
.min
/ 60;
217 const wxCDAudio::CDtoc
& wxCDAudioWin::GetToc(void)