Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reconfigure #13

Closed
ethanrublee opened this issue Jun 4, 2011 · 3 comments
Closed

reconfigure #13

ethanrublee opened this issue Jun 4, 2011 · 3 comments
Assignees
Milestone

Comments

@ethanrublee
Copy link
Member

Need to implement the reconfiguration callback logic.

void configure(tendrils& params)
{
  params.register_callback(boost::bind(reconfigure, this,_1)); //global parameter change callback
  value_ = params.get<float>("value");
  params.at<std::string>("not_validated").register_callback(boost::bind(str_cb, this, _1));
  params.at<std::string>("validated").register_callback(boost::bind(str_cb_validated, this, _1));
}

straszheim or ethanrublee may pick this up and claim it.

@ethanrublee
Copy link
Member Author

See commit fef697a

struct ParameterWatcher
{
  double value_;

  static void declare_params(ecto::tendrils& p)
  {
    p.declare<double> ("value", "I use this value", 1.0);
  }

  static void declare_io(const ecto::tendrils& parameters,
                         ecto::tendrils& inputs, ecto::tendrils& outputs)
  {
    inputs.declare<double> ("input", "input");
    outputs.declare<double> ("output", "output");
    outputs.declare<double> ("value", "the parameter.");

  }

  void onvalue_change(double v)
  {
    SHOW();
    std::cout << "old value: " << value_ << std::endl;
    std::cout << "new value: " << v << std::endl;
    value_ = v;
  }

  void configure(tendrils& parms)
  {
    parms.at("value").set_callback<double> (
                                            boost::bind(
                                                        &ParameterWatcher::onvalue_change,
                                                        this, _1));
  }

  int process(const ecto::tendrils& inputs, ecto::tendrils& outputs)
  {
    outputs.get<double> ("output") = inputs.get<double> ("input") * value_;
    outputs.get<double> ("value") = value_;
    return ecto::OK;
  }
};

@ghost ghost assigned straszheim Jun 4, 2011
@ethanrublee
Copy link
Member Author

Then the graph execution is what triggers the callbacks.

So the idium becomes, before calling the process function of the module, trigger callbacks on all parameters.

        //trigger all parameter change callbacks...
        tendrils::iterator begin = m->parameters.begin(), end =
            m->parameters.end();
        while (begin != end)
          {
            begin->second.trigger_callback();
            ++begin;
          }
        val = m->process();

All non const access to the tendril object marks it as dirty.

//... tendril
  template<typename T>
  inline T& get()
  {
    //throws on failure
    enforce_type<T> ();
    dirty_ = true; // likely changed..
    //cast a void pointer to this type.
    return *static_cast<T*> (holder_->get());
  }

  void trigger_callback()
  {
    if (dirty_)
      {
        //std::cout << "calling callback : " << type_name() << std::endl;
        holder_->trigger_callback();
      }
    dirty_ = false;
  }

The registration is typed:

  template<typename T>
  tendril& set_callback(boost::function<void(T)> cb)
  {
    typedef holder<T> holder_t;
    enforce_type<T> ();
    holder_base* hb = holder_.get();
    holder_t* ht = dynamic_cast<holder_t*> (hb);
    ht->cb = cb;
    return *this;
  }

@ethanrublee
Copy link
Member Author

Closing for now as this is probably adequate for most use cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants