PlayerSubresyncBar.cpp
资源名称:bfyy.rar [点击查看]
上传用户:tangyu_668
上传日期:2014-02-27
资源大小:678k
文件大小:7k
源码类别:
多媒体编程
开发平台:
Visual C++
- /*
- * Copyright (C) 2003-2006 Gabest
- * http://www.gabest.org
- *
- * This Program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This Program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- */
- // PlayerSubresyncBar.cpp : implementation file
- //
- #include "stdafx.h"
- #include "mplayerc.h"
- #include "mainfrm.h"
- #include "PlayerSubresyncBar.h"
- // CPlayerSubresyncBar
- IMPLEMENT_DYNAMIC(CPlayerSubresyncBar, CSizingControlBarG)
- CPlayerSubresyncBar::CPlayerSubresyncBar()
- {
- m_rt = 0;
- m_fUnlink = false;
- m_lastSegment = -1;
- }
- CPlayerSubresyncBar::~CPlayerSubresyncBar()
- {
- }
- BOOL CPlayerSubresyncBar::Create(CWnd* pParentWnd, CCritSec* pSubLock)
- {
- if(!CSizingControlBarG::Create(_T("Subresync"), pParentWnd, 0))
- return FALSE;
- m_pSubLock = pSubLock;
- m_list.CreateEx(
- WS_EX_DLGMODALFRAME|WS_EX_CLIENTEDGE,
- WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_TABSTOP|LVS_REPORT/*|LVS_SHOWSELALWAYS*/|LVS_AUTOARRANGE|LVS_NOSORTHEADER,
- CRect(0,0,100,100), this, IDC_SUBRESYNCLIST);
- m_list.SetExtendedStyle(m_list.GetExtendedStyle()|LVS_EX_FULLROWSELECT|LVS_EX_DOUBLEBUFFER);
- return TRUE;
- }
- BOOL CPlayerSubresyncBar::PreCreateWindow(CREATESTRUCT& cs)
- {
- if(!CSizingControlBarG::PreCreateWindow(cs))
- return FALSE;
- return TRUE;
- }
- BOOL CPlayerSubresyncBar::PreTranslateMessage(MSG* pMsg)
- {
- if(IsWindow(pMsg->hwnd) && IsVisible() && pMsg->message >= WM_KEYFIRST && pMsg->message <= WM_KEYLAST)
- {
- if(IsShortCut(pMsg) || IsDialogMessage(pMsg))
- return TRUE;
- }
- return CSizingControlBarG::PreTranslateMessage(pMsg);
- }
- void CPlayerSubresyncBar::SetTime(__int64 rt)
- {
- m_rt = rt;
- int curSegment;
- if(!m_sts.SearchSubs((int)(rt/10000), 25, &curSegment))
- {
- curSegment = -1;
- }
- if(m_lastSegment != curSegment) m_list.Invalidate();
- m_lastSegment = curSegment;
- }
- void CPlayerSubresyncBar::SetSubtitle(ISubStream* pSubStream, double fps)
- {
- m_pSubStream = pSubStream;
- m_mode = NONE;
- m_lastSegment = -1;
- m_sts.Empty();
- ResetSubtitle();
- if(!m_pSubStream) return;
- CLSID clsid;
- m_pSubStream->GetClassID(&clsid);
- if(clsid == __uuidof(CVobSubFile))
- {
- CVobSubFile* pVSF = (CVobSubFile*)(ISubStream*)m_pSubStream;
- m_mode = VOBSUB;
- CAtlArray<CVobSubFile::SubPos>& sp = pVSF->m_langs[pVSF->m_iLang].subpos;
- for(int i = 0, j = sp.GetCount(); i < j; i++)
- {
- CString str;
- str.Format(_T("%d,%d,%d,%d"), sp[i].vobid, sp[i].cellid, sp[i].fForced, i);
- m_sts.Add(TToW(str), false, (int)sp[i].start, (int)sp[i].stop);
- }
- m_sts.CreateDefaultStyle(DEFAULT_CHARSET);
- pVSF->m_fOnlyShowForcedSubs = false;
- for(int i = 0, j = m_list.GetHeaderCtrl()->GetItemCount(); i < j; i++) m_list.DeleteColumn(0);
- m_list.InsertColumn(COL_START, _T("Time"), LVCFMT_LEFT, 80);
- m_list.InsertColumn(COL_END, _T("End"), LVCFMT_LEFT, 80);
- m_list.InsertColumn(COL_PREVSTART, _T("Preview"), LVCFMT_LEFT, 80);
- m_list.InsertColumn(COL_PREVEND, _T("End"), LVCFMT_LEFT, 80);
- m_list.InsertColumn(COL_VOBID, _T("Vob ID"), LVCFMT_CENTER, 60);
- m_list.InsertColumn(COL_CELLID, _T("Cell ID"), LVCFMT_CENTER, 60);
- m_list.InsertColumn(COL_FORCED, _T("Forced"), LVCFMT_CENTER, 60);
- }
- else if(clsid == __uuidof(CRenderedTextSubtitle))
- {
- CRenderedTextSubtitle* pRTS = (CRenderedTextSubtitle*)(ISubStream*)m_pSubStream;
- m_mode = TEXTSUB;
- m_sts.Copy(*pRTS);
- m_sts.ConvertToTimeBased(fps);
- m_sts.Sort(true); /*!!m_fUnlink*/
- #ifndef UNICODE
- if(!m_sts.IsEntryUnicode(0))
- {
- CFont* f = m_list.GetFont();
- LOGFONT lf;
- f->GetLogFont(&lf);
- lf.lfCharSet = m_sts.GetCharSet(0);
- m_font.DeleteObject();
- m_font.CreateFontIndirect(&lf);
- m_list.SetFont(&m_font);
- }
- #endif
- for(int i = 0, j = m_list.GetHeaderCtrl()->GetItemCount(); i < j; i++) m_list.DeleteColumn(0);
- m_list.InsertColumn(COL_START, _T("Time"), LVCFMT_LEFT, 90);
- m_list.InsertColumn(COL_END, _T("End"), LVCFMT_LEFT, 4);
- m_list.InsertColumn(COL_PREVSTART, _T("Preview"), LVCFMT_LEFT, 80);
- m_list.InsertColumn(COL_PREVEND, _T("End"), LVCFMT_LEFT, 4);
- m_list.InsertColumn(COL_TEXT, _T("Text"), LVCFMT_LEFT, 275);
- m_list.InsertColumn(COL_STYLE, _T("Style"), LVCFMT_LEFT, 80);
- m_list.InsertColumn(COL_FONT, _T("Font"), LVCFMT_LEFT, 60);
- m_list.InsertColumn(COL_CHARSET, _T("CharSet"), LVCFMT_CENTER, 20);
- m_list.InsertColumn(COL_UNICODE, _T("Unicode"), LVCFMT_CENTER, 40);
- m_list.InsertColumn(COL_LAYER, _T("Layer"), LVCFMT_CENTER, 50);
- m_list.InsertColumn(COL_ACTOR, _T("Actor"), LVCFMT_LEFT, 80);
- m_list.InsertColumn(COL_EFFECT, _T("Effect"), LVCFMT_LEFT, 80);
- }
- m_subtimes.SetCount(m_sts.GetCount());
- for(int i = 0, j = m_sts.GetCount(); i < j; i++)
- {
- m_subtimes[i].orgstart = m_sts[i].start;
- m_subtimes[i].orgend = m_sts[i].end;
- }
- ResetSubtitle();
- }
- void CPlayerSubresyncBar::ResetSubtitle()
- {
- m_list.DeleteAllItems();
- if(m_mode == VOBSUB || m_mode == TEXTSUB)
- {
- TCHAR buff[32];
- int prevstart = INT_MIN;
- for(int i = 0, j = m_sts.GetCount(); i < j; i++)
- {
- m_subtimes[i].newstart = m_subtimes[i].orgstart;
- m_subtimes[i].newend = m_subtimes[i].orgend;
- FormatTime(i, buff, 0, false);
- m_list.InsertItem(i, buff, COL_START);
- FormatTime(i, buff, 0, true);
- m_list.SetItemText(i, COL_END, buff);
- if(prevstart > m_subtimes[i].orgstart) m_list.SetItemData(i, TSEP);
- prevstart = m_subtimes[i].orgstart;
- SetCheck(i, false, false);
- }
- UpdatePreview();
- m_list.SetColumnWidth(COL_START, LVSCW_AUTOSIZE);
- m_list.SetColumnWidth(COL_PREVSTART, LVSCW_AUTOSIZE);
- }
- UpdateStrings();
- }
- void CPlayerSubresyncBar::SaveSubtitle()
- {
- CMainFrame* pFrame = ((CMainFrame*)AfxGetMainWnd());
- if(!pFrame) return;
- CLSID clsid;
- m_pSubStream->GetClassID(&clsid);
- if(clsid == __uuidof(CVobSubFile) && m_mode == VOBSUB)
- {
- CVobSubFile* pVSF = (CVobSubFile*)(ISubStream*)m_pSubStream;
- CAutoLock cAutoLock(m_pSubLock);
- CAtlArray<CVobSubFile::SubPos>& sp = pVSF->m_langs[pVSF->m_iLang].subpos;
- for(int i = 0, j = sp.GetCount(); i < j; i++)
- {
- sp[i].fValid = false;
- }
- for(int i = 0, j = m_sts.GetCount(); i < j; i++)
- {
- int vobid, cellid, forced, spnum, c;
- if(_stscanf(m_sts.GetStr(i), _T("%d%c%d%c%d%c%d"), &vobid, &c, &cellid, &c, &forced, &c, &spnum) != 7) continue;
- sp[spnum].start = m_sts[i].start;
- sp[spnum].stop = m_sts[i].end;
- sp[spnum].fValid = true;
- }
- }
- else if(clsid == __uuidof