Skip to content

Commit

Permalink
Added decimation rate support to OSC agent
Browse files Browse the repository at this point in the history
  • Loading branch information
Geert Bevin committed Nov 6, 2011
1 parent 6526878 commit 7ec9375
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
3 changes: 2 additions & 1 deletion plg_osc/osc_output_plg.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ def __init__(self, address, ordinal):
#
def __decimation(self,value):
self[3].set_value(value)

self.osc.set_decimation(value)
return True

#
# Define Agent as this agents top level class
Expand Down
41 changes: 39 additions & 2 deletions plg_osc/src/osc_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ namespace

// keynumber derived from the event ID
unsigned keynum_;

// the last time data was processed
unsigned long long last_processed_;
};

};
Expand Down Expand Up @@ -173,9 +176,12 @@ struct osc_plg::osc_server_t::impl_t:
// list of active wires (fast thread only)
// this is intrusive list.
pic::ilist_t<osc_wire_t> active_wires_;

// the decimation rate in micro seconds
unsigned decimation_;
};

osc_wire_t::osc_wire_t(osc_output_t *output, unsigned index, const piw::event_data_source_t &es): output_(output), index_(index)
osc_wire_t::osc_wire_t(osc_output_t *output, unsigned index, const piw::event_data_source_t &es): output_(output), index_(index), last_processed_(0)
{
// build our URL. Something like /keyboard_1/key/1
PIC_ASSERT(output_->server_->build_channel_url(osc_path_,sizeof(osc_path_),output_->prefix_,index));
Expand Down Expand Up @@ -309,6 +315,17 @@ void osc_wire_t::ticked(unsigned long long from, unsigned long long to)

void osc_wire_t::send(unsigned long long t)
{
// don't send data until the decimation interval has expired
// note that this is only done on processing real performance data
// and not the data that's synthetically generated, for instance
// at event end
if(output_->server_->decimation_ &&
last_processed_ + output_->server_->decimation_ > t)
{
return;
}

// initialize a new OSC message
lo_message msg = lo_message_new();
piw::data_nb_t d;

Expand Down Expand Up @@ -351,6 +368,9 @@ void osc_wire_t::send(unsigned long long t)
// send the message
output_->server_->osc_send_fast(osc_path_,msg);
lo_message_free(msg);

// store the last processing time for each wire
last_processed_ = t;
}

//
Expand Down Expand Up @@ -549,7 +569,7 @@ void osc_output_t::root_latency()
// main server initialisation
//

osc_plg::osc_server_t::impl_t::impl_t(piw::clockdomain_ctl_t *d, const std::string &a): osc_thread_t(a)
osc_plg::osc_server_t::impl_t::impl_t(piw::clockdomain_ctl_t *d, const std::string &a): osc_thread_t(a), decimation_(0)
{
// start the OSC threads.
osc_startup();
Expand Down Expand Up @@ -691,6 +711,18 @@ void osc_plg::osc_server_t::impl_t::clocksink_ticked(unsigned long long f, unsig
}
}

/*
* Static methods that can be called from the fast thread.
*/

static int __set_decimation(void *i_, void *d_)
{
osc_plg::osc_server_t::impl_t *i = (osc_plg::osc_server_t::impl_t *)i_;
unsigned d = *(unsigned *)d_;
i->decimation_ = d*1000;
return 0;
}

//
// pimpl wrapper functions
//
Expand All @@ -713,3 +745,8 @@ void osc_plg::osc_server_t::remove_output(const std::string &prefix)
{
impl_->remove_output(prefix);
}

void osc_plg::osc_server_t::set_decimation(unsigned decimation)
{
piw::tsd_fastcall(__set_decimation,impl_,&decimation);
}
9 changes: 6 additions & 3 deletions plg_osc/src/osc_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ namespace osc_plg
// will be silently disconnected.
void remove_output(const std::string &prefix);

// Forward implementation class declaration with the private member variable
// is a pattern we use to clearly decouple the public agent interface from the
// class declaration of the actual implementation.
// Changes the value of the decimation rate
void set_decimation(unsigned);

// Forward implementation class declaration with the private member variable
// is a pattern we use to clearly decouple the public agent interface from the
// class declaration of the actual implementation.
class impl_t;

private:
Expand Down
1 change: 1 addition & 0 deletions plg_osc/src/osc_plg.pip
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ class osc_server[osc_plg::osc_server_t]
osc_server(clockdomain_ctl *, const stdstr &)
cookie create_output(const stdstr &,bool,unsigned)
void remove_output(const stdstr &)
void set_decimation(unsigned)
}
2 changes: 1 addition & 1 deletion plg_osc/src/osc_transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ bool osc_plg::osc_thread_t::build_channel_url(char *buf, unsigned len, const std

void osc_plg::osc_thread_t::osc_send_fast(const char *name,lo_message m)
{
// send widget value to all recipients (Stage clients)
// send value to all recipients
for(unsigned i=0;i<fast_recipients_.size();i++)
{
if(!fast_recipients_[i])
Expand Down

0 comments on commit 7ec9375

Please sign in to comment.