Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tundo.h"
Toshihiro Shimizu 890ddd
#include "tconvert.h"
Toshihiro Shimizu 890ddd
#include "tstream.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzBase includes
Toshihiro Shimizu 890ddd
#include "tdoubleparam.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// STD includes
Toshihiro Shimizu 890ddd
#include <set></set>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tspectrumparam.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
typedef pair<tdoubleparamp, tpixelparamp=""> ColorKeyParam;</tdoubleparamp,>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=========================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TSpectrumParamImp
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TSpectrumParam *m_sp;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::vector<colorkeyparam> m_keys;</colorkeyparam>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	bool m_draggingEnabled;
Toshihiro Shimizu 890ddd
	bool m_notificationEnabled;
Toshihiro Shimizu 890ddd
	bool m_isMatteEnabled;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::set<tparamobserver *=""> m_observers;</tparamobserver>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TSpectrumParamImp(TSpectrumParam *sp) : m_sp(sp), m_keys(), m_draggingEnabled(false), m_notificationEnabled(true), m_isMatteEnabled(true)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TSpectrumParamImp(const TSpectrumParamImp &s)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		copy(s);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void copy(const TSpectrumParamImp &src)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_keys.clear();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		std::vector<colorkeyparam>::const_iterator it = src.m_keys.begin();</colorkeyparam>
