form_ringComposer.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:20k
- /*****************************************************************************
- * 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_RingComposer.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * Ring composer 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_RingComposer.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- static int Default_Repeats = 1;
- static int Default_SpeakerVolume = 128;
- static int Default_BuzzerVolume = 4;
- TfrmRingComposer *frmRingComposer;
- static void imelody_play_cnf_cb( FT_IMELODY_PLAY_CNF cnf, short token, void *usrData)
- { frmRingComposer->imelody_play_cnf_cb( cnf, token, usrData);
- }
- static void imelody_play_over_ind_cb(short token, void *usrData)
- { frmRingComposer->imelody_play_over_ind_cb( token, usrData);
- }
- static void imelody_stop_cnf_cb( FT_IMELODY_STOP_CNF cnf, short token, void *usrData)
- {
- frmRingComposer->imelody_stop_cnf_cb( cnf, token, usrData);
- }
- void TfrmRingComposer::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 TfrmRingComposer::TfrmRingComposer(TComponent* Owner)
- : TForm(Owner)
- {
- int j;
- edtNotes->ReadOnly = true;
- memoRingComposer->ReadOnly = true;
- NotesBuf[0]= ' ';
- IsFirstOctave = true;
- strcpy(lastOctave, ComboBoxOctave->Text.c_str());
- // marked by Andy Ueng
- //ComboBoxVolume->Items->Add("V0");
- //ComboBoxVolume->Items->Add("V1");
- //ComboBoxVolume->Items->Add("V2");
- //ComboBoxVolume->Items->Add("V3");
- //ComboBoxVolume->Items->Add("V4");
- //ComboBoxVolume->Items->Add("V5");
- //ComboBoxVolume->Items->Add("V6");
- //ComboBoxVolume->Items->Add("V7");
- //ComboBoxVolume->Items->Add("V8");
- //ComboBoxVolume->Items->Add("V9");
- //ComboBoxVolume->Items->Add("V10");
- //ComboBoxVolume->Items->Add("V11");
- //ComboBoxVolume->Items->Add("V12");
- //ComboBoxVolume->Items->Add("V13");
- //ComboBoxVolume->Items->Add("V14");
- //ComboBoxVolume->Items->Add("V15");
- // end of marked
- // for(j=0; j<MAX_RING_COMPSER_SIZE; j++)
- // {
- // RingComposerBuf[j] = ' ';
- // }
- // strcpy(RingComposerBuf, "BEGIN:IMELODY");
- // strcat(RingComposerBuf, "nVERSION:1.2");
- // strcat(RingComposerBuf, "nFORMAT:CLASS1.0");
- // strcat(RingComposerBuf, "nMELODY: ");
- }
- //---------------------------------------------------------------------------
- void TfrmRingComposer::imelody_play_cnf_cb( FT_IMELODY_PLAY_CNF cnf, short token, void *usrData)
- {
- // modified by Andy Ueng
- // if ( cnf->ok != 0)
- if ( cnf.status == STATUS_IMELODY_PLAY_SUCCESS)
- // end of modified
- {
- sb_L1sp->Panels->Items[0]->Text = (AnsiString) " Play iMelody successfully";
- sb_L1sp->Panels->Items[1]->Text = "";
- } else
- {
- Application->MessageBox( "Play iMelody Failure", "FAILURE", MB_OK );
- btnPlayiMelody->Enabled = true;
- btnStopPlayiMelody->Enabled = false;
- }
- }
- void TfrmRingComposer::imelody_play_over_ind_cb(short token, void *usrData)
- {
- sb_L1sp->Panels->Items[0]->Text = (AnsiString) " play iMelody finish";
- sb_L1sp->Panels->Items[1]->Text = "";
- btnPlayiMelody->Enabled = true;
- btnStopPlayiMelody->Enabled = false;
- }
- void TfrmRingComposer::imelody_stop_cnf_cb( FT_IMELODY_STOP_CNF cnf, short token, void *usrData)
- {
- if ( cnf.status == STATUS_IMELODY_STOP_SUCCESS)
- {
- sb_L1sp->Panels->Items[0]->Text = (AnsiString) " Stop play iMelody successfully";
- sb_L1sp->Panels->Items[1]->Text = "";
- btnPlayiMelody->Enabled = true;
- btnStopPlayiMelody->Enabled = false;
- } else
- {
- Application->MessageBox( "Stop play iMelody failure", "FAILURE", MB_OK );
- sb_L1sp->Panels->Items[0]->Text = (AnsiString) " Stop play Melody failure";
- sb_L1sp->Panels->Items[1]->Text = "";
- btnPlayiMelody->Enabled = true;
- btnStopPlayiMelody->Enabled = false;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmRingComposer::btnDoClick(TObject *Sender)
- {
- IsContinueOctaveChange = false;
- if(IsFirstOctave == true)
- {
- strcat(NotesBuf, ComboBoxOctave->Text.c_str());
- IsFirstOctave = false;
- IsContinueOctaveChange = true;
- }
- if(RadioButtonBasicNotes->Checked)
- {
- // strcat(RingComposerBuf, "c");
- strcat(NotesBuf, "c");
- }
- if(RadioButtonFlatNotes->Checked)
- {
- // strcat(RingComposerBuf, "&c");
- strcat(NotesBuf, "&c");
- }
- if(RadioButtonSharpNotes->Checked)
- {
- // strcat(RingComposerBuf, "#c");
- strcat(NotesBuf, "#c");
- }
- strcat(NotesBuf, ComboBoxDuration->Text.c_str());
- edtNotes->Text= NotesBuf;
- }
-
- void __fastcall TfrmRingComposer::btnReClick(TObject *Sender)
- {
- IsContinueOctaveChange = false;
- if(IsFirstOctave == true)
- {
- strcat(NotesBuf, ComboBoxOctave->Text.c_str());
- IsFirstOctave = false;
- IsContinueOctaveChange = true;
- }
-
- if(RadioButtonBasicNotes->Checked)
- {
- // strcat(RingComposerBuf, "d");
- strcat(NotesBuf, "d");
- }
- if(RadioButtonFlatNotes->Checked)
- {
- // strcat(RingComposerBuf, "&d");
- strcat(NotesBuf, "&d");
- }
- if(RadioButtonSharpNotes->Checked)
- {
- strcat(RingComposerBuf, "#d");
- strcat(NotesBuf, "#d");
- }
- strcat(NotesBuf, ComboBoxDuration->Text.c_str());
- edtNotes->Text= NotesBuf;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmRingComposer::BtnMiClick(TObject *Sender)
- {
- IsContinueOctaveChange = false;
- if(IsFirstOctave == true)
- {
- strcat(NotesBuf, ComboBoxOctave->Text.c_str());
- IsFirstOctave = false;
- IsContinueOctaveChange = true;
- }
-
- if(RadioButtonBasicNotes->Checked)
- {
- // strcat(RingComposerBuf, "e");
- strcat(NotesBuf, "e");
- }
- if(RadioButtonFlatNotes->Checked)
- {
- // strcat(RingComposerBuf, "&e");
- strcat(NotesBuf, "&e");
- }
- if(RadioButtonSharpNotes->Checked)
- {
- // strcat(RingComposerBuf, "#e");
- strcat(NotesBuf, "#e");
- }
- strcat(NotesBuf, ComboBoxDuration->Text.c_str());
- edtNotes->Text= NotesBuf;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmRingComposer::btnFaClick(TObject *Sender)
- {
- IsContinueOctaveChange = false;
- if(IsFirstOctave == true)
- {
- strcat(NotesBuf, ComboBoxOctave->Text.c_str());
- IsFirstOctave = false;
- IsContinueOctaveChange = true;
- }
-
- if(RadioButtonBasicNotes->Checked)
- {
- // strcat(RingComposerBuf, "f");
- strcat(NotesBuf, "f");
- }
- if(RadioButtonFlatNotes->Checked)
- {
- // strcat(RingComposerBuf, "&f");
- strcat(NotesBuf, "&f");
- }
- if(RadioButtonSharpNotes->Checked)
- {
- // strcat(RingComposerBuf, "#f");
- strcat(NotesBuf, "#f");
- }
- strcat(NotesBuf, ComboBoxDuration->Text.c_str());
- edtNotes->Text= NotesBuf;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmRingComposer::btnSoClick(TObject *Sender)
- {
- IsContinueOctaveChange = false;
- if(IsFirstOctave == true)
- {
- strcat(NotesBuf, ComboBoxOctave->Text.c_str());
- IsFirstOctave = false;
- IsContinueOctaveChange = true;
- }
-
- if(RadioButtonBasicNotes->Checked)
- {
- // strcat(RingComposerBuf, "g");
- strcat(NotesBuf, "g");
- }
- if(RadioButtonFlatNotes->Checked)
- {
- // strcat(RingComposerBuf, "&g");
- strcat(NotesBuf, "&g");
- }
- if(RadioButtonSharpNotes->Checked)
- {
- // strcat(RingComposerBuf, "#g");
- strcat(NotesBuf, "#g");
- }
- strcat(NotesBuf, ComboBoxDuration->Text.c_str());
- edtNotes->Text= NotesBuf;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmRingComposer::btnLaClick(TObject *Sender)
- {
- IsContinueOctaveChange = false;
- if(IsFirstOctave == true)
- {
- strcat(NotesBuf, ComboBoxOctave->Text.c_str());
- IsFirstOctave = false;
- IsContinueOctaveChange = true;
- }
- if(RadioButtonBasicNotes->Checked)
- {
- // strcat(RingComposerBuf, "a");
- strcat(NotesBuf, "a");
- }
- if(RadioButtonFlatNotes->Checked)
- {
- // strcat(RingComposerBuf, "&a");
- strcat(NotesBuf, "&a");
- }
- if(RadioButtonSharpNotes->Checked)
- {
- // strcat(RingComposerBuf, "#a");
- strcat(NotesBuf, "#a");
- }
- strcat(NotesBuf, ComboBoxDuration->Text.c_str());
- edtNotes->Text= NotesBuf;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmRingComposer::btnSiClick(TObject *Sender)
- {
- IsContinueOctaveChange = false;
- if(IsFirstOctave == true)
- {
- strcat(NotesBuf, ComboBoxOctave->Text.c_str());
- IsFirstOctave = false;
- IsContinueOctaveChange = true;
- }
- if(RadioButtonBasicNotes->Checked)
- {
- // strcat(RingComposerBuf, "b");
- strcat(NotesBuf, "b");
- }
- if(RadioButtonFlatNotes->Checked)
- {
- // strcat(RingComposerBuf, "&b");
- strcat(NotesBuf, "&b");
- }
- if(RadioButtonSharpNotes->Checked)
- {
- // strcat(RingComposerBuf, "#b");
- strcat(NotesBuf, "#b");
- }
- strcat(NotesBuf, ComboBoxDuration->Text.c_str());
- edtNotes->Text= NotesBuf;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmRingComposer::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 =' ';
- unsigned 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<memoRingComposer->Lines->Count;i++)
- {
- for(j=0; j<100; j++)
- {
- MemoLine[j] = ' ';
- }
- strcpy(MemoLine, memoRingComposer->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 != memoRingComposer->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;
- // imelody_play_req.buf = RingComposerBuf;
- // imelody_play_req.buf_len = strlen(RingComposerBuf);
- //META_RESULT mr1 = META_iMelody_Play( imelody_play_req,
- // ::imelody_play_cnf_cb,
- // ::imelody_play_over_ind_cb,
- // &IMELODY_PLAY_token,
- // NULL );
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmRingComposer::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 TfrmRingComposer::btnLoadFromFileClick(TObject *Sender)
- {
- bool ok;
- ok = OpenDialog->Execute();
- if( !ok )
- return;
- else
- {
- memoRingComposer->Lines->LoadFromFile(OpenDialog->FileName);
- btnPlayiMelody->Enabled = true;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmRingComposer::btnSaveMemotoFileClick(TObject *Sender)
- {
- bool ok;
- ok = SaveDialog->Execute();
- if( !ok )
- return;
- else
- {
- memoRingComposer->Lines->SaveToFile(SaveDialog->FileName );
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmRingComposer::btnLoadFromEditorClick(TObject *Sender)
- {
- char temp_StyleBuf[10];
- char temp_NotesBuf[MAX_NOTES_BUF_SIZE];
- edtNotes->Text = "";
- memoRingComposer->Clear();
- // strcat(RingComposerBuf, "nEND:IMELODY");
- //memoRingComposer->Lines->Add(RingComposerBuf);
- memoRingComposer->Lines->Add("BEGIN:IMELODY");
- memoRingComposer->Lines->Add("VERSION:1.2");
- memoRingComposer->Lines->Add("FORMAT:CLASS1.0");
- strcpy(temp_StyleBuf, "STYLE:");
- strcat(temp_StyleBuf, ComboBoxStyle->Text.c_str());
- memoRingComposer->Lines->Add(temp_StyleBuf);
- strcpy(temp_NotesBuf, "MELODY:");
- // strcat(temp_NotesBuf, ComboBoxOctave->Text.c_str());
- strcat(temp_NotesBuf, NotesBuf);
- memoRingComposer->Lines->Add(temp_NotesBuf);
- memoRingComposer->Lines->Add("END:IMELODY");
- NotesBuf[0]= ' ';
- IsFirstOctave = true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmRingComposer::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 TfrmRingComposer::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 TfrmRingComposer::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
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmRingComposer::OctaveOnChange(TObject *Sender)
- {
- // added by Andy Ueng
- char temp_buf[10];
- IsFirstOctave = false;
-
- if(IsContinueOctaveChange == true)
- {
- if(strcmp(lastOctave, ComboBoxOctave->Text.c_str())!=0)
- {
- sprintf(temp_buf, "%s", ComboBoxOctave->Text.c_str());
- NotesBuf[strlen(NotesBuf)-1] = temp_buf[1];
- //strcat(NotesBuf, ComboBoxOctave->Text.c_str());
- }
- }
- else
- {
- strcat( NotesBuf, ComboBoxOctave->Text.c_str());
- }
- strcpy(lastOctave, ComboBoxOctave->Text.c_str());
- edtNotes->Text= NotesBuf;
- IsContinueOctaveChange = true;
- // end of added
- }
- //---------------------------------------------------------------------------