form_melody.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:9k
- /*****************************************************************************
- * 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_melody.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * Melody 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_Melody.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TfrmMelody *frmMelody;
- static int Default_Repeats = 1;
- static int Default_SpeakerVolume = 128;
- void TfrmMelody::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;
- }
- // end of added
- //---------------------------------------------------------------------------
- __fastcall TfrmMelody::TfrmMelody(TComponent* Owner)
- : TForm(Owner)
- {
- btnPlayMelody->Enabled = true;
- btnStopPlayMelody->Enabled = false;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMelody::btnPlayMelodyClick(TObject *Sender)
- {
- // added by Andy Ueng
- unsigned char repeats;
- unsigned char SpeakerVolume;
- unsigned char MelodyBuf[MAXMIDIFILESIZE];
- unsigned int MelodyBufLen;
- if ( ListBoxMelody->ItemIndex < 0 )
- {
- ShowMessage(" You must selecte a midi to play");
- return;
- }
- sb_L1sp->Panels->Items[0]->Text = (AnsiString) " playing Melody";
- sb_L1sp->Panels->Items[1]->Text = (AnsiString) "";
- // ifstream is(ListBoxMelody->Items->Strings[ListBoxMelody->ItemIndex].c_str(), ios::binary);
- // is.read(MelodyBuf, sizeof(unsigned char)*MAXMIDIFILESIZE);
- // read midi file
- FILE *fp;
- unsigned char c;
- int i=0;
- unsigned int buf_len;
- fp = fopen(ListBoxMelody->Items->Strings[ListBoxMelody->ItemIndex].c_str(), "rb");
- //fp = fopen("D:\Meta\Midi\Midi song\test2.mid", "rb");
- if(fp == NULL)
- return;
- while(!feof(fp))
- {
- c =getc(fp);
- if(i<sizeof(unsigned char)*MAXMIDIFILESIZE)
- {
- MelodyBuf[i]= c;
- i++;
- }
- }
- fclose(fp);
- MelodyBuf[i]=' ';
- buf_len = i;
- if( !IsValidRepeats( edtRepeats->Text, repeats ) ) { edtRepeatsCheck(edtRepeats); return; }
- melody_play_req->repeats = edtRepeats->Text.ToInt();
- repeats = melody_play_req->repeats;
- if( !IsValidSpeakerVolume( edtSpeakerVolume->Text, SpeakerVolume ) ) { edtSpeakerVolumeCheck(edtSpeakerVolume); return; }
- melody_play_req->Speaker_volume = edtSpeakerVolume->Text.ToInt();
- melody_play_req->buf = MelodyBuf;
- melody_play_req->buf_len = buf_len;
- if ( Sender != NULL )
- {
- dynamic_cast <TControl *>(Sender)->Enabled = false;
- }
- // modified by Andy Ueng
- // META_RESULT mr1 = META_Melody_Play( midi_play_req,
- // &midi_play_cnf,
- // midi_play_cnf_cb,
- // &MIDI_PLAY_cnf_token,
- // midi_play_over_ind_cb,
- // &MIDI_PLAY_ind_token );
- META_RESULT mr1 = META_Melody_Play( melody_play_req,
- melody_play_cnf_cb,
- melody_play_over_ind_cb,
- &MELODY_PLAY_token,
- NULL );
- // end of modified
- if ( mr1 != META_SUCCESS )
- {
- META_result_handler( mr1 );
- if ( Sender != NULL )
- {
- dynamic_cast <TControl *>(Sender)->Enabled = true;
- }
- return;
- }
- btnPlayMelody->Enabled = false;
- btnStopPlayMelody->Enabled = true;
- // end of added
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMelody::btnStopPlayMelodyClick(TObject *Sender)
- {
- // added by Andy Ueng
- btnStopPlayMelody->Enabled = false;
- btnPlayMelody->Enabled = true;
- sb_L1sp->Panels->Items[0]->Text = (AnsiString) " Stop play Melody";
- sb_L1sp->Panels->Items[1]->Text = (AnsiString) "";
- // modified by Andy Ueng
- // META_RESULT mr1 = META_Melody_Stop();
- META_Cancel_r (MELODY_PLAY_token);
-
- mr1 = META_Melody_Stop(melody_stop_cnf_cb, &MELODY_STOP_token, NULL);
- if ( mr1 != META_SUCCESS )
- {
- META_result_handler( mr1 );
- return;
- }
- // end of added
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMelody::edtRepeatsCheck(TObject *Sender)
- {
- int i;
- int data;
- AnsiString text;
- TEdit *edit = (TEdit*)Sender;
- char hint[256] =
- { " value shall be 1~255 "
- };
- text = edit->Text;
- if( !IsValidRepeats( text, data ) )
- {
- edit->Text = Default_Repeats;
- ShowHintLabel( edit, hint );
- edit->SetFocus();
- return;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMelody::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 TfrmMelody::btnAddToListClick(TObject *Sender)
- {
- bool ok;
-
- ok = OpenDialog->Execute();
- if( !ok )
- return;
- else
- {
- ListBoxMelody->Items->Add(OpenDialog->FileName.c_str());
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMelody::btnRemoveFromListClick(TObject *Sender)
- {
- if(ListBoxMelody->ItemIndex < 0)
- return;
- else
- {
- ListBoxMelody->Items->Delete(ListBoxMelody->ItemIndex);
- }
- }
- //---------------------------------------------------------------------------