Skip to content

Commit

Permalink
Вручную загружаемые субтитры теперь сохраняются в плейлисте.
Browse files Browse the repository at this point in the history
Добавлена проверка чтобы не было дублей при ручной загрузке внешних аудио-файлов.
  • Loading branch information
Aleksoid1978 committed Jul 15, 2024
1 parent 292926b commit c8dbdd6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
15 changes: 11 additions & 4 deletions src/apps/mplayerc/MainFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5933,7 +5933,7 @@ void CMainFrame::DropFiles(std::list<CString>& slFiles)
}
} else {
ISubStream *pSubStream = nullptr;
if (LoadSubtitle(fname, &pSubStream)) {
if (LoadSubtitle(fname, &pSubStream, false)) {
SetSubtitle(pSubStream); // the subtitle at the insert position according to LoadSubtitle()
b_SubLoaded = true;

Expand Down Expand Up @@ -6741,7 +6741,7 @@ void CMainFrame::OnFileLoadSubtitle()
} else {
for (const auto& fn : fns) {
ISubStream *pSubStream = nullptr;
if (LoadSubtitle(fn, &pSubStream)) {
if (LoadSubtitle(fn, &pSubStream, false)) {
SetSubtitle(pSubStream); // the subtitle at the insert position according to LoadSubtitle()
AddSubtitlePathsAddons(fn.GetString());
}
Expand Down Expand Up @@ -6785,7 +6785,7 @@ void CMainFrame::OnFileLoadAudio()
if (CComQIPtr<IGraphBuilderAudio> pGBA = m_pGB.p) {
HRESULT hr = pGBA->RenderAudioFile(fname);
if (SUCCEEDED(hr)) {
pli->m_auds.emplace_back(fname);
m_wndPlaylistBar.AddAudioToCurrent(fname);
AddAudioPathsAddons(fname.GetString());

CComQIPtr<IAMStreamSelect> pSS = FindSwitcherFilter();
Expand Down Expand Up @@ -16214,7 +16214,7 @@ void CMainFrame::ApplyExraRendererSettings()
}
}

bool CMainFrame::LoadSubtitle(const CExtraFileItem& subItem, ISubStream **actualStream)
bool CMainFrame::LoadSubtitle(const CExtraFileItem& subItem, ISubStream **actualStream, bool bAutoLoad)
{
CAppSettings& s = AfxGetAppSettings();

Expand All @@ -16238,6 +16238,9 @@ bool CMainFrame::LoadSubtitle(const CExtraFileItem& subItem, ISubStream **actual
*actualStream = m_pSubStreams.back();
s.fEnableSubtitles = true;
}
if (!bAutoLoad) {
m_wndPlaylistBar.AddSubtitleToCurrent(fname);
}

return true;
}
Expand Down Expand Up @@ -16287,6 +16290,10 @@ bool CMainFrame::LoadSubtitle(const CExtraFileItem& subItem, ISubStream **actual
s.fEnableSubtitles = true;
}

if (!bAutoLoad) {
m_wndPlaylistBar.AddSubtitleToCurrent(fname);
}

if (subChangeNotifyThread.joinable() && !::PathIsURLW(fname)) {
auto it = std::find_if(m_ExtSubFiles.cbegin(), m_ExtSubFiles.cend(), [&fname](filepathtime_t fpt) { return fpt.path == fname; });
if (it == m_ExtSubFiles.cend()) {
Expand Down
2 changes: 1 addition & 1 deletion src/apps/mplayerc/MainFrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ class CMainFrame : public CFrameWnd, public CDropTarget, public CDPI
void ApplyExraRendererSettings();

// subtitle streams order function
bool LoadSubtitle(const CExtraFileItem& subItem, ISubStream **actualStream = nullptr);
bool LoadSubtitle(const CExtraFileItem& subItem, ISubStream **actualStream = nullptr, bool bAutoLoad = true);

void UpdateSubtitle(bool fDisplayMessage = false, bool fApplyDefStyle = false);
void SetSubtitle(ISubStream* pSubStream, int iSubtitleSel = -1, bool fApplyDefStyle = false);
Expand Down
22 changes: 21 additions & 1 deletion src/apps/mplayerc/PlayerPlaylistBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ CString CPlaylistItem::GetLabel(int i) const
}

template<class T>
static bool FindFileInList(std::list<T>& sl, CString fn)
static bool FindFileInList(std::list<T>& sl, const CString& fn)
{
for (const auto& item : sl) {
if (CString(item).CompareNoCase(fn) == 0) {
Expand Down Expand Up @@ -937,6 +937,26 @@ void CPlayerPlaylistBar::SelectDefaultPlaylist()
TSelectTab();
}

void CPlayerPlaylistBar::AddAudioToCurrent(const CString& fn)
{
auto pli = GetCur();
if (pli) {
if (!FindFileInList(pli->m_auds, fn)) {
pli->m_auds.emplace_back(fn);
}
}
}

void CPlayerPlaylistBar::AddSubtitleToCurrent(const CString& fn)
{
auto pli = GetCur();
if (pli) {
if (!FindFileInList(pli->m_subs, fn)) {
pli->m_subs.emplace_back(fn);
}
}
}

BOOL CPlayerPlaylistBar::PreCreateWindow(CREATESTRUCT& cs)
{
if (!CSizingControlBarG::PreCreateWindow(cs)) {
Expand Down
3 changes: 3 additions & 0 deletions src/apps/mplayerc/PlayerPlaylistBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,9 @@ class CPlayerPlaylistBar : public CPlayerBar

void SelectDefaultPlaylist();

void AddAudioToCurrent(const CString& fn);
void AddSubtitleToCurrent(const CString& fn);

protected:
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
virtual BOOL PreTranslateMessage(MSG* pMsg);
Expand Down

0 comments on commit c8dbdd6

Please sign in to comment.