From: <sag...@us...> - 2013-02-17 15:06:04
|
Revision: 1534 http://sourceforge.net/p/modplug/code/1534 Author: saga-games Date: 2013-02-17 15:05:54 +0000 (Sun, 17 Feb 2013) Log Message: ----------- [New] VST Editor: Can now copy & paste current preset. Modified Paths: -------------- trunk/OpenMPT/mptrack/AbstractVstEditor.cpp trunk/OpenMPT/mptrack/AbstractVstEditor.h trunk/OpenMPT/mptrack/VstPresets.cpp trunk/OpenMPT/mptrack/VstPresets.h trunk/OpenMPT/mptrack/Vstplug.cpp trunk/OpenMPT/mptrack/mptrack.rc trunk/OpenMPT/mptrack/resource.h Modified: trunk/OpenMPT/mptrack/AbstractVstEditor.cpp =================================================================== --- trunk/OpenMPT/mptrack/AbstractVstEditor.cpp 2013-02-16 20:11:58 UTC (rev 1533) +++ trunk/OpenMPT/mptrack/AbstractVstEditor.cpp 2013-02-17 15:05:54 UTC (rev 1534) @@ -18,13 +18,18 @@ #include "AbstractVstEditor.h" #include "../common/StringFixer.h" #include "MIDIMacros.h" +#include "VstPresets.h" #ifndef NO_VST +UINT CAbstractVstEditor::clipboardFormat = RegisterClipboardFormat("VST Preset Data"); + BEGIN_MESSAGE_MAP(CAbstractVstEditor, CDialog) ON_WM_CLOSE() ON_WM_INITMENU() ON_WM_MENUSELECT() + ON_COMMAND(ID_EDIT_COPY, OnCopyParameters) + ON_COMMAND(ID_EDIT_PASTE, OnPasteParameters) ON_COMMAND(ID_PRESET_LOAD, OnLoadPreset) ON_COMMAND(ID_PLUG_BYPASS, OnBypassPlug) ON_COMMAND(ID_PLUG_RECORDAUTOMATION,OnRecordAutomation) @@ -147,9 +152,72 @@ } -void CAbstractVstEditor::OnRandomizePreset() +void CAbstractVstEditor::OnCopyParameters() //----------------------------------------- { + if(m_pVstPlugin == nullptr || CMainFrame::GetMainFrame() == nullptr) return; + + BeginWaitCursor(); + std::ostringstream f; + if(VSTPresets::SaveFile(f, *m_pVstPlugin, false)) + { + const std::string data = f.str(); + + HGLOBAL hCpy; + if(CMainFrame::GetMainFrame()->OpenClipboard() && (hCpy = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, data.length())) != nullptr) + { + EmptyClipboard(); + LPSTR p = (LPSTR)GlobalLock(hCpy); + if(p) + { + memcpy(p, &data[0], data.length()); + } + GlobalUnlock(hCpy); + SetClipboardData(clipboardFormat, (HANDLE) hCpy); + CloseClipboard(); + } + } + EndWaitCursor(); +} + + +void CAbstractVstEditor::OnPasteParameters() +//------------------------------------------ +{ + if(m_pVstPlugin == nullptr || CMainFrame::GetMainFrame() == nullptr) return; + + BeginWaitCursor(); + if (CMainFrame::GetMainFrame()->OpenClipboard()) + { + HGLOBAL hCpy = ::GetClipboardData(clipboardFormat); + const char *p; + + if(hCpy != nullptr && (p = static_cast<const char *>(GlobalLock(hCpy))) != nullptr) + { + FileReader file(p, GlobalSize(hCpy)); + if(VSTPresets::LoadFile(file, *m_pVstPlugin) == VSTPresets::noError) + { + CSoundFile *pSndFile = m_pVstPlugin->m_pSndFile; + CModDoc *pModDoc; + if(pSndFile != nullptr && pSndFile->GetModSpecifications().supportsPlugins && (pModDoc = pSndFile->GetpModDoc()) != nullptr) + { + pModDoc->SetModified(); + } + } else + { + Reporting::Error("Error loading preset from clipboard. Are you sure it is for this plugin?"); + } + GlobalUnlock(hCpy); + } + CloseClipboard(); + } + EndWaitCursor(); +} + + +VOID CAbstractVstEditor::OnRandomizePreset() +//----------------------------------------- +{ if(m_pVstPlugin && Reporting::Confirm("Are you sure you want to randomize parameters?\nYou will lose current parameter values.", false, false, this) == cnfYes) { m_pVstPlugin->RandomizeParams(); Modified: trunk/OpenMPT/mptrack/AbstractVstEditor.h =================================================================== --- trunk/OpenMPT/mptrack/AbstractVstEditor.h 2013-02-16 20:11:58 UTC (rev 1533) +++ trunk/OpenMPT/mptrack/AbstractVstEditor.h 2013-02-17 15:05:54 UTC (rev 1534) @@ -36,6 +36,8 @@ afx_msg void OnLoadPreset(); afx_msg void OnSavePreset(); + afx_msg void OnCopyParameters(); + afx_msg void OnPasteParameters(); afx_msg void OnRandomizePreset(); afx_msg void OnSetPreset(UINT nID); afx_msg void OnBypassPlug(); @@ -70,6 +72,7 @@ CMenu *m_pOutputMenu; CMenu *m_pMacroMenu; CMenu *m_pOptionsMenu; + static UINT clipboardFormat; void FillPresetMenu(); void UpdatePresetMenu(bool force = false); Modified: trunk/OpenMPT/mptrack/VstPresets.cpp =================================================================== --- trunk/OpenMPT/mptrack/VstPresets.cpp 2013-02-16 20:11:58 UTC (rev 1533) +++ trunk/OpenMPT/mptrack/VstPresets.cpp 2013-02-17 15:05:54 UTC (rev 1534) @@ -117,15 +117,9 @@ } -bool VSTPresets::SaveFile(const char *filename, CVstPlugin &plugin, bool bank) -//---------------------------------------------------------------------------- +bool VSTPresets::SaveFile(std::ostream &f, CVstPlugin &plugin, bool bank) +//----------------------------------------------------------------------- { - FILE *f = fopen(filename, "wb"); - if(f == nullptr) - { - return false; - } - if(!bank) { SaveProgram(f, plugin); @@ -151,12 +145,12 @@ if(writeChunk) { - void *chunk = nullptr; + char *chunk = nullptr; uint32 chunkSize = plugin.Dispatch(effGetChunk, 0, 0, &chunk, 0); if(chunkSize && chunk) { WriteBE(chunkSize, f); - fwrite(chunk, chunkSize, 1, f); + f.write(chunk, chunkSize); } } else { @@ -169,20 +163,19 @@ } // Now we know the correct chunk size. - off_t end = ftell(f); - header.byteSize = end - 8; + std::streamoff end = f.tellp(); + header.byteSize = static_cast<VstInt32>(end - 8); header.ConvertEndianness(); - fseek(f, 0, SEEK_SET); + f.seekp(0); Write(header, f); } - fclose(f); return true; } -void VSTPresets::SaveProgram(FILE *f, CVstPlugin &plugin) -//------------------------------------------------------- +void VSTPresets::SaveProgram(std::ostream &f, CVstPlugin &plugin) +//--------------------------------------------------------------- { const bool writeChunk = plugin.ProgramsAreChunks(); ChunkHeader header; @@ -193,7 +186,7 @@ header.fxVersion = plugin.GetVersion(); // Write unfinished header... We need to update the size once we're done writing. - off_t start = ftell(f); + std::streamoff start = f.tellp(); Write(header, f); const uint32 numParams = plugin.GetNumParameters(); @@ -201,16 +194,16 @@ char name[max(kVstMaxProgNameLen + 1, 256)]; plugin.Dispatch(effGetProgramName, 0, 0, name, 0); - fwrite(name, 28, 1, f); + f.write(name, 28); if(writeChunk) { - void *chunk = nullptr; + char *chunk = nullptr; uint32 chunkSize = plugin.Dispatch(effGetChunk, 1, 0, &chunk, 0); if(chunkSize && chunk) { WriteBE(chunkSize, f); - fwrite(chunk, chunkSize, 1, f); + f.write(chunk, chunkSize); } } else { @@ -221,25 +214,25 @@ } // Now we know the correct chunk size. - off_t end = ftell(f); - header.byteSize = end - start - 8; + std::streamoff end = f.tellp(); + header.byteSize = static_cast<VstInt32>(end - start - 8); header.ConvertEndianness(); - fseek(f, start, SEEK_SET); + f.seekp(start); Write(header, f); - fseek(f, end, SEEK_SET); + f.seekp(end); } -void VSTPresets::WriteBE(uint32 v, FILE *f) -//----------------------------------------- +void VSTPresets::WriteBE(uint32 v, std::ostream &f) +//------------------------------------------------- { SwapBytesBE(v); Write(v, f); } -void VSTPresets::WriteBE(float v, FILE *f) -//---------------------------------------- +void VSTPresets::WriteBE(float v, std::ostream &f) +//------------------------------------------------ { union { Modified: trunk/OpenMPT/mptrack/VstPresets.h =================================================================== --- trunk/OpenMPT/mptrack/VstPresets.h 2013-02-16 20:11:58 UTC (rev 1533) +++ trunk/OpenMPT/mptrack/VstPresets.h 2013-02-17 15:05:54 UTC (rev 1534) @@ -10,6 +10,8 @@ #pragma once +#include <ostream> + class VSTPresets { public: @@ -24,22 +26,22 @@ #ifndef NO_VST static ErrorCode LoadFile(FileReader &file, CVstPlugin &plugin); - static bool SaveFile(const char *filename, CVstPlugin &plugin, bool bank); + static bool SaveFile(std::ostream &, CVstPlugin &plugin, bool bank); protected: - static void SaveProgram(FILE *f, CVstPlugin &plugin); + static void SaveProgram(std::ostream &f, CVstPlugin &plugin); template<typename T> - static void Write(const T &v, FILE *f) + static void Write(const T &v, std::ostream &f) { - fwrite(&v, sizeof(T), 1, f); + f.write(reinterpret_cast<const char *>(&v), sizeof(T)); } - static void WriteBE(uint32 v, FILE *f); - static void WriteBE(float v, FILE *f); + static void WriteBE(uint32 v, std::ostream &f); + static void WriteBE(float v, std::ostream &f); #else static ErrorCode LoadFile(FileReader &, CVstPlugin &) { return invalidFile; } - static bool SaveFile(const char *, CVstPlugin &, bool) { return false; } + static bool SaveFile(std::ostream &, CVstPlugin &, bool) { return false; } #endif // NO_VST }; Modified: trunk/OpenMPT/mptrack/Vstplug.cpp =================================================================== --- trunk/OpenMPT/mptrack/Vstplug.cpp 2013-02-16 20:11:58 UTC (rev 1533) +++ trunk/OpenMPT/mptrack/Vstplug.cpp 2013-02-17 15:05:54 UTC (rev 1534) @@ -1658,7 +1658,10 @@ { char ext[_MAX_EXT]; _splitpath(filename, nullptr, nullptr, nullptr, ext); - return VSTPresets::SaveFile(filename, *this, !_strnicmp(ext, ".fxb", 4)); + + std::fstream f; + f.open(filename, std::ios::out | std::ios::trunc | std::ios::binary); + return f.good() && VSTPresets::SaveFile(f, *this, !_strnicmp(ext, ".fxb", 4)); } Modified: trunk/OpenMPT/mptrack/mptrack.rc =================================================================== --- trunk/OpenMPT/mptrack/mptrack.rc 2013-02-16 20:11:58 UTC (rev 1533) +++ trunk/OpenMPT/mptrack/mptrack.rc 2013-02-17 15:05:54 UTC (rev 1534) @@ -2756,9 +2756,11 @@ BEGIN POPUP "&File" BEGIN + MENUITEM "&Copy Parameters", ID_EDIT_COPY + MENUITEM "&Paste Parameters", ID_EDIT_PASTE MENUITEM "&Load Preset / Bank...", ID_PRESET_LOAD MENUITEM "&Save Preset / Bank...", ID_PRESET_SAVE - MENUITEM "Create instrument from plugin", ID_PLUGINTOINSTRUMENT + MENUITEM "&Create instrument from plugin", ID_PLUGINTOINSTRUMENT MENUITEM SEPARATOR MENUITEM "&Randomize Parameters", ID_PRESET_RANDOM END Modified: trunk/OpenMPT/mptrack/resource.h =================================================================== --- trunk/OpenMPT/mptrack/resource.h 2013-02-16 20:11:58 UTC (rev 1533) +++ trunk/OpenMPT/mptrack/resource.h 2013-02-17 15:05:54 UTC (rev 1534) @@ -1083,10 +1083,6 @@ #define ID_REARRANGE_SAMPLES 33901 #define ID_CHANNEL_MANAGER 33905 #define ID_NEW_ITPROJECT 33906 -#define ID_FILE_OPEN32908 33908 -#define ID_FILE_SAVE32909 33909 -#define ID_FILE_SAVEPRESET 33912 -#define ID_FILE_OPENPRESET 33913 #define ID_FACTORYPRESET 33914 #define ID_FACTORYPRESET_DEFAULT 33915 #define ID_MODTREE_SETPATH 33916 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |