]> git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia2/lib/cdwin.cpp
makefile typo
[wxWidgets.git] / utils / wxMMedia2 / lib / 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 <windows.h>
15 #include <stdio.h>
16 #include <mmsystem.h>
17 #include "wx/wxprec.h"
18 #define WXMMEDIA_INTERNAL
19 #include "cdbase.h"
20 #include "cdwin.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 wxCDAudioWin::wxCDAudioWin(void)
27 : wxCDAudio(), m_trksize(NULL), m_trkpos(NULL), m_ok(TRUE), m_toc(NULL)
28 {
29 MCI_OPEN_PARMS open_struct;
30 MCI_SET_PARMS set_struct;
31 DWORD ret;
32
33 m_internal = new CDAW_Internal;
34 open_struct.lpstrDeviceType = "cdaudio";
35 ret = mciSendCommand(NULL, MCI_OPEN, MCI_OPEN_TYPE,
36 (DWORD)&open_struct);
37 if (ret) {
38 m_ok = FALSE;
39 return;
40 }
41 m_internal->dev_id = open_struct.wDeviceID;
42
43 set_struct.dwTimeFormat = MCI_FORMAT_MSF;
44 ret = mciSendCommand(m_internal->dev_id, MCI_SET, MCI_SET_TIME_FORMAT,
45 (DWORD)(LPVOID)&set_struct);
46
47 PrepareToc();
48
49 set_struct.dwTimeFormat = MCI_FORMAT_TMSF;
50 ret = mciSendCommand(m_internal->dev_id, MCI_SET, MCI_SET_TIME_FORMAT,
51 (DWORD)(LPVOID)&set_struct);
52 }
53
54 wxCDAudioWin::~wxCDAudioWin(void)
55 {
56 if (m_ok) {
57 mciSendCommand(m_internal->dev_id, MCI_CLOSE, 0, NULL);
58 delete m_toc;
59 delete[] m_trksize;
60 delete[] m_trkpos;
61 }
62 delete m_internal;
63 }
64
65 void wxCDAudioWin::PrepareToc(void)
66 {
67 MCI_STATUS_PARMS status_struct;
68 wxUint16 i, nb_m_trksize;
69 wxCDtime total_time, *trk;
70 DWORD ret, tmem;
71
72 if (!m_ok)
73 return;
74
75 status_struct.dwItem = MCI_STATUS_NUMBER_OF_TRACKS;
76 ret = mciSendCommand(m_internal->dev_id, MCI_STATUS, MCI_STATUS_ITEM,
77 (DWORD)&status_struct);
78 nb_m_trksize = status_struct.dwReturn;
79
80 m_trksize = new wxCDtime[nb_m_trksize+1];
81 m_trkpos = new wxCDtime[nb_m_trksize+1];
82
83 status_struct.dwItem = MCI_STATUS_LENGTH;
84 ret = mciSendCommand(m_internal->dev_id, MCI_STATUS, MCI_STATUS_ITEM,
85 (DWORD)&status_struct);
86 total_time.track = nb_m_trksize;
87 tmem = status_struct.dwReturn;
88 total_time.min = MCI_MSF_MINUTE(tmem);
89 total_time.sec = MCI_MSF_SECOND(tmem);
90 total_time.hour = total_time.min / 60;
91 total_time.min %= 60;
92
93 for (i=1;i<=nb_m_trksize;i++) {
94 status_struct.dwItem = MCI_STATUS_POSITION;
95 status_struct.dwTrack = i;
96 ret = mciSendCommand(m_internal->dev_id, MCI_STATUS,
97 MCI_STATUS_ITEM | MCI_TRACK,
98 (DWORD)(LPVOID)&status_struct);
99 tmem = status_struct.dwReturn;
100
101 trk = &m_trkpos[i];
102 trk->track = i;
103 trk->min = MCI_MSF_MINUTE(tmem);
104 trk->sec = MCI_MSF_SECOND(tmem);
105 trk->hour = trk->min / 60;
106 trk->min %= 60;
107
108 status_struct.dwItem = MCI_STATUS_LENGTH;
109 status_struct.dwTrack = i;
110 ret = mciSendCommand(m_internal->dev_id, MCI_STATUS,
111 MCI_STATUS_ITEM | MCI_TRACK,
112 (DWORD)(LPVOID)&status_struct);
113 tmem = status_struct.dwReturn;
114
115 trk = &m_trksize[i];
116 trk->track = i;
117 trk->min = MCI_MSF_MINUTE(tmem);
118 trk->sec = MCI_MSF_SECOND(tmem);
119 trk->hour = trk->min / 60;
120 trk->min %= 60;
121 }
122
123 m_toc = new CDtoc(total_time, m_trksize, m_trkpos);
124 }
125
126 bool wxCDAudioWin::Play(const wxCDtime& beg_time, const wxCDtime& end_time)
127 {
128 DWORD tmsf;
129 MCI_PLAY_PARMS play_struct;
130
131 if (!m_ok)
132 return FALSE;
133
134 tmsf = MCI_MAKE_TMSF(beg_time.track, beg_time.min,
135 beg_time.sec, 0);
136 play_struct.dwFrom = tmsf;
137 tmsf = MCI_MAKE_TMSF(end_time.track, end_time.min,
138 end_time.sec, 0);
139 play_struct.dwTo = tmsf;
140
141 mciSendCommand(m_internal->dev_id, MCI_PLAY, 0, (DWORD)&play_struct);
142 return TRUE;
143 }
144
145 bool wxCDAudioWin::Pause(void)
146 {
147 if (!m_ok)
148 return FALSE;
149
150 return (mciSendCommand(m_internal->dev_id, MCI_PAUSE, 0, 0) == 0);
151 }
152
153 bool wxCDAudioWin::Resume(void)
154 {
155 if (!m_ok)
156 return FALSE;
157
158 return (mciSendCommand(m_internal->dev_id, MCI_RESUME, 0, 0) == 0);
159 }
160
161 wxCDAudio::CDstatus wxCDAudioWin::GetStatus(void)
162 {
163 MCI_STATUS_PARMS status_struct;
164
165 if (!m_ok)
166 return STOPPED;
167
168 status_struct.dwItem = MCI_STATUS_MODE;
169 mciSendCommand(m_internal->dev_id, MCI_STATUS, MCI_STATUS_ITEM,
170 (DWORD)&status_struct);
171 switch (status_struct.dwReturn) {
172 case MCI_MODE_PAUSE:
173 return PAUSED;
174 case MCI_MODE_PLAY:
175 return PLAYING;
176 }
177 return STOPPED;
178 }
179
180 wxCDtime wxCDAudioWin::GetTime(void)
181 {
182 MCI_STATUS_PARMS status_struct;
183 wxCDtime cd_time = {-1, -1, -1, -1};
184
185 if (!m_ok)
186 return cd_time;
187
188 status_struct.dwItem = MCI_STATUS_TIME_FORMAT;
189 mciSendCommand(m_internal->dev_id, MCI_STATUS, MCI_STATUS_ITEM,
190 (DWORD)&status_struct);
191 cd_time.track = MCI_TMSF_TRACK(status_struct.dwReturn);
192 cd_time.min = MCI_TMSF_MINUTE(status_struct.dwReturn);
193 cd_time.sec = MCI_TMSF_SECOND(status_struct.dwReturn);
194 cd_time.hour = cd_time.min / 60;
195 cd_time.min %= 60;
196 return cd_time;
197 }
198
199 const wxCDAudio::CDtoc& wxCDAudioWin::GetToc(void)
200 {
201 return *m_toc;
202 }