|
1 /* |
|
2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implementation of the Environmental Reverb proxy class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #ifdef _DEBUG |
|
24 #include <e32svr.h> |
|
25 #endif |
|
26 |
|
27 #include "EnvironmentalReverbProxy.h" |
|
28 #include "EnvironmentalReverbEventObserver.h" |
|
29 #include "RoomLevelProxy.h" |
|
30 #include <CustomInterfaceUtility.h> |
|
31 |
|
32 |
|
33 |
|
34 // ============================ MEMBER FUNCTIONS =============================== |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CEnvironmentalReverbProxy::CEnvironmentalReverbProxy |
|
38 // C++ default constructor can NOT contain any code, that |
|
39 // might leave. |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 CEnvironmentalReverbProxy::CEnvironmentalReverbProxy( |
|
43 TMMFMessageDestinationPckg aMessageHandler, |
|
44 MCustomCommand& aCustomCommand, |
|
45 CCustomInterfaceUtility* aCustomInterfaceUtility ) |
|
46 : iCustomCommand(&aCustomCommand), |
|
47 iMessageHandler(aMessageHandler), |
|
48 iCustomInterfaceUtility(aCustomInterfaceUtility) |
|
49 |
|
50 { |
|
51 } |
|
52 |
|
53 // Destructor |
|
54 CEnvironmentalReverbProxy::~CEnvironmentalReverbProxy() |
|
55 { |
|
56 // Remove the custom interface message handler before we destroy the proxy. |
|
57 |
|
58 TInt numOfRoomLevel = iCRoomLevelProxyList.Count(); |
|
59 if (numOfRoomLevel > 0) |
|
60 { |
|
61 for (TInt i = 0; i < numOfRoomLevel; ++i) |
|
62 { |
|
63 iCRoomLevelProxyList[i]->DettachReverb(*this); |
|
64 } |
|
65 }; |
|
66 iCRoomLevelProxyList.Close(); |
|
67 if(iCustomInterfaceUtility) |
|
68 iCustomInterfaceUtility->RemoveCustomInterface(iMessageHandler); |
|
69 delete iEnvironmentalReverbEventObserver; |
|
70 delete iCustomInterfaceUtility; |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // CEnvironmentalReverbProxy::NewL |
|
75 // Static function for creating an instance of the Environmental Reverb object. |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 EXPORT_C CEnvironmentalReverbProxy* CEnvironmentalReverbProxy::NewL( |
|
79 TMMFMessageDestinationPckg aMessageHandler, |
|
80 MCustomCommand& aCustomCommand, |
|
81 CCustomInterfaceUtility* aCustomInterfaceUtility ) |
|
82 { |
|
83 CEnvironmentalReverbProxy* self = new (ELeave) CEnvironmentalReverbProxy(aMessageHandler, aCustomCommand, aCustomInterfaceUtility); |
|
84 CleanupStack::PushL(self); |
|
85 self->ConstructL(); |
|
86 CleanupStack::Pop(self); |
|
87 return self; |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CEnvironmentalReverbProxy::ConstructL |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 void CEnvironmentalReverbProxy::ConstructL() |
|
95 { |
|
96 #ifdef _DEBUG |
|
97 RDebug::Print(_L("CEnvironmentalReverbProxy::ConstructL")); |
|
98 #endif |
|
99 iEnvironmentalReverbEventObserver = CEnvironmentalReverbEventObserver::NewL(iMessageHandler, *iCustomCommand, *this); |
|
100 StartObserver(); |
|
101 // sends a message to fetch initial data. |
|
102 TEfEnvReverbDataPckg dataPckgFrom; |
|
103 iCustomCommand->CustomCommandSync(iMessageHandler, (TInt)EErfInitialize, KNullDesC8, KNullDesC8, dataPckgFrom); |
|
104 SetEffectData(dataPckgFrom); |
|
105 |
|
106 } |
|
107 |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // CEnvironmentalReverbProxy::GetUniqueId |
|
111 // return a TInt 32 integer |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 TUint32 CEnvironmentalReverbProxy::GetUniqueId() const |
|
115 { |
|
116 return iReverbData.iEnvironmentalReverbId; |
|
117 } |
|
118 |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // CEnvironmentalReverbProxy::AttachRoomLevel |
|
122 // Add the reference of aProxy to array |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 TInt CEnvironmentalReverbProxy::RoomLevelAttached(CRoomLevelProxy& aProxy) |
|
126 { |
|
127 |
|
128 TInt error = iCRoomLevelProxyList.Find(&aProxy); |
|
129 if (error == KErrNotFound) |
|
130 { |
|
131 error = iCRoomLevelProxyList.Append(&aProxy); |
|
132 } |
|
133 |
|
134 |
|
135 return error; |
|
136 |
|
137 } |
|
138 |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // CEnvironmentalReverbImpl::DetachRoomLevel |
|
142 // Remove the reference of aProxy from array |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 TInt CEnvironmentalReverbProxy::RoomLevelDetached(CRoomLevelProxy& aProxy) |
|
146 { |
|
147 TInt found = iCRoomLevelProxyList.Find(&aProxy); |
|
148 if (found != KErrNotFound) |
|
149 { |
|
150 iCRoomLevelProxyList.Remove(found); |
|
151 found = KErrNone; |
|
152 } |
|
153 return found; |
|
154 } |
|
155 |
|
156 |
|
157 // ----------------------------------------------------------------------------- |
|
158 // CEnvironmentalReverbProxy::ApplyL |
|
159 // Apply the Environmental Reverb settings. |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 EXPORT_C void CEnvironmentalReverbProxy::ApplyL() |
|
163 { |
|
164 #ifdef _DEBUG |
|
165 RDebug::Print(_L("CEnvironmentalReverbProxy::Apply")); |
|
166 #endif |
|
167 |
|
168 if ( !iHaveUpdateRights ) |
|
169 { |
|
170 User::Leave(KErrAccessDenied); |
|
171 } |
|
172 |
|
173 iReverbData.iEnabled = iEnabled; |
|
174 iReverbData.iEnforced = iEnforced; |
|
175 iReverbData.iHaveUpdateRights = iHaveUpdateRights; |
|
176 iCustomCommand->CustomCommandSync(iMessageHandler, (TInt)EErfApply, DoEffectData(), KNullDesC8); |
|
177 |
|
178 } |
|
179 |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // CEnvironmentalReverbProxy::StartObserver |
|
183 // Starts the event observer. The event observer monitors asynchronous events |
|
184 // from the message handler. |
|
185 // ----------------------------------------------------------------------------- |
|
186 // |
|
187 void CEnvironmentalReverbProxy::StartObserver() |
|
188 { |
|
189 #ifdef _DEBUG |
|
190 RDebug::Print(_L("CEnvironmentalReverbProxy::StartObserver")); |
|
191 #endif |
|
192 |
|
193 iEnvironmentalReverbEventObserver->Start(); |
|
194 } |
|
195 |
|
196 // ----------------------------------------------------------------------------- |
|
197 // CEnvironmentalReverbProxy::EnvironmentalReverbEvent |
|
198 // Checks which data member has changed and notify the observers. |
|
199 // ----------------------------------------------------------------------------- |
|
200 // |
|
201 void CEnvironmentalReverbProxy::EnvironmentalReverbEvent( |
|
202 const TDesC8& aBuffer ) |
|
203 { |
|
204 #ifdef _DEBUG |
|
205 RDebug::Print(_L("CEnvironmentalReverbProxy::EnvironmentalReverbEvent")); |
|
206 #endif |
|
207 |
|
208 TEfEnvReverbDataPckg dataPckgFrom; |
|
209 dataPckgFrom.Copy(aBuffer); |
|
210 TEfEnvironmentalReverb newReverbData = dataPckgFrom(); |
|
211 |
|
212 TUint8 event = 0; |
|
213 |
|
214 if ( newReverbData.iEnabled != iReverbData.iEnabled ) |
|
215 { |
|
216 iReverbData.iEnabled = newReverbData.iEnabled; |
|
217 iEnabled = newReverbData.iEnabled; |
|
218 if ( iReverbData.iEnabled ) |
|
219 { |
|
220 event = MAudioEffectObserver::KEnabled; |
|
221 } |
|
222 else |
|
223 { |
|
224 event = MAudioEffectObserver::KDisabled; |
|
225 } |
|
226 } |
|
227 else if ( newReverbData.iEnforced != iReverbData.iEnforced ) |
|
228 { |
|
229 iReverbData.iEnforced = newReverbData.iEnforced; |
|
230 iEnforced = newReverbData.iEnforced; |
|
231 if ( iReverbData.iEnforced ) |
|
232 { |
|
233 event = MAudioEffectObserver::KEnforced; |
|
234 } |
|
235 else |
|
236 { |
|
237 event = MAudioEffectObserver::KNotEnforced; |
|
238 } |
|
239 } |
|
240 else if ( newReverbData.iHaveUpdateRights != iReverbData.iHaveUpdateRights ) |
|
241 { |
|
242 iReverbData.iHaveUpdateRights = newReverbData.iHaveUpdateRights; |
|
243 iHaveUpdateRights = newReverbData.iHaveUpdateRights; |
|
244 if ( iReverbData.iHaveUpdateRights ) |
|
245 { |
|
246 event = MAudioEffectObserver::KGainedUpdateRights; |
|
247 } |
|
248 else |
|
249 { |
|
250 event = MAudioEffectObserver::KLostUpdateRights; |
|
251 } |
|
252 } |
|
253 else if ( newReverbData.iDecayTime != iReverbData.iDecayTime ) |
|
254 { |
|
255 iReverbData.iDecayTime = newReverbData.iDecayTime; |
|
256 event = MEnvironmentalReverbObserver::KDecayTimeChanged; |
|
257 } |
|
258 else if ( newReverbData.iDecayHFRatio != iReverbData.iDecayHFRatio ) |
|
259 { |
|
260 iReverbData.iDecayHFRatio = newReverbData.iDecayHFRatio; |
|
261 event = MEnvironmentalReverbObserver::KDecayHFRatioChanged; |
|
262 } |
|
263 else if ( newReverbData.iDensity != iReverbData.iDensity ) |
|
264 { |
|
265 iReverbData.iDensity = newReverbData.iDensity; |
|
266 event = MEnvironmentalReverbObserver::KDensityChanged; |
|
267 } |
|
268 else if ( newReverbData.iDiffusion != iReverbData.iDiffusion ) |
|
269 { |
|
270 iReverbData.iDiffusion = newReverbData.iDiffusion; |
|
271 event = MEnvironmentalReverbObserver::KDiffusionChanged; |
|
272 } |
|
273 else if ( newReverbData.iReflectionsDelay != iReverbData.iReflectionsDelay ) |
|
274 { |
|
275 iReverbData.iReflectionsDelay = newReverbData.iReflectionsDelay; |
|
276 event = MEnvironmentalReverbObserver::KReflectionsDelayChanged; |
|
277 } |
|
278 else if ( newReverbData.iReflectionsLevel != iReverbData.iReflectionsLevel ) |
|
279 { |
|
280 iReverbData.iReflectionsLevel = newReverbData.iReflectionsLevel; |
|
281 event = MEnvironmentalReverbObserver::KReflectionsLevelChanged; |
|
282 } |
|
283 else if ( newReverbData.iReverbDelay != iReverbData.iReverbDelay ) |
|
284 { |
|
285 iReverbData.iReverbDelay = newReverbData.iReverbDelay; |
|
286 event = MEnvironmentalReverbObserver::KReverbDelayChanged; |
|
287 } |
|
288 else if ( newReverbData.iReverbLevel != iReverbData.iReverbLevel ) |
|
289 { |
|
290 iReverbData.iReverbLevel = newReverbData.iReverbLevel; |
|
291 event = MEnvironmentalReverbObserver::KReverbLevelChanged; |
|
292 } |
|
293 else if ( newReverbData.iRoomLevel != iReverbData.iRoomLevel ) |
|
294 { |
|
295 iReverbData.iRoomLevel = newReverbData.iRoomLevel; |
|
296 event = MEnvironmentalReverbObserver::KRoomLevelChanged; |
|
297 } |
|
298 else if ( newReverbData.iRoomHFLevel != iReverbData.iRoomHFLevel ) |
|
299 { |
|
300 iReverbData.iRoomHFLevel = newReverbData.iRoomHFLevel; |
|
301 event = MEnvironmentalReverbObserver::KRoomHFLevelChanged; |
|
302 } |
|
303 else if ( newReverbData.iEnvironmentalReverbId != iReverbData.iEnvironmentalReverbId ) |
|
304 { |
|
305 iReverbData.iEnvironmentalReverbId = newReverbData.iEnvironmentalReverbId; |
|
306 // event = MEnvironmentalReverbObserver::KRoomHFLevelChanged; |
|
307 } |
|
308 |
|
309 |
|
310 |
|
311 if (!event) |
|
312 return; |
|
313 |
|
314 for ( TInt i = 0; i < iObservers.Count(); i++ ) |
|
315 { |
|
316 iObservers[i]->EffectChanged(this, event); |
|
317 } |
|
318 } |
|
319 |
|
320 |
|
321 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
322 |
|
323 // End of File |
|
324 |
|
325 |