Toshihiro Shimizu 890ddd
		for (; it != src.m_keys.end(); ++it) {
Toshihiro Shimizu 890ddd
			TDoubleParamP s(it->first->clone());
Toshihiro Shimizu 890ddd
			TPixelParamP c(it->second->clone());
Toshihiro Shimizu 890ddd
			m_keys.push_back(std::make_pair(s, c));
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void addKey(const ColorKeyParam &colorKey)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		/*
Toshihiro Shimizu 890ddd
    m_sp->addParam(colorKey.first);
Toshihiro Shimizu 890ddd
    m_sp->addParam(colorKey.second);
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
		m_keys.push_back(colorKey);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void insertKey(int index, ColorKeyParam &colorKey)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		/*
Toshihiro Shimizu 890ddd
    m_sp->addParam(colorKey.first);
Toshihiro Shimizu 890ddd
    m_sp->addParam(colorKey.second);
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
		std::vector<colorkeyparam>::iterator it = m_keys.begin() + index;</colorkeyparam>
Toshihiro Shimizu 890ddd
		m_keys.insert(it, colorKey);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void eraseKey(int index)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		std::vector<colorkeyparam>::iterator colorKeyIt = m_keys.begin() + index;</colorkeyparam>
Toshihiro Shimizu 890ddd
		/*
Toshihiro Shimizu 890ddd
    m_sp->removeParam((*colorKeyIt).first);
Toshihiro Shimizu 890ddd
    m_sp->removeParam((*colorKeyIt).second);
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
		m_keys.erase(colorKeyIt);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getKeyCount() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return m_keys.size();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	ColorKeyParam getKey(int index) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return m_keys[index];
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void clearKeys()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_keys.clear();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void notify(const TParamChange &change)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		for (std::set<tparamobserver *="">::iterator it = m_observers.begin();</tparamobserver>
Toshihiro Shimizu 890ddd
			 it != m_observers.end(); ++it)
Toshihiro Shimizu 890ddd
			(*it)->onChange(change);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	TSpectrumParamImp &operator=(const TSpectrumParamImp &); //not implemented
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=========================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
PERSIST_IDENTIFIER(TSpectrumParam, "spectrumParam")
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TSpectrumParam::TSpectrumParam()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_imp = new TSpectrumParamImp(this); //brutto...
Toshihiro Shimizu 890ddd
	ColorKeyParam ck1(TDoubleParamP(0.0), TPixelParamP(TPixel32::Black));
Toshihiro Shimizu 890ddd
	ColorKeyParam ck2(TDoubleParamP(1.0), TPixelParamP(TPixel32::White));
Toshihiro Shimizu 890ddd
	m_imp->addKey(ck1);
Toshihiro Shimizu 890ddd
	m_imp->addKey(ck2);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TSpectrumParam::TSpectrumParam(const TSpectrumParam &src)
Toshihiro Shimizu 890ddd
	: TParam(src.getName())
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_imp = new TSpectrumParamImp(*src.m_imp);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TSpectrumParam::addObserver(TParamObserver *obs)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_imp->m_observers.insert(obs);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TSpectrumParam::removeObserver(TParamObserver *obs)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_imp->m_observers.erase(obs);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TSpectrumParam::TSpectrumParam(int keyCount, TSpectrum::ColorKey keys[])
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_imp = new TSpectrumParamImp(this);
Toshihiro Shimizu 890ddd
	for (int i = 0; i < keyCount; i++) {
Toshihiro Shimizu 890ddd
		double v = keys[i].first;
Toshihiro Shimizu 890ddd
		TPixel32 pix = keys[i].second;
Toshihiro Shimizu 890ddd
		TDoubleParamP dp(v);
Toshihiro Shimizu 890ddd
		TPixelParamP pp(pix);
Toshihiro Shimizu 890ddd
		pp->enableMatte(m_imp->m_isMatteEnabled);
Toshihiro Shimizu 890ddd
		ColorKeyParam ck(dp, pp);
Toshihiro Shimizu 890ddd
		m_imp->addKey(ck);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TSpectrumParam::copy(TParam *src)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TSpectrumParam *p = dynamic_cast<tspectrumparam *="">(src);</tspectrumparam>
Toshihiro Shimizu 890ddd
	if (!p)
Toshihiro Shimizu 890ddd
		throw TException("invalid source for copy");
Toshihiro Shimizu 890ddd
	setName(src->getName());
Toshihiro Shimizu 890ddd
	m_imp->copy(*(p->m_imp));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TSpectrumParam::~TSpectrumParam()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	delete m_imp;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TSpectrum TSpectrumParam::getValue(double frame) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(m_imp);
Toshihiro Shimizu 890ddd
	std::vector<tspectrum::colorkey> keys;</tspectrum::colorkey>
Toshihiro Shimizu 890ddd
	int keyCount = m_imp->getKeyCount();
Toshihiro Shimizu 890ddd
	for (int i = 0; i < keyCount; i++) {
Toshihiro Shimizu 890ddd
		ColorKeyParam paramKey = m_imp->getKey(i);
Toshihiro Shimizu 890ddd
		TSpectrum::ColorKey key(
Toshihiro Shimizu 890ddd
			paramKey.first->getValue(frame),
Toshihiro Shimizu 890ddd
			paramKey.second->getValue(frame));
Toshihiro Shimizu 890ddd
		keys.push_back(key);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return TSpectrum(keys.size(), &keys[0]);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TSpectrum64 TSpectrumParam::getValue64(double frame) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(m_imp);
Toshihiro Shimizu 890ddd
	std::vector<tspectrum64::colorkey> keys;</tspectrum64::colorkey>
Toshihiro Shimizu 890ddd
	int keyCount = m_imp->getKeyCount();
Toshihiro Shimizu 890ddd
	for (int i = 0; i < keyCount; i++) {
Toshihiro Shimizu 890ddd
		ColorKeyParam paramKey = m_imp->getKey(i);
Toshihiro Shimizu 890ddd
		TSpectrum64::ColorKey key(
Toshihiro Shimizu 890ddd
			paramKey.first->getValue(frame),
Toshihiro Shimizu 890ddd
			toPixel64(paramKey.second->getValue(frame)));
Toshihiro Shimizu 890ddd
		keys.push_back(key);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return TSpectrum64(keys.size(), &keys[0]);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TSpectrumParam::setValue(double frame, const TSpectrum &spectrum, bool undoing)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(getKeyCount() == spectrum.getKeyCount());
Toshihiro Shimizu 890ddd
	int keyCount = getKeyCount();
Toshihiro Shimizu 890ddd
	for (int i = 0; i < keyCount; i++) {
Toshihiro Shimizu 890ddd
		TSpectrum::Key key = spectrum.getKey(i);
Toshihiro Shimizu 890ddd
		setValue(frame, i, key.first, key.second, undoing);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TDoubleParamP TSpectrumParam::getPosition(int index) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(index <= m_imp->getKeyCount());
Toshihiro Shimizu 890ddd
	return m_imp->getKey(index).first;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TPixelParamP TSpectrumParam::getColor(int index) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(index <= m_imp->getKeyCount());
Toshihiro Shimizu 890ddd
	return m_imp->getKey(index).second;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int TSpectrumParam::getKeyCount() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(m_imp);
Toshihiro Shimizu 890ddd
	return m_imp->getKeyCount();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TSpectrumParam::setValue(double frame, int index, double s, const TPixel32 &color, bool undoing)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(m_imp);
Toshihiro Shimizu 890ddd
	int keyCount = m_imp->getKeyCount();
Toshihiro Shimizu 890ddd
	if (index < 0 || index >= keyCount)
Toshihiro Shimizu 890ddd
		throw TException("TSpectrumParam::setValue. Index out of range");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	ColorKeyParam key = m_imp->getKey(index);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//  beginParameterChange();
Toshihiro Shimizu 890ddd
	key.first->setValue(frame, s);
Toshihiro Shimizu 890ddd
	key.second->setValue(frame, color);
Toshihiro Shimizu 890ddd
	//  endParameterChange();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_imp->notify(TParamChange(this, TParamChange::m_minFrame, TParamChange::m_maxFrame, true, m_imp->m_draggingEnabled, false));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TSpectrumParam::setDefaultValue(const TSpectrum &value)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(value.getKeyCount() == getKeyCount());
Toshihiro Shimizu 890ddd
	for (int i = 0; i < getKeyCount(); i++) {
Toshihiro Shimizu 890ddd
		ColorKeyParam dstKeyParam = m_imp->getKey(i);
Toshihiro Shimizu 890ddd
		TSpectrum::Key srcKey = value.getKey(i);
Toshihiro Shimizu 890ddd
		dstKeyParam.first->setDefaultValue(srcKey.first);
Toshihiro Shimizu 890ddd
		dstKeyParam.second->setDefaultValue(srcKey.second);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TSpectrumParam::insertKey(int index, double s, const TPixel32 &color)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(m_imp);
Toshihiro Shimizu 890ddd
	int keyCount = m_imp->getKeyCount();
Toshihiro Shimizu 890ddd
	if (index < 0)
Toshihiro Shimizu 890ddd
		index = 0;
Toshihiro Shimizu 890ddd
	else if (index >= keyCount)
Toshihiro Shimizu 890ddd
		index = keyCount;
Toshihiro Shimizu 890ddd
	TDoubleParamP dp(s);
Toshihiro Shimizu 890ddd
	TPixelParamP pp(color);
Toshihiro Shimizu 890ddd
	pp->enableMatte(m_imp->m_isMatteEnabled);
Toshihiro Shimizu 890ddd
	ColorKeyParam ck(dp, pp);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_imp->insertKey(index, ck);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TSpectrumParam::addKey(double s, const TPixel32 &color)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	/*
Toshihiro Shimizu 890ddd
  assert(m_imp);
Toshihiro Shimizu 890ddd
  insertKey(m_imp->getKeyCount(), s,color);
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
	int index = m_imp->getKeyCount();
Toshihiro Shimizu 890ddd
	assert(m_imp);
Toshihiro Shimizu 890ddd
	int keyCount = m_imp->getKeyCount();
Toshihiro Shimizu 890ddd
	if (index < 0)
Toshihiro Shimizu 890ddd
		index = 0;
Toshihiro Shimizu 890ddd
	else if (index >= keyCount)
Toshihiro Shimizu 890ddd
		index = keyCount;
Toshihiro Shimizu 890ddd
	TDoubleParamP dp(s);
Toshihiro Shimizu 890ddd
	TPixelParamP pp(color);
Toshihiro Shimizu 890ddd
	pp->enableMatte(m_imp->m_isMatteEnabled);
Toshihiro Shimizu 890ddd
	ColorKeyParam ck(dp, pp);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_imp->insertKey(index, ck);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TSpectrumParam::removeKey(int index)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(m_imp);
Toshihiro Shimizu 890ddd
	int keyCount = m_imp->getKeyCount();
Toshihiro Shimizu 890ddd
	if (index < 0 || index >= keyCount)
Toshihiro Shimizu 890ddd
		throw TException("TSpectrumParam::removeKey. Index out of range");
Toshihiro Shimizu 890ddd
	m_imp->eraseKey(index);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool TSpectrumParam::isKeyframe(double frame) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int keyCount = m_imp->getKeyCount();
Toshihiro Shimizu 890ddd
	for (int i = 0; i < keyCount; i++) {
Toshihiro Shimizu 890ddd
		ColorKeyParam currentKey = m_imp->getKey(i);
Toshihiro Shimizu 890ddd
		if (currentKey.first->isKeyframe(frame))
Toshihiro Shimizu 890ddd
			return true;
Toshihiro Shimizu 890ddd
		if (currentKey.second->isKeyframe(frame))
Toshihiro Shimizu 890ddd
			return true;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TSpectrumParam::deleteKeyframe(double frame)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int keyCount = m_imp->getKeyCount();
Toshihiro Shimizu 890ddd
	for (int i = 0; i < keyCount; i++) {
Toshihiro Shimizu 890ddd
		ColorKeyParam currentKey = m_imp->getKey(i);
Toshihiro Shimizu 890ddd
		currentKey.first->deleteKeyframe(frame);
Toshihiro Shimizu 890ddd
		currentKey.second->deleteKeyframe(frame);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TSpectrumParam::clearKeyframes()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(m_imp);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int k, keyCount = m_imp->getKeyCount();
Toshihiro Shimizu 890ddd
	for (k = 0; k < keyCount; ++k) {
Toshihiro Shimizu 890ddd
		const ColorKeyParam &key = m_imp->getKey(k);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		key.first->clearKeyframes();
Toshihiro Shimizu 890ddd
		key.second->clearKeyframes();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_imp->notify(TParamChange(this, TParamChange::m_minFrame, TParamChange::m_maxFrame, true, m_imp->m_draggingEnabled, false));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TSpectrumParam::assignKeyframe(
Toshihiro Shimizu 890ddd
	double frame,
Toshihiro Shimizu 890ddd
	const TParamP &src, double srcFrame,
Toshihiro Shimizu 890ddd
	bool changedOnly)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TSpectrumParamP spectrum = src;
Toshihiro Shimizu 890ddd
	if (!spectrum)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	int keyCount = m_imp->getKeyCount();
Toshihiro Shimizu 890ddd
	if (keyCount != spectrum->m_imp->getKeyCount())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	for (int i = 0; i < keyCount; i++) {
Toshihiro Shimizu 890ddd
		ColorKeyParam dstKey = m_imp->getKey(i);
Toshihiro Shimizu 890ddd
		ColorKeyParam srcKey = spectrum->m_imp->getKey(i);
Toshihiro Shimizu 890ddd
		dstKey.first->setValue(frame, srcKey.first->getValue(srcFrame));
Toshihiro Shimizu 890ddd
		dstKey.second->setValue(frame, srcKey.second->getValue(srcFrame));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TSpectrumParam::loadData(TIStream &is)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(m_imp);
Toshihiro Shimizu 890ddd
	m_imp->clearKeys();
Toshihiro Shimizu 890ddd
	string tagName;
Toshihiro Shimizu 890ddd
	is.openChild(tagName);
Toshihiro Shimizu 890ddd
	assert(tagName == "spectrum");
Toshihiro Shimizu 890ddd
	while (!is.eos()) {
Toshihiro Shimizu 890ddd
		TDoubleParamP pos(0.0);
Toshihiro Shimizu 890ddd
		TPixelParamP color(TPixel32::Black);
Toshihiro Shimizu 890ddd
		is.openChild(tagName);
Toshihiro Shimizu 890ddd
		pos->loadData(is);
Toshihiro Shimizu 890ddd
		is.closeChild();
Toshihiro Shimizu 890ddd
		is.openChild(tagName);
Toshihiro Shimizu 890ddd
		color->loadData(is);
Toshihiro Shimizu 890ddd
		is.closeChild();
Toshihiro Shimizu 890ddd
		ColorKeyParam ck(pos, color);
Toshihiro Shimizu 890ddd
		m_imp->addKey(ck);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	is.closeChild();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TSpectrumParam::saveData(TOStream &os)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(m_imp);
Toshihiro Shimizu 890ddd
	int keyCount = m_imp->getKeyCount();
Toshihiro Shimizu 890ddd
	os.openChild("spectrum");
Toshihiro Shimizu 890ddd
	for (int i = 0; i < keyCount; i++) {
Toshihiro Shimizu 890ddd
		ColorKeyParam key = m_imp->getKey(i);
Toshihiro Shimizu 890ddd
		os.openChild("s_value");
Toshihiro Shimizu 890ddd
		key.first->saveData(os);
Toshihiro Shimizu 890ddd
		os.closeChild();
Toshihiro Shimizu 890ddd
		os.openChild("col_value");
Toshihiro Shimizu 890ddd
		key.second->saveData(os);
Toshihiro Shimizu 890ddd
		os.closeChild();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	os.closeChild();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TSpectrumParam::enableDragging(bool on)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_imp->m_draggingEnabled = on;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TSpectrumParam::enableNotification(bool on)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_imp->m_notificationEnabled = on;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool TSpectrumParam::isNotificationEnabled() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_imp->m_notificationEnabled;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
inline string toString(const TPixel32 &color)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	string alias = "(";
Toshihiro Shimizu 890ddd
	alias += ::toString(color.r) + ",";
Toshihiro Shimizu 890ddd
	alias += ::toString(color.g) + ",";
Toshihiro Shimizu 890ddd
	alias += ::toString(color.b) + ",";
Toshihiro Shimizu 890ddd
	alias += ::toString(color.m);
Toshihiro Shimizu 890ddd
	alias += ")";
Toshihiro Shimizu 890ddd
	return alias;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
inline string toString(const TSpectrum::ColorKey &key, int precision)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	string alias = "(";
Toshihiro Shimizu 890ddd
	alias += ::toString(key.first, precision) + ",";
Toshihiro Shimizu 890ddd
	alias += toString(key.second);
Toshihiro Shimizu 890ddd
	alias += ")";
Toshihiro Shimizu 890ddd
	return alias;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} // namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
string TSpectrumParam::getValueAlias(double frame, int precision)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	std::vector<tspectrum::colorkey> keys;</tspectrum::colorkey>
Toshihiro Shimizu 890ddd
	int keyCount = m_imp->getKeyCount();
Toshihiro Shimizu 890ddd
	for (int i = 0; i < keyCount; i++) {
Toshihiro Shimizu 890ddd
		ColorKeyParam paramKey = m_imp->getKey(i);
Toshihiro Shimizu 890ddd
		TSpectrum::ColorKey key(
Toshihiro Shimizu 890ddd
			paramKey.first->getValue(frame),
Toshihiro Shimizu 890ddd
			paramKey.second->getValue(frame));
Toshihiro Shimizu 890ddd
		keys.push_back(key);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	string alias = "(";
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!keys.empty()) {
Toshihiro Shimizu 890ddd
		std::vector<tspectrum::colorkey>::iterator it = keys.begin();</tspectrum::colorkey>
Toshihiro Shimizu 890ddd
		std::vector<tspectrum::colorkey>::iterator end = keys.begin();</tspectrum::colorkey>
Toshihiro Shimizu 890ddd
		std::advance(end, keys.size() - 1);
Toshihiro Shimizu 890ddd
		for (; it != end; ++it) {
Toshihiro Shimizu 890ddd
			alias += toString(*it, precision);
Toshihiro Shimizu 890ddd
			alias += ",";
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		alias += toString(*it, precision);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	alias += ")";
Toshihiro Shimizu 890ddd
	return alias;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=========================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TSpectrumParam::enableMatte(bool on)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_imp->m_isMatteEnabled = on;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool TSpectrumParam::isMatteEnabled() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_imp->m_isMatteEnabled;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool TSpectrumParam::hasKeyframes() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int keyCount = m_imp->getKeyCount();
Toshihiro Shimizu 890ddd
	for (int i = 0; i < keyCount; i++) {
Toshihiro Shimizu 890ddd
		ColorKeyParam currentKey = m_imp->getKey(i);
Toshihiro Shimizu 890ddd
		if (currentKey.first->hasKeyframes() || currentKey.second->hasKeyframes())
Toshihiro Shimizu 890ddd
			return true;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TSpectrumParam::getKeyframes(std::set<double> &frames) const</double>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int keyCount = m_imp->getKeyCount();
Toshihiro Shimizu 890ddd
	for (int i = 0; i < keyCount; i++) {
Toshihiro Shimizu 890ddd
		ColorKeyParam currentKey = m_imp->getKey(i);
Toshihiro Shimizu 890ddd
		currentKey.first->getKeyframes(frames);
Toshihiro Shimizu 890ddd
		currentKey.second->getKeyframes(frames);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int TSpectrumParam::getNextKeyframe(double frame) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	std::set<double> frames;</double>
Toshihiro Shimizu 890ddd
	getKeyframes(frames);
Toshihiro Shimizu 890ddd
	std::set<double>::iterator it = frames.upper_bound(frame);</double>
Toshihiro Shimizu 890ddd
	if (it == frames.end())
Toshihiro Shimizu 890ddd
		return -1;
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		return std::distance(frames.begin(), it);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int TSpectrumParam::getPrevKeyframe(double frame) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	std::set<double> frames;</double>
Toshihiro Shimizu 890ddd
	getKeyframes(frames);
Toshihiro Shimizu 890ddd
	std::set<double>::iterator it = frames.lower_bound(frame);</double>
Toshihiro Shimizu 890ddd
	if (it == frames.begin())
Toshihiro Shimizu 890ddd
		return -1;
Toshihiro Shimizu 890ddd
	else {
Toshihiro Shimizu 890ddd
		--it;
Toshihiro Shimizu 890ddd
		return std::distance(frames.begin(), it);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
double TSpectrumParam::keyframeIndexToFrame(int index) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	std::set<double> frames;</double>
Toshihiro Shimizu 890ddd
	getKeyframes(frames);
Toshihiro Shimizu 890ddd
	assert(0 <= index && index < (int)frames.size());
Toshihiro Shimizu 890ddd
	std::set<double>::const_iterator it = frames.begin();</double>
Toshihiro Shimizu 890ddd
	std::advance(it, index);
Toshihiro Shimizu 890ddd
	return *it;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TIStream &operator>>(TIStream &in, TSpectrumParamP &p)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPersist *tmp;
Toshihiro Shimizu 890ddd
	in >> tmp;
Toshihiro Shimizu 890ddd
	p = TSpectrumParamP(dynamic_cast<tspectrumparam *="">(tmp));</tspectrumparam>
Toshihiro Shimizu 890ddd
	return in;
Toshihiro Shimizu 890ddd
}