⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nokiacomposerview.cpp

📁 Nokia手机语音管理程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:

    if (dwReturn = mciSendCommand(NULL, MCI_OPEN,
        MCI_OPEN_TYPE | MCI_OPEN_ELEMENT,
        (DWORD)(LPVOID) &mciOpenParms))
    {
      CString errorString;

      mciGetErrorString(dwReturn, errorString.GetBuffer(300), 300);
      errorString.ReleaseBuffer();

      AfxMessageBox(CString("Error al reproducir el fichero midi: \n") + 
        CString(lpszMIDIFileName) + CString("\n") + 
        errorString , MB_ICONERROR);

      // Failed to open device. Don't close it; just return error.
      return (dwReturn);
    }

    // The device opened successfully; get the device ID.
    midiDeviceID_ = mciOpenParms.wDeviceID;

    // Check if the output port is the MIDI mapper.
    mciStatusParms.dwItem = MCI_SEQ_STATUS_PORT;
    if (dwReturn = mciSendCommand(midiDeviceID_, MCI_STATUS, 
        MCI_STATUS_ITEM, (DWORD)(LPVOID) &mciStatusParms))
    {
        mciSendCommand(midiDeviceID_, MCI_CLOSE, 0, NULL);
        return (dwReturn);
    }

    // Begin playback. The window procedure function for the parent 
    // window will be notified with an MM_MCINOTIFY message when 
    // playback is complete. At this time, the window procedure closes 
    // the device.
    mciPlayParms.dwCallback = (DWORD) GetSafeHwnd();
    if (dwReturn = mciSendCommand(midiDeviceID_, MCI_PLAY, MCI_NOTIFY, 
        (DWORD)(LPVOID) &mciPlayParms))
    {
        mciSendCommand(midiDeviceID_, MCI_CLOSE, 0, NULL);
        return (dwReturn);
    }

    return (0L);
}
 

// +-------------------------------------------------------------
// |
// | Function        : CNokiaComposerView::OnMCINotify
// | Description     : 
// |
// | wFlags          : 
// | lDevID          : 
// | 
// +-------------------------------------------------------------
LRESULT CNokiaComposerView::OnMCINotify(WPARAM wFlags, LPARAM lDevID)
{
  mciSendCommand(lDevID, MCI_CLOSE, 0, NULL);
  playingMIDI_ = false;

  switch( wFlags )
  {
  case MCI_NOTIFY_ABORTED:
    TRACE("MCI_NOTIFY_ABORTED\n");
    break;
  case MCI_NOTIFY_FAILURE:
    TRACE("MCI_NOTIFY_FAILURE\n");
    break;
  case MCI_NOTIFY_SUCCESSFUL:
    TRACE("MCI_NOTIFY_SUCCESSFUL\n");
    break;
  case MCI_NOTIFY_SUPERSEDED:
    TRACE("MCI_NOTIFY_SUPERSEDED\n");
    break;
  }
  return 0;
}

// +-------------------------------------------------------------
// |
// | Function        : CNokiaComposerView::OnStop
// | Description     : 
// | 
// +-------------------------------------------------------------
void CNokiaComposerView::OnStop() 
{
  mciSendCommand(midiDeviceID_, MCI_CLOSE, 0, NULL);
  playingMIDI_ = false;
}

// +-------------------------------------------------------------
// |
// | Function        : CNokiaComposerView::OnClose
// | Description     : 
// | 
// +-------------------------------------------------------------
void CNokiaComposerView::OnClose() 
{
  if( playingMIDI_ )
  {
    OnStop();
  }
	CFormView::OnClose();
}

// +-------------------------------------------------------------
// |
// | Function        : CNokiaComposerView::SetMelodyTextFormat
// | Description     : 
// | 
// +-------------------------------------------------------------
void CNokiaComposerView::SetMelodyTextFormat()
{
  CRichEditCtrl* pEdit;

  CHARFORMAT cf;
  cf.cbSize = sizeof(CHARFORMAT);  

  cf.dwMask      = CFM_COLOR | CFM_FACE | CFM_SIZE | CFM_BOLD;
  cf.dwEffects   = 0;
  cf.yHeight     = 10 * 20;
  cf.crTextColor = RGB(20,20,20);
  strcpy(cf.szFaceName, "Courier New");

  pEdit = (CRichEditCtrl*) GetDlgItem(IDC_MELODY);
  pEdit->SetDefaultCharFormat(cf);

  pEdit = (CRichEditCtrl* ) GetDlgItem(IDC_KEY_SEQUENCE);
  pEdit->SetDefaultCharFormat(cf);
}

// +-------------------------------------------------------------
// |
// | Funci髇         : CNokiaComposerView::OnGenerateKeySequence
// | Descripci髇     : 
// | 
// +-------------------------------------------------------------
void CNokiaComposerView::OnGenerateKeySequence() 
{
  int modifiedFlag = GetDocument()->IsModified();
  UpdateDocument();
  GetDocument()->SetModifiedFlag(modifiedFlag);

  KeySequence keySequence;
  
  keySequence.GenerateFromMelody( GetDocument()->GetMelody() );
  
  SetDlgItemText( IDC_KEY_SEQUENCE, keySequence.GetString() );
  SetDlgItemInt( IDC_KEY_COUNT, keySequence.GetKeyCount() );
}

// +-------------------------------------------------------------
// |
// | Funci髇         : CNokiaComposerView::OnGenerateNotes
// | Descripci髇     : 
// | 
// +-------------------------------------------------------------
void CNokiaComposerView::OnGenerateNotes() 
{
  CString keyString;
  
  GetDlgItemText( IDC_KEY_SEQUENCE, keyString );
  KeySequence keySequence( keyString );

  ModifyDoc md( GetDocument() );
  Melody& melody = md.GetMelody();

  melody.ParseKeySequence( keySequence );

  GetDocument()->UpdateAllViews(0,0,0);
}

