<commit_before>/* 
 * TTBlue Signal Crossfader Object
 * Copyright © 2008, <NAME>
 * 
 * License: This code is licensed under the terms of the GNU LGPL
 * http://www.gnu.org/licenses/lgpl.html 
 */

#include "TTCrossfade.h"
#define thisTTClass TTCrossfade

static bool zeroed = false;
static TTSampleValue zeroVector1[2048]; //TODO: make this dynamically sized
static TTSampleValue zeroVector2[2048]; //TODO: make this dynamically sized
static TTSampleValue zeroVector3[2048]; //TODO: make this dynamically sized


TTCrossfade::TTCrossfade(TTUInt16 newMaxNumChannels)
	: TTAudioObject("audio.crossfade", newMaxNumChannels)
{
	registerAttributeSimple(position,	kTypeFloat64);
	registerAttributeWithSetter(shape,	kTypeSymbol);
	registerAttributeWithSetter(mode,	kTypeSymbol);

	if(!zeroed){
		memset(zeroVector1, 0, sizeof(TTSampleValue) * 2048);
		memset(zeroVector2, 0, sizeof(TTSampleValue) * 2048);
		memset(zeroVector3, 0, sizeof(TTSampleValue) * 2048);
	}
	
	// Set Defaults (the attribute setters will set the process method for us)...
	setAttributeValue(TT("position"),	0.5);
	setAttributeValue(TT("shape"),		TT("equalPower"));
	setAttributeValue(TT("mode"),		TT("lookup"));
}


TTCrossfade::~TTCrossfade()
{
	;
}


TTErr TTCrossfade::setshape(const TTValue& newValue)
{
	shape = newValue;
	return setProcessPointers();
}


TTErr TTCrossfade::setmode(const TTValue& newValue)
{
	mode = newValue;
	return setProcessPointers();
}


TTErr TTCrossfade::setProcessPointers()
{
	TTErr	err =kTTErrNone;
	
	if(shape == TT("equalPower") && mode == TT("lookup")){
		err |= setProcessWithSidechain((TTProcessWithSidechainMethod)&TTCrossfade::processLookupUsingSidechain);
		err |= setProcess((TTProcessMethod)&TTCrossfade::processLookup);
	}
	else if(shape == TT("equalPower") && mode == TT("calculate")){
		err |= setProcessWithSidechain((TTProcessWithSidechainMethod)&TTCrossfade::processCalcUsingSidechain);
		err |= setProcess((TTProcessMethod)&TTCrossfade::processCalc);
	}
	else{
		err |= setProcessWithSidechain((TTProcessWithSidechainMethod)&TTCrossfade::processLinearUsingSidechain);
		err |= setProcess((TTProcessMethod)&TTCrossfade::processLinear);
	}
	return err;
}


#if 0
#pragma mark -
#pragma mark Interleaved Process Methods<commit_msg>Fixed build due to change in the TTErr type.<commit_after>/* 
 * TTBlue Signal Crossfader Object
 * Copyright © 2008, <NAME>
 * 
 * License: This code is licensed under the terms of the GNU LGPL
 * http://www.gnu.org/licenses/lgpl.html 
 */

#include "TTCrossfade.h"
#define thisTTClass TTCrossfade

static bool zeroed = false;
static TTSampleValue zeroVector1[2048]; //TODO: make this dynamically sized
static TTSampleValue zeroVector2[2048]; //TODO: make this dynamically sized
static TTSampleValue zeroVector3[2048]; //TODO: make this dynamically sized


TTCrossfade::TTCrossfade(TTUInt16 newMaxNumChannels)
	: TTAudioObject("audio.crossfade", newMaxNumChannels)
{
	registerAttributeSimple(position,	kTypeFloat64);
	registerAttributeWithSetter(shape,	kTypeSymbol);
	registerAttributeWithSetter(mode,	kTypeSymbol);

	if(!zeroed){
		memset(zeroVector1, 0, sizeof(TTSampleValue) * 2048);
		memset(zeroVector2, 0, sizeof(TTSampleValue) * 2048);
		memset(zeroVector3, 0, sizeof(TTSampleValue) * 2048);
	}
	
	// Set Defaults (the attribute setters will set the process method for us)...
	setAttributeValue(TT("position"),	0.5);
	setAttributeValue(TT("shape"),		TT("equalPower"));
	setAttributeValue(TT("mode"),		TT("lookup"));
}


TTCrossfade::~TTCrossfade()
{
	;
}


TTErr TTCrossfade::setshape(const TTValue& newValue)
{
	shape = newValue;
	return setProcessPointers();
}


TTErr TTCrossfade::setmode(const TTValue& newValue)
{
	mode = newValue;
	return setProcessPointers();
}


TTErr TTCrossfade::setProcessPointers()
{
	TTErr	err = kTTErrNone;
	
	if(shape == TT("equalPower") && mode == TT("lookup")){
		err = setProcessWithSidechain((TTProcessWithSidechainMethod)&TTCrossfade::processLookupUsingSidechain);
		err = setProcess((TTProcessMethod)&TTCrossfade::processLookup);
	}
	else if(shape == TT("equalPower") && mode == TT("calculate")){
		err = setProcessWithSidechain((TTProcessWithSidechainMethod)&TTCrossfade::processCalcUsingSidechain);
		err = setProcess((TTProcessMethod)&TTCrossfade::processCalc);
	}
	else{
		err = setProcessWithSidechain((TTProcessWithSidechainMethod)&TTCrossfade::processLinearUsingSidechain);
		err = setProcess((TTProcessMethod)&TTCrossfade::processLinear);
	}
	return err;
}


#if 0
#pragma mark -
#pragma mark Interleaved Process Methods
{'fraction_non_alphanumeric': 0.12582927908005306, 'fraction_numerical': 0.019460415745245468, 'mean_word_length': 6.731623931623932, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4484915', 'n_tokens_mistral': 1631, 'n_tokens_neox': 1447, 'n_words': 309}