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

#include "TTMatrixMixer.h"
#ifdef TT_PLATFORM_WIN
#include <algorithm>
#endif

#define thisTTClass			TTMatrixMixer
#define thisTTClassName		"matrixmixer"
#define thisTTClassTags		"audio, mixing, matrix"


TT_AUDIO_CONSTRUCTOR,
	mNumInputs(0),
	mNumOutputs(0)
{
	addAttribute(NumInputs, kTypeUInt16);	// TODO: set readonly property for this attribute
	addAttribute(NumOutputs, kTypeUInt16);	// TODO: set readonly property for this attribute
	
	addMessageWithArgument(SetGain);
	addMessageWithArgument(SetLinearGain);
	addMessageWithArgument(SetMidiGain);
	//registerMessageWithArgument(updateMaxNumChannels);
	addMessage(Clear);

	//setAttributeValue(TT("MaxNumChannels"), newMaxNumChannels);
	setProcessMethod(processAudio);
}


TTMatrixMixer::~TTMatrixMixer()
{
	;
}


// conceptually:
//	columns == inputs
//	rows == outputs


TTErr TTMatrixMixer::setNumInputs(const TTUInt16 newValue)
{
	if (newValue != mNumInputs) {
		mNumInputs = newValue;
		mGainMatrix.resize(mNumInputs);
		for_each(mGainMatrix.begin(), mGainMatrix.end(), bind2nd(mem_fun_ref(&TTSampleMatrix::value_type::resize), mNumOutputs));
	}
	return kTTErrNone;
}


TTErr TTMatrixMixer::setNumOutputs(const TTUInt16 newValue)
{
	if (newValue != mNumOutputs) {
		mNumOutputs = newValue;
		for_each(mGainMatrix.begin(), mGainMatrix.end(), bind2nd(mem_fun_ref(&TTSampleMatrix::value_type::resize), mNumOutputs));
	}
	return kTTErrNone;
}


TTErr TTMatrixMixer::Clear()
{
	for (TTSampleMatrixIter column = mGainMatrix.begin(); column != mGainMatrix.end(); column++)
		column->assign(mNumOutputs, 0.0);
	return kTTErrNone;
}


TTErr TTMatrixMixer::SetGain(const TTValue& newValue)
{
	TTUInt16	x;
	TTUInt16	y;
	TTFloat64	gainValue;
	
	if (newValue.getSize() != 3)
		return kTTErrWrongNumValues;
	
	newValue.get(0, x);
	newValue.get(1, y);
	newValue.get(2, gainValue);
	mGainMatrix[x][y] = dbToLinear(gainValue);
	return kTTErrNone;
}


TTErr TTMatrixMixer::SetLinearGain(const TTValue& newValue)
{
	TTUInt16	x;
	TTUInt16	y;
	TTFloat64	gainValue;
	
	if (newValue.getSize() != 3)
		return kTTErrWrongNumValues;
	
	newValue.get(0, x);
	newValue.get(1, y);
	newValue.get(2, gainValue);
	mGainMatrix[x][y] = gainValue;
	return kTTErrNone;
}


TTErr TTMatrixMixer::SetMidiGain(const TTValue& newValue)
{<commit_msg>MatrixMixer: adding TODO comments<commit_after>/* 
 * TTMatrixMixer Object
 * Copyright © 2009, <NAME>
 * 
 * License: This code is licensed under the terms of the GNU LGPL
 * http://www.gnu.org/licenses/lgpl.html 
 */

#include "TTMatrixMixer.h"
#ifdef TT_PLATFORM_WIN
#include <algorithm>
#endif

#define thisTTClass			TTMatrixMixer
#define thisTTClassName		"matrixmixer"
#define thisTTClassTags		"audio, mixing, matrix"


TT_AUDIO_CONSTRUCTOR,
	mNumInputs(0),
	mNumOutputs(0)
{
	addAttribute(NumInputs, kTypeUInt16);	// TODO: set readonly property for this attribute
	addAttribute(NumOutputs, kTypeUInt16);	// TODO: set readonly property for this attribute
	
	addMessageWithArgument(SetGain);
	addMessageWithArgument(SetLinearGain);
	addMessageWithArgument(SetMidiGain);
	//registerMessageWithArgument(updateMaxNumChannels);
	addMessage(Clear);

	//setAttributeValue(TT("MaxNumChannels"), newMaxNumChannels);
	setProcessMethod(processAudio);
}


TTMatrixMixer::~TTMatrixMixer()
{
	;
}


// conceptually:
//	columns == inputs
//	rows == outputs


// TODO: the next two methods should never decrease their size

TTErr TTMatrixMixer::setNumInputs(const TTUInt16 newValue)
{
	if (newValue != mNumInputs) {
		mNumInputs = newValue;
		mGainMatrix.resize(mNumInputs);
		for_each(mGainMatrix.begin(), mGainMatrix.end(), bind2nd(mem_fun_ref(&TTSampleMatrix::value_type::resize), mNumOutputs));
	}
	return kTTErrNone;
}


TTErr TTMatrixMixer::setNumOutputs(const TTUInt16 newValue)
{
	if (newValue != mNumOutputs) {
		mNumOutputs = newValue;
		for_each(mGainMatrix.begin(), mGainMatrix.end(), bind2nd(mem_fun_ref(&TTSampleMatrix::value_type::resize), mNumOutputs));
	}
	return kTTErrNone;
}


TTErr TTMatrixMixer::Clear()
{
	for (TTSampleMatrixIter column = mGainMatrix.begin(); column != mGainMatrix.end(); column++)
		column->assign(mNumOutputs, 0.0);
	return kTTErrNone;
}


TTErr TTMatrixMixer::SetGain(const TTValue& newValue)
{
	TTUInt16	x;
	TTUInt16	y;
	TTFloat64	gainValue;
	
	if (newValue.getSize() != 3)
		return kTTErrWrongNumValues;
	
	newValue.get(0, x);
	newValue.get(1, y);
	newValue.get(2, gainValue);
	mGainMatrix[x][y] = dbToLinear(gainValue);
	return kTTErrNone;
}


TTErr TTMatrixMixer::SetLinearGain(const TTValue& newValue)
{
	TTUInt16	x;
	TTUInt16	y;
	TTFloat64	gainValue;
	
	if (newValue.getSize() != 3)
		return kTTErrWrongNumValues;
	
	// FIXME: check bounds and increase matrix size if needed!!!
	
	newValue.get(0, x);
	newValue.get(1, y);
	newValue.get(2, gainValue);
	mGainMatrix[x][y] = gainValue;
	return kTTErrNone;
}


TTErr TTMatrixMixer::SetMidiGain(const TTValue& newValue)
{
{'fraction_non_alphanumeric': 0.1233201581027668, 'fraction_numerical': 0.015019762845849802, 'mean_word_length': 5.867028493894166, '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': '7139557', 'n_tokens_mistral': 1981, 'n_tokens_neox': 1867, 'n_words': 364}