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