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

Go Back   Cockos Incorporated Forums > Cockos and Friends Software Discussion > WDL users forum

Reply
 
Thread Tools Display Modes
Old 02-03-2017, 05:11 PM   #1
Youlean
Human being with feelings
 
Youlean's Avatar
 
Join Date: May 2015
Location: Serbia
Posts: 317
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
Old 02-03-2017, 05:50 PM   #2
Youlean
Human being with feelings
 
Youlean's Avatar
 
Join Date: May 2015
Location: Serbia
Posts: 317
Default

If you want to transition from an old to a new one, just call this from UnserializeState.

Code:
int IPlugBase::UnserializeParamsTransfer(ByteChunk* pChunk, int startPos, int oldNumberOfParameters)
{
	TRACE;

	WDL_MutexLock lock(&mMutex);
	int i, n = oldNumberOfParameters, pos = startPos;

	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;
}
Youlean is offline   Reply With Quote
Old 02-03-2017, 05:51 PM   #3
Youlean
Human being with feelings
 
Youlean's Avatar
 
Join Date: May 2015
Location: Serbia
Posts: 317
Default

This was tested in FL Studio with VST2 currently and it works great.
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 11:30 AM.


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