COCKOS
CONFEDERATED FORUMS
Cockos : REAPER : NINJAM : Forums
Forum Home : Register : FAQ : Members List : Search :
Old 02-08-2017, 04:41 PM   #1
Youlean
Human being with feelings
 
Youlean's Avatar
 
Join Date: May 2015
Location: Serbia
Posts: 419
Default VST3 using vectors in chunks

VST3 requires to have fixed buffers in chunks, but this code change will enable you to use vectors that you may dynamically resize. NOTE: This will break old save states as it is inserting chink size at chunk beginning.

IPlugVST3.cpp
Code:
tresult PLUGIN_API IPlugVST3::setEditorState(IBStream* state)
{
  TRACE;
  WDL_MutexLock lock(&mMutex);

  ByteChunk chunk;

  // Get the chunk size
  int chunkSize;
  state->read(&chunkSize, sizeof(int));

  if (chunkSize > 0)
  {

    // Resize IPlug ByteChunk to fit all new information
    chunk.Resize(chunkSize);

    state->read(chunk.GetBytes(), chunk.Size());
    UnserializeState(&chunk, 0);
    
    int32 savedBypass = 0;
    
    if (state->read (&savedBypass, sizeof (int32)) != kResultOk)
    {
      return kResultFalse;
    }
    
    mIsBypassed = (bool) savedBypass;
    
    RedrawParamControls();
    return kResultOk;
  }

  return kResultFalse;
}

tresult PLUGIN_API IPlugVST3::getEditorState(IBStream* state)
{
  TRACE;
  WDL_MutexLock lock(&mMutex);

  ByteChunk chunk;

  int chunkSize = 0;
  int64 stateStartPosition, stateEndPosition;
  
  // Get the position at the start
  state->tell(&stateStartPosition);

  // Leave room to write chunk size at the beginning. 
  // Write dummy chunk size that will be overwritten at the end.
  state->write(&chunkSize, sizeof(int));

  if (SerializeState(&chunk))
  {
    state->write(chunk.GetBytes(), chunk.Size());
  }
  else
  {
    return kResultFalse;
  }  

  // Get the position at the end
  state->tell(&stateEndPosition);

  // Move to beginning to write the chunk size
  state->seek(stateStartPosition, IBStream::IStreamSeekMode::kIBSeekSet);

  // Write chunk size at the beginning
  chunkSize = chunk.Size();
  state->write(&chunkSize, sizeof(int));

  // Return position to the end
  state->seek(stateEndPosition, IBStream::IStreamSeekMode::kIBSeekSet);
  
  int32 toSaveBypass = mIsBypassed ? 1 : 0;
  state->write(&toSaveBypass, sizeof (int32));  

  return kResultOk;
}

Last edited by Youlean; 02-08-2017 at 04:49 PM.
Youlean is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 01:40 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2017, vBulletin Solutions Inc.