]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/mmedia/cdwin.cpp
added new files (after library split)
[wxWidgets.git] / contrib / src / mmedia / cdwin.cpp
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 wxCDAudioWin::wxCDAudioWin(void)
47 : wxCDAudio(), m_trksize(NULL), m_trkpos(NULL), m_ok(TRUE), m_toc(NULL)
48 {
49 MCI_OPEN_PARMS open_struct;
50 MCI_SET_PARMS set_struct;
51 DWORD ret;
52
53 m_internal = new CDAW_Internal;
54 open_struct.lpstrDeviceType = "cdaudio";
55 ret = mciSendCommand(NULL, MCI_OPEN, MCI_OPEN_TYPE,
56 (DWORD)&open_struct);
57 if (ret) {
58 m_ok = FALSE;
59 return;
60 }
61 m_internal->dev_id = open_struct.wDeviceID;
62
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);
66
67 PrepareToc();
68
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);
72 }
73
74 wxCDAudioWin::~wxCDAudioWin(void)
75 {
76 if (m_ok) {
77 mciSendCommand(m_internal->dev_id, MCI_CLOSE, 0, NULL);
78 delete m_toc;
79 delete[] m_trksize;
80 delete[] m_trkpos;
81 }
82 delete m_internal;
83 }
84
85 void wxCDAudioWin::PrepareToc(void)
86 {
87 MCI_STATUS_PARMS status_struct;
88 wxUint16 i, nb_m_trksize;
89 wxCDtime total_time, *trk;
90 DWORD ret, tmem;
91
92 if (!m_ok)
93 return;
94
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;
99
100 m_trksize = new wxCDtime[nb_m_trksize+1];
101 m_trkpos = new wxCDtime[nb_m_trksize+1];
102
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;
112
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;
120
121 trk = &m_trkpos[i];
122 trk->track = i;
123 trk->min = MCI_MSF_MINUTE(tmem);
124 trk->sec = MCI_MSF_SECOND(tmem);
125 trk->hour = trk->min / 60;
126 trk->min %= 60;
127
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;
134
135 trk = &m_trksize[i];
136 trk->track = i;
137 trk->min = MCI_MSF_MINUTE(tmem);
138 trk->sec = MCI_MSF_SECOND(tmem);
139 trk->hour = trk->min / 60;
140 trk->min %= 60;
141 }
142
143 m_toc = new CDtoc(total_time, m_trksize, m_trkpos);
144 }
145
146 bool wxCDAudioWin::Play(const wxCDtime& beg_time, const wxCDtime& end_time)
147 {
148 DWORD tmsf;
149 MCI_PLAY_PARMS play_struct;
150
151 if (!m_ok)
152 return FALSE;
153
154 tmsf = MCI_MAKE_TMSF(beg_time.track, beg_time.min,
155 beg_time.sec, 0);
156 play_struct.dwFrom = tmsf;
157 tmsf = MCI_MAKE_TMSF(end_time.track, end_time.min,
158 end_time.sec, 0);
159 play_struct.dwTo = tmsf;
160
161 mciSendCommand(m_internal->dev_id, MCI_PLAY, 0, (DWORD)&play_struct);
162 return TRUE;
163 }
164
165 bool wxCDAudioWin::Pause(void)
166 {
167 if (!m_ok)
168 return FALSE;
169
170 return (mciSendCommand(m_internal->dev_id, MCI_PAUSE, 0, 0) == 0);
171 }
172
173 bool wxCDAudioWin::Resume(void)
174 {
175 if (!m_ok)
176 return FALSE;
177
178 return (mciSendCommand(m_internal->dev_id, MCI_RESUME, 0, 0) == 0);
179 }
180
181 wxCDAudio::CDstatus wxCDAudioWin::GetStatus(void)
182 {
183 MCI_STATUS_PARMS status_struct;
184
185 if (!m_ok)
186 return STOPPED;
187
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) {
192 case MCI_MODE_PAUSE:
193 return PAUSED;
194 case MCI_MODE_PLAY:
195 return PLAYING;
196 }
197 return STOPPED;
198 }
199
200 wxCDtime wxCDAudioWin::GetTime(void)
201 {
202 MCI_STATUS_PARMS status_struct;
203 wxCDtime cd_time = {-1, -1, -1, -1};
204
205 if (!m_ok)
206 return cd_time;
207
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;
215 cd_time.min %= 60;
216 return cd_time;
217 }
218
219 const wxCDAudio::CDtoc& wxCDAudioWin::GetToc(void)
220 {
221 return *m_toc;
222 }
223
224 #endif
225 // __WINDOWS__