当前位置: 首页>>代码示例>>C++>>正文


C++ FileReader::ReadConvertEndianness方法代码示例

本文整理汇总了C++中FileReader::ReadConvertEndianness方法的典型用法代码示例。如果您正苦于以下问题:C++ FileReader::ReadConvertEndianness方法的具体用法?C++ FileReader::ReadConvertEndianness怎么用?C++ FileReader::ReadConvertEndianness使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileReader的用法示例。


在下文中一共展示了FileReader::ReadConvertEndianness方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ReadDIGI

bool CSoundFile::ReadDIGI(FileReader &file, ModLoadingFlags loadFlags)
//--------------------------------------------------------------------
{
    file.Rewind();

    DIGIFileHeader fileHeader;
    if(!file.ReadConvertEndianness(fileHeader)
        || memcmp(fileHeader.signature, "DIGI Booster module\0", 20)
        || !fileHeader.numChannels
        || fileHeader.numChannels > 8
        || fileHeader.lastOrdIndex > 127)
    {
        return false;
    } else if(loadFlags == onlyVerifyHeader)
    {
        return true;
    }

    // Globals
    InitializeGlobals();
    InitializeChannels();

    m_nType = MOD_TYPE_DIGI;
    m_nChannels = fileHeader.numChannels;
    m_nSamples = 31;
    m_nSamplePreAmp = 256 / m_nChannels;
    madeWithTracker = mpt::String::Print("Digi Booster %1.%2", fileHeader.versionInt >> 4, fileHeader.versionInt & 0x0F);

    Order.ReadFromArray(fileHeader.orders, fileHeader.lastOrdIndex + 1);

    // Read sample headers
    for(SAMPLEINDEX smp = 0; smp < 31; smp++)
    {
        ModSample &sample = Samples[smp + 1];
        sample.Initialize(MOD_TYPE_MOD);
        sample.nLength = fileHeader.smpLength[smp];
        sample.nLoopStart = fileHeader.smpLoopStart[smp];
        sample.nLoopEnd = sample.nLoopStart + fileHeader.smpLoopLength[smp];
        if(fileHeader.smpLoopLength[smp])
        {
            sample.uFlags.set(CHN_LOOP);
        }
        sample.SanitizeLoops();
    
        sample.nVolume = std::min(fileHeader.smpVolume[smp], uint8(64)) * 4;
        sample.nFineTune = MOD2XMFineTune(fileHeader.smpFinetune[smp]);
    }

    // Read song + sample names
    file.ReadString<mpt::String::maybeNullTerminated>(songName, 32);
    for(SAMPLEINDEX smp = 1; smp <= 31; smp++)
    {
        file.ReadString<mpt::String::maybeNullTerminated>(m_szNames[smp], 30);
    }

    for(PATTERNINDEX pat = 0; pat <= fileHeader.lastPatIndex; pat++)
    {
        FileReader patternChunk;
        if(fileHeader.packEnable)
        {
            patternChunk = file.ReadChunk(file.ReadUint16BE());
        } else
        {
            patternChunk = file.ReadChunk(4 * 64 * GetNumChannels());
        }

        if(!(loadFlags & loadPatternData) || Patterns.Insert(pat, 64))
        {
            continue;
        }

        if(fileHeader.packEnable)
        {
            std::vector<uint8> eventMask;
            patternChunk.ReadVector(eventMask, 64);

            // Compressed patterns are stored in row-major order...
            for(ROWINDEX row = 0; row < 64; row++)
            {
                PatternRow patRow = Patterns[pat].GetRow(row);
                uint8 bit = 0x80;
                for(CHANNELINDEX chn = 0; chn < GetNumChannels(); chn++, bit >>= 1)
                {
                    if(eventMask[row] & bit)
                    {
                        ModCommand &m = patRow[chn];
                        ReadDIGIPatternEntry(patternChunk, m, *this);
                    }
                }
            }
        } else
        {
            // ...but uncompressed patterns are stored in column-major order. WTF!
            for(CHANNELINDEX chn = 0; chn < GetNumChannels(); chn++)
开发者ID:fgenesis,项目名称:tyrsound,代码行数:94,代码来源:Load_digi.cpp

示例2: 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;
}
开发者ID:ksnydertn,项目名称:modplug,代码行数:91,代码来源:VstPresets.cpp

示例3: ReadITQ

bool CSoundFile::ReadITQ(FileReader &file, ModLoadingFlags loadFlags)
//------------------------------------------------------------------
{
    file.Rewind();

    ITFileHeader fileHeader;
    if(!file.ReadConvertEndianness(fileHeader)
        || (memcmp(fileHeader.id, "ITQM", 4))
        || fileHeader.insnum > 0xFF
        || fileHeader.smpnum >= MAX_SAMPLES
        || !file.CanRead(fileHeader.ordnum + (fileHeader.insnum + fileHeader.smpnum + fileHeader.patnum) * 4))
    {
        return false;
    } else if(loadFlags == onlyVerifyHeader)
    {
        return true;
    }

    InitializeGlobals();

    bool interpretModPlugMade = false;

    // OpenMPT crap at the end of file
    file.Seek(file.GetLength() - 4);
    size_t mptStartPos = file.ReadUint32LE();
    if(mptStartPos >= file.GetLength() || mptStartPos < 0x100)
    {
        mptStartPos = file.GetLength();
    }

    if(!memcmp(fileHeader.id, "tpm.", 4))
    {
        // Legacy MPTM files (old 1.17.02.xx releases)
        ChangeModTypeTo(MOD_TYPE_MPT);
    } else
    {
        if(mptStartPos <= file.GetLength() - 3 && fileHeader.cwtv > 0x888 && fileHeader.cwtv <= 0xFFF)
        {
            file.Seek(mptStartPos);
            ChangeModTypeTo(file.ReadMagic("228") ? MOD_TYPE_MPT : MOD_TYPE_IT);
        } else
        {
            ChangeModTypeTo(MOD_TYPE_IT);
        }

        if(GetType() == MOD_TYPE_IT)
        {
            // Which tracker was used to made this?
            if((fileHeader.cwtv & 0xF000) == 0x5000)
            {
                // OpenMPT Version number (Major.Minor)
                // This will only be interpreted as "made with ModPlug" (i.e. disable compatible playback etc) if the "reserved" field is set to "OMPT" - else, compatibility was used.
                m_dwLastSavedWithVersion = (fileHeader.cwtv & 0x0FFF) << 16;
                if(!memcmp(fileHeader.reserved, "OMPT", 4))
                    interpretModPlugMade = true;
            } else if(fileHeader.cmwt == 0x888 || fileHeader.cwtv == 0x888)
            {
                // OpenMPT 1.17 and 1.18 (raped IT format)
                // Exact version number will be determined later.
                interpretModPlugMade = true;
            } else if(fileHeader.cwtv == 0x0217 && fileHeader.cmwt == 0x0200 && !memcmp(fileHeader.reserved, "\0\0\0\0", 4))
            {
                if(memchr(fileHeader.chnpan, 0xFF, sizeof(fileHeader.chnpan)) != NULL)
                {
                    // ModPlug Tracker 1.16 (semi-raped IT format)
                    m_dwLastSavedWithVersion = MAKE_VERSION_NUMERIC(1, 16, 00, 00);
                    madeWithTracker = "ModPlug tracker 1.09 - 1.16";
                } else
                {
                    // OpenMPT 1.17 disguised as this in compatible mode,
                    // but never writes 0xFF in the pan map for unused channels (which is an invalid value).
                    m_dwLastSavedWithVersion = MAKE_VERSION_NUMERIC(1, 17, 00, 00);
                    madeWithTracker = "OpenMPT 1.17 (compatibility export)";
                }
                interpretModPlugMade = true;
            } else if(fileHeader.cwtv == 0x0214 && fileHeader.cmwt == 0x0202 && !memcmp(fileHeader.reserved, "\0\0\0\0", 4))
            {
                // ModPlug Tracker b3.3 - 1.09, instruments 557 bytes apart
                m_dwLastSavedWithVersion = MAKE_VERSION_NUMERIC(1, 09, 00, 00);
                madeWithTracker = "ModPlug tracker b3.3 - 1.09";
                interpretModPlugMade = true;
            }
        } else // case: type == MOD_TYPE_MPT
        {
            if (fileHeader.cwtv >= verMptFileVerLoadLimit)
            {
                AddToLog(str_LoadingIncompatibleVersion);
                return false;
            }
            else if (fileHeader.cwtv > verMptFileVer)
            {
                AddToLog(str_LoadingMoreRecentVersion);
            }
        }
    }

    if(GetType() == MOD_TYPE_IT) mptStartPos = file.GetLength();

    // Read row highlights
    if((fileHeader.special & ITFileHeader::embedPatternHighlights))
//.........这里部分代码省略.........
开发者ID:MrEricSir,项目名称:Modipulate,代码行数:101,代码来源:Load_itq.cpp


注:本文中的FileReader::ReadConvertEndianness方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。