#include "DspPrint.h"
#include "PdGraph.h"
message::Object *DspPrint::new_object(pd::Message *init_message, PdGraph *graph) {
return new DspPrint(init_message, graph);
}
DspPrint::DspPrint(pd::Message *init_message, PdGraph *graph) : DspObject(1, 1, 0, 0, graph) {
name = utils::copy_string(init_message->is_symbol(0) ? init_message->get_symbol(0) : (char *) "print~");
}
DspPrint::~DspPrint() {
free(name);
}
void DspPrint::process_message(int inlet_index, pd::Message *message) {
if (message->is_bang(0)) {
int bufferMaxIndex = block_sizeInt - 1;
int totalLength = snprintf(NULL, 0, "%s:\n", name);
float *input_buffer = dspBufferAtInlet[0];
for (int i = 0; i < bufferMaxIndex; i++) {
totalLength += snprintf(NULL, 0, "%g ", input_buffer[i]);
}
totalLength += snprintf(NULL, 0, "%g", input_buffer[bufferMaxIndex]);
char buffer[totalLength];
int pos = snprintf(buffer, totalLength, "%s:\n", name);
for (int i = 0; i < bufferMaxIndex; i++) {
pos += snprintf(buffer + pos, totalLength, "%g ", input_buffer[i]);
}
snprintf(buffer + pos, totalLength, "%g", input_buffer[bufferMaxIndex]);
graph->print_std(buffer);
}
}
void DspPrint::processDspWithIndex(int fromIndex, int toIndex) {
}