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

#include "TTWavetable.h"

#define thisTTClass			TTWavetable
#define thisTTClassName		"wavetable"
#define thisTTClassTags		"audio, generator, oscillator, buffer"


TT_AUDIO_CONSTRUCTOR,
	index(0.0),
	indexDelta(0.0)
{
	TTUInt16	initialMaxNumChannels = arguments;

	registerAttribute(TT("frequency"),		kTypeFloat64,	&attrFrequency,		(TTSetterMethod)&TTWavetable::setFrequency);
	registerAttribute(TT("mode"),			kTypeSymbol,	&attrMode,			(TTSetterMethod)&TTWavetable::setMode);
	registerAttribute(TT("gain"),			kTypeFloat64,	&attrGain,			(TTSetterMethod)&TTWavetable::setGain);
	registerAttribute(TT("interpolation"),	kTypeSymbol,	&attrInterpolation,	(TTSetterMethod)&TTWavetable::setInterpolation);
	registerAttribute(TT("size"),			kTypeInt64,		&attrSize,			(TTSetterMethod)&TTWavetable::setSize);

	registerMessageSimple(updateSr);

//	wavetable = new TTBuffer(*kTTValNONE);
	TTObjectInstantiate(TT("buffer"), (TTObjectPtr*)&wavetable, *kTTValNONE);
	if(!wavetable)
		throw TTException("Could not create internal buffer object");
	wavetable->setnumChannels(TTUInt32(1));

	// Set Defaults...
	setAttributeValue(TT("maxNumChannels"),	initialMaxNumChannels);
	setAttributeValue(TT("size"), TTUInt32(4096));
	setAttributeValue(TT("mode"), kTTSym_sine);
	setAttributeValue(TT("frequency"), 440.0);
	setAttributeValue(TT("gain"), 0.0);			// 0 dB
	setAttributeValue(TT("interpolation"), TT("linear"));
}


TTWavetable::~TTWavetable()
{
	TTObjectRelease((TTObject**)&wavetable);
}


TTErr TTWavetable::updateSr()
{
	setAttributeValue(TT("frequency"), attrFrequency);
	return kTTErrNone;
}


TTErr TTWavetable::setFrequency(const TTValue& newValue)
{
	TTValue	v;

	attrFrequency = TTClip<TTFloat64>(newValue, 0.0, sr/2.0);
	wavetable->getAttributeValue(TT("lengthInSamples"), v);
	indexDelta = attrFrequency * TTFloat64(v) / sr;
	return kTTErrNone;
}

<commit_msg>reverting last change, as it is no longer required now that the Foundation accessor ambiguity issue is resolved.<commit_after>/*
 * TTBlue Wavetable Oscillator
 * Copyright © 2003, <NAME>
 *
 * License: This code is licensed under the terms of the GNU LGPL
 * http://www.gnu.org/licenses/lgpl.html
 */

#include "TTWavetable.h"

#define thisTTClass			TTWavetable
#define thisTTClassName		"wavetable"
#define thisTTClassTags		"audio, generator, oscillator, buffer"


TT_AUDIO_CONSTRUCTOR,
	index(0.0),
	indexDelta(0.0)
{
	TTUInt16	initialMaxNumChannels = arguments;

	registerAttribute(TT("frequency"),		kTypeFloat64,	&attrFrequency,		(TTSetterMethod)&TTWavetable::setFrequency);
	registerAttribute(TT("mode"),			kTypeSymbol,	&attrMode,			(TTSetterMethod)&TTWavetable::setMode);
	registerAttribute(TT("gain"),			kTypeFloat64,	&attrGain,			(TTSetterMethod)&TTWavetable::setGain);
	registerAttribute(TT("interpolation"),	kTypeSymbol,	&attrInterpolation,	(TTSetterMethod)&TTWavetable::setInterpolation);
	registerAttribute(TT("size"),			kTypeInt64,		&attrSize,			(TTSetterMethod)&TTWavetable::setSize);

	registerMessageSimple(updateSr);

//	wavetable = new TTBuffer(*kTTValNONE);
	TTObjectInstantiate(TT("buffer"), (TTObjectPtr*)&wavetable, *kTTValNONE);
	if(!wavetable)
		throw TTException("Could not create internal buffer object");
	wavetable->setnumChannels(TTUInt32(1));

	// Set Defaults...
	setAttributeValue(TT("maxNumChannels"),	initialMaxNumChannels);
	setAttributeValue(TT("size"), 4096);
	setAttributeValue(TT("mode"), kTTSym_sine);
	setAttributeValue(TT("frequency"), 440.0);
	setAttributeValue(TT("gain"), 0.0);			// 0 dB
	setAttributeValue(TT("interpolation"), TT("linear"));
}


TTWavetable::~TTWavetable()
{
	TTObjectRelease((TTObject**)&wavetable);
}


TTErr TTWavetable::updateSr()
{
	setAttributeValue(TT("frequency"), attrFrequency);
	return kTTErrNone;
}


TTErr TTWavetable::setFrequency(const TTValue& newValue)
{
	TTValue	v;

	attrFrequency = TTClip<TTFloat64>(newValue, 0.0, sr/2.0);
	wavetable->getAttributeValue(TT("lengthInSamples"), v);
	indexDelta = attrFrequency * TTFloat64(v) / sr;
	return kTTErrNone;
}


{'fraction_non_alphanumeric': 0.14295959837437247, 'fraction_numerical': 0.018646904135787713, 'mean_word_length': 7.285148514851485, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '4537106', 'n_tokens_mistral': 1606, 'n_tokens_neox': 1459, 'n_words': 255}