]> git.saurik.com Git - wxWidgets.git/blame - contrib/src/mmedia/cdwin.cpp
multiline checkbox doesn't make sense for listbook
[wxWidgets.git] / contrib / src / mmedia / cdwin.cpp
CommitLineData
e8482f24
GL
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
15e8daec
VS
46IMPLEMENT_DYNAMIC_CLASS(wxCDAudioWin, wxCDAudio)
47
e8482f24 48wxCDAudioWin::wxCDAudioWin(void)
2b3644c7 49 : wxCDAudio(), m_trksize(NULL), m_trkpos(NULL), m_toc(NULL), m_ok(TRUE)
e8482f24
GL
50{
51 MCI_OPEN_PARMS open_struct;
52 MCI_SET_PARMS set_struct;
e8482f24
GL
53
54 m_internal = new CDAW_Internal;
42c37dec 55 open_struct.lpstrDeviceType = _T("cdaudio");
2b3644c7 56 DWORD ret = mciSendCommand((MCIDEVICEID)NULL, MCI_OPEN, MCI_OPEN_TYPE,
e8482f24
GL
57 (DWORD)&open_struct);
58 if (ret) {
59 m_ok = FALSE;
60 return;
61 }
62 m_internal->dev_id = open_struct.wDeviceID;
63
64 set_struct.dwTimeFormat = MCI_FORMAT_MSF;
2b3644c7 65 mciSendCommand(m_internal->dev_id, MCI_SET, MCI_SET_TIME_FORMAT,
e8482f24
GL
66 (DWORD)(LPVOID)&set_struct);
67
68 PrepareToc();
69
70 set_struct.dwTimeFormat = MCI_FORMAT_TMSF;
2b3644c7 71 mciSendCommand(m_internal->dev_id, MCI_SET, MCI_SET_TIME_FORMAT,
e8482f24
GL
72 (DWORD)(LPVOID)&set_struct);
73}
74
75wxCDAudioWin::~wxCDAudioWin(void)
76{
77 if (m_ok) {
2b3644c7 78 mciSendCommand(m_internal->dev_id, MCI_CLOSE, 0,(DWORD_PTR)NULL);
e8482f24
GL
79 delete m_toc;
80 delete[] m_trksize;
81 delete[] m_trkpos;
82 }
83 delete m_internal;
84}
85
86void wxCDAudioWin::PrepareToc(void)
87{
88 MCI_STATUS_PARMS status_struct;
89 wxUint16 i, nb_m_trksize;
90 wxCDtime total_time, *trk;
42c37dec 91 DWORD tmem;
e8482f24
GL
92
93 if (!m_ok)
94 return;
95
96 status_struct.dwItem = MCI_STATUS_NUMBER_OF_TRACKS;
42c37dec 97 mciSendCommand(m_internal->dev_id, MCI_STATUS, MCI_STATUS_ITEM,
e8482f24
GL
98 (DWORD)&status_struct);
99 nb_m_trksize = status_struct.dwReturn;
100
101 m_trksize = new wxCDtime[nb_m_trksize+1];
102 m_trkpos = new wxCDtime[nb_m_trksize+1];
103
104 status_struct.dwItem = MCI_STATUS_LENGTH;
42c37dec 105 mciSendCommand(m_internal->dev_id, MCI_STATUS, MCI_STATUS_ITEM,
e8482f24
GL
106 (DWORD)&status_struct);
107 total_time.track = nb_m_trksize;
108 tmem = status_struct.dwReturn;
109 total_time.min = MCI_MSF_MINUTE(tmem);
110 total_time.sec = MCI_MSF_SECOND(tmem);
111 total_time.hour = total_time.min / 60;
112 total_time.min %= 60;
113
114 for (i=1;i<=nb_m_trksize;i++) {
115 status_struct.dwItem = MCI_STATUS_POSITION;
116 status_struct.dwTrack = i;
42c37dec 117 mciSendCommand(m_internal->dev_id, MCI_STATUS,
e8482f24
GL
118 MCI_STATUS_ITEM | MCI_TRACK,
119 (DWORD)(LPVOID)&status_struct);
120 tmem = status_struct.dwReturn;
121
122 trk = &m_trkpos[i];
123 trk->track = i;
124 trk->min = MCI_MSF_MINUTE(tmem);
125 trk->sec = MCI_MSF_SECOND(tmem);
126 trk->hour = trk->min / 60;
127 trk->min %= 60;
128
129 status_struct.dwItem = MCI_STATUS_LENGTH;
130 status_struct.dwTrack = i;
42c37dec 131 mciSendCommand(m_internal->dev_id, MCI_STATUS,
e8482f24
GL
132 MCI_STATUS_ITEM | MCI_TRACK,
133 (DWORD)(LPVOID)&status_struct);
134 tmem = status_struct.dwReturn;
135
136 trk = &m_trksize[i];
137 trk->track = i;
138 trk->min = MCI_MSF_MINUTE(tmem);
139 trk->sec = MCI_MSF_SECOND(tmem);
140 trk->hour = trk->min / 60;
141 trk->min %= 60;
142 }
143
144 m_toc = new CDtoc(total_time, m_trksize, m_trkpos);
145}
146
147bool wxCDAudioWin::Play(const wxCDtime& beg_time, const wxCDtime& end_time)
148{
149 DWORD tmsf;
150 MCI_PLAY_PARMS play_struct;
151
152 if (!m_ok)
153 return FALSE;
154
155 tmsf = MCI_MAKE_TMSF(beg_time.track, beg_time.min,
156 beg_time.sec, 0);
157 play_struct.dwFrom = tmsf;
158 tmsf = MCI_MAKE_TMSF(end_time.track, end_time.min,
159 end_time.sec, 0);
160 play_struct.dwTo = tmsf;
161
162 mciSendCommand(m_internal->dev_id, MCI_PLAY, 0, (DWORD)&play_struct);
163 return TRUE;
164}
165
166bool wxCDAudioWin::Pause(void)
167{
168 if (!m_ok)
169 return FALSE;
170
171 return (mciSendCommand(m_internal->dev_id, MCI_PAUSE, 0, 0) == 0);
172}
173
174bool wxCDAudioWin::Resume(void)
175{
176 if (!m_ok)
177 return FALSE;
178
179 return (mciSendCommand(m_internal->dev_id, MCI_RESUME, 0, 0) == 0);
180}
181
182wxCDAudio::CDstatus wxCDAudioWin::GetStatus(void)
183{
184 MCI_STATUS_PARMS status_struct;
185
186 if (!m_ok)
187 return STOPPED;
188
189 status_struct.dwItem = MCI_STATUS_MODE;
190 mciSendCommand(m_internal->dev_id, MCI_STATUS, MCI_STATUS_ITEM,
191 (DWORD)&status_struct);
192 switch (status_struct.dwReturn) {
193 case MCI_MODE_PAUSE:
194 return PAUSED;
195 case MCI_MODE_PLAY:
196 return PLAYING;
197 }
198 return STOPPED;
199}
200
201wxCDtime wxCDAudioWin::GetTime(void)
202{
203 MCI_STATUS_PARMS status_struct;
2b3644c7 204 wxCDtime cd_time = {0,0,0,0};
e8482f24
GL
205
206 if (!m_ok)
207 return cd_time;
208
209 status_struct.dwItem = MCI_STATUS_TIME_FORMAT;
210 mciSendCommand(m_internal->dev_id, MCI_STATUS, MCI_STATUS_ITEM,
211 (DWORD)&status_struct);
212 cd_time.track = MCI_TMSF_TRACK(status_struct.dwReturn);
213 cd_time.min = MCI_TMSF_MINUTE(status_struct.dwReturn);
214 cd_time.sec = MCI_TMSF_SECOND(status_struct.dwReturn);
215 cd_time.hour = cd_time.min / 60;
216 cd_time.min %= 60;
217 return cd_time;
218}
219
220const wxCDAudio::CDtoc& wxCDAudioWin::GetToc(void)
221{
222 return *m_toc;
223}
224
225#endif
226 // __WINDOWS__