javauis/mmapi_akn/baseline/src/midicontrol.cpp
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  This class has JNI wrappers for CMMAMIDIControl
       
    15 *
       
    16 */
       
    17 
       
    18 #include <jutils.h>
       
    19 
       
    20 #include "com_nokia_microedition_media_control_MIDIControl.h"
       
    21 #include "cmmaeventsource.h"
       
    22 #include "cmmamidicontrol.h"
       
    23 #include <jdebug.h>
       
    24 
       
    25 /**
       
    26  * Local function which is used to call CMMAMIDIControl class method.
       
    27  * Type of of the function pointer must be
       
    28  * void CMMAMIDIControl::aFunc( TInt, TInt, TInt )
       
    29  *
       
    30  * @param aMIDIControl CMMAMIDIControl pointer.
       
    31  * @param aFunc Pointer to the CMMAMIDIControl method.
       
    32  * @param aParam1 Parameter passed to the aFunc.
       
    33  * @param aParam2 Parameter passed to the aFunc.
       
    34  * @param aParam3 Parameter passed to the aFunc.
       
    35  */
       
    36 LOCAL_C void ReturnVoidParam3IntFuncL(
       
    37     CMMAMIDIControl* aMIDIControl,
       
    38     void (CMMAMIDIControl::*aFuncL)(TInt, TInt, TInt),
       
    39     TInt aParam1,
       
    40     TInt aParam2,
       
    41     TInt aParam3)
       
    42 {
       
    43     // call TInt CMMAMIDIControl::aFunc( TInt, TInt, TInt ) method.
       
    44     (aMIDIControl->*aFuncL)(aParam1, aParam2, aParam3);
       
    45 }
       
    46 
       
    47 /**
       
    48  * Implements generated JNI function prototype.
       
    49  */
       
    50 JNIEXPORT jint JNICALL
       
    51 Java_com_nokia_microedition_media_control_MIDIControl__1setProgram
       
    52 (
       
    53     JNIEnv*,
       
    54     jobject,
       
    55     jint aControlHandle,
       
    56     jint aEventSourceHandle,
       
    57     jint aChannel,
       
    58     jint aBank,
       
    59     jint aProgram)
       
    60 {
       
    61     CMMAEventSource* eventSource =
       
    62         JavaUnhand< CMMAEventSource >(aEventSourceHandle);
       
    63 
       
    64     CMMAMIDIControl* midiControl =
       
    65         JavaUnhand< CMMAMIDIControl >(aControlHandle);
       
    66 
       
    67     TInt error;
       
    68     error = eventSource->ExecuteTrap(&ReturnVoidParam3IntFuncL,
       
    69                                      midiControl,
       
    70                                      &CMMAMIDIControl::SetProgramL,
       
    71                                      aChannel,
       
    72                                      aBank,
       
    73                                      aProgram);
       
    74 
       
    75     return error;
       
    76 }
       
    77 
       
    78 /**
       
    79  * Local function which is used to call CMMAMIDIControl class method.
       
    80  * Type of of the function pointer must be
       
    81  * TInt CMMAMIDIControl::aFunc( TInt )
       
    82  *
       
    83  * @param aMIDIControl CMMAMIDIControl pointer.
       
    84  * @param aFunc Pointer to the CMMAMIDIControl method.
       
    85  * @param aData Parameter passed to the aFunc.
       
    86  * @param aReturnValue The return value of the aFunc will
       
    87  *                     be assigned to this parameter.
       
    88  */
       
    89 LOCAL_C void ReturnIntParamIntFuncL(
       
    90     CMMAMIDIControl* aMIDIControl,
       
    91     TInt(CMMAMIDIControl::*aFuncL)(TInt aData),
       
    92     TInt aData,
       
    93     TInt* aReturnValue)
       
    94 {
       
    95     // call TInt CMMAMIDIControl::aFunc( TDesC* aData ) method.
       
    96     *aReturnValue = (aMIDIControl->*aFuncL)(aData);
       
    97 }
       
    98 
       
    99 /**
       
   100  * Implements generated JNI function prototype.
       
   101  */
       
   102 JNIEXPORT jint JNICALL
       
   103 Java_com_nokia_microedition_media_control_MIDIControl__1getChannelVolume
       
   104 (JNIEnv*,
       
   105  jobject,
       
   106  jint aControlHandle,
       
   107  jint aEventSourceHandle,
       
   108  jint aChannel)
       
   109 {
       
   110     // Get pointer to native event source.
       
   111     CMMAEventSource* eventSource =
       
   112         JavaUnhand< CMMAEventSource >(aEventSourceHandle);
       
   113 
       
   114     CMMAMIDIControl* midiControl =
       
   115         JavaUnhand< CMMAMIDIControl >(aControlHandle);
       
   116 
       
   117 
       
   118     TInt returnValue = 0;
       
   119     TInt error;
       
   120 
       
   121     error = eventSource->ExecuteTrap(&ReturnIntParamIntFuncL,
       
   122                                      midiControl,
       
   123                                      &CMMAMIDIControl::ChannelVolumeL,
       
   124                                      aChannel,
       
   125                                      &returnValue);
       
   126 
       
   127     return (error == KErrNone) ? returnValue : error;
       
   128 }
       
   129 
       
   130 /**
       
   131  * Local function which is used to call CMMAMIDIControl class method.
       
   132  * Type of of the function pointer must be
       
   133  * void CMMAMIDIControl::aFunc( TInt, TInt )
       
   134  *
       
   135  * @param aMIDIControl CMMAMIDIControl pointer.
       
   136  * @param aFunc Pointer to the CMMAMIDIControl method.
       
   137  * @param aParam1 Parameter passed to the aFunc.
       
   138  * @param aParam2 Parameter passed to the aFunc.
       
   139  */
       
   140 LOCAL_C void ReturnVoidParamIntIntFuncL(
       
   141     CMMAMIDIControl* aMIDIControl,
       
   142     void (CMMAMIDIControl::*aFuncL)(TInt, TInt),
       
   143     TInt aParam1,
       
   144     TInt aParam2)
       
   145 {
       
   146     // call TInt CMMAMIDIControl::aFunc( TInt, TInt ) method.
       
   147     (aMIDIControl->*aFuncL)(aParam1, aParam2);
       
   148 }
       
   149 
       
   150 /**
       
   151  * Implements generated JNI function prototype.
       
   152  */
       
   153 JNIEXPORT jint JNICALL
       
   154 Java_com_nokia_microedition_media_control_MIDIControl__1setChannelVolume
       
   155 (JNIEnv*,
       
   156  jobject,
       
   157  jint aControlHandle,
       
   158  jint aEventSourceHandle,
       
   159  jint aChannel,
       
   160  jint aVolume)
       
   161 {
       
   162     // Get pointer to native event source.
       
   163     CMMAEventSource* eventSource =
       
   164         JavaUnhand< CMMAEventSource >(aEventSourceHandle);
       
   165 
       
   166     CMMAMIDIControl* midiControl =
       
   167         JavaUnhand< CMMAMIDIControl >(aControlHandle);
       
   168 
       
   169     TInt error = eventSource->ExecuteTrap(&ReturnVoidParamIntIntFuncL,
       
   170                                           midiControl,
       
   171                                           &CMMAMIDIControl::SetChannelVolumeL,
       
   172                                           aChannel,
       
   173                                           aVolume);
       
   174 
       
   175     return error;
       
   176 }
       
   177 
       
   178 /**
       
   179  * Local function which can be used to call CMMAMIDIControl class methods.
       
   180  * Type of of the function pointer must be
       
   181  * TInt CMMAMIDIControl::aFunc( TDesC* aData )
       
   182  *
       
   183  * @param aMIDIControl CMMAMIDIControl pointer.
       
   184  * @param aFunc Pointer to the CMMAMIDIControl method.
       
   185  * @param aData Parameter passed to the aFunc.
       
   186  * @param aReturnValue The return value of the aFunc will
       
   187  *                     be assigned to this parameter.
       
   188  */
       
   189 LOCAL_C void SendMIDIEventFuncL(
       
   190     CMMAMIDIControl* aMIDIControl,
       
   191     TInt(CMMAMIDIControl::*aFuncL)(const TDesC8* aData),
       
   192     const TDesC8* aData,
       
   193     TInt* aReturnValue)
       
   194 {
       
   195     // call TInt CMMAMIDIControl::aFunc( TDesC* aData ) method.
       
   196     *aReturnValue = (aMIDIControl->*aFuncL)(aData);
       
   197 }
       
   198 
       
   199 /**
       
   200  * Implements generated JNI function prototype.
       
   201  */
       
   202 JNIEXPORT jint JNICALL
       
   203 Java_com_nokia_microedition_media_control_MIDIControl__1sendMidiEvent
       
   204 (JNIEnv* aJni,
       
   205  jobject,
       
   206  jint aControlHandle,
       
   207  jint aEventSourceHandle,
       
   208  jbyteArray aData,
       
   209  jint aOffset,
       
   210  jint aLength)
       
   211 {
       
   212     // Get pointer to native event source.
       
   213     CMMAEventSource* eventSource =
       
   214         JavaUnhand< CMMAEventSource >(aEventSourceHandle);
       
   215 
       
   216     CMMAMIDIControl* midiControl =
       
   217         JavaUnhand< CMMAMIDIControl >(aControlHandle);
       
   218 
       
   219     // Get pointer to Java data
       
   220     jbyte* data = aJni->GetByteArrayElements(aData, NULL);
       
   221 
       
   222     // Assert only in debug builds, array size must be checked in Java.
       
   223     __ASSERT_DEBUG(aJni->GetArrayLength(aData) >= aOffset + aLength &&
       
   224                    aOffset >= 0 &&
       
   225                    aLength > 0,
       
   226                    User::Invariant());
       
   227 
       
   228     // Create descriptor from Java data starting from offset
       
   229     jbyte* tempJbyte = &data[ aOffset ];
       
   230     TUint8* tempPtr = (TUint8*) tempJbyte;
       
   231     TPtrC8 dataPtr(tempPtr, aLength);
       
   232 
       
   233     TInt returnValue = 0;
       
   234 
       
   235     TInt err = eventSource->ExecuteTrap(&SendMIDIEventFuncL,
       
   236                                         midiControl,
       
   237                                         &CMMAMIDIControl::SendMIDIEventL,
       
   238                                         (const TDesC8*)(&dataPtr),
       
   239                                         &returnValue);
       
   240 
       
   241     // Java bytes are not needed anymore
       
   242     aJni->ReleaseByteArrayElements(aData, data, 0);
       
   243 
       
   244     if (err != KErrNone)
       
   245     {
       
   246         // return error code to Java
       
   247         returnValue = err;
       
   248     }
       
   249 
       
   250     return returnValue;
       
   251 }
       
   252 
       
   253 JNIEXPORT jint JNICALL
       
   254 Java_com_nokia_microedition_media_control_MIDIControl__1reInitializeMidi
       
   255 (JNIEnv* aJni,
       
   256  jobject,
       
   257  jint aControlHandle,
       
   258  jint aEventSourceHandle,
       
   259  jbyteArray aMidiSequence,
       
   260  jint aOffset,
       
   261  jint aLength)
       
   262 {
       
   263     // Get pointer to native event source.
       
   264     CMMAEventSource* eventSource =
       
   265         JavaUnhand< CMMAEventSource >(aEventSourceHandle);
       
   266 
       
   267     CMMAMIDIControl* midiControl =
       
   268         JavaUnhand< CMMAMIDIControl >(aControlHandle);
       
   269 
       
   270     // Assert only in debug builds, array size must be checked in Java.
       
   271     __ASSERT_DEBUG(aJni->GetArrayLength(aMidiSequence) >= aOffset + aLength &&
       
   272                    aOffset >= 0 &&
       
   273                    aLength > 0,
       
   274                    User::Invariant());
       
   275 
       
   276     // Get pointer to Java data
       
   277     jbyte* data = aJni->GetByteArrayElements(aMidiSequence, NULL);
       
   278 
       
   279     // Create descriptor from Java data starting from offset
       
   280     jbyte* tempJbyte = &data[ aOffset ];
       
   281     TUint8* tempPtr = (TUint8*) tempJbyte;
       
   282     TPtrC8 dataPtr(tempPtr, aLength);
       
   283 
       
   284     // SendMIDIEventFuncL has suitable enough footprint for this call too.
       
   285     // Return value is not used but needs to be there for method footprint.
       
   286 
       
   287     TInt returnValue = 0;
       
   288     TInt err = eventSource->ExecuteTrap(&SendMIDIEventFuncL,
       
   289                                         midiControl,
       
   290                                         &CMMAMIDIControl::ReInitializeMidiL,
       
   291                                         (const TDesC8*)(&dataPtr),
       
   292                                         &returnValue);
       
   293 
       
   294     // Release Java bytes
       
   295     aJni->ReleaseByteArrayElements(aMidiSequence, data, 0);
       
   296     return err;
       
   297 }
       
   298 
       
   299 
       
   300 
       
   301 //  END OF FILE