From: <sag...@us...> - 2013-02-15 16:01:32
|
Revision: 1527 http://sourceforge.net/p/modplug/code/1527 Author: saga-games Date: 2013-02-15 16:01:20 +0000 (Fri, 15 Feb 2013) Log Message: ----------- [New] VST: Can now load and save FXB files. Modified Paths: -------------- trunk/OpenMPT/mptrack/AbstractVstEditor.cpp trunk/OpenMPT/mptrack/View_gen.cpp trunk/OpenMPT/mptrack/Vstplug.cpp trunk/OpenMPT/mptrack/Vstplug.h trunk/OpenMPT/mptrack/mptrack_08.vcproj trunk/OpenMPT/mptrack/mptrack_10.vcxproj trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters trunk/OpenMPT/soundlib/plugins/JBridge.cpp Added Paths: ----------- trunk/OpenMPT/mptrack/VstPresets.cpp trunk/OpenMPT/mptrack/VstPresets.h Removed Paths: ------------- trunk/OpenMPT/mptrack/fxp.cpp trunk/OpenMPT/mptrack/fxp.h Modified: trunk/OpenMPT/mptrack/AbstractVstEditor.cpp =================================================================== --- trunk/OpenMPT/mptrack/AbstractVstEditor.cpp 2013-02-14 18:33:07 UTC (rev 1526) +++ trunk/OpenMPT/mptrack/AbstractVstEditor.cpp 2013-02-15 16:01:20 UTC (rev 1527) @@ -14,7 +14,6 @@ #include "mainfrm.h" #include "sndfile.h" #include "vstplug.h" -#include "fxp.h" #include "dlg_misc.h" #include "AbstractVstEditor.h" #include "../common/StringFixer.h" @@ -105,20 +104,24 @@ if(!m_pVstPlugin) return; FileDlgResult files = CTrackApp::ShowOpenSaveFileDialog(true, "fxp", "", - "VST Program (*.fxp)|*.fxp||", + "VST Plugin Programs and Banks (*.fxp,*.fbx)|*.fxp;*.fxb|" + "VST Plugin Programs (*.fxp)|*.fxp|" + "VST Plugin Banks (*.fxb)|*.fxb|" + "All Files|*.*||", CMainFrame::GetSettings().GetWorkingDirectory(DIR_PLUGINPRESETS)); if(files.abort) return; CMainFrame::GetSettings().SetWorkingDirectory(files.workingDirectory.c_str(), DIR_PLUGINPRESETS, true); - //TODO: exception handling to distinguish errors at this level. - if (m_pVstPlugin->LoadProgram(files.first_file.c_str())) + const char *retVal = m_pVstPlugin->LoadProgram(files.first_file.c_str()); + if(retVal == nullptr) { if(m_pVstPlugin->GetModDoc() != nullptr) m_pVstPlugin->GetModDoc()->SetModified(); + UpdatePresetField(); } else { - Reporting::Error("Error loading preset. Are you sure it is for this plugin?"); + Reporting::Error(retVal, "Plugin Preset"); } } @@ -129,7 +132,8 @@ if(!m_pVstPlugin) return; FileDlgResult files = CTrackApp::ShowOpenSaveFileDialog(false, "fxp", "", - "VST Program (*.fxp)|*.fxp||", + "VST Plugin Programs (*.fxp)|*.fxp|" + "VST Plugin Banks (*.fxb)|*.fxb||", CMainFrame::GetSettings().GetWorkingDirectory(DIR_PLUGINPRESETS)); if(files.abort) return; Modified: trunk/OpenMPT/mptrack/View_gen.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_gen.cpp 2013-02-14 18:33:07 UTC (rev 1526) +++ trunk/OpenMPT/mptrack/View_gen.cpp 2013-02-15 16:01:20 UTC (rev 1527) @@ -1034,21 +1034,22 @@ } FileDlgResult files = CTrackApp::ShowOpenSaveFileDialog(true, "fxp", "", - "VST FX Program (*.fxp)|*.fxp||", + "VST Plugin Programs and Banks (*.fxp,*.fbx)|*.fxp;*.fxb|" + "VST Plugin Programs (*.fxp)|*.fxp|" + "VST Plugin Banks (*.fxb)|*.fxb|" + "All Files|*.*||", CMainFrame::GetSettings().GetDefaultDirectory(DIR_PLUGINPRESETS)); if(files.abort) return; - - //TODO: exception handling - if (!(pVstPlugin->LoadProgram(files.first_file.c_str()))) + + const char *retVal = pVstPlugin->LoadProgram(files.first_file.c_str()); + if(retVal == nullptr) { - Reporting::Error("Error loading preset. Are you sure it is for this plugin?"); + if(pSndFile->GetModSpecifications().supportsPlugins) + pModDoc->SetModified(); } else { - if(pSndFile->GetModSpecifications().supportsPlugins) - pModDoc->SetModified(); + Reporting::Error(retVal, "Plugin Preset"); } - - //end rewbs.fxpPresets } void CViewGlobals::OnSaveParam() @@ -1068,7 +1069,8 @@ return; } FileDlgResult files = CTrackApp::ShowOpenSaveFileDialog(false, "fxp", "", - "VST Program (*.fxp)|*.fxp||", + "VST Plugin Programs (*.fxp)|*.fxp|" + "VST Plugin Banks (*.fxb)|*.fxb||", CMainFrame::GetSettings().GetDefaultDirectory(DIR_PLUGINPRESETS)); if(files.abort) return; Added: trunk/OpenMPT/mptrack/VstPresets.cpp =================================================================== --- trunk/OpenMPT/mptrack/VstPresets.cpp (rev 0) +++ trunk/OpenMPT/mptrack/VstPresets.cpp 2013-02-15 16:01:20 UTC (rev 1527) @@ -0,0 +1,253 @@ +/* + * VstPresets.cpp + * -------------- + * Purpose: VST plugin preset / bank handling + * Notes : (currently none) + * Authors: OpenMPT Devs + * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. + */ + + +#include "stdafx.h" + +#ifndef NO_VST +#include "Sndfile.h" +#include "Vstplug.h" +#include <vstsdk2.4/pluginterfaces/vst2.x/vstfxstore.h> +#include "VstPresets.h" + + +// This part of the header is identical for both presets and banks. +struct ChunkHeader +{ + VstInt32 chunkMagic; ///< 'CcnK' + VstInt32 byteSize; ///< size of this chunk, excl. magic + byteSize + + VstInt32 fxMagic; ///< 'FxBk' (regular) or 'FBCh' (opaque chunk) + VstInt32 version; ///< format version (1 or 2) + VstInt32 fxID; ///< fx unique ID + VstInt32 fxVersion; ///< fx version + + // Convert all multi-byte numeric values to current platform's endianness or vice versa. + void ConvertEndianness() + { + SwapBytesBE(chunkMagic); + SwapBytesBE(byteSize); + SwapBytesBE(fxMagic); + SwapBytesBE(version); + SwapBytesBE(fxID); + SwapBytesBE(fxVersion); + } +}; + + +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.fxVersion > plugin.GetVersion()) + { + return outdatedPlugin; + } + + if(header.fxMagic == fMagic || header.fxMagic == chunkPresetMagic) + { + // Program + PlugParamIndex numParams = file.ReadUint32BE(); + char prgName[28]; + file.ReadString<StringFixer::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.GetChunk(file.ReadUint32BE()); + plugin.Dispatch(effSetChunk, 1, chunk.GetLength(), const_cast<char *>(chunk.GetRawData()), 0); + } + } 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); + + if(header.fxMagic == bankMagic) + { + VstInt32 oldCurrentProgram = plugin.GetCurrentProgram(); + for(uint32 p = 0; p < numProgs; p++) + { + plugin.SetCurrentProgram(p); + ErrorCode retVal = LoadFile(file, plugin); + if(retVal != noError) + { + return retVal; + } + } + plugin.SetCurrentProgram(oldCurrentProgram); + } else + { + FileReader chunk = file.GetChunk(file.ReadUint32BE()); + plugin.Dispatch(effSetChunk, 0, chunk.GetLength(), const_cast<char *>(chunk.GetRawData()), 0); + } + if(header.version >= 2) + { + plugin.SetCurrentProgram(currentProgram); + } + } + + return noError; +} + + +bool VSTPresets::SaveFile(const char *filename, CVstPlugin &plugin, bool bank) +//---------------------------------------------------------------------------- +{ + FILE *f = fopen(filename, "wb"); + if(f == nullptr) + { + return false; + } + + if(!bank) + { + SaveProgram(f, plugin); + } else + { + const bool writeChunk = plugin.ProgramsAreChunks(); + ChunkHeader header; + header.chunkMagic = cMagic; + header.fxMagic = writeChunk ? chunkBankMagic : bankMagic; + header.version = 2; + header.fxID = plugin.GetUID(); + header.fxVersion = plugin.GetVersion(); + + // Write unfinished header... We need to update the size once we're done writing. + fwrite(&header, sizeof(header), 1, f); + + uint32 numProgs = plugin.GetNumPrograms(), curProg = plugin.GetCurrentProgram(); + WriteBE(numProgs, f); + WriteBE(curProg, f); + char reserved[124]; + MemsetZero(reserved); + Write(reserved, f); + + if(writeChunk) + { + void *chunk = nullptr; + uint32 chunkSize = plugin.Dispatch(effGetChunk, 0, 0, &chunk, 0); + if(chunkSize && chunk) + { + WriteBE(chunkSize, f); + fwrite(chunk, chunkSize, 1, f); + } + } else + { + for(uint32 p = 0; p < numProgs; p++) + { + plugin.SetCurrentProgram(p); + SaveProgram(f, plugin); + } + plugin.SetCurrentProgram(curProg); + } + + // Now we know the correct chunk size. + off_t end = ftell(f); + header.byteSize = end - 8; + header.ConvertEndianness(); + fseek(f, 0, SEEK_SET); + fwrite(&header, sizeof(header), 1, f); + } + + fclose(f); + return true; +} + + +void VSTPresets::SaveProgram(FILE *f, CVstPlugin &plugin) +//------------------------------------------------------- +{ + const bool writeChunk = plugin.ProgramsAreChunks(); + ChunkHeader header; + header.chunkMagic = cMagic; + header.fxMagic = writeChunk ? chunkPresetMagic : fMagic; + header.version = 1; + header.fxID = plugin.GetUID(); + header.fxVersion = plugin.GetVersion(); + + // Write unfinished header... We need to update the size once we're done writing. + off_t start = ftell(f); + fwrite(&header, sizeof(header), 1, f); + + const uint32 numParams = plugin.GetNumParameters(); + WriteBE(numParams, f); + + char name[max(kVstMaxProgNameLen + 1, 256)]; + plugin.Dispatch(effGetProgramName, 0, 0, name, 0); + fwrite(name, 28, 1, f); + + if(writeChunk) + { + void *chunk = nullptr; + uint32 chunkSize = plugin.Dispatch(effGetChunk, 1, 0, &chunk, 0); + if(chunkSize && chunk) + { + WriteBE(chunkSize, f); + fwrite(chunk, chunkSize, 1, f); + } + } else + { + for(uint32 p = 0; p < numParams; p++) + { + WriteBE(plugin.GetParameter(p), f); + } + } + + // Now we know the correct chunk size. + off_t end = ftell(f); + header.byteSize = end - start - 8; + header.ConvertEndianness(); + fseek(f, start, SEEK_SET); + fwrite(&header, sizeof(header), 1, f); + fseek(f, end, SEEK_SET); +} + + +void VSTPresets::WriteBE(uint32 v, FILE *f) +//----------------------------------------- +{ + SwapBytesBE(v); + Write(v, f); +} + + +void VSTPresets::WriteBE(float v, FILE *f) +//---------------------------------------- +{ + union + { + float f; + uint32 i; + } u; + u.f = v; + WriteBE(u.i, f); +} + +#endif // NO_VST Added: trunk/OpenMPT/mptrack/VstPresets.h =================================================================== --- trunk/OpenMPT/mptrack/VstPresets.h (rev 0) +++ trunk/OpenMPT/mptrack/VstPresets.h 2013-02-15 16:01:20 UTC (rev 1527) @@ -0,0 +1,45 @@ +/* + * VstPresets.h + * ------------ + * Purpose: VST plugin preset / bank handling + * Notes : (currently none) + * Authors: OpenMPT Devs + * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. + */ + + +#pragma once + +class VSTPresets +{ +public: + enum ErrorCode + { + noError, + invalidFile, + wrongPlugin, + outdatedPlugin, + wrongParameters, + }; + +#ifndef NO_VST + static ErrorCode LoadFile(FileReader &file, CVstPlugin &plugin); + static bool SaveFile(const char *filename, CVstPlugin &plugin, bool bank); + +protected: + static void SaveProgram(FILE *f, CVstPlugin &plugin); + + template<typename T> + static void Write(const T &v, FILE *f) + { + fwrite(&v, sizeof(T), 1, f); + } + + static void WriteBE(uint32 v, FILE *f); + static void WriteBE(float v, FILE *f); + +#else + static ErrorCode LoadFile(FileReader &, CVstPlugin &) { return invalidFile; } + static bool SaveFile(const char *, CVstPlugin &, bool) { return false; } +#endif // NO_VST +}; Modified: trunk/OpenMPT/mptrack/Vstplug.cpp =================================================================== --- trunk/OpenMPT/mptrack/Vstplug.cpp 2013-02-14 18:33:07 UTC (rev 1526) +++ trunk/OpenMPT/mptrack/Vstplug.cpp 2013-02-15 16:01:20 UTC (rev 1527) @@ -15,10 +15,9 @@ #include <medparam.h> #include "mainfrm.h" #include "vstplug.h" -#include <pluginterfaces/vst2.x/vstfxstore.h> // VST Presets +#include "VstPresets.h" #include "moddoc.h" #include "sndfile.h" -#include "fxp.h" //rewbs.VSTpresets #include "AbstractVstEditor.h" //rewbs.defaultPlugGUI #include "VstEditor.h" //rewbs.defaultPlugGUI #include "defaultvsteditor.h" //rewbs.defaultPlugGUI @@ -1597,8 +1596,8 @@ } -VstInt32 CVstPlugin::GetUID() -//--------------------------- +VstInt32 CVstPlugin::GetUID() const +//--------------------------------- { if (!(m_pEffect)) return 0; @@ -1606,8 +1605,8 @@ } -VstInt32 CVstPlugin::GetVersion() -//------------------------------- +VstInt32 CVstPlugin::GetVersion() const +//------------------------------------- { if (!(m_pEffect)) return 0; @@ -1654,77 +1653,45 @@ } -bool CVstPlugin::SaveProgram(CString fileName) -//-------------------------------------------- +bool CVstPlugin::SaveProgram(const char *filename) +//------------------------------------------------ { - if (!(m_pEffect)) - return false; + char ext[_MAX_EXT]; + _splitpath(filename, nullptr, nullptr, nullptr, ext); + return VSTPresets::SaveFile(filename, *this, !_strnicmp(ext, ".fxb", 4)); +} - bool success; - // Collect required data - long ID = GetUID(); - long plugVersion = GetVersion(); - Cfxp* fxp = nullptr; - - // Construct & save fxp - - // try chunk-based preset: - if((m_pEffect->flags & effFlagsProgramChunks) != 0) +const char *CVstPlugin::LoadProgram(const char *filename) +//------------------------------------------------------- +{ + CMappedFile f; + if(!f.Open(filename)) { - void *chunk = nullptr; - long chunkSize = Dispatch(effGetChunk, 1,0, &chunk, 0); - if(chunkSize && chunk) - fxp = new Cfxp(ID, plugVersion, 1, chunkSize, chunk); + return "Can't open file."; } - // fall back on parameter based preset: - if(fxp == nullptr) - { - // Collect required data - PlugParamIndex numParams = GetNumParameters(); - float *params = new float[numParams]; - GetParams(params, 0, numParams); + size_t len = f.GetLength(); + const char *data = reinterpret_cast<const char *>(f.Lock(len)); + FileReader file(data, len); - fxp = new Cfxp(ID, plugVersion, numParams, params); + VSTPresets::ErrorCode error = VSTPresets::LoadFile(file, *this); + f.Close(); - delete[] params; - } - - success = fxp->Save(fileName); - if(fxp) - delete fxp; - - return success; - -} - - -bool CVstPlugin::LoadProgram(CString fileName) -//-------------------------------------------- -{ - if (!(m_pEffect)) - return false; - - Cfxp fxp(fileName); // load from file - - // Verify - if (m_pEffect->uniqueID != fxp.fxID) - return false; - - if (fxp.fxMagic == fMagic) // Load preset based fxp + switch(error) { - if (m_pEffect->numParams != fxp.numParams) - return false; - for (int p=0; p<fxp.numParams; p++) - SetParameter(p, fxp.params[p]); - } else if (fxp.fxMagic == chunkPresetMagic) - { - Dispatch(effSetChunk, 1, fxp.chunkSize, (BYTE*)fxp.chunk, 0); + case VSTPresets::noError: + default: + return nullptr; + case VSTPresets::invalidFile: + return "This does not appear to be a valid preset file."; + case VSTPresets::wrongPlugin: + return "This file appears to be for a different plugin."; + case VSTPresets::outdatedPlugin: + return "This file is for a newer version of this plugin."; + case VSTPresets::wrongParameters: + return "The number of parameters in this file is incompatible with the current plugin."; } - - return true; } -//end rewbs.VSTpresets VstIntPtr CVstPlugin::Dispatch(VstInt32 opCode, VstInt32 index, VstIntPtr value, void *ptr, float opt) @@ -2651,8 +2618,7 @@ { m_pMixStruct->defaultProgram = -1; - if ((m_pEffect->flags & effFlagsProgramChunks) - && (Dispatch(effIdentify, 0,0, nullptr, 0.0f) == 'NvEf')) + if(ProgramsAreChunks() && Dispatch(effIdentify, 0,0, nullptr, 0.0f) == 'NvEf') { void *p = nullptr; LONG nByteSize = 0; Modified: trunk/OpenMPT/mptrack/Vstplug.h =================================================================== --- trunk/OpenMPT/mptrack/Vstplug.h 2013-02-14 18:33:07 UTC (rev 1526) +++ trunk/OpenMPT/mptrack/Vstplug.h 2013-02-15 16:01:20 UTC (rev 1527) @@ -180,10 +180,12 @@ VstInt32 GetCurrentProgram(); VstInt32 GetNumProgramCategories(); CString GetFormattedProgramName(VstInt32 index, bool allowFallback = false); - bool LoadProgram(CString fileName); - bool SaveProgram(CString fileName); - VstInt32 GetUID(); - VstInt32 GetVersion(); + const char *LoadProgram(const char *filename); + bool SaveProgram(const char *filename); + VstInt32 GetUID() const; + VstInt32 GetVersion() const; + // Check if programs should be stored as chunks or parameters + bool ProgramsAreChunks() const { return m_pEffect && (m_pEffect->flags & effFlagsProgramChunks) != 0; } bool GetParams(float* param, VstInt32 min, VstInt32 max); bool RandomizeParams(PlugParamIndex minParam = 0, PlugParamIndex maxParam = 0); #ifdef MODPLUG_TRACKER @@ -292,7 +294,9 @@ bool GetProgramNameIndexed(long, long, char*) { return false; } CString GetFormattedProgramName(VstInt32, bool = false) { return ""; } void SetParameter(PlugParamIndex, PlugParamValue) {} - + VstInt32 GetUID() const { return 0; } + VstInt32 GetVersion() const { return 0; } + bool CanAutomateParameter(PlugParamIndex index) { return false; } CString GetFormattedParamName(PlugParamIndex) { return ""; }; @@ -302,8 +306,8 @@ CString GetParamDisplay(PlugParamIndex) { return ""; }; PlugParamValue GetParameter(PlugParamIndex) { return 0; } - bool LoadProgram(CString) {return false;} - bool SaveProgram(CString) {return false;} + const char *LoadProgram(const char *) { return false; } + bool SaveProgram(const char *) { return false; } void SetCurrentProgram(UINT) {} void SetSlot(UINT) {} void UpdateMixStructPtr(void*) {} Deleted: trunk/OpenMPT/mptrack/fxp.cpp =================================================================== --- trunk/OpenMPT/mptrack/fxp.cpp 2013-02-14 18:33:07 UTC (rev 1526) +++ trunk/OpenMPT/mptrack/fxp.cpp 2013-02-15 16:01:20 UTC (rev 1527) @@ -1,307 +0,0 @@ -#include "stdafx.h" -#include "fxp.h" -#include "../common/Reporting.h" - -/************************************ -* Cons/Dest -*************************************/ - -Cfxp::Cfxp(void) -//-------------- -{ - params=NULL; - chunk=NULL; - m_bNeedSwap=-1; -} - -Cfxp::Cfxp(CString fileName) -//-------------------------- -{ - //Cfxp(); - params=NULL; - chunk=NULL; - m_bNeedSwap=-1; - Load(fileName); -} - - -Cfxp::Cfxp(long ID, long version, long nParams, float *ps) -//-------------------------------------------------------- -{ - //Cfxp(); - params=NULL; - chunk=NULL; - m_bNeedSwap=-1; - - ChunkMagic='CcnK'; // 'KncC'; - fxMagic='FxCk'; // 'kCxF'; - byteSize=0; - version=2; - fxID=ID; - fxVersion=version; - numParams=nParams; - params = new float[numParams]; - - memcpy(params, ps, sizeof(float)*numParams); - memset(prgName, 0, 28); -} - -Cfxp::Cfxp(long ID, long plugVersion, long nPrograms, long inChunkSize, void *inChunk) -//-------------------------------------------------------------------------------- -{ - //Cfxp(); - params=NULL; - chunk=NULL; - m_bNeedSwap=-1; - - ChunkMagic='CcnK'; // 'KncC'; - fxMagic='FPCh'; - byteSize = inChunkSize + 52; //52 is: header without byteSize and fxMagic. - version=2; - fxID=ID; - fxVersion=plugVersion; - numParams=nPrograms; - chunkSize=inChunkSize; - chunk = malloc(chunkSize); - memcpy(chunk, inChunk, sizeof(char)*chunkSize); - memset(prgName, 0, 28); -} - - -Cfxp::~Cfxp(void) -{ - delete[] params; - free(chunk); -} - - -/************************************ -* Load/Save -*************************************/ - - -bool Cfxp::Load(CString fileName) -{ - //char s[256]; - CFile inStream; - CFileException e; - if ( !inStream.Open(fileName, CFile::modeRead, &e) ) - { - //TODO: exception - Reporting::Error("Error opening file."); - return false; - } - - //TODO: make ReadLE OO (extend CFILE); - //TODO: exceptions - if (!(ReadLE(inStream, ChunkMagic) && - ReadLE(inStream, byteSize) && - ReadLE(inStream, fxMagic) && - ReadLE(inStream, version) && - ReadLE(inStream, fxID) && - ReadLE(inStream, fxVersion) && - ReadLE(inStream, numParams) && - ReadLE(inStream, prgName, 28) && - ChunkMagic == 'CcnK' && - (fxMagic == 'FxCk' || fxMagic == 'FPCh'))) - { - Reporting::Error("Bad Magic number: this does not look like a preset file."); - inStream.Close(); - return false; - } - - if (fxMagic == 'FxCk') // load param list - { - params = new float[numParams]; - for (int p=0; p<numParams; p++) - { - if (!ReadLE(inStream, params[p])) - { - Reporting::Error("Error reading Params."); - inStream.Close(); - return false; - } - } - } - else if (fxMagic == 'FPCh') // load chunk - { - if (!ReadLE(inStream, chunkSize)) - { - Reporting::Error("Error reading chunk size."); - inStream.Close(); - return false; - } - - chunk = malloc(chunkSize); - - if (!chunk) - { - Reporting::Error("Error allocating memory for chunk."); - inStream.Close(); - return false; - } - - if (!ReadLE(inStream, (char*)chunk, chunkSize)) - { - Reporting::Error("Error reading chunk."); - inStream.Close(); - return false; - } - - } - - inStream.Close(); - return true; -} - -bool Cfxp::Save(CString fileName) -{ - CFile outStream; - CFileException e; - - if ( !outStream.Open(fileName, CFile::modeCreate | CFile::modeWrite, &e) ) - { - //TODO: exception - return false; - } - - //TODO: make ReadLE OO (override CFILE); - //TODO: exceptions - if (!(WriteLE(outStream, ChunkMagic) && - WriteLE(outStream, byteSize) && - WriteLE(outStream, fxMagic) && - WriteLE(outStream, version) && - WriteLE(outStream, fxID) && - WriteLE(outStream, fxVersion) && - WriteLE(outStream, numParams) && - WriteLE(outStream, prgName, 28))) - { - outStream.Close(); - return false; - } - - if (fxMagic == 'FxCk') // save param list - { - for (int p=0; p<numParams; p++) - { - if (!WriteLE(outStream, params[p])) - { - //TODO: exception - outStream.Close(); - return false; - } - } - } - else if (fxMagic == 'FPCh') // save chunk list - { - if (!WriteLE(outStream, chunkSize) || !WriteLE(outStream, (char*)chunk, chunkSize)) - { - //TODO: exception - outStream.Close(); - return false; - } - - } - - outStream.Close(); - return true; -} - -/************************************ -* Util -*************************************/ - -bool Cfxp::ReadLE(CFile &in, long &l) -{ - UINT size=sizeof(long); - if (in.Read(&l, size) < size) - return false; - - if (NeedSwap()) - SwapBytes(l); - return true; -} - -bool Cfxp::ReadLE(CFile &in, float &f) -{ - UINT size=sizeof(float); - - try { - if (in.Read(&f, size) < size) - return false; - } catch (CFileException *e) - { - char s[256]; - wsprintf(s, "%lx: %d; %d; %s;", e, e->m_cause, e->m_lOsError, (LPCTSTR)e->m_strFileName); - Reporting::Error(s); - e->Delete(); - } - - if (NeedSwap()) - SwapBytes(f); - return true; - -} - -bool Cfxp::ReadLE(CFile &in, char *c, UINT length) -{ - UINT size=sizeof(char)*length; - return (in.Read(c, size) >= size); -} - -bool Cfxp::WriteLE(CFile &out, const long &l) -{ - int size=sizeof(long); - long l2 = l; - if (NeedSwap()) - SwapBytes(l2); - out.Write(&l2, size); - return true; -} - -bool Cfxp::WriteLE(CFile &out, const float &f) -{ - int size=sizeof(float); - float f2 = f; - if (NeedSwap()) - SwapBytes(f2); - out.Write(&f2, size); - return true; -} - -bool Cfxp::WriteLE(CFile &out, const char *c, UINT length) -{ - int size=sizeof(char)*length; - out.Write(c, size); - return true; -} - -bool Cfxp::NeedSwap() -//------------------- -{ - if (m_bNeedSwap < 0) //don't yet know if we need to swap - find out! - { - static char szChnk[] = "CcnK"; - static long lChnk = 'CcnK'; - m_bNeedSwap = !!memcmp(szChnk, &lChnk, 4); - } - - return m_bNeedSwap != 0; -} - - -void Cfxp::SwapBytes(long &l) -//--------------------------- -{ - unsigned char *b = (unsigned char *)&l; - long intermediate = ((long)b[0] << 24) | ((long)b[1] << 16) | ((long)b[2] << 8) | (long)b[3]; - l = intermediate; - -} - -void Cfxp::SwapBytes(float &f) -//---------------------------- -{ - long *pl = (long *)&f; - SwapBytes(*pl); -} Deleted: trunk/OpenMPT/mptrack/fxp.h =================================================================== --- trunk/OpenMPT/mptrack/fxp.h 2013-02-14 18:33:07 UTC (rev 1526) +++ trunk/OpenMPT/mptrack/fxp.h 2013-02-15 16:01:20 UTC (rev 1527) @@ -1,42 +0,0 @@ -#pragma once -//See vstfxstore.h in VST SDK2.3 for an overview of the fxp file structure. - -class Cfxp -{ -public: - Cfxp(void); - Cfxp(CString fileName); - Cfxp(long fxID, long fxVersion, long numParams, float *params); - Cfxp(long ID, long version, long nPrograms, long inChunkSize, void *inChunk); - ~Cfxp(void); - - long ChunkMagic; // "CcnK" - long byteSize; // size of this chunk, excluding ChunkMagic and byteSize - long fxMagic; // "FxCk" - long version; // VST version - ignore - long fxID; // Plugin unique ID - long fxVersion; // plugin version - ignore? - - long numParams; - char prgName[30]; - float *params; - long chunkSize; - void *chunk; - - bool Save(CString fileName); - -protected: - int m_bNeedSwap; - bool Load(CString fileName); - - bool ReadLE(CFile &in, long &l); - bool ReadLE(CFile &in, float &f); - bool ReadLE(CFile &in, char *c, UINT length=1); - bool WriteLE(CFile &out, const long &l); - bool WriteLE(CFile &out, const float &f); - bool WriteLE(CFile &out, const char *c, UINT length=1); - - bool NeedSwap(); - void SwapBytes(long &l); - void SwapBytes(float &f); -}; Modified: trunk/OpenMPT/mptrack/mptrack_08.vcproj =================================================================== --- trunk/OpenMPT/mptrack/mptrack_08.vcproj 2013-02-14 18:33:07 UTC (rev 1526) +++ trunk/OpenMPT/mptrack/mptrack_08.vcproj 2013-02-15 16:01:20 UTC (rev 1527) @@ -325,7 +325,7 @@ > </File> <File - RelativePath=".\fxp.cpp" + RelativePath=".\VstPresets.cpp" > </File> <File @@ -883,7 +883,7 @@ > </File> <File - RelativePath=".\fxp.h" + RelativePath=".\VstPresets.h" > </File> <File Modified: trunk/OpenMPT/mptrack/mptrack_10.vcxproj =================================================================== --- trunk/OpenMPT/mptrack/mptrack_10.vcxproj 2013-02-14 18:33:07 UTC (rev 1526) +++ trunk/OpenMPT/mptrack/mptrack_10.vcxproj 2013-02-15 16:01:20 UTC (rev 1527) @@ -210,7 +210,6 @@ <ClCompile Include="EffectVis.cpp" /> <ClCompile Include="..\soundlib\Fastmix.cpp" /> <ClCompile Include="ExceptionHandler.cpp" /> - <ClCompile Include="fxp.cpp" /> <ClCompile Include="globals.cpp" /> <ClCompile Include="HyperEdit.cpp" /> <ClCompile Include="HyperEdit2.cpp" /> @@ -316,6 +315,7 @@ <ClCompile Include="..\Soundlib\Load_umx.cpp" /> <ClCompile Include="..\soundlib\Load_wav.cpp" /> <ClCompile Include="..\soundlib\Load_xm.cpp" /> + <ClCompile Include="VstPresets.cpp" /> </ItemGroup> <ItemGroup> <ResourceCompile Include="mptrack.rc" /> @@ -373,7 +373,6 @@ <ClInclude Include="..\Soundlib\Dlsbank.h" /> <ClInclude Include="EffectVis.h" /> <ClInclude Include="..\soundlib\Endianness.h" /> - <ClInclude Include="fxp.h" /> <ClInclude Include="globals.h" /> <ClInclude Include="InputHandler.h" /> <ClInclude Include="KeyConfigDlg.h" /> @@ -430,6 +429,7 @@ <ClInclude Include="tuningRatioMapWnd.h" /> <ClInclude Include="test\test.h" /> <ClInclude Include="..\soundlib\Loaders.h" /> + <ClInclude Include="VstPresets.h" /> </ItemGroup> <ItemGroup> <None Include="res\bitmap1.bmp" /> Modified: trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters =================================================================== --- trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters 2013-02-14 18:33:07 UTC (rev 1526) +++ trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters 2013-02-15 16:01:20 UTC (rev 1527) @@ -127,9 +127,6 @@ <ClCompile Include="draw_pat.cpp"> <Filter>Source Files</Filter> </ClCompile> - <ClCompile Include="fxp.cpp"> - <Filter>Source Files</Filter> - </ClCompile> <ClCompile Include="..\soundlib\Fastmix.cpp"> <Filter>Source Files</Filter> </ClCompile> @@ -424,6 +421,9 @@ <ClCompile Include="..\soundlib\MixerSettings.cpp"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="VstPresets.cpp"> + <Filter>Source Files</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="AbstractVstEditor.h"> @@ -468,9 +468,6 @@ <ClInclude Include="..\Soundlib\Dlsbank.h"> <Filter>Header Files</Filter> </ClInclude> - <ClInclude Include="fxp.h"> - <Filter>Header Files</Filter> - </ClInclude> <ClInclude Include="..\soundlib\Endianness.h"> <Filter>Header Files</Filter> </ClInclude> @@ -753,6 +750,9 @@ <ClInclude Include="..\soundlib\MixerSettings.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="VstPresets.h"> + <Filter>Header Files</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <None Include="res\bitmap1.bmp"> Modified: trunk/OpenMPT/soundlib/plugins/JBridge.cpp =================================================================== --- trunk/OpenMPT/soundlib/plugins/JBridge.cpp 2013-02-14 18:33:07 UTC (rev 1526) +++ trunk/OpenMPT/soundlib/plugins/JBridge.cpp 2013-02-15 16:01:20 UTC (rev 1527) @@ -10,14 +10,15 @@ #include "stdafx.h" + #include <pluginterfaces/vst2.x/aeffectx.h> #include "JBridge.h" +#ifdef ENABLE_JBRIDGE + namespace JBridge { -#ifdef ENABLE_JBRIDGE - // Name of the proxy DLL to load static const char *proxyRegKey = "Software\\JBridge"; @@ -106,6 +107,6 @@ return pfnBridgeMain(audioMaster, pluginPath); } +} + #endif // ENABLE_JBRIDGE - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |