diff --git a/ECTrainer2/DShowMovie.cpp b/ECTrainer2/DShowMovie.cpp index abf7e34..b3ada17 100644 --- a/ECTrainer2/DShowMovie.cpp +++ b/ECTrainer2/DShowMovie.cpp @@ -75,7 +75,7 @@ // ����Đ� bool DShowMovie::PlayMovie(std::wstring movie) { - if (this->IsPlaying()) this->StopMovie(); + this->StopMovie(); // �t�B���^�O���t�}�l�[�W���̍쐬 CHECK(CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void**)&_pGB)); @@ -125,16 +125,14 @@ CHECK(_pGB->QueryInterface(IID_IMediaPosition, (void**)&_pMediaPosition)); ShowWindow(_hWnd, SW_SHOWNORMAL); - _pMediaCont->Run(); + CHECK(_pMediaCont->Run()); return true; } // �����~ bool DShowMovie::StopMovie() { - if (!IsPlaying()) return false; - - _pMediaCont->Stop(); + if (_pMediaCont) _pMediaCont->Stop(); SAFE_RELEASE(_pMediaPosition); SAFE_RELEASE(_pMediaEvent); SAFE_RELEASE(_pMediaCont); @@ -142,8 +140,7 @@ SAFE_RELEASE(_pSource); SAFE_RELEASE(_pVMR9); SAFE_RELEASE(_pGB); - ShowWindow(_hWnd, SW_HIDE); - + if (_hWnd) ShowWindow(_hWnd, SW_HIDE); return true; } diff --git a/ECTrainer2/ECTrainer.cpp b/ECTrainer2/ECTrainer.cpp index 0b9a46f..2bcd88e 100644 --- a/ECTrainer2/ECTrainer.cpp +++ b/ECTrainer2/ECTrainer.cpp @@ -27,7 +27,7 @@ _pProcs[(int)PROC::REST] = new TobiiREST(this); _pProcs[(int)PROC::BITAL] = new BitalMonitor(this); _pProcs[(int)PROC::WORKER] = new Worker(this); - _MovieToShow = _T(""); + //_MovieToShow = _T(""); } // �f�X�g���N�^ @@ -69,9 +69,9 @@ ::MessageBox(PECTrainerGUI()->GetMainHWnd(), msg, _T("Eye Communication Trainer"), MB_OK | icon); } - -// ���ʃX���b�h�J�n�_ -DWORD WINAPI ECTrainer::ThreadEntry(LPVOID lpParameter) { - ((BaseProcess*)lpParameter)->MainLoop(); - return 0; -} +// +//// ���ʃX���b�h�J�n�_ +//DWORD WINAPI ECTrainer::ThreadEntry(LPVOID lpParameter) { +// ((BaseProcess*)lpParameter)->MainLoop(); +// return 0; +//} diff --git a/ECTrainer2/ECTrainer.h b/ECTrainer2/ECTrainer.h index 663cc86..7047e0d 100644 --- a/ECTrainer2/ECTrainer.h +++ b/ECTrainer2/ECTrainer.h @@ -32,6 +32,10 @@ STIM_STOP, // ������~ STIM_END, // �����I�� STIM_NEXT, // ���̎h���Ɉړ� + MOVIE_START, // ����Đ��J�n + MOVIE_STOP, // ����Đ���~ + MOVIE_END, // ����Đ��I�� + MOVIE_ERROR, // ����G���[ }; // �A�v���P�[�V������� @@ -47,10 +51,10 @@ BaseProcess* _pProcs[(int)PROC::NUM]; Marker* _pMarker; HINSTANCE _hInstance; - std::wstring _MovieToShow; // �Đ����铮��t�@�C�� + //std::wstring _MovieToShow; // �Đ����铮��t�@�C�� // �X���b�h�J�n�_ - static DWORD WINAPI ThreadEntry(LPVOID lpParameter); + //static DWORD WINAPI ThreadEntry(LPVOID lpParameter); public: static const int RINGBUFSIZE = 4; @@ -71,14 +75,12 @@ bool Process(); // �C���X�^���X�n���h���擾 HINSTANCE GetInstance() { return _hInstance; } - // �A�v���P�[�V�������s�����ǂ��� - //bool IsAppRun() { return _AppRunning; } // �A�v���P�[�V�������~ void StopApp(); // ���b�Z�[�W�{�b�N�X�\�� void MsgBox(LPCWSTR msg, UINT icon = 0); //�p�~�\�� - void SetMovieToShow(std::wstring file) { _MovieToShow = file; } - std::wstring GetMovieToShow() { return _MovieToShow; } + //void SetMovieToShow(std::wstring file) { _MovieToShow = file; } + //std::wstring GetMovieToShow() { return _MovieToShow; } }; diff --git a/ECTrainer2/ECTrainerGUI.cpp b/ECTrainer2/ECTrainerGUI.cpp index 3964ee3..c155c42 100644 --- a/ECTrainer2/ECTrainerGUI.cpp +++ b/ECTrainer2/ECTrainerGUI.cpp @@ -7,6 +7,7 @@ #include "ImageProc.h" #include "BitalMonitor.h" #include "TobiiREST.h" +#include "Stimulus.h" #include "Marker.h" #include "myWinUtils.h" #include "myOpenCVutil.h" @@ -130,15 +131,17 @@ cvui::image(_MainFrame, DISP_IMAGE_POS.x, DISP_IMAGE_POS.y, disp); // �h������ - std::wstring movieToShow = _pEct->GetMovieToShow(); - if (movieToShow.size() > 0) { - _pEct->SetMovieToShow(L""); - if (movieToShow == L"STOP") { - if (!_dsm->StopMovie()) _pEct->StopApp(); + if (_pEct->PStimulus()->IsNewMovie()) { + std::wstring movie = _pEct->PStimulus()->GetMovie(); + if (movie.size() < 1 || movie == L"STOP") { + _dsm->StopMovie(); + ((BaseProcess*)_pEct->PWorker())->Tell(ECTMSG::MOVIE_STOP); } else { - if (!_dsm->PlayMovie(movieToShow)) { - mwut::DebugPrintf(_T("Can't play movie: %s\n"), movieToShow.c_str()); - _pEct->StopApp(); + if (_dsm->PlayMovie(movie)) { + ((BaseProcess*)_pEct->PWorker())->Tell(ECTMSG::MOVIE_START); + } else { + _dsm->StopMovie(); + ((BaseProcess*)_pEct->PWorker())->Tell(ECTMSG::MOVIE_ERROR); } } } diff --git a/ECTrainer2/Stimulus.cpp b/ECTrainer2/Stimulus.cpp index e7e4d21..2901571 100644 --- a/ECTrainer2/Stimulus.cpp +++ b/ECTrainer2/Stimulus.cpp @@ -14,8 +14,10 @@ , _StimNo(-1) , _StartTime(0) , _pMovieObject(NULL) + , _Movie(ECTrainer::RINGBUFSIZE) { _pMovieObject = new MovieObject; + _Movie.Put(L"STOP"); } Stimulus::~Stimulus() { @@ -53,7 +55,7 @@ DWORD current = GetTickCount(); if ((float)(current - _StartTime) / 1000.F > _StimInfoSet[_StimNo].dulation) { if (_StimInfoSet[_StimNo].type == 2) { - _pEct->SetMovieToShow(L"STOP"); + _Movie.Put(L"STOP"); } if (++_StimNo < _StimInfoSet.size()) { SetStimulus(); @@ -114,67 +116,27 @@ } _pEct->PECTrainerGUI()->SetDispBuffer(_DispBuffer); } else { - std::wstring mov = mwut::Multi2Wide(_StimInfoSet[_StimNo].filename); - _pEct->SetMovieToShow(mov); + _Movie.Put(mwut::Multi2Wide(_StimInfoSet[_StimNo].filename)); } if (_StimInfoSet[_StimNo].csvfile[0] != '_') { - this->ReadCsv(); + this->LoadMovieObject(); } return true; } -// �Œ�y�[�W�\�� -//void Stimulus::SetPage(STIM_PAGE st) { - //switch (st) { - //case STIM_PAGE::OPENING: - // _DispBuffer = cv::imread(OPENING_FILE); - // _pEct->PECTrainerGUI()->SetDispBuffer(_DispBuffer); - // break; - //case STIM_PAGE::CALIB: - // _DispBuffer = cv::imread(CALIB_FILE); - // _pEct->PECTrainerGUI()->SetDispBuffer(_DispBuffer); - // break; - //case STIM_PAGE::CALIB_COMPLETE: - // _DispBuffer = cv::imread(CALIB_COMPLETE_FILE); - // _pEct->PECTrainerGUI()->SetDispBuffer(_DispBuffer); - // break; - //case STIM_PAGE::CALIB_FAILED: - // _DispBuffer = cv::imread(CALIB_FAILED_FILE); - // _pEct->PECTrainerGUI()->SetDispBuffer(_DispBuffer); - // break; - //case STIM_PAGE::WHITE: - // _DispBuffer = cv::imread(WHITE_FILE); - // _pEct->PECTrainerGUI()->SetDispBuffer(_DispBuffer); - // break; - //case STIM_PAGE::START: - // _StimNo = 0; - // SetStimulus(); - // break; - //case STIM_PAGE::STOP: - // _StimNo = -1; - // _DispBuffer = cv::imread(OPENING_FILE); - // _pEct->PECTrainerGUI()->SetDispBuffer(_DispBuffer); - // break; - //case STIM_PAGE::NEXT: - // if (++_StimNo >= _StimInfoSet.size()) _StimNo = -1; - // SetStimulus(); - // break; - //} -//} +// CSV�ǂݍ��� +void Stimulus::LoadMovieObject() { + if (_pMovieObject->GetNumFrames() > 0) return; // �ǂݍ��ݍς� + int nFrames = _pMovieObject->SetData(_StimInfoSet[_StimNo].csvfile); -// �h�����Z�b�g + mwut::DebugPrintf(_T("Movie object '%s' - %d frames read.\n"), + mwut::Multi2Wide(_StimInfoSet[_StimNo].csvfile).c_str(), nFrames); +} + +// �摜�Ƀ}�[�J�[��`�� //void Stimulus::StimWithMarker() { // cv::Mat img = cv::imread(_StimImages[_StimNo].filename); // _pMarker->Generate(img.size()); // _pMarker->DrawMarker(img); // img.copyTo(_DispBuffer); //} - -// CSV�ǂݍ��� -void Stimulus::ReadCsv() { - if (_pMovieObject->GetNumFrames() > 0) return; // �ǂݍ��ݍς� - int nFrames = _pMovieObject->SetData(_StimInfoSet[_StimNo].csvfile); - - mwut::DebugPrintf(_T("CSV file '%s' - %d frames read.\n"), - mwut::Multi2Wide(_StimInfoSet[_StimNo].csvfile).c_str(), nFrames); -} diff --git a/ECTrainer2/Stimulus.h b/ECTrainer2/Stimulus.h index c2167b8..6eb8b78 100644 --- a/ECTrainer2/Stimulus.h +++ b/ECTrainer2/Stimulus.h @@ -5,6 +5,7 @@ #include #include #include "myOpenCV.h" +#include "RingBuffer.h" class BaseProcess; class Marker; @@ -34,14 +35,18 @@ MovieObject* _pMovieObject; int _StimNo; // �h���f�[�^�ԍ��@-1:��~ DWORD _StartTime; // �h���񎦊J�n���� + RingBuffer _Movie; - //void StimWithMarker(); + // �h����ݒ� bool SetStimulus(); - void ReadCsv(); + // ����I�u�W�F�N�g�� + void LoadMovieObject(); // ��{���� bool Routine(); // �C�x���g���� bool EventProc(MSG& msg); + // �摜�Ƀ}�[�J�[��`�� + //void StimWithMarker(); public: // �R���X�g���N�^ @@ -50,5 +55,8 @@ ~Stimulus(); // ������ bool Init(); - //void SetPage(STIM_PAGE st); + // �������Ԃ� + std::wstring GetMovie() { return _Movie.Get(); } + // ������̍X�V��� + bool IsNewMovie() { return _Movie.IsNew(); } }; diff --git a/ECTrainer2/Worker.cpp b/ECTrainer2/Worker.cpp index 3c3098f..55d953f 100644 --- a/ECTrainer2/Worker.cpp +++ b/ECTrainer2/Worker.cpp @@ -62,28 +62,28 @@ _AppStatus = APP_STATUS::CALIB; ((BaseProcess*)_pEct->PStimulus())->Tell(ECTMSG::CALIB_START); ((BaseProcess*)_pEct->PTobiiREST())->Tell(ECTMSG::CALIB_START); - this->EventLog(_T("Calibration start")); + this->EventLog(_T("�L�����u���[�V���� �J�n")); } break; case (int)ECTMSG::CALIB_OK: // �L�����u���[�V�������� _AppStatus = APP_STATUS::IDLE; ((BaseProcess*)_pEct->PStimulus())->Tell(ECTMSG::CALIB_OK); - this->EventLog(_T("Calibration complete")); + this->EventLog(_T("�L�����u���[�V���� ����")); break; case (int)ECTMSG::CALIB_FAILED: // �L�����u���[�V�������s case (int)ECTMSG::CALIB_ERR: // �L�����u���[�V�����G���[ _AppStatus = APP_STATUS::IDLE; ((BaseProcess*)_pEct->PStimulus())->Tell(ECTMSG::CALIB_FAILED); - this->EventLog(_T("Calibration failed")); + this->EventLog(_T("�L�����u���[�V���� ���s")); break; case (int)ECTMSG::STIM_START: // �����J�n if (_AppStatus == APP_STATUS::IDLE) { _AppStatus = APP_STATUS::STIM; ((BaseProcess*)_pEct->PStimulus())->Tell(ECTMSG::STIM_START); - this->EventLog(_T("Stimulation start")); + this->EventLog(_T("���� �J�n")); } break; @@ -91,7 +91,7 @@ if (_AppStatus == APP_STATUS::STIM) { _AppStatus = APP_STATUS::IDLE; ((BaseProcess*)_pEct->PStimulus())->Tell(ECTMSG::STIM_STOP); - this->EventLog(_T("Stimulation stop")); + this->EventLog(_T("���� ��~")); } break; @@ -99,12 +99,28 @@ if (_AppStatus == APP_STATUS::STIM) { _AppStatus = APP_STATUS::IDLE; ((BaseProcess*)_pEct->PStimulus())->Tell(ECTMSG::STIM_STOP); - this->EventLog(_T("Stimulation end")); + this->EventLog(_T("���� �I��")); } break; case (int)ECTMSG::STIM_NEXT: // ���̎h���Ɉړ� - this->EventLog(_T("Stimulation move next")); + this->EventLog(_T("���̎h���Ɉړ�")); + break; + + case (int)ECTMSG::MOVIE_START: // ����Đ��J�n + this->EventLog(_T("���� �Đ��J�n")); + break; + + case (int)ECTMSG::MOVIE_STOP: // ����Đ���~ + this->EventLog(_T("���� �Đ���~")); + break; + + case (int)ECTMSG::MOVIE_END: // ����Đ��I�� + this->EventLog(_T("���� �Đ��I��")); + break; + + case (int)ECTMSG::MOVIE_ERROR: // ����G���[ + this->EventLog(_T("���� �G���[")); break; } return true;