Files
AccompanyCube/CompleteFormUnit.cpp
2026-06-13 00:10:11 +08:00

1385 lines
37 KiB
C++

//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "GlobalUnit.h"
#include "MessageFormUnit.h"
#include "CompleteFormUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "PNGButton"
#pragma resource "*.dfm"
USEFORM("MessageFormUnit.cpp", MessageForm);
TCompleteForm *CompleteForm;
static const TCursor crBeginPos = 0x57,
crEndPos = 0x58;
extern TPNGButton *g_btnFontChange;
extern Vcl::Extctrls::TPanel *g_panelFontName;
extern CommonListBoxUnit::TListBox *g_lbFontSelect;
//---------------------------------------------------------------------------
__fastcall TCompleteForm::TCompleteForm(TComponent* Owner)
: TBackgroundForm(Owner)
{
m_nVolLevel = 0;
m_iStartBar = m_iLastStartBar = 0;
m_dblStartPoint = m_dblLastStartPoint = 0;
m_tTimer = m_tAccuracy = 0;
m_bModifyRecord = false;
m_iHintStage = -1;
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::FormActivate(TObject *Sender)
{
if( Sender ){
return;
}
m_lblBeat->Caption = g_strTimeSignature[g_iMelodyTimeSignature];
m_lblTempo->Caption = IntToStr( g_nMelodyTempo );
m_bModifyRecord = false;
m_btnModify->Down = false;
m_btnBeginPos->Down = false;
m_btnBeginPos->Enabled = false;
m_btnEndPos->Down = false;
m_btnEndPos->Enabled = false;
m_panelBarsShow->ShowModifyPos( false );
if( g_iComposeKey>=0 ){
m_lblKey->Caption = g_strMelodyKey[g_iComposeKey];
}
else if( g_iMelodyKey>=0 ){
m_lblKey->Caption = g_strMelodyKey[g_iMelodyKey];
g_iComposeKey = g_iMelodyKey;
}
else{
m_lblKey->Caption = "-";
}
if( !g_bBaseComposeLoaded){
ReloadBaseCompose();
// g_bBaseComposeLoaded = false;
}
bool bStyleChanged = UpdateSegmentBars();
if( g_lstComposeStages.size()==0 ){
g_bkCompose.Clear();
InitComposeStage();
ReloadCompose( g_iComposeKey );
}
else{
bool bBarChanged = false;
if( bStyleChanged ){
bBarChanged = UpdateStageBars();
if( bBarChanged ){
ClearGlobalVars( LIST_COMPLETEVOLS );
g_bSongNeedSave = false;
}
}
if( bBarChanged || !g_bComposeLoaded || g_iComposeKey!=g_iMelodyKey ){
g_bkCompose.Clear();
ReloadCompose( g_iComposeKey );
}
else{
f_MM_SetStreamVolume( 4, g_fMusicVolume );
}
}
if( g_lstCompleteVols.size()==0 ){
InitialBarVols();
}
f_MM_SetStreamVolume( 5, g_fAudioVolume );
m_nSpeakerVolPos = 100 - g_fSpeakerVolume * 100;
m_nMicrophoneVolPos = 100 - g_fRecordVolume * 100;
m_btnSpeakerVolPos->Top = 5 + m_nSpeakerVolPos;
m_btnMicrophoneVolPos->Top = 5 + m_nMicrophoneVolPos;
m_btnSpeakerVolPos->Hint = IntToStr(100-m_nSpeakerVolPos);
m_btnMicrophoneVolPos->Hint = IntToStr(100-m_nMicrophoneVolPos);
m_panelBarsShow->InitialVars();
m_iStartBar = m_iLastStartBar = 0;
m_dblStartPoint = m_dblLastStartPoint = 0;
m_panelBarsShow->SetPlayPoint( 0, 0 );
ShowPlayTime();
//Application->MainForm->Perform(UM_HANDLEAUTOPROJ, 1, 0);//add by tj 2013/1/2
m_panelBarsShow->SetFocus();
m_panelBarsShow->Invalidate();
Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::FormDeactivate(TObject *Sender)
{
if( Application->ActiveFormHandle!=Application->MainFormHandle ){
return;
}
g_bCanStep = true;
StopClick( NULL );
if( m_panelSpeakerVolSet->Visible ){
m_panelSpeakerVolSet->Hide();
m_btnVolSpeakerSet->Down = false;
}
if( m_panelMicrophoneVolSet->Visible ){
m_panelMicrophoneVolSet->Hide();
m_btnVolMicrophoneSet->Down = false;
}
// g_lSongVerifyParam = 0;
if( Sender && g_iComposeKey!=g_iMelodyKey ){
g_bComposeLoaded = false;
}
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::StepClick(TObject *Sender)
{
PostMessage(Application->MainFormHandle, UM_JUMP_PAGE, WPARAM(3),LPARAM(this));
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::FormCreate(TObject *Sender)
{
SetTransparent( this );
m_lblPlayTime->Font->Color = RGB(60,43,23);
m_lblBeat->Font->Color = RGB(60,43,23);
m_lblTempo->Font->Color = RGB(60,43,23);
m_lblKey->Font->Color = RGB(60,43,23);
m_pTimerHint = new TTimer(this);
m_pTimerHint->Enabled = false;
m_pTimerHint->Interval = TIME_HINT;
m_pTimerHint->OnTimer = HintTimerProc;
m_pStageInfoWnd = new TSkinHintWindow(this);
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::FormDestroy(TObject *Sender)
{
if( m_panelBarsShow->IsPlaying() )
StopClick( NULL );
delete m_pTimerHint;
delete m_pStageInfoWnd;
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::FormResize(TObject *Sender)
{
int wOriClient = 798,
hOriClient = 494;
m_btnPrevStep->Top = Height - DPIY( hOriClient - 460 );
m_btnSave->Top = m_btnPrevStep->Top;
m_btnSave->Left = ClientWidth - DPIX( wOriClient - 705 );
m_btnUpload->Top = m_btnPrevStep->Top;
// m_btnUpload->Left = Width - DPIX( wOriClient - 620 );
m_imgBreakH->Width = Width - DPIX(28);
m_imgBreakI->Left = Width - DPIX( wOriClient - 649 );
m_btnAudioEffect->Left = m_imgBreakI->Left - DPIX(60);
m_btnVolSpeakerSet->Top = Height - DPIY( hOriClient - 455 );
m_btnVolMicrophoneSet->Top = m_btnVolSpeakerSet->Top;
m_btnMicSet->Top = m_btnVolSpeakerSet->Top;
m_panelVolLevel->Top = m_btnVolSpeakerSet->Top;
m_panelSpeakerVolSet->Top = Height - DPIY(hOriClient - 322);
m_panelMicrophoneVolSet->Top = m_panelSpeakerVolSet->Top;
m_panelMusicInfo->Left = Width - DPIX( wOriClient - 666 );
m_lbKeySelect->Left = m_panelMusicInfo->Left + m_btnKeyChange->Left - m_lbKeySelect->Width;
m_panelBarsShow->SetBounds( m_panelBarsShow->Left,
m_panelBarsShow->Top,
Width,
Height - DPIY(84) );
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::VolLevelPaint(TObject *Sender)
{
int xPos = 0;
for( int i=0; i<m_nVolLevel; i++ ){
if( i<22 ){
m_pbVolLevel->Canvas->Brush->Color = RGB(70,154,8);
m_pbVolLevel->Canvas->Pen->Color = RGB(70,154,8);
}
else if( i<32 ){
m_pbVolLevel->Canvas->Brush->Color = RGB(221,241,2);
m_pbVolLevel->Canvas->Pen->Color = RGB(221,241,2);
}
else if( i<42 ){
m_pbVolLevel->Canvas->Brush->Color = RGB(221,122,0);
m_pbVolLevel->Canvas->Pen->Color = RGB(221,122,0);
}
else if( i<52 ){
m_pbVolLevel->Canvas->Brush->Color = RGB(215,78,2);
m_pbVolLevel->Canvas->Pen->Color = RGB(215,78,2);
}
else{
m_pbVolLevel->Canvas->Brush->Color = RGB(255,0,0);
m_pbVolLevel->Canvas->Pen->Color = RGB(255,0,0);
}
m_pbVolLevel->Canvas->Rectangle( xPos, 0, xPos+2, m_pbVolLevel->Height );
xPos += 3;
}
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::BtnVolSetClick(TObject *Sender)
{
if( Sender==m_btnVolSpeakerSet ){
if( m_panelSpeakerVolSet->Visible ){
m_panelSpeakerVolSet->Hide();
m_btnVolSpeakerSet->Down = false;
}
else{
m_panelSpeakerVolSet->Show();
m_btnVolSpeakerSet->Down = true;
}
}
else if( Sender==m_btnVolMicrophoneSet ){
if( m_panelMicrophoneVolSet->Visible ){
m_panelMicrophoneVolSet->Hide();
m_btnVolMicrophoneSet->Down = false;
}
else{
m_panelMicrophoneVolSet->Show();
m_btnVolMicrophoneSet->Down = true;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::ImgVolSetMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
{
if( Button==mbLeft && X>8 && X<24 && Y>=16 && Y<=116 ){
int yPos = Y - 16;
if( Sender==m_imgSpeakerVolSet ){
m_nSpeakerVolPos = yPos;
m_btnSpeakerVolPos->Top = yPos + 5;
m_btnSpeakerVolPos->Hint = IntToStr(100-m_nSpeakerVolPos);
g_fSpeakerVolume = (100-m_nSpeakerVolPos)/100.0;
f_MM_SetStreamVolume( 0, g_fSpeakerVolume );
}
else{
m_nMicrophoneVolPos = yPos;
m_btnMicrophoneVolPos->Top = yPos + 5;
m_btnMicrophoneVolPos->Hint = IntToStr(100-m_nMicrophoneVolPos);
g_fRecordVolume = (100-m_nMicrophoneVolPos)/100.0;
f_MM_SetStreamVolume( 1, g_fRecordVolume );
}
}
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::BtnVolPosMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X,
int Y)
{
if( Button==mbLeft ){
m_bPosDraging = true;
m_yPosDragBegin = Y;
((TPNGButton*)Sender)->Hint = "";
}
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::BtnVolPosMouseMove(TObject *Sender, TShiftState Shift, int X, int Y)
{
if( m_bPosDraging==true ){
int yPos = (Sender==m_btnSpeakerVolPos)?m_nSpeakerVolPos:m_nMicrophoneVolPos;
yPos += Y - m_yPosDragBegin;
if( yPos<0 )
yPos = 0;
else if( yPos>100 )
yPos = 100;
if( Sender==m_btnSpeakerVolPos ){
m_nSpeakerVolPos = yPos;
m_btnSpeakerVolPos->Top = yPos + 5;
}
else{
m_nMicrophoneVolPos = yPos;
m_btnMicrophoneVolPos->Top = yPos + 5;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::BtnVolPosMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X,
int Y)
{
if( Button==mbLeft ){
m_bPosDraging = false;
if( Sender==m_btnSpeakerVolPos ){
m_btnSpeakerVolPos->Hint = IntToStr(100-m_nSpeakerVolPos);
g_fSpeakerVolume = (100-m_nSpeakerVolPos)/100.0;
f_MM_SetStreamVolume( 0, g_fSpeakerVolume );
}
else{
m_btnMicrophoneVolPos->Hint = IntToStr(100-m_nMicrophoneVolPos);
g_fRecordVolume = (100-m_nMicrophoneVolPos)/100.0;
f_MM_SetStreamVolume( 1, g_fRecordVolume );
}
}
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::RecordClick(TObject *Sender)
{
HRESULT hr = S_FALSE;
/*
hr = f_MM_CheckRecordDevice( g_iRecordDevice, g_iRecordInput, NULL);
if( hr!=S_OK ){
ShowErrorMessage( hr );
if( hr==3 || hr==6 || hr==37 || hr==46 || hr==23 ){
g_iRecordDevice = g_iRecordInput = -1;
PostMessage(Application->MainFormHandle, UM_MICSETTING, WPARAM(0),LPARAM(0));
}
return;
}
*/
int nMelodyBeatsPerMeasure = g_iMelodyTimeSignature==0 ? 4 :
g_iMelodyTimeSignature==1 ? 3 :
g_iMelodyTimeSignature==2 ? 2 : 3;
double dblPlayStartBar=0, dblEditStartBar=0, dblEditEndBar=0;
m_dwLastVol = 0;
m_iRecordBar = 0;
m_dblRecordPoint = 0;
if( !m_btnModify->Down ){
m_iStartBar = 0;
m_dblStartPoint = 0;
m_panelBarsShow->SetPlayPoint( m_iStartBar, (int)m_dblStartPoint );
}
else{
int iModifyBeginBar, iModifyBeginPoint, iModifyEndBar, iModifyEndPoint;
m_panelBarsShow->GetModifyPos( true, iModifyBeginBar, iModifyBeginPoint );
m_panelBarsShow->GetModifyPos( false, iModifyEndBar, iModifyEndPoint );
if( m_iStartBar>iModifyBeginBar || m_iStartBar==iModifyBeginBar
&& m_dblStartPoint>=iModifyBeginPoint ){
if( iModifyBeginBar>0 )
m_iStartBar = iModifyBeginBar-1;
else
m_iStartBar = 0;
m_dblStartPoint = 0;
m_panelBarsShow->SetPlayPoint( m_iStartBar, 0 );
}
dblPlayStartBar = m_iStartBar + m_dblStartPoint / POINTS_PER_BAR;
BARVOLS *pBV = NULL;
if( iModifyBeginBar>=0 ){
pBV = g_lstCompleteVols[iModifyBeginBar];
m_dwLastVol = pBV->aVols[iModifyBeginPoint];
dblEditStartBar = iModifyBeginBar + (double)iModifyBeginPoint/POINTS_PER_BAR;
}
else{
pBV = g_lstCompleteVols[0];
m_dwLastVol = pBV->aVols[0];
}
if( iModifyEndBar>=0 ){
dblEditEndBar = iModifyEndBar + (double)iModifyEndPoint/POINTS_PER_BAR;
}
}
hr = f_MM_Record(Handle, dblPlayStartBar, dblEditStartBar,
dblEditEndBar, TYPE_COMPOSE);
if( hr==S_OK ){
SetPlayTimer( true, m_tTimer, m_tAccuracy, Handle );
m_panelBarsShow->Play( true );
m_btnRecord->Enabled = false;
m_btnRecord->Down = true;
m_btnStop->Enabled = true;
m_btnPlay->Enabled = false;
m_btnPlay->Visible = true;
m_btnPause->Visible = false;
m_btnModify->Enabled = false;
m_btnBeginPos->Enabled = false;
m_btnEndPos->Enabled = false;
m_btnPrevStep->Enabled = false;
m_btnSave->Enabled = false;
// Application->MainForm->Perform(UM_HANDLEAUTOPROJ, 0, 0);//add by tj 2013/1/2
//禁止跳转及打开/新建工程
PostMessage(Application->MainFormHandle, UM_REFRESH_PAGE_STATE, PAGE_COMPLETEONLY, 0);
}
else{
ShowErrorMessage( hr );
if( hr==3 || hr==6 || hr==37 || hr==46 || hr==23 ){
g_iRecordDevice = g_iRecordInput = -1;
PostMessage(Application->MainFormHandle, UM_MICSETTING, WPARAM(0),LPARAM(0));
}
}
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::StopClick(TObject *Sender)
{
if( m_panelBarsShow->IsPlaying() ){
SetPlayTimer( false, m_tTimer, m_tAccuracy );
f_MM_Stop();
if( m_btnRecord->Down ){
f_MM_SetStreamVolume( 5, g_fAudioVolume );
PostMessage(Application->MainFormHandle, UM_REFRESH_PAGE_STATE, PAGE_ALL, 0);
}
m_nVolLevel = 0;
m_pbVolLevel->Invalidate();
m_panelBarsShow->Play( false );
}
m_btnStop->Enabled = false;
m_btnPlay->Down = false;
m_btnPlay->Visible = true;
m_btnPlay->Enabled = true;
m_btnPause->Visible = false;
m_btnRecord->Enabled = true;
m_btnRecord->Down = false;
m_btnModify->Enabled = true;
if( m_btnModify->Down ){
m_btnBeginPos->Enabled = true;
m_btnEndPos->Enabled = true;
}
m_btnPrevStep->Enabled = true;
m_btnSave->Enabled = true;
m_iStartBar = m_iLastStartBar;
m_dblStartPoint = m_dblLastStartPoint;
m_panelBarsShow->SetPlayPoint( m_iStartBar, (int)m_dblStartPoint );
ShowPlayTime();
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::PlayClick(TObject *Sender)
{
if( g_bRecProtect && g_bShowProtectMsg ){
MessageForm->ShowMessage( "使用收费风格,将可能听到随机杂音\n\n但不会影响保存的歌曲",
MB_ICONINFORMATION|MB_OK|MB_UNCHECKED );
g_bShowProtectMsg = !MessageForm->GetCheckState();
Application->MainForm->Update();
}
double dblComposeStartPoint = m_iStartBar + m_dblStartPoint / POINTS_PER_BAR ;
HRESULT hr = f_MM_Play( Handle, dblComposeStartPoint, TYPE_SONG_COMPOSE );
if( hr==S_OK && !m_panelBarsShow->IsPlaying() ){
SetPlayTimer( true, m_tTimer, m_tAccuracy, Handle );
m_panelBarsShow->Play( true );
m_btnPlay->Visible = false;
m_btnPlay->Down = true;
m_btnPause->Visible = true;
m_btnStop->Enabled = true;
m_btnRecord->Enabled = false;
}
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::PauseClick(TObject *Sender)
{
if( m_panelBarsShow->IsPlaying() ){
SetPlayTimer( false, m_tTimer, m_tAccuracy );
f_MM_Stop();
m_nVolLevel = 0;
m_pbVolLevel->Invalidate();
m_panelBarsShow->Play( false );
}
m_btnPlay->Visible = true;
m_btnPlay->Down = false;
m_btnPause->Visible = false;
}
//---------------------------------------------------------------------------
void TCompleteForm::ShowPlayTime()
{
char strTime[10];
GetPlayTime( m_iStartBar, m_dblStartPoint, strTime );
m_lblPlayTime->Caption = strTime;
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::UMMediaTime(TMessage &Message)
{
if( !m_panelBarsShow->IsPlaying() )
return;
int iModifyBeginBar, iModifyBeginPoint, iModifyEndBar, iModifyEndPoint;
bool bRecording = m_btnRecord->Down, bNewBar = false;
int iBar = m_iStartBar;
double dblStartPoint = m_dblStartPoint + g_dblStep;
int iLastPoint = (int)m_dblStartPoint;
if( dblStartPoint>=(double)POINTS_PER_BAR ){
dblStartPoint -= POINTS_PER_BAR;
iBar++;
bNewBar = true;
}
if( bRecording && m_btnModify->Down ){
m_panelBarsShow->GetModifyPos( true, iModifyBeginBar, iModifyBeginPoint );
m_panelBarsShow->GetModifyPos( false, iModifyEndBar, iModifyEndPoint );
if( !((iBar>iModifyBeginBar || iBar==iModifyBeginBar && dblStartPoint>=(double)iModifyBeginPoint ) &&
( iModifyEndBar<0 || iBar<iModifyEndBar || iBar==iModifyEndBar &&
dblStartPoint<(double)iModifyEndPoint )) ){
bRecording = false;
}
else{
g_bSongNeedSave = true;
//g_bSongSaved = false;
g_strMP3File = "";
}
}
//获取实时音量
DWORD dwVolume = 0;
if( bRecording ){
dwVolume= f_MM_GetStreamVolume( 1 );
}
else{
dwVolume= f_MM_GetStreamVolume( 6 );
}
if( dwVolume==-1 ){
dwVolume = 0;
}
m_nVolLevel = (53 * LOWORD( dwVolume )) / 0x8000;
m_pbVolLevel->Invalidate();
if( bNewBar ){
if( bRecording ){
BARVOLS *pBV = g_lstCompleteVols[m_iStartBar];
if( iLastPoint<POINTS_PER_BAR-1 ){
for( int i=iLastPoint+1; i<POINTS_PER_BAR; i++ ){
pBV->aVols[i] = m_dwLastVol;
}
m_panelBarsShow->InvalidateBar( m_iStartBar, iLastPoint, POINTS_PER_BAR-1 );
}
iLastPoint = 0;
}
else if( iBar==g_lstCompleteVols.size() ){
StopClick(NULL);
return;
}
}
int iCurrPoint = (int)dblStartPoint;
if( iBar!=m_iStartBar || iCurrPoint!=(int)m_dblStartPoint ){
if( iBar==m_panelBarsShow->ComposeBarCount() ){
StopClick(NULL);
if( bRecording ){
m_iRecordBar = iBar-1;
m_dblRecordPoint = POINTS_PER_BAR - 1;
}
return;
}
m_panelBarsShow->SetPlayPoint( iBar, (int)dblStartPoint );
BARVOLS *pBV = g_lstCompleteVols[iBar];
if( bRecording ){
pBV->bRecording = true;
if( iLastPoint<iCurrPoint ){
for( int i=iLastPoint; i<iCurrPoint; i++ ){
pBV->aVols[i] = m_dwLastVol;
}
m_panelBarsShow->InvalidateBar( iBar, iLastPoint, iCurrPoint );
}
pBV->aVols[iCurrPoint] = dwVolume;
m_dwLastVol = dwVolume;
}
else if( pBV->bRecording ){
pBV->bRecording = false;
m_panelBarsShow->InvalidateBar( iBar, iLastPoint, iCurrPoint );
}
}
m_iStartBar = iBar;
m_dblStartPoint = dblStartPoint;
if( bRecording ){
m_iRecordBar = iBar;
m_dblRecordPoint = dblStartPoint;
}
ShowPlayTime();
}
// ---------------------------------------------------------------------------
void __fastcall TCompleteForm::UMRecordComplete(TMessage &Message) {
int msDelay = Message.WParamHi;
int iModifyBeginBar, iModifyBeginPoint, iModifyEndBar, iModifyEndPoint;
m_panelBarsShow->GetModifyPos(true, iModifyBeginBar, iModifyBeginPoint);
m_panelBarsShow->GetModifyPos(false, iModifyEndBar, iModifyEndPoint);
int iShiftBeginBar=0, iShiftBeginPoint=0,
iShiftEndBar=g_lstMelodyBars.size()-1, iShiftEndPoint=POINTS_PER_BAR-1; //最后位置
if( m_iRecordBar==iModifyBeginBar && (int)m_dblRecordPoint<=iModifyBeginPoint
|| m_iRecordBar<iModifyBeginBar ){
iShiftEndBar = iShiftEndPoint = 0;
}
else{
if( iModifyBeginBar>=0 ){
iShiftBeginBar = iModifyBeginBar;
iShiftBeginPoint = iModifyBeginPoint;
}
if( m_iRecordBar==iModifyEndBar && (int)m_dblRecordPoint<=iModifyEndPoint
|| m_iRecordBar<iModifyEndBar ){
iShiftEndBar = m_iRecordBar;
iShiftEndPoint = (int)m_dblRecordPoint;
}
else if( iModifyEndBar>=0 ){
iShiftEndBar = iModifyEndBar;
iShiftEndPoint = iModifyEndPoint;
}
SaveAutoProj();
}
//波形移位
int nShift = (int)(msDelay / (g_dblTimePerBar/POINTS_PER_BAR));
DebugPrint( "Shift %d points from %d.%d to %d.%d\n", nShift,
iShiftBeginBar, iShiftBeginPoint, iShiftEndBar, iShiftEndPoint );
if( nShift>0 && (iShiftEndBar-iShiftBeginBar)*POINTS_PER_BAR
+ (iShiftEndPoint-iShiftBeginPoint) > nShift ){
int iShiftToBar = iShiftBeginBar, iShiftToPoint = iShiftBeginPoint,
iShiftFromBar = iShiftBeginBar, iShiftFromPoint = iShiftToPoint+nShift;
if( iShiftFromPoint>=POINTS_PER_BAR ){
iShiftFromPoint %= POINTS_PER_BAR;
iShiftFromBar++;
}
while( iShiftFromBar<iShiftEndBar || iShiftFromBar==iShiftEndBar
&& iShiftFromPoint<=iShiftEndPoint ){
g_lstCompleteVols[iShiftToBar]->aVols[iShiftToPoint]
= g_lstCompleteVols[iShiftFromBar]->aVols[iShiftFromPoint];
iShiftToPoint++;
if( iShiftToPoint>=POINTS_PER_BAR ){
int iPoint = 0;
if( iShiftToBar==iShiftBeginBar ) iPoint = iShiftBeginPoint;
m_panelBarsShow->InvalidateBar( iShiftToBar, iPoint,
POINTS_PER_BAR-1, BAR_DATA );
iShiftToPoint = 0;
iShiftToBar++;
}
iShiftFromPoint++;
if( iShiftFromPoint>=POINTS_PER_BAR ){
iShiftFromPoint = 0;
iShiftFromBar++;
}
}
int iPoint = 0;
if( iShiftToBar==iShiftBeginBar ) iPoint = iShiftBeginPoint;
m_panelBarsShow->InvalidateBar( iShiftToBar, iPoint, iShiftToPoint, BAR_DATA );
}
m_panelBarsShow->Invalidate();
//Application->MainForm->Perform(UM_HANDLEAUTOPROJ, 1, 0);//add by tj 2013/1/2
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::UMRecordVolJust(TMessage &Message)
{
m_nMicrophoneVolPos = 100 - (int)Message.WParam;
m_btnMicrophoneVolPos->Top = 5 + m_nMicrophoneVolPos;
m_btnMicrophoneVolPos->Hint = IntToStr(100-m_nMicrophoneVolPos);
g_fRecordVolume = (int)Message.WParam / 100.0;
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::ModifyClick(TObject *Sender)
{
m_bModifyRecord = !m_bModifyRecord;
if( m_bModifyRecord ){
m_btnModify->Down = true;
m_btnBeginPos->Enabled = true;
m_btnEndPos->Enabled = true;
m_panelBarsShow->ShowModifyPos();
}
else{
m_btnModify->Down = false;
m_btnBeginPos->Down = false;
m_btnBeginPos->Enabled = false;
m_btnEndPos->Down = false;
m_btnEndPos->Enabled = false;
m_panelBarsShow->ShowModifyPos( false );
}
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::BeginPosClick(TObject *Sender)
{
m_btnBeginPos->Down = true;
m_btnEndPos->Down = false;
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::EndPosClick(TObject *Sender)
{
m_btnBeginPos->Down = false;
m_btnEndPos->Down = true;
}
//---------------------------------------------------------------------------
void TCompleteForm::InitialBarVols()
{
int iFirstBar = 0;
int nComposeStageNum = g_lstComposeStages.size();
for( int i=0; i<nComposeStageNum; i++ ){
COMPOSESTAGE* pComposeStage = g_lstComposeStages[i];
if( pComposeStage->iMelodyStage<COMPOSE_INTRO_1 ){
MELODYSTAGE * pMStage = g_lstMelodyStages[pComposeStage->iMelodyStage];
for( int j=pMStage->iFirstBar; j<=pMStage->iLastBar; j++ ){
MELODYBAR *pMBar = g_lstMelodyBars[j];
BARVOLS * pVols = new BARVOLS;
pVols->bRecording = false;
pVols->bInvalid = false;
for( int j=0; j<POINTS_PER_BAR; j++ ){
pVols->aVols[j] = pMBar->tBarVol.aVols[j];
}
g_lstCompleteVols.push_back( pVols );
}
}
else{
for( int j=0; j<pComposeStage->nStageBars; j++ ){
BARVOLS * pVols = new BARVOLS;
pVols->bRecording = false;
g_lstCompleteVols.push_back( pVols );
}
}
}
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::PlayTimeClick(TObject *Sender)
{
g_bShowPlayTick = !g_bShowPlayTick;
if( m_lblPlayTime->Caption.Compare("--:--:---")!=0 )
ShowPlayTime();
if( g_bShowPlayTick ){
m_lblPlayTime->Hint = "当前位置(节拍)";
}
else{
m_lblPlayTime->Hint = "当前位置(时间)";
}
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::BarsShowMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
m_panelBarsShow->SetFocus();
if( m_panelSpeakerVolSet->Visible ){
m_panelSpeakerVolSet->Hide();
m_btnVolSpeakerSet->Down = false;
}
if( m_panelMicrophoneVolSet->Visible ){
m_panelMicrophoneVolSet->Hide();
m_btnVolMicrophoneSet->Down = false;
}
if( !m_btnRecord->Down ){
if( Button==mbLeft ){
if( m_btnBeginPos->Enabled && m_btnBeginPos->Down ||
m_btnEndPos->Enabled && m_btnEndPos->Down ){
X += 6;
Y += 19;
}
int iHitType = -1;
DWORD dwHit = m_panelBarsShow->HitTest( X, Y, iHitType );
int iHitBar = LOWORD(dwHit),
iHitPoint = HIWORD(dwHit);
if( iHitType>0 ){
m_iBX = X;
m_iHitBar = iHitBar;
m_iHitPoint = iHitPoint;
m_bDragOrHit = true;
if( m_btnBeginPos->Enabled && m_btnBeginPos->Down ){
if( m_panelBarsShow->SetModifyPos(true, iHitBar, iHitPoint)){
m_btnBeginPos->Down = false;
}
m_bDragOrHit = false;
}
else if (m_btnEndPos->Enabled && m_btnEndPos->Down) {
if( m_panelBarsShow->SetModifyPos(false, iHitBar, iHitPoint)){
m_btnEndPos->Down = false;
}
m_bDragOrHit = false;
}
}
}
else if( Button==mbRight ){
if( m_btnModify->Down) {
if( m_btnBeginPos->Enabled && m_btnBeginPos->Down ||
m_btnEndPos->Enabled && m_btnEndPos->Down ) {
m_btnBeginPos->Down = false;
m_btnEndPos->Down = false;
m_panelBarsShow->Cursor = crDefault;
}else {
m_bModifyRecord = false;
m_btnModify->Down = false;
m_btnBeginPos->Down = false;
m_btnBeginPos->Enabled = false;
m_btnEndPos->Down = false;
m_btnEndPos->Enabled = false;
m_panelBarsShow->ShowModifyPos(false);
}
}
}
}
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::BarsShowMouseMove(TObject *Sender, TShiftState Shift, int X, int Y)
{
bool bShowHint = false;
if( m_btnBeginPos->Enabled && m_btnBeginPos->Down ){
m_panelBarsShow->Cursor = crBeginPos;
}
else if( m_btnEndPos->Enabled && m_btnEndPos->Down ){
m_panelBarsShow->Cursor = crEndPos;
}
else{
if( m_panelBarsShow->Cursor!=crDefault ){
m_panelBarsShow->Cursor = crDefault;
}
bShowHint = true;
}
if( bShowHint ){
int iHitType = -1;
DWORD dwHit = m_panelBarsShow->HitTest( X, Y, iHitType );
int iHitBar = LOWORD(dwHit),
iHitPoint = HIWORD(dwHit);
if( iHitType==2 ){
int iHitStage = m_panelBarsShow->FindStage( iHitBar );
if( iHitStage>=0 ){
if( iHitStage!=m_iHintStage ){
m_pStageInfoWnd->ReleaseHandle();
m_iHintStage = iHitStage;
m_pTimerHint->Enabled = true;
}
}
}
else{
if( m_iHintStage!=-1 ){
m_iHintStage = -1;
m_pTimerHint->Enabled = false;
m_pStageInfoWnd->ReleaseHandle();
}
}
}
if( m_bDragOrHit ) {
if( X - m_iBX >= 5) {
m_bDragOrHit = false;
m_panelBarsShow->ShowModifyPos();
m_btnBeginPos->Enabled = true;
m_btnEndPos->Enabled = true;
m_btnBeginPos->Down = false;
m_btnEndPos->Down = false;
m_btnModify->Enabled = true;
m_btnModify->Down = true;
m_bModifyRecord = true;
m_bIsBeginSel = TRUE;
m_panelBarsShow->SetModifyPos(true, m_iHitBar, m_iHitPoint);
m_btnBeginPos->Down = false;
int iEndBar, iEndPoint;
m_panelBarsShow->GetModifyPos(false, iEndBar, iEndPoint);
if( iEndBar>=0 && ( iEndBar<m_iHitBar
|| iEndBar==m_iHitBar && iEndPoint<m_iHitPoint+10 )){
m_panelBarsShow->SetModifyPos(false, -1, -1);
}
}
}
if (m_bIsBeginSel && m_bModifyRecord) {
// Here we must judge the mouse button
if (m_btnBeginPos->Enabled && m_btnBeginPos->Down ||
m_btnEndPos->Enabled && m_btnEndPos->Down) {
X += 6;
Y += 19;
}
int iHitType = -1;
DWORD dwHit = m_panelBarsShow->HitTest(X, Y, iHitType);
int iHitBar = LOWORD(dwHit), iHitPoint = HIWORD(dwHit);
if (iHitType > 0) {
int iBeginBar, iBeginPoint;
m_panelBarsShow->GetModifyPos(true, iBeginBar, iBeginPoint);
if (iBeginBar < 0 || iHitBar > iBeginBar ||
iHitBar == iBeginBar && iHitPoint > iBeginPoint+15) {
m_panelBarsShow->SetModifyPos(false, iHitBar, iHitPoint);
m_btnEndPos->Down = false;
}
}
}
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::BarsShowMouseLeave(TObject *Sender)
{
if( m_iHintStage!=-1 ){
m_pTimerHint->Enabled = false;
m_iHintStage = -1;
m_pStageInfoWnd->ReleaseHandle();
}
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::SaveClick(TObject *Sender)
{
PostMessage(Application->MainForm->Handle, UM_SAVEMUSIC, 0, 0);
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::LBKeySelectMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
{
int iKey = -1;
if( X>=0 && X < m_lbKeySelect->Width && Y>=0 && Y<m_lbKeySelect->Height ){
iKey = m_lbKeySelect->ItemIndex;
if( iKey>=0 ){
m_lblKey->Caption = g_strMelodyKey[iKey];
}
}
if( iKey>=0 && g_iComposeKey!=iKey ){
g_iComposeKey = iKey;
ComposeWithNewKey();
}
HidePopList( m_lbKeySelect );
}
//---------------------------------------------------------------------------
void TCompleteForm::HidePopList(CommonListBoxUnit::TListBox* pList)
{
if( pList==m_lbKeySelect )
m_btnKeyChange->Down = false;
pList->Hide();
m_panelBarsShow->SetFocus();
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::KeyChangeMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
Perform( UM_HIDEPOPCONTROL, 0, 0 );
if (!m_lbKeySelect->Visible) {
m_btnKeyChange->Down = true;
if (m_lbKeySelect->ItemIndex != g_iMelodyKey)
m_lbKeySelect->ItemIndex = g_iMelodyKey;
m_lbKeySelect->Show();
m_lbKeySelect->SetFocus();
}
}
//---------------------------------------------------------------------------
void TCompleteForm::ComposeWithNewKey()
{
if( m_panelBarsShow->IsPlaying() ){
StopClick( NULL );
}
ReloadCompose( g_iComposeKey );
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::HintTimerProc(TObject* Sender)
{
m_pTimerHint->Enabled = false;
if( m_iHintStage==-1 )
return;
String strHint = GetElementInfo( m_iHintStage, LIST_COMPOSESTAGES ).c_str();
TPoint point = Mouse->CursorPos;
point.y -= 16;
m_pStageInfoWnd->ShowHintWindow( point, strHint);
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
{
switch( Key ){
case VK_F8:
if( m_btnPrevStep->Enabled ){
StepClick( m_btnPrevStep );
}
break;
case VK_F6:
if( m_btnSave->Enabled ){
SaveClick( NULL );
}
break;
case VK_UP: case VK_DOWN:
break;
case VK_RETURN:
if( m_lbKeySelect->Visible ){
int iSel = m_lbKeySelect->ItemIndex;
if( iSel!=g_iComposeKey ){
m_lblKey->Caption = g_strMelodyKey[iSel];
g_iComposeKey = iSel;
ComposeWithNewKey();
}
HidePopList( m_lbKeySelect );
}
break;
case VK_ESCAPE:
if( m_lbKeySelect->Visible ){
HidePopList( m_lbKeySelect );
}
if( m_panelSpeakerVolSet->Visible ){
m_panelSpeakerVolSet->Hide();
m_btnVolSpeakerSet->Down = false;
}
if( m_panelMicrophoneVolSet->Visible ){
m_panelMicrophoneVolSet->Hide();
m_btnVolMicrophoneSet->Down = false;
}
break;
case ' ':
if( m_btnPause->Visible && m_btnPause->Enabled ){
PauseClick( NULL );
}
else if( m_btnPlay->Visible && m_btnPlay->Enabled ){
PlayClick( NULL );
}
else if( m_btnStop->Enabled ){
StopClick( NULL );
}
break;
case 'W':
if( m_panelBarsShow->IsPlaying() ){
StopClick( NULL );
}
if( g_lstCompleteVols.size()>0 ){
m_iStartBar = m_iLastStartBar = 0;
m_dblStartPoint = m_dblLastStartPoint = 0;
m_panelBarsShow->SetPlayPoint( 0, 0 );
ShowPlayTime();
}
break;
case 'R':
if( m_btnRecord->Enabled && !m_btnRecord->Down ){
RecordClick( NULL );
}
break;
case 'P':
if( m_btnModify->Enabled ){
ModifyClick( NULL );
}
break;
case 'B':
if( m_btnBeginPos->Enabled ){
BeginPosClick( NULL );
}
break;
case 'E':
if( m_btnEndPos->Enabled ){
EndPosClick( NULL );
}
break;
/* case 'K':
if( m_btnKeyChange->Enabled ){
BtnKeyChangeClick( NULL );
}
break;
*/
default:
break;
}
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::BarsShowMouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
m_bDragOrHit = false;
int iHitType = -1;
DWORD dwHit = m_panelBarsShow->HitTest(X, Y, iHitType);
int iHitBar = LOWORD(dwHit), iHitPoint = HIWORD(dwHit);
if( iHitBar == m_iHitBar && abs(iHitPoint - m_iHitPoint)<2
&& !m_btnBeginPos->Down && !m_btnEndPos->Down ){
m_iLastStartBar = m_iStartBar = iHitBar;
m_dblLastStartPoint = m_dblStartPoint = iHitPoint;
m_panelBarsShow->SetPlayPoint( m_iStartBar, (int)m_dblStartPoint );
ShowPlayTime();
if( m_btnPlay->Down ){
double dblComposeStartPoint = m_iStartBar + m_dblStartPoint / POINTS_PER_BAR ;
f_MM_Play( Handle, dblComposeStartPoint, TYPE_SONG_COMPOSE );
}
}
if (m_bIsBeginSel && m_bModifyRecord) {
m_bIsBeginSel = FALSE;
if (Button == mbLeft) {
if (m_btnBeginPos->Enabled && m_btnBeginPos->Down ||
m_btnEndPos->Enabled && m_btnEndPos->Down) {
X += 6;
Y += 19;
}
int iHitType = -1;
DWORD dwHit = m_panelBarsShow->HitTest(X, Y, iHitType);
int iHitBar = LOWORD(dwHit), iHitPoint = HIWORD(dwHit);
if (iHitType > 0) {
int iBeginBar, iBeginPoint;
m_panelBarsShow->GetModifyPos(true, iBeginBar, iBeginPoint);
if (iBeginBar < 0 || iHitBar > iBeginBar ||
iHitBar == iBeginBar && iHitPoint > iBeginPoint+15) {
m_panelBarsShow->SetModifyPos(false, iHitBar, iHitPoint);
m_btnEndPos->Down = false;
}
}
}
}
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::EnableNextStep( bool bEnabled )
{
m_btnSave->Enabled = bEnabled;
m_btnUpload->Enabled = bEnabled;
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::AuidoEffectClick(TObject *Sender)
{
StopClick( NULL );
PostMessage(Application->MainFormHandle, UM_AUDIOEFFECT, WPARAM(0),LPARAM(0));
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::UploadClick(TObject *Sender)
{
// PostMessage(Application->MainForm->Handle, UM_UPLOADMUSIC, 0, 0);
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::MicSetClick(TObject *Sender)
{
/* StopClick( NULL );
m_panelMicrophoneVolSet->Visible = false;
m_btnVolMicrophoneSet->Down = false;
m_panelSpeakerVolSet->Visible = false;
m_btnVolSpeakerSet->Down = false;
*/
PostMessage(Application->MainFormHandle, UM_MICSETTING, WPARAM(0),LPARAM(0));
}
//---------------------------------------------------------------------------
void TCompleteForm::ShowErrorMessage( int errcode )
{
String msg;
if( errcode==46 ){
msg += L"录音设备被其它程序占用。";
}
else if( errcode==6 ){
msg += L"录音设备不支持所需格式。";
}
else if( errcode==1 ){
msg += L"内存空间不足。";
}
else if( errcode==37 ){
msg += L"录音设备无法打开。";
}
else if( errcode==3 ){
msg += L"录音设备驱动无效。";
}
else if( errcode==23 ){
msg += L"录音设备不可用。";
}
else{
msg += L"录音设备启动失败。";
}
MessageForm->ShowMessage( msg, MB_ICONERROR|MB_OK );
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::BarsShowDblClick(TObject *Sender)
{
if (!m_btnRecord->Down) {
TPoint pt;
GetCursorPos(&pt);
pt = m_panelBarsShow->ScreenToClient(pt);
int iHitType = -1;
DWORD dwHit = m_panelBarsShow->HitTest(pt.X, pt.Y, iHitType);
if( ( iHitType==0||iHitType==1 ) && m_bModifyRecord ){
int iHitBar = LOWORD(dwHit), iHitPoint = HIWORD(dwHit);
int iModifyBar, iModifyPoint;
int deltaX = iHitType ? 3 : 6;
m_panelBarsShow->GetModifyPos(true, iModifyBar, iModifyPoint);
if( iModifyBar==iHitBar && iModifyPoint+deltaX>iHitPoint
&& iModifyPoint-deltaX<iHitPoint ){
m_panelBarsShow->SetModifyPos(true, -1, -1);
return;
}
m_panelBarsShow->GetModifyPos(false, iModifyBar, iModifyPoint);
if( iModifyBar==iHitBar && iModifyPoint+deltaX>iHitPoint
&& iModifyPoint-deltaX<iHitPoint ){
m_panelBarsShow->SetModifyPos(false, -1, -1);
return;
}
}
}
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::OnPlayOver(TMessage &msg)
{
StopClick(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::UMSetFontPosition(TMessage &msg)
{
if( g_btnFontChange && g_panelFontName && g_lbFontSelect ){
g_btnFontChange->Parent = this;
g_panelFontName->Parent = this;
g_lbFontSelect->Parent = this;
g_btnFontChange->Top = m_btnVolSpeakerSet->Top;
g_panelFontName->Top = g_btnFontChange->Top + 1;
g_lbFontSelect->Top = g_btnFontChange->Top - g_lbFontSelect->Height;
// if( g_iWindowState==wsMaximized )
g_btnFontChange->Left = 451;
// else
// g_btnFontChange->Left = m_panelVolLevel->Left + m_panelVolLevel->Width + 10;
g_panelFontName->Left = g_btnFontChange->Left + g_btnFontChange->Width;
g_lbFontSelect->Left = g_panelFontName->Left;
}
}
//---------------------------------------------------------------------------
void __fastcall TCompleteForm::UMHidePopControl(TMessage &msg)
{
if( m_lbKeySelect->Visible ){
m_lbKeySelect->Hide();
m_btnKeyChange->Down = false;
}
if( g_lbFontSelect->Visible ){
g_lbFontSelect->Hide();
g_btnFontChange->Down = false;
}
}
//---------------------------------------------------------------------------