void CMainDlg::PutSetting(CTrackBarCtrl& slid, CEdit& ed, double val, double div, int inv) { if (inv) slid.SetPos(inv - (int) (val * div)); else slid.SetPos((int) (val * div)); char valstr[40]; sprintf(valstr, "%6.3f", val); ed.SetWindowText(valstr); }
void prefs_file::LoadFile(int filename_id, int metadata_id, int level_id, int enable_id) { COMDLG_FILTERSPEC c_rgSaveTypes[] = { { _T("Audio Files"), L"*.aiff;*.au;*.caf;*.flac;*.iff;*.mat;*.nist;*.ogg;*.paf;*.rf64;*.sf;*.snd;*.sph;*.svx;*.voc;*.w64;*.wav" }, { _T("All Files"), L"*.*"} }; // CoCreate the File Open Dialog object. IFileDialog *pfd = NULL; HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pfd)); if (SUCCEEDED(hr)) { // Set the file types to display only. // Notice that this is a 1-based array. hr = pfd->SetFileTypes(ARRAYSIZE(c_rgSaveTypes), c_rgSaveTypes); if (SUCCEEDED(hr)) { // Show the dialog hr = pfd->Show(NULL); if (SUCCEEDED(hr)) { // Obtain the result once the user clicks // the 'Open' button. // The result is an IShellItem object. IShellItem *psiResult; hr = pfd->GetResult(&psiResult); if (SUCCEEDED(hr)) { PWSTR pszFilePath = NULL; hr = psiResult->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath); if (SUCCEEDED(hr)) { int n_channels; int n_frames; int sampling_rate; double attenuation; // Calculate the optimum attentuation to prevent clipping if (preprocessor::calculate_attenuation(pszFilePath, FILTER_LEN, REALSIZE, &attenuation, &n_channels, &n_frames, &sampling_rate)) { SetDlgItemText(filename_id, pszFilePath); std::wstringstream info; info << n_frames << L" samples, " << n_channels << L" channels, " << sampling_rate << L" Hz"; SetDlgItemText(metadata_id, info.str().c_str()); CTrackBarCtrl slider = GetDlgItem(IDC_SLIDER_LEVEL1); slider.SetPos((int)(attenuation * FILE_LEVEL_STEPS_PER_DB)); CheckDlgButton(enable_id, 1); RefreshFileLevelLabel(); } CoTaskMemFree(pszFilePath); } psiResult->Release(); } } } } pfd->Release(); }