<commit_before>/** @file
 *
 * @ingroup dspGeneratorLib
 *
 * @brief GeneratorLib: Generate a basic, cycling waveform using a wavetable.
 *
 * @details Wavetable is currently limited to using an internal buffer for managing its waveshape.  Shape options include sine, triangle and sawtooth.
 *
 * @see TTBuffer, TTSampleMatrix, TTMatrix, TTAudioSignal
 *
 * @authors <NAME>, <NAME>
 *
 * @copyright Copyright © 2003-2013 by <NAME> & <NAME> @n
 * This code is licensed under the terms of the "New BSD License" @n
 * http://creativecommons.org/licenses/BSD/
 */

#include "TTWavetable.h"

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


TT_AUDIO_CONSTRUCTOR,
	mIndex(0.0),
	mIndexDelta(0.0),
	mInternalBuffer(1,1),
	mWavetable(NULL)
{
	TTUInt16	initialMaxNumChannels = arguments;

	addAttributeWithSetter(Frequency,		kTypeFloat64);
	addAttributeWithSetter(Mode,			kTypeSymbol);
	addAttributeWithSetter(Gain,			kTypeFloat64);
	addAttributeWithSetter(Interpolation,	kTypeSymbol);
	addAttributeWithSetter(Size,			kTypeUInt32);

	addUpdates(SampleRate);

	// Set Defaults...
	setAttributeValue("maxNumChannels",	initialMaxNumChannels);
	setAttributeValue("size", 8192);
	setAttributeValue("mode", kTTSym_sine);
	setAttributeValue("frequency", 440.0);
	setAttributeValue("gain", 0.0);			// 0 dB
	setAttributeValue("interpolation", "linear");
    
    // Checkout the current SampleMatrix as wavetable...
    mInternalBuffer.checkOutMatrix(mWavetable);
}


TTWavetable::~TTWavetable()
{
}


TTErr TTWavetable::updateSampleRate(const TTValue&, TTValue&)
{
	setAttributeValue("frequency", mFrequency);
	return kTTErrNone;
}


TTErr TTWavetable::setFrequency(const TTValue& newValue)
{
	mFrequency = TTClip<TTFloat64>(newValue, 0.0, sr/2.0);
	mIndexDelta = mFrequency * mSize * srInv;	
	return kTTErrNone;
}


TTErr TTWavetable::setMode(const TTValue& newValue)
{
    // TODO: implement the ability to use an externally defined buffer
    // would support via mMode == TT("externalBuffer")
    
	mMode = newValue[0];
    //TTValue aReturnWeDontCareAbout;
    
	if (mMode != TT("filePath")) {
        
        // use fill() to draw the appropriate waveform
        return mInternalBuffer.fill(newValue);
    
    } else {
		
        if (newValue.size() > 1) {
            
            // use resizeThenLoad() to import a soundfile
            TTValue soundFilePath = newValue[1];
            return mInternalBuffer.resizeThenLoad(soundFilePath);
            
        } else {
            return kTTErrWrongNumValues;
        }
	}
}


TTErr TTWavetable::setInterpolation(const TTValue& newValue)
{
	mMode = newValue;
	if (mMode == "linear")
		setProcessMethod(processWithLinearInterpolation);
	else if (mMode == "lfo")
		setProcessMethod(processAsLFO);
	else
		setProcessMethod(processWithNoInterpolation);
	return kTTErrNone;
}<commit_msg>TTwavetable: changing mMode that should be mInterpolation<commit_after>/** @file
 *
 * @ingroup dspGeneratorLib
 *
 * @brief GeneratorLib: Generate a basic, cycling waveform using a wavetable.
 *
 * @details Wavetable is currently limited to using an internal buffer for managing its waveshape.  Shape options include sine, triangle and sawtooth.
 *
 * @see TTBuffer, TTSampleMatrix, TTMatrix, TTAudioSignal
 *
 * @authors <NAME>, <NAME>
 *
 * @copyright Copyright © 2003-2013 by <NAME> & <NAME> @n
 * This code is licensed under the terms of the "New BSD License" @n
 * http://creativecommons.org/licenses/BSD/
 */

#include "TTWavetable.h"

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


TT_AUDIO_CONSTRUCTOR,
	mIndex(0.0),
	mIndexDelta(0.0),
	mInternalBuffer(1,1),
	mWavetable(NULL)
{
	TTUInt16	initialMaxNumChannels = arguments;

	addAttributeWithSetter(Frequency,		kTypeFloat64);
	addAttributeWithSetter(Mode,			kTypeSymbol);
	addAttributeWithSetter(Gain,			kTypeFloat64);
	addAttributeWithSetter(Interpolation,	kTypeSymbol);
	addAttributeWithSetter(Size,			kTypeUInt32);

	addUpdates(SampleRate);

	// Set Defaults...
	setAttributeValue("maxNumChannels",	initialMaxNumChannels);
	setAttributeValue("size", 8192);
	setAttributeValue("mode", kTTSym_sine);
	setAttributeValue("frequency", 440.0);
	setAttributeValue("gain", 0.0);			// 0 dB
	setAttributeValue("interpolation", "linear");
    
    // Checkout the current SampleMatrix as wavetable...
    mInternalBuffer.checkOutMatrix(mWavetable);
}


TTWavetable::~TTWavetable()
{
}


TTErr TTWavetable::updateSampleRate(const TTValue&, TTValue&)
{
	setAttributeValue("frequency", mFrequency);
	return kTTErrNone;
}


TTErr TTWavetable::setFrequency(const TTValue& newValue)
{
	mFrequency = TTClip<TTFloat64>(newValue, 0.0, sr/2.0);
	mIndexDelta = mFrequency * mSize * srInv;	
	return kTTErrNone;
}


TTErr TTWavetable::setMode(const TTValue& newValue)
{
    // TODO: implement the ability to use an externally defined buffer
    // would support via mMode == TT("externalBuffer")
    
	mMode = newValue[0];
    //TTValue aReturnWeDontCareAbout;
    
	if (mMode != TT("filePath")) {
        
        // use fill() to draw the appropriate waveform
        return mInternalBuffer.fill(newValue);
    
    } else {
		
        if (newValue.size() > 1) {
            
            // use resizeThenLoad() to import a soundfile
            TTValue soundFilePath = newValue[1];
            return mInternalBuffer.resizeThenLoad(soundFilePath);
            
        } else {
            return kTTErrWrongNumValues;
        }
	}
}


TTErr TTWavetable::setInterpolation(const TTValue& newValue)
{
	mInterpolation = newValue;
	if (mInterpolation == "linear")
		setProcessMethod(processWithLinearInterpolation);
	else if (mInterpolation == "lfo")
		setProcessMethod(processAsLFO);
	else
		setProcessMethod(processWithNoInterpolation);
	return kTTErrNone;
}
{'fraction_non_alphanumeric': 0.1076301162203133, 'fraction_numerical': 0.01414855987872663, 'mean_word_length': 4.158992180712424, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2488760', 'n_tokens_mistral': 2078, 'n_tokens_neox': 1917, 'n_words': 440}