zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

commit e3734bef85e2f4850a6b9ec471a561b70476b755
parent f5ea06b9467bc266cba38a20ba677805d1dbc523
Author: Johannes Lorenz <j.git@lorenz-ho.me>
Date:   Sat, 21 Nov 2020 22:04:02 +0100

Run MW-path-search/oscdoc/json over ALL ports

Also, this adds two minor improvements for oscdoc and json-schema:

1. Do not dump ports twice
2. Use the new, much improved `rtosc::walk_ports` (instead of the old
   `rtosc::walk_ports2`

Diffstat:
Msrc/Misc/MiddleWare.cpp | 24++++++++++++++++++------
Msrc/Misc/MiddleWare.h | 7+++++++
Msrc/Misc/Schema.cpp | 33++++++++++++++++++++-------------
Msrc/main.cpp | 4++--
4 files changed, 47 insertions(+), 21 deletions(-)

diff --git a/src/Misc/MiddleWare.cpp b/src/Misc/MiddleWare.cpp @@ -95,9 +95,8 @@ static void liblo_error_cb(int i, const char *m, const char *loc) fprintf(stderr, "liblo :-( %d-%s@%s\n",i,m,loc); } -// we need to access those earlier +// we need to access this before the definitions // bad style? -static const rtosc::MergePorts& getParameterPorts(); static const rtosc::Ports& getNonRtParamPorts(); static int handler_function(const char *path, const char *types, lo_arg **argv, @@ -125,19 +124,32 @@ static int handler_function(const char *path, const char *types, lo_arg **argv, if(!strcmp(buffer, "/path-search") && !strcmp("ss", rtosc_argument_string(buffer))) { + constexpr bool debug_path_search = true; + if(debug_path_search) { + printf("MW: path-search: %s, %s\n", + rtosc_argument(buffer, 0).s, rtosc_argument(buffer, 1).s); + } char reply_buffer[1024*20]; std::size_t length = - rtosc::path_search(getParameterPorts(), buffer, 128, + rtosc::path_search(MiddleWare::getAllPorts(), buffer, 128, reply_buffer, sizeof(reply_buffer)); if(length) { lo_message msg = lo_message_deserialise((void*)reply_buffer, length, NULL); + if(debug_path_search) { + printf(" reply:\n"); + lo_message_pp(msg); + } lo_address addr = lo_address_new_from_url(mw->activeUrl().c_str()); if(addr) lo_send_message(addr, reply_buffer, msg); lo_address_free(addr); lo_message_free(msg); } + else { + if(debug_path_search) + printf(" -> no reply!\n"); + } } else if(buffer[0]=='/' && strrchr(buffer, '/')[1]) { @@ -1742,15 +1754,15 @@ static rtosc::MergePorts middwareSnoopPorts = &middwareSnoopPortsWithoutNonRtParams }; -static rtosc::MergePorts parameterPorts = +const rtosc::MergePorts allPorts = { // order is important: params should be queried on Master first // (because MiddleWare often just redirects, hiding the metadata) &Master::ports, - &nonRtParamPorts + &middwareSnoopPorts }; -const rtosc::MergePorts& getParameterPorts() { return parameterPorts; } const rtosc::Ports& getNonRtParamPorts() { return nonRtParamPorts; } +const rtosc::MergePorts& MiddleWare::getAllPorts() { return allPorts; } static rtosc::Ports middlewareReplyPorts = { {"echo:ss", 0, 0, diff --git a/src/Misc/MiddleWare.h b/src/Misc/MiddleWare.h @@ -16,6 +16,10 @@ class Fl_Osc_Interface; +namespace rtosc { + struct MergePorts; +} + namespace zyn { struct SYNTH_T; @@ -86,6 +90,9 @@ class MiddleWare //!Make @p new_master the current master //!@warning use with care, and only in frozen state void switchMaster(Master* new_master); + + static const rtosc::MergePorts& getAllPorts(); + private: class MiddleWareImpl *impl; }; diff --git a/src/Misc/Schema.cpp b/src/Misc/Schema.cpp @@ -1,15 +1,10 @@ #include <cstring> #include <ostream> #include <rtosc/ports.h> +#include <set> +#include <string> using namespace rtosc; -// forwards declaration from rtosc lib -void walk_ports2(const rtosc::Ports *base, - char *name_buffer, - size_t buffer_size, - void *data, - rtosc::port_walker_t walker); - namespace zyn { static const char *escape_string(const char *msg) @@ -139,8 +134,7 @@ static ostream &add_options(ostream &o, Port::MetaContainer meta) * - 'domain' : range [OPTIONAL] */ static bool first = true; -void dump_param_cb(const rtosc::Port *p, const char *full_name, const char*, - const Ports&,void *v, void*) +static bool do_dump(const rtosc::Port *p, const char *full_name, void *v) { typedef std::vector<std::pair<int,string>> opts; std::ostream &o = *(std::ostream*)v; @@ -175,7 +169,7 @@ void dump_param_cb(const rtosc::Port *p, const char *full_name, const char*, } } if(meta.find("internal") != meta.end()) - return; + return false; char type = 0; if(mparameter != p->meta().end()) { @@ -195,14 +189,14 @@ void dump_param_cb(const rtosc::Port *p, const char *full_name, const char*, if(!type) { fprintf(stderr, "rtosc port dumper: Cannot handle '%s'\n", full_name); fprintf(stderr, " args = <%s>\n", args); - return; + return false; } } else { //fprintf(stderr, "Skipping \"%s\"\n", name); //if(args) { // fprintf(stderr, " type = %s\n", args); //} - return; + return false; } const char *min = meta["min"]; @@ -253,6 +247,19 @@ void dump_param_cb(const rtosc::Port *p, const char *full_name, const char*, o << " ]"; } o << "\n }"; + return true; +} + +static void dump_param_cb(const rtosc::Port *p, const char *full_name, const char*, + const Ports&,void *v, void*) +{ + static std::set<std::pair<std::string, std::string>> already_dumped; + if(already_dumped.find(std::make_pair(full_name, p->name)) == already_dumped.end()) + { + bool dumped = do_dump(p, full_name, v); + if(dumped) + already_dumped.emplace(full_name, p->name); + } } void dump_json(std::ostream &o, const rtosc::Ports &p) @@ -262,7 +269,7 @@ void dump_json(std::ostream &o, const rtosc::Ports &p) o << " \"parameter\" : [\n"; char buffer[1024]; memset(buffer, 0, sizeof(buffer)); - walk_ports2(&p, buffer, 1024, &o, dump_param_cb); + walk_ports(&p, buffer, 1024, &o, dump_param_cb, true, nullptr, true); o << "\n ],\n"; o << " \"actions\" : [\n"; //walk_ports2(formatter.p, buffer, 1024, &o, dump_action_cb); diff --git a/src/main.cpp b/src/main.cpp @@ -459,7 +459,7 @@ int main(int argc, char *argv[]) rtosc::OscDocFormatter s; ofstream outfile(optarguments); s.prog_name = "ZynAddSubFX"; - s.p = &Master::ports; + s.p = &MiddleWare::getAllPorts(); s.uri = "http://example.com/fake/"; s.doc_origin = "http://example.com/fake/url.xml"; s.author_first = "Mark"; @@ -471,7 +471,7 @@ int main(int argc, char *argv[]) if(optarguments) { ofstream outfile(optarguments); - dump_json(outfile, Master::ports); + dump_json(outfile, MiddleWare::getAllPorts()); } break; case 'Z':