form_imelody.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:11k
- /*****************************************************************************
- * Copyright Statement:
- * --------------------
- * This software is protected by Copyright and the information contained
- * herein is confidential. The software may not be copied and the information
- * contained herein may not be used or disclosed except with the written
- * permission of MediaTek Inc. (C) 2005
- *
- * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
- * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
- * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
- * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
- * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
- * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
- * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
- * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
- * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
- * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
- *
- * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
- * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
- * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
- * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
- * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
- *
- * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
- * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
- * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
- * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
- * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
- *
- *****************************************************************************/
- /*****************************************************************************
- *
- * Filename:
- * ---------
- * form_imelody.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * iMelody form source
- *
- * Author:
- * -------
- * Andy Ueng (mtk00490)
- *
- *============================================================================
- * HISTORY
- * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *------------------------------------------------------------------------------
- * $Revision$
- * $Modtime$
- * $Log$
- *
- *------------------------------------------------------------------------------
- * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *============================================================================
- ****************************************************************************/
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "form_iMelody.h"
- #include "meta.h"
- #include "META_iMelody_cb.h"
- extern void imelody_play_cnf_cb( FT_IMELODY_PLAY_CNF cnf, short token, void *usrData);
- extern void imelody_play_over_ind_cb(short token, void *usrData);
- extern void imelody_stop_cnf_cb( FT_IMELODY_STOP_CNF cnf, short token, void *usrData);
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TfrmiMelody *frmiMelody;
- // added by Andy Ueng
- static int Default_Repeats = 1;
- static int Default_SpeakerVolume = 128;
- static int Default_BuzzerVolume = 4;
- // end of added
- void TfrmiMelody::ShowHintLabel( TControl *sender, char* hint )
- {
- TPoint pt0 = this->ClientOrigin;
- TPoint pt1 = sender->ClientOrigin;
- lblHint->Left = (pt1.x-pt0.x);
- lblHint->Top = (pt1.y-pt0.y)+sender->Height+3;
- lblHint->Caption = hint;
- lblHint->Visible = true;
- HintTimer->Enabled = true;
- }
- //---------------------------------------------------------------------------
- __fastcall TfrmiMelody::TfrmiMelody(TComponent* Owner)
- : TForm(Owner)
- {
- memoiMelody->Clear();
- RadioButtonSpeaker->Checked = true;
- RadioButtonBuzzer->Checked = false;
- btnPlayiMelody->Enabled = false;
- btnStopPlayiMelody->Enabled = false;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmiMelody::btnStopPlayiMelodyClick(TObject *Sender)
- {
- // added by Andy Ueng
- sb_L1sp->Panels->Items[0]->Text = (AnsiString) " Stop play iMelody";
- sb_L1sp->Panels->Items[1]->Text = "";
- META_Cancel_r (IMELODY_PLAY_token);
- META_RESULT mr1 = META_iMelody_Stop(imelody_stop_cnf_cb, &IMELODY_STOP_token, NULL);
- if ( mr1 != META_SUCCESS )
- {
- META_result_handler( mr1 );
- return;
- }
- btnPlayiMelody->Enabled = true;
- btnStopPlayiMelody->Enabled = false;
- // end of added
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmiMelody::btnPlayiMelodyClick(TObject *Sender)
- {
- unsigned char repeats;
- unsigned char SpeakerVolume;
- unsigned char BuzzerVolume;
- unsigned int buf_len = 0;
- int i, j;
- unsigned char LineFeed ='n';
- unsigned char SpaceChar = ' ';
- unsigned char NullChar =' ';
- char MemoLine[MAX_IMELODY_FILE_SIZE];
- unsigned char iMelodyBuf[MAX_IMELODY_FILE_SIZE];
- AnsiString AnsiBuf;
- bool flag_imelody_song_end=true;
- MemoLine[0]=' ';
- iMelodyBuf[0]=' ';
- sb_L1sp->Panels->Items[0]->Text = (AnsiString) " Play iMelody";
- sb_L1sp->Panels->Items[1]->Text = "";
- if( !IsValidRepeats( edtRepeats->Text, repeats ) ) { edtRepeatsCheck(edtRepeats); return; }
- imelody_play_req.repeats = edtRepeats->Text.ToInt();
- if(RadioButtonSpeaker->Checked)
- {
- if( !IsValidSpeakerVolume( edtSpeakerVolume->Text, SpeakerVolume ) ) { edtSpeakerVolumeCheck(edtSpeakerVolume); return; }
- imelody_play_req.Speaker_Buzzer_volume = edtSpeakerVolume->Text.ToInt();
- imelody_play_req.Output_Inf = IMY_TO_GMI;
- }
- if(RadioButtonBuzzer->Checked)
- {
- if( !IsValidBuzzerVolume( edtBuzzerVolume->Text, BuzzerVolume ) ) { edtSpeakerVolumeCheck(edtSpeakerVolume); return; }
- imelody_play_req.Speaker_Buzzer_volume = edtBuzzerVolume->Text.ToInt();
- imelody_play_req.Output_Inf = IMY_TO_BUZZER;
- }
- for(i=0; i<memoiMelody->Lines->Count;i++)
- {
- for(j=0; j<MAX_IMELODY_FILE_SIZE; j++)
- {
- MemoLine[j] = ' ';
- }
- strcpy(MemoLine, memoiMelody->Lines->Strings[i].c_str());
- strcat(MemoLine, &NullChar);
- if(strncmp(MemoLine, "MELODY:", 7)==0)
- {
- flag_imelody_song_end = false;
- }
- if(strncmp(MemoLine, "END:IMELODY", 11)==0)
- {
- flag_imelody_song_end = true;
- }
- strcat(iMelodyBuf, MemoLine);
-
- buf_len = buf_len + strlen(MemoLine);
- if(i != memoiMelody->Lines->Count -1 && flag_imelody_song_end == true )
- {
- strcat(iMelodyBuf, "n");
- buf_len++;
- }
- }
- strcat(iMelodyBuf, &NullChar);
- imelody_play_req.buf = iMelodyBuf;
- imelody_play_req.buf_len = buf_len;
- // end of modified
- if ( Sender != NULL )
- {
- dynamic_cast <TControl *>(Sender)->Enabled = false;
- }
-
- META_RESULT mr1 = META_iMelody_Play( imelody_play_req,
- imelody_play_cnf_cb,
- imelody_play_over_ind_cb,
- &IMELODY_PLAY_token,
- NULL );
-
- if ( mr1 != META_SUCCESS )
- {
- META_result_handler( mr1 );
- if ( Sender != NULL )
- {
- dynamic_cast <TControl *>(Sender)->Enabled = true;
- }
- return;
- }
- btnPlayiMelody->Enabled = false;
- btnStopPlayiMelody->Enabled = true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmiMelody::btnSaveMemotoFileClick(TObject *Sender)
- {
- bool ok;
- // char str[512];
- ok = SaveDialog->Execute();
- if( !ok )
- return;
- else
- {
- memoiMelody->Lines->SaveToFile(SaveDialog->FileName );
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmiMelody::btnLoadFromFileClick(TObject *Sender)
- {
- bool ok;
-
- ok = OpenDialog->Execute();
- if( !ok )
- return;
- else
- {
- memoiMelody->Lines->LoadFromFile(OpenDialog->FileName);
- btnPlayiMelody->Enabled = true;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmiMelody::edtRepeatsCheck(TObject *Sender)
- {
- int i;
- int data;
- AnsiString text;
- TEdit *edit = (TEdit*)Sender;
- char hint[256] =
- { " value shall be 0~255 "
- };
- text = edit->Text;
- if( !IsValidRepeats( text, data ) )
- {
- edit->Text = Default_Repeats;
- ShowHintLabel( edit, hint );
- edit->SetFocus();
- return;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmiMelody::HintTimerTimer(TObject *Sender)
- {
- HintTimer->Enabled = false;
- lblHint->Visible = false;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmiMelody::edtSpeakerVolumeCheck(TObject *Sender)
- {
- // added by Andy Ueng
- int i;
- int data;
- AnsiString text;
- TEdit *edit = (TEdit*)Sender;
- char hint[256] =
- { " value shall be 0~255 "
- };
- text = edit->Text;
- if( !IsValidSpeakerVolume( text, data ) )
- {
- edit->Text = Default_SpeakerVolume;
- ShowHintLabel( edit, hint );
- edit->SetFocus();
- return;
- }
- // end of added
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmiMelody::edtBuzzerVolumeCheck(TObject *Sender)
- {
- // added by Andy Ueng
- int i;
- int data;
- AnsiString text;
- TEdit *edit = (TEdit*)Sender;
- char hint[256] =
- { " value shall be 0~7 "
- };
- text = edit->Text;
- if( !IsValidBuzzerVolume( text, data ) )
- {
- edit->Text = Default_BuzzerVolume;
- ShowHintLabel( edit, hint );
- edit->SetFocus();
- return;
- }
- // end of added
- }
- //---------------------------------------------------------------------------