JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
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) 2023, 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//------------------------------------------------------------------------
87enum ChunkType
88{
89 kHeader,
90 kComponentState,
91 kControllerState,
92 kProgramData,
93 kMetaInfo,
94 kChunkList,
95 kNumPresetChunks
96};
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//------------------------------------------------------------------------
116 PresetFile (IBStream* stream);
117 virtual ~PresetFile ();
118
120 struct Entry
121 {
122 ChunkID id;
123 TSize offset;
124 TSize size;
125 };
126
127 IBStream* getStream () const { 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
222 IBStream* stream;
224 enum { kMaxEntries = 128 };
225 Entry entries[kMaxEntries];
226 int32 entryCount {0};
227};
228
229//------------------------------------------------------------------------
232class FileStream: public IBStream
233{
234public:
235//------------------------------------------------------------------------
236 static IBStream* open (const char* filename, const char* mode);
237
238 //---from FUnknown------------------
239 DECLARE_FUNKNOWN_METHODS
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//------------------------------------------------------------------------
262 ReadOnlyBStream (IBStream* sourceStream, TSize sourceOffset, TSize sectionSize);
263 virtual ~ReadOnlyBStream ();
264
265 //---from FUnknown------------------
266 DECLARE_FUNKNOWN_METHODS
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:
276 IBStream* sourceStream;
277 TSize sourceOffset;
278 TSize sectionSize;
279 TSize seekPosition;
280};
281
282//------------------------------------------------------------------------
285class BufferStream : public IBStream
286{
287public:
288 BufferStream ();
289 virtual ~BufferStream ();
290
291 //---from FUnknown------------------
292 DECLARE_FUNKNOWN_METHODS
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:
301 Buffer mBuffer;
302};
303
304//------------------------------------------------------------------------
305} // namespace Vst
306} // namespace Steinberg
Handling 16 Byte Globally Unique Identifiers.
Definition funknown.h:241
Base class for streams.
Definition ibstream.h:30
Stream implementation for a memory buffer.
tresult PLUGIN_API write(void *buffer, int32 numBytes, int32 *numBytesWritten=nullptr) SMTG_OVERRIDE
Writes binary data to stream.
DECLARE_FUNKNOWN_METHODS tresult PLUGIN_API read(void *buffer, int32 numBytes, int32 *numBytesRead=nullptr) SMTG_OVERRIDE
Reads binary data from stream.
tresult PLUGIN_API tell(int64 *pos) SMTG_OVERRIDE
Gets current stream read-write position.
tresult PLUGIN_API seek(int64 pos, int32 mode, int64 *result=nullptr) SMTG_OVERRIDE
Sets stream read-write position.
Stream implementation for a file using stdio.
tresult PLUGIN_API write(void *buffer, int32 numBytes, int32 *numBytesWritten=nullptr) SMTG_OVERRIDE
Writes binary data to stream.
static IBStream * open(const char *filename, const char *mode)
open a stream using stdio function
tresult PLUGIN_API seek(int64 pos, int32 mode, int64 *result=nullptr) SMTG_OVERRIDE
Sets stream read-write position.
tresult PLUGIN_API tell(int64 *pos) SMTG_OVERRIDE
Gets current stream read-write position.
DECLARE_FUNKNOWN_METHODS tresult PLUGIN_API read(void *buffer, int32 numBytes, int32 *numBytesRead=nullptr) SMTG_OVERRIDE
Reads binary data from stream.
Component base interface: Vst::IComponent.
Edit controller component interface: Vst::IEditController.
Component extension to access program list data: Vst::IProgramListData.
Definition ivstunits.h:215
Component extension to access unit data: Vst::IUnitData.
Definition ivstunits.h:247
Edit controller extension to describe the plug-in structure: Vst::IUnitInfo.
Definition ivstunits.h:145
Handler for a VST 3 Preset File.
const Entry * getEntry(ChunkType which) const
Returns an entry for a given chunk type.
static bool loadPreset(IBStream *stream, const FUID &classID, IComponent *component, IEditController *editController=nullptr, std::vector< FUID > *otherClassIDArray=nullptr)
Shortcut helper to load preset with component/controller state.
void setClassID(const FUID &uid)
Sets the associated classID (component ID: Processor part (not the controller!)).
bool writeHeader()
Writes into the stream the main header.
bool contains(ChunkType which) const
Checks if a given chunk type exist in the stream.
bool writeMetaInfo(const char *xmlBuffer, int32 size=-1, bool forceWriting=false)
Writes the meta XML info, -1 means null-terminated, forceWriting to true will force to rewrite the XM...
const Entry & at(int32 index) const
Returns the entry at a given position.
bool writeChunk(const void *data, int32 size, ChunkType which=kComponentState)
Writes a given data of a given size as "which" chunk type.
bool readMetaInfo(char *xmlBuffer, int32 &size)
Reads the meta XML info and its size, the size could be retrieved by passing zero as xmlBuffer.
bool storeComponentState(IComponent *component)
Stores the component state (only one time).
bool readChunkList()
Reads and build the chunk list (including the header chunk).
const Entry * getLastEntry() const
Returns the last available entry.
int32 getEntryCount() const
Returns the number of total entries in the current stream.
const FUID & getClassID() const
Returns the associated classID (component ID: Processor part (not the controller!)).
IBStream * getStream() const
Returns the associated stream.
bool restoreComponentState(IComponent *component)
Restores the component state.
bool getUnitProgramListID(int32 &unitProgramListID)
Gets the unitProgramListID saved in the kProgramData chunk (if available).
bool writeChunkList()
Writes into the stream the chunk list (should be at the end).
bool seekToControllerState()
Seeks to the begin of the Controller State.
bool storeControllerState(IEditController *editController)
Stores the controller state (only one time).
bool seekToComponentState()
Seeks to the begin of the Component State.
bool prepareMetaInfoUpdate()
checks if meta info chunk is the last one and jump to correct position.
FUID classID
classID is the FUID of the component (processor) part
bool restoreControllerState(IEditController *editController)
Restores the controller state.
static bool savePreset(IBStream *stream, const FUID &classID, IComponent *component, IEditController *editController=nullptr, const char *xmlBuffer=nullptr, int32 xmlSize=-1)
Shortcut helper to create preset from component/controller state.
bool restoreProgramData(IProgramListData *programListData, ProgramListID *programListID=nullptr, int32 programIndex=0)
Restores a IProgramListData with a given identifier and index.
bool storeProgramData(IBStream *inStream, ProgramListID listID)
Store program data or unit data from stream (including the header chunk).
Internal structure used for chunk handling.
Stream representing a Read-Only subsection of its source stream.
DECLARE_FUNKNOWN_METHODS tresult PLUGIN_API read(void *buffer, int32 numBytes, int32 *numBytesRead=nullptr) SMTG_OVERRIDE
Reads binary data from stream.
tresult PLUGIN_API tell(int64 *pos) SMTG_OVERRIDE
Gets current stream read-write position.
tresult PLUGIN_API seek(int64 pos, int32 mode, int64 *result=nullptr) SMTG_OVERRIDE
Sets stream read-write position.
tresult PLUGIN_API write(void *buffer, int32 numBytes, int32 *numBytesWritten=nullptr) SMTG_OVERRIDE
Writes binary data to stream.
memcmp
int32 ProgramListID
program list identifier
Definition vsttypes.h:82
int32 UnitID
unit identifier
Definition vsttypes.h:79