// FilePlayerDLG.cpp : 実装ファイル // #include "stdafx.h" #include "resource.h" #include "FilePlayerDLG.h" // CFilePlayerDLG ダイアログ IMPLEMENT_DYNAMIC(CFilePlayerDLG, CDialog) CFilePlayerDLG::CFilePlayerDLG(CNiDevice* dev, BOOL lgn, FileDevParam param, CWnd* pParent /*=NULL*/) : CDialog(CFilePlayerDLG::IDD, pParent) { // dev_param = param; lap_param = param; lap_param.start_frame = 0; lap_param.controler = &control; lap_param.counter = NULL; stop_frame = 0; control = NI_FILE_PLAYER_START; playing = FALSE; pause = FALSE; nidev = dev; login = lgn; playButton = NULL; stopButton = NULL; pauseButton = NULL; exitButton = NULL; reptButton = NULL; calcButton = NULL; mirrButton = NULL; cmButton = NULL; posButton = NULL; tmscaleSldr = NULL; tmscaleEBox = NULL; allfrmEBox = NULL; plytmEBox = NULL; frameEBox = NULL; stateEBox = NULL; } void CFilePlayerDLG::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CFilePlayerDLG, CDialog) ON_BN_CLICKED(IDC_BUTTON_FLPLAYER_PLAY, &CFilePlayerDLG::OnButtonPlay) ON_BN_CLICKED(IDC_BUTTON_FLPLAYER_STOP, &CFilePlayerDLG::OnButtonStop) ON_BN_CLICKED(IDC_BUTTON_FLPLAYER_PAUSE, &CFilePlayerDLG::OnButtonPause) ON_BN_CLICKED(IDC_BUTTON_FLPLAYER_EXIT, &CFilePlayerDLG::OnButtonExit) ON_WM_CLOSE() ON_BN_CLICKED(IDC_CHECK_FLPLAYER_REPEAT, &CFilePlayerDLG::OnCheckLoop) ON_BN_CLICKED(IDC_CHECK_FLPLAYER_CALCQUAT, &CFilePlayerDLG::OnCheckQuat) ON_BN_CLICKED(IDC_CHECK_FLPLAYER_INITPOS, &CFilePlayerDLG::OnCheckInitpos) ON_BN_CLICKED(IDC_CHECK_FLPLAYER_CMUNIT, &CFilePlayerDLG::OnCheckCmUnit) ON_BN_CLICKED(IDC_CHECK_FLPLAYER_MIRROR, &CFilePlayerDLG::OnCheckMirror) ON_EN_CHANGE(IDC_EDIT_FLPLAYER_TIMESCALE, &CFilePlayerDLG::OnChangeTimeScale) ON_WM_HSCROLL() END_MESSAGE_MAP() void CFilePlayerDLG::terminate(void) { control = NI_FILE_PLAYER_STOP; ::Sleep(NIDEVICE_WAIT_TIME); } BOOL CFilePlayerDLG::OnInitDialog() { TCHAR buf[LNAME]; CDialog::OnInitDialog(); playButton = (CButton*)GetDlgItem(IDC_BUTTON_FLPLAYER_PLAY); stopButton = (CButton*)GetDlgItem(IDC_BUTTON_FLPLAYER_STOP); pauseButton = (CButton*)GetDlgItem(IDC_BUTTON_FLPLAYER_PAUSE); exitButton = (CButton*)GetDlgItem(IDC_BUTTON_FLPLAYER_EXIT); reptButton = (CButton*)GetDlgItem(IDC_CHECK_FLPLAYER_REPEAT); calcButton = (CButton*)GetDlgItem(IDC_CHECK_FLPLAYER_CALCQUAT); mirrButton = (CButton*)GetDlgItem(IDC_CHECK_FLPLAYER_MIRROR); cmButton = (CButton*)GetDlgItem(IDC_CHECK_FLPLAYER_CMUNIT); posButton = (CButton*)GetDlgItem(IDC_CHECK_FLPLAYER_INITPOS); tmscaleSldr = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_FLPLAYER_TIMESCALE); tmscaleEBox = (CEdit*)GetDlgItem(IDC_EDIT_FLPLAYER_TIMESCALE); allfrmEBox = (CEdit*)GetDlgItem(IDC_INFO_FLPLAYER_ALLFRAME); plytmEBox = (CEdit*)GetDlgItem(IDC_INFO_FLPLAYER_ALLTIME); frameEBox = (CEdit*)GetDlgItem(IDC_INFO_FLPLAYER_FRAME); stateEBox = (CEdit*)GetDlgItem(IDC_INFO_FLPLAYER_STATE); lap_param.counter = frameEBox; playButton->GetFocus(); // if (lap_param.repeat) reptButton->SetCheck(1); else reptButton->SetCheck(0); if (lap_param.calc_quat) calcButton->SetCheck(1); else calcButton->SetCheck(0); if (lap_param.mirroring) mirrButton->SetCheck(1); else mirrButton->SetCheck(0); if (lap_param.cm_unit) cmButton->SetCheck(1); else cmButton->SetCheck(0); if (lap_param.init_pos) posButton->SetCheck(1); else posButton->SetCheck(0); // tmscaleSldr->SetRange(-100, 100); double pos = - log(lap_param.time_scale)/log(2.0)*10.0; tmscaleSldr->SetPos(100); // for bug when pos==0 tmscaleSldr->SetPos((int)pos); int val = - (int)lap_param.time_scale; if (val==0 && lap_param.time_scale!=0.0) { val = (int)(1.0/lap_param.time_scale); } if (val==0 || val==-1) val = 1; sntprintf(buf, LNAME, _T("%d"), val); tmscaleEBox->SetWindowText(buf); // Information sntprintf(buf, LNAME, _T(" %d"), nidev->getFileFrameNum()); allfrmEBox->SetWindowText(buf); sntprintf(buf, LNAME, _T(" %-8.2f"), nidev->getFilePlayTime()*lap_param.time_scale); plytmEBox->SetWindowText(buf); frameEBox->SetWindowText(_T(" 0")); stateEBox->SetWindowText(_T(" STOP")); stopButton->EnableWindow(FALSE); pauseButton->EnableWindow(FALSE); return TRUE; } void CFilePlayerDLG::OnOK() { // for press Enter key } void CFilePlayerDLG::play_file_data(void) { if (lap_param.start_frame<0) { dev_param.start_frame = lap_param.start_frame = stop_frame; } if (lap_param.start_frame<0) return; TCHAR buf[LNAME]; stateEBox->SetWindowText(_T(" PLAY")); sntprintf(buf, LNAME, _T(" %d"), lap_param.start_frame); frameEBox->SetWindowText(buf); do { if (lap_param.start_frame==0) { dev_param = lap_param; } stop_frame = nidev->execLoadedData(login, dev_param); if (lap_param.repeat && (control==NI_FILE_PLAYER_START || control==NI_FILE_PLAYER_GO)) lap_param.start_frame = 0; } while(lap_param.repeat && (control==NI_FILE_PLAYER_START || control==NI_FILE_PLAYER_GO)); nidev->clearLocalFPS(); if (stop_frame<0) { ::MessageBox(nidev->hWnd, nidev->getErrorMessage(), _T("Error"), MB_OK); } // no repeat if (control==NI_FILE_PLAYER_START || control==NI_FILE_PLAYER_GO) { control = NI_FILE_PLAYER_STOP; //tmscaleSldr->EnableWindow(TRUE); //tmscaleEBox->EnableWindow(TRUE); } playing = FALSE; if (!pause) { playButton->EnableWindow(TRUE); stopButton->EnableWindow(FALSE); } if (control==NI_FILE_PLAYER_STOP) { OnButtonStop(); } return; } void CFilePlayerDLG::OnButtonPlay() { if (playing || pause) return; control = NI_FILE_PLAYER_START; playing = TRUE; //tmscaleSldr->EnableWindow(FALSE); //tmscaleEBox->EnableWindow(FALSE); playButton->EnableWindow(FALSE); stopButton->EnableWindow(TRUE); pauseButton->EnableWindow(TRUE); play_file_data(); } void CFilePlayerDLG::OnButtonPause() { if (pause) { control = NI_FILE_PLAYER_GO; pause = FALSE; playing = TRUE; play_file_data(); } else if (playing) { control = NI_FILE_PLAYER_PAUSE; pause = TRUE; playing = FALSE; lap_param.start_frame = -1; stateEBox->SetWindowText(_T(" PAUSE")); } } void CFilePlayerDLG::OnButtonStop() { control = NI_FILE_PLAYER_STOP; pause = FALSE; playing = FALSE; lap_param.start_frame = 0; stateEBox->SetWindowText(_T(" STOP")); //tmscaleSldr->EnableWindow(TRUE); //tmscaleEBox->EnableWindow(TRUE); playButton->EnableWindow(TRUE); stopButton->EnableWindow(FALSE); pauseButton->EnableWindow(FALSE); } void CFilePlayerDLG::OnClose() { terminate(); CDialog::OnClose(); } void CFilePlayerDLG::OnButtonExit() { terminate(); CDialog::OnOK(); } void CFilePlayerDLG::OnCheckQuat() { if (calcButton->GetCheck()) lap_param.calc_quat = TRUE; else lap_param.calc_quat = FALSE; } void CFilePlayerDLG::OnCheckLoop() { if (reptButton->GetCheck()) lap_param.repeat = TRUE; else lap_param.repeat = FALSE; } void CFilePlayerDLG::OnCheckMirror() { if (mirrButton->GetCheck()) lap_param.mirroring = TRUE; else lap_param.mirroring = FALSE; } void CFilePlayerDLG::OnCheckCmUnit() { if (cmButton->GetCheck()) lap_param.cm_unit = TRUE; else lap_param.cm_unit = FALSE; } void CFilePlayerDLG::OnCheckInitpos() { if (posButton->GetCheck()) lap_param.init_pos = TRUE; else lap_param.init_pos = FALSE; } void CFilePlayerDLG::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { TCHAR buf[LNAME]; if (tmscaleSldr==(CSliderCtrl*)pScrollBar) { int pos = tmscaleSldr->GetPos(); lap_param.time_scale = (float)(power(2.0f, -pos/10.0f)); int val = - (int)lap_param.time_scale; if (val==0 && lap_param.time_scale!=0.0) { val = (int)(1.0/lap_param.time_scale); } if (val==0 || val==-1) val = 1; sntprintf(buf, LNAME, _T("%d"), val); tmscaleEBox->SetWindowText(buf); tmscaleEBox->UpdateWindow(); sntprintf(buf, LNAME, _T(" %-8.2f"), nidev->getFilePlayTime()*lap_param.time_scale); plytmEBox->SetWindowText(buf); } } void CFilePlayerDLG::OnChangeTimeScale() { TCHAR buf[LNAME]; tmscaleEBox->GetWindowText(buf, LNAME); int val = ttoi(buf); if (val>1024 || val<-1024) { if (val>1024) val = 1024; else if (val<-1024) val = -1024; sntprintf(buf, LNAME, _T("%d"), val); tmscaleEBox->SetWindowText(buf); tmscaleEBox->UpdateWindow(); } if (val==0) val = 1; if (val>0) { lap_param.time_scale = 1.0f/val; } else { lap_param.time_scale = - (float)val; } int pos = - (int)(log(lap_param.time_scale)/log(2.0)*10.0); tmscaleSldr->SetPos((int)pos); sntprintf(buf, LNAME, _T(" %-8.2f"), nidev->getFilePlayTime()*lap_param.time_scale); plytmEBox->SetWindowText(buf); }