本文整理汇总了C++中FileReader::GetPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ FileReader::GetPosition方法的具体用法?C++ FileReader::GetPosition怎么用?C++ FileReader::GetPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileReader
的用法示例。
在下文中一共展示了FileReader::GetPosition方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadFile
VSTPresets::ErrorCode VSTPresets::LoadFile(FileReader &file, CVstPlugin &plugin)
//------------------------------------------------------------------------------
{
const bool firstChunk = file.GetPosition() == 0;
ChunkHeader header;
if(!file.ReadConvertEndianness(header) || header.chunkMagic != cMagic)
{
return invalidFile;
}
if(header.fxID != plugin.GetUID())
{
return wrongPlugin;
}
if(header.fxMagic == fMagic || header.fxMagic == chunkPresetMagic)
{
// Program
PlugParamIndex numParams = file.ReadUint32BE();
VstPatchChunkInfo info;
info.version = 1;
info.pluginUniqueID = header.fxID;
info.pluginVersion = header.fxVersion;
info.numElements = numParams;
MemsetZero(info.future);
plugin.Dispatch(effBeginLoadProgram, 0, 0, &info, 0.0f);
plugin.Dispatch(effBeginSetProgram, 0, 0, nullptr, 0.0f);
char prgName[28];
file.ReadString<mpt::String::maybeNullTerminated>(prgName, 28);
plugin.Dispatch(effSetProgramName, 0, 0, prgName, 0.0f);
if(header.fxMagic == fMagic)
{
if(plugin.GetNumParameters() != numParams)
{
return wrongParameters;
}
for(PlugParamIndex p = 0; p < numParams; p++)
{
plugin.SetParameter(p, file.ReadFloatBE());
}
} else
{
FileReader chunk = file.ReadChunk(file.ReadUint32BE());
plugin.Dispatch(effSetChunk, 1, chunk.GetLength(), const_cast<char *>(chunk.GetRawData()), 0);
}
plugin.Dispatch(effEndSetProgram, 0, 0, nullptr, 0.0f);
} else if((header.fxMagic == bankMagic || header.fxMagic == chunkBankMagic) && firstChunk)
{
// Bank - only read if it's the first chunk in the file, not if it's a sub chunk.
uint32 numProgs = file.ReadUint32BE();
uint32 currentProgram = file.ReadUint32BE();
file.Skip(124);
VstPatchChunkInfo info;
info.version = 1;
info.pluginUniqueID = header.fxID;
info.pluginVersion = header.fxVersion;
info.numElements = numProgs;
MemsetZero(info.future);
plugin.Dispatch(effBeginLoadBank, 0, 0, &info, 0.0f);
if(header.fxMagic == bankMagic)
{
VstInt32 oldCurrentProgram = plugin.GetCurrentProgram();
for(uint32 p = 0; p < numProgs; p++)
{
plugin.Dispatch(effBeginSetProgram, 0, 0, nullptr, 0.0f);
plugin.Dispatch(effSetProgram, 0, 0, nullptr, 0.0f);
ErrorCode retVal = LoadFile(file, plugin);
if(retVal != noError)
{
return retVal;
}
plugin.Dispatch(effEndSetProgram, 0, 0, nullptr, 0.0f);
}
plugin.SetCurrentProgram(oldCurrentProgram);
} else
{
FileReader chunk = file.ReadChunk(file.ReadUint32BE());
plugin.Dispatch(effSetChunk, 0, chunk.GetLength(), const_cast<char *>(chunk.GetRawData()), 0);
}
if(header.version >= 2)
{
plugin.SetCurrentProgram(currentProgram);
}
}
return noError;
}
示例2: ReadSample
OPENMPT_NAMESPACE_BEGIN
#if MPT_COMPILER_GCC
#if MPT_GCC_AT_LEAST(4,6,0)
#pragma GCC diagnostic push
#endif
#pragma GCC diagnostic ignored "-Wswitch"
#elif MPT_COMPILER_CLANG
#pragma clang diagnostic push
#if MPT_CLANG_AT_LEAST(3,3,0)
#pragma clang diagnostic ignored "-Wswitch"
#else
#pragma clang diagnostic ignored "-Wswitch-enum"
#endif
#endif
// Read a sample from memory
size_t SampleIO::ReadSample(ModSample &sample, FileReader &file) const
//--------------------------------------------------------------------
{
if(sample.nLength < 1 || !file.IsValid())
{
return 0;
}
LimitMax(sample.nLength, MAX_SAMPLE_LENGTH);
const char * const sourceBuf = file.GetRawData();
const FileReader::off_t fileSize = file.BytesLeft(), filePosition = file.GetPosition();
FileReader::off_t bytesRead = 0; // Amount of memory that has been read from file
sample.uFlags.set(CHN_16BIT, GetBitDepth() >= 16);
sample.uFlags.set(CHN_STEREO, GetChannelFormat() != mono);
size_t sampleSize = sample.AllocateSample(); // Target sample size in bytes
if(sampleSize == 0)
{
sample.nLength = 0;
return 0;
}
ASSERT(sampleSize >= sample.GetSampleSizeInBytes());
//////////////////////////////////////////////////////
// 8-Bit / Mono / PCM
if(GetBitDepth() == 8 && GetChannelFormat() == mono)
{
switch(GetEncoding())
{
case signedPCM: // 8-Bit / Mono / Signed / PCM
bytesRead = CopyMonoSample<SC::DecodeInt8>(sample, sourceBuf, fileSize);
break;
case unsignedPCM: // 8-Bit / Mono / Unsigned / PCM
bytesRead = CopyMonoSample<SC::DecodeUint8>(sample, sourceBuf, fileSize);
break;
case deltaPCM: // 8-Bit / Mono / Delta / PCM
case MT2:
bytesRead = CopyMonoSample<SC::DecodeInt8Delta>(sample, sourceBuf, fileSize);
break;
case PCM7to8: // 7 Bit stored as 8-Bit with highest bit unused / Mono / Signed / PCM
bytesRead = CopyMonoSample<SC::DecodeInt7>(sample, sourceBuf, fileSize);
break;
}
}
//////////////////////////////////////////////////////
// 8-Bit / Stereo Split / PCM
else if(GetBitDepth() == 8 && GetChannelFormat() == stereoSplit)
{
switch(GetEncoding())
{
case signedPCM: // 8-Bit / Stereo Split / Signed / PCM
bytesRead = CopyStereoSplitSample<SC::DecodeInt8>(sample, sourceBuf, fileSize);
break;
case unsignedPCM: // 8-Bit / Stereo Split / Unsigned / PCM
bytesRead = CopyStereoSplitSample<SC::DecodeUint8>(sample, sourceBuf, fileSize);
break;
case deltaPCM: // 8-Bit / Stereo Split / Delta / PCM
case MT2:
bytesRead = CopyStereoSplitSample<SC::DecodeInt8Delta>(sample, sourceBuf, fileSize);
break;
}
}
//////////////////////////////////////////////////////
// 8-Bit / Stereo Interleaved / PCM
else if(GetBitDepth() == 8 && GetChannelFormat() == stereoInterleaved)
{
switch(GetEncoding())
{
case signedPCM: // 8-Bit / Stereo Interleaved / Signed / PCM
bytesRead = CopyStereoInterleavedSample<SC::DecodeInt8>(sample, sourceBuf, fileSize);
break;
case unsignedPCM: // 8-Bit / Stereo Interleaved / Unsigned / PCM
bytesRead = CopyStereoInterleavedSample<SC::DecodeUint8>(sample, sourceBuf, fileSize);
break;
case deltaPCM: // 8-Bit / Stereo Interleaved / Delta / PCM
bytesRead = CopyStereoInterleavedSample<SC::DecodeInt8Delta>(sample, sourceBuf, fileSize);
break;
//.........这里部分代码省略.........
示例3: ReadITQ
//.........这里部分代码省略.........
}
for(uint16 n = 0; n < fileHeader.smpnum; n++)
{
if(smpPos[n] > 0)
{
minPtr = std::min(minPtr, smpPos[n]);
}
}
for(uint16 n = 0; n < fileHeader.patnum; n++)
{
if(patPos[n] > 0)
{
minPtr = std::min(minPtr, patPos[n]);
}
}
if(fileHeader.special & ITFileHeader::embedSongMessage)
{
minPtr = std::min(minPtr, fileHeader.msgoffset);
}
// Reading IT Edit History Info
// This is only supposed to be present if bit 1 of the special flags is set.
// However, old versions of Schism and probably other trackers always set this bit
// even if they don't write the edit history count. So we have to filter this out...
// This is done by looking at the parapointers. If the history data end after
// the first parapointer, we assume that it's actually no history data.
if(fileHeader.special & ITFileHeader::embedEditHistory)
{
const uint16 nflt = file.ReadUint16LE();
if(file.CanRead(nflt * sizeof(ITHistoryStruct)) && file.GetPosition() + nflt * sizeof(ITHistoryStruct) <= minPtr)
{
m_FileHistory.reserve(nflt);
for(size_t n = 0; n < nflt; n++)
{
FileHistory mptHistory;
ITHistoryStruct itHistory;
file.ReadConvertEndianness(itHistory);
itHistory.ConvertToMPT(mptHistory);
m_FileHistory.push_back(mptHistory);
}
} else
{
// Oops, we were not supposed to read this.
file.SkipBack(2);
}
} else if(fileHeader.highlight_major == 0 && fileHeader.highlight_minor == 0 && fileHeader.cmwt == 0x0214 && fileHeader.cwtv == 0x0214 && !memcmp(fileHeader.reserved, "\0\0\0\0", 4) && (fileHeader.special & (ITFileHeader::embedEditHistory | ITFileHeader::embedPatternHighlights)) == 0)
{
// Another non-conforming application is unmo3 < v2.4.0.1, which doesn't set the special bit
// at all, but still writes the two edit history length bytes (zeroes)...
if(file.ReadUint16LE() != 0)
{
// These were not zero bytes -> We're in the wrong place!
file.SkipBack(2);
madeWithTracker = "UNMO3";
}
}
// Reading MIDI Output & Macros
if(m_SongFlags[SONG_EMBEDMIDICFG] && file.Read(m_MidiCfg))
{
m_MidiCfg.Sanitize();
}