📄 dlgdest.cpp
字号:
}
// clean up
SafeLocalFree( pvConversion );
}
if(fRes)
{
// make playable
m_fPlayable = TRUE;
m_butPlay.EnableWindow(m_fPlayable);
}
}
// ----------------------------------------------------------------------------------
// OnPlay
// ----------------------------------------------------------------------------------
void
CDlgDest::OnPlay
()
{
MMRESULT mmRes = MMSYSERR_NOERROR;
//
// must not be in use
//
ASSERT( 0 == g_hwo );
if( 0 == m_lpwhdr )
{
m_lpwhdr = ( LPWAVEHDR )LocalAlloc( LPTR, sizeof( WAVEHDR ) );
if( 0 == m_lpwhdr )
{
MessageBox( "Insufficient memory for rendering !", "MultiChan : Error", MB_ICONEXCLAMATION | MB_OK );
return;
}
}
m_lpwhdr->dwBufferLength = m_cbData;
m_lpwhdr->lpData = ( char * )m_pbData;
//
// open wave device
//
mmRes = waveOutOpen( &g_hwo, // handle of the output device
WAVE_MAPPER, // as appropriate
( WAVEFORMATEX* )&m_wfExt, // describe what's next
( DWORD_PTR )WavePlayFileCB, // the callback
( DWORD_PTR )this, // object issuing the request
CALLBACK_FUNCTION // callback via function
);
if(TrapMMError(mmRes, "waveOutOpen"))
{
//
// prepare the header
//
mmRes = waveOutPrepareHeader(g_hwo, m_lpwhdr, sizeof(WAVEHDR));
if(TrapMMError(mmRes, "waveOutPrepareHeader"))
{
//
// revert playable state
//
WaveTogglePlayback( WAVE_TOGGLE_DESTINATION, WAVE_TOGGLE_DISABLE );
//
// start singing
//
mmRes = waveOutWrite(g_hwo, m_lpwhdr, sizeof(WAVEHDR));
TrapMMError(mmRes, "waveOutWrite");
} // prepare header
} // open
} // OnPlay
// ----------------------------------------------------------------------------------
// OnStop
// ----------------------------------------------------------------------------------
void
CDlgDest::OnStop
()
{
MMRESULT mmRes = MMSYSERR_NOERROR;
//
// ensure validity
//
ASSERT( g_hwo );
ASSERT( !m_fPlayable );
//
// stop playback
//
mmRes = waveOutReset( g_hwo );
TrapMMError( mmRes, "waveOutReset" );
} // OnStop
//
// RecalcDependant
//
void
CDlgDest::RecalcDependantVariables
()
{
m_wfExt.Format.nBlockAlign = m_wfExt.Format.wBitsPerSample * m_wfExt.Format.nChannels / 8;
m_wfExt.Format.nAvgBytesPerSec = m_wfExt.Format.nBlockAlign * m_wfExt.Format.nSamplesPerSec;
// update UI
char sz[100];
_snprintf(sz, 100, "%d", m_wfExt.Format.nAvgBytesPerSec);
SetDlgItemText(IDC_AVEBITS, sz);
}
/*
* CDlgDest
* UI operations
*/
// ----------------------------------------------------------------------------------
// track combobox changes
// ----------------------------------------------------------------------------------
void
CDlgDest::OnComboSamplerate
()
{
m_wfExt.Format.nSamplesPerSec = ( DWORD )m_comboSampleRate.GetItemData(m_comboSampleRate.GetCurSel());
RecalcDependantVariables();
}
void
CDlgDest::OnComboBitdepth
()
{
m_wfExt.Format.wBitsPerSample = (USHORT)m_comboBitDepth.GetItemData(m_comboBitDepth.GetCurSel());
m_wfExt.Samples.wValidBitsPerSample = min(m_wfExt.Samples.wValidBitsPerSample, m_wfExt.Format.wBitsPerSample);
m_wValidBitsPerSample = m_wfExt.Samples.wValidBitsPerSample;
RecalcDependantVariables();
UpdateData(FALSE); // update m_wValidBitsPerSample display
}
void
CDlgDest::OnComboWaveformat
()
{
m_wfExt.Format.wFormatTag = (WORD)m_comboFormat.GetItemData(m_comboFormat.GetCurSel());
switch(m_wfExt.Format.wFormatTag)
{
case WAVE_FORMAT_PCM:
m_wfExt.Format.cbSize = 0;
break;
case WAVE_FORMAT_IEEE_FLOAT:
m_wfExt.Format.cbSize = 0;
break;
case WAVE_FORMAT_EXTENSIBLE:
m_wfExt.Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX);
break;
default:
MessageBox("Format type not supported", "MultiChan : Warning", MB_ICONWARNING | MB_OK);
break;
}
}
// ----------------------------------------------------------------------------------
// Update
// ----------------------------------------------------------------------------------
void
CDlgDest::Update
()
{
// update dwChannelMask
CDlgSrc* pdlgSrc = 0;
BOOL fGotSources = (0 != g_listSources.GetCount() );
m_cRemix.EnableWindow( fGotSources );
m_cValidBits.EnableWindow( fGotSources );
m_cChannels.EnableWindow( fGotSources );
m_cOutput.EnableWindow( fGotSources );
m_comboBitDepth.EnableWindow( fGotSources );
m_comboSampleRate.EnableWindow( fGotSources );
m_cAveBitsPerSec.EnableWindow( fGotSources );
m_cChannelMask.EnableWindow( fGotSources );
m_comboFormat.EnableWindow( fGotSources );
m_butPlay.EnableWindow( fGotSources && m_pbData );
m_butStop.EnableWindow( !fGotSources );
//
// setting channel mask - if SPEAKER_NOT_SPECIFIED, don't mind
//
m_wfExt.dwChannelMask = 0;
for
(
POSITION pos = g_listSources.GetHeadPosition();
pos;
)
{
//
// iterative step
//
pdlgSrc = g_listSources.GetNext(pos);
if( !(SPEAKER_NOT_SPECIFIED & pdlgSrc->m_dwChannelMask) )
m_wfExt.dwChannelMask |= pdlgSrc->m_dwChannelMask;
} // for
m_wfExt.dwChannelMask &= 0x7fffffff; // correct any deviations
//
// set up a proper WAVEFORMATEXTENSIBLE (number of channels = the number of SRC dialogs that were created)
//
m_wfExt.Format.nChannels = (WORD)g_listSources.GetCount();
if(m_wfExt.Format.nChannels > 2)
{
m_wfExt.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
m_wfExt.Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX);
m_comboFormat.SelectString(0, "WAVE_FORMAT_EXTENSIBLE");
}
RecalcDependantVariables();
m_wValidBitsPerSample = m_wfExt.Samples.wValidBitsPerSample;
// update UI
char sz[100];
_snprintf(sz, 100, "%d", m_wfExt.Format.nChannels);
SetDlgItemText(IDC_CHANNELS, sz);
m_strChannelMask.Format("0x%08x", m_wfExt.dwChannelMask);
UpdateData(FALSE);
}
void
CDlgDest::OnEditValidbits
()
{
UpdateData(TRUE);
m_wfExt.Samples.wValidBitsPerSample = LOWORD(m_wValidBitsPerSample);
}
// ----------------------------------------------------------------------------------
// dummy implementations to prevent dlgs from disappearing when user hits enter or esc
// ----------------------------------------------------------------------------------
void CDlgDest::OnOK()
{
// do nothing
}
void CDlgDest::OnCancel()
{
// do nothing
}
HBRUSH
CDlgDest::OnCtlColor
(
CDC* pDC,
CWnd* pWnd,
UINT nCtlColor
)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if((nCtlColor == CTLCOLOR_STATIC))
{
if(pWnd->m_hWnd == m_cOutput.m_hWnd)
{
pDC->SetBkColor(GetSysColor(COLOR_ACTIVECAPTION));
pDC->SetTextColor(GetSysColor(COLOR_CAPTIONTEXT));
return GetSysColorBrush(COLOR_ACTIVECAPTION);
}
}
return hbr;
}
void
CDlgDest::OnLButtonDown
(
UINT nFlags,
CPoint point
)
{
RECT rcClient;
m_cOutput.GetClientRect(&rcClient);
m_cOutput.MapWindowPoints(this, &rcClient);
m_fDragging = PtInRect(&rcClient, point);
if(m_fDragging)
{
SetCapture();
m_fDragging = TRUE;
m_ptPosInCaption = point;
}
CDialog::OnLButtonDown(nFlags, point);
SetFocus();
SetWindowPos(&wndTop, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
}
void
CDlgDest::OnLButtonUp
(
UINT nFlags,
CPoint point
)
{
m_fDragging = FALSE;
ReleaseCapture();
CDialog::OnLButtonUp(nFlags, point);
}
void
CDlgDest::OnMouseMove
(
UINT nFlags,
CPoint point
)
{
RECT rcClientParent;
GetParent()->GetClientRect(&rcClientParent);
GetParent()->MapWindowPoints(this, &rcClientParent);
if(PtInRect(&rcClientParent, point))
{
if(m_fDragging)
{
CRect rcWindow;
CRect rcParent;
CPoint pt(point.x - m_ptPosInCaption.x, point.y - m_ptPosInCaption.y);
GetWindowRect(&rcWindow);
GetParent()->GetWindowRect(&rcParent);
rcWindow.OffsetRect(pt);
rcWindow -= rcParent.TopLeft();
SetWindowPos(NULL, rcWindow.left, rcWindow.top, 0,0, SWP_NOZORDER | SWP_NOSIZE);
}
}
else
{
ReleaseCapture();
m_fDragging = FALSE;
}
}
/*
* CDlgDest
* message processing
*/
LRESULT
CDlgDest::WindowProc
(
UINT nMessage,
WPARAM wParam,
LPARAM lParam
)
{
MMRESULT mmRes = MMSYSERR_NOERROR;
switch( nMessage )
{
case WM_START_PLAYBACK:
{
break;
}
case WM_STOP_PLAYBACK:
{
//
// revert playable state
//
WaveTogglePlayback( WAVE_TOGGLE_DESTINATION, WAVE_TOGGLE_ALLOW );
//
// unprepare and release
//
mmRes = waveOutUnprepareHeader( g_hwo, m_lpwhdr, sizeof( WAVEHDR ) );
if( TrapMMError( mmRes, "waveOutUnprepareHeader" ) )
{
mmRes = waveOutClose( g_hwo );
TrapMMError( mmRes, "waveOutClose" );
g_hwo = 0;
}
break;
}
}
return( CWnd::WindowProc( nMessage, wParam, lParam ) );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -