COCKOS
CONFEDERATED FORUMS
Cockos : REAPER : NINJAM : Forums
Forum Home : Register : FAQ : Members List : Search :

Go Back   Cockos Incorporated Forums > Other Software Discussion > WDL users forum

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 02-03-2017, 05:11 PM   #1
Youlean
Human being with feelings
 
Youlean's Avatar
 
Join Date: May 2015
Location: Serbia
Posts: 654
Default Adding new parameters in new plugin versions - Example

Here is simple code change that will allow you to add new parameters in the future versions of the plugin without braking the plugin. You can also remove parameters. NOTE: If you want to add new parameter you need to put it to the end of enum.
Also this is not well tested, so test it before use.

IPlugBase.cpp
Code:
bool IPlugBase::SerializeParams(ByteChunk* pChunk)
{
  TRACE;

  WDL_MutexLock lock(&mMutex);
  bool savedOK = true;
  int i, n = mParams.GetSize();

  // Save number of parameters. Do this so you can add parameters in the future versions without braking the plugin. 
  // NOTE: Add new parameters at the end.
  pChunk->Put(&n);

  for (i = 0; i < n && savedOK; ++i)
  {
    IParam* pParam = mParams.Get(i);
    Trace(TRACELOC, "%d %s %f", i, pParam->GetNameForHost(), pParam->Value());
    double v = pParam->Value();
    savedOK &= (pChunk->Put(&v) > 0);
  }

  return savedOK;
}

int IPlugBase::UnserializeParams(ByteChunk* pChunk, int startPos)
{
  TRACE;

  WDL_MutexLock lock(&mMutex);
  int i, n = mParams.GetSize(), pos = startPos;

  // Use last saved parameter number.
  pos = pChunk->Get(&n, pos);
  n = IPMIN(n, mParams.GetSize());

  for (int i = 0; i < n && pos >= 0; ++i)
  {
    IParam* pParam = mParams.Get(i);
    double v = 0.0;
    Trace(TRACELOC, "%d %s %f", i, pParam->GetNameForHost(), pParam->Value());
    pos = pChunk->Get(&v, pos);
    pParam->Set(v);
  }

  OnParamReset();
  return pos;
}

Last edited by Youlean; 02-03-2017 at 05:53 PM.
Youlean is offline   Reply With Quote
 

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 06:23 PM.


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