RingToneComposeEngine.c
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:222k
源码类别:

MTK

开发平台:

C/C++

  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2005
  8. *
  9. *  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  10. *  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  11. *  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
  12. *  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  13. *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  14. *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  15. *  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  16. *  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  17. *  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
  18. *  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
  19. *  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
  20. *  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
  21. *
  22. *  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
  23. *  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  24. *  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  25. *  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
  26. *  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
  27. *
  28. *  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
  29. *  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
  30. *  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
  31. *  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
  32. *  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
  33. *
  34. *****************************************************************************/
  35. /*****************************************************************************
  36.  *
  37.  * Filename:
  38.  * ---------
  39.  * RingToneComposeEngine.c
  40.  *
  41.  * Project:
  42.  * --------
  43.  * MAUI
  44.  *
  45.  * Description:
  46.  * ------------
  47.  * This file implements the tone editor screen related functionalities of Ring Tone Composer.
  48.  *
  49.  * Author:
  50.  * -------
  51.  * -------
  52.  *
  53.  *============================================================================
  54.  *             HISTORY
  55.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  56.  *------------------------------------------------------------------------------
  57.  * removed!
  58.  *
  59.  * removed!
  60.  * removed!
  61.  * removed!
  62.  *
  63.  * removed!
  64.  * removed!
  65.  * removed!
  66.  *
  67.  * removed!
  68.  * removed!
  69.  * removed!
  70.  *
  71.  * removed!
  72.  * removed!
  73.  * removed!
  74.  *
  75.  * removed!
  76.  * removed!
  77.  * removed!
  78.  *
  79.  * removed!
  80.  * removed!
  81.  * removed!
  82.  *
  83.  * removed!
  84.  * removed!
  85.  * removed!
  86.  *
  87.  * removed!
  88.  * removed!
  89.  * removed!
  90.  *
  91.  * removed!
  92.  * removed!
  93.  * removed!
  94.  *
  95.  * removed!
  96.  * removed!
  97.  * removed!
  98.  *
  99.  * removed!
  100.  * removed!
  101.  * removed!
  102.  *
  103.  * removed!
  104.  * removed!
  105.  * removed!
  106.  *
  107.  * removed!
  108.  * removed!
  109.  * removed!
  110.  *
  111.  * removed!
  112.  * removed!
  113.  * removed!
  114.  *
  115.  * removed!
  116.  * removed!
  117.  * removed!
  118.  *
  119.  * removed!
  120.  * removed!
  121.  * removed!
  122.  *
  123.  * removed!
  124.  * removed!
  125.  * removed!
  126.  *
  127.  * removed!
  128.  * removed!
  129.  * removed!
  130.  *
  131.  * removed!
  132.  * removed!
  133.  * removed!
  134.  *
  135.  * removed!
  136.  * removed!
  137.  * removed!
  138.  *
  139.  * removed!
  140.  * removed!
  141.  * removed!
  142.  *
  143.  * removed!
  144.  * removed!
  145.  * removed!
  146.  *
  147.  * removed!
  148.  * removed!
  149.  * removed!
  150.  *
  151.  * removed!
  152.  * removed!
  153.  * removed!
  154.  *
  155.  * removed!
  156.  * removed!
  157.  * removed!
  158.  *
  159.  * removed!
  160.  * removed!
  161.  * removed!
  162.  *
  163.  * removed!
  164.  * removed!
  165.  * removed!
  166.  *
  167.  * removed!
  168.  * removed!
  169.  * removed!
  170.  *
  171.  * removed!
  172.  * removed!
  173.  * removed!
  174.  *
  175.  * removed!
  176.  * removed!
  177.  * removed!
  178.  *
  179.  * removed!
  180.  * removed!
  181.  * removed!
  182.  *
  183.  * removed!
  184.  * removed!
  185.  * removed!
  186.  *
  187.  * removed!
  188.  * removed!
  189.  * removed!
  190.  *
  191.  * removed!
  192.  * removed!
  193.  * removed!
  194.  *
  195.  * removed!
  196.  * removed!
  197.  * removed!
  198.  *
  199.  * removed!
  200.  * removed!
  201.  * removed!
  202.  *
  203.  * removed!
  204.  * removed!
  205.  * removed!
  206.  *
  207.  * removed!
  208.  * removed!
  209.  * removed!
  210.  *
  211.  * removed!
  212.  * removed!
  213.  * removed!
  214.  *
  215.  * removed!
  216.  * removed!
  217.  * removed!
  218.  *
  219.  * removed!
  220.  * removed!
  221.  * removed!
  222.  *
  223.  * removed!
  224.  * removed!
  225.  * removed!
  226.  *
  227.  * removed!
  228.  * removed!
  229.  * removed!
  230.  *
  231.  * removed!
  232.  * removed!
  233.  * removed!
  234.  *
  235.  * removed!
  236.  * removed!
  237.  * removed!
  238.  *
  239.  * removed!
  240.  * removed!
  241.  * removed!
  242.  *
  243.  * removed!
  244.  * removed!
  245.  * removed!
  246.  *
  247.  * removed!
  248.  * removed!
  249.  * removed!
  250.  *
  251.  * removed!
  252.  * removed!
  253.  * removed!
  254.  *
  255.  * removed!
  256.  * removed!
  257.  * removed!
  258.  *
  259.  * removed!
  260.  * removed!
  261.  * removed!
  262.  *
  263.  * removed!
  264.  * removed!
  265.  * removed!
  266.  *
  267.  * removed!
  268.  * removed!
  269.  * removed!
  270.  *
  271.  * removed!
  272.  * removed!
  273.  * removed!
  274.  *
  275.  * removed!
  276.  * removed!
  277.  * removed!
  278.  *
  279.  * removed!
  280.  * removed!
  281.  * removed!
  282.  *
  283.  * removed!
  284.  * removed!
  285.  * removed!
  286.  *
  287.  * removed!
  288.  * removed!
  289.  * removed!
  290.  *
  291.  * removed!
  292.  * removed!
  293.  * removed!
  294.  *
  295.  * removed!
  296.  * removed!
  297.  * removed!
  298.  *
  299.  * removed!
  300.  * removed!
  301.  * removed!
  302.  *
  303.  * removed!
  304.  * removed!
  305.  * removed!
  306.  *
  307.  * removed!
  308.  * removed!
  309.  * removed!
  310.  *
  311.  * removed!
  312.  * removed!
  313.  * removed!
  314.  *
  315.  * removed!
  316.  * removed!
  317.  * removed!
  318.  *
  319.  * removed!
  320.  * removed!
  321.  * removed!
  322.  *
  323.  * removed!
  324.  * removed!
  325.  * removed!
  326.  *
  327.  * removed!
  328.  * removed!
  329.  * removed!
  330.  *
  331.  * removed!
  332.  * removed!
  333.  * removed!
  334.  *
  335.  * removed!
  336.  * removed!
  337.  * removed!
  338.  *
  339.  * removed!
  340.  * removed!
  341.  * removed!
  342.  *
  343.  * removed!
  344.  * removed!
  345.  * removed!
  346.  *
  347.  * removed!
  348.  * removed!
  349.  * removed!
  350.  *
  351.  * removed!
  352.  * removed!
  353.  * removed!
  354.  *
  355.  * removed!
  356.  * removed!
  357.  * removed!
  358.  *
  359.  * removed!
  360.  * removed!
  361.  * removed!
  362.  *
  363.  * removed!
  364.  * removed!
  365.  * removed!
  366.  *
  367.  * removed!
  368.  * removed!
  369.  * removed!
  370.  *
  371.  * removed!
  372.  * removed!
  373.  * removed!
  374.  *
  375.  * removed!
  376.  * removed!
  377.  * removed!
  378.  *
  379.  *------------------------------------------------------------------------------
  380.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  381.  *============================================================================
  382.  ****************************************************************************/
  383. /**
  384.  * Copyright Notice
  385.  * ?2002 - 2003, Pixtel Communications, Inc., 1489 43rd Ave. W.,
  386.  * Vancouver, B.C. V6M 4K8 Canada. All Rights Reserved.
  387.  *  (It is illegal to remove this copyright notice from this software or any
  388.  *  portion of it)
  389. **/
  390. /**************************************************************
  391.    FILENAME : RingToneComposerEngine.c
  392.    PURPOSE     : 
  393.    REMARKS     : nil
  394.    AUTHOR      : Vikram
  395.    DATE     : 
  396. **************************************************************/
  397. #include "MMI_features.h"
  398. #if defined(__MMI_RING_COMPOSER__) && defined(__MMI_IMELODY_SUPPORT__)
  399. #include "GlobalConstants.h"
  400. #include "GlobalDefs.h"
  401. #include "gui.h"
  402. #include "HistoryGprot.h"
  403. #include "Unicodexdcl.h"
  404. #include "ComposeRingToneEngineProts.h"
  405. #include "FileSystemDef.h"
  406. #include "wgui_categories.h"
  407. #include "gui_data_types.h"
  408. #include "Asciiprot.h"
  409. #include "ComposeRingToneDefs.h"
  410. #include "TimerEvents.h"
  411. #include "SettingProfile.h"
  412. #include "DownloadDefs.h"
  413. #include "FileSystemGProt.h"
  414. #include "CustDataProts.h"
  415. #include "ComposeRingToneProts.h"
  416. #include "gpioInc.h"
  417. #include "ProfileGprots.h"
  418. #include "mdi_datatype.h"
  419. #include "mdi_audio.h"
  420. #include "FileManagerDef.h"
  421. #include "CommonScreens.h"
  422. #include "KeyBrd.h"
  423. #include "fs_type.h"
  424. #include "FS_Func.h"
  425. #ifdef __MMI_TOUCH_RING_COMPOSER__
  426. #include "PixtelDataTypes.h"
  427. #include "TouchScreenGprot.h"
  428. #include "gui_buttons.h"
  429. #include "wgui_softkeys.h"
  430. #include "ScrMemMgrGprot.h"     /* screen memeory manager */
  431. #endif /* __MMI_TOUCH_RING_COMPOSER__ */ 
  432. #if defined(__MMI_TOUCH_RING_COMPOSER__) || defined(__MMI_MAINLCD_240X320__)
  433. #include "DebugInitDef.h"
  434. #endif 
  435. #ifdef MMI_ON_HARDWARE_P
  436. #ifdef __DRM_SUPPORT__
  437. #include "drm_gprot.h"
  438. #endif 
  439. #endif /* MMI_ON_HARDWARE_P */ 
  440. /* 
  441.  * Define
  442.  */
  443. #define  MULTITAP_TIME           1000
  444.    /* iMelody header/tailer */
  445. #define  MELODY_HEADER           "BEGIN:IMELODYrnVERSION:1.2rnFORMAT:CLASS1.0rn"
  446. #define  MELODY_END              "rnEND:IMELODYrn"
  447.    /* mask for musical note */
  448. #define  NOTE_MASK               0x0000000F     /* symbol of musical note */
  449. #define  CLEAR_NOTE_MASK            0xFFFFFFF0
  450. #define  DURATION_MASK           0x00001E00     /* beat length */
  451. #define  CLEAR_DURATION_MASK        0xFFFFE1FF
  452. #define  CLEAR_NOTETYPE_MASK        0xFFFFFFCF
  453. #define  NOTETYPE_MASK           0x00000030     /* sharp, normal, flat */
  454. #define  OCTAVE_MASK             0x000001C0     /* octave */
  455.    /* UI related */
  456. #ifdef __MMI_TOUCH_RING_COMPOSER__
  457. #define RNGC_X_POS_BASED         25
  458. #define RNGC_X_POS_OFFSET        20
  459. #else /* __MMI_TOUCH_RING_COMPOSER__ */ 
  460. #define RNGC_X_POS_BASED         25
  461. #define RNGC_X_POS_OFFSET        20
  462. #endif /* __MMI_TOUCH_RING_COMPOSER__ */ 
  463. #if defined ( __MMI_MAINLCD_128X128__)
  464. #define  BKG_IMG_Y1              27     /* y-coordinate based of musical notes */
  465. #define  NOTE_BAR_HEIGHT            9   /* the height to display remaining number of notes */
  466. #define  RNGC_NOTE_OFFSET        BKG_IMG_Y1
  467. #define  RNGC_EFFECT_NOTE_OFFSET    (BKG_IMG_Y1+14)
  468. #elif defined (__MMI_MAINLCD_128X160__)
  469. #define  BKG_IMG_Y1           29        /* y-coordinate based of musical notes */
  470. #define  NOTE_BAR_HEIGHT            10  /* the height to display remaining number of notes */
  471. #define  RNGC_NOTE_OFFSET        (BKG_IMG_Y1+8)
  472. #define  RNGC_EFFECT_NOTE_OFFSET       (BKG_IMG_Y1+14+8)
  473. #elif defined( __MMI_MAINLCD_176X220__) /* || defined(__MMI_MAINLCD_240X320__)//041205 Calvin modified */
  474. #ifdef __MMI_TOUCH_RING_COMPOSER__
  475. #define  BKG_IMG_Y1              52
  476. #define  NOTE_BAR_HEIGHT            11  /* the height to display remaining number of notes */
  477. #define  RNGC_NOTE_OFFSET        (BKG_IMG_Y1+6)
  478. #define  RNGC_EFFECT_NOTE_OFFSET     (BKG_IMG_Y1+4+6)
  479. #else /* __MMI_TOUCH_RING_COMPOSER__ */ 
  480. #define  BKG_IMG_Y1              52
  481. #define  NOTE_BAR_HEIGHT            11  /* the height to display remaining number of notes */
  482. #define  RNGC_NOTE_OFFSET        (BKG_IMG_Y1+8)
  483. #define  RNGC_EFFECT_NOTE_OFFSET (BKG_IMG_Y1+14+8)
  484. #endif /* __MMI_TOUCH_RING_COMPOSER__ */ 
  485. /* [~PMT  MANISH   20050614 */
  486. #elif defined(__MMI_MAINLCD_240X320__)
  487. #define  BKG_IMG_Y1              (108)
  488. #define  NOTE_BAR_HEIGHT            (18)        /* the height to display remaining number of notes */
  489. #define  RNGC_NOTE_OFFSET        (BKG_IMG_Y1+13)
  490. #define  RNGC_EFFECT_NOTE_OFFSET     (BKG_IMG_Y1+8+13)
  491. #define   MMI_RNGC_INSTRUMENT_SELECT_HEIGHT (39)
  492. /* ~] */
  493. #else 
  494. #define  BKG_IMG_Y1              27     /* y-coordinate based of musical notes */
  495. #define  NOTE_BAR_HEIGHT            9   /* the height to display remaining number of notes */
  496. #define  RNGC_NOTE_OFFSET        (BKG_IMG_Y1+21)
  497. #define  RNGC_EFFECT_NOTE_OFFSET (BKG_IMG_Y1+14+21)
  498. #endif 
  499. #define  RNGC_MAX_FILE_LEN       2048
  500. #ifdef __MMI_TOUCH_RING_COMPOSER__
  501. #define  RNGC_NOTE_SELECTION_FINAL  0x0001
  502. #define  RNGC_SHOW_SELECTION_AREA   0x0002
  503. #define  RNGC_SELECTION_AREA_REDRAW 0x0004
  504. #define RNGC_PEN_EVENT_UP        0x0008
  505. #endif /* __MMI_TOUCH_RING_COMPOSER__ */ 
  506. /* 
  507.  * Typedef 
  508.  */
  509. /* 
  510.  * Local Variable
  511.  */
  512. MMI_BOOL CurrentNodePlaying = MMI_FALSE;
  513. /* 
  514.  * Local Function
  515.  */
  516. /* 
  517.  * Global Variable
  518.  */
  519. rngc_engine_context_struct *g_rngc_eng_cntx;
  520. #ifdef __MMI_TOUCH_RING_COMPOSER__
  521. touch_rngc_struct touch_rngc_context;
  522. rngc_selection_area_layout_struct const *selection_area_context;
  523. S32 rngc_pen_event_on_object = RNGC_PEN_NONE;
  524. const UI_filled_area touch_rngc_color_key_filler = {UI_FILLED_AREA_TYPE_COLOR | UI_FILLED_AREA_SHADOW,
  525.     UI_NULL_IMAGE,
  526.     NULL,
  527.     {128, 255, 255, 100},
  528.     {0, 0, 0, 0},
  529.     {0, 0, 0, 100},
  530.     {50, 50, 50, 100},
  531.     0
  532. };
  533. #endif /* __MMI_TOUCH_RING_COMPOSER__ */ 
  534. /* MTK Elvis for R2L characters */
  535. extern BOOL r2lMMIFlag;
  536. /* MTk end */
  537. /* 
  538.  * Global Function
  539.  */
  540. const UI_filled_area lightblue_color_dialog_background = {UI_FILLED_AREA_TYPE_COLOR,
  541.     UI_NULL_IMAGE,
  542.     NULL,
  543.     {108, 182, 255, 100},
  544.     {0, 0, 0, 0},
  545.     {0, 0, 0, 100},
  546.     {50, 50, 50, 100},
  547.     0
  548. };
  549. /* [~PMT  MANISH   20050617 */
  550. #ifdef __MMI_MAINLCD_240X320__
  551. const UI_filled_area rngc_instrument_select_background = {UI_FILLED_AREA_TYPE_COLOR,
  552.     UI_NULL_IMAGE,
  553.     NULL,
  554.     {215, 215, 215, 100},
  555.     {0, 0, 0, 0},
  556.     {0, 0, 0, 100},
  557.     {0, 0, 0, 0},
  558.     0
  559. };
  560. #endif /* __MMI_MAINLCD_240X320__ */ 
  561. /* ~] */
  562. #define        SetVibrationOff()    {g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]&=CLEAR_NOTE_MASK;
  563.                                g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]|=NOTE_VIBRATION_OFF;}
  564. #define        SetVibrationOn()     {g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]&=CLEAR_NOTE_MASK;
  565.                               g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]|=NOTE_VIBRATION_ON;}
  566. #define        SetLEDOff()          {g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]&=CLEAR_NOTE_MASK;
  567.                                g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]|=NOTE_LED_OFF;}
  568. #define        SetLEDOn()           {g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]&=CLEAR_NOTE_MASK;
  569.                               g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]|=NOTE_LED_ON;}
  570. #define        SetBackLightOff()    {g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]&=CLEAR_NOTE_MASK;
  571.                                g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]|=NOTE_BACKLIGHT_OFF;}
  572. #define        SetBackLightOn()     {g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]&=CLEAR_NOTE_MASK;
  573.                               g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]|=NOTE_BACKLIGHT_ON;}
  574. #define        SetNoteType(nType)      {g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]&=CLEAR_NOTETYPE_MASK;
  575.                               g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]|=nType;}
  576. #define        SetOctave(nType)     {g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]&=~OCTAVE_MASK;
  577.                               g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]|=nType;}
  578. #define        IncrementNoteBeat()        {                                                                        
  579.                                  S32 nTempVal;                                                                     
  580.                                  nTempVal=g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]&DURATION_MASK;
  581.                                  g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]&=CLEAR_DURATION_MASK;  
  582.                                  if(nTempVal >= DURATION_1BY16)                                                    
  583.                                     g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]|=DURATION_3BY2;     
  584.                                  else                                                                              
  585.                                  {                                                                                 
  586.                                     nTempVal=nTempVal>>9;                                                          
  587.                                     ++nTempVal;                                                                    
  588.                                     nTempVal=nTempVal<<9;                                                          
  589.                                     g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]|=nTempVal;          
  590.                                  }                                                                                 
  591.                                  }
  592. #ifdef __MMI_TOUCH_RING_COMPOSER__
  593. #define     TouchRngcDecrementNoteBeat()  {                                                                        
  594.                                  S32 nTempVal;                                                                     
  595.                                  nTempVal=g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]&DURATION_MASK;
  596.                                  g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]&=CLEAR_DURATION_MASK;  
  597.                                  if(nTempVal <= DURATION_3BY2)                                                     
  598.                                     g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]|=DURATION_1BY16;    
  599.                                  else                                                                              
  600.                                  {                                                                                 
  601.                                     nTempVal=nTempVal>>9;                                                          
  602.                                     --nTempVal;                                                                    
  603.                                     nTempVal=nTempVal<<9;                                                          
  604.                                     g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]|=nTempVal;          
  605.                                  }                                                                                 
  606.                                  }
  607. #endif /* __MMI_TOUCH_RING_COMPOSER__ */ 
  608. #define        IncrementRestBeat()        {                                                                        
  609.                                  S32 nTempVal;                                                                     
  610.                                  nTempVal=g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]&DURATION_MASK;
  611.                                  g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]&=CLEAR_DURATION_MASK;  
  612.                                  if(nTempVal >= DURATION_1BY16)                                                    
  613.                                     g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]|=DURATION_3BY8;     
  614.                                  else                                                                              
  615.                                  {                                                                                 
  616.                                     nTempVal=nTempVal>>9;                                                          
  617.                                     ++nTempVal;                                                                    
  618.                                     nTempVal=nTempVal<<9;                                                          
  619.                                     g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]|=nTempVal;          
  620.                                  }                                                                                 
  621.                                  }
  622. /* vandana UI code */
  623. // declare this struct in the function calling the entry for Composer engine
  624. // Also allocate the memory there only.
  625. /* [~PMT  MANISH   20050614 */
  626. #if defined(__MMI_MAINLCD_176X220__) && defined(__MMI_TOUCH_RING_COMPOSER__)
  627. const U8 gnYCoords[] = 
  628. {
  629.     45 + RNGC_NOTE_OFFSET,
  630.     54 + RNGC_NOTE_OFFSET,
  631.     51 + RNGC_NOTE_OFFSET,
  632.     48 + RNGC_NOTE_OFFSET,
  633.     45 + RNGC_NOTE_OFFSET,
  634.     42 + RNGC_NOTE_OFFSET,
  635.     39 + RNGC_NOTE_OFFSET,
  636.     24 + RNGC_NOTE_OFFSET,
  637.     21 + RNGC_NOTE_OFFSET,
  638.     18 + RNGC_NOTE_OFFSET,
  639.     15 + RNGC_NOTE_OFFSET,
  640.     12 + RNGC_NOTE_OFFSET,
  641.     9 + RNGC_NOTE_OFFSET,
  642.     6 + RNGC_NOTE_OFFSET,
  643.     15 + RNGC_NOTE_OFFSET,
  644.     12 + RNGC_NOTE_OFFSET,
  645.     9 + RNGC_NOTE_OFFSET,
  646.     6 + RNGC_NOTE_OFFSET,
  647.     3 + RNGC_NOTE_OFFSET,
  648.     0 + RNGC_NOTE_OFFSET,
  649.     RNGC_NOTE_OFFSET - 3,
  650.     21 + RNGC_NOTE_OFFSET,
  651.     22 + RNGC_NOTE_OFFSET,
  652.     22 + RNGC_NOTE_OFFSET,
  653.     8 + RNGC_NOTE_OFFSET
  654. };
  655. #elif defined( __MMI_MAINLCD_176X220__) /* || defined(__MMI_MAINLCD_240X320__)//041205 Calvin modified */
  656. const U8 gnYCoords[] = 
  657. {
  658.     59 + RNGC_NOTE_OFFSET,
  659.     68 + RNGC_NOTE_OFFSET,
  660.     65 + RNGC_NOTE_OFFSET,
  661.     62 + RNGC_NOTE_OFFSET,
  662.     59 + RNGC_NOTE_OFFSET,
  663.     56 + RNGC_NOTE_OFFSET,
  664.     53 + RNGC_NOTE_OFFSET,
  665.     38 + RNGC_NOTE_OFFSET,
  666.     35 + RNGC_NOTE_OFFSET,
  667.     32 + RNGC_NOTE_OFFSET,
  668.     29 + RNGC_NOTE_OFFSET,
  669.     26 + RNGC_NOTE_OFFSET,
  670.     23 + RNGC_NOTE_OFFSET,
  671.     20 + RNGC_NOTE_OFFSET,
  672.     29 + RNGC_NOTE_OFFSET,
  673.     26 + RNGC_NOTE_OFFSET,
  674.     23 + RNGC_NOTE_OFFSET,
  675.     20 + RNGC_NOTE_OFFSET,
  676.     17 + RNGC_NOTE_OFFSET,
  677.     14 + RNGC_NOTE_OFFSET,
  678.     11 + RNGC_NOTE_OFFSET,
  679.     21 + RNGC_NOTE_OFFSET,
  680.     22 + RNGC_NOTE_OFFSET,
  681.     22 + RNGC_NOTE_OFFSET,
  682.     8 + RNGC_NOTE_OFFSET
  683. };
  684. #elif defined(__MMI_MAINLCD_240X320__)
  685. const U8 gnYCoords[] = 
  686. {
  687.     49 + RNGC_NOTE_OFFSET,
  688.     59 + RNGC_NOTE_OFFSET,
  689.     56 + RNGC_NOTE_OFFSET,
  690.     53 + RNGC_NOTE_OFFSET,
  691.     50 + RNGC_NOTE_OFFSET,
  692.     47 + RNGC_NOTE_OFFSET,
  693.     44 + RNGC_NOTE_OFFSET,
  694.     29 + RNGC_NOTE_OFFSET,
  695.     26 + RNGC_NOTE_OFFSET,
  696.     23 + RNGC_NOTE_OFFSET,
  697.     20 + RNGC_NOTE_OFFSET,
  698.     17 + RNGC_NOTE_OFFSET,
  699.     14 + RNGC_NOTE_OFFSET,
  700.     11 + RNGC_NOTE_OFFSET,
  701.     20 + RNGC_NOTE_OFFSET,
  702.     17 + RNGC_NOTE_OFFSET,
  703.     14 + RNGC_NOTE_OFFSET,
  704.     11 + RNGC_NOTE_OFFSET,
  705.     8 + RNGC_NOTE_OFFSET,
  706.     5 + RNGC_NOTE_OFFSET,
  707.     2 + RNGC_NOTE_OFFSET,
  708.     21 + RNGC_NOTE_OFFSET,
  709.     22 + RNGC_NOTE_OFFSET,
  710.     22 + RNGC_NOTE_OFFSET,
  711.     8 + RNGC_NOTE_OFFSET
  712. };
  713. /* ~] */
  714. #else 
  715. const U8 gnYCoords[] = 
  716. {
  717.     54 + RNGC_NOTE_OFFSET,
  718.     51 + RNGC_NOTE_OFFSET,
  719.     48 + RNGC_NOTE_OFFSET,
  720.     45 + RNGC_NOTE_OFFSET,
  721.     42 + RNGC_NOTE_OFFSET,
  722.     39 + RNGC_NOTE_OFFSET,
  723.     36 + RNGC_NOTE_OFFSET,
  724.     33 + RNGC_NOTE_OFFSET,
  725.     30 + RNGC_NOTE_OFFSET,
  726.     27 + RNGC_NOTE_OFFSET,
  727.     24 + RNGC_NOTE_OFFSET,
  728.     21 + RNGC_NOTE_OFFSET,
  729.     18 + RNGC_NOTE_OFFSET,
  730.     15 + RNGC_NOTE_OFFSET,
  731.     24 + RNGC_NOTE_OFFSET,
  732.     21 + RNGC_NOTE_OFFSET,
  733.     18 + RNGC_NOTE_OFFSET,
  734.     14 + RNGC_NOTE_OFFSET,
  735.     12 + RNGC_NOTE_OFFSET,
  736.     9 + RNGC_NOTE_OFFSET,
  737.     6 + RNGC_NOTE_OFFSET,
  738.     21 + RNGC_NOTE_OFFSET,
  739.     22 + RNGC_NOTE_OFFSET,
  740.     22 + RNGC_NOTE_OFFSET,
  741.     8 + RNGC_NOTE_OFFSET
  742. };
  743. #endif 
  744. const NoteInfo gNotesList[] = 
  745. {
  746.     {DURATION_3BY2 | OCTAVE_3 | NORMAL, IMG_3BY2_OCT_L_M_N - COMPOSE_RING_TONE_ENGINE_BASE},
  747.     {DURATION_3BY2 | OCTAVE_3 | FLAT, IMG_3BY2_OCT_L_M_F - COMPOSE_RING_TONE_ENGINE_BASE},
  748.     {DURATION_3BY2 | OCTAVE_3 | SHARP, IMG_3BY2_OCT_L_M_S - COMPOSE_RING_TONE_ENGINE_BASE},
  749.     {DURATION_3BY2 | OCTAVE_5 | NORMAL, IMG_3BY2_OCT_U_N - COMPOSE_RING_TONE_ENGINE_BASE},
  750.     {DURATION_3BY2 | OCTAVE_5 | FLAT, IMG_3BY2_OCT_U_F - COMPOSE_RING_TONE_ENGINE_BASE},
  751.     {DURATION_3BY2 | OCTAVE_5 | SHARP, IMG_3BY2_OCT_U_S - COMPOSE_RING_TONE_ENGINE_BASE},
  752.     {DURATION_1 | OCTAVE_3 | NORMAL, IMG_1_OCT_L_M_N - COMPOSE_RING_TONE_ENGINE_BASE},
  753.     {DURATION_1 | OCTAVE_3 | FLAT, IMG_1_OCT_L_M_F - COMPOSE_RING_TONE_ENGINE_BASE},
  754.     {DURATION_1 | OCTAVE_3 | SHARP, IMG_1_OCT_L_M_S - COMPOSE_RING_TONE_ENGINE_BASE},
  755.     {DURATION_1 | OCTAVE_5 | NORMAL, IMG_1_OCT_U_N - COMPOSE_RING_TONE_ENGINE_BASE},
  756.     {DURATION_1 | OCTAVE_5 | FLAT, IMG_1_OCT_U_F - COMPOSE_RING_TONE_ENGINE_BASE},
  757.     {DURATION_1 | OCTAVE_5 | SHARP, IMG_1_OCT_U_S - COMPOSE_RING_TONE_ENGINE_BASE},
  758.     {DURATION_3BY4 | OCTAVE_3 | NORMAL, IMG_3BY4_OCT_L_M_N - COMPOSE_RING_TONE_ENGINE_BASE},
  759.     {DURATION_3BY4 | OCTAVE_3 | FLAT, IMG_3BY4_OCT_L_M_F - COMPOSE_RING_TONE_ENGINE_BASE},
  760.     {DURATION_3BY4 | OCTAVE_3 | SHARP, IMG_3BY4_OCT_L_M_S - COMPOSE_RING_TONE_ENGINE_BASE},
  761.     {DURATION_3BY4 | OCTAVE_5 | NORMAL, IMG_3BY4_OCT_U_N - COMPOSE_RING_TONE_ENGINE_BASE},
  762.     {DURATION_3BY4 | OCTAVE_5 | FLAT, IMG_3BY4_OCT_U_F - COMPOSE_RING_TONE_ENGINE_BASE},
  763.     {DURATION_3BY4 | OCTAVE_5 | SHARP, IMG_3BY4_OCT_U_S - COMPOSE_RING_TONE_ENGINE_BASE},
  764.     {DURATION_1BY2 | OCTAVE_3 | NORMAL, IMG_1BY2_OCT_L_M_N - COMPOSE_RING_TONE_ENGINE_BASE},
  765.     {DURATION_1BY2 | OCTAVE_3 | FLAT, IMG_1BY2_OCT_L_M_F - COMPOSE_RING_TONE_ENGINE_BASE},
  766.     {DURATION_1BY2 | OCTAVE_3 | SHARP, IMG_1BY2_OCT_L_M_S - COMPOSE_RING_TONE_ENGINE_BASE},
  767.     {DURATION_1BY2 | OCTAVE_5 | NORMAL, IMG_1BY2_OCT_U_N - COMPOSE_RING_TONE_ENGINE_BASE},
  768.     {DURATION_1BY2 | OCTAVE_5 | FLAT, IMG_1BY2_OCT_U_F - COMPOSE_RING_TONE_ENGINE_BASE},
  769.     {DURATION_1BY2 | OCTAVE_5 | SHARP, IMG_1BY2_OCT_U_S - COMPOSE_RING_TONE_ENGINE_BASE},
  770.     {DURATION_3BY8 | OCTAVE_3 | NORMAL, IMG_3BY8_OCT_L_M_N - COMPOSE_RING_TONE_ENGINE_BASE},
  771.     {DURATION_3BY8 | OCTAVE_3 | FLAT, IMG_3BY8_OCT_L_M_F - COMPOSE_RING_TONE_ENGINE_BASE},
  772.     {DURATION_3BY8 | OCTAVE_3 | SHARP, IMG_3BY8_OCT_L_M_S - COMPOSE_RING_TONE_ENGINE_BASE},
  773.     {DURATION_3BY8 | OCTAVE_5 | NORMAL, IMG_3BY8_OCT_U_N - COMPOSE_RING_TONE_ENGINE_BASE},
  774.     {DURATION_3BY8 | OCTAVE_5 | FLAT, IMG_3BY8_OCT_U_F - COMPOSE_RING_TONE_ENGINE_BASE},
  775.     {DURATION_3BY8 | OCTAVE_5 | SHARP, IMG_3BY8_OCT_U_S - COMPOSE_RING_TONE_ENGINE_BASE},
  776.     {DURATION_1BY4 | OCTAVE_3 | NORMAL, IMG_1BY4_OCT_L_M_N - COMPOSE_RING_TONE_ENGINE_BASE},
  777.     {DURATION_1BY4 | OCTAVE_3 | FLAT, IMG_1BY4_OCT_L_M_F - COMPOSE_RING_TONE_ENGINE_BASE},
  778.     {DURATION_1BY4 | OCTAVE_3 | SHARP, IMG_1BY4_OCT_L_M_S - COMPOSE_RING_TONE_ENGINE_BASE},
  779.     {DURATION_1BY4 | OCTAVE_5 | NORMAL, IMG_1BY4_OCT_U_N - COMPOSE_RING_TONE_ENGINE_BASE},
  780.     {DURATION_1BY4 | OCTAVE_5 | FLAT, IMG_1BY4_OCT_U_F - COMPOSE_RING_TONE_ENGINE_BASE},
  781.     {DURATION_1BY4 | OCTAVE_5 | SHARP, IMG_1BY4_OCT_U_S - COMPOSE_RING_TONE_ENGINE_BASE},
  782.     {DURATION_3BY16 | OCTAVE_3 | NORMAL, IMG_3BY16_OCT_L_M_N - COMPOSE_RING_TONE_ENGINE_BASE},
  783.     {DURATION_3BY16 | OCTAVE_3 | FLAT, IMG_3BY16_OCT_L_M_F - COMPOSE_RING_TONE_ENGINE_BASE},
  784.     {DURATION_3BY16 | OCTAVE_3 | SHARP, IMG_3BY16_OCT_L_M_S - COMPOSE_RING_TONE_ENGINE_BASE},
  785.     {DURATION_3BY16 | OCTAVE_5 | NORMAL, IMG_3BY16_OCT_U_N - COMPOSE_RING_TONE_ENGINE_BASE},
  786.     {DURATION_3BY16 | OCTAVE_5 | FLAT, IMG_3BY16_OCT_U_F - COMPOSE_RING_TONE_ENGINE_BASE},
  787.     {DURATION_3BY16 | OCTAVE_5 | SHARP, IMG_3BY16_OCT_U_S - COMPOSE_RING_TONE_ENGINE_BASE},
  788.     {DURATION_1BY8 | OCTAVE_3 | NORMAL, IMG_1BY8_OCT_L_M_N - COMPOSE_RING_TONE_ENGINE_BASE},
  789.     {DURATION_1BY8 | OCTAVE_3 | FLAT, IMG_1BY8_OCT_L_M_F - COMPOSE_RING_TONE_ENGINE_BASE},
  790.     {DURATION_1BY8 | OCTAVE_3 | SHARP, IMG_1BY8_OCT_L_M_S - COMPOSE_RING_TONE_ENGINE_BASE},
  791.     {DURATION_1BY8 | OCTAVE_5 | NORMAL, IMG_1BY8_OCT_U_N - COMPOSE_RING_TONE_ENGINE_BASE},
  792.     {DURATION_1BY8 | OCTAVE_5 | FLAT, IMG_1BY8_OCT_U_F - COMPOSE_RING_TONE_ENGINE_BASE},
  793.     {DURATION_1BY8 | OCTAVE_5 | SHARP, IMG_1BY8_OCT_U_S - COMPOSE_RING_TONE_ENGINE_BASE},
  794.     {DURATION_3BY32 | OCTAVE_3 | NORMAL, IMG_3BY32_OCT_L_M_N - COMPOSE_RING_TONE_ENGINE_BASE},
  795.     {DURATION_3BY32 | OCTAVE_3 | FLAT, IMG_3BY32_OCT_L_M_F - COMPOSE_RING_TONE_ENGINE_BASE},
  796.     {DURATION_3BY32 | OCTAVE_3 | SHARP, IMG_3BY32_OCT_L_M_S - COMPOSE_RING_TONE_ENGINE_BASE},
  797.     {DURATION_3BY32 | OCTAVE_5 | NORMAL, IMG_3BY32_OCT_U_N - COMPOSE_RING_TONE_ENGINE_BASE},
  798.     {DURATION_3BY32 | OCTAVE_5 | FLAT, IMG_3BY32_OCT_U_F - COMPOSE_RING_TONE_ENGINE_BASE},
  799.     {DURATION_3BY32 | OCTAVE_5 | SHARP, IMG_3BY32_OCT_U_S - COMPOSE_RING_TONE_ENGINE_BASE},
  800.     {DURATION_1BY16 | OCTAVE_3 | NORMAL, IMG_1BY16_OCT_L_M_N - COMPOSE_RING_TONE_ENGINE_BASE},
  801.     {DURATION_1BY16 | OCTAVE_3 | FLAT, IMG_1BY16_OCT_L_M_F - COMPOSE_RING_TONE_ENGINE_BASE},
  802.     {DURATION_1BY16 | OCTAVE_3 | SHARP, IMG_1BY16_OCT_L_M_S - COMPOSE_RING_TONE_ENGINE_BASE},
  803.     {DURATION_1BY16 | OCTAVE_5 | NORMAL, IMG_1BY16_OCT_U_N - COMPOSE_RING_TONE_ENGINE_BASE},
  804.     {DURATION_1BY16 | OCTAVE_5 | FLAT, IMG_1BY16_OCT_U_F - COMPOSE_RING_TONE_ENGINE_BASE},
  805.     {DURATION_1BY16 | OCTAVE_5 | SHARP, IMG_1BY16_OCT_U_S - COMPOSE_RING_TONE_ENGINE_BASE},
  806. /********************Rest Notes********/
  807.     {DURATION_3BY8 | OCTAVE_3, IMG_3BY8_OCT_L_M - COMPOSE_RING_TONE_ENGINE_BASE},
  808.     {DURATION_1BY4 | OCTAVE_3, IMG_1BY4_OCT_L_M - COMPOSE_RING_TONE_ENGINE_BASE},
  809.     {DURATION_3BY16 | OCTAVE_3, IMG_3BY16_OCT_L_M - COMPOSE_RING_TONE_ENGINE_BASE},
  810.     {DURATION_1BY8 | OCTAVE_3, IMG_1BY8_OCT_L_M - COMPOSE_RING_TONE_ENGINE_BASE},
  811.     {DURATION_3BY32 | OCTAVE_3, IMG_3BY32_OCT_L_M - COMPOSE_RING_TONE_ENGINE_BASE},
  812.     {DURATION_1BY16 | OCTAVE_3, IMG_1BY16_OCT_L_M - COMPOSE_RING_TONE_ENGINE_BASE},
  813. /*********************************Rest Notes End***************/
  814. };
  815. const PS8 gRngcMusicalNote[] = 
  816. {
  817.     "c", "d", "e", "f", "g", "a", "b", "r", "vibeon", "vibeoff", "ledon", "ledoff", "backon", "backoff"
  818. };
  819. const PS8 gRngcDuration[] = 
  820. {
  821.     "0.", "0", "1.", "1", "2.", "2", "3.", "3", "4.", "4"
  822. };
  823. #ifdef __MMI_TOUCH_RING_COMPOSER__
  824. static const rngc_matrix_key_layout_struct normal_toolbar_matrix_layout = 
  825. {
  826.     1, 1,
  827.     2, 7,
  828.     RNGC_NOTE_SELECT_MATRIX_WIDTH, RNGC_NOTE_SELECT_MATRIX_HEIGHT,
  829.     RNGC_MATRIX_KEY_WIDTH, RNGC_MATRIX_KEY_HEIGHT,
  830.     {
  831.      {IMG_TOUCH_RING_UP, TOUCH_IMG_1_OCT_L_M_N, TOUCH_IMG_1BY2_OCT_L_M_N, TOUCH_IMG_1BY4_OCT_L_M_N,
  832.       TOUCH_IMG_1BY8_OCT_L_M_N, TOUCH_IMG_1BY16_OCT_L_M_N, IMG_RING_EVENTVIB_ON},
  833.      {IMG_TOUCH_RING_DOWN, TOUCH_IMG_1BY4_OCT_L_M, TOUCH_IMG_1BY8_OCT_L_M, TOUCH_IMG_1BY16_OCT_L_M, IMG_TOUCH_RNGC_HASH,
  834.       IMG_TOUCH_RING_P, IMG_TOUCH_RING_DOT},
  835.      },
  836.     {
  837.      {GUI_RNGC_OCTAVE_UP, GUI_RNGC_KEY_NOTE1, GUI_RNGC_KEY_NOTE2, GUI_RNGC_KEY_NOTE3, GUI_RNGC_KEY_NOTE4,
  838.       GUI_RNGC_KEY_NOTE5, NOTE_VIBRATION_ON},
  839.      {GUI_RNGC_OCTAVE_DOWN, GUI_RNGC_KEY_NOTE6, GUI_RNGC_KEY_NOTE7, GUI_RNGC_KEY_NOTE8, GUI_RNGC_KEY_SHARP,
  840.       GUI_RNGC_KEY_FLAT, GUI_RNGC_KEY_DOT},
  841.      }
  842. };
  843. #if defined(__MMI_MAINLCD_176X220__)    /* PMT MANISH   20050614 */
  844. static const rngc_custom_key_layout_struct normal_toolbar_custom_layout[] = 
  845. {
  846.     {1, 185, 34, 14, IMG_TOUCH_RING_EDIT, GUI_RNGC_KEY_EDIT},
  847.     {36, 185, 45, 14, IMG_TOUCH_RING_INSERT, GUI_RNGC_KEY_INSERT},
  848.     {82, 185, 45, 14, IMG_TOUCH_RING_PLAY, GUI_RNGC_KEY_PLAY},
  849.     {128, 185, 23, 14, IMG_TOUCH_RING_PREV, GUI_RNGC_KEY_NEXT},
  850.     {152, 185, 23, 14, IMG_TOUCH_RING_NEXT, GUI_RNGC_KEY_PREV}
  851. };
  852. /* [~PMT  MANISH   20050614 */
  853. #elif defined(__MMI_MAINLCD_240X320__)  /* 072505 Calvin modified */
  854. static const rngc_custom_key_layout_struct normal_toolbar_custom_layout[] = 
  855. {
  856.     {1, NORMAL_TOOLBAR_IMAGE_Y + 1, 57, NORMAL_TOOLBAR_HEIGHT - 2, IMG_TOUCH_RING_EDIT, GUI_RNGC_KEY_EDIT},
  857.     {59, NORMAL_TOOLBAR_IMAGE_Y + 1, 52, NORMAL_TOOLBAR_HEIGHT - 2, IMG_TOUCH_RING_INSERT, GUI_RNGC_KEY_INSERT},
  858.     {112, NORMAL_TOOLBAR_IMAGE_Y + 1, 59, NORMAL_TOOLBAR_HEIGHT - 2, IMG_TOUCH_RING_PLAY, GUI_RNGC_KEY_PLAY},
  859.     {172, NORMAL_TOOLBAR_IMAGE_Y + 1, 33, NORMAL_TOOLBAR_HEIGHT - 2, IMG_TOUCH_RING_PREV, GUI_RNGC_KEY_NEXT},
  860.     {206, NORMAL_TOOLBAR_IMAGE_Y + 1, 33, NORMAL_TOOLBAR_HEIGHT - 2, IMG_TOUCH_RING_NEXT, GUI_RNGC_KEY_PREV}
  861. };
  862. #else 
  863. static const rngc_custom_key_layout_struct normal_toolbar_custom_layout[] = 
  864. {
  865.     {1, 185, 34, 14, IMG_TOUCH_RING_EDIT, GUI_RNGC_KEY_EDIT},
  866.     {36, 185, 45, 14, IMG_TOUCH_RING_INSERT, GUI_RNGC_KEY_INSERT},
  867.     {82, 185, 45, 14, IMG_TOUCH_RING_PLAY, GUI_RNGC_KEY_PLAY},
  868.     {128, 185, 23, 14, IMG_TOUCH_RING_PREV, GUI_RNGC_KEY_NEXT},
  869.     {152, 185, 23, 14, IMG_TOUCH_RING_NEXT, GUI_RNGC_KEY_PREV}
  870. };
  871. #endif 
  872. /* ~] */
  873. const static rngc_selection_area_layout_struct normal_toolbar_layout = 
  874. {
  875.     0,
  876.     5,
  877.     NORMAL_TOOLBAR_IMAGE_X,
  878.     NORMAL_TOOLBAR_IMAGE_Y,
  879.     (rngc_matrix_key_layout_struct *) & normal_toolbar_matrix_layout,
  880.     (rngc_custom_key_layout_struct *) normal_toolbar_custom_layout,
  881.     1,
  882.     0,
  883.     IMG_TOUCH_RING_NORMAL
  884. };
  885. const static rngc_matrix_key_layout_struct note_selection_matrix_layout = 
  886. {
  887.     1, 1,
  888.     2, 7,
  889.     RNGC_NOTE_SELECT_MATRIX_WIDTH, RNGC_NOTE_SELECT_MATRIX_HEIGHT,
  890.     RNGC_MATRIX_KEY_WIDTH, RNGC_MATRIX_KEY_HEIGHT,
  891.     {
  892.      {IMG_TOUCH_RING_UP, TOUCH_IMG_1_OCT_L_M_N, TOUCH_IMG_1BY2_OCT_L_M_N, TOUCH_IMG_1BY4_OCT_L_M_N,
  893.       TOUCH_IMG_1BY8_OCT_L_M_N, TOUCH_IMG_1BY16_OCT_L_M_N, IMG_RING_EVENTVIB_ON},
  894.      {IMG_TOUCH_RING_DOWN, TOUCH_IMG_1BY4_OCT_L_M, TOUCH_IMG_1BY8_OCT_L_M, TOUCH_IMG_1BY16_OCT_L_M, IMG_TOUCH_RNGC_HASH,
  895.       IMG_TOUCH_RING_P, IMG_TOUCH_RING_DOT},
  896.      },
  897.     {
  898.      {GUI_RNGC_OCTAVE_UP, GUI_RNGC_KEY_NOTE1, GUI_RNGC_KEY_NOTE2, GUI_RNGC_KEY_NOTE3, GUI_RNGC_KEY_NOTE4,
  899.       GUI_RNGC_KEY_NOTE5, NOTE_VIBRATION_ON},
  900.      {GUI_RNGC_OCTAVE_DOWN, GUI_RNGC_KEY_NOTE6, GUI_RNGC_KEY_NOTE7, GUI_RNGC_KEY_NOTE8, GUI_RNGC_KEY_SHARP,
  901.       GUI_RNGC_KEY_FLAT, GUI_RNGC_KEY_DOT},
  902.      }
  903. };
  904. /* Notice: If you want to change the button size, please remember to modify the memory size defined in ScrMemMgr.h */
  905. #if defined(__MMI_MAINLCD_176X220__)    /* PMT MANISH   20050614 */
  906. static rngc_custom_key_layout_struct note_selection_custom_layout[] = 
  907. {
  908.     {134, 151, 18, 23, IMG_RING_EVENTBL_ON, NOTE_BACKLIGHT_ON},
  909. #ifdef __MMI_RING_COMPOSER_NO_LED__
  910.     {153, 151, 22, 23, 0, NOTE_LED_ON},
  911. #else 
  912.     {153, 151, 22, 23, IMG_RING_EVENTLED_ON, NOTE_LED_ON},
  913. #endif 
  914.     {134, 175, 41, 23, IMG_TOUCH_RING_DOWN, GUI_RNGC_KEY_OK},
  915. };
  916. /* [~PMT  MANISH   20050614 */
  917. #elif defined(__MMI_MAINLCD_240X320__)
  918. static rngc_custom_key_layout_struct note_selection_custom_layout[] = 
  919. {
  920.     {176, NOTE_SELECTION_IMAGE_Y + 1, 24, 31, IMG_RING_EVENTLED_ON, NOTE_LED_ON},
  921.     {201, NOTE_SELECTION_IMAGE_Y + 1, 38, 31, IMG_RING_EVENTBL_ON, NOTE_BACKLIGHT_ON},
  922.     {176, NOTE_SELECTION_IMAGE_Y + 34, 63, 31, IMG_TOUCH_RING_DOWN, GUI_RNGC_KEY_OK},
  923. };
  924. #else 
  925. static rngc_custom_key_layout_struct note_selection_custom_layout[] = 
  926. {
  927.     {134, 152, 18, 23, IMG_RING_EVENTLED_ON, NOTE_LED_ON},
  928.     {153, 152, 22, 23, IMG_RING_EVENTBL_ON, NOTE_BACKLIGHT_ON},
  929.     {134, 176, 41, 23, IMG_TOUCH_RING_DOWN, GUI_RNGC_KEY_OK},
  930. };
  931. #endif 
  932. /* ~] */
  933. static const rngc_selection_area_layout_struct note_selection_layout = 
  934. {
  935.     14,
  936.     3,
  937.     NOTE_SELECTION_IMAGE_X,
  938.     NOTE_SELECTION_IMAGE_Y,
  939.     (rngc_matrix_key_layout_struct *) & note_selection_matrix_layout,
  940.     (rngc_custom_key_layout_struct *) note_selection_custom_layout,
  941.     1,
  942. #ifdef __MMI_MAINLCD_240X320__  /* 072505 Calvin modified */
  943.     2,
  944. #else 
  945.     1,
  946. #endif 
  947.     IMG_TOUCH_RING_SELECTION
  948. };
  949. #endif /* __MMI_TOUCH_RING_COMPOSER__ */ 
  950. /* 110805 ringtonecomposer Calvin Start */
  951. // #if defined(__MMI_TOUCH_RING_COMPOSER__) || defined(__MMI_MAINLCD_240X320__)
  952. /* static const U8 CurrentInstrument[]= */
  953. const U8 CurrentInstrument[] = 
  954. {
  955.     INSTR_PIANO,
  956.     INSTR_GUITAR,
  957.     INSTR_VIOLIN,
  958.     INSTR_SPHONE,
  959.     INSTR_SDRUMS,
  960.     INSTR_FLUTE,
  961.     INSTR_HARMONICA,
  962.     INSTR_TRUMPET,
  963.     INSTR_MUSICBOX,
  964.     INSTR_XYLOPHONE
  965. };
  966. // #endif       /* __MMI_TOUCH_RING_COMPOSER__) || defined(__MMI_MAINLCD_240X320__ */
  967. /* 110805 ringtonecomposer Calvin Start */
  968. #if defined(__MMI_TOUCH_RING_COMPOSER__)
  969. extern void mmi_rngc_finish_insert_editing(void);
  970. #endif 
  971. /*****************************************************************************
  972.  * FUNCTION
  973.  *  EntryRngcComposerEngine
  974.  * DESCRIPTION
  975.  *  Entry function of editor screen in ring tone composer
  976.  * PARAMETERS
  977.  *  void
  978.  * RETURNS
  979.  *  void
  980.  *****************************************************************************/
  981. void EntryRngcComposerEngine(void)
  982. {
  983.     /*----------------------------------------------------------------*/
  984.     /* Local Variables                                                */
  985.     /*----------------------------------------------------------------*/
  986.     U8 *guiBuffer = NULL;
  987.     /*----------------------------------------------------------------*/
  988.     /* Code Body                                                      */
  989.     /*----------------------------------------------------------------*/
  990.     mmi_frm_kbd_set_tone_state(MMI_KEY_TONE_DISABLED);
  991.     /* first time of entering */
  992.     if (g_rngc_eng_cntx == NULL)
  993.     {
  994.         g_rngc_eng_cntx = OslMalloc(sizeof(rngc_engine_context_struct));
  995.         if (g_rngc_eng_cntx == NULL)
  996.         {
  997.             return;
  998.         }
  999.         EntryNewScreen(SCR_COMPOSER_ENGINE, ExitRngcComposerEngine, NULL, NULL);
  1000.         InitializeComposer();
  1001.         SetRingComposer(
  1002.             STR_RING_COMPOSE_TITLE,
  1003.             STR_GLOBAL_OPTIONS,
  1004.             IMG_GLOBAL_OPTIONS,
  1005.             STR_GLOBAL_BACK,
  1006.             IMG_GLOBAL_BACK,
  1007.             g_rngc_cntx.CurrInstr,
  1008.             MAX_NOTES,
  1009.             guiBuffer);
  1010.         g_rngc_eng_cntx->CurrUIPos = 0;
  1011.         redraw_ringcomposer();
  1012.     }
  1013.     else
  1014.     {
  1015.         EntryNewScreen(SCR_COMPOSER_ENGINE, ExitRngcComposerEngine, NULL, NULL);
  1016.         SetRingComposer(
  1017.             STR_RING_COMPOSE_TITLE,
  1018.             STR_GLOBAL_OPTIONS,
  1019.             IMG_GLOBAL_OPTIONS,
  1020.             STR_GLOBAL_BACK,
  1021.             IMG_GLOBAL_BACK,
  1022.             g_rngc_cntx.CurrInstr,
  1023.             (MAX_NOTES - g_rngc_eng_cntx->TotalNotes),
  1024.             guiBuffer);
  1025.         if (g_rngc_eng_cntx->TotalNotes)
  1026.         {
  1027.             RedrawNotes();
  1028.             ChangeRightSoftkey(STR_GLOBAL_CLEAR, IMG_GLOBAL_CLEAR);
  1029.         }
  1030.         else
  1031.         {
  1032.             g_rngc_eng_cntx->CurrUIPos = 0;
  1033.             redraw_ringcomposer();
  1034.         }
  1035.     }
  1036.     mdi_audio_suspend_background_play();
  1037.     SetKeyHandler(HandleKey_0, KEY_0, KEY_EVENT_UP);
  1038.     SetKeyHandler(HandleKey_1, KEY_1, KEY_EVENT_UP);
  1039.     SetKeyHandler(HandleKey_2, KEY_2, KEY_EVENT_UP);
  1040.     SetKeyHandler(HandleKey_3, KEY_3, KEY_EVENT_UP);
  1041.     SetKeyHandler(HandleKey_4, KEY_4, KEY_EVENT_UP);
  1042.     SetKeyHandler(HandleKey_5, KEY_5, KEY_EVENT_UP);
  1043.     SetKeyHandler(HandleKey_6, KEY_6, KEY_EVENT_UP);
  1044.     SetKeyHandler(HandleKey_7, KEY_7, KEY_EVENT_UP);
  1045.     SetKeyHandler(HandleKey_8, KEY_8, KEY_EVENT_UP);
  1046.     SetKeyHandler(HandleKey_9, KEY_9, KEY_EVENT_UP);
  1047.     SetKeyHandler(HandleKey_STAR, KEY_STAR, KEY_EVENT_UP);
  1048.     SetKeyHandler(HandleKey_POUND, KEY_POUND, KEY_EVENT_UP);
  1049.     SetKeyHandler(HandleKey_UP, KEY_UP_ARROW, KEY_EVENT_UP);
  1050.     SetKeyHandler(HandleKey_DOWN, KEY_DOWN_ARROW, KEY_EVENT_UP);
  1051.     SetKeyHandler(HandleKey_LEFT, KEY_LEFT_ARROW, KEY_EVENT_UP);
  1052.     SetKeyHandler(HandleKey_RIGHT, KEY_RIGHT_ARROW, KEY_EVENT_UP);
  1053.     SetKeyHandler(HandleKey_END, KEY_END, KEY_EVENT_DOWN);
  1054.     SetKeyHandler(HandleKey_CLEARLONG, KEY_RSK, KEY_LONG_PRESS);
  1055.     SetRightSoftkeyFunction(RngcComposerRSKUpHandler, KEY_EVENT_UP);
  1056.     SetRightSoftkeyFunction(RngcComposerRSKDownHandler, KEY_EVENT_DOWN);
  1057.     SetLeftSoftkeyFunction(EntryRngcCompToneOptList, KEY_EVENT_UP);
  1058. }
  1059. /*****************************************************************************
  1060.  * FUNCTION
  1061.  *  ExitRngcComposerEngine
  1062.  * DESCRIPTION
  1063.  *  Exit function of editor screen in ring tone composer
  1064.  *  1. Stop playing tone
  1065.  *  2. Reset IsKeyPadAudioDisable;
  1066.  * PARAMETERS
  1067.  *  void
  1068.  * RETURNS
  1069.  *  void
  1070.  *****************************************************************************/
  1071. void ExitRngcComposerEngine(void)
  1072. {
  1073.     /*----------------------------------------------------------------*/
  1074.     /* Local Variables                                                */
  1075.     /*----------------------------------------------------------------*/
  1076.     history ScrComposer;
  1077.     /*----------------------------------------------------------------*/
  1078.     /* Code Body                                                      */
  1079.     /*----------------------------------------------------------------*/
  1080.     /* 072505 Calvin Start */
  1081. #ifdef __MMI_MAINLCD_240X320__
  1082. #ifdef __MMI_UI_LIST_HIGHLIGHT_EFFECTS__
  1083.     gui_unblock_list_effect();
  1084. #endif 
  1085. #endif /* __MMI_MAINLCD_240X320__ */ 
  1086.     /* 072505 Calvin End */
  1087.     StopTimer(NOTE_MULTITAP_TIMER);
  1088.     mdi_audio_stop_string();
  1089.     mdi_audio_resume_background_play();
  1090.     mmi_frm_kbd_set_tone_state(MMI_KEY_TONE_ENABLED);
  1091.     ScrComposer.scrnID = SCR_COMPOSER_ENGINE;
  1092.     ScrComposer.entryFuncPtr = EntryRngcComposerEngine;
  1093.     pfnUnicodeStrcpy((S8*) ScrComposer.inputBuffer, (S8*) L"");
  1094. #ifdef __MMI_TOUCH_RING_COMPOSER__
  1095.     if (selection_area_context == &note_selection_layout)
  1096.     {
  1097.         selection_area_context->custom_keys[2].key_image = IMG_TOUCH_RING_DOWN;
  1098.     }
  1099.     selection_area_context = &normal_toolbar_layout;
  1100.     touch_rngc_context.area_type = GUI_RNGC_NORMAL_TOOLBAR;
  1101. #endif /* __MMI_TOUCH_RING_COMPOSER__ */ 
  1102.     AddHistory(ScrComposer);
  1103.     RedrawCategoryFunction = MMI_dummy_function;
  1104. }
  1105. /*****************************************************************************
  1106.  * FUNCTION
  1107.  *  RngcClearStave
  1108.  * DESCRIPTION
  1109.  *  Clear all notes in stave
  1110.  * PARAMETERS
  1111.  *  void
  1112.  * RETURNS
  1113.  *  void
  1114.  *****************************************************************************/
  1115. void RngcClearStave(void)
  1116. {
  1117.     /*----------------------------------------------------------------*/
  1118.     /* Local Variables                                                */
  1119.     /*----------------------------------------------------------------*/
  1120.     /*----------------------------------------------------------------*/
  1121.     /* Code Body                                                      */
  1122.     /*----------------------------------------------------------------*/
  1123.     g_rngc_eng_cntx->TotalNotes = 0;
  1124.     g_rngc_eng_cntx->CurrNoteIndex = 0;
  1125.     g_rngc_eng_cntx->CurrUIPos = 0;
  1126.     g_rngc_eng_cntx->IsRskLP = 0;
  1127.     memset(g_rngc_eng_cntx->NotesList, 0xFF, sizeof(g_rngc_eng_cntx->NotesList));
  1128. }
  1129. /*****************************************************************************
  1130.  * FUNCTION
  1131.  *  RngcInitCursor
  1132.  * DESCRIPTION
  1133.  *  
  1134.  * PARAMETERS
  1135.  *  void
  1136.  * RETURNS
  1137.  *  void
  1138.  *****************************************************************************/
  1139. void RngcInitCursor(void)
  1140. {
  1141.     /*----------------------------------------------------------------*/
  1142.     /* Local Variables                                                */
  1143.     /*----------------------------------------------------------------*/
  1144.     U16 i;
  1145.     S32 width, height;
  1146.     PU8 img;
  1147.     /*----------------------------------------------------------------*/
  1148.     /* Code Body                                                      */
  1149.     /*----------------------------------------------------------------*/
  1150.     /* get the maximum size of cursor */
  1151.     g_rngc_eng_cntx->CursorWidth = 0;
  1152.     for (i = IMG_3BY2_OCT_L_M_N; i <= IMG_RING_EVENTVIB_OFF; i++)
  1153.     {
  1154.         img = (PU8) GetImage(i);
  1155.         gui_measure_image(img, &width, &height);
  1156.         if (g_rngc_eng_cntx->CursorWidth < width)
  1157.         {
  1158.             g_rngc_eng_cntx->CursorWidth = (U8) width;
  1159.         }
  1160.     }
  1161. }
  1162. /*****************************************************************************
  1163.  * FUNCTION
  1164.  *  InitializeComposer
  1165.  * DESCRIPTION
  1166.  *  This function is to reset state and global variables used in composed engine.
  1167.  * PARAMETERS
  1168.  *  void
  1169.  * RETURNS
  1170.  *  void
  1171.  *****************************************************************************/
  1172. void InitializeComposer(void)
  1173. {
  1174.     /*----------------------------------------------------------------*/
  1175.     /* Local Variables                                                */
  1176.     /*----------------------------------------------------------------*/
  1177.     /*----------------------------------------------------------------*/
  1178.     /* Code Body                                                      */
  1179.     /*----------------------------------------------------------------*/
  1180.     RngcInitCursor();
  1181.     RngcClearStave();
  1182.     g_rngc_cntx.CurrSpeed = NORMAL_SPEED;
  1183.     g_rngc_cntx.CurrInstr = INSTR_PIANO;
  1184. }
  1185. #ifdef __MMI_TOUCH_RING_COMPOSER__
  1186. /*****************************************************************************
  1187.  * FUNCTION
  1188.  *  mmi_touch_rngc_setup
  1189.  * DESCRIPTION
  1190.  *  
  1191.  * PARAMETERS
  1192.  *  touch_rngc_context      [?]     
  1193.  * RETURNS
  1194.  *  void
  1195.  *****************************************************************************/
  1196. void mmi_touch_rngc_setup(touch_rngc_struct *touch_rngc_context)
  1197. {
  1198.     /*----------------------------------------------------------------*/
  1199.     /* Local Variables                                                */
  1200.     /*----------------------------------------------------------------*/
  1201.     /*----------------------------------------------------------------*/
  1202.     /* Code Body                                                      */
  1203.     /*----------------------------------------------------------------*/
  1204.     touch_rngc_context->flag = 0;
  1205.     touch_rngc_context->flag |= RNGC_SELECTION_AREA_REDRAW;
  1206.     touch_rngc_context->mode = GUI_RNGC_VIEW;
  1207.     if (touch_rngc_context->play_mode != RNGC_PAUSE)
  1208.     {
  1209.         selection_area_context = &normal_toolbar_layout;
  1210.         touch_rngc_context->area_type = GUI_RNGC_NORMAL_TOOLBAR;
  1211.     }
  1212.     touch_rngc_context->play_mode = RNGC_PLAY;
  1213. }
  1214. #endif /* __MMI_TOUCH_RING_COMPOSER__ */ 
  1215. /*****************************************************************************
  1216.  * FUNCTION
  1217.  *  HandleKey_CLEARLONG
  1218.  * DESCRIPTION
  1219.  *  Handler of long-pressed RSK.
  1220.  *  1. clear all notes and reset all state varilables.
  1221.  *  2. redraw screen and set RSK to Back
  1222.  * PARAMETERS
  1223.  *  void
  1224.  * RETURNS
  1225.  *  void
  1226.  *****************************************************************************/
  1227. void HandleKey_CLEARLONG(void)
  1228. {
  1229.     /*----------------------------------------------------------------*/
  1230.     /* Local Variables                                                */
  1231.     /*----------------------------------------------------------------*/
  1232.     /*----------------------------------------------------------------*/
  1233.     /* Code Body                                                      */
  1234.     /*----------------------------------------------------------------*/
  1235.     if (g_rngc_eng_cntx->TotalNotes != 0)   /* not cleared yet */
  1236.     {
  1237.         RngcClearStave();
  1238.         g_rngc_eng_cntx->CurrUIPos = 0;
  1239.         RedrawNotes();
  1240.         ChangeRightSoftkey(STR_GLOBAL_BACK, IMG_GLOBAL_BACK);
  1241.         g_rngc_eng_cntx->IsRskLP = 1;
  1242.     }
  1243. }
  1244. /*****************************************************************************
  1245.  * FUNCTION
  1246.  *  FreeMemory
  1247.  * DESCRIPTION
  1248.  *  Free allocated memory to stored composed information
  1249.  * PARAMETERS
  1250.  *  void
  1251.  * RETURNS
  1252.  *  void
  1253.  *****************************************************************************/
  1254. void FreeMemory(void)
  1255. {
  1256.     /*----------------------------------------------------------------*/
  1257.     /* Local Variables                                                */
  1258.     /*----------------------------------------------------------------*/
  1259.     /*----------------------------------------------------------------*/
  1260.     /* Code Body                                                      */
  1261.     /*----------------------------------------------------------------*/
  1262.     if (g_rngc_eng_cntx)
  1263.     {
  1264.         OslMfree(g_rngc_eng_cntx);
  1265.         g_rngc_eng_cntx = NULL;
  1266.     }
  1267. }
  1268. /*****************************************************************************
  1269.  * FUNCTION
  1270.  *  RngcComposerRSKUpHandler
  1271.  * DESCRIPTION
  1272.  *  Event handler of RSK up when composing ring tone
  1273.  *  If there is no musical note and RSK is not long pressed, go back to previous screen
  1274.  *  otherwise, reset state flag.
  1275.  * PARAMETERS
  1276.  *  void
  1277.  * RETURNS
  1278.  *  void
  1279.  *****************************************************************************/
  1280. void RngcComposerRSKUpHandler(void)
  1281. {
  1282.     /*----------------------------------------------------------------*/
  1283.     /* Local Variables                                                */
  1284.     /*----------------------------------------------------------------*/
  1285.     /*----------------------------------------------------------------*/
  1286.     /* Code Body                                                      */
  1287.     /*----------------------------------------------------------------*/
  1288.     if (g_rngc_eng_cntx->TotalNotes == 0 && g_rngc_eng_cntx->IsRskLP == 0)
  1289.     {
  1290.         FreeMemory();
  1291.         StopTimer(NOTE_MULTITAP_TIMER);
  1292.         if (g_rngc_cntx.CurrEditState == ENUM_COMP_ADD)
  1293.         {
  1294.             GoBackToHistory(SCR_FMGR_EXPLORER);
  1295.         }
  1296.         else
  1297.         {
  1298.             GoBackHistory();
  1299.         }
  1300.     }
  1301.     else if (g_rngc_eng_cntx->IsRskLP == 1)
  1302.     {
  1303.         g_rngc_eng_cntx->IsRskLP = 0;
  1304.     }
  1305. #ifdef __MMI_TOUCH_RING_COMPOSER__
  1306.     if (touch_rngc_context.mode == GUI_RNGC_INSERT_EDIT)
  1307.     {
  1308.         touch_rngc_context.mode = GUI_RNGC_INSERT;
  1309.     }
  1310. #endif /* __MMI_TOUCH_RING_COMPOSER__ */ 
  1311. }
  1312. /*****************************************************************************
  1313.  * FUNCTION
  1314.  *  RngcComposerRSKDownHandler
  1315.  * DESCRIPTION
  1316.  *  Event handler of RSK down when composing ring tone
  1317.  *  Delete one musical note.
  1318.  * PARAMETERS
  1319.  *  void
  1320.  * RETURNS
  1321.  *  void
  1322.  *****************************************************************************/
  1323. void RngcComposerRSKDownHandler(void)
  1324. {
  1325.     /*----------------------------------------------------------------*/
  1326.     /* Local Variables                                                */
  1327.     /*----------------------------------------------------------------*/
  1328.     /*----------------------------------------------------------------*/
  1329.     /* Code Body                                                      */
  1330.     /*----------------------------------------------------------------*/
  1331.     if (g_rngc_eng_cntx->TotalNotes)
  1332.     {
  1333.         DeleteCurNote();
  1334.         /* change RSK to "Back" if there is no note */
  1335.         if (!g_rngc_eng_cntx->TotalNotes)
  1336.         {
  1337.             ChangeRightSoftkey(STR_GLOBAL_BACK, IMG_GLOBAL_BACK);
  1338.             g_rngc_eng_cntx->IsRskLP = 1;
  1339.         }
  1340.     }
  1341. }
  1342. /*****************************************************************************
  1343.  * FUNCTION
  1344.  *  DeleteCurNote
  1345.  * DESCRIPTION
  1346.  *  Event handler of RSK down when composing ring tone
  1347.  *  Delete one musical note.
  1348.  * PARAMETERS
  1349.  *  void
  1350.  * RETURNS
  1351.  *  void
  1352.  *****************************************************************************/
  1353. void DeleteCurNote(void)
  1354. {
  1355.     /*----------------------------------------------------------------*/
  1356.     /* Local Variables                                                */
  1357.     /*----------------------------------------------------------------*/
  1358.     /*----------------------------------------------------------------*/
  1359.     /* Code Body                                                      */
  1360.     /*----------------------------------------------------------------*/
  1361.     if (g_rngc_eng_cntx->CurrNoteIndex < g_rngc_eng_cntx->TotalNotes)
  1362.     {
  1363.         /* highlight on the last one */
  1364.         if (g_rngc_eng_cntx->CurrNoteIndex == g_rngc_eng_cntx->TotalNotes - 1)
  1365.         {
  1366.             g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] = 0xFFFF;
  1367.         }
  1368.         else    /* internal note */
  1369.         {
  1370.             memcpy(
  1371.                 (g_rngc_eng_cntx->NotesList + g_rngc_eng_cntx->CurrNoteIndex),
  1372.                 (g_rngc_eng_cntx->NotesList + (g_rngc_eng_cntx->CurrNoteIndex + 1)),
  1373.                 (g_rngc_eng_cntx->TotalNotes - g_rngc_eng_cntx->CurrNoteIndex) * sizeof(U16));
  1374.         }
  1375.         --g_rngc_eng_cntx->TotalNotes;
  1376.     }
  1377.     else if (g_rngc_eng_cntx->CurrNoteIndex == g_rngc_eng_cntx->TotalNotes)
  1378.     {
  1379.     #ifdef __MMI_TOUCH_RING_COMPOSER__
  1380.         g_rngc_eng_cntx->NotesList[--g_rngc_eng_cntx->CurrNoteIndex] = 0;
  1381.     #else 
  1382.         g_rngc_eng_cntx->NotesList[--g_rngc_eng_cntx->CurrNoteIndex] = 0xFFFF;
  1383.     #endif 
  1384.         --g_rngc_eng_cntx->TotalNotes;
  1385.         if (g_rngc_eng_cntx->TotalNotes < g_rngc_eng_cntx->CurrUIPos)
  1386.         {
  1387.             --g_rngc_eng_cntx->CurrUIPos;
  1388.         }
  1389.     }
  1390.     GDI_LOCK;
  1391.     RedrawNotes();
  1392. #ifdef __MMI_TOUCH_RING_COMPOSER__
  1393.     if (touch_rngc_context.mode == GUI_RNGC_INSERT_EDIT || touch_rngc_context.mode == GUI_RNGC_INSERT)
  1394.     {
  1395.         mmi_rngc_finish_insert_editing();
  1396.     }
  1397. #endif /* __MMI_TOUCH_RING_COMPOSER__ */ 
  1398.     GDI_UNLOCK;
  1399. }
  1400. /*****************************************************************************
  1401.  * FUNCTION
  1402.  *  RngcPlayCurrentNodeCallBack
  1403.  * DESCRIPTION
  1404.  *  
  1405.  * PARAMETERS
  1406.  *  result      [IN]        
  1407.  * RETURNS
  1408.  *  void
  1409.  *****************************************************************************/
  1410. void RngcPlayCurrentNodeCallBack(mdi_result result)
  1411. {
  1412.     /*----------------------------------------------------------------*/
  1413.     /* Local Variables                                                */
  1414.     /*----------------------------------------------------------------*/
  1415.     /*----------------------------------------------------------------*/
  1416.     /* Code Body                                                      */
  1417.     /*----------------------------------------------------------------*/
  1418.     CurrentNodePlaying = MMI_FALSE;
  1419. }
  1420. /*****************************************************************************
  1421.  * FUNCTION
  1422.  *  PlayCurrentNode
  1423.  * DESCRIPTION
  1424.  *  Play iMelody stream of current input note
  1425.  * PARAMETERS
  1426.  *  void
  1427.  * RETURNS
  1428.  *  void
  1429.  *****************************************************************************/
  1430. void PlayCurrentNode(void)
  1431. {
  1432.     /*----------------------------------------------------------------*/
  1433.     /* Local Variables                                                */
  1434.     /*----------------------------------------------------------------*/
  1435.     static U8 pCurrentNode[512];    /* because audio interface does not make a copy, we have to prepare a buffer */
  1436.     U8 pNoteString[10];
  1437.     U8 *temp;
  1438.     /*----------------------------------------------------------------*/
  1439.     /* Code Body                                                      */
  1440.     /*----------------------------------------------------------------*/
  1441. #ifdef __MMI_SILENT_MEETING_PROFILE__
  1442.     if (IsMeetingModeActivated() || IsSilentModeActivated())
  1443.         if ((g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] & NOTE_MASK) < NOTE_REST)
  1444.         {
  1445.             return;
  1446.         }
  1447. #endif /* __MMI_SILENT_MEETING_PROFILE__ */ 
  1448.     memset(pNoteString, 0, 10);
  1449.     temp = GetStringForNode(pNoteString, g_rngc_eng_cntx->CurrNoteIndex);
  1450.     *temp = 0;
  1451.     /* generate iMelody string */
  1452.     sprintf(
  1453.         (S8*) pCurrentNode,
  1454.         "%sCOMPOSER:MTK(%d)rnBEAT:%drnMELODY:",
  1455.         MELODY_HEADER,
  1456.         g_rngc_cntx.CurrInstr,
  1457.         g_rngc_cntx.CurrSpeed);
  1458.     strcat((S8*) & pCurrentNode, (S8*) pNoteString);
  1459.     strcat((S8*) pCurrentNode, (S8*) MELODY_END);
  1460.     if (mdi_audio_play_string
  1461.         ((void*)pCurrentNode, strlen((S8*) pCurrentNode), MDI_FORMAT_IMELODY, DEVICE_AUDIO_PLAY_ONCE, NULL,
  1462.          RngcPlayCurrentNodeCallBack) == MDI_AUDIO_SUCCESS)
  1463.     {
  1464.         CurrentNodePlaying = MMI_TRUE;
  1465.     }
  1466. }
  1467. /*****************************************************************************
  1468.  * FUNCTION
  1469.  *  InsertNote
  1470.  * DESCRIPTION
  1471.  *  Insert a note to screen accroding to current position
  1472.  * PARAMETERS
  1473.  *  nNote       [IN]        Musical note symbol
  1474.  * RETURNS
  1475.  *  void
  1476.  *****************************************************************************/
  1477. void InsertNote(U16 nNote)
  1478. {
  1479.     /*----------------------------------------------------------------*/
  1480.     /* Local Variables                                                */
  1481.     /*----------------------------------------------------------------*/
  1482.     U16 nCount;
  1483.     /*----------------------------------------------------------------*/
  1484.     /* Code Body                                                      */
  1485.     /*----------------------------------------------------------------*/
  1486.     StopTimer(NOTE_MULTITAP_TIMER);
  1487.     if (g_rngc_eng_cntx->TotalNotes >= MAX_NOTES)
  1488.     {
  1489.         return;
  1490.     }
  1491.     /* internal note */
  1492.     if (g_rngc_eng_cntx->CurrNoteIndex < g_rngc_eng_cntx->TotalNotes)
  1493.     {
  1494.         /* shift one note right */
  1495.         for (nCount = g_rngc_eng_cntx->TotalNotes; nCount > g_rngc_eng_cntx->CurrNoteIndex; --nCount)
  1496.         {
  1497.             g_rngc_eng_cntx->NotesList[nCount] = g_rngc_eng_cntx->NotesList[nCount - 1];
  1498.         }
  1499.         /* insert note */
  1500.         ++g_rngc_eng_cntx->CurrNoteIndex;
  1501.         g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] = nNote;
  1502.         /* increase total number of notes */
  1503.         ++g_rngc_eng_cntx->TotalNotes;
  1504.         if (g_rngc_eng_cntx->CurrUIPos < NUM_NOTES_IN_STAVE - 1)
  1505.         {
  1506.             ++g_rngc_eng_cntx->CurrUIPos;
  1507.         }
  1508.         PlayCurrentNode();
  1509.         RedrawNotes();
  1510.     }
  1511.     else    /* last note */
  1512.     {
  1513.         /* insert note */
  1514.         g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] = nNote;
  1515.         /* increase total number of notes */
  1516.         ++g_rngc_eng_cntx->TotalNotes;
  1517.         if (g_rngc_eng_cntx->TotalNotes == 1)
  1518.         {
  1519.             change_right_softkey(STR_GLOBAL_CLEAR, IMG_GLOBAL_CLEAR);
  1520.         }
  1521.         PlayCurrentNode();
  1522.         ShowNote(g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]);
  1523.     }
  1524. #if !defined (__MMI_TOUCH_RING_COMPOSER__)
  1525.     /* auto shift cursor if a note is insert at the end */
  1526.     if (g_rngc_eng_cntx->CurrNoteIndex == g_rngc_eng_cntx->TotalNotes - 1 ||
  1527.         g_rngc_eng_cntx->CurrNoteIndex == g_rngc_eng_cntx->TotalNotes)
  1528.     {
  1529.         StartTimer(NOTE_MULTITAP_TIMER, MULTITAP_TIME, (FuncPtr) HandleKey_RIGHT);
  1530.     }
  1531. #endif /* !defined (__MMI_TOUCH_RING_COMPOSER__) */ 
  1532. }
  1533. /*****************************************************************************
  1534.  * FUNCTION
  1535.  *  RedrawNotes
  1536.  * DESCRIPTION
  1537.  *  This function is to redraw the stave
  1538.  * PARAMETERS
  1539.  *  void
  1540.  * RETURNS
  1541.  *  void
  1542.  *****************************************************************************/
  1543. void RedrawNotes(void)
  1544. {
  1545.     /*----------------------------------------------------------------*/
  1546.     /* Local Variables                                                */
  1547.     /*----------------------------------------------------------------*/
  1548.     S16 nFirstNoteIndex;
  1549.     S16 nEndNote;
  1550.     U16 nTemp;
  1551.     U16 nImageId = 0;
  1552.     U16 nCount = 0;
  1553.     U8 nYVal = 0;
  1554.     DisplayInfo sDisplayInfo[NUM_NOTES_IN_STAVE];
  1555.     /*----------------------------------------------------------------*/
  1556.     /* Code Body                                                      */
  1557.     /*----------------------------------------------------------------*/
  1558.     /* get the first note to be drawed */
  1559.     nFirstNoteIndex = g_rngc_eng_cntx->CurrNoteIndex - g_rngc_eng_cntx->CurrUIPos;
  1560.     if (nFirstNoteIndex < 0)
  1561.     {
  1562.         nFirstNoteIndex = 0;
  1563.     }
  1564.     /* get the last note to be drawed */
  1565.     if (nFirstNoteIndex + NUM_NOTES_IN_STAVE >= g_rngc_eng_cntx->TotalNotes)    /* tail */
  1566.     {
  1567.         nEndNote = g_rngc_eng_cntx->TotalNotes - 1;
  1568.     }
  1569.     else
  1570.     {
  1571.         nEndNote = (nFirstNoteIndex + NUM_NOTES_IN_STAVE) - 1;
  1572.     }
  1573.     for (nTemp = nFirstNoteIndex; nTemp <= nEndNote; ++nTemp)
  1574.     {
  1575.         GetIndexInList(g_rngc_eng_cntx->NotesList[nTemp], &nImageId, &nYVal);
  1576.         sDisplayInfo[nCount].nImageId = nImageId;
  1577.         sDisplayInfo[nCount].nXPos = (U8) nTemp;
  1578.         sDisplayInfo[nCount].nYPos = nYVal;
  1579.         ++nCount;
  1580.     }
  1581.     RefreshNotesList(nCount, (DisplayInfo*) sDisplayInfo);
  1582. }
  1583. /*****************************************************************************
  1584.  * FUNCTION
  1585.  *  HandleKey_0
  1586.  * DESCRIPTION
  1587.  *  Key event handler of number keys
  1588.  *  Insert corresponding musical note to stave
  1589.  * PARAMETERS
  1590.  *  void
  1591.  * RETURNS
  1592.  *  void
  1593.  *****************************************************************************/
  1594. void HandleKey_0(void)
  1595. {
  1596. #ifdef __MMI_TOUCH_RING_COMPOSER__
  1597.     /*----------------------------------------------------------------*/
  1598.     /* Local Variables                                                */
  1599.     /*----------------------------------------------------------------*/
  1600.     /*----------------------------------------------------------------*/
  1601.     /* Code Body                                                      */
  1602.     /*----------------------------------------------------------------*/
  1603.     if (touch_rngc_context.mode == GUI_RNGC_INSERT_EDIT)
  1604.     {
  1605.         mmi_rngc_finish_insert_editing();
  1606.     }
  1607. #endif /* __MMI_TOUCH_RING_COMPOSER__ */ 
  1608.     InsertNote(NOTE_REST | DURATION_1BY4 | OCTAVE_4);
  1609. }
  1610. /*****************************************************************************
  1611.  * FUNCTION
  1612.  *  HandleKey_1
  1613.  * DESCRIPTION
  1614.  *  
  1615.  * PARAMETERS
  1616.  *  void
  1617.  * RETURNS
  1618.  *  void
  1619.  *****************************************************************************/
  1620. void HandleKey_1(void)
  1621. {
  1622. #ifdef __MMI_TOUCH_RING_COMPOSER__
  1623.     /*----------------------------------------------------------------*/
  1624.     /* Local Variables                                                */
  1625.     /*----------------------------------------------------------------*/
  1626.     /*----------------------------------------------------------------*/
  1627.     /* Code Body                                                      */
  1628.     /*----------------------------------------------------------------*/
  1629.     if (touch_rngc_context.mode == GUI_RNGC_INSERT_EDIT)
  1630.     {
  1631.         mmi_rngc_finish_insert_editing();
  1632.     }
  1633. #endif /* __MMI_TOUCH_RING_COMPOSER__ */ 
  1634.     InsertNote(NOTE_C | DURATION_1BY4 | OCTAVE_4 | NORMAL);
  1635. }
  1636. /*****************************************************************************
  1637.  * FUNCTION
  1638.  *  HandleKey_2
  1639.  * DESCRIPTION
  1640.  *  
  1641.  * PARAMETERS
  1642.  *  void
  1643.  * RETURNS
  1644.  *  void
  1645.  *****************************************************************************/
  1646. void HandleKey_2(void)
  1647. {
  1648. #ifdef __MMI_TOUCH_RING_COMPOSER__
  1649.     /*----------------------------------------------------------------*/
  1650.     /* Local Variables                                                */
  1651.     /*----------------------------------------------------------------*/
  1652.     /*----------------------------------------------------------------*/
  1653.     /* Code Body                                                      */
  1654.     /*----------------------------------------------------------------*/
  1655.     if (touch_rngc_context.mode == GUI_RNGC_INSERT_EDIT)
  1656.     {
  1657.         mmi_rngc_finish_insert_editing();
  1658.     }
  1659. #endif /* __MMI_TOUCH_RING_COMPOSER__ */ 
  1660.     InsertNote(NOTE_D | DURATION_1BY4 | OCTAVE_4 | NORMAL);
  1661. }
  1662. /*****************************************************************************
  1663.  * FUNCTION
  1664.  *  HandleKey_3
  1665.  * DESCRIPTION
  1666.  *  
  1667.  * PARAMETERS
  1668.  *  void
  1669.  * RETURNS
  1670.  *  void
  1671.  *****************************************************************************/
  1672. void HandleKey_3(void)
  1673. {
  1674. #ifdef __MMI_TOUCH_RING_COMPOSER__
  1675.     /*----------------------------------------------------------------*/
  1676.     /* Local Variables                                                */
  1677.     /*----------------------------------------------------------------*/
  1678.     /*----------------------------------------------------------------*/
  1679.     /* Code Body                                                      */
  1680.     /*----------------------------------------------------------------*/
  1681.     if (touch_rngc_context.mode == GUI_RNGC_INSERT_EDIT)
  1682.     {
  1683.         mmi_rngc_finish_insert_editing();
  1684.     }
  1685. #endif /* __MMI_TOUCH_RING_COMPOSER__ */ 
  1686.     InsertNote(NOTE_E | DURATION_1BY4 | OCTAVE_4 | NORMAL);
  1687. }
  1688. /*****************************************************************************
  1689.  * FUNCTION
  1690.  *  HandleKey_4
  1691.  * DESCRIPTION
  1692.  *  
  1693.  * PARAMETERS
  1694.  *  void
  1695.  * RETURNS
  1696.  *  void
  1697.  *****************************************************************************/
  1698. void HandleKey_4(void)
  1699. {
  1700. #ifdef __MMI_TOUCH_RING_COMPOSER__
  1701.     /*----------------------------------------------------------------*/
  1702.     /* Local Variables                                                */
  1703.     /*----------------------------------------------------------------*/
  1704.     /*----------------------------------------------------------------*/
  1705.     /* Code Body                                                      */
  1706.     /*----------------------------------------------------------------*/
  1707.     if (touch_rngc_context.mode == GUI_RNGC_INSERT_EDIT)
  1708.     {
  1709.         mmi_rngc_finish_insert_editing();
  1710.     }
  1711. #endif /* __MMI_TOUCH_RING_COMPOSER__ */ 
  1712.     InsertNote(NOTE_F | DURATION_1BY4 | OCTAVE_4 | NORMAL);
  1713. }
  1714. /*****************************************************************************
  1715.  * FUNCTION
  1716.  *  HandleKey_5
  1717.  * DESCRIPTION
  1718.  *  
  1719.  * PARAMETERS
  1720.  *  void
  1721.  * RETURNS
  1722.  *  void
  1723.  *****************************************************************************/
  1724. void HandleKey_5(void)
  1725. {
  1726. #ifdef __MMI_TOUCH_RING_COMPOSER__
  1727.     /*----------------------------------------------------------------*/
  1728.     /* Local Variables                                                */
  1729.     /*----------------------------------------------------------------*/
  1730.     /*----------------------------------------------------------------*/
  1731.     /* Code Body                                                      */
  1732.     /*----------------------------------------------------------------*/
  1733.     if (touch_rngc_context.mode == GUI_RNGC_INSERT_EDIT)
  1734.     {
  1735.         mmi_rngc_finish_insert_editing();
  1736.     }
  1737. #endif /* __MMI_TOUCH_RING_COMPOSER__ */ 
  1738.     InsertNote(NOTE_G | DURATION_1BY4 | OCTAVE_4 | NORMAL);
  1739. }
  1740. /*****************************************************************************
  1741.  * FUNCTION
  1742.  *  HandleKey_6
  1743.  * DESCRIPTION
  1744.  *  
  1745.  * PARAMETERS
  1746.  *  void
  1747.  * RETURNS
  1748.  *  void
  1749.  *****************************************************************************/
  1750. void HandleKey_6(void)
  1751. {
  1752. #ifdef __MMI_TOUCH_RING_COMPOSER__
  1753.     /*----------------------------------------------------------------*/
  1754.     /* Local Variables                                                */
  1755.     /*----------------------------------------------------------------*/
  1756.     /*----------------------------------------------------------------*/
  1757.     /* Code Body                                                      */
  1758.     /*----------------------------------------------------------------*/
  1759.     if (touch_rngc_context.mode == GUI_RNGC_INSERT_EDIT)
  1760.     {
  1761.         mmi_rngc_finish_insert_editing();
  1762.     }
  1763. #endif /* __MMI_TOUCH_RING_COMPOSER__ */ 
  1764.     InsertNote(NOTE_A | DURATION_1BY4 | OCTAVE_4 | NORMAL);
  1765. }
  1766. /*****************************************************************************
  1767.  * FUNCTION
  1768.  *  HandleKey_7
  1769.  * DESCRIPTION
  1770.  *  
  1771.  * PARAMETERS
  1772.  *  void
  1773.  * RETURNS
  1774.  *  void
  1775.  *****************************************************************************/
  1776. void HandleKey_7(void)
  1777. {
  1778. #ifdef __MMI_TOUCH_RING_COMPOSER__
  1779.     /*----------------------------------------------------------------*/
  1780.     /* Local Variables                                                */
  1781.     /*----------------------------------------------------------------*/
  1782.     /*----------------------------------------------------------------*/
  1783.     /* Code Body                                                      */
  1784.     /*----------------------------------------------------------------*/
  1785.     if (touch_rngc_context.mode == GUI_RNGC_INSERT_EDIT)
  1786.     {
  1787.         mmi_rngc_finish_insert_editing();
  1788.     }
  1789. #endif /* __MMI_TOUCH_RING_COMPOSER__ */ 
  1790.     InsertNote(NOTE_B | DURATION_1BY4 | OCTAVE_4 | NORMAL);
  1791. }
  1792. /*****************************************************************************
  1793.  * FUNCTION
  1794.  *  HandleKey_8
  1795.  * DESCRIPTION
  1796.  *  
  1797.  * PARAMETERS
  1798.  *  void
  1799.  * RETURNS
  1800.  *  void
  1801.  *****************************************************************************/
  1802. void HandleKey_8(void)
  1803. {
  1804. #ifndef __MMI_RING_COMPOSER_NO_VIB__
  1805.     /*----------------------------------------------------------------*/
  1806.     /* Local Variables                                                */
  1807.     /*----------------------------------------------------------------*/
  1808.     /*----------------------------------------------------------------*/
  1809.     /* Code Body                                                      */
  1810.     /*----------------------------------------------------------------*/
  1811. #ifdef __MMI_TOUCH_RING_COMPOSER__
  1812.     if (touch_rngc_context.mode == GUI_RNGC_INSERT_EDIT)
  1813.     {
  1814.         mmi_rngc_finish_insert_editing();
  1815.     }
  1816. #endif /* __MMI_TOUCH_RING_COMPOSER__ */ 
  1817.     InsertNote(NOTE_VIBRATION_ON);
  1818. #endif /* __MMI_RING_COMPOSER_NO_VIB__ */ 
  1819. }
  1820. /*****************************************************************************
  1821.  * FUNCTION
  1822.  *  HandleKey_9
  1823.  * DESCRIPTION
  1824.  *  
  1825.  * PARAMETERS
  1826.  *  void
  1827.  * RETURNS
  1828.  *  void
  1829.  *****************************************************************************/
  1830. void HandleKey_9(void)
  1831. {
  1832. #ifdef __MMI_TOUCH_RING_COMPOSER__
  1833.     /*----------------------------------------------------------------*/
  1834.     /* Local Variables                                                */
  1835.     /*----------------------------------------------------------------*/
  1836.     /*----------------------------------------------------------------*/
  1837.     /* Code Body                                                      */
  1838.     /*----------------------------------------------------------------*/
  1839.     if (touch_rngc_context.mode == GUI_RNGC_INSERT_EDIT)
  1840.     {
  1841.         mmi_rngc_finish_insert_editing();
  1842.     }
  1843. #endif /* __MMI_TOUCH_RING_COMPOSER__ */ 
  1844. #ifdef __MMI_RING_COMPOSER_NO_LED__
  1845.     InsertNote(NOTE_BACKLIGHT_ON);
  1846. #else 
  1847.     InsertNote(NOTE_LED_ON);
  1848. #endif 
  1849. }
  1850. /*****************************************************************************
  1851.  * FUNCTION
  1852.  *  HandleKey_END
  1853.  * DESCRIPTION
  1854.  *  
  1855.  * PARAMETERS
  1856.  *  void
  1857.  * RETURNS
  1858.  *  void
  1859.  *****************************************************************************/
  1860. void HandleKey_END(void)
  1861. {
  1862.     /*----------------------------------------------------------------*/
  1863.     /* Local Variables                                                */
  1864.     /*----------------------------------------------------------------*/
  1865.     /*----------------------------------------------------------------*/
  1866.     /* Code Body                                                      */
  1867.     /*----------------------------------------------------------------*/
  1868.     FreeMemory();
  1869.     StopTimer(NOTE_MULTITAP_TIMER);
  1870.     DisplayIdleScreen();
  1871. }
  1872. /*****************************************************************************
  1873.  * FUNCTION
  1874.  *  HandleKey_STAR
  1875.  * DESCRIPTION
  1876.  *  Start key handler
  1877.  *  Change note duration/type according to highlighted note.
  1878.  * PARAMETERS
  1879.  *  void
  1880.  * RETURNS
  1881.  *  void
  1882.  *****************************************************************************/
  1883. void HandleKey_STAR(void)
  1884. {
  1885.     /*----------------------------------------------------------------*/
  1886.     /* Local Variables                                                */
  1887.     /*----------------------------------------------------------------*/
  1888.     U32 nValue;
  1889.     /*----------------------------------------------------------------*/
  1890.     /* Code Body                                                      */
  1891.     /*----------------------------------------------------------------*/
  1892.     if (g_rngc_eng_cntx->TotalNotes > MAX_NOTES)
  1893.     {
  1894.         return;
  1895.     }
  1896.     /* highlighted on empty position */
  1897.     if (g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] == 0xFFFF)
  1898.     {
  1899.         return;
  1900.     }
  1901.     StopTimer(NOTE_MULTITAP_TIMER);
  1902.     nValue = g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] & NOTE_MASK;
  1903.     switch (nValue)
  1904.     {
  1905.     #ifndef __MMI_RING_COMPOSER_NO_LED__
  1906.         case NOTE_LED_ON:
  1907.             SetBackLightOn()break;
  1908.         case NOTE_LED_OFF:
  1909.             SetBackLightOff()break;
  1910.         case NOTE_BACKLIGHT_ON:
  1911.             SetLEDOn()break;
  1912.         case NOTE_BACKLIGHT_OFF:
  1913.             SetLEDOff()break;
  1914.     #endif /* __MMI_RING_COMPOSER_NO_LED__ */ 
  1915.         case NOTE_C:
  1916.         case NOTE_D:
  1917.         case NOTE_E:
  1918.         case NOTE_F:
  1919.         case NOTE_G:
  1920.         case NOTE_A:
  1921.         case NOTE_B:
  1922.             IncrementNoteBeat()break;
  1923.         case NOTE_REST:
  1924.             IncrementRestBeat()break;
  1925.         default:
  1926. #if 0            
  1927. /* under construction !*/
  1928. #else
  1929.             return; /* vib/led/backlight, return. */
  1930. #endif
  1931.     }
  1932.     PlayCurrentNode();
  1933.     ShowNote(g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]);
  1934.     if (g_rngc_eng_cntx->CurrNoteIndex == g_rngc_eng_cntx->TotalNotes - 1)
  1935.     {
  1936.         StartTimer(NOTE_MULTITAP_TIMER, MULTITAP_TIME, (FuncPtr) HandleKey_RIGHT);
  1937.     }
  1938. }
  1939. /*****************************************************************************
  1940.  * FUNCTION
  1941.  *  HandleKey_POUND
  1942.  * DESCRIPTION
  1943.  *  Pound key handler
  1944.  *  change flag/sharp/normal state of a musical note
  1945.  * PARAMETERS
  1946.  *  void
  1947.  * RETURNS
  1948.  *  void
  1949.  *****************************************************************************/
  1950. void HandleKey_POUND(void)
  1951. {
  1952.     /*----------------------------------------------------------------*/
  1953.     /* Local Variables                                                */
  1954.     /*----------------------------------------------------------------*/
  1955.     U32 nValue;
  1956.     U32 nNoteType;
  1957.     /*----------------------------------------------------------------*/
  1958.     /* Code Body                                                      */
  1959.     /*----------------------------------------------------------------*/
  1960.     if (g_rngc_eng_cntx->TotalNotes > MAX_NOTES)
  1961.     {
  1962.         return;
  1963.     }
  1964.     if (g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] == 0xFFFF)
  1965.     {
  1966.         return;
  1967.     }
  1968.     StopTimer(NOTE_MULTITAP_TIMER);
  1969.     nValue = g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] & NOTE_MASK;
  1970.     nNoteType = g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] & NOTETYPE_MASK;
  1971.     switch (nValue)
  1972.     {
  1973.         case NOTE_C:
  1974.         case NOTE_F:
  1975.             if (nNoteType == NORMAL)
  1976.                 SetNoteType(SHARP)
  1977.                 else
  1978.                 SetNoteType(NORMAL) break;
  1979.         case NOTE_D:
  1980.         case NOTE_G:
  1981.         case NOTE_A:
  1982.             if (nNoteType == NORMAL)
  1983.                 SetNoteType(FLAT)
  1984.                 else
  1985.             if (nNoteType == FLAT)
  1986.                 SetNoteType(SHARP)
  1987.                 else
  1988.                 SetNoteType(NORMAL) break;
  1989.         case NOTE_B:
  1990.         case NOTE_E:
  1991.             if (nNoteType == NORMAL)
  1992.                 SetNoteType(FLAT)
  1993.                 else
  1994.                 SetNoteType(NORMAL) break;
  1995.         default:    /* other notes, pound key does not effect */
  1996. #if 0
  1997. /* under construction !*/
  1998. #else   
  1999.             return; /* vib/led/backlight, return. */
  2000. #endif
  2001.     }
  2002.     PlayCurrentNode();
  2003.     ShowNote(g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]);
  2004.     if (g_rngc_eng_cntx->CurrNoteIndex == g_rngc_eng_cntx->TotalNotes - 1)
  2005.     {
  2006.         StartTimer(NOTE_MULTITAP_TIMER, MULTITAP_TIME, (FuncPtr) HandleKey_RIGHT);
  2007.     }
  2008. }
  2009. /*****************************************************************************
  2010.  * FUNCTION
  2011.  *  HandleKey_UP
  2012.  * DESCRIPTION
  2013.  *  Up key handler
  2014.  *  Change on/off for vibration/backlight/led notes
  2015.  *  Change octave for musical notes
  2016.  * PARAMETERS
  2017.  *  void
  2018.  * RETURNS
  2019.  *  void
  2020.  *****************************************************************************/
  2021. void HandleKey_UP(void)
  2022. {
  2023.     /*----------------------------------------------------------------*/
  2024.     /* Local Variables                                                */
  2025.     /*----------------------------------------------------------------*/
  2026.     U32 nNoteOctave;
  2027.     U32 nValue;
  2028.     /*----------------------------------------------------------------*/
  2029.     /* Code Body                                                      */
  2030.     /*----------------------------------------------------------------*/
  2031.     if (g_rngc_eng_cntx->TotalNotes > MAX_NOTES)
  2032.     {
  2033.         return;
  2034.     }
  2035.     if (g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] == 0xFFFF)
  2036.     {
  2037.         return;
  2038.     }
  2039.     StopTimer(NOTE_MULTITAP_TIMER);
  2040.     nValue = g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] & NOTE_MASK;
  2041.     nNoteOctave = g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] & OCTAVE_MASK;
  2042.     switch (nValue)
  2043.     {
  2044.         case NOTE_LED_OFF:
  2045.             SetLEDOn();
  2046.             break;
  2047.         case NOTE_BACKLIGHT_OFF:
  2048.             SetBackLightOn();
  2049.             break;
  2050.         case NOTE_VIBRATION_OFF:
  2051.             SetVibrationOn();
  2052.             break;
  2053.         case NOTE_REST:
  2054.             break;
  2055.         case NOTE_C:
  2056.         case NOTE_D:
  2057.         case NOTE_E:
  2058.         case NOTE_F:
  2059.         case NOTE_G:
  2060.         case NOTE_A:
  2061.         case NOTE_B:
  2062.             if (nNoteOctave == OCTAVE_3)
  2063.                 SetOctave(OCTAVE_4)
  2064.                 else
  2065.             if (nNoteOctave == OCTAVE_4)
  2066.                 SetOctave(OCTAVE_5)
  2067.                 else
  2068.             if (nNoteOctave == OCTAVE_5)
  2069.                 SetOctave(OCTAVE_3) break;
  2070.     }
  2071.     PlayCurrentNode();
  2072.     ShowNote(g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]);
  2073.     /* after pressing up key should not move the cursor */
  2074. #ifndef __MMI_TOUCH_RING_COMPOSER__
  2075.     if (g_rngc_eng_cntx->CurrNoteIndex == g_rngc_eng_cntx->TotalNotes - 1)
  2076.     {
  2077.         StartTimer(NOTE_MULTITAP_TIMER, MULTITAP_TIME, (FuncPtr) HandleKey_RIGHT);
  2078.     }
  2079. #endif /* __MMI_TOUCH_RING_COMPOSER__ */ 
  2080. }
  2081. /*****************************************************************************
  2082.  * FUNCTION
  2083.  *  HandleKey_DOWN
  2084.  * DESCRIPTION
  2085.  *  Up key handler
  2086.  *  Change on/off for vibration/backlight/led notes
  2087.  *  Change octave for musical notes
  2088.  * PARAMETERS
  2089.  *  void
  2090.  * RETURNS
  2091.  *  void
  2092.  *****************************************************************************/
  2093. void HandleKey_DOWN(void)
  2094. {
  2095.     /*----------------------------------------------------------------*/
  2096.     /* Local Variables                                                */
  2097.     /*----------------------------------------------------------------*/
  2098.     U32 nNoteOctave;
  2099.     U32 nValue;
  2100.     /*----------------------------------------------------------------*/
  2101.     /* Code Body                                                      */
  2102.     /*----------------------------------------------------------------*/
  2103.     if (g_rngc_eng_cntx->TotalNotes > MAX_NOTES)
  2104.     {
  2105.         return;
  2106.     }
  2107.     if (g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] == 0xFFFF)
  2108.     {
  2109.         return;
  2110.     }
  2111.     StopTimer(NOTE_MULTITAP_TIMER);
  2112.     nValue = g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] & NOTE_MASK;
  2113.     nNoteOctave = g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] & OCTAVE_MASK;
  2114.     switch (nValue)
  2115.     {
  2116.         case NOTE_LED_ON:
  2117.             SetLEDOff();
  2118.             break;
  2119.         case NOTE_BACKLIGHT_ON:
  2120.             SetBackLightOff();
  2121.             break;
  2122.         case NOTE_VIBRATION_ON:
  2123.             SetVibrationOff();
  2124.             break;
  2125.         case NOTE_REST:
  2126.             break;
  2127.         case NOTE_C:
  2128.         case NOTE_D:
  2129.         case NOTE_E:
  2130.         case NOTE_F:
  2131.         case NOTE_G:
  2132.         case NOTE_A:
  2133.         case NOTE_B:
  2134.         {
  2135.             if (nNoteOctave == OCTAVE_3)
  2136.                 SetOctave(OCTAVE_5)
  2137.                 else
  2138.             if (nNoteOctave == OCTAVE_4)
  2139.                 SetOctave(OCTAVE_3)
  2140.                 else
  2141.             if (nNoteOctave == OCTAVE_5)
  2142.                 SetOctave(OCTAVE_4) break;
  2143.         }
  2144.         default:
  2145.             break;
  2146.     }
  2147.     PlayCurrentNode();
  2148.     ShowNote(g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]);
  2149.     /* after pressing down key should not move the cursor */
  2150. #ifndef __MMI_TOUCH_RING_COMPOSER__
  2151.     if (g_rngc_eng_cntx->CurrNoteIndex == g_rngc_eng_cntx->TotalNotes - 1)
  2152.     {
  2153.         StartTimer(NOTE_MULTITAP_TIMER, MULTITAP_TIME, (FuncPtr) HandleKey_RIGHT);
  2154.     }
  2155. #endif /* __MMI_TOUCH_RING_COMPOSER__ */ 
  2156. }
  2157. /*****************************************************************************
  2158.  * FUNCTION
  2159.  *  HandleKey_LEFT
  2160.  * DESCRIPTION
  2161.  *  Left key handler
  2162.  *  Move cursor left
  2163.  * PARAMETERS
  2164.  *  void
  2165.  * RETURNS
  2166.  *  void
  2167.  *****************************************************************************/
  2168. void HandleKey_LEFT(void)
  2169. {
  2170.     /*----------------------------------------------------------------*/
  2171.     /* Local Variables                                                */
  2172.     /*----------------------------------------------------------------*/
  2173.     DisplayInfo sDisplayInfo[NUM_NOTES_IN_STAVE];
  2174.     U16 nTemp;
  2175.     U16 nEnd;
  2176.     U16 nImageId = 0;
  2177.     U8 nYVal = 0;
  2178.     /*----------------------------------------------------------------*/
  2179.     /* Code Body                                                      */
  2180.     /*----------------------------------------------------------------*/
  2181.     StopTimer(NOTE_MULTITAP_TIMER);
  2182.     if (g_rngc_eng_cntx->CurrNoteIndex > 0)
  2183.     {
  2184.         --g_rngc_eng_cntx->CurrNoteIndex;
  2185.         if (g_rngc_eng_cntx->CurrUIPos == 0)
  2186.         {
  2187.             nTemp = g_rngc_eng_cntx->TotalNotes - g_rngc_eng_cntx->CurrNoteIndex;
  2188.             if (nTemp >= NUM_NOTES_IN_STAVE)
  2189.             {
  2190.                 nEnd = NUM_NOTES_IN_STAVE;
  2191.             }
  2192.             else
  2193.             {
  2194.                 nEnd = nTemp;
  2195.             }
  2196.             for (nTemp = 0; nTemp < nEnd; ++nTemp)
  2197.             {
  2198.                 GetIndexInList(g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex + nTemp], &nImageId, &nYVal);
  2199.                 sDisplayInfo[nTemp].nImageId = nImageId;
  2200.                 sDisplayInfo[nTemp].nXPos = (U8) nTemp;
  2201.                 sDisplayInfo[nTemp].nYPos = nYVal;
  2202.             }
  2203.             RefreshNotesList(nEnd, (DisplayInfo*) & sDisplayInfo);
  2204.         }
  2205.         else
  2206.         {
  2207.             --g_rngc_eng_cntx->CurrUIPos;
  2208.             redraw_ringcomposer();
  2209.         }
  2210.     #ifdef __MMI_TOUCH_RING_COMPOSER__
  2211.         if ( /* touch_rngc_context.mode == GUI_RNGC_EDIT || */ touch_rngc_context.mode == GUI_RNGC_INSERT_EDIT ||
  2212.             touch_rngc_context.mode == GUI_RNGC_INSERT)
  2213.         {
  2214.             mmi_rngc_finish_insert_editing();
  2215.         }
  2216.     #endif /* __MMI_TOUCH_RING_COMPOSER__ */ 
  2217.     }
  2218. }
  2219. /*****************************************************************************
  2220.  * FUNCTION
  2221.  *  HandleKey_RIGHT
  2222.  * DESCRIPTION
  2223.  *  Right key handler
  2224.  *  Move cursor right
  2225.  * PARAMETERS
  2226.  *  void
  2227.  * RETURNS
  2228.  *  void
  2229.  *****************************************************************************/
  2230. void HandleKey_RIGHT(void)
  2231. {
  2232.     /*----------------------------------------------------------------*/
  2233.     /* Local Variables                                                */
  2234.     /*----------------------------------------------------------------*/
  2235.     /*----------------------------------------------------------------*/
  2236.     /* Code Body                                                      */
  2237.     /*----------------------------------------------------------------*/
  2238.     /* already in right boundary */
  2239.     if (g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] == 0xFFFF)
  2240.     {
  2241.         return;
  2242.     }
  2243.     StopTimer(NOTE_MULTITAP_TIMER);
  2244.     if (g_rngc_eng_cntx->CurrNoteIndex < (g_rngc_eng_cntx->TotalNotes))
  2245.     {
  2246.         ++g_rngc_eng_cntx->CurrNoteIndex;
  2247.         if (g_rngc_eng_cntx->CurrUIPos == NUM_NOTES_IN_STAVE - 1)
  2248.         {
  2249.             /* handle the right movement */
  2250.             RedrawNotes();
  2251.         }
  2252.         else
  2253.         {
  2254.             ++g_rngc_eng_cntx->CurrUIPos;
  2255.             redraw_ringcomposer();
  2256.         }
  2257.     }
  2258. #ifdef __MMI_TOUCH_RING_COMPOSER__
  2259.     if ( /* touch_rngc_context.mode == GUI_RNGC_EDIT || */ touch_rngc_context.mode == GUI_RNGC_INSERT_EDIT ||
  2260.         touch_rngc_context.mode == GUI_RNGC_INSERT)
  2261.     {
  2262.         mmi_rngc_finish_insert_editing();
  2263.     }
  2264.     if ((touch_rngc_context.mode == GUI_RNGC_EDIT)
  2265.         && (g_rngc_eng_cntx->CurrNoteIndex >= g_rngc_eng_cntx->TotalNotes))
  2266.     {
  2267.         touch_rngc_context.area_type = GUI_RNGC_NORMAL_TOOLBAR;
  2268.         selection_area_context = &normal_toolbar_layout;
  2269.         touch_rngc_context.mode = GUI_RNGC_VIEW;
  2270.         touch_rngc_context.play_mode = RNGC_PLAY;
  2271.         touch_rngc_context.flag |= RNGC_SELECTION_AREA_REDRAW;
  2272.         redraw_ringcomposer();
  2273.     }    
  2274. #endif /* __MMI_TOUCH_RING_COMPOSER__ */ 
  2275. }
  2276. /*****************************************************************************
  2277.  * FUNCTION
  2278.  *  GenerateMelodyFile
  2279.  * DESCRIPTION
  2280.  *  Generate and write iMelody file to file system
  2281.  * PARAMETERS
  2282.  *  pFileName       [IN]        Filename
  2283.  * RETURNS
  2284.  *  enum value of result
  2285.  *****************************************************************************/
  2286. S32 GenerateMelodyFile(PS8 pFileName)
  2287. {
  2288.     /*----------------------------------------------------------------*/
  2289.     /* Local Variables                                                */
  2290.     /*----------------------------------------------------------------*/
  2291.     S8 *pMelody = NULL;
  2292.     S32 err = 0;
  2293.     U16 nSize = 0;
  2294.     U32 wByte = 0;
  2295.     S8 tmpBuff[100];
  2296.     S8 FileNameBuff[FMGR_MAX_PATH_LEN * ENCODING_LENGTH];
  2297.     FILE_HANDLE fileHandle;
  2298.     /*----------------------------------------------------------------*/
  2299.     /* Code Body                                                      */
  2300.     /*----------------------------------------------------------------*/
  2301.     /* generate filename */
  2302.     GenerateCompleteComposeFileName((PS8) pFileName, (PS8) FileNameBuff);
  2303. #ifdef MMI_ON_HARDWARE_P
  2304.     if ((err = RngcCreateDir()) != FS_NO_ERROR)
  2305.     {
  2306.         return err;
  2307.     }
  2308. #else /* MMI_ON_HARDWARE_P */ 
  2309.     if ((err = RngcCreateDir()) != 0)
  2310.     {
  2311.         return err;
  2312.     }
  2313. #endif /* MMI_ON_HARDWARE_P */ 
  2314.     fileHandle = FS_Open((U16*) FileNameBuff, FS_READ_WRITE | FS_CREATE_ALWAYS);
  2315.     if (!pfOpenError(fileHandle))
  2316.     {
  2317.         /* write header */
  2318.         err = FS_Write(fileHandle, MELODY_HEADER, AsciiStrlen((const S8*)MELODY_HEADER), &wByte);
  2319.         if (err == 0)
  2320.         {
  2321.             sprintf(
  2322.                 (PS8) tmpBuff,
  2323.                 "COMPOSER:MTK(%d)rnBEAT:%drnMELODY:",
  2324.                 g_rngc_cntx.CurrInstr,
  2325.                 g_rngc_cntx.CurrSpeed);
  2326.             FS_Write(fileHandle, tmpBuff, AsciiStrlen((const S8*)tmpBuff), &wByte);
  2327.         }
  2328.         /* generate iMelody string */
  2329.         if (err == 0)
  2330.         {
  2331.             pMelody = OslMalloc(g_rngc_eng_cntx->TotalNotes * 7);
  2332.             nSize = GetMelodyFromStruct((PU8) pMelody, (U16) (g_rngc_eng_cntx->TotalNotes * 7));
  2333.             err = FS_Write(fileHandle, pMelody, nSize, &wByte);
  2334.             OslMfree(pMelody);
  2335.         }
  2336.         /* write tail */
  2337.         if (err == 0)
  2338.         {
  2339.             err = FS_Write(fileHandle, MELODY_END, AsciiStrlen((const S8*)MELODY_END), &wByte);
  2340.         }
  2341.         FS_Close(fileHandle);
  2342.         if (err < 0)
  2343.         {
  2344.             FS_Delete((U16*) FileNameBuff);
  2345.         }
  2346.     }
  2347.     else
  2348.     {
  2349.         err = (S32) fileHandle;
  2350.     }
  2351.     return err;
  2352. }
  2353. /*****************************************************************************
  2354.  * FUNCTION
  2355.  *  GenerateCompleteComposeFileName
  2356.  * DESCRIPTION
  2357.  *  Generate complete file path+name
  2358.  * PARAMETERS
  2359.  *  pFileName           [IN]            Filename
  2360.  *  pCompletePath       [IN/OUT]        Comple filename+path
  2361.  * RETURNS
  2362.  *  void
  2363.  *****************************************************************************/
  2364. void GenerateCompleteComposeFileName(PS8 pFileName, PS8 pCompletePath)
  2365. {
  2366.     /*----------------------------------------------------------------*/
  2367.     /* Local Variables                                                */
  2368.     /*----------------------------------------------------------------*/
  2369.     /*----------------------------------------------------------------*/
  2370.     /* Code Body                                                      */
  2371.     /*----------------------------------------------------------------*/
  2372.     pfnUnicodeStrcpy((S8*) pCompletePath, (S8*) RINGCOMPOSER_PATH);
  2373.     pfnUnicodeStrcat((S8*) pCompletePath, (S8*) pFileName);
  2374. }
  2375. /*****************************************************************************
  2376.  * FUNCTION
  2377.  *  EditMelody
  2378.  * DESCRIPTION
  2379.  *  Read an iMelody file and convert to the structure used in program
  2380.  *  Display ring tone composer stave
  2381.  * PARAMETERS
  2382.  *  pFileName       [IN]        Filename
  2383.  * RETURNS
  2384.  *  void
  2385.  *****************************************************************************/
  2386. void EditMelody(U8 *pFileName)
  2387. {
  2388.     /*----------------------------------------------------------------*/
  2389.     /* Local Variables                                                */
  2390.     /*----------------------------------------------------------------*/
  2391.     S8 *pMelody = NULL;
  2392.     FILE_HANDLE fileHandle;
  2393.     S32 nFileSize;
  2394.     U32 nEror = 0;
  2395.     S8 FilleNameBuff[MAX_IMAGE_NAME_PATH_WIDTH + RNGC_FILE_LEN];        /* padding for filepath */
  2396. #ifdef MMI_ON_HARDWARE_P
  2397. #ifdef __DRM_SUPPORT__
  2398.     DRM_RIGHTS_STRUCT *rights;
  2399. #endif 
  2400. #endif /* MMI_ON_HARDWARE_P */ 
  2401.     /*----------------------------------------------------------------*/
  2402.     /* Code Body                                                      */
  2403.     /*----------------------------------------------------------------*/
  2404.     GenerateCompleteComposeFileName((PS8) pFileName, (PS8) FilleNameBuff);
  2405. #ifdef MMI_ON_HARDWARE_P
  2406. #ifdef __DRM_SUPPORT__
  2407.     fileHandle = DRM_open_file((PU16) FilleNameBuff, FS_READ_ONLY, DRM_PERMISSION_NONE);
  2408.     if (fileHandle > FS_NO_ERROR)
  2409.     {
  2410.         rights = DRM_get_rights(fileHandle);
  2411.         DRM_close_file(fileHandle);
  2412.         if (rights != NULL)
  2413.         {
  2414.             DisplayPopup(
  2415.                 (U8*) GetString(STR_GLOBAL_DRM_PROHIBITED),
  2416.                 IMG_GLOBAL_UNFINISHED,
  2417.                 0,
  2418.                 UI_POPUP_NOTIFYDURATION_TIME,
  2419.                 ERROR_TONE);
  2420.             return;
  2421.         }
  2422.     }
  2423. #endif /* __DRM_SUPPORT__ */ 
  2424. #endif /* MMI_ON_HARDWARE_P */ 
  2425.     fileHandle = FS_Open((U16*) FilleNameBuff, FS_READ_ONLY);
  2426.     if (!pfOpenError(fileHandle))
  2427.     {
  2428.         nFileSize = GetFSFileSize(fileHandle);
  2429.         if (nFileSize > RNGC_MAX_FILE_LEN)
  2430.         {
  2431.             DisplayPopup(
  2432.                 (U8*) GetString(STR_GLOBAL_UNSUPPORTED_FORMAT),
  2433.                 IMG_GLOBAL_WARNING,
  2434.                 0,
  2435.                 UI_POPUP_NOTIFYDURATION_TIME,
  2436.                 ERROR_TONE);
  2437.             FS_Close(fileHandle);
  2438.             return;
  2439.         }
  2440.         pMelody = OslMalloc(nFileSize + 1);
  2441.         if (g_rngc_eng_cntx == NULL)
  2442.         {
  2443.             g_rngc_eng_cntx = OslMalloc(sizeof(rngc_engine_context_struct));
  2444.         }
  2445.         pfread(pMelody, 1, nFileSize, fileHandle, &nEror);
  2446.         pMelody[nFileSize] = 0;
  2447.         FS_Close(fileHandle);
  2448.         g_rngc_eng_cntx->TotalNotes = 0;
  2449.         g_rngc_eng_cntx->CurrNoteIndex = 0;
  2450.         g_rngc_eng_cntx->CurrUIPos = 0;
  2451.         g_rngc_eng_cntx->IsRskLP = 0;
  2452.         RngcInitCursor();
  2453.         memset(g_rngc_eng_cntx->NotesList, 0, sizeof(g_rngc_eng_cntx->NotesList));
  2454.         g_rngc_cntx.CurrInstr = INSTR_FLUTE;    /* to sync with media task */
  2455.         if (GetComposerStructFromMelody((PU8) pMelody))
  2456.         {
  2457.             memset(
  2458.                 (void*)(g_rngc_eng_cntx->NotesList + g_rngc_eng_cntx->TotalNotes),
  2459.                 0xFF,
  2460.                 sizeof(g_rngc_eng_cntx->NotesList) - (sizeof(U16) * (g_rngc_eng_cntx->TotalNotes)));
  2461.             if (g_rngc_eng_cntx->CurrNoteIndex >= NUM_NOTES_IN_STAVE)
  2462.             {
  2463.                 g_rngc_eng_cntx->CurrUIPos = NUM_NOTES_IN_STAVE - 1;
  2464.             }
  2465.             else
  2466.             {
  2467.                 g_rngc_eng_cntx->CurrUIPos = g_rngc_eng_cntx->CurrNoteIndex;
  2468.             }
  2469.             EntryRngcComposerEngine();
  2470.         }
  2471.         else
  2472.         {
  2473.             OslMfree(g_rngc_eng_cntx);
  2474.             g_rngc_eng_cntx = NULL;
  2475.             DisplayPopup(
  2476.                 (U8*) GetString(STR_GLOBAL_UNSUPPORTED_FORMAT),
  2477.                 IMG_GLOBAL_WARNING,
  2478.                 0,
  2479.                 UI_POPUP_NOTIFYDURATION_TIME,
  2480.                 ERROR_TONE);
  2481.         }
  2482.         OslMfree(pMelody);
  2483.     }
  2484. }
  2485. /*****************************************************************************
  2486.  * FUNCTION
  2487.  *  GetIndexInList
  2488.  * DESCRIPTION
  2489.  *  This function is to retreive duration/note symbol/octave/type of a musical node
  2490.  * PARAMETERS
  2491.  *  nNote           [IN]            The value of the musical note
  2492.  *  pImageId        [IN/OUT]        Image id to be display for the musical note
  2493.  *  pYVal           [IN/OUT]        The y-coordinate of the musical note
  2494.  * RETURNS
  2495.  *  void
  2496.  *****************************************************************************/
  2497. void GetIndexInList(U16 nNote, U16 *pImageId, U8 *pYVal)
  2498. {
  2499.     /*----------------------------------------------------------------*/
  2500.     /* Local Variables                                                */
  2501.     /*----------------------------------------------------------------*/
  2502.     U16 nListCount = 0;
  2503.     U32 nNoteOctave;
  2504.     U32 nValue;
  2505.     U32 nDuration;
  2506.     U32 nNoteType;
  2507.     U32 nIndex;
  2508.     /*----------------------------------------------------------------*/
  2509.     /* Code Body                                                      */
  2510.     /*----------------------------------------------------------------*/
  2511.     nDuration = nNote & DURATION_MASK;
  2512.     nValue = nNote & NOTE_MASK;
  2513.     nNoteOctave = nNote & OCTAVE_MASK;
  2514.     nNoteType = nNote & NOTETYPE_MASK;
  2515.     /* vibe, backlight, led */
  2516.     if (nValue >= NOTE_VIBRATION_ON)
  2517.     {
  2518.         switch (nValue)
  2519.         {
  2520.             case NOTE_VIBRATION_ON:
  2521.                 *pImageId = IMG_RING_EVENTVIB_ON;
  2522.                 break;
  2523.             case NOTE_VIBRATION_OFF:
  2524.                 *pImageId = IMG_RING_EVENTVIB_OFF;
  2525.                 break;
  2526.             case NOTE_LED_ON:
  2527.                 *pImageId = IMG_RING_EVENTLED_ON;
  2528.                 break;
  2529.             case NOTE_LED_OFF:
  2530.                 *pImageId = IMG_RING_EVENTLED_OFF;
  2531.                 break;
  2532.             case NOTE_BACKLIGHT_ON:
  2533.                 *pImageId = IMG_RING_EVENTBL_ON;
  2534.                 break;
  2535.             case NOTE_BACKLIGHT_OFF:
  2536.                 *pImageId = IMG_RING_EVENTBL_OFF;
  2537.                 break;
  2538.             default:
  2539.                 break;
  2540.         }
  2541.         *pYVal = RNGC_EFFECT_NOTE_OFFSET;
  2542.         return;
  2543.     }
  2544.     /* OCTAVE_4 and OCTAVE_3 use the same symbol */
  2545. #if defined(__MMI_MAINLCD_176X220__) || defined(__MMI_MAINLCD_240X320__)        /* 041205 Calvin modified */
  2546.     if (nNoteOctave == OCTAVE_4)    /* only octave 4 use the normal musical note */
  2547.     {
  2548.         nIndex = nNoteType | OCTAVE_3 | nDuration;
  2549.     }
  2550.     else if (nValue == 1 && nNoteOctave == OCTAVE_3)
  2551.     {
  2552.         nIndex = nNoteType | OCTAVE_3 | nDuration;
  2553.     }
  2554.     else
  2555.     {
  2556.         nIndex = nNoteType | OCTAVE_5 | nDuration;
  2557.     }
  2558. #else /* defined(__MMI_MAINLCD_176X220__) || defined(__MMI_MAINLCD_240X320__) */ 
  2559.     if (nNoteOctave == OCTAVE_4)
  2560.     {
  2561.         nIndex = nNoteType | OCTAVE_3 | nDuration;
  2562.     }
  2563.     else
  2564.     {
  2565.         nIndex = nNoteType | nNoteOctave | nDuration;
  2566.     }
  2567. #endif /* defined(__MMI_MAINLCD_176X220__) || defined(__MMI_MAINLCD_240X320__) */ 
  2568.     for (nListCount = 0; nListCount < sizeof(gNotesList); nListCount++)
  2569.     {
  2570.         if (gNotesList[nListCount].nNote == nIndex)
  2571.         {
  2572.             nNoteOctave = nNoteOctave >> 6;
  2573.             if (nValue == NOTE_REST)
  2574.             {
  2575.                 if (nDuration == DURATION_3BY8 || nDuration == DURATION_1BY4)
  2576.                 {
  2577.                     *pYVal = gnYCoords[21];
  2578.                 }
  2579.                 else if (nDuration == DURATION_3BY16 || nDuration == DURATION_1BY8)
  2580.                 {
  2581.                     *pYVal = gnYCoords[22];
  2582.                 }
  2583.                 else
  2584.                 {
  2585.                     *pYVal = gnYCoords[23];
  2586.                 }
  2587.             }
  2588.             else
  2589.             {
  2590.                 *pYVal = gnYCoords[((nNoteOctave - 1) * 7 + nValue) - 1];
  2591.             }
  2592.             *pImageId = gNotesList[nListCount].nImageId + COMPOSE_RING_TONE_ENGINE_BASE;
  2593.             return;
  2594.         }
  2595.     }
  2596.     return;
  2597. }
  2598. /*****************************************************************************
  2599.  * FUNCTION
  2600.  *  GetMelodyFromStruct
  2601.  * DESCRIPTION
  2602.  *  This function is to generate iMelody string for a given node
  2603.  * PARAMETERS
  2604.  *  pList           [IN/OUT]        Strating address to write the iMelody string
  2605.  *  nListSize       [IN]            Musical note
  2606.  * RETURNS
  2607.  *  address of current write cursor
  2608.  *****************************************************************************/
  2609. U16 GetMelodyFromStruct(U8 *pList, U16 nListSize)
  2610. {
  2611.     /*----------------------------------------------------------------*/
  2612.     /* Local Variables                                                */
  2613.     /*----------------------------------------------------------------*/
  2614.     U16 nCount = 0;
  2615.     U8 *pNoteString = pList;
  2616.     U8 *pTemp;
  2617.     U16 nCurrentNode = g_rngc_eng_cntx->CurrNoteIndex;
  2618.     /*----------------------------------------------------------------*/
  2619.     /* Code Body                                                      */
  2620.     /*----------------------------------------------------------------*/
  2621.     g_rngc_eng_cntx->CurrNoteIndex = 0;
  2622.     while (nCount < g_rngc_eng_cntx->TotalNotes)
  2623.     {
  2624.         /* insert string of musical note to pNoteString */
  2625.         pTemp = GetStringForNode(pNoteString, g_rngc_eng_cntx->NotesList[nCount]);
  2626.         /* adjust location of string pointer */
  2627.         pNoteString += (pTemp - pNoteString);
  2628.         ++g_rngc_eng_cntx->CurrNoteIndex;
  2629.         ++nCount;
  2630.     }
  2631.     *pNoteString = 0;
  2632.     g_rngc_eng_cntx->CurrNoteIndex = nCurrentNode;
  2633.     return pNoteString - pList;
  2634. }
  2635. /*****************************************************************************
  2636.  * FUNCTION
  2637.  *  GetStringForNode
  2638.  * DESCRIPTION
  2639.  *  This function is to generate iMelody string for a given node
  2640.  * PARAMETERS
  2641.  *  pStr        [IN/OUT]        Strating address to write the iMelody string
  2642.  *  nNote       [IN]            Musical note
  2643.  * RETURNS
  2644.  *  address of current write cursor
  2645.  *****************************************************************************/
  2646. U8 *GetStringForNode(U8 *pStr, U32 nNote)
  2647. {
  2648.     /*----------------------------------------------------------------*/
  2649.     /* Local Variables                                                */
  2650.     /*----------------------------------------------------------------*/
  2651.     U32 nNoteOctave;
  2652.     U32 nValue;
  2653.     U32 nDuration;
  2654.     U32 nNoteType;
  2655.     U8 *pNote = pStr;
  2656.     U16 len, index;
  2657.     /*----------------------------------------------------------------*/
  2658.     /* Code Body                                                      */
  2659.     /*----------------------------------------------------------------*/
  2660.     nValue = g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] & NOTE_MASK;
  2661.     nDuration = g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] & DURATION_MASK;
  2662.     nNoteOctave = g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] & OCTAVE_MASK;
  2663.     nNoteType = g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] & NOTETYPE_MASK;
  2664.     /* octave */
  2665.     if (nNoteOctave == OCTAVE_3)
  2666.     {
  2667.         memcpy(pNote, "*3", 2);
  2668.         pNote += 2;
  2669.     }
  2670.     else if (nNoteOctave == OCTAVE_5)
  2671.     {
  2672.         memcpy(pNote, "*5", 2);
  2673.         pNote += 2;
  2674.     }
  2675.     /* note type */
  2676.     if (nNoteType == SHARP)
  2677.     {
  2678.         memcpy(pNote, "#", 1);
  2679.         pNote += 1;
  2680.     }
  2681.     else if (nNoteType == FLAT)
  2682.     {
  2683.         memcpy(pNote, "&", 1);
  2684.         pNote += 1;
  2685.     }
  2686.     index = (U16) (nValue - 1);
  2687.     len = strlen((PS8) gRngcMusicalNote[index]);
  2688.     memcpy(pNote, gRngcMusicalNote[index], len);
  2689.     pNote += len;
  2690.     if (nDuration > 0)
  2691.     {
  2692.         index = (U16) (nDuration / DURATION_3BY2 - 1);
  2693.         len = strlen((PS8) gRngcDuration[index]);
  2694.         memcpy(pNote, gRngcDuration[index], len);
  2695.         pNote += len;
  2696.     }
  2697.     return pNote;
  2698. }
  2699. /*****************************************************************************
  2700.  * FUNCTION
  2701.  *  GetComposerStructFromMelody
  2702.  * DESCRIPTION
  2703.  *  Parsing header of iMelody string, and convert to the structure used in this application
  2704.  * PARAMETERS
  2705.  *  pMelody     [IN]        IMelody string, including header
  2706.  * RETURNS
  2707.  *  success or failed
  2708.  *****************************************************************************/
  2709. U8 GetComposerStructFromMelody(U8 *pMelody)
  2710. {
  2711.     /*----------------------------------------------------------------*/
  2712.     /* Local Variables                                                */
  2713.     /*----------------------------------------------------------------*/
  2714.     U8 *ptr = pMelody;
  2715.     U8 instrument;
  2716.     /*----------------------------------------------------------------*/
  2717.     /* Code Body                                                      */
  2718.     /*----------------------------------------------------------------*/
  2719.     if (!CompareMelody(&ptr, "BEGIN:"))
  2720.     {
  2721.         return FALSE;
  2722.     }
  2723.     if (!CompareMelody(&ptr, "IMELODY"))
  2724.     {
  2725.         return FALSE;
  2726.     }
  2727.     if (!CompareMelody(&ptr, "VERSION:"))
  2728.     {
  2729.         return FALSE;
  2730.     }
  2731.     if (!CompareMelody(&ptr, "1.0") && !CompareMelody(&ptr, "1.1") && !CompareMelody(&ptr, "1.2"))
  2732.     {
  2733.         return FALSE;
  2734.     }
  2735.     if (!CompareMelody(&ptr, "FORMAT:"))
  2736.     {
  2737.         return FALSE;
  2738.     }
  2739.     if (!CompareMelody(&ptr, "CLASS1.0") && !CompareMelody(&ptr, "CLASS2.0"))
  2740.     {
  2741.         return FALSE;
  2742.     }
  2743.     while (*ptr != 0)
  2744.     {
  2745.         if (CompareMelody(&ptr, "NAME:"))   /* ignore song name */
  2746.         {
  2747.             ClearToEnd(&ptr);
  2748.         }
  2749.         else if (CompareMelody(&ptr, "COMPOSER:"))
  2750.         {   /* ignore composer name */
  2751.             g_rngc_cntx.CurrInstr = GetInstrument(&ptr);
  2752.             /* check instrument */
  2753.             for (instrument = 0; instrument < ENUM_TOTAL_INSTR; instrument++)
  2754.             {
  2755.                 if ((U8) g_rngc_cntx.CurrInstr == CurrentInstrument[instrument])
  2756.                 {
  2757.                     break;
  2758.                 }
  2759.             }
  2760.             if( instrument == ENUM_TOTAL_INSTR)
  2761.             {
  2762.                 return FALSE;
  2763.             }
  2764.             ClearToEnd(&ptr);
  2765.         }
  2766.         else if (CompareMelody(&ptr, "BEAT:"))
  2767.         {
  2768.             g_rngc_cntx.CurrSpeed = (U8) GetBeat(&ptr);
  2769.             ClearToEnd(&ptr);
  2770.         }
  2771.         else if (CompareMelody(&ptr, "STYLE:"))
  2772.         {
  2773.             ClearToEnd(&ptr);
  2774.         }
  2775.         else if (CompareMelody(&ptr, "VOLUME:"))
  2776.         {
  2777.             ClearToEnd(&ptr);
  2778.         }
  2779.         else if (CompareMelody(&ptr, "MELODY:"))
  2780.         {
  2781.             if (GetMelody(&ptr) == FALSE)
  2782.             {
  2783.                 return FALSE;
  2784.             }
  2785.             if (!CompareMelody(&ptr, "END:IMELODY"))
  2786.             {
  2787.                 return FALSE;
  2788.             }
  2789.             break;
  2790.         }
  2791.         else
  2792.         {
  2793.             return FALSE;
  2794.         }
  2795.     }
  2796.     return TRUE;
  2797. }
  2798. /*****************************************************************************
  2799.  * FUNCTION
  2800.  *  GetMelody
  2801.  * DESCRIPTION
  2802.  *  Retrieve musical note according to the melody string
  2803.  * PARAMETERS
  2804.  *  pptr        [IN]        Pointer of an iMelody string
  2805.  * RETURNS
  2806.  *  success or failed
  2807.  *****************************************************************************/
  2808. U8 GetMelody(U8 **pptr)
  2809. {
  2810.     /*----------------------------------------------------------------*/
  2811.     /* Local Variables                                                */
  2812.     /*----------------------------------------------------------------*/
  2813.     U8 **ptr = pptr;
  2814.     /*----------------------------------------------------------------*/
  2815.     /* Code Body                                                      */
  2816.     /*----------------------------------------------------------------*/
  2817.     while (**ptr)
  2818.     {
  2819.         if (g_rngc_eng_cntx->TotalNotes == MAX_NOTES)
  2820.         {
  2821.             if (**ptr == 10 || **ptr == 13)
  2822.             {
  2823.                 return TRUE;
  2824.             }
  2825.             else
  2826.             {