]>
Commit | Line | Data |
---|---|---|
1 | //////////////////////////////////////////////////////////////////////////////// | |
2 | // Name: cdwin.cpp | |
3 | // Purpose: wxMMedia | |
4 | // Author: Guilhem Lavaux | |
5 | // Created: 1997 | |
6 | // Updated: 1998 | |
7 | // Copyright: (C) 1997, 1998, Guilhem Lavaux | |
8 | // License: wxWindows license | |
9 | //////////////////////////////////////////////////////////////////////////////// | |
10 | #ifdef __GNUG__ | |
11 | #pragma implementation "cdwin.h" | |
12 | #endif | |
13 | ||
14 | #include "wx/wxprec.h" | |
15 | ||
16 | #ifndef WX_PRECOMP | |
17 | #include "wx/defs.h" | |
18 | #endif | |
19 | ||
20 | #ifdef __BORLANDC__ | |
21 | #pragma hdrstop | |
22 | #endif | |
23 | ||
24 | #ifdef __WINDOWS__ | |
25 | ||
26 | // --------------------------------------------------------------------------- | |
27 | // System headers | |
28 | // --------------------------------------------------------------------------- | |
29 | ||
30 | #include <windows.h> | |
31 | #include <stdio.h> | |
32 | #include <mmsystem.h> | |
33 | ||
34 | // --------------------------------------------------------------------------- | |
35 | // MMedia headers | |
36 | // --------------------------------------------------------------------------- | |
37 | ||
38 | #define WXMMEDIA_INTERNAL | |
39 | #include "wx/mmedia/cdbase.h" | |
40 | #include "wx/mmedia/cdwin.h" | |
41 | ||
42 | // --------------------------------------------------------------------------- | |
43 | // Implementation | |
44 | // --------------------------------------------------------------------------- | |
45 | ||
46 | IMPLEMENT_DYNAMIC_CLASS(wxCDAudioWin, wxCDAudio) | |
47 | ||
48 | wxCDAudioWin::wxCDAudioWin(void) | |
49 | : wxCDAudio(), m_trksize(NULL), m_trkpos(NULL), m_ok(TRUE), m_toc(NULL) | |
50 | { | |
51 | MCI_OPEN_PARMS open_struct; | |
52 | MCI_SET_PARMS set_struct; | |
53 | DWORD ret; | |
54 | ||
55 | m_internal = new CDAW_Internal; | |
56 | open_struct.lpstrDeviceType = "cdaudio"; | |
57 | ret = mciSendCommand(NULL, MCI_OPEN, MCI_OPEN_TYPE, | |
58 | (DWORD)&open_struct); | |
59 | if (ret) { | |
60 | m_ok = FALSE; | |
61 | return; | |
62 | } | |
63 | m_internal->dev_id = open_struct.wDeviceID; | |
64 | ||
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); | |
68 | ||
69 | PrepareToc(); | |
70 | ||
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); | |
74 | } | |
75 | ||
76 | wxCDAudioWin::~wxCDAudioWin(void) | |
77 | { | |
78 | if (m_ok) { | |
79 | mciSendCommand(m_internal->dev_id, MCI_CLOSE, 0, NULL); | |
80 | delete m_toc; | |
81 | delete[] m_trksize; | |
82 | delete[] m_trkpos; | |
83 | } | |
84 | delete m_internal; | |
85 | } | |
86 | ||
87 | void wxCDAudioWin::PrepareToc(void) | |
88 | { | |
89 | MCI_STATUS_PARMS status_struct; | |
90 | wxUint16 i, nb_m_trksize; | |
91 | wxCDtime total_time, *trk; | |
92 | DWORD ret, tmem; | |
93 | ||
94 | if (!m_ok) | |
95 | return; | |
96 | ||
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; | |
101 | ||
102 | m_trksize = new wxCDtime[nb_m_trksize+1]; | |
103 | m_trkpos = new wxCDtime[nb_m_trksize+1]; | |
104 | ||
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; | |
114 | ||
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; | |
122 | ||
123 | trk = &m_trkpos[i]; | |
124 | trk->track = i; | |
125 | trk->min = MCI_MSF_MINUTE(tmem); | |
126 | trk->sec = MCI_MSF_SECOND(tmem); | |
127 | trk->hour = trk->min / 60; | |
128 | trk->min %= 60; | |
129 | ||
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; | |
136 | ||
137 | trk = &m_trksize[i]; | |
138 | trk->track = i; | |
139 | trk->min = MCI_MSF_MINUTE(tmem); | |
140 | trk->sec = MCI_MSF_SECOND(tmem); | |
141 | trk->hour = trk->min / 60; | |
142 | trk->min %= 60; | |
143 | } | |
144 | ||
145 | m_toc = new CDtoc(total_time, m_trksize, m_trkpos); | |
146 | } | |
147 | ||
148 | bool wxCDAudioWin::Play(const wxCDtime& beg_time, const wxCDtime& end_time) | |
149 | { | |
150 | DWORD tmsf; | |
151 | MCI_PLAY_PARMS play_struct; | |
152 | ||
153 | if (!m_ok) | |
154 | return FALSE; | |
155 | ||
156 | tmsf = MCI_MAKE_TMSF(beg_time.track, beg_time.min, | |
157 | beg_time.sec, 0); | |
158 | play_struct.dwFrom = tmsf; | |
159 | tmsf = MCI_MAKE_TMSF(end_time.track, end_time.min, | |
160 | end_time.sec, 0); | |
161 | play_struct.dwTo = tmsf; | |
162 | ||
163 | mciSendCommand(m_internal->dev_id, MCI_PLAY, 0, (DWORD)&play_struct); | |
164 | return TRUE; | |
165 | } | |
166 | ||
167 | bool wxCDAudioWin::Pause(void) | |
168 | { | |
169 | if (!m_ok) | |
170 | return FALSE; | |
171 | ||
172 | return (mciSendCommand(m_internal->dev_id, MCI_PAUSE, 0, 0) == 0); | |
173 | } | |
174 | ||
175 | bool wxCDAudioWin::Resume(void) | |
176 | { | |
177 | if (!m_ok) | |
178 | return FALSE; | |
179 | ||
180 | return (mciSendCommand(m_internal->dev_id, MCI_RESUME, 0, 0) == 0); | |
181 | } | |
182 | ||
183 | wxCDAudio::CDstatus wxCDAudioWin::GetStatus(void) | |
184 | { | |
185 | MCI_STATUS_PARMS status_struct; | |
186 | ||
187 | if (!m_ok) | |
188 | return STOPPED; | |
189 | ||
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) { | |
194 | case MCI_MODE_PAUSE: | |
195 | return PAUSED; | |
196 | case MCI_MODE_PLAY: | |
197 | return PLAYING; | |
198 | } | |
199 | return STOPPED; | |
200 | } | |
201 | ||
202 | wxCDtime wxCDAudioWin::GetTime(void) | |
203 | { | |
204 | MCI_STATUS_PARMS status_struct; | |
205 | wxCDtime cd_time = {-1, -1, -1, -1}; | |
206 | ||
207 | if (!m_ok) | |
208 | return cd_time; | |
209 | ||
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; | |
217 | cd_time.min %= 60; | |
218 | return cd_time; | |
219 | } | |
220 | ||
221 | const wxCDAudio::CDtoc& wxCDAudioWin::GetToc(void) | |
222 | { | |
223 | return *m_toc; | |
224 | } | |
225 | ||
226 | #endif | |
227 | // __WINDOWS__ |