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