LMMS
Loading...
Searching...
No Matches
vstpresetfile.h
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2// Project : VST SDK
3//
4// Category : Helpers
5// Filename : public.sdk/source/vst/vstpresetfile.h
6// Created by : Steinberg, 03/2006
7// Description : VST 3 Preset File Format
8//
9//-----------------------------------------------------------------------------
10// LICENSE
11// (c) 2021, Steinberg Media Technologies GmbH, All Rights Reserved
12//-----------------------------------------------------------------------------
13// Redistribution and use in source and binary forms, with or without modification,
14// are permitted provided that the following conditions are met:
15//
16// * Redistributions of source code must retain the above copyright notice,
17// this list of conditions and the following disclaimer.
18// * Redistributions in binary form must reproduce the above copyright notice,
19// this list of conditions and the following disclaimer in the documentation
20// and/or other materials provided with the distribution.
21// * Neither the name of the Steinberg Media Technologies nor the names of its
22// contributors may be used to endorse or promote products derived from this
23// software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
26// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
33// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
34// OF THE POSSIBILITY OF SUCH DAMAGE.
35//-----------------------------------------------------------------------------
36
37#pragma once
38
42
44#include "base/source/fbuffer.h"
45
46#include <cstdio>
47#include <vector>
48
49//------------------------------------------------------------------------
50/*
51 VST 3 Preset File Format Definition
52 ===================================
53
540 +---------------------------+
55 | HEADER |
56 | header id ('VST3') | 4 Bytes
57 | version | 4 Bytes (int32)
58 | ASCII-encoded class id | 32 Bytes
59 +--| offset to chunk list | 8 Bytes (int64)
60 | +---------------------------+
61 | | DATA AREA |<-+
62 | | data of chunks 1..n | |
63 | ... ... |
64 | | | |
65 +->+---------------------------+ |
66 | CHUNK LIST | |
67 | list id ('List') | | 4 Bytes
68 | entry count | | 4 Bytes (int32)
69 +---------------------------+ |
70 | 1..n | |
71 | +----------------------+ | |
72 | | chunk id | | | 4 Bytes
73 | | offset to chunk data |----+ 8 Bytes (int64)
74 | | size of chunk data | | 8 Bytes (int64)
75 | +----------------------+ |
76EOF +---------------------------+
77*/
78
79//------------------------------------------------------------------------
80namespace Steinberg {
81namespace Vst {
82
83//------------------------------------------------------------------------
84using ChunkID = char[4];
85
86//------------------------------------------------------------------------
97
98//------------------------------------------------------------------------
99extern const ChunkID& getChunkID (ChunkType type);
100
101//------------------------------------------------------------------------
102inline bool isEqualID (const ChunkID id1, const ChunkID id2)
103{
104 return memcmp (id1, id2, sizeof (ChunkID)) == 0;
105}
106
107//------------------------------------------------------------------------
113{
114public:
115//------------------------------------------------------------------------
117 virtual ~PresetFile ();
118
126
127 IBStream* getStream () { return stream; }
128
129 const FUID& getClassID () const { return classID; }
130 void setClassID (const FUID& uid) { classID = uid; }
131
132 const Entry* getEntry (ChunkType which) const;
133 const Entry* getLastEntry () const;
134 int32 getEntryCount () const { return entryCount; }
135 const Entry& at (int32 index) const { return entries[index]; }
136 bool contains (ChunkType which) const { return getEntry (which) != nullptr; }
137
138 bool readChunkList ();
139 bool writeHeader ();
140 bool writeChunkList ();
141
143 bool readMetaInfo (char* xmlBuffer, int32& size);
144
146 bool writeMetaInfo (const char* xmlBuffer, int32 size = -1, bool forceWriting = false);
147 bool prepareMetaInfoUpdate ();
148
150 bool writeChunk (const void* data, int32 size, ChunkType which = kComponentState);
151
152 //-------------------------------------------------------------
153 // for storing and restoring the whole plug-in state (component and controller states)
154 bool seekToComponentState ();
155 bool storeComponentState (IComponent* component);
156 bool storeComponentState (IBStream* componentStream);
157 bool restoreComponentState (IComponent* component);
158
159 bool seekToControllerState ();
160 bool storeControllerState (IEditController* editController);
161 bool storeControllerState (IBStream* editStream);
162 bool restoreControllerState (IEditController* editController);
163
164 bool restoreComponentState (IEditController* editController);
165
166 //--- ----------------------------------------------------------
170 bool storeProgramData (IBStream* inStream, ProgramListID listID);
171
172 //---when plug-in uses IProgramListData-----------------------
174 bool storeProgramData (IProgramListData* programListData, ProgramListID programListID,
175 int32 programIndex);
177 bool restoreProgramData (IProgramListData* programListData, ProgramListID* programListID = nullptr,
178 int32 programIndex = 0);
179
180 //---when plug-in uses IUnitData------------------------------
182 bool storeProgramData (IUnitData* unitData, UnitID unitID);
184 bool restoreProgramData (IUnitData* unitData, UnitID* unitID = nullptr);
185
186 //--- ----------------------------------------------------------
189 bool restoreProgramData (IUnitInfo* unitInfo, int32 unitProgramListID, int32 programIndex = -1);
190
192 bool getUnitProgramListID (int32& unitProgramListID);
193
194 //--- ---------------------------------------------------------------------
197 static bool savePreset (IBStream* stream, const FUID& classID, IComponent* component,
198 IEditController* editController = nullptr,
199 const char* xmlBuffer = nullptr, int32 xmlSize = -1);
200 static bool savePreset (IBStream* stream, const FUID& classID, IBStream* componentStream,
201 IBStream* editStream = nullptr, const char* xmlBuffer = nullptr,
202 int32 xmlSize = -1);
203
206 static bool loadPreset (IBStream* stream, const FUID& classID, IComponent* component,
207 IEditController* editController = nullptr,
208 std::vector<FUID>* otherClassIDArray = nullptr);
209//------------------------------------------------------------------------
210protected:
211 bool readID (ChunkID id);
212 bool writeID (const ChunkID id);
213 bool readEqualID (const ChunkID id);
214 bool readSize (TSize& size);
215 bool writeSize (TSize size);
216 bool readInt32 (int32& value);
217 bool writeInt32 (int32 value);
218 bool seekTo (TSize offset);
219 bool beginChunk (Entry& e, ChunkType which);
220 bool endChunk (Entry& e);
221
224 enum { kMaxEntries = 128 };
227};
228
229//------------------------------------------------------------------------
232class FileStream: public IBStream
233{
234public:
235//------------------------------------------------------------------------
236 static IBStream* open (const char* filename, const char* mode);
237
238 //---from FUnknown------------------
240
241 //---from IBStream------------------
242 tresult PLUGIN_API read (void* buffer, int32 numBytes, int32* numBytesRead = nullptr) SMTG_OVERRIDE;
243 tresult PLUGIN_API write (void* buffer, int32 numBytes, int32* numBytesWritten = nullptr) SMTG_OVERRIDE;
244 tresult PLUGIN_API seek (int64 pos, int32 mode, int64* result = nullptr) SMTG_OVERRIDE;
245 tresult PLUGIN_API tell (int64* pos) SMTG_OVERRIDE;
246
247//------------------------------------------------------------------------
248protected:
249 FileStream (FILE* file);
250 virtual ~FileStream ();
251
252 FILE* file;
253};
254
255//------------------------------------------------------------------------
259{
260public:
261//------------------------------------------------------------------------
263 virtual ~ReadOnlyBStream ();
264
265 //---from FUnknown------------------
267
268 //---from IBStream------------------
269 tresult PLUGIN_API read (void* buffer, int32 numBytes, int32* numBytesRead = nullptr) SMTG_OVERRIDE;
270 tresult PLUGIN_API write (void* buffer, int32 numBytes, int32* numBytesWritten = nullptr) SMTG_OVERRIDE;
271 tresult PLUGIN_API seek (int64 pos, int32 mode, int64* result = nullptr) SMTG_OVERRIDE;
272 tresult PLUGIN_API tell (int64* pos) SMTG_OVERRIDE;
273
274//------------------------------------------------------------------------
275protected:
280};
281
282//------------------------------------------------------------------------
285class BufferStream : public IBStream
286{
287public:
288 BufferStream ();
289 virtual ~BufferStream ();
290
291 //---from FUnknown------------------
293
294 //---from IBStream------------------
295 tresult PLUGIN_API read (void* buffer, int32 numBytes, int32* numBytesRead = nullptr) SMTG_OVERRIDE;
296 tresult PLUGIN_API write (void* buffer, int32 numBytes, int32* numBytesWritten = nullptr) SMTG_OVERRIDE;
297 tresult PLUGIN_API seek (int64 pos, int32 mode, int64* result = nullptr) SMTG_OVERRIDE;
298 tresult PLUGIN_API tell (int64* pos) SMTG_OVERRIDE;
299
300protected:
302};
303
304//------------------------------------------------------------------------
305} // namespace Vst
306} // namespace Steinberg
CAdPlugDatabase::CRecord::RecordType type
Definition adplugdb.cpp:93
Definition fbuffer.h:56
Definition funknown.h:233
Definition ibstream.h:30
tresult PLUGIN_API write(void *buffer, int32 numBytes, int32 *numBytesWritten=nullptr) SMTG_OVERRIDE
Definition vstpresetfile.cpp:874
DECLARE_FUNKNOWN_METHODS tresult PLUGIN_API read(void *buffer, int32 numBytes, int32 *numBytesRead=nullptr) SMTG_OVERRIDE
Definition vstpresetfile.cpp:864
tresult PLUGIN_API tell(int64 *pos) SMTG_OVERRIDE
Definition vstpresetfile.cpp:926
Buffer mBuffer
Definition vstpresetfile.h:301
BufferStream()
Definition vstpresetfile.cpp:858
virtual ~BufferStream()
Definition vstpresetfile.cpp:861
tresult PLUGIN_API seek(int64 pos, int32 mode, int64 *result=nullptr) SMTG_OVERRIDE
Definition vstpresetfile.cpp:884
tresult PLUGIN_API write(void *buffer, int32 numBytes, int32 *numBytesWritten=nullptr) SMTG_OVERRIDE
Definition vstpresetfile.cpp:722
static IBStream * open(const char *filename, const char *mode)
open a stream using stdio function
Definition vstpresetfile.cpp:692
tresult PLUGIN_API seek(int64 pos, int32 mode, int64 *result=nullptr) SMTG_OVERRIDE
Definition vstpresetfile.cpp:731
tresult PLUGIN_API tell(int64 *pos) SMTG_OVERRIDE
Definition vstpresetfile.cpp:743
DECLARE_FUNKNOWN_METHODS tresult PLUGIN_API read(void *buffer, int32 numBytes, int32 *numBytesRead=nullptr) SMTG_OVERRIDE
Definition vstpresetfile.cpp:713
FileStream(FILE *file)
Definition vstpresetfile.cpp:699
FILE * file
Definition vstpresetfile.h:252
virtual ~FileStream()
Definition vstpresetfile.cpp:703
Definition ivstcomponent.h:158
Definition ivsteditcontroller.h:392
Definition ivstunits.h:215
Definition ivstunits.h:247
Definition ivstunits.h:145
const Entry * getEntry(ChunkType which) const
Returns an entry for a given chunk type.
Definition vstpresetfile.cpp:197
static bool loadPreset(IBStream *stream, const FUID &classID, IComponent *component, IEditController *editController=nullptr, std::vector< FUID > *otherClassIDArray=nullptr)
Definition vstpresetfile.cpp:144
bool readSize(TSize &size)
Definition vstpresetfile.cpp:236
void setClassID(const FUID &uid)
Sets the associated classID (component ID: Processor part (not the controller!)).
Definition vstpresetfile.h:130
int32 entryCount
Definition vstpresetfile.h:226
bool writeHeader()
Writes into the stream the main header.
Definition vstpresetfile.cpp:328
bool contains(ChunkType which) const
Checks if a given chunk type exist in the stream.
Definition vstpresetfile.h:136
PresetFile(IBStream *stream)
Constructor of Preset file based on a stream.
Definition vstpresetfile.cpp:181
bool writeMetaInfo(const char *xmlBuffer, int32 size=-1, bool forceWriting=false)
Definition vstpresetfile.cpp:410
const Entry & at(int32 index) const
Returns the entry at a given position.
Definition vstpresetfile.h:135
bool writeChunk(const void *data, int32 size, ChunkType which=kComponentState)
Definition vstpresetfile.cpp:453
bool readMetaInfo(char *xmlBuffer, int32 &size)
Definition vstpresetfile.cpp:390
bool readEqualID(const ChunkID id)
Definition vstpresetfile.cpp:229
bool endChunk(Entry &e)
Definition vstpresetfile.cpp:377
bool readInt32(int32 &value)
Definition vstpresetfile.cpp:258
bool storeComponentState(IComponent *component)
Stores the component state (only one time).
Definition vstpresetfile.cpp:470
bool readChunkList()
Reads and build the chunk list (including the header chunk).
Definition vstpresetfile.cpp:288
bool beginChunk(Entry &e, ChunkType which)
Definition vstpresetfile.cpp:364
const Entry * getLastEntry() const
Returns the last available entry.
Definition vstpresetfile.cpp:207
int32 getEntryCount() const
Returns the number of total entries in the current stream.
Definition vstpresetfile.h:134
const FUID & getClassID() const
Returns the associated classID (component ID: Processor part (not the controller!)).
Definition vstpresetfile.h:129
bool readID(ChunkID id)
Definition vstpresetfile.cpp:213
bool restoreComponentState(IComponent *component)
Restores the component state.
Definition vstpresetfile.cpp:490
@ kMaxEntries
Definition vstpresetfile.h:224
IBStream * stream
Definition vstpresetfile.h:222
bool getUnitProgramListID(int32 &unitProgramListID)
Definition vstpresetfile.cpp:676
bool writeChunkList()
Writes into the stream the chunk list (should be at the end).
Definition vstpresetfile.cpp:340
bool writeID(const ChunkID id)
Definition vstpresetfile.cpp:221
bool seekToControllerState()
Seeks to the begin of the Controller State.
Definition vstpresetfile.cpp:516
bool storeControllerState(IEditController *editController)
Stores the controller state (only one time).
Definition vstpresetfile.cpp:523
bool seekToComponentState()
Seeks to the begin of the Component State.
Definition vstpresetfile.cpp:463
bool writeSize(TSize size)
Definition vstpresetfile.cpp:247
bool prepareMetaInfoUpdate()
checks if meta info chunk is the last one and jump to correct position.
Definition vstpresetfile.cpp:429
IBStream * getStream()
Returns the associated stream.
Definition vstpresetfile.h:127
FUID classID
classID is the FUID of the component (processor) part
Definition vstpresetfile.h:223
bool seekTo(TSize offset)
Definition vstpresetfile.cpp:280
bool writeInt32(int32 value)
Definition vstpresetfile.cpp:269
bool restoreControllerState(IEditController *editController)
Restores the controller state.
Definition vstpresetfile.cpp:544
virtual ~PresetFile()
Definition vstpresetfile.cpp:190
static bool savePreset(IBStream *stream, const FUID &classID, IComponent *component, IEditController *editController=nullptr, const char *xmlBuffer=nullptr, int32 xmlSize=-1)
Definition vstpresetfile.cpp:102
Entry entries[kMaxEntries]
Definition vstpresetfile.h:225
bool restoreProgramData(IProgramListData *programListData, ProgramListID *programListID=nullptr, int32 programIndex=0)
Definition vstpresetfile.cpp:593
bool storeProgramData(IBStream *inStream, ProgramListID listID)
Definition vstpresetfile.cpp:557
IBStream * sourceStream
Definition vstpresetfile.h:276
TSize sectionSize
Definition vstpresetfile.h:278
DECLARE_FUNKNOWN_METHODS tresult PLUGIN_API read(void *buffer, int32 numBytes, int32 *numBytesRead=nullptr) SMTG_OVERRIDE
Definition vstpresetfile.cpp:783
TSize seekPosition
Definition vstpresetfile.h:279
virtual ~ReadOnlyBStream()
Definition vstpresetfile.cpp:768
ReadOnlyBStream(IBStream *sourceStream, TSize sourceOffset, TSize sectionSize)
Definition vstpresetfile.cpp:756
TSize sourceOffset
Definition vstpresetfile.h:277
tresult PLUGIN_API tell(int64 *pos) SMTG_OVERRIDE
Definition vstpresetfile.cpp:845
tresult PLUGIN_API seek(int64 pos, int32 mode, int64 *result=nullptr) SMTG_OVERRIDE
Definition vstpresetfile.cpp:823
tresult PLUGIN_API write(void *buffer, int32 numBytes, int32 *numBytesWritten=nullptr) SMTG_OVERRIDE
Definition vstpresetfile.cpp:813
* e
Definition inflate.c:1404
static char filename[]
Definition features.c:5
#define SMTG_OVERRIDE
Definition fplatform.h:241
#define DECLARE_FUNKNOWN_METHODS
Definition funknown.h:89
static PuglViewHint int value
Definition pugl.h:1708
JSAMPIMAGE data
Definition jpeglib.h:945
Definition ivstattributes.h:28
char[4] ChunkID
Definition vstpresetfile.h:84
bool isEqualID(const ChunkID id1, const ChunkID id2)
Definition vstpresetfile.h:102
ChunkType
Definition vstpresetfile.h:88
@ kComponentState
Definition vstpresetfile.h:90
@ kNumPresetChunks
Definition vstpresetfile.h:95
@ kHeader
Definition vstpresetfile.h:89
@ kProgramData
Definition vstpresetfile.h:92
@ kChunkList
Definition vstpresetfile.h:94
@ kMetaInfo
Definition vstpresetfile.h:93
@ kControllerState
Definition vstpresetfile.h:91
int32 ProgramListID
program list identifier
Definition vsttypes.h:76
const ChunkID & getChunkID(ChunkType type)
Definition vstpresetfile.cpp:65
int32 UnitID
unit identifier
Definition vsttypes.h:73
Definition baseiids.cpp:43
int int32
Definition ftypes.h:50
int64 TSize
Definition ftypes.h:75
long long int64
Definition ftypes.h:66
int32 tresult
Definition ftypes.h:76
png_structrp int mode
Definition png.h:1139
Definition vstpresetfile.h:121
TSize offset
Definition vstpresetfile.h:123
ChunkID id
Definition vstpresetfile.h:122
TSize size
Definition vstpresetfile.h:124
ulg size
Definition extract.c:2350
int result
Definition process.c:1455