<commit_before>/* 
 * Jamoma RampLib Base Class
 * Copyright © 2008, <NAME>
 * 
 * License: This code is licensed under the terms of the GNU LGPL
 * http://www.gnu.org/licenses/lgpl.html 
 */

#ifdef WIN_VERSION
 #pragma warning(disable:4083) //warning C4083: expected 'newline'; found identifier 's'
#endif // WIN_VERSION

#include "RampLib.h"
#include "ext.h"

RampUnit::RampUnit(const char* rampName, RampUnitCallback aCallbackMethod, void *aBaton)
	: TTObject(rampName), startValue(NULL), targetValue(NULL), currentValue(NULL), normalizedValue(0.0), numValues(0), functionUnit(NULL)
{
	callback = aCallbackMethod;
	baton = aBaton;
	setNumValues(1);
	currentValue[0] = 0.0;
	targetValue[0] = 0.0;
	startValue[0] = 0.0;

	registerAttribute(TT("function"),	kTypeSymbol,	&attrFunction,	(TTSetterMethod)&RampUnit::setFunction);
	setAttributeValue(TT("function"), TT("linear"));
}


RampUnit::~RampUnit()
{
	delete functionUnit;
	delete [] currentValue;
	delete [] targetValue;
	delete [] startValue;
}


void RampUnit::set(TTUInt32 newNumValues, TTFloat64 *newValues)
{
	TTUInt32 i;
	
	stop();
	setNumValues(newNumValues);
	for(i=0; i<newNumValues; i++)
		currentValue[i] = newValues[i];
}


TTErr RampUnit::setFunction(const TTValue& functionName)
{
	TTErr	err;
	
	attrFunction = functionName;
	if(attrFunction == TT("none"))
		attrFunction = TT("linear");
	
	err = FunctionLib::createUnit(attrFunction, &functionUnit);
	if(err)
		logError("Jamoma ramp unit failed to load the requested FunctionUnit from TTBlue.");
	return err;
}


TTErr RampUnit::getFunctionParameterNames(TTSymbol* parameterName, TTValue& names)
{
	functionUnit->getAttributeNames(names);
	return kTTErrNone;
}


TTErr RampUnit::setFunctionParameterValue(TTSymbol* parameterName, const TTValue& newValue)
{
	functionUnit->setAttributeValue(parameterName, newValue);
	return kTTErrNone;
}


TTErr RampUnit::getFunctionParameterValue(TTSymbol* parameterName, TTValue& value)<commit_msg>RampLib: no longer loads a new function when the new function requested is the same as the old one.<commit_after>/* 
 * Jamoma RampLib Base Class
 * Copyright © 2008, <NAME>
 * 
 * License: This code is licensed under the terms of the GNU LGPL
 * http://www.gnu.org/licenses/lgpl.html 
 */

#ifdef WIN_VERSION
 #pragma warning(disable:4083) //warning C4083: expected 'newline'; found identifier 's'
#endif // WIN_VERSION

#include "RampLib.h"
#include "ext.h"

RampUnit::RampUnit(const char* rampName, RampUnitCallback aCallbackMethod, void *aBaton)
	: TTObject(rampName), startValue(NULL), targetValue(NULL), currentValue(NULL), normalizedValue(0.0), numValues(0), functionUnit(NULL)
{
	callback = aCallbackMethod;
	baton = aBaton;
	setNumValues(1);
	currentValue[0] = 0.0;
	targetValue[0] = 0.0;
	startValue[0] = 0.0;

	registerAttribute(TT("function"),	kTypeSymbol,	&attrFunction,	(TTSetterMethod)&RampUnit::setFunction);
	setAttributeValue(TT("function"), TT("linear"));
}


RampUnit::~RampUnit()
{
	TTObjectRelease(&functionUnit);
	delete [] currentValue;
	delete [] targetValue;
	delete [] startValue;
}


void RampUnit::set(TTUInt32 newNumValues, TTFloat64 *newValues)
{
	TTUInt32 i;
	
	stop();
	setNumValues(newNumValues);
	for(i=0; i<newNumValues; i++)
		currentValue[i] = newValues[i];
}


TTErr RampUnit::setFunction(const TTValue& functionName)
{
	TTErr		err;
	TTSymbolPtr	newFunctionName = NULL;
	
	functionName.get(0, &newFunctionName);
	
	if(newFunctionName == TT("none"))
		newFunctionName = TT("linear");
	
	if(newFunctionName == attrFunction)
		return kTTErrNone;
	
	attrFunction = newFunctionName;
	err = FunctionLib::createUnit(attrFunction, &functionUnit);
	if(err)
		logError("Jamoma ramp unit failed to load the requested FunctionUnit from TTBlue.");
	return err;
}


TTErr RampUnit::getFunctionParameterNames(TTSymbol* parameterName, TTValue& names)
{
	functionUnit->getAttributeNames(names);
	return kTTErrNone;
}


TTErr RampUnit::setFunctionParameterValue(TTSymbol* parameterName, const TTValue& newValue)
{
	functionUnit->setAttributeValue(parameterName, newValue);
	return kTTErrNone;
}


TTErr RampUnit::getFunctionParameterValue(TTSymbol* parameterName, TTValue& value)
{'fraction_non_alphanumeric': 0.12758786711603273, 'fraction_numerical': 0.015647568608570053, 'mean_word_length': 6.302284710017575, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6188346', 'n_tokens_mistral': 1474, 'n_tokens_neox': 1380, 'n_words': 315}