rewrite audio for animation

This commit is contained in:
Ivan Morozov
2021-05-17 12:20:16 +03:00
parent 42170638c2
commit 757dc61ce8
10 changed files with 26 additions and 228 deletions

View File

@ -360,7 +360,6 @@ HEADERS += \
../Enums/enums.h \
../PPTFormatLib.h \
../PPTXWriter/Animation.h \
../PPTXWriter/ridmanager.h \
../Reader/ClassesAtom.h \
../Reader/CommonZLib.h \
../Reader/PPTDocumentInfo.h \
@ -652,6 +651,5 @@ SOURCES += \
../../../ASCOfficePPTXFile/Editor/Drawing/TextAttributesEx.cpp \
../../../Common/3dParty/pole/pole.cpp \
../PPTXWriter/Animation.cpp \
../PPTXWriter/ridmanager.cpp \
../Records/Animations/TimeVariant.cpp

View File

@ -406,15 +406,14 @@ void Animation::FillAudio(CRecordClientVisualElementContainer *pCVEC,
{
if (pCVEC->m_bVisualShapeAtom)
{
oAudio.cMediaNode.tgtEl.embed =
new OOX::RId(pCVEC->m_oVisualShapeAtom.m_nObjectIdRef);
std::vector<CRecordSoundContainer*> soundCont;
this->m_pSoundContainer->GetRecordsByType(
&soundCont, false);
oAudio.cMediaNode.tgtEl.name =
static_cast<CRecordCString*>
(soundCont[pCVEC->m_oVisualShapeAtom.m_nOldIdRef -1]->m_arRecords[0])->m_strText;
CExFilesInfo* pInfo1 = m_pExMedia->LockAudioFromCollection(pCVEC->m_oVisualShapeAtom.m_nObjectIdRef);
if (pInfo1 && m_pRels)
{
bool bExternal(false);
oAudio.cMediaNode.tgtEl.embed =
new OOX::RId(m_pRels->WriteAudio(pInfo1->m_strFilePath, bExternal));
oAudio.cMediaNode.tgtEl.name = pInfo1->m_name;
}
}
}

View File

@ -51,7 +51,7 @@
#include "../../../ASCOfficePPTXFile/PPTXFormat/Logic/Timing/Video.h"
#include "../Records/SlideProgTagsContainer.h"
#include "../Records/SoundCollectionContainer.h"
#include "ImageManager.h"
#include "../Records/Animations/AnimationInfoContainer.h"
namespace PPT_FORMAT
@ -86,10 +86,11 @@ struct SValue
class Animation
{
public:
Animation(CRecordPP10SlideBinaryTagExtension *pPPT10Ext, const std::vector<SOldAnimation> &oldAnim) :
Animation(CRecordPP10SlideBinaryTagExtension *pPPT10Ext, const std::vector<SOldAnimation> &oldAnim, CExMedia* pExMedia, CRelsGenerator* pRels) :
m_pPPT10(pPPT10Ext),
m_arrOldAnim(oldAnim),
m_pSoundContainer(nullptr),
m_pExMedia(pExMedia),
m_pRels(pRels),
m_cTnId(1),
m_pBldLst(nullptr),
m_currentBldP(nullptr)
@ -97,11 +98,6 @@ public:
}
// Not delete any pointers
CRecordPP10SlideBinaryTagExtension *m_pPPT10; // Must be it xor (maybe 'or' i dunno)
std::vector<SOldAnimation> m_arrOldAnim; // this one
CRecordSoundCollectionContainer *m_pSoundContainer; // Optional
// Call it and only it to convert animation
void Convert(PPTX::Logic::Timing &oTiming);
@ -236,7 +232,14 @@ private:
void PushAnimEffect(PPTX::Logic::ChildTnLst& oParent, SOldAnimation *pOldAnim, std::wstring filter, std::wstring transition = L"in");
void PushSet(PPTX::Logic::ChildTnLst& oParent, SOldAnimation *pOldAnim, int dur = 0);
public:
// Not delete any pointers
CRecordPP10SlideBinaryTagExtension *m_pPPT10; // For new animation
std::vector<SOldAnimation> m_arrOldAnim; // this one can dublicate new animation
private:
CExMedia *m_pExMedia;
CRelsGenerator *m_pRels;
unsigned m_cTnId;
PPTX::Logic::BldLst *m_pBldLst; // Do not delete
PPTX::Logic::BldP *m_currentBldP;

View File

@ -47,6 +47,7 @@
#include "StylesWriter.h"
#include "Converter.h"
#include "Animation.h"
namespace PPT_FORMAT
{
@ -1472,21 +1473,7 @@ void PPT_FORMAT::CPPTXWriter::WriteTiming(CStringWriter& oWriter, CRelsGenerator
if (!pPP10SlideBinaryTag && arrOldAnim.empty())
return;
Animation animation(pPP10SlideBinaryTag, arrOldAnim);
std::vector<CRecordSoundCollectionContainer*> sound;
m_pUserInfo->m_oDocument.GetRecordsByType(&sound, false);
if (!sound.empty())
{
animation.m_pSoundContainer = sound[0];
}
m_oManager.m_ridManager.setRIDfromAnimation(animation);
m_oManager.m_ridManager.setRID(oRels.getRId());
auto paths = m_oManager.m_ridManager.getPathesForSlideRels();
for (auto& path : paths)
{
oRels.WriteHyperlinkMedia(path, false, false, L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/audio");
}
Animation animation(pPP10SlideBinaryTag, arrOldAnim, &(m_pUserInfo->m_oExMedia), &oRels);
animation.Convert(oTiming);
oWriter.WriteString(oTiming.toXML());

View File

@ -32,7 +32,6 @@
#pragma once
#include "ImageManager.h"
#include "ridmanager.h"
class CStylesWriter;

View File

@ -34,16 +34,13 @@
#ifndef DISABLE_FILE_DOWNLOADER
#include "../../../Common/FileDownloader/FileDownloader.h"
#endif
#include "ridmanager.h"
#include <boost/algorithm/string.hpp>
#include "../../../ASCOfficePPTXFile/Editor/Drawing/Attributes.h"
namespace PPT_FORMAT
{
class CMediaManager
{
public:
RIDManager m_ridManager;
private:
std::map<std::wstring, std::wstring> m_mapMedia;
@ -151,7 +148,6 @@ namespace PPT_FORMAT
for (auto& audio : audioCont)
{
auto pathAudio = GenerateAudio(audio.m_strFilePath);
m_ridManager.addSoundPath(pathAudio);
}
}

View File

@ -1758,7 +1758,10 @@ void PPT_FORMAT::CShapeWriter::WriteButton()
}
case II_HyperlinkAction:
{
hlink.action = L"ppaction://hlinksldjump";
if (hlink.id.is_init())
hlink.action = L"ppaction://hlinksldjump";
else
hlink.action = L"ppaction://noaction";
break;
}
default:

View File

@ -1,122 +0,0 @@
#include "ridmanager.h"
#include "../Records/SoundContainer.h"
#include <map>
#include <cmath>
RIDManager::RIDManager() :
m_RID(1),
m_haveSetedSoundRIDCollection(false)
{
}
std::vector<std::wstring> RIDManager::getPathesForSlideRels()
{
std::vector<std::wstring> paths;
if (m_arrRID.empty())
return paths;
std::map<_UINT32, _UINT32*> mapRIDs; // first value is old rId : second new rId
unsigned i = 0;
for (auto* pRID : m_arrRID)
{
auto searchIter(mapRIDs.find(*pRID));
if (searchIter == mapRIDs.end())
{
mapRIDs.insert(std::make_pair(*pRID, pRID));
*pRID = m_RID++;
}
else
*pRID = *(searchIter->second);
if (i < m_soundRIDCollection.size())
*(m_soundRIDCollection[i++]) = std::to_wstring(*pRID);
}
for (auto RID : mapRIDs)
{
const unsigned soundPos = RID.first - 1;
if (soundPos < m_soundPaths.size())
paths.push_back(m_soundPaths[soundPos]);
else if (m_soundPaths.size()) //TODO
paths.push_back(m_soundPaths.back());
}
return paths;
}
void RIDManager::setRIDfromAnimation(Animation& anim)
{
clearRIDSforSlide();
setSoundRIDCollection(anim.m_pSoundContainer);
if (anim.m_pPPT10)
searchSound(anim.m_pPPT10->m_pExtTimeNodeContainer);
else if (!anim.m_arrOldAnim.empty())
searchSound(anim.m_arrOldAnim);
}
void RIDManager::setSoundRIDCollection(CRecordSoundCollectionContainer* pColection)
{
if (!pColection) return;
if (!m_haveSetedSoundRIDCollection)
{
for (auto* pRec : pColection->m_arRecords)
{
auto soundCont = dynamic_cast<CRecordSoundContainer*>(pRec);
if (soundCont)
{
auto recStr = dynamic_cast<CRecordCString*>(soundCont->m_arRecords[2]);
if (recStr)
m_soundRIDCollection.push_back(&(recStr->m_strText));
}
}
m_haveSetedSoundRIDCollection = true;
}
}
void RIDManager::addSoundPath(std::wstring& path)
{
m_soundPaths.push_back(path);
}
void RIDManager::searchSound (CRecordExtTimeNodeContainer* const pETNC)
{
if (!pETNC) return;
if (pETNC->m_haveClientVisualElement && pETNC->m_pClientVisualElement)
addSound(pETNC->m_pClientVisualElement);
for (auto* pSubEffect : pETNC->m_arrRgSubEffect)
addSound(pSubEffect->m_pClientVisualElement);
for (auto* pETNCChildren : pETNC->m_arrRgExtTimeNodeChildren)
searchSound(pETNCChildren);
}
void RIDManager::searchSound (const std::vector<SOldAnimation> &arrAnim)
{
for (auto anim : arrAnim)
{
if (anim.anim->m_AnimationAtom.m_fSound)
m_arrRID.push_back(&(anim.anim->m_AnimationAtom.m_SoundIdRef));
}
}
void RIDManager::addSound(CRecordClientVisualElementContainer* const pCVEC)
{
if (!pCVEC) return;
if (pCVEC->m_bVisualShapeAtom)
m_arrRID.push_back(&(pCVEC->m_oVisualShapeAtom.m_nObjectIdRef));
}
void RIDManager::clearRIDSforSlide()
{
m_arrRID.clear();
m_arrSoundRef.clear();
m_RID = 1;
}

View File

@ -1,60 +0,0 @@
#ifndef RIDMANAGER_H
#define RIDMANAGER_H
#include "Animation.h"
// This class is heeded for rId audio in the first.
// And later maybe will be used for video.
class RIDManager
{
public:
RIDManager();
// This methods take all rid by ref and correct it
// Look at the example
/*
It for animation
we have rIDs in ppt ETNC | we need (add some constants(1) and rewrite array)
1 slide 1 2 3 2 4 1 1 1 slide 2 3 4 3 5 2 2
2 slide 3 3 5 6 6 2 slide 2 2 3 4 4
3 slide 7 3 slide 2
we have soundCollection. It's an array [1,2,3,4,5,6,7] with rIDs inside
|
we need new arrays with [1 2 3 4], [3 5 6], [7]. It for _rels
and write in _rels (rId : assciate with audio №)
1 rels 2:1 3:2 4:3 5:4
2 rels 2:3 3:5 4:6
3 rels 2:7
*/
// It sets in first
void addSoundPath(std::wstring& path);
void setRIDfromTransitions(int &soundRID);
void setRIDfromAnimation(Animation& anim);
void setRID(int RID) // It's num was added to output //// add some constants(1)
{m_RID = RID;}
std::vector<std::wstring> getPathesForSlideRels(); // Correct RIDs and get paths for rels in current slide
private:
// It set once
void setSoundRIDCollection(CRecordSoundCollectionContainer* pColection);
void searchSound (CRecordExtTimeNodeContainer* const pETNC);
void searchSound (const std::vector<SOldAnimation> &arrAnim);
void addSound(CRecordClientVisualElementContainer* const pCVEC);
void clearRIDSforSlide();
private:
// for input --> rewrite --> output
std::vector<_UINT32*> m_arrRID; // It's for one slide animation
std::vector<_UINT32*> m_arrSoundRef; // It's for one slide _rels
int m_RID;
bool m_haveSetedSoundRIDCollection;
std::vector<std::wstring*> m_soundRIDCollection; // It sets once
std::vector<std::wstring > m_soundPaths; // It sets once
};
#endif // RIDMANAGER_H

View File

@ -52,18 +52,13 @@ public:
m_nObjectIdRef = StreamUtils::ReadDWORD ( pStream );
m_nData1 = StreamUtils::ReadDWORD ( pStream );
m_nData2 = StreamUtils::ReadDWORD ( pStream );
m_nOldIdRef = m_nObjectIdRef;
}
public:
TimeVisualElementEnum m_Type;
ElementTypeEnum m_RefType;
// Warning! It used by RIDManager to change
_UINT32 m_nObjectIdRef; // ShapeIdRef || SoundIdRef
// This is it's copy
_UINT32 m_nOldIdRef;
_UINT32 m_nData1;
_UINT32 m_nData2;
};