Skip to content
This repository has been archived by the owner on Mar 27, 2020. It is now read-only.

Commit

Permalink
invalid port names detected and auto-fixed on file load
Browse files Browse the repository at this point in the history
fixes #14
  • Loading branch information
Skrylar committed Mar 26, 2019
1 parent 84fd2ad commit 49a673e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
15 changes: 14 additions & 1 deletion src/jack-audio-module-widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,25 @@ json_t* jack_audio_module_widget_base::toJson() {
}

void jack_audio_module_widget_base::fromJson(json_t* json) {
auto module = reinterpret_cast<JackAudioModule*>(this->module);
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)) {
this->port_names[i]->setText(std::string(json_string_value(item), json_string_length(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));
}
}
}
}
Expand Down
31 changes: 22 additions & 9 deletions src/jaq.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,36 @@ namespace jaq {

m_output = (flags & JackPortIsOutput) > 0;

static const size_t buffer_size = 128;
static const size_t buffer_size = 256;
char port_name[buffer_size];
snprintf
(reinterpret_cast<char*>(&port_name),
buffer_size,
"%s-%s",
name, // desired port name
"%s:%s-%s",
jack_get_client_name(mom.handle),
name, // desired port name
m_output ? "out" : "in"); // idiomatic suffix

handle = client::x_jack_port_register(
mom.handle,
name,
JACK_DEFAULT_AUDIO_TYPE,
flags,
0);
auto x = client::x_jack_port_by_name(mom.handle, port_name);

if (x == NULL) {
snprintf
(reinterpret_cast<char*>(&port_name),
buffer_size,
"%s-%s",
name, // desired port name
m_output ? "out" : "in"); // idiomatic suffix

handle = client::x_jack_port_register(
mom.handle,
name,
JACK_DEFAULT_AUDIO_TYPE,
flags,
0);
} else return false;

if (handle) return true;

else {
this->mom = 0;
return false;
Expand Down

0 comments on commit 49a673e

Please sign in to comment.