//----------------------------------------------------------------------------- // // Musepack Demuxer // // Author : Igor Janos // //----------------------------------------------------------------------------- #include "stdafx.h" #include "..\resource.h" // minimalny a maximalny cas, ktory je mozne navolit v property pagese #define MIN_TIME 1 #define MAX_TIME 10 #define ITEM(x) GetDlgItem(m_Dlg, x) void MakeNiceTime(int time_ms, CString &v) { int ms = time_ms%1000; time_ms -= ms; time_ms /= 1000; int h, m, s; h = time_ms / 3600; time_ms -= h*3600; m = time_ms / 60; time_ms -= m*60; s = time_ms; v.Format(_T("%.2d:%.2d:%.2d,%.3d"), h, m, s, ms); } //----------------------------------------------------------------------------- // // CMPCPropertyPage class // //----------------------------------------------------------------------------- CUnknown *CMPCPropertyPage::CreateInstance(LPUNKNOWN lpUnk, HRESULT *phr) { return new CMPCPropertyPage(lpUnk, phr); } CMPCPropertyPage::CMPCPropertyPage(LPUNKNOWN lpUnk, HRESULT *phr) : CBasePropertyPage(NAME("MPC Property Page"), lpUnk, IDD_PAGE_DEMUX, IDS_PAGE_DEMUX), demux(NULL) { } CMPCPropertyPage::~CMPCPropertyPage() { } HRESULT CMPCPropertyPage::OnConnect(IUnknown *pUnknown) { // hold a pointer ASSERT(!demux); HRESULT hr = pUnknown->QueryInterface(IID_IMusepackSplitter, (void**)&demux); if (FAILED(hr)) return hr; // okej return NOERROR; } HRESULT CMPCPropertyPage::OnDisconnect() { if (demux) { demux->Release(); demux = NULL; } return NOERROR; } HRESULT CMPCPropertyPage::OnActivate() { demux->SetPropertyPageWindow(m_Dlg); // initialize out controls LVCOLUMN col; col.mask = LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; col.pszText = _T("Name"); col.cx = 105; col.iSubItem = 0; ListView_InsertColumn(ITEM(IDC_LIST_CONTENT), 0, &col); col.pszText = _T("Value"); col.cx = 100; col.iSubItem = 1; ListView_InsertColumn(ITEM(IDC_LIST_CONTENT), 1, &col); UpdateList(); return NOERROR; } HRESULT CMPCPropertyPage::OnDeactivate() { demux->SetPropertyPageWindow(NULL); return NOERROR; } void CMPCPropertyPage::UpdateList() { // first reset everything ListView_DeleteAllItems(ITEM(IDC_LIST_CONTENT)); // now check for the file MPC_File_Info info; HRESULT hr = demux->GetFileInfo(&info); if (FAILED(hr)) return ; // now fill in the values CString name, val; LVITEM i; int item; i.mask = LVIF_TEXT; i.iSubItem = 0; // Duration i.pszText = _T("Duration"); i.iItem = 0; MakeNiceTime(info.duration * 1000, val); item = ListView_InsertItem(ITEM(IDC_LIST_CONTENT), &i); ListView_SetItemText(ITEM(IDC_LIST_CONTENT), item, 1, val.GetBuffer()); // Stream version i.pszText = _T("Stream version"); i.iItem = 1; val.Format(_T("%d"), info.stream_version); item = ListView_InsertItem(ITEM(IDC_LIST_CONTENT), &i); ListView_SetItemText(ITEM(IDC_LIST_CONTENT), item, 1, val.GetBuffer()); // Stream version i.pszText = _T("Sample rate"); i.iItem = 2; val.Format(_T("%d Hz"), info.sample_rate); item = ListView_InsertItem(ITEM(IDC_LIST_CONTENT), &i); ListView_SetItemText(ITEM(IDC_LIST_CONTENT), item, 1, val.GetBuffer()); // Channels i.pszText = _T("Channels"); i.iItem = 3; val.Format(_T("%d"), info.channels); item = ListView_InsertItem(ITEM(IDC_LIST_CONTENT), &i); ListView_SetItemText(ITEM(IDC_LIST_CONTENT), item, 1, val.GetBuffer()); // Gains i.pszText = _T("Title gain"); i.iItem = 4; val.Format(_T("%3.2f dB"), info.gain_title_db); item = ListView_InsertItem(ITEM(IDC_LIST_CONTENT), &i); ListView_SetItemText(ITEM(IDC_LIST_CONTENT), item, 1, val.GetBuffer()); i.pszText = _T("Title peak"); i.iItem = 5; val.Format(_T("%8.6f"), info.gain_title_peak_db); item = ListView_InsertItem(ITEM(IDC_LIST_CONTENT), &i); ListView_SetItemText(ITEM(IDC_LIST_CONTENT), item, 1, val.GetBuffer()); i.pszText = _T("Album gain"); i.iItem = 6; val.Format(_T("%3.2f dB"), info.gain_album_db); item = ListView_InsertItem(ITEM(IDC_LIST_CONTENT), &i); ListView_SetItemText(ITEM(IDC_LIST_CONTENT), item, 1, val.GetBuffer()); i.pszText = _T("Album peak"); i.iItem = 7; val.Format(_T("%8.6f"), info.gain_album_peak_db); item = ListView_InsertItem(ITEM(IDC_LIST_CONTENT), &i); ListView_SetItemText(ITEM(IDC_LIST_CONTENT), item, 1, val.GetBuffer()); if (info.stream_version == 8) { // Frames per packet i.pszText = _T("Frames per packet"); i.iItem = 8; val.Format(_T("%d"), info.block_frames); item = ListView_InsertItem(ITEM(IDC_LIST_CONTENT), &i); ListView_SetItemText(ITEM(IDC_LIST_CONTENT), item, 1, val.GetBuffer()); } } INT_PTR CMPCPropertyPage::OnReceiveMessage(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_UPDATE_VISUALS: UpdateList(); break; } return __super::OnReceiveMessage(hwnd, uMsg, wParam, lParam); }