vstpresetfile.h

Go to the documentation of this file.
00001 //------------------------------------------------------------------------
00002 // Project     : VST SDK
00003 // Version     : 3.0
00004 //
00005 // Category    : Helpers
00006 // Filename    : vstpresetfile.h
00007 // Created by  : Steinberg, 03/2006
00008 // Modified    : $Date: 2008/01/09 12:51:07 $
00009 // Description : VST3 Preset File Format
00010 //
00011 //-----------------------------------------------------------------------------
00012 // LICENSE
00013 // © 2008, Steinberg Media Technologies GmbH, All Rights Reserved
00014 //-----------------------------------------------------------------------------
00015 // This Software Development Kit may not be distributed in parts or its entirety  
00016 // without prior written agreement by Steinberg Media Technologies GmbH. 
00017 // This SDK must not be used to re-engineer or manipulate any technology used  
00018 // in any Steinberg or Third-party application or software module, 
00019 // unless permitted by law.
00020 // Neither the name of the Steinberg Media Technologies nor the names of its
00021 // contributors may be used to endorse or promote products derived from this software without specific prior written permission.
00022 // 
00023 // THIS SDK IS PROVIDED BY STEINBERG MEDIA TECHNOLOGIES GMBH "AS IS" AND
00024 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
00025 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
00026 //
00027 // IN NO EVENT SHALL STEINBERG MEDIA TECHNOLOGIES GMBH BE LIABLE FOR ANY DIRECT, 
00028 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
00029 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
00030 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
00031 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
00032 // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
00033 // OF THE POSSIBILITY OF SUCH DAMAGE.
00034 //-----------------------------------------------------------------------------
00035 
00036 #ifndef __vstpresetfile__
00037 #define __vstpresetfile__
00038 
00039 #include "pluginterfaces/vst/ivstcomponent.h"
00040 #include "pluginterfaces/vst/ivsteditcontroller.h"
00041 #include "pluginterfaces/vst/ivstunits.h"
00042 
00043 #include "pluginterfaces/host/frame/ibstream.h"
00044 
00045 #include <cstdio>
00046 
00047 //------------------------------------------------------------------------
00048 /*
00049         VST3 Preset File Format Definition
00050         ==================================
00051 
00052 0       +---------------------------+
00053         | HEADER                                        |
00054         | header id     ('VST3')                |               4 Bytes
00055         | version                                       |               4 Bytes (int32)
00056         | ASCII-encoded class id        |               32 Bytes 
00057  +--| offset to chunk list              |               8 Bytes (int64)
00058  |      +---------------------------+
00059  |      | DATA AREA                                     |<-+
00060  |      | data of chunks 1..n           |  |
00061  |      ...                                               ...  |
00062  |      |                                                       |  |
00063  +->+---------------------------+  |
00064         | CHUNK LIST                            |  |
00065         | list id ('List')                      |  |    4 Bytes
00066         | entry count                           |  |    4 Bytes (int32)
00067         +---------------------------+  |
00068         |  1..n                                         |  |
00069         |  +----------------------+ |  |
00070         |  | chunk id                     | |  |        4 Bytes
00071         |  | offset to chunk data |----+        8 Bytes (int64)
00072         |  | size of chunk data   | |           8 Bytes (int64)
00073         |  +----------------------+ |
00074 EOF     +---------------------------+
00075 
00076 */
00077 //------------------------------------------------------------------------
00078 
00079 //------------------------------------------------------------------------
00080 namespace Steinberg {
00081 namespace Vst {
00082 
00083 //------------------------------------------------------------------------
00084 typedef char ChunkID[4];
00085 
00086 //------------------------------------------------------------------------
00087 enum ChunkType
00088 {
00089         kHeader,
00090         kComponentState,
00091         kControllerState,
00092         kProgramData,
00093         kMetaInfo,
00094         kChunkList,
00095         kNumPresetChunks
00096 };
00097 
00098 //------------------------------------------------------------------------
00099 extern const ChunkID& getChunkID (ChunkType type);
00100 
00101 //------------------------------------------------------------------------
00102 inline bool isEqualID (const ChunkID id1, const ChunkID id2)
00103 {
00104         return memcmp (id1, id2, sizeof(ChunkID)) == 0;
00105 }
00106 
00107 //------------------------------------------------------------------------
00108 // PresetFile
00109 //------------------------------------------------------------------------
00110 class PresetFile
00111 {
00112 public:
00113 //------------------------------------------------------------------------
00114         PresetFile (IBStream* stream);
00115         virtual ~PresetFile ();
00116 
00117         struct Entry
00118         {
00119                 ChunkID id;
00120                 TSize offset;
00121                 TSize size;
00122         };
00123 
00124         IBStream* getStream () { return stream; }
00125 
00126         const FUID& getClassID () const { return classID; }
00127         void setClassID (const FUID& uid) { classID = uid; }
00128 
00129         const Entry* getEntry (ChunkType which) const;
00130         const Entry* getLastEntry () const;
00131         int32 getEntryCount () const { return entryCount; }
00132         const Entry& at (int32 index) const { return entries[index]; }
00133         bool contains (ChunkType which) const { return getEntry (which) != 0; }
00134 
00135         bool readChunkList ();
00136         bool writeHeader ();
00137         bool writeChunkList ();
00138 
00139         bool readMetaInfo (char* xmlBuffer, int32& size);
00140         bool writeMetaInfo (const char* xmlBuffer, int32 size = -1); // -1 means null-terminated
00141         bool prepareMetaInfoUpdate ();
00142 
00143         // use if data already exists (e.g. convert from other formats)
00144         bool writeChunk (const void* data, int32 size, ChunkType which = kComponentState); 
00145 
00146         bool storeComponentState (IComponent* component);
00147         bool restoreComponentState (IComponent* component);
00148         bool restoreComponentState (IEditController* editController);
00149 
00150         bool storeControllerState (IEditController* editController);
00151         bool restoreControllerState (IEditController* editController);
00152 
00153         bool storeProgramData (IBStream* stream, ProgramListID listID, int32 programIndex);
00154         bool storeProgramData (IUnitData* unitData, ProgramListID listID, int32 programIndex);
00155         bool restoreProgramData (IUnitData* unitData, ProgramListID* listID = 0, int32 programIndex = 0);
00156         bool restoreProgramData (IUnitInfo* unitInfo, ProgramListID listID, int32 programIndex);
00157 
00158 //------------------------------------------------------------------------
00159         // shortcut to create preset from component/controller state
00160         static bool savePreset (IBStream* stream, 
00161                                                         const FUID& classID, 
00162                                                         IComponent* component, 
00163                                                         IEditController* editController = 0,
00164                                                         const char* xmlBuffer = 0,
00165                                                         int32 xmlSize = -1);
00166 
00167         // shortcut to load preset with component/controller state
00168         static bool loadPreset (IBStream* stream, 
00169                                                         const FUID& classID, 
00170                                                         IComponent* component, 
00171                                                         IEditController* editController = 0);
00172 //------------------------------------------------------------------------
00173 protected:
00174         IBStream* stream;
00175         FUID classID;
00176         enum { kMaxEntries = 128 };
00177         Entry entries[kMaxEntries];
00178         int32 entryCount;
00179 
00180         bool readID (ChunkID id);
00181         bool writeID (const ChunkID id);
00182         bool readEqualID (const ChunkID id);
00183         bool readSize (TSize& size);
00184         bool writeSize (TSize size);
00185         bool readInt32 (int32& value);
00186         bool writeInt32 (int32 value);
00187         bool seekTo (TSize offset);
00188         bool beginChunk (Entry& e, ChunkType which);
00189         bool endChunk (Entry& e);
00190 };
00191 
00192 //------------------------------------------------------------------------
00193 // FileStream
00194 //------------------------------------------------------------------------
00196 class FileStream: public IBStream
00197 {
00198 public:
00199 //------------------------------------------------------------------------
00200         static IBStream* open (const char* filename, const char* mode);
00201 
00202         // FUnknown
00203         DECLARE_FUNKNOWN_METHODS
00204 
00205         // IBStream
00206         tresult PLUGIN_API read (void* buffer, int32 numBytes, int32* numBytesRead = 0);
00207         tresult PLUGIN_API write (void* buffer, int32 numBytes, int32* numBytesWritten = 0);
00208         tresult PLUGIN_API seek (int64 pos, int32 mode, int64* result = 0);
00209         tresult PLUGIN_API tell (int64* pos);
00210 //------------------------------------------------------------------------
00211 protected:
00212         FileStream (FILE* file);
00213         virtual ~FileStream ();
00214 
00215         FILE* file;
00216 };
00217 
00218 //------------------------------------------------------------------------
00219 }} // namespace Vst
00220 
00221 #endif  // __vstpresetfile__
Empty

Copyright ©2008 Steinberg Media Technologies. All Rights Reserved.