mmlibs/mmfw/MIDI/src/midistandardcustomcommands.cpp
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     1 // Copyright (c) 2003-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 <mmf/common/midistandardcustomcommands.h>
       
    17 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    18 #include <mmf/common/mmfmidiconfig.h>
       
    19 #include <mmf/common/midieventreceiver.h>
       
    20 #endif
       
    21 
       
    22 /**
       
    23 Constructor.
       
    24 @param aController	
       
    25        The client side controller object to be used by this custom command interface.
       
    26 */
       
    27 EXPORT_C RMidiControllerCustomCommands::RMidiControllerCustomCommands(RMMFController& aController) :
       
    28 	RMMFCustomCommandsBase(aController, KUidInterfaceMidi)
       
    29 	{
       
    30 	}
       
    31 
       
    32 /**
       
    33 Change the position of the currently playing MIDI resource to the given position.
       
    34 May be called whenever a MIDI resource is open.
       
    35 
       
    36 @param aMicroBeats 
       
    37        Metrical position to move to. Clamped to (0, DurationMicroBeats()).
       
    38 @return One of the system-wide error codes.
       
    39 */
       
    40 EXPORT_C TInt RMidiControllerCustomCommands::SetPositionMicroBeats(TInt64 aMicroBeats) const
       
    41 	{
       
    42 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
    43 	configPackage().iPositionMicroBeats = aMicroBeats;
       
    44 	return iController.CustomCommandSync(iDestinationPckg, 
       
    45 										 EMMFMidiControllerSetPositionMicroBeats, 
       
    46 										 configPackage,
       
    47 										 KNullDesC8);
       
    48 	}
       
    49 
       
    50 /**
       
    51 Gets the current metrical position of the MIDI resource being played.
       
    52 
       
    53 @param aMicroBeats 
       
    54        (BPM*1000000) relative to the start of the resource.
       
    55 @return One of the system-wide error codes.
       
    56 */
       
    57 EXPORT_C TInt RMidiControllerCustomCommands::PositionMicroBeats(TInt64& aMicroBeats) const
       
    58 	{
       
    59 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
    60 	TInt error = iController.CustomCommandSync(iDestinationPckg, 
       
    61 											   EMMFMidiControllerPositionMicroBeats, 
       
    62 											   KNullDesC8,
       
    63 											   KNullDesC8,
       
    64 											   configPackage);
       
    65 	if (!error)
       
    66 		aMicroBeats = configPackage().iPositionMicroBeats;
       
    67 	return error;
       
    68 	}
       
    69 
       
    70 /**
       
    71 Synchronous function to play a single note.
       
    72 Multiple calls to this function will be accommodated as far as the MIDI engine can
       
    73 manage. The same functionality could be implemented using the SendMessage function.
       
    74 
       
    75 @param aChannel 
       
    76        Logical channel to play note on. 0 <= aChannel <= 15.
       
    77 @param aNote 
       
    78        Note to play. 0 <= aNote <= 127
       
    79 @param aDuration 
       
    80        Length of time to play note for.
       
    81 @param aNoteOnVelocity 
       
    82        Velocity with which to start the note. 0 <= aNoteOnVelocity <= 127.
       
    83 @param aNoteOffVelocity 
       
    84        Velocity with which to stop the note. 0 <= aNoteOffVelocity <= 127.
       
    85 @return One of the system-wide error codes.
       
    86 */
       
    87 EXPORT_C TInt RMidiControllerCustomCommands::PlayNote(TInt aChannel,TInt aNote, const TTimeIntervalMicroSeconds& aDuration,TInt aNoteOnVelocity,TInt aNoteOffVelocity)
       
    88 	{
       
    89 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
    90 	configPackage().iChannel = aChannel;
       
    91 	configPackage().iNote = aNote;
       
    92 	configPackage().iDurationMicroSeconds = aDuration;
       
    93 	configPackage().iNoteOnVelocity = aNoteOnVelocity;
       
    94 	configPackage().iNoteOffVelocity = aNoteOffVelocity;
       
    95 	return iController.CustomCommandSync(iDestinationPckg, 
       
    96 										 EMMFMidiControllerPlayNote, 
       
    97 										 configPackage,
       
    98 										 KNullDesC8);
       
    99 	}
       
   100 
       
   101 /**
       
   102 Synchronous function to play a single note at a specified time.
       
   103 Multiple calls to this function will be accommodated as far as the MIDI engine can
       
   104 manage. The same functionality could be implemented using the SendMessage function.
       
   105 
       
   106 @param aChannel 
       
   107        Logical channel to play note on. 0 <= aChannel <= 15.
       
   108 @param aNote 
       
   109        Note to play. 0 <= aNote <= 127
       
   110 @param aStartTime 
       
   111        Specifies the time at which to start playing the note, relative 
       
   112 	   to the MIDI resource playing time or the time elapsed since Play()
       
   113 	   was called if no resource is present.
       
   114 @param aDuration 
       
   115        Length of time to play note for.
       
   116 @param aNoteOnVelocity 
       
   117        Velocity with which to start the note. 0 <= aNoteOnVelocity <= 127.
       
   118 @param aNoteOffVelocity 
       
   119        Velocity with which to stop the note. 0 <= aNoteOffVelocity <= 127.
       
   120 @return One of the system-wide error codes.
       
   121 */
       
   122 EXPORT_C TInt RMidiControllerCustomCommands::PlayNote(TInt aChannel,TInt aNote,const TTimeIntervalMicroSeconds& aStartTime, const TTimeIntervalMicroSeconds& aDuration,TInt aNoteOnVelocity,TInt aNoteOffVelocity)
       
   123 	{
       
   124 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
   125 	configPackage().iChannel = aChannel;
       
   126 	configPackage().iNote = aNote;
       
   127 	configPackage().iStartTime = aStartTime;
       
   128 	configPackage().iDurationMicroSeconds = aDuration;
       
   129 	configPackage().iNoteOnVelocity = aNoteOnVelocity;
       
   130 	configPackage().iNoteOffVelocity = aNoteOffVelocity;
       
   131 	return iController.CustomCommandSync(iDestinationPckg, 
       
   132 										 EMMFMidiControllerPlayNoteWithStartTime, 
       
   133 										 configPackage,
       
   134 										 KNullDesC8);
       
   135 	}
       
   136 
       
   137 /**
       
   138 Stops the playback of all notes on the given channel, by means of an All Notes Off MIDI message.
       
   139 
       
   140 @param aChannel 
       
   141        Logical channel to stop notes on. 0 <= aChannel <= 15.
       
   142 @return One of the system-wide error codes.
       
   143 */
       
   144 EXPORT_C TInt RMidiControllerCustomCommands::StopNotes(TInt aChannel)
       
   145 	{
       
   146 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
   147 	configPackage().iChannel = aChannel;
       
   148 	return iController.CustomCommandSync(iDestinationPckg, 
       
   149 										 EMMFMidiControllerStopNotes, 
       
   150 										 configPackage,
       
   151 										 KNullDesC8);
       
   152 	}
       
   153 
       
   154 /**
       
   155 Synchronous function to commence playback of a note. Multiple calls to this
       
   156 function will be accommodated as far as the MIDI engine can manage.
       
   157 
       
   158 @param aChannel 
       
   159        Logical channel to play note on. 0 <= aChannel <= 15.
       
   160 @param aNote 
       
   161        Note to play. 0 <= aNote <= 127.
       
   162 @param aVelocity 
       
   163        Velocity with which to start the note. The legal integer range is
       
   164 	   0 <= aVelocity <= 127, but the value zero actually causes the message
       
   165 	   to be interpreted as a Note Off message instead of a Note On.
       
   166 @return One of the system-wide error codes.
       
   167 */
       
   168 EXPORT_C TInt RMidiControllerCustomCommands::NoteOn(TInt aChannel, TInt aNote, TInt aVelocity)
       
   169 	{
       
   170 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
   171 	configPackage().iChannel = aChannel;
       
   172 	configPackage().iNote = aNote;
       
   173 	configPackage().iNoteOnVelocity = aVelocity;
       
   174 	return iController.CustomCommandSync(iDestinationPckg, 
       
   175 										 EMMFMidiControllerNoteOn, 
       
   176 										 configPackage,
       
   177 										 KNullDesC8);
       
   178 	}
       
   179 
       
   180 /**
       
   181 Synchronous function to terminate playback of a note. If no corresponding note
       
   182 is found then no error is raised.
       
   183 
       
   184 @param aChannel 
       
   185        Logical channel on which the note is playing. 0 <= aChannel <= 15.
       
   186 @param aNote 
       
   187        Note to terminate. 0 <= aNote <= 127.
       
   188 @param aVelocity 
       
   189        Velocity with which to stop the note. 0 <= aVelocity <= 127. There is no 
       
   190 	   standard behaviour corresponding with note off velocity.
       
   191 @return One of the system-wide error codes.
       
   192 */
       
   193 EXPORT_C TInt RMidiControllerCustomCommands::NoteOff(TInt aChannel,TInt aNote,TInt aVelocity)
       
   194 	{
       
   195 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
   196 	configPackage().iChannel = aChannel;
       
   197 	configPackage().iNote = aNote;
       
   198 	configPackage().iNoteOffVelocity = aVelocity;
       
   199 	return iController.CustomCommandSync(iDestinationPckg, 
       
   200 										 EMMFMidiControllerNoteOff, 
       
   201 										 configPackage,
       
   202 										 KNullDesC8);
       
   203 	}
       
   204 
       
   205 /**
       
   206 Gets the current playback rate factor of the currently open MIDI resource.
       
   207 The playback rate is independent from tempo, i.e., it can be used to give
       
   208 an overall speed factor for playback.
       
   209 
       
   210 @param aPlayBackRate 
       
   211        Current playback rate in percent times 1000, i.e., 100000 means original
       
   212 	   playback speed, 200000 means double speed, and 50000 means half speed playback.
       
   213 @return One of the system-wide error codes.
       
   214 */
       
   215 EXPORT_C TInt RMidiControllerCustomCommands::PlaybackRate(TInt& aPlayBackRate) const
       
   216 	{
       
   217 	TPckgBuf<TMMFMidiConfig3> configPackage;
       
   218 	TInt error = iController.CustomCommandSync(iDestinationPckg, 
       
   219 											   EMMFMidiControllerPlaybackRate, 
       
   220 											   KNullDesC8,
       
   221 											   KNullDesC8,
       
   222 											   configPackage);
       
   223 	if (!error)
       
   224 		aPlayBackRate = configPackage().iPlayBackRate;
       
   225 	return error;
       
   226 	}
       
   227 
       
   228 /**
       
   229 Sets the playback rate for the playback of the current MIDI resource.
       
   230 The playback rate is independent from tempo, i.e., it can be used to give
       
   231 an overall speed factor for playback. May be called whether playback
       
   232 is in progress or not.
       
   233 
       
   234 @param aPlayBackRate 
       
   235        Playback rate in percent times 1000, i.e., 100000 means original 
       
   236 	   playback speed, 200000 means double speed, and 50000 means half speed playback.
       
   237 @return One of the system-wide error codes.
       
   238 */
       
   239 EXPORT_C TInt RMidiControllerCustomCommands::SetPlaybackRate(TInt aPlayBackRate)
       
   240 	{
       
   241 	TPckgBuf<TMMFMidiConfig3> configPackage;
       
   242 	configPackage().iPlayBackRate = aPlayBackRate;
       
   243 	return iController.CustomCommandSync(iDestinationPckg, 
       
   244 										 EMMFMidiControllerSetPlaybackRate, 
       
   245 										 configPackage,
       
   246 										 KNullDesC8);
       
   247 	}
       
   248 
       
   249 /**
       
   250 Gets the maximum playback rate in milli-percentage from the MIDI engine.
       
   251 @see SetPlaybackRate() for milli-percentage details.
       
   252 
       
   253 @param aMaxRate
       
   254        Playback rate supported by MIDI player.
       
   255 @return One of the system-wide error codes.
       
   256 */
       
   257 EXPORT_C TInt RMidiControllerCustomCommands::MaxPlaybackRate(TInt& aMaxRate) const
       
   258 	{
       
   259 	TPckgBuf<TMMFMidiConfig3> configPackage;
       
   260 	TInt error = iController.CustomCommandSync(iDestinationPckg, 
       
   261 												EMMFMidiControllerMaxPlaybackRate, 
       
   262 												KNullDesC8,
       
   263 												KNullDesC8,
       
   264 												configPackage);
       
   265 	if (!error)
       
   266 		aMaxRate = configPackage().iPlayBackMaxRate;
       
   267 	return error;
       
   268 	}
       
   269 
       
   270 /**
       
   271 Gets the minimum playback rate in milli-percentage from the MIDI engine.
       
   272 @see SetPlaybackRate() for milli-percentage details.
       
   273 
       
   274 @param aMinRate
       
   275        Minimum playback rate supported by MIDI player.
       
   276 @return One of the system-wide error codes.
       
   277 */
       
   278 EXPORT_C TInt RMidiControllerCustomCommands::MinPlaybackRate(TInt& aMinRate) const
       
   279 	{
       
   280 	TPckgBuf<TMMFMidiConfig3> configPackage;
       
   281 	TInt error = iController.CustomCommandSync(iDestinationPckg, 
       
   282 												EMMFMidiControllerMinPlaybackRate, 
       
   283 												KNullDesC8,
       
   284 												KNullDesC8,
       
   285 												configPackage);
       
   286 	if (!error)
       
   287 		aMinRate = configPackage().iPlayBackMinRate;
       
   288 	return error;
       
   289 	}
       
   290 
       
   291 /**
       
   292 Gets the current tempo of the currently open MIDI resource. The tempo is independent
       
   293 from the playback rate, i.e., the resulting playback speed will be affected by both.
       
   294 
       
   295 @param  aMicroBeatsPerMinute
       
   296         Tempo at the current position of the currently open resource in microbeats
       
   297 		per minute, i.e. BPM * 1000000. Filled in by the controller framework.
       
   298 @return One of the system-wide error codes.
       
   299 */
       
   300 EXPORT_C TInt RMidiControllerCustomCommands::TempoMicroBeatsPerMinute(TInt& aMicroBeatsPerMinute) const
       
   301 	{
       
   302 	TPckgBuf<TMMFMidiConfig1> configPackage;
       
   303 	TInt error = iController.CustomCommandSync(iDestinationPckg, 
       
   304 												EMMFMidiControllerTempo, 
       
   305 												KNullDesC8,
       
   306 												KNullDesC8,
       
   307 												configPackage);
       
   308 	if (!error)
       
   309 		aMicroBeatsPerMinute = configPackage().iTempo;
       
   310 	return error;
       
   311 	}
       
   312 
       
   313 /**
       
   314 Sets the tempo at which the current MIDI resource should be played. May be
       
   315 called whether playback is in progress or not. The tempo is independent 
       
   316 from the playback rate, i.e., the resulting playback speed will be affected by both.
       
   317 
       
   318 @param aMicroBeatsPerMinute 
       
   319        Tempo in microbeats per minute (BPM*1000000) to set.
       
   320 @return One of the system-wide error codes.
       
   321 */
       
   322 EXPORT_C TInt RMidiControllerCustomCommands::SetTempo(TInt aMicroBeatsPerMinute)
       
   323 	{
       
   324 	TPckgBuf<TMMFMidiConfig1> configPackage;
       
   325 	configPackage().iTempo = aMicroBeatsPerMinute;
       
   326 	return iController.CustomCommandSync(iDestinationPckg, 
       
   327 										 EMMFMidiControllerSetTempo, 
       
   328 										 configPackage,
       
   329 										 KNullDesC8);
       
   330 	}
       
   331 
       
   332 /**
       
   333 Gets the pitch shift in use for the currently open MIDI resource.
       
   334 
       
   335 @param aPitch 
       
   336        Shift in cents, i.e. semitones * 100. One octave equals 1200 cents.
       
   337 @return One of the system-wide error codes.
       
   338 */
       
   339 EXPORT_C TInt RMidiControllerCustomCommands::PitchTranspositionCents(TInt& aPitch) const
       
   340 	{
       
   341 	TPckgBuf<TMMFMidiConfig1> configPackage;
       
   342 	TInt error = iController.CustomCommandSync(iDestinationPckg, 
       
   343 												EMMFMidiControllerPitch, 
       
   344 												KNullDesC8,
       
   345 												KNullDesC8,
       
   346 												configPackage);
       
   347 	if (!error)
       
   348 		aPitch = configPackage().iPitch;
       
   349 	return error;
       
   350 	}
       
   351 
       
   352 /**
       
   353 Sets the pitch shift to apply to the currently open MIDI resource.
       
   354 May be called during playback.
       
   355 
       
   356 @param aCents 
       
   357        Pitch shift in cents, i.e. semitones * 100. One octave equals 1200 cents.
       
   358 @param aCentsApplied 
       
   359        Actual pitch shift applied - may differ from the requested value due to
       
   360 	   limitations of the MIDI engine.
       
   361 @return One of the system-wide error codes.
       
   362 */
       
   363 EXPORT_C TInt RMidiControllerCustomCommands::SetPitchTransposition(TInt aCents, TInt& aCentsApplied)
       
   364 	{
       
   365 	TPckgBuf<TMMFMidiConfig1> configPackage;
       
   366 	configPackage().iPitch = aCents;
       
   367 	TInt err = iController.CustomCommandSync(iDestinationPckg, 
       
   368 											EMMFMidiControllerSetPitch, 
       
   369 											configPackage,
       
   370 											KNullDesC8,
       
   371 											configPackage);
       
   372 	aCentsApplied = configPackage().iPitch;
       
   373 	return err;
       
   374 	}
       
   375 
       
   376 /**
       
   377 Gets the length of the currently open MIDI resource in micro-beats.
       
   378 
       
   379 @param aDuration 
       
   380        Duration in microbeats (beats * 1000000).
       
   381 @return One of the system-wide error codes.
       
   382 */
       
   383 EXPORT_C TInt RMidiControllerCustomCommands::DurationMicroBeats(TInt64& aDuration) const
       
   384 	{
       
   385 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
   386 	TInt error = iController.CustomCommandSync(iDestinationPckg, 
       
   387 												EMMFMidiControllerDurationMicroBeats, 
       
   388 												KNullDesC8,
       
   389 												KNullDesC8,
       
   390 												configPackage);
       
   391 	if (!error)
       
   392 		aDuration = configPackage().iDurationMicroBeats;
       
   393 	return error;
       
   394 	}
       
   395 
       
   396 /**
       
   397 Gets the number of tracks present in the currently open MIDI resource.
       
   398 
       
   399 @param aTracks 
       
   400        Number of tracks.
       
   401 @return One of the system-wide error codes.
       
   402 */
       
   403 EXPORT_C TInt RMidiControllerCustomCommands::NumTracks(TInt& aTracks) const
       
   404 	{
       
   405 	TPckgBuf<TMMFMidiConfig1> configPackage;
       
   406 	TInt error = iController.CustomCommandSync(iDestinationPckg, 
       
   407 												EMMFMidiControllerNumTracks, 
       
   408 												KNullDesC8,
       
   409 												KNullDesC8,
       
   410 												configPackage);
       
   411 	if (!error)
       
   412 		aTracks = configPackage().iNumTracks;
       
   413 	return error;
       
   414 	}
       
   415 
       
   416 /**
       
   417 Mutes or unmutes a particular track.
       
   418 
       
   419 @param aTrack 
       
   420        Index of the track to mute - 0 <= aTrack < NumTracksL().
       
   421 @param aMuted 
       
   422        ETrue to mute the track, EFalse to unmute it.
       
   423 @return One of the system-wide error codes.
       
   424 */
       
   425 EXPORT_C TInt RMidiControllerCustomCommands::SetTrackMute(TInt aTrack, TBool aMuted) const
       
   426 	{
       
   427 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
   428 	configPackage().iTrack = aTrack;
       
   429 	configPackage().iMuted = aMuted;
       
   430 	return iController.CustomCommandSync(iDestinationPckg, 
       
   431 										 EMMFMidiControllerSetTrackMute, 
       
   432 										 configPackage,
       
   433 										 KNullDesC8);
       
   434 	}
       
   435 
       
   436 /**
       
   437 Gets the MIME type of the MIDI resource currently open.
       
   438 
       
   439 @param aMimeType 
       
   440        Descriptor containing the MIDI mime type.
       
   441 @return One of the system-wide error codes.
       
   442 */
       
   443 EXPORT_C TInt RMidiControllerCustomCommands::MimeType(TDes8& aMimeType) const
       
   444 	{
       
   445 	return iController.CustomCommandSync(iDestinationPckg, 
       
   446 										EMMFMidiControllerMimeType, 
       
   447 										KNullDesC8,										 
       
   448 										KNullDesC8,
       
   449 										aMimeType);
       
   450 	}
       
   451 
       
   452 /**
       
   453 Sets the frequency at which MMIDIClientUtilityObserver::MmcuoSyncUpdateL() is called
       
   454 to allow other components to synchronise with playback of this MIDI resource.
       
   455 
       
   456 @param aMicroSeconds 
       
   457        Temporal interval to callback at. Used in preference to aMicroBeats if both are set.
       
   458 @param aMicroBeats 
       
   459        Metrical interval to callback at. Set both parameters to zero to cancel.
       
   460 @return One of the system-wide error codes.
       
   461 */
       
   462 EXPORT_C TInt RMidiControllerCustomCommands::SetSyncUpdateCallbackInterval(const TTimeIntervalMicroSeconds& aMicroSeconds,TInt64 aMicroBeats)
       
   463 	{
       
   464 	TPckgBuf<TMMFMidiConfig3> configPackage;
       
   465 	configPackage().iCallbackIntervalMicroSeconds = aMicroSeconds;
       
   466 	configPackage().iCallbackIntervalMicroBeats = aMicroBeats;
       
   467 	return iController.CustomCommandSync(iDestinationPckg, 
       
   468 										 EMMFMidiControllerSetSyncUpdateCallbackInterval, 
       
   469 										 configPackage,
       
   470 										 KNullDesC8);
       
   471 	}
       
   472 
       
   473 /**
       
   474 Sends a single MIDI message to the MIDI engine.
       
   475 
       
   476 @param aMidiMessage 
       
   477        Descriptor containing the MIDI message data. If there are several
       
   478        MIDI messages in the buffer, only the first one is processed.
       
   479 @param aBytes
       
   480        Number of bytes of the message buffer actually processed.
       
   481 @return One of the system-wide error codes.
       
   482 */
       
   483 EXPORT_C TInt RMidiControllerCustomCommands::SendMessage(const TDesC8& aMidiMessage, TInt& aBytes)
       
   484 	{
       
   485 	TPckgBuf<TMMFMidiConfig3> configPackage;
       
   486 	configPackage().iMidiMessage = &aMidiMessage;
       
   487 	TInt error = iController.CustomCommandSync(iDestinationPckg, 
       
   488 												EMMFMidiControllerSendMessage, 
       
   489 												configPackage,
       
   490 												KNullDesC8,
       
   491 												configPackage);
       
   492 	if (!error)
       
   493 		aBytes = configPackage().iBytesProcessed;
       
   494 	return error;
       
   495 	}
       
   496 
       
   497 /**
       
   498 Sends a single MIDI message, with time stamp, to the MIDI engine.
       
   499 
       
   500 @param aMidiMessage 
       
   501        Descriptor containing the MIDI message data. If there are several
       
   502 	   MIDI messages in the buffer, only the first one is processed.
       
   503 @param aTime
       
   504        The time at which to execute the message, relative to the MIDI resource playing
       
   505        time or the time elapsed since Play() was called if no resource is present.
       
   506 @param aBytes
       
   507        Number of bytes of the message buffer actually processed.
       
   508 @return One of the system-wide error codes.
       
   509 */
       
   510 EXPORT_C TInt RMidiControllerCustomCommands::SendMessage(const TDesC8& aMidiMessage,const TTimeIntervalMicroSeconds& aTime, TInt& aBytes)
       
   511 	{
       
   512 	TPckgBuf<TMMFMidiConfig3> configPackage;
       
   513 	configPackage().iMidiMessage = &aMidiMessage;
       
   514 	configPackage().iTimeStamp = aTime;
       
   515 	TInt error = iController.CustomCommandSync(iDestinationPckg, 
       
   516 												EMMFMidiControllerSendMessageWithTimeStamp, 
       
   517 												configPackage,
       
   518 												KNullDesC8,
       
   519 												configPackage);
       
   520 	if (!error)
       
   521 		aBytes = configPackage().iBytesProcessed;
       
   522 	return error;
       
   523 	}
       
   524 
       
   525 /**
       
   526 Sends a mip message to the MIDI engine. This is a convenience function,
       
   527 because the same functionality could be achieved with the SendMessage() function.
       
   528 
       
   529 @param aEntry 
       
   530        Array of logical {channel, MIP} value pairs to send, highest priority first.
       
   531 @return One of the system-wide error codes.
       
   532 */
       
   533 EXPORT_C TInt RMidiControllerCustomCommands::SendMipMessage(const RArray<TMipMessageEntry>& aEntry)
       
   534 	{
       
   535 	TPckgBuf<TMMFMidiConfig1> configPackage;
       
   536 	TArray<TMipMessageEntry> mipMessage(aEntry.Array());
       
   537 	configPackage().iMipMessage = &mipMessage;
       
   538 	return iController.CustomCommandSync(iDestinationPckg, 
       
   539 										 EMMFMidiControllerSendMipMessage, 
       
   540 										 configPackage,
       
   541 										 KNullDesC8);
       
   542 	}
       
   543 
       
   544 /**
       
   545 Gets the number of standard or custom sound banks currently available.
       
   546 
       
   547 @param aCustom
       
   548        Specifies whether to reference a custom or standard sound bank.
       
   549 @param aNumBanks 
       
   550        Number of custom or standard sound banks available.
       
   551 @return One of the system-wide error codes.
       
   552 */
       
   553 EXPORT_C TInt RMidiControllerCustomCommands::NumberOfBanks(TBool aCustom, TInt& aNumBanks) const
       
   554 	{
       
   555 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
   556 	configPackage().iCustom = aCustom;
       
   557 	TInt error = iController.CustomCommandSync(iDestinationPckg, 
       
   558 												EMMFMidiControllerNumberOfBanks, 
       
   559 												configPackage,
       
   560 												KNullDesC8,
       
   561 												configPackage);
       
   562 	if (!error)
       
   563 		aNumBanks = configPackage().iNumBanks;
       
   564 	return error;
       
   565 	}
       
   566 
       
   567 /**
       
   568 Gets the identifier of a sound bank. Bank identifier (aka bank number) is a
       
   569 14-bit value consisting of MIDI bank MSB and LSB values.
       
   570 
       
   571 @param  aCustom
       
   572         Specifies whether to reference a custom or standard sound bank.
       
   573 @param  aBankIndex 
       
   574         Index of sound bank where 0 <= aBankIndex < NumberOfBanks().
       
   575 @param  aBankId
       
   576         Identifier of the specified bank occupying, at most, 14 bits.
       
   577 @return One of the system-wide error codes.
       
   578 */
       
   579 EXPORT_C TInt RMidiControllerCustomCommands::GetBankId(TBool aCustom, TInt aBankIndex, TInt& aBankId) const
       
   580 	{
       
   581 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
   582 	configPackage().iCustom = aCustom;
       
   583 	configPackage().iBankIndex = aBankIndex;
       
   584 	TInt error = iController.CustomCommandSync(iDestinationPckg, 
       
   585 												EMMFMidiControllerGetBankId, 
       
   586 												configPackage,
       
   587 												KNullDesC8,
       
   588 												configPackage);
       
   589 	if (!error)
       
   590 		aBankId = configPackage().iBankId;
       
   591 	return error;
       
   592 	}
       
   593 
       
   594 
       
   595 /**
       
   596 Loads one or more custom sound banks from a file into memory for use.
       
   597 If several banks are loaded with consequent LoadCustomBanks() function calls,
       
   598 the banks are combined if the bank sets have conflicting bank numbers.
       
   599 
       
   600 @param aFileName 
       
   601        Name of the file containing the custom sound bank.
       
   602 @param aBankCollectionIndex
       
   603        Identifier of the custom sound bank loaded, occupying no more than 14 bits.
       
   604 @return One of the system-wide error codes.
       
   605 */
       
   606 EXPORT_C TInt RMidiControllerCustomCommands::LoadCustomBank(const TDesC& aFileName,TInt& aBankCollectionIndex)
       
   607 	{
       
   608 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
   609 	configPackage().iFileName = &aFileName;
       
   610 	TInt error = iController.CustomCommandSync(iDestinationPckg, 
       
   611 												EMMFMidiControllerLoadCustomBank, 
       
   612 												configPackage,
       
   613 												KNullDesC8,
       
   614 												configPackage);
       
   615 	if (!error)
       
   616 		aBankCollectionIndex = configPackage().iBankId;
       
   617 	return error;
       
   618 	}
       
   619 
       
   620 
       
   621 /**
       
   622 Loads one or more custom sound banks from a descriptor into memory for use.
       
   623 If several banks are loaded with consequent LoadCustomBanks() function calls,
       
   624 the banks are combined if the bank sets have conflicting bank numbers.
       
   625 
       
   626 @param aBankData 
       
   627        Descriptor containing the custom sound bank.
       
   628 @param aBankCollectionIndex
       
   629        Identifier of the custom sound bank loaded, occupying no more than 14 bits.
       
   630 @return One of the system-wide error codes.
       
   631 */
       
   632 EXPORT_C TInt RMidiControllerCustomCommands::LoadCustomBankData(const TDesC8& aBankData,TInt& aBankCollectionIndex)
       
   633 	{
       
   634 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
   635 	configPackage().iBankData = &aBankData;
       
   636 	TInt error = iController.CustomCommandSync(iDestinationPckg, 
       
   637 												EMMFMidiControllerLoadCustomBankData, 
       
   638 												configPackage,
       
   639 												KNullDesC8,
       
   640 												configPackage);
       
   641 	if (!error)
       
   642 		aBankCollectionIndex = configPackage().iBankId;
       
   643 	return error;
       
   644 	}
       
   645 
       
   646 
       
   647 /**
       
   648 Removes a custom sound bank from memory. Only valid for sound banks previously
       
   649 loaded from file. Once unloaded the custom sound bank is no longer available for use.
       
   650 
       
   651 @param aBankCollectionIndex 
       
   652        Identifier of the custom sound bank to unload,occupying no more than 14 bits.
       
   653 @return One of the system-wide error codes.
       
   654 */
       
   655 EXPORT_C TInt RMidiControllerCustomCommands::UnloadCustomBank(TInt aBankCollectionIndex)
       
   656 	{
       
   657 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
   658 	configPackage().iBankId= aBankCollectionIndex;
       
   659 	return iController.CustomCommandSync(iDestinationPckg, 
       
   660 										EMMFMidiControllerUnloadCustomBank, 
       
   661 										configPackage,
       
   662 										KNullDesC8);
       
   663 	}
       
   664 
       
   665 /**
       
   666 Query if a bank has been loaded to the memory.
       
   667 
       
   668 @param aBankCollectionIndex
       
   669        Identifier of the custom sound bank to check if it's in memory or not.
       
   670 @param aBankLoaded 
       
   671        ETrue if the specified bank is in memory, EFalse otherwise.
       
   672 @return One of the system-wide error codes.
       
   673 */
       
   674 EXPORT_C TInt RMidiControllerCustomCommands::CustomBankLoaded(TInt aBankCollectionIndex, TBool& aBankLoaded) const
       
   675 	{
       
   676 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
   677 	configPackage().iBankId= aBankCollectionIndex;
       
   678 	TInt error = iController.CustomCommandSync(iDestinationPckg, 
       
   679 												EMMFMidiControllerCustomBankLoaded, 
       
   680 												configPackage,
       
   681 												KNullDesC8,
       
   682 												configPackage);
       
   683 	if (!error)
       
   684 		aBankLoaded = configPackage().iBankLoaded;
       
   685 	return error;
       
   686 	}
       
   687 
       
   688 
       
   689 /**
       
   690 Removes all custom sound banks from memory.
       
   691 
       
   692 @return One of the system-wide error codes.
       
   693 */
       
   694 EXPORT_C TInt RMidiControllerCustomCommands::UnloadAllCustomBanks()
       
   695 	{
       
   696 	return iController.CustomCommandSync(iDestinationPckg, 
       
   697 										EMMFMidiControllerUnloadAllCustomBanks, 
       
   698 										KNullDesC8,
       
   699 										KNullDesC8);
       
   700 	}
       
   701 
       
   702 /**
       
   703 Gets the number of instruments available in a given sound bank.
       
   704 
       
   705 @param aBankId
       
   706        Identifier of sound bank to reference, occupying no more than 14 bits.
       
   707 @param aCustom
       
   708        Specifies whether to reference a custom or standard sound bank.
       
   709 @param aNumInstruments 
       
   710        Count of the number of instruments available for the specified sound bank.
       
   711 @return One of the system-wide error codes.
       
   712 */
       
   713 EXPORT_C TInt RMidiControllerCustomCommands::NumberOfInstruments(TInt aBankId, TBool aCustom, TInt& aNumInstruments) const
       
   714 	{
       
   715 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
   716 	configPackage().iBankId = aBankId;
       
   717 	configPackage().iCustom = aCustom;
       
   718 	TInt error = iController.CustomCommandSync(iDestinationPckg, 
       
   719 												EMMFMidiControllerNumberOfInstruments, 
       
   720 												configPackage,
       
   721 												KNullDesC8,
       
   722 												configPackage);
       
   723 	if (!error)
       
   724 		aNumInstruments = configPackage().iNumInstruments;
       
   725 	return error;
       
   726 	}
       
   727 
       
   728 
       
   729 /**
       
   730 Gets the identifier of an instrument.
       
   731 
       
   732 @param aBankId 
       
   733        Identifier of the sound bank to reference, occupying no more than 14 bits.
       
   734 @param aCustom 
       
   735        Specifies whether to reference a custom or standard sound bank.
       
   736 @param aInstrumentIndex 
       
   737        Index of the instrument to reference where 0 <= aInstrumentIndex < NumberOfInstruments(). 
       
   738 @param aInstrumentId 
       
   739        Identifier of specified instrument. This may differ from the index since the index
       
   740 	   simply enumerates the instruments, whereas identifiers may not be contiguous,
       
   741 	   especially where certain instruments correspond to General MIDI-defined instruments
       
   742 	   but not all instruments are present. Instrument identifiers are between 0 and 127 inclusive.
       
   743 @return One of the system-wide error codes.
       
   744 */
       
   745 EXPORT_C TInt RMidiControllerCustomCommands::GetInstrumentId(TInt aBankId, TBool aCustom, TInt aInstrumentIndex, TInt& aInstrumentId) const
       
   746 	{
       
   747 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
   748 	configPackage().iBankId = aBankId;
       
   749 	configPackage().iCustom = aCustom;
       
   750 	configPackage().iInstrumentIndex = aInstrumentIndex;
       
   751 	TInt error = iController.CustomCommandSync(iDestinationPckg, 
       
   752 									 			EMMFMidiControllerGetInstrumentId, 
       
   753 												configPackage,
       
   754 												KNullDesC8,
       
   755 												configPackage);
       
   756 	if (!error)
       
   757 		aInstrumentId = configPackage().iInstrumentId;
       
   758 	return error;
       
   759 	}
       
   760 
       
   761 
       
   762 /**
       
   763 Gets the name of the given instrument.
       
   764 
       
   765 @param  aBankId 
       
   766         Identifier of the bank that the instrument belongs to, occupying no more than 14 bits.
       
   767 @param  aCustom 
       
   768         Specifies whether to reference a custom or standard sound bank.
       
   769 @param  aInstrumentId 
       
   770         Identifier of the instrument under scrutiny. 0 <= aInstrumentId <= 127.
       
   771 @return Buffer containing the name of the specified instrument. If it has no name
       
   772         then an empty descriptor is returned.
       
   773 */
       
   774 EXPORT_C HBufC* RMidiControllerCustomCommands::InstrumentNameL(TInt aBankId, TBool aCustom, TInt aInstrumentId) const
       
   775 	{
       
   776 	// First, get the size of the instrument name so we can create a descriptor big enough to hold it
       
   777 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
   778 	configPackage().iBankId = aBankId;
       
   779 	configPackage().iCustom = aCustom;
       
   780 	configPackage().iInstrumentId = aInstrumentId;
       
   781 	TPckgBuf<TInt> descriptorSizePckg;
       
   782 	User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg,
       
   783 													 EMMFMidiControllerInstrumentName,
       
   784 													 configPackage,
       
   785 													 KNullDesC8,
       
   786 													 descriptorSizePckg));
       
   787 
       
   788 	// Now create a descriptor of appropriate size and get the server to copy the data into it
       
   789 	HBufC8* instrumentNameBuffer = HBufC8::NewLC(descriptorSizePckg());
       
   790 	TPtr8 instrumentNameBufferPtr = instrumentNameBuffer->Des();
       
   791 	User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg,
       
   792 													 EMMFMidiControllerCopyInstrumentName,
       
   793 													 KNullDesC8,
       
   794 													 KNullDesC8,
       
   795 													 instrumentNameBufferPtr));
       
   796 
       
   797 	// Stream data out of the 8bit descriptor into a 16bit descriptor
       
   798 	RDesReadStream stream;
       
   799 	stream.Open(*instrumentNameBuffer);
       
   800 	CleanupClosePushL(stream);
       
   801 
       
   802 	HBufC* instrumentName = HBufC::NewL(stream, KMaxTInt);
       
   803 	
       
   804 	CleanupStack::PopAndDestroy();//stream
       
   805 	CleanupStack::PopAndDestroy(instrumentNameBuffer);
       
   806 
       
   807 	return instrumentName;
       
   808 	}
       
   809 
       
   810 
       
   811 /**
       
   812 Sets a logical channel to use the given instrument.
       
   813 
       
   814 @param aChannel 
       
   815        Logical channel to set the instrument for. 0 <= aChannel <= 15.
       
   816 @param aBankId 
       
   817        Identifier of the bank that the instrument belongs to, occupying no more than 14 bits.
       
   818        The bank ID is a concatenation of MIDI bank MSB and LSB values.
       
   819 @param aInstrumentId 
       
   820        Identifier of the instrument under scrutiny. 0 <= aInstrumentId <= 127.
       
   821 @return One of the system-wide error codes.
       
   822 */
       
   823 EXPORT_C TInt RMidiControllerCustomCommands::SetInstrument(TInt aChannel,TInt aBankId,TInt aInstrumentId)
       
   824 	{
       
   825 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
   826 	configPackage().iChannel = aChannel;
       
   827 	configPackage().iBankId = aBankId;
       
   828 	configPackage().iInstrumentId = aInstrumentId;
       
   829 	return iController.CustomCommandSync(iDestinationPckg, 
       
   830 										EMMFMidiControllerSetInstrument,
       
   831 										configPackage,
       
   832 										KNullDesC8);
       
   833 	}
       
   834 
       
   835 /**
       
   836 Loads an individual instrument from file into custom sound bank memory for use.
       
   837 The bank and instrument id given in the file can be mapped into different bank
       
   838 and instrument id in memory.
       
   839 
       
   840 @param aFileName 
       
   841        Name of the file containing the instrument.
       
   842 @param aFileBankId 
       
   843        Identifier of the bank in the file from which to load the instrument,
       
   844 	   occupying no more than 14 bits.
       
   845 @param aFileInstrumentId 
       
   846        Identifier of the instrument to load. 0 <= aInstrumentId <= 127.
       
   847 @param aMemoryBankId 
       
   848        Identifier of the custom bank in memory to load the instrument into,
       
   849        occupying no more than 14 bits.
       
   850 @param aMemoryInstrumentId 
       
   851        Identifier of the instrument in memory to load the new instrument into.
       
   852 	   0 <= aInstrumentId <= 127.
       
   853 @return One of the system-wide error codes.
       
   854 */
       
   855 EXPORT_C TInt RMidiControllerCustomCommands::LoadCustomInstrument(const TDesC& aFileName, TInt aFileBankId, TInt aFileInstrumentId, TInt aMemoryBankId, TInt aMemoryInstrumentId)
       
   856 	{
       
   857 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
   858 	configPackage().iFileName = &aFileName;
       
   859 	configPackage().iBankId = aFileBankId;
       
   860 	configPackage().iInstrumentId = aFileInstrumentId;
       
   861 	configPackage().iMemoryBankId = aMemoryBankId;
       
   862 	configPackage().iMemoryInstrumentId = aMemoryInstrumentId;
       
   863 	return iController.CustomCommandSync(iDestinationPckg, 
       
   864 										EMMFMidiControllerLoadCustomInstrument,
       
   865 										configPackage,
       
   866 										KNullDesC8);
       
   867 	}
       
   868 
       
   869 
       
   870 /**
       
   871 Loads an individual instrument from descriptor into custom sound bank memory for use.
       
   872 The bank and instrument id given in the descriptor can be mapped into different bank
       
   873 and instrument id in memory.
       
   874 
       
   875 @param aInstrumentData 
       
   876        Descriptor containing the instrument.
       
   877 @param aBankDataId 
       
   878        Identifier of the bank in the descriptor from which to load the instrument,
       
   879        occupying no more than 14 bits.
       
   880 @param aInstrumentDataId 
       
   881        Identifier of the instrument to load. 0 <= aInstrumentId <= 127.
       
   882 @param aMemoryBankId 
       
   883        Identifier of the custom bank in memory to load the instrument into,
       
   884        occupying no more than 14 bits.
       
   885 @param aMemoryInstrumentId 
       
   886        Identifier of the instrument in memory to load the new instrument into.
       
   887 	   0 <= aInstrumentId <= 127.
       
   888 @return One of the system-wide error codes.
       
   889 */
       
   890 EXPORT_C TInt RMidiControllerCustomCommands::LoadCustomInstrumentData(const TDesC8& aInstrumentData, TInt aBankDataId, TInt aInstrumentDataId, TInt aMemoryBankId, TInt aMemoryInstrumentId)
       
   891 	{
       
   892 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
   893 	configPackage().iInstrumentData = &aInstrumentData;
       
   894 	configPackage().iBankId = aBankDataId;
       
   895 	configPackage().iInstrumentId = aInstrumentDataId;
       
   896 	configPackage().iMemoryBankId = aMemoryBankId;
       
   897 	configPackage().iMemoryInstrumentId = aMemoryInstrumentId;
       
   898 	return iController.CustomCommandSync(iDestinationPckg, 
       
   899 										EMMFMidiControllerLoadCustomInstrumentData,
       
   900 										configPackage,
       
   901 										KNullDesC8);
       
   902 	}
       
   903 
       
   904 /**
       
   905 Removes an instrument from custom sound bank memory. Only valid for
       
   906 instruments previously loaded from file. Once unloaded the instrument
       
   907 is no longer available for use.
       
   908 
       
   909 @param aCustomBankId 
       
   910        Identifier of the custom sound bank containing the instrument to unload,
       
   911 	   occupying no more than 14 bits.
       
   912 @param aInstrumentId
       
   913        Identifier of the instrument to unload. 0 <= aInstrumentId <= 127.
       
   914 @return One of the system-wide error codes.
       
   915 */
       
   916 EXPORT_C TInt RMidiControllerCustomCommands::UnloadCustomInstrument(TInt aCustomBankId,TInt aInstrumentId)
       
   917 	{
       
   918 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
   919 	configPackage().iBankId = aCustomBankId;
       
   920 	configPackage().iInstrumentId = aInstrumentId;
       
   921 	return iController.CustomCommandSync(iDestinationPckg, 
       
   922 										EMMFMidiControllerUnloadCustomInstrument,
       
   923 										configPackage,
       
   924 										KNullDesC8);
       
   925 	}
       
   926 
       
   927 /**
       
   928 Gets the name of a particular percussion key corresponding to a given note.
       
   929 
       
   930 @param aNote 
       
   931        Note to query. 0 <= aNote <= 127.
       
   932 @param aBankId 
       
   933        Identifier of the bank that the instrument belongs to, occupying no more than 14 bits.
       
   934        The bank ID is a concatenation of MIDI bank MSB and LSB values.
       
   935 @param aCustom 
       
   936        Specifies whether to reference a custom or standard sound bank.
       
   937 @param aInstrumentId
       
   938        Identifier of an instrument.
       
   939 @return Descriptor containing the name of the percussion key. If the key
       
   940         does not have a name then an empty descriptor is returned.
       
   941 */
       
   942 EXPORT_C HBufC* RMidiControllerCustomCommands::PercussionKeyNameL(TInt aNote, TInt aBankId, TBool aCustom, TInt aInstrumentId) const
       
   943 	{
       
   944 	// First, get the size of the percussion key name so we can create a descriptor big enough to hold it
       
   945 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
   946 	configPackage().iNote = aNote;
       
   947 	configPackage().iBankId = aBankId;
       
   948 	configPackage().iCustom = aCustom;
       
   949 	configPackage().iInstrumentId = aInstrumentId;
       
   950 	TPckgBuf<TInt> descriptorSizePckg;
       
   951 	User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg,
       
   952 													 EMMFMidiControllerPercussionKeyName,
       
   953 													 configPackage,
       
   954 													 KNullDesC8,
       
   955 													 descriptorSizePckg));
       
   956 
       
   957 	// Now create a descriptor of appropriate size and get the server to copy the data into it
       
   958 	HBufC8* keyNameBuffer = HBufC8::NewLC(descriptorSizePckg());
       
   959 	TPtr8 keyNameBufferPtr = keyNameBuffer->Des();
       
   960 	User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg,
       
   961 													 EMMFMidiControllerCopyPercussionKeyName,
       
   962 													 KNullDesC8,
       
   963 													 KNullDesC8,
       
   964 													 keyNameBufferPtr));
       
   965 
       
   966 	// Stream data out of the 8bit descriptor into a 16bit descriptor
       
   967 	RDesReadStream stream;
       
   968 	stream.Open(*keyNameBuffer);
       
   969 	CleanupClosePushL(stream);
       
   970 
       
   971 	HBufC* keyName = HBufC::NewL(stream, KMaxTInt);
       
   972 	
       
   973 	CleanupStack::PopAndDestroy();//stream
       
   974 	CleanupStack::PopAndDestroy(keyNameBuffer);
       
   975 	
       
   976 	return keyName;
       
   977 	}
       
   978 
       
   979 /**
       
   980 Get the stop time currently set for the MIDI resource.
       
   981 
       
   982 @param aStopTime
       
   983        Time at which playback will stop, relative to the start of the resource.
       
   984 @return One of the system-wide error codes.
       
   985 */
       
   986 EXPORT_C TInt RMidiControllerCustomCommands::StopTime(TTimeIntervalMicroSeconds& aStopTime) const
       
   987 	{
       
   988 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
   989 	TInt error = iController.CustomCommandSync(iDestinationPckg, 
       
   990 												EMMFMidiControllerStopTime,
       
   991 												KNullDesC8,
       
   992 												KNullDesC8,
       
   993 												configPackage);
       
   994 	if (!error)
       
   995 		aStopTime = configPackage().iStopTime;
       
   996 	return error;
       
   997 	}
       
   998 
       
   999 
       
  1000 /**
       
  1001 Sets the stop time to use for the currently open MIDI resource
       
  1002 
       
  1003 @param aStopTime
       
  1004        Time at which playback will stop, relative to the start of the resource.
       
  1005        Clamped to 0 and the duration of the resource.
       
  1006 @return One of the system-wide error codes.
       
  1007 */
       
  1008 EXPORT_C TInt RMidiControllerCustomCommands::SetStopTime(const TTimeIntervalMicroSeconds& aStopTime) const
       
  1009 	{
       
  1010 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
  1011 	configPackage().iStopTime = aStopTime;
       
  1012 	return iController.CustomCommandSync(iDestinationPckg, 
       
  1013 										EMMFMidiControllerSetStopTime,
       
  1014 										configPackage,
       
  1015 										KNullDesC8);
       
  1016 	}
       
  1017 
       
  1018 /**
       
  1019 Gets the polyphony of the MIDI engine.
       
  1020 
       
  1021 @param aNumNotes 
       
  1022        The number of currently active voices.
       
  1023 @return One of the system-wide error codes.
       
  1024 */
       
  1025 EXPORT_C TInt RMidiControllerCustomCommands::Polyphony(TInt& aNumNotes) const
       
  1026 	{
       
  1027 	TPckgBuf<TMMFMidiConfig1> configPackage;
       
  1028 	TInt error = iController.CustomCommandSync(iDestinationPckg, 
       
  1029 											EMMFMidiControllerPolyphony,
       
  1030 											KNullDesC8,
       
  1031 											KNullDesC8,
       
  1032 											configPackage);
       
  1033 	if (!error)
       
  1034 		aNumNotes = configPackage().iNumNotes;
       
  1035 	return error;
       
  1036 	}
       
  1037 
       
  1038 
       
  1039 /**
       
  1040 Gets the current maximum number of notes the engine can handle
       
  1041 This can be greater than the value returned by RMidiControllerCustomCommands::Polyphony
       
  1042 
       
  1043 @param aNumNotes 
       
  1044        The maximum number of notes the engine can handle
       
  1045 @return One of the system-wide error codes.
       
  1046 */
       
  1047 EXPORT_C TInt RMidiControllerCustomCommands::MaxPolyphony(TInt& aMaxNotes) const
       
  1048 	{
       
  1049 	TPckgBuf<TMMFMidiConfig1> configPackage;
       
  1050 	TInt error = iController.CustomCommandSync(iDestinationPckg, 
       
  1051 											EMMFMidiControllerMaxPolyphony,
       
  1052 											KNullDesC8,
       
  1053 											KNullDesC8,
       
  1054 											configPackage);
       
  1055 	if (!error)
       
  1056 		aMaxNotes = configPackage().iMaxNotes;
       
  1057 	return error;
       
  1058 	}
       
  1059 
       
  1060 /**
       
  1061 Get the maximum number of logical channels supported by the MIDI engine.
       
  1062 
       
  1063 @param aChannels
       
  1064        The maximum number of logical channels that the MIDI engine supports,
       
  1065 	   0 <= aChannels <=15.
       
  1066 @return One of the system-wide error codes.
       
  1067 */
       
  1068 EXPORT_C TInt RMidiControllerCustomCommands::ChannelsSupported(TInt& aChannels) const
       
  1069 	{
       
  1070 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
  1071 	TInt error = iController.CustomCommandSync(iDestinationPckg, 
       
  1072 											EMMFMidiControllerChannelsSupported,
       
  1073 											KNullDesC8,
       
  1074 											KNullDesC8,
       
  1075 											configPackage);
       
  1076 	if (!error)
       
  1077 		aChannels = configPackage().iChannel;
       
  1078 	return error;
       
  1079 	}
       
  1080 
       
  1081 
       
  1082 /**
       
  1083 Get the current volume setting of a logical channel.
       
  1084 
       
  1085 @param aChannel 
       
  1086        Logical channel to query. 0 <= aChannel <= 15.
       
  1087 @param aChannelVol 
       
  1088        Volume currently set on the specified channel in decibels.
       
  1089 @return One of the system-wide error codes.
       
  1090 */
       
  1091 EXPORT_C TInt RMidiControllerCustomCommands::ChannelVolume(TInt aChannel, TReal32& aChannelVol) const
       
  1092 	{
       
  1093 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
  1094 	configPackage().iChannel = aChannel;
       
  1095 	TInt error = iController.CustomCommandSync(iDestinationPckg, 
       
  1096 												EMMFMidiControllerChannelVolume,
       
  1097 												configPackage,
       
  1098 												KNullDesC8,
       
  1099 												configPackage);
       
  1100 	if (!error)
       
  1101 		aChannelVol = configPackage().iChannelVol;
       
  1102 	return error;
       
  1103 	}
       
  1104 
       
  1105 /**
       
  1106 Gets the Maximum volume setting that may be applied to a logical channel.
       
  1107 
       
  1108 @param aMaxVol 
       
  1109        Maximum volume setting. Minimum value is -infinity dB, which is the 
       
  1110        smallest possible value that TReal32 supports.
       
  1111 @return One of the system-wide error codes.
       
  1112 */
       
  1113 EXPORT_C TInt RMidiControllerCustomCommands::MaxChannelVolume(TReal32& aMaxVol) const
       
  1114 	{
       
  1115 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
  1116 	TInt error = iController.CustomCommandSync(iDestinationPckg, 
       
  1117 												EMMFMidiControllerMaxChannelVolume,
       
  1118 												KNullDesC8,
       
  1119 												KNullDesC8,
       
  1120 												configPackage);
       
  1121 	if (!error)
       
  1122 		aMaxVol = configPackage().iMaxChannelVol;
       
  1123 	return error;
       
  1124 	}
       
  1125 
       
  1126 /**
       
  1127 Set the volume of a channel.
       
  1128 
       
  1129 @param aChannel 
       
  1130        Logical channel to set the volume on. 0 <= aChannel <= 15.
       
  1131 @param aVolume 
       
  1132        The channel volume can be set within a range. The minimum 
       
  1133        channel volume is -infinity dB, which is the smallest possible
       
  1134        value that TReal32 supports while the maximum channel volume
       
  1135        is set via MaxVolumeL() which represents the volume level in dB
       
  1136        corresponding to the MIDI Channel Volume controller.
       
  1137 @return One of the system-wide error codes.
       
  1138 */
       
  1139 EXPORT_C TInt RMidiControllerCustomCommands::SetChannelVolume(TInt aChannel,TReal32 aVolume)
       
  1140 	{
       
  1141 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
  1142 	configPackage().iChannel = aChannel;
       
  1143 	configPackage().iChannelVol = aVolume;
       
  1144 	return iController.CustomCommandSync(iDestinationPckg, 
       
  1145 										EMMFMidiControllerSetChannelVolume,
       
  1146 										configPackage,
       
  1147 										KNullDesC8);
       
  1148 	}
       
  1149 
       
  1150 /**
       
  1151 Set the muting state of a channel without changing its volume setting.
       
  1152 When unmuted the channel goes back to its previous volume setting.
       
  1153 
       
  1154 @param aChannel 
       
  1155        Logical channel to set the mute state of. 0 <= aChannel <= 15.
       
  1156 @param aMuted 
       
  1157        ETrue to mute the channel, EFalse to unmute it.
       
  1158 @return One of the system-wide error codes.
       
  1159 */
       
  1160 EXPORT_C TInt RMidiControllerCustomCommands::SetChannelMute(TInt aChannel,TBool aMuted)
       
  1161 	{
       
  1162 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
  1163 	configPackage().iChannel = aChannel;
       
  1164 	configPackage().iMuted = aMuted;
       
  1165 	return iController.CustomCommandSync(iDestinationPckg, 
       
  1166 										EMMFMidiControllerSetChannelMute,
       
  1167 										configPackage,
       
  1168 										KNullDesC8);
       
  1169 	}
       
  1170 
       
  1171 
       
  1172 /**
       
  1173 Gets the overall volume of the MIDI client.
       
  1174 
       
  1175 @param aVolume 
       
  1176        The current overall volume setting.
       
  1177 @return One of the system-wide error codes.
       
  1178 */
       
  1179 EXPORT_C TInt RMidiControllerCustomCommands::Volume(TInt& aVolume) const
       
  1180 	{
       
  1181 	TPckgBuf<TMMFMidiConfig1> configPackage;
       
  1182 	TInt error = iController.CustomCommandSync(iDestinationPckg, 
       
  1183 												EMMFMidiControllerVolume,
       
  1184 												KNullDesC8,
       
  1185 												KNullDesC8,
       
  1186 												configPackage);
       
  1187 	if (!error)
       
  1188 		aVolume = configPackage().iVolume;
       
  1189 	return error;
       
  1190 	}
       
  1191 
       
  1192 
       
  1193 /**
       
  1194 Maximum volume setting that may be applied overall.
       
  1195 
       
  1196 @param aMaxVolume 
       
  1197        Maximum volume setting. Minimum value is always zero which is silent.
       
  1198 @return One of the system-wide error codes.
       
  1199 */
       
  1200 EXPORT_C TInt RMidiControllerCustomCommands::MaxVolume(TInt& aMaxVolume) const
       
  1201 	{
       
  1202 	TPckgBuf<TMMFMidiConfig1> configPackage;
       
  1203 	TInt error = iController.CustomCommandSync(iDestinationPckg, 
       
  1204 										EMMFMidiControllerMaxVolume,
       
  1205 										KNullDesC8,
       
  1206 										KNullDesC8,
       
  1207 										configPackage);
       
  1208 	if (!error)
       
  1209 		aMaxVolume = configPackage().iMaxVolume;
       
  1210 	return error;
       
  1211 	}
       
  1212 
       
  1213 
       
  1214 /**
       
  1215 Set the overall volume of the MIDI client.
       
  1216 This setting scales all channel volumes respectively so the actual volume
       
  1217 that a channel is played at is (overall volume * channel volume / max volume).
       
  1218 
       
  1219 @param aVolume
       
  1220        Overall volume setting to use.
       
  1221 @return One of the system-wide error codes.
       
  1222 */
       
  1223 EXPORT_C TInt RMidiControllerCustomCommands::SetVolume(TInt aVolume)
       
  1224 	{
       
  1225 	TPckgBuf<TMMFMidiConfig1> configPackage;
       
  1226 	configPackage().iVolume = aVolume;
       
  1227 	return iController.CustomCommandSync(iDestinationPckg, 
       
  1228 										EMMFMidiControllerSetVolume,
       
  1229 										configPackage,
       
  1230 										KNullDesC8);
       
  1231 	}
       
  1232 
       
  1233 /**
       
  1234 Length of time over which the volume is faded up from zero to the current setting
       
  1235 when playback is started.
       
  1236 
       
  1237 @param aRampDuration 
       
  1238        Duration of the ramping period.
       
  1239 @return One of the system-wide error codes.
       
  1240 */
       
  1241 EXPORT_C TInt RMidiControllerCustomCommands::SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration)
       
  1242 	{
       
  1243 	TPckgBuf<TMMFMidiConfig1> configPackage;
       
  1244 	configPackage().iRampDuration = aRampDuration;
       
  1245 	return iController.CustomCommandSync(iDestinationPckg, 
       
  1246 										EMMFMidiControllerSetVolumeRamp,
       
  1247 										configPackage,
       
  1248 										KNullDesC8);
       
  1249 	}
       
  1250 
       
  1251 /**
       
  1252 Get the current stereo balance value.
       
  1253 
       
  1254 @param aBalance 
       
  1255        Balance value ranging from KMMFBalanceMaxLeft to KMMFBalanceMaxRight.
       
  1256 @return One of the system-wide error codes.
       
  1257 */
       
  1258 EXPORT_C TInt RMidiControllerCustomCommands::GetBalance(TInt& aBalance) const
       
  1259 	{
       
  1260 	TPckgBuf<TMMFMidiConfig1> configPackage;
       
  1261 	TInt error = iController.CustomCommandSync(iDestinationPckg, 
       
  1262 												EMMFMidiControllerGetBalance,
       
  1263 												KNullDesC8,
       
  1264 												KNullDesC8,
       
  1265 												configPackage);
       
  1266 	if (!error)
       
  1267 		aBalance = configPackage().iBalance;
       
  1268 	return error;
       
  1269 	}
       
  1270 
       
  1271 /**
       
  1272 Set the current stereo balance value.
       
  1273 
       
  1274 @param aBalance 
       
  1275        Balance value to set. Defaults to KMMFBalanceCenter to restore equal left-right balance.
       
  1276 @return One of the system-wide error codes.
       
  1277 */
       
  1278 EXPORT_C TInt RMidiControllerCustomCommands::SetBalance(TInt aBalance)
       
  1279 	{
       
  1280 	TPckgBuf<TMMFMidiConfig1> configPackage;
       
  1281 	configPackage().iBalance = aBalance;
       
  1282 	return iController.CustomCommandSync(iDestinationPckg, 
       
  1283 										EMMFMidiControllerSetBalance,
       
  1284 										configPackage,
       
  1285 										KNullDesC8);
       
  1286 	}
       
  1287 
       
  1288 /**
       
  1289 Set the max polyphony the engine can handle.
       
  1290 
       
  1291 @param aMaxNotes 
       
  1292        Max polyphony level,  1 <= Polyphony() <= aMaxNotes.
       
  1293 @return One of the system-wide error codes.
       
  1294 */
       
  1295 EXPORT_C TInt RMidiControllerCustomCommands::SetMaxPolyphony(TInt aMaxNotes)
       
  1296 	{
       
  1297 	TPckgBuf<TMMFMidiConfig1> configPackage;
       
  1298 	configPackage().iMaxNotes = aMaxNotes;
       
  1299 	return iController.CustomCommandSync(iDestinationPckg, 
       
  1300 										EMMFMidiControllerSetMaxPolyphony,
       
  1301 										configPackage,
       
  1302 										KNullDesC8);
       
  1303 	}
       
  1304 
       
  1305 /**
       
  1306 Gets the number of times the current opened resources has to be repeated.
       
  1307 
       
  1308 @param aNumRepeats
       
  1309        The number of times the current opened resources has to be repeated.
       
  1310 @return One of the system-wide error codes.
       
  1311 */
       
  1312 EXPORT_C TInt RMidiControllerCustomCommands::GetRepeats(TInt& aNumRepeats) const
       
  1313 	{
       
  1314 	TPckgBuf<TMMFMidiConfig1> configPackage;
       
  1315 	TInt error = iController.CustomCommandSync(iDestinationPckg, 
       
  1316 												EMMFMidiControllerGetRepeats,
       
  1317 												KNullDesC8,
       
  1318 												KNullDesC8,
       
  1319 												configPackage);
       
  1320 	if (!error)
       
  1321 		aNumRepeats = configPackage().iNumRepeats;
       
  1322 	return error;
       
  1323 	}
       
  1324 
       
  1325 /**
       
  1326 Set the number of times to repeat the current MIDI resource.
       
  1327 After Stop() has been called, repeat number of times and the
       
  1328 trailing silence are reset.
       
  1329 
       
  1330 @param aRepeatNumberOfTimes 
       
  1331        Number of times to repeat the resource during playback. This includes the first playing.
       
  1332 @param aTrailingSilence 
       
  1333        Time in microseconds to pause between repeats.
       
  1334 @return One of the system-wide error codes.
       
  1335 */
       
  1336 EXPORT_C TInt RMidiControllerCustomCommands::SetRepeats(TInt aRepeatNumberOfTimes, const TTimeIntervalMicroSeconds& aTrailingSilence)
       
  1337 	{
       
  1338 	
       
  1339 	TPckgBuf<TMMFMidiConfig3> configPackage;
       
  1340 	configPackage().iRepeatNumberOfTimes = aRepeatNumberOfTimes;
       
  1341 	configPackage().iTrailingSilence = aTrailingSilence;
       
  1342 	return iController.CustomCommandSync(iDestinationPckg, 
       
  1343 										EMMFMidiControllerSetRepeats,
       
  1344 										configPackage,
       
  1345 										KNullDesC8);
       
  1346 	}
       
  1347 
       
  1348 /**
       
  1349 Tell the MIDI engine to use a custom bank or a standard bank.
       
  1350 
       
  1351 @param aCustom
       
  1352        If Etrue the custom bank in memory is used otherwise the standard bank
       
  1353        is used leaving the custom bank in memory.
       
  1354 @return One of the system-wide error codes.
       
  1355 */
       
  1356 EXPORT_C TInt RMidiControllerCustomCommands::SetBank(TBool aCustom)
       
  1357 	{
       
  1358 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
  1359 	configPackage().iCustom = aCustom;
       
  1360 	return iController.CustomCommandSync(iDestinationPckg, 
       
  1361 										EMMFMidiControllerSetBank,
       
  1362 										configPackage,
       
  1363 										KNullDesC8);
       
  1364 	}
       
  1365 
       
  1366 /**
       
  1367 Gets the muting status of a specific track.
       
  1368 
       
  1369 @param aTrack 
       
  1370        The track to query.
       
  1371 @param aTrackMute 
       
  1372        The mute status of the track.
       
  1373 @return One of the system-wide error codes.
       
  1374 */
       
  1375 EXPORT_C TInt RMidiControllerCustomCommands::IsTrackMute(TInt aTrack, TBool& aTrackMute) const
       
  1376 	{
       
  1377 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
  1378 	configPackage().iTrack = aTrack;
       
  1379 	TInt error = iController.CustomCommandSync(iDestinationPckg, 
       
  1380 												EMMFMidiControllerIsTrackMute,
       
  1381 												configPackage,
       
  1382 												KNullDesC8,
       
  1383 												configPackage);
       
  1384 	if (!error)
       
  1385 		aTrackMute = configPackage().iMuted;
       
  1386 	return error;
       
  1387 	}
       
  1388 
       
  1389 
       
  1390 /**
       
  1391 Gets the muting status of a specific channel.
       
  1392 
       
  1393 @param aChannel
       
  1394        The channel to query.
       
  1395 @param aChannelMute
       
  1396        The mute status of the channel.
       
  1397 @return One of the system-wide error codes.
       
  1398 */
       
  1399 EXPORT_C TInt RMidiControllerCustomCommands::IsChannelMute(TInt aChannel, TBool& aChannelMute) const
       
  1400 	{
       
  1401 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
  1402 	configPackage().iChannel = aChannel;
       
  1403 	TInt error = iController.CustomCommandSync(iDestinationPckg, 
       
  1404 												EMMFMidiControllerIsChannelMute,
       
  1405 												configPackage,
       
  1406 												KNullDesC8,
       
  1407 												configPackage);
       
  1408 	if (!error)
       
  1409 		aChannelMute = configPackage().iMuted;
       
  1410 	return error;
       
  1411 	}
       
  1412 
       
  1413 
       
  1414 /**
       
  1415 Gets the instrument assigned to a specified channel.
       
  1416 
       
  1417 @param aChannel 
       
  1418        Logical channel, 0 <= aChannel <= 15.
       
  1419 @param aInstrumentId 
       
  1420        Identifier of the instrument assigned to aChannel. 0 <= aInstrumentId <= 127.
       
  1421 @param aBankId 
       
  1422        Identifier of the bank that the instrument belongs to, occupying no more than 14 bits.
       
  1423 @return One of the system-wide error codes.
       
  1424 */
       
  1425 EXPORT_C TInt RMidiControllerCustomCommands::GetInstrument(TInt aChannel, TInt& aInstrumentId, TInt& aBankId)
       
  1426 	{
       
  1427 	TPckgBuf<TMMFMidiConfig2> configPackage;
       
  1428 	configPackage().iChannel = aChannel;
       
  1429 	TInt error = iController.CustomCommandSync(iDestinationPckg, 
       
  1430 												EMMFMidiControllerGetInstrument,
       
  1431 												configPackage,
       
  1432 												KNullDesC8,
       
  1433 												configPackage);
       
  1434 	if (!error)
       
  1435 		{
       
  1436 		aInstrumentId = configPackage().iInstrumentId;
       
  1437 		aBankId = configPackage().iBankId;
       
  1438 		}
       
  1439 	return error;
       
  1440 	}
       
  1441 
       
  1442 /**
       
  1443 Closes any currently open resources, such as files, descriptors or URLs in use.
       
  1444 Does nothing if there is nothing currently open.
       
  1445 
       
  1446 @return One of the system-wide error codes.
       
  1447 */
       
  1448 EXPORT_C TInt RMidiControllerCustomCommands::Close()
       
  1449 	{
       
  1450 	return iController.CustomCommandSync(iDestinationPckg, 
       
  1451 										EMMFMidiControllerClose,
       
  1452 										KNullDesC8,
       
  1453 										KNullDesC8);
       
  1454 	}
       
  1455 
       
  1456 /**
       
  1457 Stops playback of a resource but does not change the current position
       
  1458 or release any resources. Pauses the internal timer if no resource is open.
       
  1459 
       
  1460 @param aFadeOutDuration 
       
  1461        Length of time over which the volume is faded out from the current setting to zero.
       
  1462 @return One of the system-wide error codes.
       
  1463 */
       
  1464 EXPORT_C TInt RMidiControllerCustomCommands::Stop(const TTimeIntervalMicroSeconds& aFadeOutDuration)
       
  1465 	{
       
  1466 	TPckgBuf<TMMFMidiConfig1> configPackage;
       
  1467 	configPackage().iFadeOutDuration = aFadeOutDuration;
       
  1468 	return iController.CustomCommandSync(iDestinationPckg, 
       
  1469 										EMMFMidiControllerStop,
       
  1470 										configPackage,
       
  1471 										KNullDesC8);
       
  1472 	}
       
  1473 
       
  1474 
       
  1475 /**
       
  1476 Start receiving events from the controller. This can only be called once the controller is open.
       
  1477 
       
  1478 @param aSizeOfMidiEvent 
       
  1479        The size of the MIDI event object.
       
  1480 @param aStatus 
       
  1481        Status flag belonging to an active object that will have it's RunL() called
       
  1482        when this request complete.
       
  1483 */
       
  1484 EXPORT_C void RMidiControllerCustomCommands::ReceiveEvents(TPckgBuf<TInt>& aSizeOfMidiEvent, TRequestStatus& aStatus)
       
  1485 	{
       
  1486 	iController.CustomCommandAsync(iDestinationPckg, 
       
  1487 									EMMFMidiControllerReceiveEvents,
       
  1488 									KNullDesC8,
       
  1489 									KNullDesC8,
       
  1490 									aSizeOfMidiEvent,
       
  1491 									aStatus);
       
  1492 	}
       
  1493 
       
  1494 /**
       
  1495 Get the MIDI event from the MIDI controller.
       
  1496 
       
  1497 @param aMidiEventPckg
       
  1498        MIDI event.
       
  1499 @return One of the system-wide error codes.
       
  1500 */
       
  1501 EXPORT_C TInt RMidiControllerCustomCommands::RetrieveEvent(TDes8& aMidiEventPckg)
       
  1502 	{
       
  1503 	return iController.CustomCommandSync(iDestinationPckg,
       
  1504 										 EMMFMidiControllerRetrieveEvent,
       
  1505 										 KNullDesC8,
       
  1506 										 KNullDesC8,
       
  1507 										 aMidiEventPckg);
       
  1508 	}
       
  1509 
       
  1510 /**
       
  1511 Stop receiving events from the MIDI controller.
       
  1512 
       
  1513 @return One of the system-wide error codes.
       
  1514 */
       
  1515 EXPORT_C TInt RMidiControllerCustomCommands::CancelReceiveEvents()
       
  1516 	{
       
  1517 	return iController.CustomCommandSync(iDestinationPckg, 
       
  1518 										EMMFMidiControllerCancelReceiveEvents,
       
  1519 										KNullDesC8,
       
  1520 										KNullDesC8);
       
  1521 	}
       
  1522 
       
  1523 
       
  1524 CMidiEventReceiver* CMidiEventReceiver::NewL(const TMMFMessage& aMessage)
       
  1525 	{
       
  1526 	return new(ELeave) CMidiEventReceiver(aMessage);
       
  1527 	}
       
  1528 
       
  1529 CMidiEventReceiver::~CMidiEventReceiver()
       
  1530 	{
       
  1531 	if (!(iMessage.IsCompleted()))
       
  1532 		iMessage.Complete(KErrDied);
       
  1533 	delete iEventBuf;
       
  1534 	}
       
  1535 
       
  1536 void CMidiEventReceiver::PrepareEventL(const CMMFMidiEvent& aEvent)
       
  1537 	{
       
  1538 	// eventbuf should be NULL.  delete it anyway though to prevent memory leaks in release mode
       
  1539 	ASSERT(!iEventBuf);
       
  1540 	
       
  1541 	delete iEventBuf;
       
  1542 	iEventBuf = NULL;
       
  1543 
       
  1544 	iEventBuf = CBufFlat::NewL(32);
       
  1545 	RBufWriteStream s;
       
  1546 	s.Open(*iEventBuf);
       
  1547 	CleanupClosePushL(s);
       
  1548 	aEvent.ExternalizeL(s);
       
  1549 	CleanupStack::PopAndDestroy();//s
       
  1550 	// Write the size of the externalised data back to the client
       
  1551 	TPckgBuf<TInt> pckg;
       
  1552 	pckg() = iEventBuf->Ptr(0).Length();
       
  1553 	TInt error = iMessage.WriteDataToClient(pckg);
       
  1554 	iMessage.Complete(error);
       
  1555 	}
       
  1556 
       
  1557 void CMidiEventReceiver::SendEventL(TMMFMessage& aMessage)
       
  1558 	{
       
  1559 	if (!iEventBuf)
       
  1560 		{
       
  1561 		User::Leave(KErrNotReady);
       
  1562 		}
       
  1563 	else
       
  1564 		{
       
  1565 		aMessage.WriteDataToClientL(iEventBuf->Ptr(0));
       
  1566 		}
       
  1567 	}
       
  1568 
       
  1569 TBool CMidiEventReceiver::IsWaitingToSendEvent()
       
  1570 	{
       
  1571 	return (iEventBuf!=NULL);
       
  1572 	}
       
  1573 
       
  1574 CMidiEventReceiver::CMidiEventReceiver(const TMMFMessage& aMessage) : iMessage(aMessage)
       
  1575 	{
       
  1576 	}
       
  1577 
       
  1578 
       
  1579 /**
       
  1580 Constructor.
       
  1581 
       
  1582 @param aEventType	
       
  1583        A UID to define the type of MIDI event.
       
  1584 @param aErrorCode	
       
  1585        The error code associated with the MIDI event.
       
  1586 */
       
  1587 EXPORT_C CMMFMidiEvent::CMMFMidiEvent(TUid aEventType, TInt aErrorCode)
       
  1588 	: iEventType(aEventType), iErrorCode(aErrorCode)
       
  1589 	{
       
  1590 	ZeroMembers();
       
  1591 	}
       
  1592 
       
  1593 /**
       
  1594 Default constructor.
       
  1595 */
       
  1596 EXPORT_C CMMFMidiEvent::CMMFMidiEvent()
       
  1597 	: iEventType(KNullUid), iErrorCode(KErrNone)
       
  1598 	{
       
  1599 	ZeroMembers();
       
  1600 	}
       
  1601 
       
  1602 /**
       
  1603 Set to default values all the data members.
       
  1604 */
       
  1605 void CMMFMidiEvent::ZeroMembers()
       
  1606 	{
       
  1607 	iOldState = EMidiStateClosedDisengaged;
       
  1608 	iNewState = EMidiStateClosedDisengaged;
       
  1609 	iMicroSeconds = 0;
       
  1610 	iMicroBeats = 0;
       
  1611 	iChannel = 0;
       
  1612 	iVolumeInDecibels = 0;
       
  1613 	iMute = EFalse;
       
  1614 	iMetaDataEntryId = 0;
       
  1615 	iPolyphony = 0;
       
  1616 	iBankId = 0;
       
  1617 	iInstrumentId = 0;
       
  1618 	iTempoMicroBeats = 0;
       
  1619 	}
       
  1620 
       
  1621 /**
       
  1622 Destructor.
       
  1623 */
       
  1624 EXPORT_C CMMFMidiEvent::~CMMFMidiEvent()
       
  1625 	{
       
  1626 	iMipMessage.Close();
       
  1627 	}
       
  1628 	
       
  1629 /**
       
  1630 Externalize the object to a stream. All the member variables will be written to the stream.
       
  1631 
       
  1632 @param aStream	
       
  1633        The write stream object.
       
  1634 */
       
  1635 EXPORT_C void CMMFMidiEvent::ExternalizeL(RWriteStream& aStream) const
       
  1636 	{
       
  1637 	aStream << iEventType;
       
  1638 	aStream.WriteInt32L(iErrorCode);
       
  1639 	aStream.WriteInt32L(iOldState);
       
  1640 	aStream.WriteInt32L(iNewState);
       
  1641 	aStream << iMicroSeconds.Int64();
       
  1642 	aStream << iMicroBeats;
       
  1643 	aStream.WriteInt32L(iChannel);
       
  1644 	aStream << iVolumeInDecibels;
       
  1645 	aStream.WriteInt32L(iMute);
       
  1646 	aStream.WriteInt32L(iMetaDataEntryId);
       
  1647 
       
  1648 	aStream.WriteInt32L(iMipMessage.Count());
       
  1649 	for (TInt i=0; i<iMipMessage.Count(); i++)
       
  1650 		{
       
  1651 		aStream.WriteInt32L(iMipMessage[i].iChannel);
       
  1652 		aStream.WriteInt32L(iMipMessage[i].iMIPValue);
       
  1653 		}
       
  1654 
       
  1655 	aStream.WriteInt32L(iPolyphony);
       
  1656 	aStream.WriteInt32L(iBankId);
       
  1657 	aStream.WriteInt32L(iInstrumentId);
       
  1658 	aStream.WriteInt32L(iTempoMicroBeats);
       
  1659 	}
       
  1660 
       
  1661 /**
       
  1662 Internalize the object from a stream. All the member variables will be read from the stream.
       
  1663 
       
  1664 @param aStream	
       
  1665        The read stream object.
       
  1666 */
       
  1667 EXPORT_C void CMMFMidiEvent::InternalizeL(RReadStream& aStream)
       
  1668 	{
       
  1669 	aStream >> iEventType;
       
  1670 	iErrorCode = aStream.ReadInt32L();
       
  1671 	iOldState = STATIC_CAST(TMidiState, aStream.ReadInt32L());
       
  1672 	iNewState = STATIC_CAST(TMidiState, aStream.ReadInt32L());
       
  1673 
       
  1674 	TInt64 microSeconds;
       
  1675 	aStream >> microSeconds;
       
  1676 	iMicroSeconds = microSeconds;
       
  1677 	
       
  1678 	aStream >> iMicroBeats;
       
  1679 	iChannel = aStream.ReadInt32L();
       
  1680 	aStream >> iVolumeInDecibels;
       
  1681 	iMute = aStream.ReadInt32L();
       
  1682 	iMetaDataEntryId = aStream.ReadInt32L();
       
  1683 
       
  1684 	TInt count = aStream.ReadInt32L();
       
  1685 	for (TInt i=0; i<count; i++)
       
  1686 		{
       
  1687 		TMipMessageEntry entry;
       
  1688 		entry.iChannel = aStream.ReadInt32L();
       
  1689 		entry.iMIPValue = aStream.ReadInt32L();
       
  1690 		User::LeaveIfError(iMipMessage.Append(entry));
       
  1691 		}
       
  1692 
       
  1693 	iPolyphony = aStream.ReadInt32L();
       
  1694 	iBankId = aStream.ReadInt32L();
       
  1695 	iInstrumentId = aStream.ReadInt32L();
       
  1696 	iTempoMicroBeats = aStream.ReadInt32L();
       
  1697 	}
       
  1698 
       
  1699 /**
       
  1700 Copies a MIDI event into this CMMFMidiEvent.
       
  1701 
       
  1702 @param aOther	
       
  1703        The CMMFMidiEvent to copy from.
       
  1704 */
       
  1705 EXPORT_C void CMMFMidiEvent::CopyL(const CMMFMidiEvent& aOther)
       
  1706 	{
       
  1707 	iEventType = aOther.iEventType;
       
  1708 	iErrorCode = aOther.iErrorCode;
       
  1709 	iOldState = aOther.iOldState;
       
  1710 	iNewState = aOther.iNewState;
       
  1711 	iMicroSeconds = aOther.iMicroSeconds;
       
  1712 	iMicroBeats = aOther.iMicroBeats;
       
  1713 	iChannel = aOther.iChannel;
       
  1714 	iVolumeInDecibels = aOther.iVolumeInDecibels;
       
  1715 	iMute = aOther.iMute;
       
  1716 	iMetaDataEntryId = aOther.iMetaDataEntryId;
       
  1717 	iPolyphony = aOther.iPolyphony;
       
  1718 	iBankId = aOther.iBankId;
       
  1719 	iInstrumentId = aOther.iInstrumentId;
       
  1720 	iTempoMicroBeats = aOther.iTempoMicroBeats;
       
  1721 
       
  1722 	for (TInt i=0; i<aOther.iMipMessage.Count(); i++)
       
  1723 		{
       
  1724 		User::LeaveIfError(iMipMessage.Append(aOther.iMipMessage[i]));
       
  1725 		}
       
  1726 	}
       
  1727 
       
  1728