iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
IPlugVST3_Common.h
1/*
2 ==============================================================================
3
4 This file is part of the iPlug 2 library. Copyright (C) the iPlug 2 developers.
5
6 See LICENSE.txt for more info.
7
8 ==============================================================================
9*/
10
11#pragma once
12
13#include "pluginterfaces/base/ibstream.h"
14#
15#include "IPlugAPIBase.h"
16#include "IPlugVST3_Parameter.h"
17#include "IPlugVST3_ControllerBase.h"
18
19BEGIN_IPLUG_NAMESPACE
20
23{
24 template <class T>
25 static bool GetState(T* pPlug, Steinberg::IBStream* pState)
26 {
27 IByteChunk chunk;
28
29 // TODO: IPlugVer should be in chunk!
30 // IByteChunk::GetIPlugVerFromChunk(chunk)
31
32 if (pPlug->SerializeState(chunk))
33 {
34 /*
35 int chunkSize = chunk.Size();
36 void* data = (void*) &chunkSize;
37 state->write(data, (Steinberg::int32) sizeof(int));*/
38 pState->write(chunk.GetData(), chunk.Size());
39 }
40 else
41 return false;
42
43 Steinberg::int32 toSaveBypass = pPlug->GetBypassed() ? 1 : 0;
44 pState->write(&toSaveBypass, sizeof (Steinberg::int32));
45
46 return true;
47 };
48
49 template <class T>
50 static bool SetState(T* pPlug, Steinberg::IBStream* pState)
51 {
52 TRACE
53
54 IByteChunk chunk;
55
56 const int bytesPerBlock = 128;
57 char buffer[bytesPerBlock];
58
59 while(true)
60 {
61 Steinberg::int32 bytesRead = 0;
62 auto status = pState->read(buffer, (Steinberg::int32) bytesPerBlock, &bytesRead);
63
64 if (bytesRead <= 0 || (status != Steinberg::kResultTrue && pPlug->GetHost() != kHostWaveLab))
65 break;
66
67 chunk.PutBytes(buffer, bytesRead);
68 }
69 int pos = pPlug->UnserializeState(chunk,0);
70
71 Steinberg::int32 savedBypass = 0;
72
73 pState->seek(pos,Steinberg::IBStream::IStreamSeekMode::kIBSeekSet);
74 if (pState->read (&savedBypass, sizeof (Steinberg::int32)) != Steinberg::kResultOk) {
75 return false;
76 }
77
78 IPlugVST3ControllerBase* pController = dynamic_cast<IPlugVST3ControllerBase*>(pPlug);
79
80 if (pController)
81 pController->UpdateParams(pPlug, savedBypass);
82
83 pPlug->OnRestoreState();
84
85 return true;
86 }
87};
88
89// Host
90static void IPlugVST3GetHost(IPlugAPIBase* pPlug, Steinberg::FUnknown* context)
91{
92 Steinberg::Vst::String128 tmpStringBuf;
93 char hostNameCString[128];
94 Steinberg::FUnknownPtr<Steinberg::Vst::IHostApplication>pApp(context);
95
96 if ((pPlug->GetHost() == kHostUninit) && pApp)
97 {
98 pApp->getName(tmpStringBuf);
99 Steinberg::UString(tmpStringBuf, 128).toAscii(hostNameCString, 128);
100 pPlug->SetHost(hostNameCString, 0); // Can't get version in VST3
101 }
102}
103
104END_IPLUG_NAMESPACE
Manages a block of memory, for plug-in settings store/recall.
Definition: IPlugStructs.h:112
int PutBytes(const void *pSrc, int nBytesToCopy)
Copies data into the chunk, placing it at the end, resizing if necessary.
Definition: IPlugStructs.h:147
uint8_t * GetData()
Gets a ptr to the chunk data.
Definition: IPlugStructs.h:242
int Size() const
Returns the current size of the chunk.
Definition: IPlugStructs.h:221
The base class of an IPlug plug-in, which interacts with the different plug-in APIs.
Definition: IPlugAPIBase.h:43
void SetHost(const char *host, int version)
Called to set the name of the current host, if known (calls on to HostSpecificInit() and OnHostIdenti...
Shared VST3 controller code.
EHost GetHost() const
Shared VST3 State management code.