#include "DspThrow.h"
#include "pd::Context.h"
#include "PdGraph.h"
message::Object *DspThrow::new_object(pd::Message *init_message, PdGraph *graph) {
return new DspThrow(init_message, graph);
}
DspThrow::DspThrow(pd::Message *init_message, PdGraph *graph) : DspObject(0, 1, 0, 0, graph) {
if (init_message->is_symbol(0)) {
name = utils::copy_string(init_message->get_symbol(0));
buffer = ALLOC_ALIGNED_BUFFER(graph->get_block_size() * sizeof(float));
} else {
name = NULL;
buffer = NULL;
graph->print_err("throw~ may not be initialised without a name. \"set\" message not supported.");
}
process_function = &processSignal;
}
DspThrow::~DspThrow() {
FREE_ALIGNED_BUFFER(buffer);
free(name);
}
void DspThrow::process_message(int inlet_index, pd::Message *message) {
if (inlet_index == 0 && message->is_symbol_str(0, "set") && message->is_symbol(1)) {
graph->print_err("throw~ does not support the \"set\" message.");
}
}
void DspThrow::processSignal(DspObject *dspObject, int fromIndex, int toIndex) {
DspThrow *d = reinterpret_cast<DspThrow *>(dspObject);
memcpy(d->buffer, d->dspBufferAtInlet[0], toIndex*sizeof(float));
}
bool DspThrow::is_leaf_node() {
return graph->getContext()->get_dsp_catch(name) == NULL;
}