os/mm/mmlibs/mmfw/tsrc/mmfunittest/MidiClnt/MidiTestCntrl/Ts_cmmfmiditestcontroller.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200 (2014-06-10)
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include <e32svr.h>
    17 
    18 //const TInt KOpenDelay =500000;;		// EABI warning removal
    19 //const TInt KPrepareDelay = 500000;;	// EABI warning removal
    20 //const TInt KFrameReadyDelay = 500000;;	// EABI warning removal
    21 //const TInt KDuration = 1000000;		// EABI warning removal
    22 //const TInt KFrameLength = 100000;		// EABI warning removal
    23 
    24 //const TInt KMaxVolume = 100;		// EABI warning removal
    25 //const TInt KFrameWidth = 100;		// EABI warning removal
    26 //const TInt KFrameHeight = 50;		// EABI warning removal
    27 
    28 //const TInt KBufMimeTypeGranularity = 4;		// EABI warning removal
    29 
    30 const TUint8 KMaxChannelNumber = 15;
    31 
    32 #include <mmf/server/mmffile.h>
    33 #include "Ts_cmmfmiditestcontroller.h"
    34 
    35 #include <mmf/common/mmfmidi.h>
    36 
    37 
    38 
    39 /*
    40 _LIT(KMmfTestControllerCategory, "CMMFTestController");
    41 GLDEF_C void Panic(TMmfTestControllerPanic aReason)
    42 	{
    43 	User::Panic(KMmfTestControllerCategory, aReason);
    44 	}
    45 */
    46 _LIT(KMidiClntChunk, "MidiClntChunk");
    47 _LIT(KMidiClntSemaphore, "MidiClntSemaphore");
    48 
    49 
    50 CMMFMidiTestController* CMMFMidiTestController::NewL()
    51 	{
    52 	CMMFMidiTestController* self = CMMFMidiTestController::NewLC();
    53 	CleanupStack::Pop();
    54 	return self;
    55 	}
    56 
    57 CMMFMidiTestController* CMMFMidiTestController::NewLC(void)
    58 	{
    59 	CMMFMidiTestController* self = new (ELeave) CMMFMidiTestController();
    60 	CleanupStack::PushL(self);
    61 	self->ConstructL();
    62 	return self;
    63 	}
    64 
    65 CMMFMidiTestController::CMMFMidiTestController()
    66 	{
    67 	iPlayBackRate = 1001;
    68 	iMinRate = 1002;
    69 	iMaxRate = 1003;
    70 	iTempoMicroBeatsPerMinute = 1004;
    71 	iPitchTranspositionCents= 1005;
    72 	iCentsApplied = 1006;
    73 	iDurationMicroSeconds = 1007;
    74 	iDurationMicroBeats = 1008;
    75 	iNumTracks = 1009;
    76 	iPositionMicroSeconds = 1010;
    77 	iPositionMicroBeats = 1011;
    78 	iNumBanks = 1012;
    79 	iNumInstruments = 1013;
    80 	iStopTime = 999;
    81 	iNumNotes = 57;
    82 	iChannels = 15;
    83 	iMaxVol = 60000;
    84 	iMaxVolume = 100000;
    85 	iBalance = 2;
    86 	iRepeatNumberOfTimes = 0;
    87 	iTrailingSilence = TTimeIntervalMicroSeconds(0);
    88 	iCurrentMidiTestControllerState = EMidiStateClosedDisengaged;
    89 	}
    90 
    91 CMMFMidiTestController::~CMMFMidiTestController(void)
    92 	{
    93 	delete iDelayEvent;
    94 	delete iMidiEventGenerator;
    95 	delete iChanVolumeValues;
    96 	}
    97                     
    98 void CMMFMidiTestController::ConstructL (void)
    99 	{
   100 	iDelayEvent = CControllerTimer::NewL(this);
   101 	CActiveScheduler::Add(iDelayEvent);
   102 
   103 	iMidiEventGenerator = CMidiEventGenerator::NewL(this);
   104 	CActiveScheduler::Add(iMidiEventGenerator);
   105 
   106 	//TUid uid = {0x101F945C};
   107 	CMidiCustomCommandParser* midiParser = CMidiCustomCommandParser::NewL(*this);
   108 	iMidiEventHandler = midiParser;
   109 	CleanupStack::PushL(midiParser);
   110 	AddCustomCommandParserL(*midiParser);
   111 	CleanupStack::Pop();
   112 	
   113 	CMMFDRMCustomCommandParser* drmParser = CMMFDRMCustomCommandParser::NewL(*this);
   114 	CleanupStack::PushL(drmParser);
   115 	AddCustomCommandParserL(*drmParser);
   116 	CleanupStack::Pop();
   117 	
   118 	iChanVolumeValues = new(ELeave)CArrayFixFlat<TReal32>(KMaxChannelNumber);
   119 	if (iChanVolumeValues)
   120 		{
   121 		for (TInt i=0; i<=KMaxChannelNumber; i++)
   122 			iChanVolumeValues->AppendL(0);
   123 		}
   124 	}
   125 
   126 // The method below need to be filled in with the correct responses
   127 
   128 void CMMFMidiTestController::AddDataSourceL(MDataSource& aDataSource)
   129 	{
   130 	iDataSource = &aDataSource;
   131 	iDelayEvent->DelayOpen(TTimeIntervalMicroSeconds(1000000));//1sec
   132 	}
   133 
   134 void CMMFMidiTestController::AddDataSinkL(MDataSink& /*aDataSink*/)
   135 	{
   136 	}
   137 
   138 void CMMFMidiTestController::RemoveDataSourceL(MDataSource& /*aDataSource*/)
   139 	{
   140 	iDataSource = NULL;
   141 	}
   142 
   143 void CMMFMidiTestController::RemoveDataSinkL(MDataSink& /*aDataSink*/)
   144 	{
   145 	}
   146 
   147 void CMMFMidiTestController::RemoveSourceSinkL()
   148 	{
   149 	}
   150 
   151 
   152 void CMMFMidiTestController::ResetL() //XXX - replacement for RemoveSourceSink()
   153 	{
   154 	}
   155 
   156 /*No leave happens when there is no iDataSource here because a
   157   user suppose to perform Midi Live Event even when there 
   158   is no resource (file) opened.*/
   159 void CMMFMidiTestController::PrimeL()
   160 	{
   161 	 if (iDataSource)
   162 		{
   163 		iDataSource->SourcePrimeL();
   164 		}
   165 	}
   166 
   167 void CMMFMidiTestController::PlayL()
   168 	{
   169 	if (iDataSource)
   170 		{
   171 		if (!iDisableAutoIntent)
   172 			{
   173 			User::LeaveIfError( MdcExecuteIntent(ContentAccess::EPlay) );
   174 			}
   175 		}	
   176 	iDelayEvent->DelayPlayStarted(TTimeIntervalMicroSeconds(100000));//1 sec
   177 	}
   178 
   179 void CMMFMidiTestController::PauseL()
   180 	{
   181 	if (iDataSource)
   182 		{
   183 		iDataSource->SourcePauseL();
   184 		}
   185 	else
   186 		{
   187 		User::Leave(KErrNotReady);
   188 		}			
   189 	}
   190 
   191 void CMMFMidiTestController::StopL()
   192 	{
   193 	if(iDelayEvent->IsActive())
   194 		{
   195 		iDelayEvent->Cancel();
   196 		}
   197 	iDelayEvent->DelayStop(TTimeIntervalMicroSeconds(0));
   198 	if (iDataSource)
   199 		{
   200 		iDataSource->SourceStopL();
   201 		}
   202 	}
   203 
   204 TTimeIntervalMicroSeconds CMMFMidiTestController::PositionL() const
   205 	{
   206 	if (!iDataSource)
   207 		{
   208 		User::Leave(KErrNotReady);
   209 		}
   210 	return iPositionMicroSeconds;				
   211 
   212 	}
   213 
   214 void CMMFMidiTestController::SetPositionL(const TTimeIntervalMicroSeconds& /*aPosition*/)
   215 	{
   216 	}
   217 
   218 TTimeIntervalMicroSeconds CMMFMidiTestController::DurationL() const
   219 	{
   220 	return iDurationMicroSeconds;
   221 	}
   222 
   223 void CMMFMidiTestController::CustomCommand(TMMFMessage& aMessage)
   224 	{
   225 	if (aMessage.Destination().InterfaceId() == KUidInterfaceMMFDRMControl)
   226 		{
   227 		aMessage.Complete(KErrNotSupported);
   228 		}
   229 	else
   230 		{
   231 		aMessage.Complete(KErrNone);
   232 		}
   233 	}
   234 
   235 void CMMFMidiTestController::SetPrioritySettings(const TMMFPrioritySettings& /*aPrioritySettings*/)
   236 	{
   237 	}
   238 
   239 void CMMFMidiTestController::GetNumberOfMetaDataEntriesL(TInt& aNumberOfEntries)
   240 	{
   241 	aNumberOfEntries = 10;
   242 	}
   243 
   244 CMMFMetaDataEntry* CMMFMidiTestController::GetMetaDataEntryL(TInt /*aIndex*/)
   245 	{ 
   246 	CMMFMetaDataEntry* metaDataEntry = NULL;
   247 	return metaDataEntry;
   248 	}
   249 
   250 TInt CMMFMidiTestController::SendEventToClient(const TMMFEvent& aEvent)
   251 	{
   252 	//send event to client...
   253 	TInt result = DoSendEventToClient(aEvent);
   254 	return result;
   255 	}
   256 
   257 TInt CMMFMidiTestController::OpenComplete()
   258 	{
   259 	CMMFMidiEvent* opencomplete = new CMMFMidiEvent(KMMFEventCategoryMidiOpenDataSourceComplete, KErrNone);
   260 	if(!opencomplete)
   261 		return KErrNoMemory;
   262 	switch (iCurrentMidiTestControllerState)
   263 	{
   264 		case EMidiStateClosedDisengaged: 
   265 			opencomplete->iOldState = EMidiStateClosedDisengaged;
   266 			opencomplete->iNewState = EMidiStateOpenDisengaged;
   267 			iCurrentMidiTestControllerState = EMidiStateOpenDisengaged;
   268 			break;
   269 		case EMidiStateOpenPlaying:
   270 			opencomplete->iOldState = EMidiStateOpenPlaying;
   271 			opencomplete->iNewState = EMidiStateOpenEngaged;
   272 			iCurrentMidiTestControllerState = EMidiStateOpenEngaged;
   273 			break;
   274 		default:
   275 			opencomplete->iOldState = iCurrentMidiTestControllerState;
   276 			opencomplete->iNewState = iCurrentMidiTestControllerState;
   277 			opencomplete->iEventType = KMMFErrorCategoryControllerGeneralError;
   278 			break;
   279 	}	
   280 	opencomplete->iMicroSeconds = iDurationMicroSeconds;
   281 	iMidiEventHandler->SendMidiEventToClient(*opencomplete);
   282 	delete opencomplete;
   283 	return KErrNone;
   284 	}
   285 
   286 TInt CMMFMidiTestController::PlayStarted()
   287 	{
   288 	CMMFMidiEvent* playStarted = new CMMFMidiEvent(KMMFEventCategoryMidiPlaying, KErrNone);
   289 	if(!playStarted)
   290 		return KErrNoMemory;
   291 	// decide which is the state the MIDI controller can go into when Play is called
   292 	switch (iCurrentMidiTestControllerState)
   293 		{
   294 		case EMidiStateClosedDisengaged:
   295 		playStarted->iOldState = EMidiStateClosedDisengaged;
   296 		playStarted->iNewState = EMidiStateClosedEngaged;
   297 		iCurrentMidiTestControllerState = EMidiStateClosedEngaged;
   298 		playStarted->iMicroSeconds = TTimeIntervalMicroSeconds(0);
   299 		iMidiEventHandler->SendMidiEventToClient(*playStarted);
   300 		delete playStarted; 
   301 		iDelayEvent->PlayFinished(TTimeIntervalMicroSeconds(20000000));//20 sec
   302 		iMidiEventGenerator->MidiEventTrigger();
   303 		break;
   304 	
   305 		case EMidiStateOpenDisengaged:
   306 		playStarted->iOldState = EMidiStateOpenDisengaged;
   307 		playStarted->iNewState = EMidiStateOpenPlaying;
   308 		iCurrentMidiTestControllerState = EMidiStateOpenPlaying;
   309 		playStarted->iMicroSeconds = TTimeIntervalMicroSeconds(0);
   310 		iMidiEventHandler->SendMidiEventToClient(*playStarted);
   311 		delete playStarted; 
   312 		iDelayEvent->PlayFinished(TTimeIntervalMicroSeconds(20000000));//20 sec
   313 		iMidiEventGenerator->MidiEventTrigger();
   314 		break;
   315 		
   316 		case EMidiStateOpenEngaged:
   317 		playStarted->iOldState = EMidiStateOpenEngaged;
   318 		playStarted->iNewState = EMidiStateOpenPlaying;
   319 		iCurrentMidiTestControllerState = EMidiStateOpenPlaying;
   320 		playStarted->iMicroSeconds = TTimeIntervalMicroSeconds(0);
   321 		iMidiEventHandler->SendMidiEventToClient(*playStarted);
   322 		delete playStarted; 
   323 		iDelayEvent->PlayFinished(TTimeIntervalMicroSeconds(20000000));//20 sec
   324 		iMidiEventGenerator->MidiEventTrigger();
   325 		break;
   326 		
   327 		default:
   328 		playStarted->iOldState = iCurrentMidiTestControllerState;
   329 		playStarted->iNewState = iCurrentMidiTestControllerState;
   330 		playStarted->iEventType = KMMFErrorCategoryControllerGeneralError;
   331 		playStarted->iMicroSeconds = TTimeIntervalMicroSeconds(0);
   332 		iMidiEventHandler->SendMidiEventToClient(*playStarted);
   333 		delete playStarted; 
   334 		break;
   335 		}
   336 	return KErrNone;
   337 	}
   338 
   339 TInt CMMFMidiTestController::PlayFinished()
   340 	{
   341 	TUid tmp;
   342 	tmp.iUid = 0 ;
   343 	CMMFMidiEvent* playFinished = new CMMFMidiEvent(tmp, KErrNone);
   344 	if(!playFinished)
   345 		return KErrNoMemory;
   346 	switch (iCurrentMidiTestControllerState)
   347 		{
   348 		case EMidiStateClosedEngaged:
   349 		playFinished->iOldState = EMidiStateClosedEngaged;
   350 		playFinished->iNewState = EMidiStateClosedEngaged;
   351 		iCurrentMidiTestControllerState = EMidiStateClosedEngaged;
   352 		break;
   353 	
   354 		case EMidiStateOpenPlaying:
   355 		playFinished->iOldState = EMidiStateOpenPlaying;
   356 		playFinished->iNewState = EMidiStateOpenEngaged;
   357 		iCurrentMidiTestControllerState = EMidiStateOpenEngaged;
   358 		break;
   359 			
   360 		default:
   361 		playFinished->iOldState = iCurrentMidiTestControllerState;
   362 		playFinished->iNewState = iCurrentMidiTestControllerState;
   363 		playFinished->iEventType = KMMFErrorCategoryControllerGeneralError;
   364 		break;
   365 		}
   366 		
   367 	playFinished->iMicroSeconds = iDurationMicroSeconds;
   368 	iMidiEventHandler->SendMidiEventToClient(*playFinished);
   369 	delete playFinished;
   370 	return KErrNone;
   371 	}
   372 
   373 TInt CMMFMidiTestController::Stop()
   374 	{
   375 	CMMFMidiEvent* playStop = new CMMFMidiEvent(KMMFEventCategoryMidiPlayingComplete, KErrNone);
   376 	if(!playStop)
   377 		return KErrNoMemory;
   378 	
   379 	switch (iCurrentMidiTestControllerState)
   380 		{
   381 		case EMidiStateOpenPlaying:
   382 		playStop->iOldState = EMidiStateOpenPlaying;
   383 		playStop->iNewState = EMidiStateOpenDisengaged;
   384 		iCurrentMidiTestControllerState = EMidiStateOpenDisengaged;
   385 		break;
   386 		
   387 		case EMidiStateClosedEngaged:
   388 		playStop->iOldState = EMidiStateClosedEngaged;
   389 		playStop->iNewState = EMidiStateClosedDisengaged;
   390 		iCurrentMidiTestControllerState = EMidiStateClosedDisengaged;
   391 		break;
   392 		
   393 		case EMidiStateOpenEngaged:
   394 		playStop->iOldState = EMidiStateOpenEngaged;
   395 		playStop->iNewState = EMidiStateOpenDisengaged;
   396 		iCurrentMidiTestControllerState = EMidiStateOpenDisengaged;
   397 		break;
   398 		
   399 		default:
   400 		playStop->iOldState = iCurrentMidiTestControllerState;
   401 		playStop->iNewState = iCurrentMidiTestControllerState;
   402 		playStop->iEventType = KMMFErrorCategoryControllerGeneralError;
   403 		break;
   404 		}
   405 	
   406 	playStop->iMicroSeconds = iPositionMicroSeconds;
   407 	iMidiEventHandler->SendMidiEventToClient(*playStop);
   408 	delete playStop;
   409 	return KErrNone;
   410 	}
   411 
   412 TInt CMMFMidiTestController::Close()
   413 	{
   414 	CMMFMidiEvent* close = new CMMFMidiEvent(KMMFEventCategoryMidiClose, KErrNone);
   415 	if(!close)
   416 		return KErrNoMemory;
   417 	
   418 	switch (iCurrentMidiTestControllerState)
   419 		{
   420 		case EMidiStateOpenDisengaged:
   421 		close->iOldState = EMidiStateOpenDisengaged;
   422 		close->iNewState = EMidiStateClosedDisengaged;
   423 		iCurrentMidiTestControllerState = EMidiStateClosedDisengaged;
   424 		break;
   425 		
   426 		case EMidiStateOpenPlaying:
   427 		close->iOldState = EMidiStateOpenPlaying;
   428 		close->iNewState = EMidiStateClosedDisengaged;
   429 		iCurrentMidiTestControllerState = EMidiStateClosedEngaged;
   430 		break;
   431 		
   432 		case EMidiStateOpenEngaged:
   433 		close->iOldState = EMidiStateOpenEngaged;
   434 		close->iNewState = EMidiStateClosedEngaged;
   435 		iCurrentMidiTestControllerState = EMidiStateClosedEngaged;
   436 		break;
   437 		
   438 		default:
   439 		close->iOldState = iCurrentMidiTestControllerState;
   440 		close->iNewState = iCurrentMidiTestControllerState;
   441 		close->iEventType = KMMFErrorCategoryControllerGeneralError;
   442 		break;
   443 		}
   444 	close->iMicroSeconds = TTimeIntervalMicroSeconds(0);
   445 	iMidiEventHandler->SendMidiEventToClient(*close);
   446 	delete close;
   447 	return KErrNone;
   448 	}
   449 
   450 TInt CMMFMidiTestController::SyncUpdate()
   451 	{
   452 	CMMFMidiEvent* syncUpd = new CMMFMidiEvent(KMMFEventCategoryMidiSyncUpdate, KErrNone);
   453 	if(!syncUpd)
   454 		return KErrNoMemory;
   455 	iMidiEventHandler->SendMidiEventToClient(*syncUpd);
   456 	delete syncUpd;
   457 	return KErrNone;
   458 	}
   459 
   460 TInt CMMFMidiTestController::TempoChanged()
   461 	{
   462 	CMMFMidiEvent* tempoChanged = new CMMFMidiEvent(KMMFEventCategoryTempoChanged, KErrNone);
   463 	if(!tempoChanged)
   464 		return KErrNoMemory;
   465 	tempoChanged->iTempoMicroBeats = 60; //Adagio
   466 	iMidiEventHandler->SendMidiEventToClient(*tempoChanged);
   467 	delete tempoChanged;
   468 	iMidiEventGenerator->MidiEventTrigger();
   469 	return KErrNone;
   470 	}
   471 
   472 TInt CMMFMidiTestController::VolumeChanged()
   473 	{
   474 	CMMFMidiEvent* volumeChanged = new CMMFMidiEvent(KMMFEventCategoryVolumeChanged, KErrNone);
   475 	if(!volumeChanged)
   476 		return KErrNoMemory;
   477 	volumeChanged->iVolumeInDecibels = 50000;
   478 	volumeChanged->iChannel = 14;
   479 	iMidiEventHandler->SendMidiEventToClient(*volumeChanged);
   480 	delete volumeChanged;
   481 	iMidiEventGenerator->MidiEventTrigger();
   482 	return KErrNone;
   483 	}
   484 
   485 TInt CMMFMidiTestController::MuteChanged()
   486 	{
   487 	CMMFMidiEvent* muteChanged = new CMMFMidiEvent(KMMFEventCategoryMuteChanged, KErrNone);
   488 	if(!muteChanged)
   489 		return KErrNoMemory;
   490 	muteChanged->iChannel = 15;
   491 	muteChanged->iMute = ETrue;
   492 	iMidiEventHandler->SendMidiEventToClient(*muteChanged);
   493 	delete muteChanged;
   494 	iMidiEventGenerator->MidiEventTrigger();
   495 	return KErrNone;
   496 	}
   497 
   498 TInt CMMFMidiTestController::PolyphonyChanged()
   499 	{
   500 	CMMFMidiEvent* polyphonyChanged = new CMMFMidiEvent(KMMFEventCategoryPolyphonyChanged, KErrNone);
   501 	if(!polyphonyChanged)
   502 		return KErrNoMemory;
   503 	polyphonyChanged->iPolyphony = 10;
   504 	iMidiEventHandler->SendMidiEventToClient(*polyphonyChanged);
   505 	delete polyphonyChanged;
   506 	iMidiEventGenerator->MidiEventTrigger();
   507 	return KErrNone;
   508 	}
   509 
   510 TInt CMMFMidiTestController::InstrumentChanged()
   511 	{
   512 	CMMFMidiEvent* instrumentChanged = new CMMFMidiEvent(KMMFEventCategoryInstrumentChanged, KErrNone);
   513 	if(!instrumentChanged )
   514 		return KErrNoMemory;
   515 	instrumentChanged->iChannel = 3;
   516 	instrumentChanged->iBankId = 4;
   517 	instrumentChanged->iInstrumentId = 5; 
   518 	iMidiEventHandler->SendMidiEventToClient(*instrumentChanged);
   519 	delete instrumentChanged ;
   520 	iMidiEventGenerator->MidiEventTrigger();
   521 	return KErrNone;
   522 	}
   523 
   524 TInt CMMFMidiTestController::SmfMetaDataEntryFound()
   525 	{
   526 	TTimeIntervalMicroSeconds position(200000);
   527 	CMMFMidiEvent* smfMetaDataEntryFound = new CMMFMidiEvent(KMMFEventCategoryMetaDataEntryFound, KErrNone);
   528 	if(!smfMetaDataEntryFound )
   529 		return KErrNoMemory;
   530 	smfMetaDataEntryFound->iMetaDataEntryId = 15;//Not supported in this test controller
   531 	smfMetaDataEntryFound->iMicroSeconds = position;
   532 	iMidiEventHandler->SendMidiEventToClient(*smfMetaDataEntryFound);
   533 	delete smfMetaDataEntryFound;
   534 	iMidiEventGenerator->MidiEventTrigger();
   535 	return KErrNone;
   536 	}
   537 
   538 TInt CMMFMidiTestController::MipMessageReceived()
   539 	{
   540 	TMipMessageEntry mipMessageEntry;
   541 	mipMessageEntry.iChannel = 11;
   542 	mipMessageEntry.iMIPValue = 21;
   543 
   544 	TMipMessageEntry mipMessageEntry2;
   545 	mipMessageEntry2.iChannel = 1;
   546 	mipMessageEntry2.iMIPValue = 2;
   547 
   548 	CMMFMidiEvent* mipMessageReceived = new CMMFMidiEvent(KMMFEventCategoryMipMessageReceived, KErrNone);
   549 	if(!mipMessageReceived )
   550 		return KErrNoMemory;
   551 	mipMessageReceived->iMipMessage.Append(mipMessageEntry);
   552 
   553 	CMMFMidiEvent* mipMessageReceived2 = new CMMFMidiEvent(KMMFEventCategoryMipMessageReceived, KErrNone);
   554 	if(!mipMessageReceived2 )
   555 		return KErrNoMemory;
   556 	mipMessageReceived2->iMipMessage.Append(mipMessageEntry2);
   557 
   558 	
   559 	iMidiEventHandler->SendMidiEventToClient(*mipMessageReceived);
   560 	iMidiEventHandler->SendMidiEventToClient(*mipMessageReceived2);
   561 	delete mipMessageReceived;
   562 	delete mipMessageReceived2;
   563 	return KErrNone;
   564 	}
   565 
   566 void CMMFMidiTestController::MmcSetPositionMicroBeatsL(TInt64 /*aMicroBeats*/)
   567 	{
   568 	InsertInterfaceNameInChunk(_L8("SetPositionMicroBeatsL"));
   569 	}
   570 
   571 void CMMFMidiTestController::MmcPositionMicroBeatsL(TInt64& aMicroBeats)
   572 	{
   573 	aMicroBeats = iPositionMicroBeats;
   574 	InsertInterfaceNameInChunk(_L8("PositionMicroBeatsL"));
   575 	}
   576 
   577 void CMMFMidiTestController::MmcPlayNoteL(TInt /*aChannel*/,TInt /*aNote*/,const TTimeIntervalMicroSeconds& /*aDuration*/,TInt /*aNoteOnVelocity*/,TInt /*aNoteOffVelocity*/)
   578 	{
   579 	InsertInterfaceNameInChunk(_L8("PlayNoteL"));
   580 	}
   581 
   582 void CMMFMidiTestController::MmcPlayNoteL(TInt /*aChannel*/,TInt /*aNote*/,const TTimeIntervalMicroSeconds& /*aStartTime*/, const TTimeIntervalMicroSeconds& /*aDuration*/,TInt /*aNoteOnVelocity*/,TInt /*aNoteOffVelocity*/)
   583 	{
   584 	InsertInterfaceNameInChunk(_L8("PlayNoteWithStartTime"));
   585 	}
   586 
   587 void CMMFMidiTestController::MmcStopNotesL(TInt /*aChannel*/)
   588 	{
   589 	InsertInterfaceNameInChunk(_L8("StopNotes"));
   590 	}
   591 
   592 void CMMFMidiTestController::MmcNoteOnL(TInt /*aChannel*/,TInt /*aNote*/,TInt /*aVelocity*/)
   593 	{
   594 	InsertInterfaceNameInChunk(_L8("NoteOnL"));
   595 	}
   596 
   597 void CMMFMidiTestController::MmcNoteOffL(TInt /*aChannel*/,TInt /*aNote*/,TInt /*aVelocity*/)
   598 	{
   599 	InsertInterfaceNameInChunk(_L8("NoteOffL"));
   600 	}
   601 
   602 void CMMFMidiTestController::MmcPlaybackRateL(TInt& aPlayBackRate)
   603 	{
   604 	aPlayBackRate = iPlayBackRate;
   605 	InsertInterfaceNameInChunk(_L8("PlaybackRateL"));
   606 	}
   607 
   608 void CMMFMidiTestController::MmcSetPlaybackRateL(TInt /*aPlayBackRate*/)
   609 	{
   610 	InsertInterfaceNameInChunk(_L8("SetPlaybackRateL"));
   611 	}
   612 
   613 void CMMFMidiTestController::MmcMaxPlaybackRateL(TInt& aMaxRate)
   614 	{
   615 	aMaxRate = iMaxRate;
   616 	InsertInterfaceNameInChunk(_L8("MaxPlaybackRateL"));
   617 	}
   618 
   619 void CMMFMidiTestController::MmcMinPlaybackRateL(TInt& aMinRate)
   620 	{
   621 	aMinRate = iMinRate;
   622 	InsertInterfaceNameInChunk(_L8("MinPlaybackRateL"));
   623 	}
   624 
   625 void CMMFMidiTestController::MmcTempoMicroBeatsPerMinuteL(TInt& aMicroBeatsPerMinute)
   626 	{
   627 	aMicroBeatsPerMinute = iTempoMicroBeatsPerMinute;
   628 	InsertInterfaceNameInChunk(_L8("TempoMicroBeatsPerMinuteL"));
   629 	}
   630 
   631 void CMMFMidiTestController::MmcSetTempoL(TInt /*aMicroBeatsPerMinute*/)
   632 	{
   633 	InsertInterfaceNameInChunk(_L8("SetTempoL"));
   634 	}
   635 
   636 void CMMFMidiTestController::MmcPitchTranspositionCentsL(TInt& aPitch)
   637 	{
   638 	aPitch = iPitchTranspositionCents;
   639 	InsertInterfaceNameInChunk(_L8("PitchTranspositionCentsL"));
   640 	}
   641 
   642 void CMMFMidiTestController::MmcSetPitchTranspositionL(TInt /*aCents*/, TInt& aCentsApplied)
   643 	{
   644 	aCentsApplied = iCentsApplied; 
   645 	InsertInterfaceNameInChunk(_L8("SetPitchTranspositionL"));
   646 	}
   647 
   648 void CMMFMidiTestController::MmcDurationMicroBeatsL(TInt64& aDuration)
   649 	{
   650 	aDuration = iDurationMicroBeats;
   651 	InsertInterfaceNameInChunk(_L8("DurationMicroBeatsL"));
   652 	}
   653 
   654 void CMMFMidiTestController::MmcNumTracksL(TInt& aTracks)
   655 	{
   656 	aTracks = iNumTracks;
   657 	InsertInterfaceNameInChunk(_L8("NumTracksL"));
   658 	}
   659 
   660 void CMMFMidiTestController::MmcSetTrackMuteL(TInt /*aTrack*/, TBool /*aMuted*/)
   661 	{
   662 	InsertInterfaceNameInChunk(_L8("SetTrackMuteL"));
   663 	}
   664 
   665 void CMMFMidiTestController::MmcMimeTypeL(TDes8& aMimeType)
   666 	{
   667 	_LIT(K,"Midi-x");
   668 	aMimeType.Copy(K);
   669 	InsertInterfaceNameInChunk(_L8("MimeTypeL"));
   670 	}
   671 
   672 void CMMFMidiTestController::MmcSetSyncUpdateCallbackIntervalL(const TTimeIntervalMicroSeconds& aMicroSeconds,TInt64 /*aMicroBeats*/)
   673 	{
   674 	InsertInterfaceNameInChunk(_L8("SetSyncUpdateCallbackIntervalL"));
   675 	iDelayEvent->DelaySyncUpdate(aMicroSeconds);
   676 	}
   677 
   678 void CMMFMidiTestController::MmcSendMessageL(const TDesC8& aMidiMessage, TInt& aBytes)
   679 	{
   680 	aBytes = aMidiMessage.Length();
   681 	InsertInterfaceNameInChunk(_L8("SendMessageL"));
   682 	}
   683 
   684 void CMMFMidiTestController::MmcSendMessageL(const TDesC8& aMidiMessage,const TTimeIntervalMicroSeconds& /*aTime*/, TInt& aBytes)
   685 	{
   686 	aBytes = aMidiMessage.Length();
   687 	InsertInterfaceNameInChunk(_L8("SendMessageWithTimeStamp"));
   688 	}
   689 
   690 void CMMFMidiTestController::MmcSendMipMessageL(const TArray<TMipMessageEntry>& aEntry)
   691 	{
   692 	for(TInt i=0; i< aEntry.Count(); i++)
   693 		{
   694 		TMipMessageEntry tmp = aEntry[i];
   695 		tmp.iChannel++;//to remove the warning
   696 		}
   697 	InsertInterfaceNameInChunk(_L8("SendMipMessageL"));
   698 	}
   699 
   700 void CMMFMidiTestController::MmcNumberOfBanksL(TBool /*aCustom*/, TInt& aNumBanks)
   701 	{
   702 	aNumBanks = iNumBanks;
   703 	InsertInterfaceNameInChunk(_L8("NumberOfBanksL"));
   704 	}
   705 
   706 void CMMFMidiTestController::MmcGetBankIdL(TBool /*aCustom*/, TInt aBankIndex, TInt& aBankId)
   707 	{
   708 	aBankId = ++aBankIndex;
   709 	InsertInterfaceNameInChunk(_L8("GetBankIdL"));
   710 	}
   711 
   712 void CMMFMidiTestController::MmcLoadCustomBankL(const TDesC& /*aFileName*/,TInt& aBankId)
   713 	{
   714 	aBankId = 60;
   715 	InsertInterfaceNameInChunk(_L8("LoadCustomBankL"));
   716 	}
   717 
   718 void CMMFMidiTestController::MmcUnloadCustomBankL(TInt /*aBankId*/)
   719 	{
   720 	InsertInterfaceNameInChunk(_L8("UnloadCustomBankL"));
   721 	}
   722 
   723 void CMMFMidiTestController::MmcCustomBankLoadedL(TInt /*aBankId*/, TBool& aBankLoaded)
   724 	{
   725 	aBankLoaded = ETrue;
   726 	InsertInterfaceNameInChunk(_L8("CustomBankLoadedL"));
   727 	}
   728 
   729 void CMMFMidiTestController::MmcUnloadAllCustomBanksL()
   730 	{
   731 	InsertInterfaceNameInChunk(_L8("UnloadAllCustomBanksL"));
   732 	}
   733 
   734 void CMMFMidiTestController::MmcNumberOfInstrumentsL(TInt /*aBankId*/, TBool /*aCustom*/, TInt& aNumInstruments)
   735 	{
   736 	aNumInstruments = iNumInstruments;
   737 	InsertInterfaceNameInChunk(_L8("NumberOfInstrumentsL"));
   738 	}
   739 
   740 void CMMFMidiTestController::MmcGetInstrumentIdL(TInt /*aBankId*/,TBool /*aCustom*/,TInt /*aInstrumentIndex*/, TInt& aInstrumentId)
   741 	{
   742 	aInstrumentId = 89;
   743 	InsertInterfaceNameInChunk(_L8("GetInstrumentIdL"));
   744 	}
   745 
   746 const TDesC& CMMFMidiTestController::MmcInstrumentNameL(TInt /*aBankId*/, TBool /*aCustom*/, TInt /*aInstrumentId*/)
   747 	{	
   748 	_LIT(KInstrumentName, "Guitar");
   749 	InsertInterfaceNameInChunk(_L8("InstrumentNameL"));
   750 	return KInstrumentName;
   751 	}
   752 
   753 void CMMFMidiTestController::MmcSetInstrumentL(TInt /*aChannel*/,TInt /*aBankId*/,TInt /*aInstrumentId*/)
   754 	{
   755 	InsertInterfaceNameInChunk(_L8("SetInstrumentL"));
   756 	}
   757 
   758 void CMMFMidiTestController::MmcLoadCustomInstrumentL(const TDesC& /*aFileName*/, TInt /*aFileBankId*/, TInt /*aFileInstrumentId*/, TInt /*aMemoryBankId*/, TInt /*aMemoryInstrumentId*/)
   759 	{
   760 	InsertInterfaceNameInChunk(_L8("LoadCustomInstrumentL"));
   761 	}
   762 
   763 void CMMFMidiTestController::MmcUnloadCustomInstrumentL(TInt /*aCustomBankId*/,TInt /*aInstrumentId*/)
   764 	{
   765 	InsertInterfaceNameInChunk(_L8("UnloadCustomInstrumentL"));
   766 	}
   767 
   768 const TDesC& CMMFMidiTestController::MmcPercussionKeyNameL(TInt /*aNote*/, TInt /*aBankId*/, TBool /*aCustom*/, TInt /*aInstrumentId*/)
   769 	{
   770 	_LIT(KPercussionKeyName, "Do");
   771 	InsertInterfaceNameInChunk(_L8("PercussionKeyNameL"));
   772 	return KPercussionKeyName;
   773 	}
   774 
   775 void CMMFMidiTestController::MmcStopTimeL(TTimeIntervalMicroSeconds& aStopTime)
   776 	{
   777 	aStopTime = iStopTime;
   778 	InsertInterfaceNameInChunk(_L8("StopTimeL"));
   779 	}
   780 
   781 void CMMFMidiTestController::MmcSetStopTimeL(const TTimeIntervalMicroSeconds& /*aStopTime*/)
   782 	{
   783 	InsertInterfaceNameInChunk(_L8("SetStopTimeL"));
   784 	}
   785 
   786 void CMMFMidiTestController::MmcPolyphonyL(TInt& aNumNotes)
   787 	{
   788 	aNumNotes = iNumNotes;
   789 	InsertInterfaceNameInChunk(_L8("PolyphonyL"));
   790 	}
   791 
   792 void CMMFMidiTestController::MmcMaxPolyphonyL(TInt& aMaxNotes)
   793 	{
   794 	aMaxNotes = iMaxNotes;
   795 	InsertInterfaceNameInChunk(_L8("MaxPolyphonyL"));
   796 	}
   797 
   798 
   799 void CMMFMidiTestController::MmcChannelsSupportedL(TInt& aChannels)
   800 	{
   801 	aChannels = iChannels;
   802 	InsertInterfaceNameInChunk(_L8("ChannelsSupportedL"));
   803 	}
   804 
   805 void CMMFMidiTestController::MmcChannelVolumeL(TInt aChannel, TReal32& aChannelVol)
   806 	{
   807 	aChannelVol = iChanVolumeValues->At(aChannel);
   808 	InsertInterfaceNameInChunk(_L8("ChannelVolumeL"));
   809 	}
   810 
   811 void CMMFMidiTestController::MmcMaxChannelVolumeL(TReal32& aMaxVol)
   812 	{
   813 	aMaxVol = iMaxVol;
   814 	InsertInterfaceNameInChunk(_L8("MaxChannelVolumeL"));
   815 	}
   816 
   817 void CMMFMidiTestController::MmcSetChannelVolumeL(TInt aChannel,TReal32 aVolume)
   818 	{
   819 	iChanVolumeValues->InsertL(aChannel, aVolume);
   820 	InsertInterfaceNameInChunk(_L8("SetChannelVolumeL"));
   821 	}
   822 
   823 void CMMFMidiTestController::MmcSetChannelMuteL(TInt /*aChannel*/,TBool /*aMuted*/)
   824 	{
   825 	InsertInterfaceNameInChunk(_L8("SetChannelMuteL"));
   826 	}
   827 
   828 void CMMFMidiTestController::MmcVolumeL(TInt& aVolume)
   829 	{
   830 	aVolume = 70000;
   831 	InsertInterfaceNameInChunk(_L8("VolumeL"));
   832 	}
   833 
   834 void CMMFMidiTestController::MmcMaxVolumeL(TInt& aMaxVolume)
   835 	{
   836 	aMaxVolume = iMaxVolume;
   837 	InsertInterfaceNameInChunk(_L8("MaxVolumeL"));
   838 	}
   839 
   840 void CMMFMidiTestController::MmcSetVolumeL(TInt /*aVolume*/)
   841 	{
   842 	InsertInterfaceNameInChunk(_L8("SetVolumeL"));
   843 	}
   844 
   845 void CMMFMidiTestController::MmcSetVolumeRampL(const TTimeIntervalMicroSeconds& /*aRampDuration*/)
   846 	{
   847 	InsertInterfaceNameInChunk(_L8("SetVolumeRampL"));
   848 	}
   849 
   850 void CMMFMidiTestController::MmcGetBalanceL(TInt& aBalance)
   851 	{
   852 	aBalance = iBalance;
   853 	InsertInterfaceNameInChunk(_L8("GetBalanceL"));
   854 	}
   855 
   856 void CMMFMidiTestController::MmcSetBalanceL(TInt /*aBalance*/)
   857 	{
   858 	InsertInterfaceNameInChunk(_L8("SetBalanceL"));
   859 	}
   860 
   861 void  CMMFMidiTestController::MmcLoadCustomBankDataL(const TDesC8& /*aBankData*/,TInt& aBankId)
   862 	{
   863 	aBankId  = 20;
   864 	InsertInterfaceNameInChunk(_L8("LoadCustomBankDataL"));
   865 	}
   866 
   867 void  CMMFMidiTestController::MmcLoadCustomInstrumentDataL(const TDesC8& /*aInstrumentData*/, TInt /*aBankDataId*/, TInt /*aInstrumentDataId*/, TInt /*aMemoryBankId*/, TInt /*aMemoryInstrumentId*/)
   868 	{
   869 	InsertInterfaceNameInChunk(_L8("LoadCustomInstrumentDataL"));
   870 	}
   871 
   872 void  CMMFMidiTestController::MmcSetMaxPolyphonyL(TInt aMaxNotes)
   873 	{
   874 	iMaxNotes = aMaxNotes;
   875 	InsertInterfaceNameInChunk(_L8("SetMaxPolyphonyL"));
   876 	}
   877 
   878 void  CMMFMidiTestController::MmcGetRepeatsL(TInt& aNumRepeats)
   879 	{
   880 	aNumRepeats = iRepeatNumberOfTimes;
   881 	InsertInterfaceNameInChunk(_L8("GetRepeats"));
   882 	}
   883 
   884 void  CMMFMidiTestController::MmcSetRepeatsL(TInt aRepeatNumberOfTimes, const TTimeIntervalMicroSeconds& aTrailingSilence)
   885 	{
   886 	iRepeatNumberOfTimes = aRepeatNumberOfTimes;
   887 	iTrailingSilence = aTrailingSilence;
   888 	InsertInterfaceNameInChunk(_L8("SetRepeatsL"));
   889 	}
   890 
   891 void  CMMFMidiTestController::MmcSetBankL(TBool /*aCustom*/)
   892 	{
   893 	InsertInterfaceNameInChunk(_L8("SetBankL"));
   894 	}
   895 
   896 void  CMMFMidiTestController::MmcIsTrackMuteL(TInt /*aTrack*/, TBool& aTrackMute)
   897 	{
   898 	aTrackMute = ETrue;
   899 	InsertInterfaceNameInChunk(_L8("IsTrackMuteL"));
   900 	}
   901 
   902 void  CMMFMidiTestController::MmcIsChannelMuteL(TInt /*aChannel*/, TBool& aChannelMute)
   903 	{
   904 	aChannelMute = ETrue;
   905 	InsertInterfaceNameInChunk(_L8("IsChannelMuteL"));
   906 	}
   907 
   908 void  CMMFMidiTestController::MmcGetInstrumentL(TInt /*aChannel*/, TInt& aInstrumentId, TInt& aBankId)
   909 	{
   910 	aInstrumentId = 10;
   911 	aBankId = 11;
   912 	InsertInterfaceNameInChunk(_L8("GetInstrumentL"));
   913 	}
   914 
   915 void  CMMFMidiTestController::MmcCloseL()
   916 	{
   917 	iDelayEvent->DelayClose(TTimeIntervalMicroSeconds(0));
   918 	}
   919 
   920 void  CMMFMidiTestController::MmcStopL(const TTimeIntervalMicroSeconds& /*aFadeOutDuration*/)
   921 	{
   922 	if(iDelayEvent->IsActive())
   923 		iDelayEvent->Cancel();
   924 	if(iMidiEventGenerator->IsActive())
   925 		iMidiEventGenerator->Cancel();
   926 
   927 	iDelayEvent->DelayStop(TTimeIntervalMicroSeconds(0));
   928 	}
   929 
   930 
   931 
   932 //
   933 //
   934 //
   935 CMMFMidiTestController::CControllerTimer* CMMFMidiTestController::CControllerTimer::NewL(CMMFMidiTestController* aController)
   936 	{
   937 	CControllerTimer* self = new (ELeave) CControllerTimer(aController);
   938 	CleanupStack::PushL(self);
   939 	self->ConstructL();
   940 	CleanupStack::Pop(self);
   941 	return self;
   942 	}
   943 
   944 CMMFMidiTestController::CControllerTimer::CControllerTimer(CMMFMidiTestController* aController)
   945 	:CTimer(EPriorityStandard)
   946 	{
   947 	iController = aController;
   948 	}
   949 
   950 void CMMFMidiTestController::CControllerTimer::DelayOpen(TTimeIntervalMicroSeconds aDelay)
   951 	{
   952 	ASSERT(iController);
   953 	iType = ETmrOpenComplete;
   954 	After(I64INT(aDelay.Int64()));
   955 	}
   956 
   957 void CMMFMidiTestController::CControllerTimer::DelayPlayStarted(TTimeIntervalMicroSeconds aDelay)
   958 	{
   959 	ASSERT(iController);
   960 	iType = ETmrDelayPlayStarted;
   961 	After(I64INT(aDelay.Int64()));
   962 	}
   963 
   964 void CMMFMidiTestController::CControllerTimer::PlayFinished(TTimeIntervalMicroSeconds aDelay)
   965 	{
   966 	ASSERT(iController);
   967 	iType = ETmrPlayFinished;
   968 	After(I64INT(aDelay.Int64()));
   969 	}
   970 
   971 void CMMFMidiTestController::CControllerTimer::DelaySyncUpdate(TTimeIntervalMicroSeconds aDelay)
   972 	{
   973 	ASSERT(iController);
   974 	iType = ETmrSyncUpdate;
   975 	After(I64INT(aDelay.Int64()));
   976 	}
   977 
   978 void CMMFMidiTestController::CControllerTimer::DelayStop(TTimeIntervalMicroSeconds aDelay)
   979 	{
   980 	ASSERT(iController);
   981 	iType = ETmrDelayStop;
   982 	After(I64INT(aDelay.Int64()));
   983 	}
   984 
   985 void CMMFMidiTestController::CControllerTimer::DelayClose(TTimeIntervalMicroSeconds aDelay)
   986 	{
   987 	ASSERT(iController);
   988 	iType = ETmrDelayClose;
   989 	After(I64INT(aDelay.Int64()));
   990 	}
   991 
   992 void CMMFMidiTestController::CControllerTimer::RunL()
   993 	{
   994 	ASSERT(iController);
   995 	switch(iType) 
   996 		{
   997 		case ETmrOpenComplete :
   998 			User::LeaveIfError(iController->OpenComplete());
   999 			break;
  1000 		case ETmrSyncUpdate :
  1001 			User::LeaveIfError(iController->SyncUpdate());
  1002 			break;
  1003 		case ETmrDelayPlayStarted :
  1004 			User::LeaveIfError(iController->PlayStarted());
  1005 			break;
  1006 		case ETmrPlayFinished :
  1007 			User::LeaveIfError(iController->PlayFinished());
  1008 			break;
  1009 		case ETmrDelayStop :
  1010 			User::LeaveIfError(iController->Stop());
  1011 			break;
  1012 		case ETmrDelayClose :
  1013 			User::LeaveIfError(iController->Close());
  1014 			break;
  1015 		}
  1016 	}
  1017 //
  1018 //
  1019 //
  1020 CMMFMidiTestController::CMidiEventGenerator* CMMFMidiTestController::CMidiEventGenerator::NewL(CMMFMidiTestController* aController)
  1021 	{
  1022 	CMidiEventGenerator* self = new (ELeave) CMidiEventGenerator(aController);
  1023 	CleanupStack::PushL(self);
  1024 	self->ConstructL();
  1025 	CleanupStack::Pop(self);
  1026 	return self;
  1027 	}
  1028 
  1029 CMMFMidiTestController::CMidiEventGenerator::CMidiEventGenerator(CMMFMidiTestController* aController)
  1030 	:CTimer(EPriorityStandard)
  1031 	{
  1032 	iController = aController;
  1033 	iDelay = TTimeIntervalMicroSeconds(0);//2 secs
  1034 	iTriggerCount = 0;
  1035 	}
  1036 
  1037 void CMMFMidiTestController::CMidiEventGenerator::MidiEventTrigger()
  1038 	{
  1039 	switch(iTriggerCount) 
  1040 		{
  1041 		case  0:
  1042 			iType = EEventTempoChanged;
  1043 			break;
  1044 		case  1:
  1045 			iType = EEventVolumeChanged;
  1046 			break;
  1047 		case  2:
  1048 			iType = EEventMuteChanged;
  1049 			break;
  1050 		case  3:
  1051 			iType = EEventPolyphonyChanged;
  1052 			break;
  1053 		case  4:
  1054 			iType = EEventInstrumentChanged;
  1055 			break;
  1056 		case  5:
  1057 			iType = EEventSmfMetaDataEntryFound;
  1058 			break;
  1059 		case  6:
  1060 			iType = EEventVolumeChanged;
  1061 			break;
  1062 		case  7:
  1063 			iType = EEventMuteChanged;
  1064 			break;
  1065 		case  8:
  1066 			iType = EEventPolyphonyChanged;
  1067 			break;
  1068 		case  9:
  1069 			iType = EEventInstrumentChanged;
  1070 			break;
  1071 		case  10:
  1072 			iType = EEventSmfMetaDataEntryFound;
  1073 			break;
  1074 		case  11:
  1075 			iType = EEventMipMessageReceived;
  1076 			break;
  1077 		}
  1078 	++iTriggerCount;
  1079 	After(I64INT(iDelay.Int64()));
  1080 	}
  1081 
  1082 /*
  1083 void CMMFMidiTestController::CMidiEventGenerator::DelaySyncUpdate(TTimeIntervalMicroSeconds aDelay)
  1084 	{
  1085 	ASSERT(iController);
  1086 	iType = ETmrSyncUpdate;
  1087 	After(I64INT(aDelay.Int64()));
  1088 	}
  1089 */
  1090 
  1091 void CMMFMidiTestController::CMidiEventGenerator::RunL()
  1092 	{
  1093 	ASSERT(iController);
  1094 	
  1095 	switch(iType) 
  1096 		{
  1097 		case  EEventTempoChanged:
  1098 			User::LeaveIfError(iController->TempoChanged());
  1099 			break;
  1100 		case  EEventVolumeChanged:
  1101 			User::LeaveIfError(iController->VolumeChanged());
  1102 			break;
  1103 		case  EEventMuteChanged:
  1104 			User::LeaveIfError(iController->MuteChanged());
  1105 			break;
  1106 		case  EEventPolyphonyChanged:
  1107 			User::LeaveIfError(iController->PolyphonyChanged());
  1108 			break;
  1109 		case  EEventInstrumentChanged:
  1110 			User::LeaveIfError(iController->InstrumentChanged());
  1111 			break;
  1112 		case  EEventSmfMetaDataEntryFound:
  1113 			User::LeaveIfError(iController->SmfMetaDataEntryFound());
  1114 			break;
  1115 		case  EEventMipMessageReceived:
  1116 			User::LeaveIfError(iController->MipMessageReceived());
  1117 			break;
  1118 		}
  1119 	}
  1120 
  1121 void CMMFMidiTestController::InsertInterfaceNameInChunk(const TDesC8& aInterfaceName)
  1122 	{
  1123 	TFindChunk findChunk(KMidiClntChunk);
  1124 	TFullName chunkName;
  1125 	TInt err = findChunk.Next(chunkName);
  1126 
  1127 	if(err == KErrNone)
  1128 		{
  1129 		RChunk chunk;
  1130 		chunk.OpenGlobal(KMidiClntChunk,EFalse);
  1131 		TUint8* base = chunk.Base();
  1132 		for(TInt i=0; i<40 ; i++)
  1133 			{
  1134 			*base = 0x0;
  1135 			base++;
  1136 			}
  1137 		TBuf8<40> buf(aInterfaceName);
  1138 		TPtr8 ptr(chunk.Base(),chunk.Size());
  1139 		ptr = buf;
  1140 		chunk.Close();
  1141 		RSemaphore sem;
  1142 		sem.OpenGlobal(KMidiClntSemaphore);
  1143 		sem.Signal();
  1144 		sem.Close();
  1145 		}
  1146 	}
  1147 
  1148 TInt CMMFMidiTestController::MdcEvaluateIntent(ContentAccess::TIntent aIntent) 
  1149    {
  1150    if (iDataSource == NULL)
  1151 	   	{
  1152 	   	return KErrNotReady;
  1153 		}      
  1154    if (iDataSource && iDataSource->DataSourceType()==KUidMmfFileSource)
  1155       {
  1156       CMMFFile* file = static_cast<CMMFFile*>(iDataSource);
  1157       TInt err = file->EvaluateIntent(aIntent);
  1158       return err;
  1159       }
  1160    else
  1161       {
  1162       // Evaluating intent will always succeed on sinks that 
  1163       // don't support DRM
  1164       return KErrNone;
  1165       }
  1166    
  1167    }
  1168    
  1169 TInt CMMFMidiTestController::MdcExecuteIntent(ContentAccess::TIntent aIntent)
  1170    {
  1171    	if (iDataSource == NULL)
  1172 	   	{
  1173 	   	return KErrNotReady;
  1174 		}   
  1175    	if (iDataSource->DataSourceType()==KUidMmfFileSource)
  1176 	      {
  1177 	      CMMFFile* file = static_cast<CMMFFile*>(iDataSource);
  1178 	      TInt err = file->ExecuteIntent(aIntent);
  1179 	      return err;
  1180 	      }
  1181    	else
  1182 	      {
  1183 	      // Executing intent will always succeed on sinks that 
  1184 	      // don't support DRM
  1185 	      return KErrNone;
  1186 	      }
  1187    }
  1188    
  1189 TInt CMMFMidiTestController::MdcDisableAutomaticIntent(TBool aDisableAutoIntent)
  1190    {
  1191    iDisableAutoIntent = aDisableAutoIntent;
  1192    return KErrNone;
  1193    }
  1194    
  1195    
  1196 TInt CMMFMidiTestController::MdcSetAgentProperty(ContentAccess::TAgentProperty aProperty, TInt aValue)
  1197    {
  1198    if (iDataSource == NULL)
  1199    	{
  1200    	return KErrNotReady;
  1201    	}
  1202    	
  1203    if (iDataSource->DataSourceType()==KUidMmfFileSource)
  1204       {
  1205       CMMFFile* file = static_cast<CMMFFile*>(iDataSource);
  1206       TInt err = file->SetAgentProperty(aProperty, aValue);
  1207       return err;
  1208       }
  1209    else
  1210       {
  1211       return KErrNone;
  1212       }
  1213    }
  1214 
  1215 // __________________________________________________________________________
  1216 // Exported proxy for instantiation method resolution
  1217 // Define the interface UIDs
  1218 
  1219 
  1220 const TImplementationProxy ImplementationTable[] =
  1221 	{
  1222 		IMPLEMENTATION_PROXY_ENTRY(KMmfMidiTestControllerUid,	CMMFMidiTestController::NewL)
  1223 	};
  1224 
  1225 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
  1226 	{
  1227 	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
  1228 
  1229 	return ImplementationTable;
  1230 	}
  1231