messagingappbase/smartmessaging/ringbc/inc/RingBCToneConverter.h
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     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:  
       
    15 *       For checking the validity of Smart messaging ringing tone and for 
       
    16 *       ripping the ringing tone title from binary data. 
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 #define _DEBUG_
       
    24 
       
    25 #ifndef __RINGTONECONVERT_H
       
    26 #define __RINGTONECONVERT_H
       
    27 
       
    28 //  INCLUDES
       
    29 #include <e32base.h>
       
    30 #include "NsmRingTone.h"
       
    31 
       
    32 // FORWARD DECLARATIONS
       
    33 NONSHARABLE_STRUCT( TInstruction )
       
    34     {
       
    35     TInt iValue;
       
    36     TInt iDuration;
       
    37     TInt iDurspecifier;
       
    38     TInt iScale;
       
    39     TInt iStyle;
       
    40     };
       
    41 
       
    42 // CONSTANTS
       
    43 
       
    44 NONSHARABLE_STRUCT( TCompData )
       
    45     {
       
    46 	TInt iTempo;
       
    47 	CArrayFix<TInstruction>* iSongData;
       
    48 	TInt iSongLength;
       
    49 	TBuf<KrtSongTitleTextLength> iSongTitle;
       
    50     };
       
    51 
       
    52 //  CLASS DECLARATION 
       
    53 NONSHARABLE_CLASS( CRingBCNSMConverter ) : public CBase
       
    54     {
       
    55     public:     // New functions
       
    56 
       
    57         /**
       
    58         * Creates an instance of CRingBCNSMConverter and returns it.
       
    59         */
       
    60 	    static CRingBCNSMConverter* NewL();
       
    61 
       
    62     protected:
       
    63         /**
       
    64         * Second-phase constructor.
       
    65         */
       
    66         void ConstructL();
       
    67 
       
    68         /**
       
    69         * Default C++ constructor.
       
    70         */
       
    71 	    CRingBCNSMConverter();
       
    72 
       
    73     public:
       
    74         /**
       
    75         * Destructor.
       
    76         */
       
    77 	    ~CRingBCNSMConverter();
       
    78 
       
    79     public:     // New methods
       
    80 
       
    81         /**
       
    82         * Converts a Nokia Smart Messaging stream into TCompData.
       
    83         *
       
    84         * Smart Messaging:	<ringing-tone-programming-language>::=<command>+
       
    85         *					<command>::=
       
    86         *							<command-length><command-part>+ |
       
    87         *							<command-end>
       
    88         *					<command-length>::='binary[00000001..11111111], indicates
       
    89         *							how many command parts there are in the command.'
       
    90         *					<command-end>::='binary[00000000]. This indicates the end 
       
    91         *							of the ringing tone programming language.'
       
    92 
       
    93         * @param aFileData      The NSM stream.
       
    94         * @return               The song.
       
    95         */
       
    96 	    TCompData* ConvertNsmToCompDataL( const TDesC8& aFileData );
       
    97 
       
    98         /**
       
    99         * Sets the title of the song.
       
   100         *
       
   101         * @param aFileName      The new title of the song.
       
   102         * @return               Error code
       
   103         */
       
   104 	    void SetTitle( const TDesC& aFileName );
       
   105 
       
   106 	    /**
       
   107         * Returns a pointer to the title of the ring tone.
       
   108         *
       
   109 	    * Usage: 
       
   110 	    *	1) Create converter(converter = CRingBCNSMConverter::NewL())
       
   111 	    *	2) Call TitleL function to get title pointer(title = converter->TitleL(aFileData))
       
   112 	    *	3) Use title pointer however necessary
       
   113 	    *
       
   114         * @param aFileData          A pointer to the raw file data.
       
   115         * @return                   The title as a HBufC. The ownership is
       
   116         *                           transferred and it is left in cleanup stack.
       
   117 	    *
       
   118         **/
       
   119 	    HBufC* TitleLC(TPtr8& aFileData);
       
   120 
       
   121 	    /**
       
   122         * Check if a NSM stream is a valid ringtone.
       
   123         *
       
   124 	    * Usage: 
       
   125 	    *	1) Create converter(converter = CRingBCNSMConverter::NewL())
       
   126 	    *	2) Call function(booleanValue = converter->IsRingToneMimeTypeL(aFileData))
       
   127         *
       
   128         * @param aFileData		    A pointer to the raw file data.
       
   129         * @return                   ETrue if the tune is a ring tone, EFalse otherwise.
       
   130 	    *
       
   131 	    **/
       
   132         TBool IsRingToneMimeTypeL(TPtr8& aFileData);
       
   133 
       
   134     private:
       
   135 
       
   136 	    struct TNsmRTPatterns
       
   137 	    {
       
   138 		    TInt iStart;
       
   139 		    TInt iEnd;
       
   140 	    };
       
   141     
       
   142         /**
       
   143         * Description:		This function processes Nokia Smart Messaging Ringing Tone
       
   144         *					<command-part> to generate Composer data.
       
   145         *
       
   146         * Smart Messaging:	<command-part>::=
       
   147         *							<ringing-tone-programming> |
       
   148         *							<unicode> |
       
   149         *							<cancel-command><cancel-command-specifier> |
       
   150         *							<sound><sound-command-specifier>
       
   151         *
       
   152         *					If necessary, filler bits are aded to ensure that 
       
   153         *					<command-part> is always octet-aligned.
       
   154         *
       
   155         *					The Ringing Tone programming requires that the order of 
       
   156         *					the command parts is the following: <ringing-tone-
       
   157         *					programming>, [<unicode>,] <sound>.
       
   158         */
       
   159 	    void ProcessNsmRingToneCommandPartL();
       
   160 
       
   161         /**
       
   162         * Description:		This function processes Nokia Smart Messaging Ringing Tone
       
   163         *					<sound-command-specifier> to generate Composer data.
       
   164         *
       
   165         * Smart Messaging:	<sound-command-specifier>::=
       
   166         *							<basic-song-type><basic-song> |
       
   167         *							<temporary-song-type><temporary-song> |
       
   168         *							<midi-song-type><midi-song> |
       
   169         *							<digitized-song-type><digitized-song>
       
   170         */
       
   171 	    void ProcessNsmRingToneSoundSpecL();
       
   172 
       
   173         /**
       
   174         * Description:		This function processes Nokia Smart Messaging Ringing Tone
       
   175         *					<song-title> 
       
   176         *
       
   177         * Smart Messaging:	<song-title>::=<text-length><text>
       
   178         *					<text>::=<default-char>+ |  'Uincode disabled'
       
   179         *							 <ISO-10646-char>+  'Uincode enabled'
       
   180         *					<text-length>::='binary[0000..1111]; Indicating how many
       
   181         *							characters are used for the following text.'	
       
   182         */
       
   183 	    void ProcessNsmRingToneSongTitleL();
       
   184 
       
   185         /**
       
   186         * Description:		This function processes Nokia Smart Messaging Ringing Tone
       
   187         *					<temporary-song> to generate Composer data.
       
   188         *
       
   189         * Smart Messaging:	<temporary-song>::=<song-sequence-length><song-sequence>
       
   190         *					<song-sequence-length>::='binary[00000000..11111111]; 
       
   191         *							Indicates how many song patterns follow
       
   192         *					<song-sequence>::=<song-pattern>+
       
   193         *					<song-pattern>::=
       
   194         *							<pattern-header> |
       
   195         *							<pattern-header><pattern-instruction>+
       
   196         *					<pattern-header>::=
       
   197         *    						<pattern-header-id><pattern-id><loop-value><pattern-specifier>
       
   198         *					<loop-value>::='binary[0000..1111]; Indicates how many
       
   199         *							times the pattern should be repeated. Value zero 
       
   200         *							means no repeat. Value binary 1111 means infinite.
       
   201         *					<pattern-spacifier>::=
       
   202         *							<already-defined-pattern> | <length-of-new-pattern>
       
   203         *					<already-defined-pattern::='binary[00000000]; Indicates that
       
   204         *							an already defined pattern is used again.'
       
   205         *					<length-of-the-new-pattern>::='binary[00000001..11111111];
       
   206         *							Indicates how many pattern instructions there are
       
   207         *							in the song pattern. 
       
   208         */
       
   209 	    void ProcessNsmRingToneSongL();
       
   210 
       
   211         /**
       
   212         * Description:		This function processes Nokia Smart Messaging Ringing Tone
       
   213         *					<pattern-instruction> to generate Composer data.
       
   214         *
       
   215         * Smart Messaging:	<pattern-instruction>::=
       
   216         *							<note-instruction> | <scale-instruction> |
       
   217         *							<style-instruction> | <tempo-instruction> |
       
   218         *							<volume-instruction>
       
   219         *					<scale-intruction>::=<scale-instruction-id><scale-value>
       
   220         *					<style-intruction>::=<style-instruction-id><style-value>
       
   221         *					<tempo-intruction>::=<tempo-instruction-id><tempo-value>
       
   222         *					<volume-intruction>::=<volume-instruction-id><volume-value>
       
   223         */
       
   224 	    void ProcessNsmRingTonePatternInstructionL();
       
   225 
       
   226         /**
       
   227         * Description:		This function forms a composer symbol from the pattern
       
   228         *					instructions and places it into the CompData structure.
       
   229         *
       
   230         * Smart Messaging:	<note-instruction>::=<note-instruction-id><note-value>
       
   231         *							<note-duration><note-duration-specifier>
       
   232         */
       
   233 	    void ProcessNsmRingToneNoteInstructionL(TInt aScale, TInt aStyle);
       
   234 
       
   235         /**
       
   236         * This function extracts the specified number of bits from 
       
   237         * the bit stream(returned int will contain both the instruction
       
   238         * bits and the data bits).
       
   239         *
       
   240         * @param aNumBits   The number of bits to get.
       
   241         * @return           The value.
       
   242         */
       
   243 	    TInt GetBits(TInt aNumBits);
       
   244 
       
   245         /**
       
   246         */
       
   247 	    void ResetForCompData();
       
   248 
       
   249     private:        // Data
       
   250 
       
   251         /// The data being converted from an NSM stream.
       
   252 	    TPtrC8 iReceivedNsmRTData;
       
   253 
       
   254         /// The flags associated with an NSM stream.
       
   255 	    TInt iNsmRTFlags;
       
   256 
       
   257         /// The current position in the stream.
       
   258 	    TInt iNsmPosition;
       
   259 
       
   260         /// The current bit number in the NSM stream.
       
   261 	    TInt iNsmPositionBit;
       
   262 
       
   263         /// Patterns of NSM data.
       
   264 	    TFixedArray<TNsmRTPatterns,4> iNsmRTPatterns;
       
   265 
       
   266         /// The default scale of a tone.
       
   267 	    TInt iScale;
       
   268 
       
   269         /// The default style of a tone.
       
   270 	    TInt iStyle;
       
   271 	    
       
   272         /// The song data created. Owns.
       
   273 	    TCompData iCompData;
       
   274 
       
   275         /// The song data received for conversion. Refs.
       
   276 	    TCompData* iReceivedCompData;
       
   277 
       
   278         /// The position in the song data.
       
   279 	    TInt iCompDataPosition;
       
   280 
       
   281         /// If ETrue, the song data cannot be loaded to Composer.
       
   282         TBool iReadOnly;
       
   283 };
       
   284 #endif