// +-------------------------------------------------------------
// |
// | Funci髇         : CNokiaComposerView::OnOctaveDown
// | Descripci髇     : 
// | 
// +-------------------------------------------------------------
void CNokiaComposerView::OnOctaveDown() 
{
  ModifyDoc md( GetDocument() );
  Melody& melody = md.GetMelody();

  if( melody.CanOctaveDown() )
  {
    melody.OctaveDown();
  }
  else
  {
    MessageBeep(MB_ICONASTERISK);
  }

  GetDocument()->UpdateAllViews(0,0,0);
}

// +-------------------------------------------------------------
// |
// | Funci髇         : CNokiaComposerView::OnOctaveUp
// | Descripci髇     : 
// | 
// +-------------------------------------------------------------
void CNokiaComposerView::OnOctaveUp() 
{
  ModifyDoc md( GetDocument() );
  Melody& melody = md.GetMelody();

  if( melody.CanOctaveUp() )
  {
    melody.OctaveUp();
  }
  else
  {
    MessageBeep(MB_ICONASTERISK);
  }

  GetDocument()->UpdateAllViews(0,0,0);
}

// +-------------------------------------------------------------
// |
// | Funci髇         : CNokiaComposerView::OnSemitoneDown
// | Descripci髇     : 
// | 
// +-------------------------------------------------------------
void CNokiaComposerView::OnSemitoneDown() 
{
  ModifyDoc md( GetDocument() );
  Melody& melody = md.GetMelody();

  if( melody.CanSemitoneDown() )
  {
    melody.SemitoneDown();
  }
  else
  {
    MessageBeep(MB_ICONASTERISK);
  }

  GetDocument()->UpdateAllViews(0,0,0);
}

// +-------------------------------------------------------------
// |
// | Funci髇         : CNokiaComposerView::OnSemitoneUp
// | Descripci髇     : 
// | 
// +-------------------------------------------------------------
void CNokiaComposerView::OnSemitoneUp() 
{
  ModifyDoc md( GetDocument() );
  Melody& melody = md.GetMelody();

  if( melody.CanSemitoneUp() )
  {
    melody.SemitoneUp();
  }
  else
  {
    MessageBeep(MB_ICONASTERISK);
  }

  GetDocument()->UpdateAllViews(0,0,0);
}

// +-------------------------------------------------------------
// |
// | Funci髇         : CNokiaComposerView::OnEditCopy
// | Descripci髇     : 
// | 
// +-------------------------------------------------------------
void CNokiaComposerView::OnEditCopy() 
{
  CWnd* pFocusWnd = GetFocus();
  int   focusId = pFocusWnd->GetDlgCtrlID();

  pFocusWnd->SendMessage(WM_COPY,0,0);
}

// +-------------------------------------------------------------
// |
// | Funci髇         : CNokiaComposerView::OnEditCut
// | Descripci髇     : 
// | 
// +-------------------------------------------------------------
void CNokiaComposerView::OnEditCut() 
{
  CWnd* pFocusWnd = GetFocus();
  int   focusId = pFocusWnd->GetDlgCtrlID();

  pFocusWnd->SendMessage(WM_CUT,0,0);
}

// +-------------------------------------------------------------
// |
// | Funci髇         : CNokiaComposerView::OnEditUndo
// | Descripci髇     : 
// | 
// +-------------------------------------------------------------
void CNokiaComposerView::OnEditUndo() 
{
  CWnd* pFocusWnd = GetFocus();
  int   focusId = pFocusWnd->GetDlgCtrlID();

  pFocusWnd->SendMessage(WM_UNDO,0,0);
}

// +-------------------------------------------------------------
// |
// | Funci髇         : CNokiaComposerView::OnUpdateOctaveDown
// | Descripci髇     : 
// |
// | pCmdUI          : 
// | 
// +-------------------------------------------------------------
void CNokiaComposerView::OnUpdateOctaveDown(CCmdUI* pCmdUI) 
{
  const Melody &melody = GetDocument()->GetMelody();
  
  pCmdUI->Enable( melody.CanOctaveDown() );
}

// +-------------------------------------------------------------
// |
// | Funci髇         : CNokiaComposerView::OnUpdateOctaveUp
// | Descripci髇     : 
// |
// | pCmdUI          : 
// | 
// +-------------------------------------------------------------
void CNokiaComposerView::OnUpdateOctaveUp(CCmdUI* pCmdUI) 
{
  const Melody &melody = GetDocument()->GetMelody();
  
  pCmdUI->Enable( melody.CanOctaveUp() );	
}

// +-------------------------------------------------------------
// |
// | Funci髇         : CNokiaComposerView::OnUpdateSemitoneDown
// | Descripci髇     : 
// |
// | pCmdUI          : 
// | 
// +-------------------------------------------------------------
void CNokiaComposerView::OnUpdateSemitoneDown(CCmdUI* pCmdUI) 
{
  const Melody &melody = GetDocument()->GetMelody();
  
  pCmdUI->Enable( melody.CanSemitoneDown() );
}

// +-------------------------------------------------------------
// |
// | Funci髇         : CNokiaComposerView::OnUpdateSemitoneUp
// | Descripci髇     : 
// |
// | pCmdUI          : 
// | 
// +-------------------------------------------------------------
void CNokiaComposerView::OnUpdateSemitoneUp(CCmdUI* pCmdUI) 
{
  const Melody &melody = GetDocument()->GetMelody();
  
  pCmdUI->Enable( melody.CanSemitoneUp() );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -