Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: it's something, but it segfaults #1

Open
wants to merge 1 commit into
base: feature/rackv2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/jack-audio-module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,44 @@ void JackAudioModule::process(const ProcessArgs &args) {
}
}

json_t* jack_audio_module_base::dataToJson() {
auto map = Module::toJson();
auto port_names = json_array();

for (int i = 0; i < JACK_PORTS; i++) {
auto str = json_string(this->port_names[i]->text.c_str());
json_array_append_new(port_names, str);
}

json_object_set_new(map, "port_names", port_names);
return map;
}

void jack_audio_module_base::dataFromJson(json_t* json) {
auto module = reinterpret_cast<JackAudioModule*>(this);
auto port_names = json_object_get(json, "port_names");
if (json_is_array(port_names)) {
for (size_t i = 0; i < std::min(json_array_size(port_names), (size_t)8); i++) {
auto item = json_array_get(port_names, i);
if (json_is_string(item)) {
if (module->jport[i].rename(json_string_value(item))) {
this->port_names[i]->text = std::string(json_string_value(item));
} else {
static const size_t buffer_size = 128;
char port_name[buffer_size];
hashidsxx::Hashids hash(g_hashid_salt);
std::string id = hash.encode(reinterpret_cast<size_t>(module));

snprintf(reinterpret_cast<char*>(&port_name),
buffer_size,
"%s:%d", id.c_str(), (int)i);
this->port_names[i]->setText(std::string(port_name));
}
}
}
}
}

void jack_audio_module_base::report_backlogged() {
// we're over half capacity, so set our output latch
if (output_latch.try_set()) {
Expand Down
4 changes: 4 additions & 0 deletions src/jack-audio-module.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct jack_audio_module_base: public Module {
int lastSampleRate = 0;
int lastNumOutputs = -1;
int lastNumInputs = -1;
TextField* port_names[8];

dsp::SampleRateConverter<AUDIO_INPUTS> inputSrc;
dsp::SampleRateConverter<AUDIO_OUTPUTS> outputSrc;
Expand All @@ -42,6 +43,9 @@ struct jack_audio_module_base: public Module {

void report_backlogged();

virtual json_t* dataToJson() override;
virtual void dataFromJson(json_t* json) override;

jack_audio_module_base(size_t params, size_t inputs,
size_t outputs, size_t lights);
virtual ~jack_audio_module_base();
Expand Down