The CTK Development Page


Notes for simplified socket interface in v1.0.2

Sample data and vector data are transmitted via separate buffers. Previously get_sample() looks specifically to the sample buffer for input, and get_vector() to the vector buffer. This means that get_vector() cannot be used to receive sample data. Therefor sample data input/output had to be written as a separate case from vector data input/output. For example the compute() method for the Floor block:
if (inputs_are_all_sample_data) {
// For sample data 
CTKSample sample; 
(*input_sockets)[0]->get_sample(sample); 
if (sample<param_1) sample=param_1;
(*output_sockets)[0]->put_sample(sample); 
} else { 
// For frame data 
CTKVector *xv0; 
(*input_sockets)[0]->get_vector(xv0); 
for (CTKVector::iterator fp=xv0->begin(); fpend(); ++fp) 
if (*fp<pram_1) *fp=param_1;
(*output_sockets)[0]->put_vector(xv0); 

Now, the get_vector and put_vector can handle sample data transparently. The get_vector will look first at the vector buffer and if that fails then look to the sample buffer. The put_vector will check if the vector is size 1, and if so it will send its contents via the sample buffer. This is an inefficient way of handling sample data, but it means that for blocks that are essentially designed for vector input/output (but which might get samples as a bizarre case) the compute method can now be written more simply. For example the Floor block compute can now be written (inefficiently but equivalently) as: 

/// For frame OR sample data 
CTKVector *xv0;
(*input_sockets)[0]->get_vector(xv0);
for (CTKVector::iterator fp=xv0->begin(); fpend(); ++fp)
if (*fp< param_1) *fp=param_1;
(*output_sockets)[0]->put_vector(xv0);
The methods read_vector(), write_vector() and flush_vector() - i.e. the methods for getting and putting more than one vector at a time - have been similarly rewritten so that they can handle sample data if necessary.