// --------------------------------------------------------------------------- #include #pragma hdrstop #include "GlobalUnit.h" #include "RecordFormUnit.h" #include "MessageFormUnit.h" #include "ProgressFormUnit.h" bool RECORD_FROM_FILE = false; static const TCursor crBeginPos = 0x57, crEndPos = 0x58; // --------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "PNGButton" #pragma resource "*.dfm" USEFORM("MessageFormUnit.cpp", MessageForm); TRecordForm *RecordForm; extern TPNGButton *g_btnFontChange; extern Vcl::Extctrls::TPanel *g_panelFontName; extern CommonListBoxUnit::TListBox *g_lbFontSelect; // --------------------------------------------------------------------------- __fastcall TRecordForm::TRecordForm(TComponent* Owner) : TBackgroundForm(Owner) { m_nVolLevel = 0; m_bKeyDown = false; m_iStartBar = m_iLastStartBar = 0; m_dblStartPoint = m_dblLastStartPoint = 0; m_tTimer = m_tAccuracy = 0; m_bModifyRecord = false; } // --------------------------------------------------------------------------- void __fastcall TRecordForm::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_pBmpWhiteDDown = new TBitmap(); m_pBmpWhiteDDown->LoadFromResourceName(int(HInstance), "KBWhiteDDown"); m_pBmpWhiteLDown = new TBitmap(); m_pBmpWhiteLDown->LoadFromResourceName(int(HInstance), "KBWhiteLDown"); m_pBmpWhiteRDown = new TBitmap(); m_pBmpWhiteRDown->LoadFromResourceName(int(HInstance), "KBWhiteRDown"); m_pBmpBlackDown = new TBitmap(); m_pBmpBlackDown->LoadFromResourceName(int(HInstance), "KBBlackDown"); m_nBlackWidth = m_pBmpBlackDown->Width; m_nBlackHeight = m_pBmpBlackDown->Height; m_nWhiteWidth = m_pBmpWhiteDDown->Width; m_nGroupWidth = m_nWhiteWidth * 7; // Add by GGGrass 2012年12月14日 13:08:34 m_imgFirst = new TPngImage(); m_imgFirst->LoadFromResourceName(int(HInstance), L"NoticeImage1"); m_imgSecond = new TPngImage(); m_imgSecond->LoadFromResourceName(int(HInstance), L"NoticeImage2"); m_imgThird = new TPngImage(); m_imgThird->LoadFromResourceName(int(HInstance), L"NoticeImage3"); m_imgForth = new TPngImage(); m_imgForth->LoadFromResourceName(int(HInstance), L"NoticeImage4"); // End By GGGrass 2012年12月14日 13:08:39 m_aBlackHitTest[0].x1 = 12; m_aBlackHitTest[0].iKey = 1; m_aBlackHitTest[1].x1 = 32; m_aBlackHitTest[1].iKey = 3; m_aBlackHitTest[2].x1 = 72; m_aBlackHitTest[2].iKey = 6; m_aBlackHitTest[3].x1 = 92; m_aBlackHitTest[3].iKey = 8; m_aBlackHitTest[4].x1 = 112; m_aBlackHitTest[4].iKey = 10; for (int i = 0; i < 5; i++) m_aBlackHitTest[i].x2 = m_aBlackHitTest[i].x1 + m_pBmpBlackDown->Width; m_aKey[0].xPos = -1; m_aKey[0].pBmp = m_pBmpWhiteRDown; m_aKey[1].xPos = 12; m_aKey[1].pBmp = m_pBmpBlackDown; m_aKey[2].xPos = 19; m_aKey[2].pBmp = m_pBmpWhiteDDown; m_aKey[3].xPos = 32; m_aKey[3].pBmp = m_pBmpBlackDown; m_aKey[4].xPos = 39; m_aKey[4].pBmp = m_pBmpWhiteLDown; m_aKey[5].xPos = 59; m_aKey[5].pBmp = m_pBmpWhiteRDown; m_aKey[6].xPos = 72; m_aKey[6].pBmp = m_pBmpBlackDown; m_aKey[7].xPos = 79; m_aKey[7].pBmp = m_pBmpWhiteDDown; m_aKey[8].xPos = 92; m_aKey[8].pBmp = m_pBmpBlackDown; m_aKey[9].xPos = 99; m_aKey[9].pBmp = m_pBmpWhiteDDown; m_aKey[10].xPos = 112; m_aKey[10].pBmp = m_pBmpBlackDown; m_aKey[11].xPos = 119; m_aKey[11].pBmp = m_pBmpWhiteLDown; m_iPressGroup = m_iPressKey = -1; Screen->Cursors[crBeginPos] = LoadCursor(HInstance, L"BeginCursor"); Screen->Cursors[crEndPos] = LoadCursor(HInstance, L"EndCursor"); m_btnAudioEffect->Visible = true; } // --------------------------------------------------------------------------- void __fastcall TRecordForm::FormDestroy(TObject *Sender) { if (m_panelBarsShow->IsPlaying()) StopClick(NULL); if (m_imgFirst) delete m_imgFirst; if (m_imgSecond) delete m_imgSecond; if (m_imgThird) delete m_imgThird; if (m_imgForth) delete m_imgForth; } // --------------------------------------------------------------------------- void __fastcall TRecordForm::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_btnKeyChange->Visible = true; } else { m_lblKey->Caption = "-"; m_btnKeyChange->Visible = false; } //显示播放时间点 if( !g_lstMelodyBars.empty() ){ ShowPlayTime(); } else { m_lblPlayTime->Caption = "--:--:---"; } //有关音量的设置 if (g_fRecordVolume < 0) { g_fRecordVolume = f_MM_GetStreamVolume(1) / 100.0; } else { f_MM_SetStreamVolume(1, g_fRecordVolume); } if (g_fSpeakerVolume < 0) { g_fSpeakerVolume = f_MM_GetStreamVolume(0) / 100.0; } else { f_MM_SetStreamVolume(0, g_fSpeakerVolume); } m_nSpeakerVolPos = 100 - g_fSpeakerVolume * 100; m_nMicrophoneVolPos = 100 - g_fRecordVolume * 100; m_btnSpeakerVolPos->Top = DPIY(5 + m_nSpeakerVolPos); m_btnMicrophoneVolPos->Top = DPIY(5 + m_nMicrophoneVolPos); m_btnSpeakerVolPos->Hint = IntToStr(100 - m_nSpeakerVolPos); m_btnMicrophoneVolPos->Hint = IntToStr(100 - m_nMicrophoneVolPos); //有关按钮的初始化 m_bModifyRecord = false; m_btnModify->Down = false; m_btnBeginPos->Down = false; m_btnBeginPos->Enabled = false; m_btnEndPos->Down = false; m_btnEndPos->Enabled = false; m_btnWithCompose->Enabled = false; m_btnWithCompose->Down = g_bPredefine; m_panelBarsShow->ShowModifyPos(false); m_btnModify->Enabled = !g_lstMelodyBars.empty();// && !g_bMidiMelody; m_btnNextStep->Enabled = !g_lstMelodyBars.empty(); m_btnAudioEffect->Enabled = g_bAudioLoaded; m_btnPlay->Visible = true; m_btnPlay->Enabled = !g_lstMelodyBars.empty(); m_btnPlay->Down = false; m_btnRecord->Enabled = true; m_btnRecord->Down = false; m_btnPause->Visible = false; m_btnStop->Enabled = false; m_panelBarsShow->InitialVars(g_lstMelodyBars.size()); m_bAudioModified = false; m_iStartBar = m_iLastStartBar = 0; m_dblStartPoint = m_dblLastStartPoint = 0; m_panelBarsShow->SetPlayPoint(0, 0); ShowPlayTime(); m_panelBarsShow->SetFocus(); m_panelBarsShow->Invalidate(); Invalidate(); } // --------------------------------------------------------------------------- void __fastcall TRecordForm::FormDeactivate(TObject *Sender) { if( Application->ActiveFormHandle!=Application->MainFormHandle ){ return; } g_bCanStep = true; StopClick(NULL); ShowKeyboard( false ); if (m_panelMicrophoneVolSet->Visible) { m_panelMicrophoneVolSet->Hide(); m_btnVolMicrophoneSet->Down = false; } if (m_panelSpeakerVolSet->Visible) { m_panelSpeakerVolSet->Hide(); m_btnVolSpeakerSet->Down = false; } for( int i=0; itBarVol.bRecording = false; } if( Sender && m_bAudioModified ){ if( g_bPredefine ){ ClearGlobalVars( LIST_COMPLETEVOLS ); g_bComposeLoaded = false; } else{ ClearGlobalVars(LIST_MELODYCHORDS | LIST_MELODYSTAGES | LIST_COMPOSESTAGES | LIST_COMPLETEVOLS); } } } //--------------------------------------------------------------------------- void __fastcall TRecordForm::FormResize(TObject *Sender) { // m_imgRightBottomConner->Left = Width - 6; // m_imgRightBottomConner->Top = Height - 6; // m_imgLeftBottomConner->Top = Height - 6; // m_imgBottomSide->Top = Height - 6; // m_imgBottomSide->Width = Width - 12; // m_imgRightSide->Left = Width - 6; // m_imgRightSide->Height = Height - 6; int wOriClient = 798, hOriClient = 494; m_imgBreakH->Width = Width - DPIX(28); m_imgBreakI->Left = Width - DPIX(wOriClient - 649); m_btnAudioEffect->Left = m_imgBreakI->Left - DPIX(60); m_btnPrevStep->Top = Height - DPIY(hOriClient - 460); m_btnNextStep->Top = m_btnPrevStep->Top; m_btnNextStep->Left = ClientWidth - DPIX(wOriClient - 705); 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_btnShowKeyboard->Top = m_panelVolLevel->Top; m_panelSpeakerVolSet->Top = Height - DPIY(hOriClient - 322); m_panelMicrophoneVolSet->Top = m_panelSpeakerVolSet->Top; m_panelKeyboard->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, ClientWidth, ClientHeight - DPIY(84) ); m_imgNotice->Left = (m_panelBarsShow->Width - m_imgNotice->Width) / 2; m_imgNotice->Top = (m_panelBarsShow->Height - m_imgNotice->Height) / 3; } // --------------------------------------------------------------------------- void __fastcall TRecordForm::StepClick(TObject *Sender) { PostMessage(Application->MainFormHandle, UM_JUMP_PAGE, Sender==m_btnNextStep?WPARAM(2):WPARAM(0),LPARAM(this)); } // --------------------------------------------------------------------------- void __fastcall TRecordForm::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 TRecordForm::ShowKeyboardClick(TObject *Sender) { ShowKeyboard( !m_panelKeyboard->Visible ); } // --------------------------------------------------------------------------- void TRecordForm::ShowKeyboard( bool bShow ) { if( bShow && !m_panelKeyboard->Visible ){ // 创建模拟键盘设备 HRESULT hResult = f_MM_CreateRealTimeMIDIStream( false ); if (hResult != S_OK) { DebugPrint("Create realtime midi stream error.\n"); } else{ m_panelKeyboard->Show(); m_btnShowKeyboard->Down = true; } } else if( !bShow && m_panelKeyboard->Visible ){ m_panelKeyboard->Hide(); m_btnShowKeyboard->Down = false; // 释放模拟键盘设备 HRESULT hResult = f_MM_FreeRealTimeMIDIStream(); if (hResult != S_OK) { DebugPrint("Free realtime midi stream error.\n"); } } } // --------------------------------------------------------------------------- void __fastcall TRecordForm::KeyboardPaint(TObject *Sender) { if (m_bKeyDown) { int xPos = m_iPressGroup * m_nGroupWidth + m_aKey[m_iPressKey].xPos; m_pbKeyboard->Canvas->Draw(xPos, 0, m_aKey[m_iPressKey].pBmp); } } // --------------------------------------------------------------------------- int TRecordForm::KeyboardGetPressKey(int X, int Y) { short iPressKey = -1, iPressGroup = X / m_nGroupWidth; int xInGroup = X % m_nGroupWidth; int iWhite = xInGroup / m_nWhiteWidth; if (iWhite < 3) iPressKey = iWhite * 2; else iPressKey = iWhite * 2 - 1; if (Y < m_nBlackHeight) { for (int i = 0; i < 5; i++) { if (xInGroup >= m_aBlackHitTest[i].x1 && xInGroup < m_aBlackHitTest[i].x2) { iPressKey = m_aBlackHitTest[i].iKey; break; } } } return MAKELONG(iPressKey, iPressGroup); } // --------------------------------------------------------------------------- void __fastcall TRecordForm::KeyboardMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if (Sender == m_pbKeyboard && Button == mbLeft) { m_bKeyDown = true; int iKey = KeyboardGetPressKey(X, Y); int iPressGroup = HIWORD(iKey); int iPressKey = LOWORD(iKey); if (iPressGroup != m_iPressGroup || iPressKey != m_iPressKey) { HRESULT hRet = f_MM_RealTimeMIDINoteOn(iPressGroup * 12 + iPressKey + 48); m_iPressGroup = iPressGroup; m_iPressKey = iPressKey; m_pbKeyboard->Invalidate(); } } } // --------------------------------------------------------------------------- void __fastcall TRecordForm::KeyboardMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { if (m_bKeyDown && X >= 0 && Y >= 0 && X < m_pbKeyboard->Width && Y < m_pbKeyboard->Height) { int iKey = KeyboardGetPressKey(X, Y); int iPressGroup = HIWORD(iKey); int iPressKey = LOWORD(iKey); if (iPressGroup != m_iPressGroup || iPressKey != m_iPressKey) { HRESULT hRet = f_MM_RealTimeMIDINoteOff(m_iPressGroup * 12 + m_iPressKey + 48); hRet = f_MM_RealTimeMIDINoteOn( iPressGroup * 12 + iPressKey + 48); m_iPressGroup = iPressGroup; m_iPressKey = iPressKey; m_pbKeyboard->Invalidate(); } } } // --------------------------------------------------------------------------- void __fastcall TRecordForm::KeyboardMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if (Button == mbLeft && m_bKeyDown) { m_bKeyDown = false; f_MM_RealTimeMIDINoteOff(m_iPressGroup*12 + m_iPressKey + 48); m_iPressGroup = m_iPressKey = -1; m_pbKeyboard->Invalidate(); } } // --------------------------------------------------------------------------- void __fastcall TRecordForm::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 TRecordForm::ImgVolSetMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if (Button == mbLeft && X > DPIX(8) && X < DPIX(24) && Y >= DPIY(16) && Y <= DPIY(116)) { int yPos = Y - DPIY(16); if (Sender == m_imgSpeakerVolSet) { m_nSpeakerVolPos = yPos; m_btnSpeakerVolPos->Top = yPos + DPIY(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 + DPIY(5); m_btnMicrophoneVolPos->Hint = IntToStr(100 - m_nMicrophoneVolPos); g_fRecordVolume = (100 - m_nMicrophoneVolPos) / 100.0; f_MM_SetStreamVolume(1, g_fRecordVolume); } } } // --------------------------------------------------------------------------- void __fastcall TRecordForm::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 TRecordForm::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 TRecordForm::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 TRecordForm::LoadMelodyFromFile() { StopClick( NULL ); m_bFromFile = true; if (m_btnModify->Down) { m_btnModify->Down = false; m_panelBarsShow->ShowModifyPos(); } // 指定工程文件名 wstring strFileName; TOpenDialog * pDlg = new TOpenDialog(NULL); pDlg->Title = "打开旋律文件"; pDlg->Options << ofFileMustExist; pDlg->InitialDir = ExtractFilePath(g_strProjectName.c_str()); pDlg->Filter = "MIDI文件 (*.mid)|*.mid|音频文件 (*.wav)|*.wav"; pDlg->DefaultExt = "mid"; if (pDlg->Execute(Handle)) { strFileName = pDlg->FileName.c_str(); } delete pDlg; if( strFileName.length() > 0 ){ ClearGlobalVars(); m_panelBarsShow->InitialVars(0); m_iStartBar = 0; m_dblStartPoint = 0; m_panelBarsShow->SetPlayPoint(m_iStartBar, (int)m_dblStartPoint); m_dwLastVol = 0; g_bAudioLoaded = false; m_bFromFile = true; int iFileType = FILETYPE_MIDI; if( ExtractFileExt( strFileName.c_str() ).CompareIC(".wav")==0 ){ iFileType = FILETYPE_WAVE; g_bMidiMelody = false; } else{ g_bMidiMelody = true; } PostMessage(Application->MainFormHandle, UM_REFRESH_PAGE_STATE, PAGE_RECORDONLY, 0); //禁止跳转及打开/新建工程 TProgressForm *frmProgress = new TProgressForm(NULL); int ret = frmProgress->MM_Load( strFileName.c_str(), iFileType ); TMessage msgReturn = frmProgress->m_MsgTransparent; delete frmProgress; if( ret==mrOk ){ int iTS, iTempo; f_MM_GetMelodyInfo( NULL, &iTS, &iTempo ); if( iTS!=g_iMelodyTimeSignature ){ SetMelodyTS( iTS ); } if( iTempo!=g_nMelodyTempo ){ SetMelodyTempo( iTempo ); } m_lblBeat->Caption = g_strTimeSignature[g_iMelodyTimeSignature]; m_lblTempo->Caption = IntToStr(g_nMelodyTempo); PostMessage( Handle, msgReturn.Msg, msgReturn.WParam, msgReturn.LParam ); } } } // --------------------------------------------------------------------------- void __fastcall TRecordForm::RecordClick(TObject *Sender) { HRESULT hr = S_FALSE; m_bFromFile = false; m_iRecordBar = 0; m_dblRecordPoint = 0; int nMelodyBeatsPerMeasure = g_iMelodyTimeSignature == 0 ? 4 : g_iMelodyTimeSignature == 1 ? 3 : g_iMelodyTimeSignature == 2 ? 2 : 3; double dblEditStartBar = -1, dblEditEndBar = -1, dblPlayStartBar = 0; int iWithCompose = 0; bool bModify = m_btnModify->Down || g_bPredefine; if (!bModify ){ if( !g_lstMelodyBars.empty() ){ if( MessageForm->ShowMessage( "确定清除当前内容重新录音?", MB_YESNO | MB_ICONQUESTION )==mrNo ){ return; } else{ ClearGlobalVars(); ResetAudioEffects(); m_panelBarsShow->InitialVars(0); m_iStartBar = 0; m_dblStartPoint = 0; m_panelBarsShow->SetPlayPoint(0,0); m_dwLastVol = 0; g_bAudioLoaded = false; g_fAudioVolume = 1; f_MM_SetStreamVolume(2, 1); } } } 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; MELODYBAR *pBV = NULL; if( iModifyBeginBar>=0 ){ pBV = g_lstMelodyBars[iModifyBeginBar]; m_dwLastVol = pBV->tBarVol.aVols[iModifyBeginPoint]; dblEditStartBar = iModifyBeginBar + (double)iModifyBeginPoint/POINTS_PER_BAR; } else{ pBV = g_lstMelodyBars[0]; m_dwLastVol = pBV->tBarVol.aVols[0]; } if( iModifyEndBar>=0 ) dblEditEndBar = iModifyEndBar + (double)iModifyEndPoint/POINTS_PER_BAR; if( m_btnWithCompose->Down ) iWithCompose |= TYPE_BASECOMPOSE; if( g_bPredefine ) iWithCompose |= TYPE_PREDEFINE; } BYTE* pBeatData = NULL; int nBeatSize = 0; // if( g_bPrebeat && g_iSelectedStyleID>0 && ( !bModify || dblEditEndBar<=0 && !g_bPredefine )){ if( g_iSelectedStyleID>0 && ( g_bPrebeat || bModify && m_btnWithCompose->Down )){ pBeatData = new BYTE[1000000]; nBeatSize = 1000000; hr = f_SM_GetPrebeat( nBeatSize, pBeatData, g_iSelectedStyleID ); if( hr!=0 ){ delete[] pBeatData; pBeatData = NULL; nBeatSize = 0; } } f_MM_LoadPrebeat( pBeatData, nBeatSize ); if( pBeatData ){ delete[] pBeatData; pBeatData = NULL; } hr = f_MM_Record(Handle, dblPlayStartBar, dblEditStartBar, dblEditEndBar, iWithCompose); if( hr==S_OK ){ if( !bModify ){ m_imgNotice->Visible = true; String strSignature = L""; int nBPM = nMelodyBeatsPerMeasure; if( g_iMelodyTimeSignature==3 ){ nBPM = 2; } //strSignature = L"Melody Time Signature: " + IntToStr(nBPM); //OutputDebugString(strSignature.c_str()); ShowNoticeImg(nBPM - 1); // End Add By GGGrass 2012年12月14日 11:02:55 // 第一小节 MELODYBAR * pBV = new MELODYBAR; pBV->tBarVol.aVols[0] = 0; pBV->tBarVol.bInvalid = true; g_lstMelodyBars.push_back(pBV); m_panelBarsShow->AddNewBar(0); m_panelBarsShow->SetPlayPoint(0, 0); } SetPlayTimer(true, m_tTimer, m_tAccuracy, Handle); m_panelBarsShow->Play(true); m_lblKey->Caption = "-"; m_btnKeyChange->Visible = false; 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_btnWithCompose->Enabled = false; m_btnAudioEffect->Enabled = false; m_btnMicSet->Enabled = false; m_btnPrevStep->Enabled = false; m_btnNextStep->Enabled = false; // Application->MainForm->Perform(UM_HANDLEAUTOPROJ, 0, 0);//add by tj 2013/1/2 PostMessage(Application->MainFormHandle, UM_REFRESH_PAGE_STATE, PAGE_RECORDONLY, 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)); } } Application->MainForm->Update(); } // --------------------------------------------------------------------------- void __fastcall TRecordForm::StopClick(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); } if( g_lstMelodyStages.size()> 0){ m_btnModify->Enabled = true; if( m_btnModify->Down ){ m_btnBeginPos->Enabled = true; m_btnEndPos->Enabled = true; m_btnWithCompose->Enabled = true; } PostMessage(Application->MainFormHandle, UM_REFRESH_PAGE_STATE, PAGE_ALL, 0); } m_imgNotice->Visible = false; m_btnStop->Enabled = false; m_btnRecord->Enabled = true; m_btnRecord->Down = false; m_btnPlay->Visible = true; m_btnPlay->Enabled = !g_lstMelodyBars.empty(); m_btnPlay->Down = false; m_btnPause->Visible = false; m_btnPrevStep->Enabled = true; m_btnMicSet->Enabled = true; m_iStartBar = m_iLastStartBar; m_dblStartPoint = m_dblLastStartPoint; m_panelBarsShow->SetPlayPoint(m_iStartBar, (int)m_dblStartPoint); ShowPlayTime(); } // --------------------------------------------------------------------------- void __fastcall TRecordForm::PlayClick(TObject *Sender) { double dblAudioStartPoint = m_iStartBar + m_dblStartPoint / POINTS_PER_BAR; f_MM_SetStreamVolume(2, 1); HRESULT hr = f_MM_Play(Handle, dblAudioStartPoint, TYPE_AUDIO); SetPlayTimer(true, m_tTimer, m_tAccuracy, Handle); m_panelBarsShow->Play(true); m_btnRecord->Enabled = false; m_btnPlay->Visible = false; m_btnPlay->Down = true; m_btnPause->Visible = true; m_btnStop->Enabled = true; } // --------------------------------------------------------------------------- void __fastcall TRecordForm::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 TRecordForm::ShowPlayTime() { char strTime[10]; GetPlayTime(m_iStartBar, m_dblStartPoint, strTime); m_lblPlayTime->Caption = strTime; } // --------------------------------------------------------------------------- void __fastcall TRecordForm::UMMediaTime(TMessage &Message) { if (!m_panelBarsShow->IsPlaying()) return; 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 (m_imgNotice->Visible) { int nBPM = g_iMelodyTimeSignature==0 ? 4 : g_iMelodyTimeSignature==1 ? 3 : 2; int iInterval = ( nBPM==4 ? 30 :nBPM==3 ? 40 : 60 ); int iIndex = dblStartPoint/iInterval; ShowNoticeImg( nBPM-iIndex-1 ); } if (bRecording ){ int iModifyBeginBar(-1), iModifyBeginPoint(0), iModifyEndBar(-1), iModifyEndPoint(0); if( 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 if( !m_bAudioModified ){ m_bAudioModified = true; } } // 获取实时音量 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) { bool bAutoStop = ( !bRecording || g_bPredefine ) && iBar==g_lstMelodyBars.size(); if( bRecording ) { MELODYBAR *pBV = g_lstMelodyBars[m_iStartBar]; if (iLastPoint < POINTS_PER_BAR - 1) { for (int i = iLastPoint + 1; i < POINTS_PER_BAR; i++) { pBV->tBarVol.aVols[i] = m_dwLastVol; } m_panelBarsShow->InvalidateBar(m_iStartBar, iLastPoint, POINTS_PER_BAR - 1); } if( !bAutoStop && iBar == g_lstMelodyBars.size() ) { if (m_imgNotice->Visible) m_imgNotice->Visible = false; MELODYBAR * pNewBV = new MELODYBAR; pNewBV->tBarVol.aVols[0] = m_dwLastVol; g_lstMelodyBars.push_back(pNewBV); m_panelBarsShow->AddNewBar(iBar); } iLastPoint = 0; } if( bAutoStop ){ if( bRecording ){ m_iRecordBar = iBar-1; m_dblRecordPoint = POINTS_PER_BAR - 1; } StopClick(NULL); return; } } int iCurrPoint = (int)dblStartPoint; if (iBar != m_iStartBar || iCurrPoint != (int)m_dblStartPoint) { MELODYBAR *pBV = g_lstMelodyBars[iBar]; if (bRecording || m_bFromFile && pBV->tBarVol.bRecording) { pBV->tBarVol.bRecording = true; if (iLastPoint < iCurrPoint) { for (int i = iLastPoint; i < iCurrPoint; i++) { pBV->tBarVol.aVols[i] = m_dwLastVol; } m_panelBarsShow->InvalidateBar(iBar, iLastPoint, iCurrPoint); } pBV->tBarVol.aVols[iCurrPoint] = dwVolume; m_dwLastVol = dwVolume; } else if (pBV->tBarVol.bRecording) { pBV->tBarVol.bRecording = false; m_panelBarsShow->InvalidateBar(iBar, iLastPoint, iCurrPoint); } m_panelBarsShow->SetPlayPoint(iBar, (int)dblStartPoint); } m_iStartBar = iBar; m_dblStartPoint = dblStartPoint; if( bRecording ){ m_iRecordBar = iBar; m_dblRecordPoint = dblStartPoint; } ShowPlayTime(); } // --------------------------------------------------------------------------- void __fastcall TRecordForm::UMRecordComplete(TMessage &Message) { int msDelay = Message.WParamHi; int nValidNotes = Message.WParamLo; int nOffsetBars = Message.LParamLo; int nValidBars = Message.LParamHi; if( g_bPredefine ) nValidBars = g_lstMelodyBars.size(); bool bJump = false; if (nValidBars == 0) { for( int i=g_lstMelodyBars.size()-1; i>=0; i-- ){ delete g_lstMelodyBars[i]; } g_lstMelodyBars.clear(); MessageForm->ShowMessage(L"无效的音频输入\n请调整话筒音量后重新录音!", MB_OK | MB_ICONERROR); Application->MainForm->Update(); m_btnModify->Down = false; m_btnPlay->Enabled = false; g_bAudioLoaded = false; g_bWeakup = false; g_iMelodyKey = -1; m_lblKey->Caption = "-"; m_btnKeyChange->Visible = false; } else { 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=0 ){ iShiftBeginBar = iModifyBeginBar; iShiftBeginPoint = iModifyBeginPoint; } if( m_iRecordBar==iModifyEndBar && (int)m_dblRecordPoint<=iModifyEndPoint || m_iRecordBar=0 ){ iShiftEndBar = iModifyEndBar; iShiftEndPoint = iModifyEndPoint; } } if( !g_bPredefine && bJump ){ /* if( nValidNotes < 7 ){ String strMessage = L"可识别的有效音符数不足,可能导致旋律分析不准确!"; MessageForm->ShowMessage(strMessage, MB_OK | MB_ICONINFORMATION); } */ if (m_btnModify->Down) { m_btnBeginPos->Enabled = true; m_btnEndPos->Enabled = true; m_panelBarsShow->ShowModifyPos(); if (g_lstMelodyStages.size() > 0) m_btnWithCompose->Enabled = true; } else if(!m_bFromFile){ MELODYBAR* pMB0 = g_lstMelodyBars[0]; delete pMB0; g_lstMelodyBars.erase(g_lstMelodyBars.begin()); } f_MM_GetMelodyInfo(&g_iMelodyKey, NULL, NULL); m_lblKey->Caption = g_strMelodyKey[g_iMelodyKey]; m_btnKeyChange->Visible = true; SetWavNotes(); } g_bAudioLoaded = true; if (nOffsetBars > 0) { m_panelBarsShow->SetModifyPos(true, -1, -1); m_panelBarsShow->SetModifyPos(false, -1, -1); iModifyEndBar = iModifyBeginBar = -1; m_iLastStartBar = m_iStartBar = 0; m_dblLastStartPoint = m_dblStartPoint = 0; m_panelBarsShow->SetPlayPoint(m_iStartBar, (int)m_dblStartPoint); iShiftBeginBar -= nOffsetBars; if( iShiftBeginBar<0 ){ iShiftBeginBar = 0; iShiftBeginPoint = 0; } iShiftEndBar -= nOffsetBars; if( iShiftEndBar<0 ){ iShiftEndBar = 0; iShiftEndPoint = 0; } } else{ if (nValidBars <= iModifyEndBar || nValidBars <= iModifyBeginBar) { m_panelBarsShow->SetModifyPos(true, -1, -1); m_panelBarsShow->SetModifyPos(false, -1, -1); } if (nValidBars <= m_iLastStartBar) { m_iLastStartBar = m_iStartBar = 0; m_dblLastStartPoint = m_dblStartPoint = 0; m_panelBarsShow->SetPlayPoint(m_iStartBar, (int)m_dblStartPoint); } } if( nValidBars<=iShiftBeginBar ){ iShiftBeginBar = iShiftEndBar = 0; iShiftBeginPoint = iShiftEndPoint = 0; } else if( nValidBars<=iShiftEndBar ){ iShiftEndBar = nValidBars-1; iShiftEndPoint = POINTS_PER_BAR-1; } if (m_bFromFile) { for (int i = 0; i < nValidBars; i++) { MELODYBAR * pBV = new MELODYBAR; pBV->tBarVol.bRecording = false; pBV->tBarVol.bInvalid = false; for( int j=0; jtBarVol.aVols[j] = f_MM_GetAudioVolume( i + j/(double)POINTS_PER_BAR ); } g_lstMelodyBars.push_back(pBV); } } else if( !g_bPredefine ){ MELODYBARLIST::iterator iBV = g_lstMelodyBars.begin(); for (int i = 0; i < nOffsetBars; i++) { delete(*iBV); iBV = g_lstMelodyBars.erase(iBV); } for (int i = 0; i < nValidBars; i++) { (*iBV)->tBarVol.bRecording = false; (*iBV)->tBarVol.bInvalid = false; iBV++; } while (iBV != g_lstMelodyBars.end()) { delete(*iBV); iBV = g_lstMelodyBars.erase(iBV); } } //波形移位 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( iShiftFromBartBarVol.aVols[iShiftToPoint] = g_lstMelodyBars[iShiftFromBar]->tBarVol.aVols[iShiftFromPoint]; iShiftToPoint++; if( iShiftToPoint>=POINTS_PER_BAR ){ iShiftToPoint = 0; iShiftToBar++; } iShiftFromPoint++; if( iShiftFromPoint>=POINTS_PER_BAR ){ iShiftFromPoint = 0; iShiftFromBar++; } } } } m_panelBarsShow->InitialVars(nValidBars); // Enter the forth page while we has done recording if( nValidBars>0 ){ PostMessage(Application->MainFormHandle, UM_REFRESH_PAGE_STATE, PAGE_ALL, 0); if( bJump ){ if( g_bPredefine ){ SaveAutoProj(); } g_iComposeKey = -1; PostMessage(Application->MainFormHandle, UM_JUMP_PAGE, WPARAM(4),LPARAM(this)); } } else{ PostMessage(Application->MainFormHandle, UM_REFRESH_PAGE_STATE, PAGE_SETUPRECORD, 0); } m_btnPrevStep->Enabled = true; m_btnNextStep->Enabled = !g_lstMelodyBars.empty(); m_btnRecord->Down = false; m_btnPlay->Visible = true; m_btnPlay->Enabled = !g_lstMelodyBars.empty(); m_btnRecord->Enabled = true; m_btnPlay->Down = false; m_btnPause->Visible = false; m_btnStop->Enabled = false; m_btnAudioEffect->Enabled = g_bAudioLoaded; // Application->MainForm->Perform(UM_HANDLEAUTOPROJ, 1, 0);//add by tj 2013/1/2 } // --------------------------------------------------------------------------- void __fastcall TRecordForm::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 TRecordForm::KeyboardMouseEnter(TObject *Sender) { Screen->Cursor = crHandPoint; } // --------------------------------------------------------------------------- void __fastcall TRecordForm::KeyboardMouseLeave(TObject *Sender) { Screen->Cursor = crDefault; } // --------------------------------------------------------------------------- void __fastcall TRecordForm::ModifyClick(TObject *Sender) { m_bModifyRecord = !m_bModifyRecord; if (m_bModifyRecord) { m_btnModify->Down = true; m_btnBeginPos->Enabled = true; m_btnEndPos->Enabled = true; if (g_lstMelodyStages.size() > 0) m_btnWithCompose->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_btnWithCompose->Enabled = false; m_panelBarsShow->ShowModifyPos(false); } } // --------------------------------------------------------------------------- void __fastcall TRecordForm::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_panelKeyboard->Visible) { ShowKeyboard( 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) { //2013.1.25 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->Enabled = true; m_btnModify->Down = false; m_btnBeginPos->Down = false; m_btnBeginPos->Enabled = false; m_btnEndPos->Down = false; m_btnEndPos->Enabled = false; m_btnWithCompose->Enabled = false; m_panelBarsShow->ShowModifyPos(false); } } } } } // --------------------------------------------------------------------------- void __fastcall TRecordForm::BeginPosClick(TObject *Sender) { m_btnBeginPos->Down = true; m_btnEndPos->Down = false; } // --------------------------------------------------------------------------- void __fastcall TRecordForm::EndPosClick(TObject *Sender) { m_btnBeginPos->Down = false; m_btnEndPos->Down = true; } // --------------------------------------------------------------------------- void __fastcall TRecordForm::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 TRecordForm::BarsShowMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { 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; } 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; if (g_lstMelodyStages.size() > 0) m_btnWithCompose->Enabled = 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 && ( iEndBarSetModifyPos(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 TRecordForm::WithComposeClick(TObject *Sender) { m_btnWithCompose->Down = !m_btnWithCompose->Down; } // --------------------------------------------------------------------------- void __fastcall TRecordForm::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_F12: #ifdef _PROFESSIONAL if (m_btnRecord->Enabled && !m_btnRecord->Down){ LoadMelodyFromFile(); } #endif break; case VK_ESCAPE: if (m_panelMicrophoneVolSet->Visible) { m_panelMicrophoneVolSet->Hide(); m_btnVolMicrophoneSet->Down = false; } if (m_panelSpeakerVolSet->Visible) { m_panelSpeakerVolSet->Hide(); m_btnVolSpeakerSet->Down = false; } if (m_panelKeyboard->Visible) { ShowKeyboard( 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_lstMelodyBars.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_btnWithCompose->Enabled) { WithComposeClick(NULL); } break; default: //Application->MainForm->OnKeyDown( Sender, Key, Shift ); break; } } // --------------------------------------------------------------------------- void __fastcall TRecordForm::DeleteBarsClick(TObject *Sender) { // 删除所选小节 } // --------------------------------------------------------------------------- void __fastcall TRecordForm::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 __fastcall TRecordForm::LBKeySelectMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if (X >= 0 && X < m_lbKeySelect->Width && Y >= 0 && Y < m_lbKeySelect->Height) { int iKey = m_lbKeySelect->ItemIndex; if( iKey >= 0 && iKey != g_iMelodyKey ){ g_iMelodyKey = iKey; m_lblKey->Caption = g_strMelodyKey[g_iMelodyKey]; if( g_bPredefine ){ g_bBaseComposeLoaded = false; g_bComposeLoaded = false; } else{ SetWavNotes(); m_bAudioModified = true; } } } m_lbKeySelect->Hide(); m_btnKeyChange->Down = false; } // --------------------------------------------------------------------------- void __fastcall TRecordForm::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 = m_iHitBar; m_dblLastStartPoint = m_dblStartPoint = m_iHitPoint; m_panelBarsShow->SetPlayPoint(m_iStartBar,(int)m_dblStartPoint); ShowPlayTime(); if (m_btnPlay->Down) { double dblAudioStartBar = m_iStartBar + m_dblStartPoint / POINTS_PER_BAR; f_MM_Play(Handle, dblAudioStartBar, TYPE_AUDIO); } } 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 TRecordForm::AudioEffectClick(TObject *Sender) { StopClick( NULL ); PostMessage(Application->MainFormHandle, UM_AUDIOEFFECT, WPARAM(0),LPARAM(0)); } //--------------------------------------------------------------------------- void __fastcall TRecordForm::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 TRecordForm::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 TRecordForm::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-deltaXSetModifyPos(true, -1, -1); return; } m_panelBarsShow->GetModifyPos(false, iModifyBar, iModifyPoint); if( iModifyBar==iHitBar && iModifyPoint+deltaX>iHitPoint && iModifyPoint-deltaXSetModifyPos(false, -1, -1); return; } } } } //--------------------------------------------------------------------------- void TRecordForm::ShowNoticeImg(const int iStepIndex) { // m_imgNotice if(iStepIndex > 4 || iStepIndex < 0) return ; switch (iStepIndex) { case 0: m_imgNotice->Picture = (TPicture*)m_imgFirst; break; case 1: m_imgNotice->Picture = (TPicture*)m_imgSecond; break; case 2: m_imgNotice->Picture = (TPicture*)m_imgThird; break; case 3: m_imgNotice->Picture = (TPicture*)m_imgForth; break; default: m_imgNotice->Picture = (TPicture*)m_imgFirst; break; } } // --------------------------------------------------------------------------- void __fastcall TRecordForm::OnPlayOver(TMessage &msg) { StopClick(NULL); } //--------------------------------------------------------------------------- void __fastcall TRecordForm::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; g_btnFontChange->Left = DPIX(451);//m_btnShowKeyboard->Left + m_btnShowKeyboard->Width + 20; g_panelFontName->Left = g_btnFontChange->Left + g_btnFontChange->Width; g_lbFontSelect->Left = g_panelFontName->Left; } } //--------------------------------------------------------------------------- void __fastcall TRecordForm::UMHidePopControl(TMessage &msg) { if( m_btnBeginPos->Down ){ m_btnBeginPos->Down = false; } if( m_btnEndPos->Down ){ m_btnEndPos->Down = false; } if( m_lbKeySelect->Visible ){ m_lbKeySelect->Hide(); m_btnKeyChange->Down = false; } if( g_lbFontSelect->Visible ){ g_lbFontSelect->Hide(); g_btnFontChange->Down = false; } } //---------------------------------------------------------------------------