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

1906 lines
53 KiB
C++

//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "GlobalUnit.h"
#include "ComposeFormUnit.h"
#include "MessageFormUnit.h"
#include "StyleSelFormUnit.h"
#include "CommonListboxUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "PNGButton"
#pragma resource "*.dfm"
TComposeForm *ComposeForm;
static const TCursor crDropDisabled = 0x5B,
crDeleteStage = 0x5C;
extern TPNGButton *g_btnFontChange;
extern Vcl::Extctrls::TPanel *g_panelFontName;
extern CommonListBoxUnit::TListBox *g_lbFontSelect;
//---------------------------------------------------------------------------
__fastcall TComposeForm::TComposeForm(TComponent* Owner)
: TBackgroundForm(Owner)
{
m_iStartBar = m_iLastStartBar = m_nTotalBarNum = 0;
m_dblStartPoint = m_dblLastStartPoint = 0;
m_tTimer = m_tAccuracy = 0;
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::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_lblStyleName->Font->Color = RGB(60,43,23);
m_bmpDeleteNormal = new TBitmap();
m_bmpDeleteNormal->LoadFromResourceName(int(HInstance), L"ImgDeleteStageNormal");
m_bmpDeleteHover = new TBitmap();
m_bmpDeleteHover->LoadFromResourceName(int(HInstance), L"ImgDeleteStageHover");
m_imgDelete->Picture->Bitmap = m_bmpDeleteNormal;
//创建拖动跟随图标
m_imgDrag = new TImage(this);
m_imgDrag->Width =m_lbResource->Width;
m_imgDrag->Height = m_lbResource->ItemHeight;
m_imgDrag->Canvas->Font->Name = "黑体";
m_imgDrag->Canvas->Font->Size = m_lblKey->Font->Size;// int(9 * 96.0 / g_yDpi + 0.5);
//初始化画布,避免首次复制小图后无法显示大图
m_imgDrag->Canvas->Rectangle( 0, 0, m_imgDrag->Width, m_imgDrag->Height );
m_xImgDrag = m_yImgDrag = 0;
m_bDraging = false;
m_iDragingIndex = -1;
m_lbResource->SetDragImage( m_imgDrag );
m_lbCompose->SetDragImage( m_imgDrag );
m_panelBarsShow->SetDragImage( m_imgDrag );
m_pPopMenu = new TPopMenu(this);
Screen->Cursors[crDropDisabled] = LoadCursor(HInstance, L"DisableDropCursor");
Screen->Cursors[crDeleteStage] = LoadCursor(HInstance, L"DeleteStageCur");
m_pTimerHint = new TTimer(this);
m_pTimerHint->Enabled = false;
m_pTimerHint->Interval = TIME_HINT;
m_pTimerHint->OnTimer = HintTimerProc;
m_pStageInfoWnd = new TSkinHintWindow(this);
m_iHintStage = -1;
m_pHintObject = NULL;
// m_btnAPR->Enabled = g_bAPRAvaliable;
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::FormDestroy(TObject *Sender)
{
if( m_panelBarsShow->IsPlaying() )
StopClick( NULL );
if( m_pPopMenu )
delete m_pPopMenu;
delete m_pTimerHint;
delete m_pStageInfoWnd;
delete m_bmpDeleteNormal;
delete m_bmpDeleteHover;
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::FormResize(TObject *Sender)
{
int wOriClient = 798,
hOriClient = 494;
m_btnPrevStep->Top = Height - ( hOriClient - 460 );
m_btnNextStep->Top = m_btnPrevStep->Top;
m_btnNextStep->Left = ClientWidth - ( wOriClient - 705 );
m_imgBreakH->Width = Width - 28;
m_imgBreakI->Left = Width - ( wOriClient - 649 );
m_btnAudioEffect->Left = m_imgBreakI->Left - 60;
m_btnVolAudioSet->Top = Height - ( hOriClient - 455 );
m_btnVolMusicSet->Top = m_btnVolAudioSet->Top;
m_btnMicSet->Top = m_btnVolAudioSet->Top;
m_btnStyleChange->Top = m_btnVolAudioSet->Top;
m_panelStyleName->Top = m_btnVolAudioSet->Top + 1;
m_iResListTop = m_panelBarsShow->Top;
m_panelAudioVolSet->Top = Height - (hOriClient - 322);
m_panelMusicVolSet->Top = m_panelAudioVolSet->Top;
m_panelMusicInfo->Left = Width - ( wOriClient - 666 );
int barLeft = m_panelListIcon->Visible ? m_panelListIcon->Width : m_lbCompose->Width;
int barWidth = Width - (m_panelListIcon->Visible ? m_panelListIcon->Width : m_lbCompose->Width);
m_panelBarsShow->SetBounds( barLeft,
m_panelBarsShow->Top,
barWidth,
Height - 84 );
//计算列表框大小
CalcListSize();
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::FormActivate(TObject *Sender)
{
if( Sender ){
return;
}
m_lblBeat->Caption = g_strTimeSignature[g_iMelodyTimeSignature];
m_lblTempo->Caption = IntToStr( g_nMelodyTempo );
//调的显示
if( g_iMelodyKey>=0 ){
m_lblKey->Caption = g_strMelodyKey[g_iMelodyKey];
m_lblDiao->Visible = true;
}
else{
m_lblKey->Caption = "-";
m_lblDiao->Visible = false;
}
//风格名、音色库名、音色选择
m_lblStyleName->Caption = g_strSelectedStyleName.data();
// m_btnAPR->Down = g_bAPRActive;
if( !g_bBaseComposeLoaded){
ReloadBaseCompose();
// g_bBaseComposeLoaded = false;
}
//检测风格的变动
bool bStyleChanged = UpdateSegmentBars();
if( m_lbCompose->GetCount() != g_lstComposeStages.size())
{
m_lbResource->Clear();
m_lbCompose->Clear();
}
if( g_lstComposeStages.size()==0 /*|| m_lbCompose->GetCount() != g_lstComposeStages.size()*/){
g_bkCompose.Clear();
InitComposeStage();
ReloadCompose();
m_lbResource->Clear();
m_lbCompose->Clear();
}
else{
//检测前间奏小节数的变动
bool bBarChanged = false;
if( bStyleChanged ){
bBarChanged = UpdateStageBars();
if( bBarChanged ){
// m_lbResource->Clear();
// m_lbCompose->Clear();
ClearGlobalVars( LIST_COMPLETEVOLS );
}
}
//检测和弦的变动
// BOOL bChordModified = m_panelBarsShow->CheckModify(CHECK_CHORD) & CHECK_CHORD;
if( bBarChanged || !g_bComposeLoaded ){
g_bkCompose.Clear();
ReloadCompose();
// GenerateCompose( g_iMelodyKey, bBarChanged || !g_bSongNeedSave );
// g_bkCompose.Backup();
// m_panelBarsShow->BackupModify();
m_lbResource->Clear();
m_lbCompose->Clear();
}
else{
f_MM_SetStreamVolume( 4, g_fMusicVolume );
f_MM_SetStreamVolume( 5, g_fAudioVolume );
}
}
// m_panelBarsShow->BackupModify();
// m_btnReload->Enabled = false;
//初始化资源列表框
if( m_lbResource->Count==0 ){
InitResourceList();
}
//初始化资源列表后计算列表框大小
CalcListSize();
if( m_lbCompose->Count==0 ){
ResetComposeList();
}
//段落列表设置后初始化小节显示
m_panelBarsShow->InitialVars();
//显示资源及曲式窗口
if( !m_panelListIcon->Visible ){
m_panelResource->Show();
m_btnResourceMin->Show();
m_btnResourceMax->Hide();
m_btnResourceClose->Hide();
m_lbResource->Invalidate();
m_panelCompose->Show();
m_btnComposeMin->Show();
m_btnComposeMax->Hide();
m_btnComposeClose->Hide();
m_lbCompose->Invalidate();
}
m_nTotalBarNum = m_panelBarsShow->ComposeBarCount();
m_nAudioVolPos = 100 - g_fAudioVolume * 100;
m_nMusicVolPos = 100 - g_fMusicVolume * 100;
m_btnAudioVolPos->Top = 5 + m_nAudioVolPos;
m_btnMusicVolPos->Top = 5 + m_nMusicVolPos;
m_btnAudioVolPos->Hint = IntToStr(100-m_nAudioVolPos);
m_btnMusicVolPos->Hint = IntToStr(100-m_nMusicVolPos);
m_iStartBar = m_iLastStartBar = 0;
m_dblStartPoint = m_dblLastStartPoint = 0;
m_panelBarsShow->SetPlayPoint( 0, 0 );
ShowPlayTime();
m_panelBarsShow->SetFocus();
m_lbResource->ClearSelection();
m_lbCompose->ClearSelection();
SetFocusStage( -1 );
Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::FormDeactivate(TObject *Sender)
{
if( Application->ActiveFormHandle!=Application->MainFormHandle ){
return;
}
StopClick( NULL );
g_bCanStep = true;
if( Sender ){
if( !g_lstComposeStages.size()){
MessageForm->ShowMessage(L"曲式结构不能为空!", MB_OK | MB_ICONERROR);
g_bCanStep = false;
}else{
ReloadCompose();
}
}
if( m_panelAudioVolSet->Visible ){
m_panelAudioVolSet->Hide();
m_btnVolAudioSet->Down = false;
}
if( m_panelMusicVolSet->Visible ){
m_panelMusicVolSet->Hide();
m_btnVolMusicSet->Down = false;
}
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::StepClick(TObject *Sender)
{
PostMessage(Application->MainFormHandle, UM_JUMP_PAGE, Sender==m_btnNextStep?WPARAM(4):WPARAM(2),LPARAM(this));
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::PlayClick(TObject *Sender)
{
ReloadCompose();
if( g_bRecProtect && g_bShowProtectMsg ){
MessageForm->ShowMessage( "使用收费风格,将可能听到随机杂音\n\n但不会影响保存的歌曲",
MB_ICONINFORMATION|MB_OK|MB_UNCHECKED );
g_bShowProtectMsg = !MessageForm->GetCheckState();
Application->MainForm->Update();
}
m_nTotalBarNum = m_panelBarsShow->ComposeBarCount();
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;
}
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::StopClick(TObject *Sender)
{
if( m_panelBarsShow->IsPlaying() ){
SetPlayTimer( false, m_tTimer, m_tAccuracy );
f_MM_Stop();
m_panelBarsShow->Play( false );
}
m_btnStop->Enabled = false;
m_btnPlay->Down = false;
m_btnPlay->Visible = true;
m_btnPause->Visible = false;
m_iStartBar = m_iLastStartBar;
m_dblStartPoint = m_dblLastStartPoint;
m_panelBarsShow->SetPlayPoint( m_iStartBar, (int)m_dblStartPoint );
ShowPlayTime();
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::PauseClick(TObject *Sender)
{
if( m_panelBarsShow->IsPlaying() ){
SetPlayTimer( false, m_tTimer, m_tAccuracy );
f_MM_Stop();
m_panelBarsShow->Play( false );
}
m_btnPlay->Visible = true;
m_btnPlay->Down = false;
m_btnPause->Visible = false;
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::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 TComposeForm::BtnVolSetClick(TObject *Sender)
{
if( Sender==m_btnVolAudioSet ){
if( m_panelAudioVolSet->Visible ){
m_panelAudioVolSet->Hide();
m_btnVolAudioSet->Down = false;
}
else{
m_panelAudioVolSet->Show();
m_btnVolAudioSet->Down = true;
}
}
else if( Sender==m_btnVolMusicSet ){
if( m_panelMusicVolSet->Visible ){
m_panelMusicVolSet->Hide();
m_btnVolMusicSet->Down = false;
}
else{
m_panelMusicVolSet->Show();
m_btnVolMusicSet->Down = true;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::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_imgAudioVolSet ){
m_nAudioVolPos = yPos;
m_btnAudioVolPos->Top = yPos + 5;
m_btnAudioVolPos->Hint = IntToStr(100-m_nAudioVolPos);
g_fAudioVolume = (100-m_nAudioVolPos)/100.0;
f_MM_SetStreamVolume( 5, g_fAudioVolume );
}
else{
m_nMusicVolPos = yPos;
m_btnMusicVolPos->Top = yPos + 5;
m_btnMusicVolPos->Hint = IntToStr(100-m_nMusicVolPos);
g_fMusicVolume = (100-m_nMusicVolPos)/100.0;
f_MM_SetStreamVolume( 4, g_fMusicVolume );
}
}
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::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 TComposeForm::BtnVolPosMouseMove(TObject *Sender, TShiftState Shift, int X, int Y)
{
if( m_bPosDraging==true ){
int yPos = (Sender==m_btnAudioVolPos)?m_nAudioVolPos:m_nMusicVolPos;
yPos += Y - m_yPosDragBegin;
if( yPos<0 )
yPos = 0;
else if( yPos>100 )
yPos = 100;
if( Sender==m_btnAudioVolPos ){
m_nAudioVolPos = yPos;
m_btnAudioVolPos->Top = yPos + 5;
}
else{
m_nMusicVolPos = yPos;
m_btnMusicVolPos->Top = yPos + 5;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::BtnVolPosMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
{
if( Button==mbLeft && m_bPosDraging ){
m_bPosDraging = false;
if( Sender==m_btnAudioVolPos ){
m_btnAudioVolPos->Hint = IntToStr(100-m_nAudioVolPos);
g_fAudioVolume = (100-m_nAudioVolPos)/100.0;
f_MM_SetStreamVolume( 5, g_fAudioVolume );
}
else{
m_btnMusicVolPos->Hint = IntToStr(100-m_nMusicVolPos);
g_fMusicVolume = (100-m_nMusicVolPos)/100.0;
f_MM_SetStreamVolume( 4, g_fMusicVolume );
}
}
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::BarsShowMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
{
m_panelBarsShow->SetFocus();
if( Button!=mbLeft && Button!=mbRight )
return;
if( m_iHintStage!=-1 ){
m_iHintStage = -1;
m_pHintObject = NULL;
m_pTimerHint->Enabled = false;
m_pStageInfoWnd->ReleaseHandle();
}
if( m_panelAudioVolSet->Visible ){
m_panelAudioVolSet->Hide();
m_btnVolAudioSet->Down = false;
}
if( m_panelMusicVolSet->Visible ){
m_panelMusicVolSet->Hide();
m_btnVolMusicSet->Down = false;
}
// if( !m_btnReload->Down ){
int iHitType = -1;
DWORD dwHit = m_panelBarsShow->HitTest( X, Y, iHitType );
int iHitBar = LOWORD(dwHit),
iHitPoint = HIWORD(dwHit);
if( iHitType==2 || iHitType==0 && Sender!=m_panelBarsShow ){
int iStage = m_panelBarsShow->FindStage( iHitBar );
//设置选中段
m_lbResource->ClearSelection();
m_lbCompose->ItemIndex = iStage;
SetFocusStage( iStage );
}
else if( iHitType!=1 ){
m_lbResource->ClearSelection();
m_lbCompose->ClearSelection();
SetFocusStage( -1 );
}
CheckOperationState();
if( iHitType>0 && Button==mbLeft && Sender==m_panelBarsShow ){
BarsLButtonDown( iHitType, iHitBar, iHitPoint, X, Y );
}
else if( Button==mbRight && ( iHitType>0 || iHitType==0 && Sender!=m_panelBarsShow )){
TPoint point(X,Y);
point = m_panelBarsShow->ClientToScreen(point);
BarsRButtonDown( iHitType, iHitBar, iHitPoint, point.x, point.y );
}
// }
}
//---------------------------------------------------------------------------
void TComposeForm::InitResourceList()
{
m_lbResource->Clear();
m_lbResource->Items->BeginUpdate();
String strText;
for( int i=0; i<MAX_INTRO_NUM; i++ ){
if( g_arrIntroBarNum[i]>0 ){
strText.printf( L"(%d小节)", g_arrIntroBarNum[i] );
m_lbResource->AddItem( g_strIntro[i]+strText, (TObject*)(COMPOSE_INTRO_1 + i) );
}
}
for( int i=0; i<g_lstMelodyStages.size(); i++ ){
MELODYSTAGE *pMStage = g_lstMelodyStages[i];
strText = String(GetStageName( i ).c_str()) + L"段 " + String(g_strStageVar[pMStage->iVar]);
m_lbResource->AddItem( strText, (TObject*)(MAKELONG(i, pMStage->iVar)) );
}
for( int i=0; i<MAX_ENDING_NUM; i++ ){
if( g_arrEndingBarNum[i]>0 ){
strText.printf( L"(%d小节)", g_arrEndingBarNum[i] );
m_lbResource->AddItem( g_strEnding[i]+strText, (TObject*)(COMPOSE_ENDING_1 + i) );
}
}
m_lbResource->Items->EndUpdate();
m_lbResource->Invalidate();
}
//---------------------------------------------------------------------------
void TComposeForm::ResetComposeList()
{
m_lbCompose->Clear();
m_lbCompose->Items->BeginUpdate();
for( int i=0; i<g_lstComposeStages.size(); i++ ){
String strText;
COMPOSESTAGE* pCStage = g_lstComposeStages[i];
if( pCStage->iMelodyStage>=COMPOSE_ENDING_1 ){
int iEnding = pCStage->iMelodyStage - COMPOSE_ENDING_1;
strText.printf( L"(%d小节)", pCStage->nStageBars );
m_lbCompose->AddItem( g_strEnding[iEnding]+strText,
(TObject*)pCStage->iMelodyStage );
}
else if( pCStage->iMelodyStage>=COMPOSE_INTRO_1 ){
int iIntro = pCStage->iMelodyStage - COMPOSE_INTRO_1;
strText.printf( L"(%d小节)", pCStage->nStageBars );
m_lbCompose->AddItem( g_strIntro[iIntro]+strText,
(TObject*)pCStage->iMelodyStage );
}
else{
strText = String(GetStageName( pCStage->iMelodyStage ).c_str()) +
L"段 " + String(g_strStageVar[pCStage->iVar]);
m_lbCompose->AddItem( strText, (TObject*)(MAKELONG(pCStage->iMelodyStage, pCStage->iVar)) );
}
}
m_lbCompose->Items->EndUpdate();
m_lbCompose->Invalidate();
}
//---------------------------------------------------------------------------
/*
bool TComposeForm::Compose(bool bCombineSong)
{
if( m_panelBarsShow->IsPlaying() ){
StopClick( NULL );
}
bool bRet = GenerateCompose( g_iMelodyKey, bCombineSong );
// m_btnReload->Enabled = !bRet;
return bRet;
}
//---------------------------------------------------------------------------
*/
void TComposeForm::ShowPlayTime()
{
char strTime[10];
GetPlayTime( m_iStartBar, m_dblStartPoint, strTime );
m_lblPlayTime->Caption = strTime;
}
//---------------------------------------------------------------------------
void TComposeForm::BarsLButtonDown( int iHitType, int iHitBar, int iHitPoint, int X, int Y )
{
if( iHitType==1 ){ //设置播放位置
if( m_panelBarsShow->IsPlaying() ){
SetPlayTimer( false, m_tTimer, m_tAccuracy );
f_MM_Stop();
}
m_iLastStartBar = m_iStartBar = iHitBar;
m_dblLastStartPoint = m_dblStartPoint = iHitPoint;
m_panelBarsShow->SetPlayPoint( m_iStartBar, (int)m_dblStartPoint );
ShowPlayTime();
if( m_panelBarsShow->IsPlaying() ){
ReloadCompose();
double dblComposeStartPoint = m_iStartBar + m_dblStartPoint / POINTS_PER_BAR ;
f_MM_Play( Handle, dblComposeStartPoint, TYPE_SONG_COMPOSE );
SetPlayTimer( true, m_tTimer, m_tAccuracy, Handle );
}
}
else if( iHitType==2 ){ //开始拖动
int iStage = m_panelBarsShow->FindStage( iHitBar );
DrawDragImg( m_lbCompose, iStage );
SetCapture( m_panelBarsShow->Handle );
m_xImgDrag = - m_imgDrag->Width/2;
m_yImgDrag = - m_imgDrag->Height/2;
m_lbResource->SetDragState( true );
m_lbCompose->SetDragState( true );
m_panelBarsShow->SetDragState( true );
m_lbCompose->SetDragStage( false, iStage );
m_panelBarsShow->SetDragStage( false, iStage );
m_iDragingIndex = iStage;
m_bDraging = true;
m_btnAdd->ShowHint = false;
m_btnMoveUp->ShowHint = false;
m_btnMoveDown->ShowHint = false;
}
}
//---------------------------------------------------------------------------
void TComposeForm::BarsRButtonDown( int iHitType, int iHitBar, int iHitPoint, int X, int Y )
{
m_pPopMenu->ClearMenuItem();
if( iHitType==0 || iHitType==2 ){ //设置段落伴奏类型
int iStage = m_panelBarsShow->FindStage( iHitBar );
COMPOSESTAGE* pCStage = g_lstComposeStages[iStage];
if( pCStage->iMelodyStage<COMPOSE_INTRO_1 ){
int iVar = pCStage->iVar;
for( int i=0; i<STAGE_VAR_NUM; i++ ){
bool bChecked = false;
if( iVar==i ) bChecked = true;
String strText = "伴奏类型 " + IntToStr( i+1 );
m_pPopMenu->CreateCustomMenuItem( strText, OnSelectStageVar, -1, true, bChecked, i|SHOW_STAGE_VAR );
}
m_pPopMenu->CreateCustomMenuItem( "-" );
}
if( pCStage->idStyle!=g_iSelectedStyleID ){
String strText = "全局风格 - ";
strText += g_strSelectedStyleName.c_str();
m_pPopMenu->CreateCustomMenuItem( strText,
OnSetStageStyle, -1, true, false, g_iSelectedStyleID );
}
m_pPopMenu->CreateCustomMenuItem( "选择风格...", OnSetStageStyle );
m_pPopMenu->CreateCustomMenuItem( "-" );
m_pPopMenu->CreateCustomMenuItem( "移除段落", OnDeleteStage );
m_pPopMenu->Tag = iStage;
}
else if( iHitType==1 ){ //设置加花类型
int iFirstBar, iStage = m_panelBarsShow->FindStage( iHitBar, & iFirstBar );
COMPOSESTAGE* pCStage = g_lstComposeStages[iStage];
if( pCStage->iMelodyStage<COMPOSE_INTRO_1 ){
int iFill = -1;
for( int i=0; i<pCStage->aFills.size(); i++ ){
int iPos = LOWORD(pCStage->aFills[i]),
iType = HIWORD(pCStage->aFills[i]);
if( iPos==iHitBar-iFirstBar ){
iFill = iType;
break;
}
}
for( int i=0; i<COMPOSE_FILL_NUM; i++ ){
bool bChecked = false;
if( iFill==i ) bChecked = true;
String strText = "加花-" + IntToStr( i+1 );
m_pPopMenu->CreateCustomMenuItem( strText, OnSelectBarFill, -1, true, bChecked, i );
}
m_pPopMenu->Tag = iHitBar;
}
}
m_pPopMenu->Popup(X, Y);
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::OnSelectStageVar( TObject* Sender )
{
TMenuItem* pItem = (TMenuItem*)Sender;
if( !pItem->Checked ){
int iSetStage = m_pPopMenu->Tag;
int iVar = pItem->Tag & 0xFFFF;
m_panelBarsShow->SetStageVar( iSetStage, iVar );
COMPOSESTAGE* pCStage = g_lstComposeStages[iSetStage];
String strText = String(GetStageName( pCStage->iMelodyStage ).c_str()) + L"段 " +
String(g_strStageVar[pCStage->iVar]);
m_lbCompose->Items->Strings[iSetStage] = strText;
m_lbCompose->Items->Objects[iSetStage] = (TObject*)(MAKELONG(pCStage->iMelodyStage, iVar));
m_lbCompose->Invalidate();
}
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::OnSetStageStyle( TObject* Sender )
{
TMenuItem* pItem = (TMenuItem*)Sender;
int iSetStage = m_pPopMenu->Tag;
int idStyle = pItem->Tag;
StopClick(NULL);
if( idStyle<=0 ){
PostMessage( Handle, UM_SELECTSTYLE, 0, 0 );
}
else{
int iMelodyStage = g_lstComposeStages[iSetStage]->iMelodyStage;
g_lstComposeStages[iSetStage]->idStyle = g_iSelectedStyleID;
g_lstComposeStages[iSetStage]->strStyleName = "";
m_lblStyleName->Caption = g_strSelectedStyleName.c_str();
bool bBarChanged = UpdateStageBars();
if( bBarChanged )
g_bkCompose.Clear();
ReloadCompose();
// Compose( bBarChanged || !g_bSongNeedSave );
// m_panelBarsShow->BackupModify();
// m_btnReload->Enabled = false;
//重置曲式列表框
if( bBarChanged ){
m_panelBarsShow->InitialVars();
int iSelIndex = m_lbCompose->ItemIndex;
ResetComposeList();
m_lbCompose->ItemIndex = iSelIndex;
m_nTotalBarNum = m_panelBarsShow->ComposeBarCount();
}
Application->MainForm->Update();
}
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::OnSelectBarFill( TObject* Sender )
{
TMenuItem* pItem = (TMenuItem*)Sender;
int iSetBar = m_pPopMenu->Tag;
int iFill = pItem->Tag;
if( pItem->Checked )//取消原状态
iFill = -1;
m_panelBarsShow->SetBarFill( iSetBar, iFill );
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::OnAddStage( TObject* Sender )
{
DWORD dwItemData = DWORD(m_lbResource->Items->Objects[m_pPopMenu->Tag]);
AddStage( LOWORD(dwItemData) );
CheckOperationState();
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::OnDeleteStage( TObject* Sender )
{
DeleteStage( m_pPopMenu->Tag );
CheckOperationState();
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::UMMediaTime(TMessage &Message)
{
if( !m_panelBarsShow->IsPlaying() )
return;
int iBar = m_iStartBar;
double dblStartPoint = m_dblStartPoint + g_dblStep;
if( dblStartPoint>=(double)POINTS_PER_BAR ){
dblStartPoint -= POINTS_PER_BAR;
iBar++;
}
int iCurrPoint = (int)dblStartPoint;
if( iBar!=m_iStartBar || iCurrPoint!=(int)m_dblStartPoint ){
if( iBar==m_nTotalBarNum ){
StopClick(NULL);
return;
}
m_panelBarsShow->SetPlayPoint( iBar, (int)dblStartPoint );
}
m_iStartBar = iBar;
m_dblStartPoint = dblStartPoint;
ShowPlayTime();
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::UMReload(TMessage &msg)
{
if( msg.WParam ){
StopClick( NULL );
}
if( m_panelBarsShow->IsPlaying() ){
SetPlayTimer( false, m_tTimer, m_tAccuracy );
f_MM_Stop();
}
BOOL bModified = g_bkCompose.CheckModified();
if( bModified & CHECK_STAGE || bModified & CHECK_POS ){
ClearGlobalVars( LIST_COMPLETEVOLS );
g_bSongNeedSave = false;
}
ReloadCompose();
m_nTotalBarNum = m_panelBarsShow->ComposeBarCount();
if( m_panelBarsShow->IsPlaying() ){
double dblComposeStartPoint = m_iStartBar + m_dblStartPoint / POINTS_PER_BAR ;
f_MM_Play( Handle, dblComposeStartPoint, TYPE_SONG_COMPOSE );
SetPlayTimer( true, m_tTimer, m_tAccuracy, Handle );
}
}
//---------------------------------------------------------------------------
/*
void __fastcall TComposeForm::UMEnableReload(TMessage &Message)
{
if( g_lstComposeStages.size()==0 ){
// m_btnReload->Enabled = false;
m_btnPlay->Enabled = false;
}
else{
// m_btnReload->Enabled = Message.WParam;
if( !m_btnPlay->Enabled )
m_btnPlay->Enabled = true;
if( ( Message.WParam & CHECK_POS || Message.WParam & CHECK_STAGE ) &&
m_panelBarsShow->IsPlaying() ){
StopClick( NULL );
m_iStartBar = m_iLastStartBar = 0;
m_dblStartPoint = m_dblLastStartPoint = 0;
m_panelBarsShow->SetPlayPoint( 0, 0 );
ShowPlayTime();
}
}
}
//---------------------------------------------------------------------------
*/
void TComposeForm::AddStage( int iMelodyStage )
{
StopClick( NULL );
m_iStartBar = m_iLastStartBar = 0;
m_dblStartPoint = m_dblLastStartPoint = 0;
m_panelBarsShow->SetPlayPoint( 0, 0 );
ShowPlayTime();
m_lbCompose->AddStage( iMelodyStage );
m_panelBarsShow->AddStage( iMelodyStage );
}
//---------------------------------------------------------------------------
void TComposeForm::DeleteStage( int iComposeStage )
{
if( g_lstComposeStages.size()==1 ){
MessageForm->ShowMessage(L"曲式结构不能为空!", MB_OK | MB_ICONERROR);
return;
}
StopClick( NULL );
m_iStartBar = m_iLastStartBar = 0;
m_dblStartPoint = m_dblLastStartPoint = 0;
m_panelBarsShow->SetPlayPoint( 0, 0 );
ShowPlayTime();
m_lbCompose->DeleteStage( iComposeStage );
m_panelBarsShow->DeleteStage( iComposeStage );
// UpdateGlobalStyle();
// m_lblStyleName->Caption = g_strSelectedStyleName.c_str();
}
//---------------------------------------------------------------------------
void TComposeForm::DrawDragImg( TObject* Sender, int iSelIndex )
{
TSkinListBox* pLBSender = (TSkinListBox*)Sender;
TRect rcSel = pLBSender->ItemRect(iSelIndex);
m_imgDrag->Width = rcSel.Width()-4;
m_imgDrag->Height = rcSel.Height()-2;
TRect rcDraw( 0, 0, m_imgDrag->Width, m_imgDrag->Height );
//绘制底色
COLORREF rColor;
DWORD dwItemData = DWORD(pLBSender->Items->Objects[iSelIndex]);
WORD iVar = HIWORD( dwItemData );
int iInd = LOWORD( dwItemData );
if( iInd>=COMPOSE_ENDING_1 ){
rColor = g_clrEnding[iInd-COMPOSE_ENDING_1];
}
else if( iInd>=COMPOSE_INTRO_1 ){
rColor = g_clrIntro[iInd-COMPOSE_INTRO_1];
}
else{
rColor = g_clrStage[iVar];
}
m_imgDrag->Canvas->Brush->Color = rColor;
m_imgDrag->Canvas->FillRect( rcDraw );
//绘制列表项文字
m_imgDrag->Canvas->Brush->Style = bsClear;
String strText = pLBSender->Items->Strings[iSelIndex];
int nTextWidth = m_imgDrag->Canvas->TextWidth( strText ),
nTextHeight = m_imgDrag->Canvas->TextHeight( strText );
if( nTextWidth>rcDraw.Width()-4 ){
strText = strText.SubString(0, 8) + "...";
nTextWidth = m_imgDrag->Canvas->TextWidth( strText );
}
int x = rcDraw.left + ( rcDraw.Width() - nTextWidth ) / 2,
y = rcDraw.top + ( rcDraw.Height() - nTextHeight ) / 2 + 1;
m_imgDrag->Canvas->TextOut( x, y, strText );
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::ListBoxMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
if( m_iHintStage!=-1 ){
m_iHintStage = -1;
m_pHintObject = NULL;
m_pTimerHint->Enabled = false;
m_pStageInfoWnd->ReleaseHandle();
}
if( Sender==m_lbCompose ){
m_lbResource->ClearSelection();
}
else{
m_lbCompose->ClearSelection();
SetFocusStage( -1 );
}
ComposeListBoxUnit::TListBox *pLBSender = (ComposeListBoxUnit::TListBox *)Sender;
int iSelIndex = pLBSender->ItemAtPos(TPoint(X,Y),true);
if( iSelIndex==-1 ){
pLBSender->ItemIndex = -1;
if( pLBSender==m_lbCompose ){
SetFocusStage( -1 );
}
CheckOperationState();
return;
}
if(Button==mbLeft){
if( Shift.Contains(ssDouble) ){
if( Sender==m_lbResource ){ //双击添加
DWORD dwItemData = DWORD(pLBSender->Items->Objects[iSelIndex]);
AddStage( LOWORD(dwItemData) );
//m_lbResource->ClearSelection();
}
}
else{ //开始拖动
DrawDragImg( Sender, iSelIndex );
TRect rcSel = pLBSender->ItemRect(iSelIndex);
m_xImgDrag = rcSel.left + 1 - X;
m_yImgDrag = rcSel.top + 1 - Y;
SetCapture( pLBSender->Handle );
m_lbResource->SetDragState( true );
m_lbCompose->SetDragState( true );
m_panelBarsShow->SetDragState( true );
if( pLBSender==m_lbCompose ){ //设置选中段
SetFocusStage( iSelIndex );
m_lbCompose->SetDragStage( false, iSelIndex );
m_panelBarsShow->SetDragStage( false, iSelIndex );
m_iDragingIndex = iSelIndex;
}
else{
DWORD dwItemData = DWORD(pLBSender->Items->Objects[iSelIndex]);
m_lbCompose->SetDragStage( true, LOWORD(dwItemData) );
m_panelBarsShow->SetDragStage( true, LOWORD(dwItemData) );
m_iDragingIndex = LOWORD( dwItemData );
}
m_bDraging = true;
m_btnAdd->ShowHint = false;
m_btnMoveUp->ShowHint = false;
m_btnMoveDown->ShowHint = false;
CheckOperationState();
}
}
else if(Button==mbRight){ //右键菜单
m_pPopMenu->ClearMenuItem();
pLBSender->ItemIndex = iSelIndex;
if( pLBSender==m_lbCompose ){
SetFocusStage( iSelIndex );
COMPOSESTAGE* pCStage = g_lstComposeStages[iSelIndex];
if( pCStage->iMelodyStage<COMPOSE_INTRO_1 ){
int iVar = pCStage->iVar;
for( int i=0; i<STAGE_VAR_NUM; i++ ){
bool bChecked = false;
if( iVar==i ) bChecked = true;
String strText = "伴奏类型 " + IntToStr( i+1 );
m_pPopMenu->CreateCustomMenuItem( strText, OnSelectStageVar, -1, true, bChecked, i|SHOW_STAGE_VAR );
}
m_pPopMenu->CreateCustomMenuItem( "-" );
}
m_pPopMenu->CreateCustomMenuItem( "移除段落", OnDeleteStage );
}
else{
m_pPopMenu->CreateCustomMenuItem( "添加段落", OnAddStage );
}
CheckOperationState();
m_pPopMenu->Tag = iSelIndex;
TPoint point(X,Y);
point = pLBSender->ClientToScreen(point);
m_pPopMenu->Popup(point.x, point.y);
}
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::StageMouseMove(TObject *Sender, TShiftState Shift, int X, int Y)
{
if( m_bDraging ){ //显示拖动
TWinControl* pSender = (TWinControl*)Sender;
TPoint ptClient(X, Y), ptScreen = pSender->ClientToScreen( ptClient );
bool bInDropArea = false;
ptClient = m_lbCompose->ScreenToClient( ptScreen );
if( ptClient.x>0 && ptClient.x<m_lbCompose->Width &&
ptClient.y>0 && ptClient.y<m_lbCompose->Height ){
m_panelBarsShow->SetDragingPoint( -1, -1 );
if( m_lbCompose->SetDragingPoint( ptClient.x, ptClient.y ) )
Screen->Cursor = crDefault;
else
Screen->Cursor = crDropDisabled;
bInDropArea = true;
}
ptClient = m_panelBarsShow->ScreenToClient( ptScreen );
if( ptClient.x>0 && ptClient.x<m_panelBarsShow->Width &&
ptClient.y>0 && ptClient.y<m_panelBarsShow->Height ){
m_lbCompose->SetDragingPoint( -1, -1 );
if( m_panelBarsShow->SetDragingPoint( ptClient.x, ptClient.y ) )
Screen->Cursor = crDefault;
else
Screen->Cursor = crDropDisabled;
bInDropArea = true;
}
ptClient = m_imgDelete->ScreenToClient( ptScreen );
if( Sender!=m_lbResource && ptClient.x>0 && ptClient.x<m_imgDelete->Width &&
ptClient.y>0 && ptClient.y<m_imgDelete->Height ){
Screen->Cursor = crDeleteStage;
m_imgDelete->Picture->Bitmap = m_bmpDeleteHover;
bInDropArea = true;
}
else{
m_imgDelete->Picture->Bitmap = m_bmpDeleteNormal;
}
if( !bInDropArea ){
Screen->Cursor = crDropDisabled;
m_panelBarsShow->SetDragingPoint( -1, -1 );
m_lbCompose->SetDragingPoint( -1, -1 );
}
int xImgDrag = ptScreen.x+m_xImgDrag,
yImgDrag = ptScreen.y+m_yImgDrag;
m_lbResource->SetDragImgPos( xImgDrag, yImgDrag );
m_lbCompose->SetDragImgPos( xImgDrag, yImgDrag );
m_panelBarsShow->SetDragImgPos( xImgDrag, yImgDrag );
}
else{ //显示段落信息
int iHintStage = -1;
if( Sender==m_panelBarsShow ){
int iHitType = -1;
DWORD dwHit = m_panelBarsShow->HitTest( X, Y, iHitType );
int iHitBar = LOWORD(dwHit);
if( iHitType==2 ){
iHintStage = m_panelBarsShow->FindStage( iHitBar );
}
}
else{
TSkinListBox * pLBSender = (TSkinListBox *)Sender;
iHintStage = pLBSender->ItemAtPos(TPoint(X,Y),true);
}
if( iHintStage>=0 ){
if( iHintStage!=m_iHintStage || Sender!=m_pHintObject ){
m_pStageInfoWnd->ReleaseHandle();
m_pTimerHint->Enabled = true;
m_iHintStage = iHintStage;
m_pHintObject = Sender;
}
}
else{
if( m_iHintStage!=-1 ){
m_iHintStage = -1;
m_pHintObject = NULL;
m_pTimerHint->Enabled = false;
m_pStageInfoWnd->ReleaseHandle();
}
}
}
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::StageMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
{
if( m_bDraging ){
ReleaseCapture();
TWinControl* pSender = (TWinControl*)Sender;
TPoint ptClient(X, Y), ptScreen = pSender->ClientToScreen( ptClient );
ptClient = m_lbCompose->ScreenToClient( ptScreen );
if( ptClient.x>0 && ptClient.x<m_lbCompose->Width &&
ptClient.y>0 && ptClient.y<m_lbCompose->Height ){
int iInsertPos = m_lbCompose->SetDropPoint( ptClient.x, ptClient.y );
if( iInsertPos>=0 ){
if( Sender==m_lbResource ){
m_panelBarsShow->InsertStage( m_iDragingIndex, iInsertPos );
}
else{
m_panelBarsShow->MoveStage( m_iDragingIndex, iInsertPos );
}
}
}
ptClient = m_panelBarsShow->ScreenToClient( ptScreen );
if( ptClient.x>0 && ptClient.x<m_panelBarsShow->Width &&
ptClient.y>0 && ptClient.y<m_panelBarsShow->Height ){
int iInsertPos = m_panelBarsShow->SetDropPoint( ptClient.x, ptClient.y );
if( iInsertPos>=0 ){
if( Sender==m_lbResource ){
m_lbCompose->InsertStage( m_iDragingIndex, iInsertPos );
}
else{
m_lbCompose->MoveStage( m_iDragingIndex, iInsertPos );
}
}
}
ptClient = m_imgDelete->ScreenToClient( ptScreen );
if( Sender!=m_lbResource && ptClient.x>0 && ptClient.x<m_imgDelete->Width &&
ptClient.y>0 && ptClient.y<m_imgDelete->Height ){
DeleteStage( m_iDragingIndex );
}
m_imgDelete->Picture->Bitmap = m_bmpDeleteNormal;
m_lbResource->SetDragState( false );
m_lbCompose->SetDragState( false );
m_panelBarsShow->SetDragState( false );
m_iDragingIndex = -1;
m_bDraging = false;
Screen->Cursor = crDefault;
m_btnAdd->ShowHint = false;
m_btnMoveUp->ShowHint = false;
m_btnMoveDown->ShowHint = false;
CheckOperationState();
}
}
//---------------------------------------------------------------------------
/*
void __fastcall TComposeForm::LBFontSelectMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
if( X>=0 && X < m_lbFontSelect->Width && Y>=0 && Y<m_lbFontSelect->Height ){
// if( X>m_lbFontSelect->Width - 19 ) //滚动条位置
// return;
int iSel = m_lbFontSelect->ItemIndex;
if( iSel>=0 ){
if( iSel!=g_idFont ){
m_lblFontName->Caption = g_lstFonts[iSel]->strFontName;
if( f_MM_SetFont( g_lstFonts[iSel]->strFileName )==S_OK ){
g_idFont = iSel;
g_strFontFile = ExtractFileName(g_lstFonts[iSel]->strFileName).c_str();
}
}
}
}
HidePopList( m_lbFontSelect );
}
//---------------------------------------------------------------------------
void TComposeForm::HidePopList(CommonListBoxUnit::TListBox* pList)
{
pList->Hide();
m_panelBarsShow->SetFocus();
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::BtnFontChangeClick(TObject *Sender)
{
if( m_iHintStage!=-1 ){
m_iHintStage = -1;
m_pHintObject = NULL;
m_pTimerHint->Enabled = false;
m_pStageInfoWnd->ReleaseHandle();
}
m_lbResource->ClearSelection();
m_lbCompose->ClearSelection();
SetFocusStage( -1 );
if( !m_lbFontSelect->Visible ){
m_btnFontChange->Down = true;
if( m_lbFontSelect->ItemIndex != g_idFont )
m_lbFontSelect->ItemIndex = g_idFont;
m_lbFontSelect->Show();
m_lbFontSelect->SetFocus();
SetCapture( m_lbFontSelect->Handle );
}
else{
HidePopList( m_lbFontSelect );
}
}
//---------------------------------------------------------------------------
*/
void __fastcall TComposeForm::HintTimerProc(TObject* Sender)
{
m_pTimerHint->Enabled = false;
if( m_iHintStage==-1 )
return;
String strHint;
if( m_pHintObject==m_panelBarsShow ){
strHint = GetElementInfo( m_iHintStage, LIST_COMPOSESTAGES ).c_str();
}
else{
strHint = ((TSkinListBox*)m_pHintObject)->Items->Strings[m_iHintStage];
}
TPoint point = Mouse->CursorPos;
point.y -= 16;
m_pStageInfoWnd->ShowHintWindow( point, strHint);
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::StageMouseLeave(TObject *Sender)
{
if( m_iHintStage!=-1 ){
m_pTimerHint->Enabled = false;
m_iHintStage = -1;
m_pHintObject = NULL;
m_pStageInfoWnd->ReleaseHandle();
}
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::BtnListMinClick(TObject *Sender)
{
if( Sender==m_btnComposeMin ){
m_panelCompose->Height = 16;
m_panelCompose->Top = m_panelBarsShow->Top + m_panelBarsShow->Height - m_panelCompose->Height;
m_btnComposeMin->Visible = false;
m_btnComposeMax->Visible = true;
m_panelResource->Height = m_panelCompose->Top - m_panelResource->Top;
m_lbResource->Height = m_panelResource->Height - m_panelCompose->Height - 1;
m_btnResourceMin->Visible = false;
m_btnResourceClose->Visible = true;
m_lbResource->Invalidate();
m_lbResource->SetFocus();
}
else{
m_panelResource->Height = 17;
m_btnResourceMin->Visible = false;
m_btnResourceMax->Visible = true;
m_panelCompose->Top = m_panelResource->Top + m_panelResource->Height;
m_panelCompose->Height = m_panelBarsShow->Height - m_panelResource->Height;
m_lbCompose->Height = m_panelCompose->Height - 31;
m_panelComposeBottom->Top = m_panelCompose->Height - 15;
m_btnComposeMin->Visible = false;
m_btnComposeClose->Visible = true;
m_lbCompose->Invalidate();
m_lbCompose->SetFocus();
}
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::BtnListMaxClick(TObject *Sender)
{
if( Sender==m_btnComposeMax ){
m_panelCompose->Top = m_iComListTop;
m_panelCompose->Height = m_nComListHeight;
m_btnComposeMax->Visible = false;
m_btnComposeMin->Visible = true;
m_lbCompose->Hide();
m_lbCompose->Height = m_nComListHeight - 31;
m_lbCompose->Show();
m_panelComposeBottom->Top = m_nComListHeight - 15;
m_lbCompose->SetFocus();
m_panelResource->Height = m_panelCompose->Top - m_panelResource->Top;
m_btnResourceClose->Visible = false;
m_btnResourceMin->Visible = true;
m_lbResource->Hide();
m_lbResource->Height = m_panelResource->Height - 17;
m_lbResource->Show();
}
else{
m_panelResource->Height = m_nResListHeight;
m_btnResourceMax->Visible = false;
m_btnResourceMin->Visible = true;
m_lbResource->Hide();
m_lbResource->Height = m_panelResource->Height - 17;
m_lbResource->Show();
m_lbResource->SetFocus();
m_panelCompose->Height = m_nComListHeight;
m_panelCompose->Top = m_iComListTop;
m_btnComposeClose->Visible = false;
m_btnComposeMin->Visible = true;
m_lbCompose->Hide();
m_lbCompose->Height = m_nComListHeight - 31;
m_lbCompose->Show();
m_panelComposeBottom->Top = m_nComListHeight - 15;
}
}
//---------------------------------------------------------------------------
void TComposeForm::CalcListSize()
{
int hItem = m_lbCompose->ItemHeight,
hTotal = m_panelBarsShow->Height,
hResFull = (m_lbResource->Count+1)*hItem + 17,
hResPartial = hTotal * 4 / 9,
hResShow = hResFull<=hResPartial ? hResFull : hResPartial;
m_nComListHeight = ((hTotal - hResShow - 31)/hItem+1)*hItem + 31;
m_nResListHeight = hTotal - m_nComListHeight;
m_iComListTop = m_iResListTop + m_nResListHeight;
m_panelResource->Height = m_nResListHeight;
m_lbResource->Height = m_nResListHeight - 17;
m_panelCompose->Top = m_iComListTop;
m_panelCompose->Height = m_nComListHeight;
m_lbCompose->Height = m_nComListHeight - 31;
m_panelComposeBottom->Top = m_nComListHeight - 15;
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::BtnListCloseClick(TObject *Sender)
{
//填充左侧背景
this->FillLeftSide( m_panelListIcon->Top + m_panelListIcon->Height );
//关闭资源及曲式窗口
m_panelResource->Hide();
m_panelCompose->Hide();
m_panelListIcon->Show();
m_panelBarsShow->Left = m_panelListIcon->Width;
m_panelBarsShow->Width = Width - m_panelListIcon->Width;
m_panelBarsShow->SetFocus();
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::BtnListShowClick(TObject *Sender)
{
//取消左侧背景填充
this->FillLeftSide(-1);
m_panelListIcon->Hide();
//打开列表框
m_panelResource->Show();
m_panelCompose->Show();
if( Sender==m_btnResourceOpen ){
m_panelCompose->Height = 16;
m_panelCompose->Top = m_panelBarsShow->Top + m_panelBarsShow->Height - 16;
m_btnComposeMin->Visible = false;
m_btnComposeMax->Visible = true;
m_btnComposeClose->Visible = false;
m_panelResource->Height = m_panelCompose->Top - m_panelResource->Top;
m_lbResource->Height = m_panelResource->Height - 17;
m_btnResourceMax->Visible = false;
m_btnResourceMin->Visible = false;
m_btnResourceClose->Visible = true;
m_lbResource->SetFocus();
}
else{
m_panelResource->Height = 17;
m_btnResourceMin->Visible = false;
m_btnResourceMax->Visible = true;
m_btnResourceClose->Visible = false;
m_panelCompose->Top = m_panelResource->Top + 17;
m_panelCompose->Height = m_panelBarsShow->Height - 17;
m_lbCompose->Height = m_panelCompose->Height - 31;
m_panelComposeBottom->Top = m_panelCompose->Height - 15;
m_btnComposeMax->Visible = false;
m_btnComposeMin->Visible = false;
m_btnComposeClose->Visible = true;
m_lbCompose->SetFocus();
}
m_panelBarsShow->Left = m_lbResource->Width;
m_panelBarsShow->Width = Width - m_lbResource->Width;
}
//---------------------------------------------------------------------------
void TComposeForm::CheckOperationState()
{
m_btnAdd->Enabled = m_lbResource->ItemIndex>=0;
bool bCanMoveUp = false, bCanMoveDown = false;
int iSel = m_lbCompose->ItemIndex;
if( iSel>=0 ){
int iStage = LOWORD(DWORD(m_lbCompose->Items->Objects[iSel]));
if( iStage<COMPOSE_ENDING_1 ){
if( iSel>0 ){
bCanMoveUp = true;
}
if( iSel<m_lbCompose->Count-2 ){
bCanMoveDown = true;
}
else{
int iLastStage = LOWORD(DWORD(m_lbCompose->Items->Objects[m_lbCompose->Count-1]));
if( iSel==m_lbCompose->Count-2 && iLastStage<COMPOSE_ENDING_1 ){
bCanMoveDown = true;
}
}
}
}
m_btnMoveUp->Enabled = bCanMoveUp;
m_btnMoveDown->Enabled = bCanMoveDown;
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::BtnAddClick(TObject *Sender)
{
int iSel = m_lbResource->ItemIndex;
if( iSel>=0 ){
int iMelodyStage = LOWORD(DWORD(m_lbResource->Items->Objects[iSel]));
AddStage( iMelodyStage );
}
CheckOperationState();
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::BtnMoveClick(TObject *Sender)
{
int iSel = m_lbCompose->ItemIndex,
iInsPos = iSel + ( Sender==m_btnMoveDown? 2 : -1 );
if( iSel>=0 && iInsPos>=0 ){
m_lbCompose->MoveStage( iSel, iInsPos );
m_panelBarsShow->MoveStage( iSel, iInsPos );
}
CheckOperationState();
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
{
switch( Key ){
case VK_F9:
if( m_btnNextStep->Enabled ){
StepClick( m_btnNextStep );
}
break;
case VK_F8:
if( m_btnPrevStep->Enabled ){
StepClick( m_btnPrevStep );
}
break;
case VK_DELETE:
break;
case VK_UP: case VK_DOWN:
if( ActiveControl==(TWinControl*)m_panelBarsShow ){
}
break;
case VK_RETURN:
break;
case VK_ESCAPE:
if( m_panelAudioVolSet->Visible ){
m_panelAudioVolSet->Hide();
m_btnVolAudioSet->Down = false;
}
if( m_panelMusicVolSet->Visible ){
m_panelMusicVolSet->Hide();
m_btnVolMusicSet->Down = false;
}
break;
case ' ':
if( m_btnPause->Visible && m_btnPause->Enabled ){
PauseClick( NULL );
}
else if( m_btnPlay->Visible && m_btnPlay->Enabled ){
PlayClick( NULL );
}
break;
case 'W':
if( m_panelBarsShow->IsPlaying() ){
StopClick( NULL );
}
if( m_nTotalBarNum>0 ){
m_iStartBar = m_iLastStartBar = 0;
m_dblStartPoint = m_dblLastStartPoint = 0;
m_panelBarsShow->SetPlayPoint( 0, 0 );
ShowPlayTime();
}
break;
case 'T':
if( m_btnStyleChange->Enabled ){
BtnStyleChangeClick( NULL );
}
break;
}
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::BtnStyleChangeClick(TObject *Sender)
{
StopClick(NULL);
PostMessage( Handle, UM_SELECTSTYLE, 0, 0 );
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::UMSelectStyle(TMessage &msg)
{
bool bStyleChanged = false;
bool bBarChanged = false;
int iSegNo = -1;
StyleSelForm = new TStyleSelForm(this);
StyleSelForm->m_bBase = false;
int iSelStage = m_lbCompose->ItemIndex;
if( iSelStage>=0 ){
StyleSelForm->m_idSelected = g_lstComposeStages[iSelStage]->idStyle;
StyleSelForm->m_iSelStage = iSelStage;
if( StyleSelForm->m_idSelected==g_iSelectedStyleID ){
StyleSelForm->m_strName = g_strSelectedStyleName;
}
else{
StyleSelForm->m_strName = g_lstComposeStages[iSelStage]->strStyleName;
}
int iMelodyStage = g_lstComposeStages[iSelStage]->iMelodyStage;
if( iMelodyStage>=0x110 ){
StyleSelForm->m_iSegType = 2;
StyleSelForm->m_iSegNo = iSegNo = iMelodyStage - 0x110;
for( int i=iSelStage-1; i>=0; i-- ){
if( g_lstComposeStages[i]->iMelodyStage<0x100 ){
MELODYSTAGE *pMStage = g_lstMelodyStages[g_lstComposeStages[i]->iMelodyStage];
if( g_lstMelodyBars[pMStage->iLastBar]->iChords[1]!=-1 ){
StyleSelForm->m_iChordType =
( g_lstMelodyBars[pMStage->iLastBar]->iChords[1] % CHORD_TYPE_NUM ) % 2;
}
else{
StyleSelForm->m_iChordType =
( g_lstMelodyBars[pMStage->iLastBar]->iChords[0] % CHORD_TYPE_NUM ) % 2;
}
break;
}
}
}
else if( iMelodyStage>=0x100 ){
StyleSelForm->m_iSegType = 1;
StyleSelForm->m_iSegNo = iSegNo = iMelodyStage - 0x100;
//后向搜索
for( int i=iSelStage+1; i<g_lstComposeStages.size(); i++ ){
if( g_lstComposeStages[i]->iMelodyStage<0x100 ){
MELODYSTAGE *pMStage = g_lstMelodyStages[g_lstComposeStages[i]->iMelodyStage];
StyleSelForm->m_iChordType =
( g_lstMelodyBars[pMStage->iFirstBar]->iChords[0] % CHORD_TYPE_NUM ) % 2;
break;
}
}
if( StyleSelForm->m_iChordType==-1 ){
//前向搜索
for( int i=iSelStage-1; i>=0; i-- ){
if( g_lstComposeStages[i]->iMelodyStage<0x100 ){
MELODYSTAGE *pMStage = g_lstMelodyStages[g_lstComposeStages[i]->iMelodyStage];
if( g_lstMelodyBars[pMStage->iLastBar]->iChords[1]!=-1 ){
StyleSelForm->m_iChordType =
( g_lstMelodyBars[pMStage->iLastBar]->iChords[1] % CHORD_TYPE_NUM ) % 2;
}
else{
StyleSelForm->m_iChordType =
( g_lstMelodyBars[pMStage->iLastBar]->iChords[0] % CHORD_TYPE_NUM ) % 2;
}
break;
}
}
}
}
else{
StyleSelForm->m_iSegType = 0;
StyleSelForm->m_iSegNo = iSegNo = g_lstComposeStages[iSelStage]->iVar;
MELODYSTAGE *pMStage = g_lstMelodyStages[iMelodyStage];
StyleSelForm->m_iChordType =
( g_lstMelodyBars[pMStage->iFirstBar]->iChords[0] % CHORD_TYPE_NUM ) % 2;
}
}
else{
StyleSelForm->m_idSelected = g_iSelectedStyleID;
StyleSelForm->m_strName = g_strSelectedStyleName;
for( int i=0; i<g_lstComposeStages.size(); i++ ){
if( g_lstComposeStages[i]->iMelodyStage<0x100 ){
MELODYSTAGE *pMStage = g_lstMelodyStages[g_lstComposeStages[i]->iMelodyStage];
StyleSelForm->m_iChordType =
( g_lstMelodyBars[pMStage->iFirstBar]->iChords[0] % CHORD_TYPE_NUM ) % 2;
break;
}
}
}
StyleSelForm->ShowModal();
if( iSelStage>=0 ){
if( g_lstComposeStages[iSelStage]->idStyle!=StyleSelForm->m_idSelected ||
g_lstComposeStages[iSelStage]->iVar!=StyleSelForm->m_iSegNo ){
int iMelodyStage = g_lstComposeStages[iSelStage]->iMelodyStage;
g_lstComposeStages[iSelStage]->idStyle = StyleSelForm->m_idSelected;
g_lstComposeStages[iSelStage]->strStyleName = StyleSelForm->m_strName;
if( iMelodyStage>=0x100 ){
if( iMelodyStage>=0x110 ){
iMelodyStage = 0x110 + StyleSelForm->m_iSegNo;
}
else{
iMelodyStage = 0x100 + StyleSelForm->m_iSegNo;
}
g_lstComposeStages[iSelStage]->iMelodyStage = iMelodyStage;
int nBarNum = f_SM_GetSegmentBarNum( iMelodyStage, StyleSelForm->m_idSelected );
if( g_lstComposeStages[iSelStage]->nStageBars!=nBarNum ){
g_lstComposeStages[iSelStage]->nStageBars = nBarNum;
bBarChanged = true;
ClearGlobalVars( LIST_COMPLETEVOLS );
}
}
else{
g_lstComposeStages[iSelStage]->iVar = StyleSelForm->m_iSegNo;
}
bStyleChanged = true;
}
if( g_lstComposeStages[iSelStage]->idStyle!=g_iSelectedStyleID ){
m_lblStyleName->Caption = g_lstComposeStages[iSelStage]->strStyleName.c_str();
// UpdateGlobalStyle();
}
else{
m_lblStyleName->Caption = g_strSelectedStyleName.c_str();
}
}
else if( g_iSelectedStyleID!=StyleSelForm->m_idSelected ){
g_iSelectedStyleID = StyleSelForm->m_idSelected;
g_strSelectedStyleName = StyleSelForm->m_strName;
m_lblStyleName->Caption = g_strSelectedStyleName.c_str();
bStyleChanged = UpdateSegmentBars();
bBarChanged = UpdateStageBars();
if( bBarChanged ){
m_lbResource->Clear();
//m_lbCompose->Clear();
ClearGlobalVars( LIST_COMPLETEVOLS );
}
}
delete StyleSelForm;
//Compose only as Select Style Id has changed
/* bool bCombineSong = m_panelBarsShow->CheckModify( CHECK_STAGE | CHECK_POS );
if( bCombineSong ){
ClearGlobalVars( LIST_COMPLETEVOLS );
g_bSongNeedSave = false;
}
*/
if( bStyleChanged || bBarChanged ){
g_bkCompose.Clear();
}
ReloadCompose();
// m_panelBarsShow->BackupModify();
m_panelBarsShow->InitialVars();
// m_btnReload->Enabled = false;
//初始化资源列表框
if( m_lbResource->Count==0 ){
InitResourceList();
}
//计算列表框大小
CalcListSize();
//重置曲式列表框
int iSelIndex = m_lbCompose->ItemIndex;
ResetComposeList();
m_lbCompose->ItemIndex = iSelIndex;
m_nTotalBarNum = m_panelBarsShow->ComposeBarCount();
Application->MainForm->Update();
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::AudioEffectClick(TObject *Sender)
{
StopClick( NULL );
PostMessage(Application->MainFormHandle, UM_AUDIOEFFECT, WPARAM(0),LPARAM(0));
}
//---------------------------------------------------------------------------
void TComposeForm::SetFocusStage( int iSelIndex )
{
if( iSelIndex==-1 || g_lstComposeStages[iSelIndex]->idStyle==g_iSelectedStyleID ){
m_lblStyleName->Caption = g_strSelectedStyleName.c_str();
}
else{
m_lblStyleName->Caption = g_lstComposeStages[iSelIndex]->strStyleName.c_str();
}
m_panelBarsShow->SetFocusStage( iSelIndex );
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::ChangeChordMode( bool bAlpha )
{
g_iShowType = bAlpha;
m_panelBarsShow->Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::MicSetClick(TObject *Sender)
{
PostMessage(Application->MainFormHandle, UM_MICSETTING, WPARAM(0),LPARAM(0));
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::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_btnVolAudioSet->Top;
g_panelFontName->Top = g_btnFontChange->Top + 1;
g_lbFontSelect->Top = g_btnFontChange->Top - g_lbFontSelect->Height;
g_btnFontChange->Left = 451;//m_panelStyleName->Left + m_panelStyleName->Width + 20;
g_panelFontName->Left = g_btnFontChange->Left + g_btnFontChange->Width;
g_lbFontSelect->Left = g_panelFontName->Left;
}
}
//---------------------------------------------------------------------------
void __fastcall TComposeForm::UMHidePopControl(TMessage &msg)
{
if( g_lbFontSelect->Visible ){
g_lbFontSelect->Hide();
g_btnFontChange->Down = false;
}
}
//---------------------------------------------------------------------------