Browse Source

Better spec dump.

fixes
Ben Niemann 2 years ago
parent
commit
3212ec7520
  1. 17
      noisicaa/audioproc/engine/control_value.cpp
  2. 4
      noisicaa/audioproc/engine/control_value.h
  3. 2
      noisicaa/audioproc/engine/realm.cpp
  4. 129
      noisicaa/audioproc/engine/spec.cpp
  5. 3
      noisicaa/audioproc/engine/spec.h

17
noisicaa/audioproc/engine/control_value.cpp

@ -20,6 +20,7 @@
* @end:license
*/
#include "noisicaa/audioproc/engine/misc.h"
#include "noisicaa/audioproc/engine/control_value.h"
namespace noisicaa {
@ -31,12 +32,28 @@ ControlValue::ControlValue(ControlValueType type, const string& name, uint32_t g
ControlValue::~ControlValue() {}
const char* ControlValue::type_name() const {
switch (_type) {
case ControlValueType::FloatCV: return "FLOAT";
case ControlValueType::IntCV: return "INT";
default: return "??";
}
}
FloatControlValue::FloatControlValue(const string& name, float value, uint32_t generation)
: ControlValue(ControlValueType::FloatCV, name, generation),
_value(value) {}
string FloatControlValue::formatted_value() const {
return sprintf("%f", _value);
}
IntControlValue::IntControlValue(const string& name, int64_t value, uint32_t generation)
: ControlValue(ControlValueType::IntCV, name, generation),
_value(value) {}
string IntControlValue::formatted_value() const {
return sprintf("%ld", _value);
}
} // namespace noisicaa

4
noisicaa/audioproc/engine/control_value.h

@ -42,8 +42,10 @@ public:
virtual ~ControlValue();
ControlValueType type() const { return _type; }
const char* type_name() const;
const string& name() const { return _name; }
uint32_t generation() const { return _generation; }
virtual string formatted_value() const = 0;
protected:
ControlValue(ControlValueType type, const string& name, uint32_t generation);
@ -60,6 +62,7 @@ class FloatControlValue : public ControlValue {
public:
FloatControlValue(const string& name, float value, uint32_t generation);
string formatted_value() const;
float value() const { return _value; }
void set_value(float value, uint32_t generation) {
_value = value;
@ -74,6 +77,7 @@ class IntControlValue : public ControlValue {
public:
IntControlValue(const string& name, int64_t value, uint32_t generation);
string formatted_value() const;
int64_t value() const { return _value; }
void set_value(int64_t value, uint32_t generation) {
_value = value;

2
noisicaa/audioproc/engine/realm.cpp

@ -210,7 +210,7 @@ string Realm::dump() const {
Program* program = _current_program.load();
if (program != nullptr) {
out += program->spec->dump();
out += program->spec->dump(_host_system);
} else {
out += "No current program.\n";
}

129
noisicaa/audioproc/engine/spec.cpp

@ -40,50 +40,105 @@ Spec::~Spec() {
_buffer_map.clear();
}
string Spec::dump() const {
string Spec::dump(HostSystem* host_system) const {
string out = "";
int i = 0;
for (const auto& opcode : _opcodes) {
const auto& opspec = opspecs[opcode.opcode];
if (_buffers.size() > 0) {
out += "Buffers:\n";
unsigned int i = 0;
for (const auto& buf : _buffers) {
out += sprintf(
"% 3u %s [%d bytes]\n",
i, pb::PortDescription::Type_Name(buf->type()).c_str(), buf->size(host_system));
++i;
}
}
string args = "";
for (size_t a = 0 ; a < opcode.args.size() ; ++a) {
const auto& arg = opcode.args[a];
if (_processors.size() > 0) {
out += "Processors:\n";
unsigned int i = 0;
for (const auto& proc : _processors) {
out += sprintf(
"% 3u %016lx [node_id=%s, state=%s]\n",
i, proc->id(), proc->node_id().c_str(), proc->state_name(proc->state()));
++i;
}
}
if (a > 0) {
args += ", ";
}
if (_control_values.size() > 0) {
out += "Control Values:\n";
unsigned int i = 0;
for (const auto& cv : _control_values) {
out += sprintf(
"% 3u %s [type=%s, value=%s, generation=%d]\n",
i, cv->name().c_str(), cv->type_name(), cv->formatted_value().c_str(), cv->generation());
++i;
}
}
switch (opspec.argspec[a]) {
case 'i':
args += sprintf("%ld", arg.int_value());
break;
case 'b': {
args += sprintf("#BUF<%d>", arg.int_value());
break;
}
case 'p': {
Processor* processor = _processors[arg.int_value()];
args += sprintf("#PROC<%016lx>", processor->id());
break;
}
case 'c': {
ControlValue* cv = _control_values[arg.int_value()];
args += sprintf("#CV<%s>", cv->name().c_str());
break;
}
case 'f':
args += sprintf("%f", arg.float_value());
break;
case 's':
args += sprintf("\"%s\"", arg.string_value().c_str());
break;
}
if (_child_realms.size() > 0) {
out += "Child Realms:\n";
unsigned int i = 0;
for (const auto& cr : _child_realms) {
out += sprintf(
"% 3u %s\n",
i, cr->name().c_str());
++i;
}
}
out += sprintf("% 3d %s(%s)\n", i, opspec.name, args.c_str());
++i;
if (_opcodes.size() > 0) {
out += "Opcodes:\n";
unsigned int i = 0;
for (const auto& opcode : _opcodes) {
const auto& opspec = opspecs[opcode.opcode];
string args = "";
for (size_t a = 0 ; a < opcode.args.size() ; ++a) {
const auto& arg = opcode.args[a];
if (a > 0) {
args += ", ";
}
switch (opspec.argspec[a]) {
case 'i':
args += sprintf("%ld", arg.int_value());
break;
case 'b': {
args += sprintf("#BUF<%d>", arg.int_value());
break;
}
case 'p': {
Processor* processor = _processors[arg.int_value()];
args += sprintf("#PROC<%016lx>", processor->id());
break;
}
case 'c': {
ControlValue* cv = _control_values[arg.int_value()];
args += sprintf("#CV<%s>", cv->name().c_str());
break;
}
case 'r': {
Realm* cr = _child_realms[arg.int_value()];
args += sprintf("#REALM<%s>", cr->name().c_str());
break;
}
case 'f':
args += sprintf("%f", arg.float_value());
break;
case 's':
args += sprintf("\"%s\"", arg.string_value().c_str());
break;
default:
args += sprintf("?%c?", opspec.argspec[a]);
break;
}
}
out += sprintf("% 3u %s(%s)\n", i, opspec.name, args.c_str());
++i;
}
}
return out;

3
noisicaa/audioproc/engine/spec.h

@ -42,6 +42,7 @@ class Processor;
class ControlValue;
class BufferType;
class Realm;
class HostSystem;
struct Instruction {
OpCode opcode;
@ -56,7 +57,7 @@ public:
Spec(const Spec&) = delete;
Spec operator=(const Spec&) = delete;
string dump() const;
string dump(HostSystem* host_system) const;
void set_bpm(uint32_t bpm) { _bpm = bpm; }
uint32_t bpm() const { return _bpm; }

Loading…
Cancel
Save