zynaddsubfx

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

commit b129ae4c516c5e418c31967df28fd5dccd32564c
parent 9b20e0a7e054996e8f7ffcc53ae8c8ea8f8cc08d
Author: fundamental <[email protected]>
Date:   Mon,  1 Jun 2015 18:22:18 -0400

ConfigUI: Fix Bank/Preset Widgets

Diffstat:
Msrc/Misc/Config.cpp | 24++++++++++++++++++++----
Msrc/UI/ConfigUI.fl | 6+++++-
Msrc/UI/Fl_Osc_ListView.H | 7++++---
Msrc/UI/Fl_Osc_ListView.cpp | 43++++++++++++++++++++++++++++++-------------
Msrc/UI/Osc_ListModel.h | 1+
Asrc/UI/Osc_SimpleListModel.h | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 128 insertions(+), 21 deletions(-)

diff --git a/src/Misc/Config.cpp b/src/Misc/Config.cpp @@ -60,8 +60,16 @@ static rtosc::Ports ports = { [](const char *msg, rtosc::RtData &d) { Config &c = *(Config*)d.obj; - if(rtosc_narguments(msg) != 0) - return; + if(rtosc_narguments(msg) != 0) { + std::string args = rtosc_argument_string(msg); + + //clear everything + c.clearpresetsdirlist(); + for(int i=0; i<(int)args.size(); ++i) + if(args[i] == 's') + c.cfg.presetsDirList[i] = rtosc_argument(msg, i).s; + } + char types[MAX_BANK_ROOT_DIRS+1]; rtosc_arg_t args[MAX_BANK_ROOT_DIRS]; size_t pos = 0; @@ -85,8 +93,16 @@ static rtosc::Ports ports = { [](const char *msg, rtosc::RtData &d) { Config &c = *(Config*)d.obj; - if(rtosc_narguments(msg) != 0) - return; + if(rtosc_narguments(msg) != 0) { + std::string args = rtosc_argument_string(msg); + + //clear everything + c.clearbankrootdirlist(); + for(int i=0; i<(int)args.size(); ++i) + if(args[i] == 's') + c.cfg.bankRootDirList[i] = rtosc_argument(msg, i).s; + } + char types[MAX_BANK_ROOT_DIRS+1]; rtosc_arg_t args[MAX_BANK_ROOT_DIRS]; size_t pos = 0; diff --git a/src/UI/ConfigUI.fl b/src/UI/ConfigUI.fl @@ -300,7 +300,11 @@ activatebutton_presetdir(true);} };} {} } Function {show()} {} { - code {configwindow->show();} {} + code { + rootsbrowse->update(); + presetbrowse->update(); + configwindow->show(); + } {} } decl {class Fl_Osc_Interface *osc;} {public local } diff --git a/src/UI/Fl_Osc_ListView.H b/src/UI/Fl_Osc_ListView.H @@ -3,15 +3,16 @@ #include <vector> #include "Fl_Osc_Widget.H" #include <FL/Fl_Browser.H> +#include "Osc_SimpleListModel.h" -class Fl_Osc_ListView:public Fl_Browser, public Fl_Osc_Widget +class Fl_Osc_ListView:public Fl_Browser, Fl_Osc_Widget { public: Fl_Osc_ListView(int x,int y, int w, int h, const char *label=0); virtual ~Fl_Osc_ListView(void); void init(const char *path_); - void OSC_raw(const char *msg); + void doUpdate(Osc_SimpleListModel::list_t l); void update(void); void insert(std::string s, int offset); @@ -21,5 +22,5 @@ class Fl_Osc_ListView:public Fl_Browser, public Fl_Osc_Widget private: void sendUpdate() const; std::string path; - std::vector<std::string> data; + Osc_SimpleListModel *data; }; diff --git a/src/UI/Fl_Osc_ListView.cpp b/src/UI/Fl_Osc_ListView.cpp @@ -3,10 +3,13 @@ #include <rtosc/rtosc.h> Fl_Osc_ListView::Fl_Osc_ListView(int x,int y, int w, int h, const char *label) - :Fl_Browser(x,y,w,h,label) + :Fl_Browser(x,y,w,h,label), data(0) {} -Fl_Osc_ListView::~Fl_Osc_ListView(void) {}; +Fl_Osc_ListView::~Fl_Osc_ListView(void) +{ + delete data; +}; void Fl_Osc_ListView::init(const char *path_) { @@ -16,38 +19,52 @@ void Fl_Osc_ListView::init(const char *path_) loc = pane->base; assert(osc); path = path_; - oscRegister(path_); + data = new Osc_SimpleListModel(osc); + data->callback = [this](Osc_SimpleListModel::list_t l){this->doUpdate(l);}; + data->update(loc+path_); } -void Fl_Osc_ListView::OSC_raw(const char *msg) + +void Fl_Osc_ListView::doUpdate(Osc_SimpleListModel::list_t l) { this->clear(); - for(int i=0; i<(int)rtosc_narguments(msg); ++i) { - this->add(rtosc_argument(msg, i).s); + for(int i=0; i<(int)l.size(); ++i) { + this->add(l[i].c_str()); } } - void Fl_Osc_ListView::update(void) { - osc->requestValue(path.c_str()); + data->update(loc+path); } void Fl_Osc_ListView::insert(std::string s, int offset) { - fprintf(stderr, "UNIMPLEMENTED\n"); + assert(offset); + data->list.insert(data->list.begin()+offset-1, s); + data->apply(); + //fprintf(stderr, "UNIMPLEMENTED\n"); } void Fl_Osc_ListView::append(std::string s) { - fprintf(stderr, "UNIMPLEMENTED\n"); + data->list.push_back(s); + data->apply(); } void Fl_Osc_ListView::doMove(int i, int j) { - fprintf(stderr, "UNIMPLEMENTED\n"); + assert(i); + assert(j); + auto &list = data->list; + std::string value = list[j-1]; + list.erase(list.begin()+j-1); + list.insert(list.begin()+i-1, value); + //std::swap(data->list[i-1], data->list[j-1]); + data->apply(); } void Fl_Osc_ListView::doRemove(int offset) { - fprintf(stderr, "UNIMPLEMENTED\n"); + assert(offset); + data->list.erase(data->list.begin()+offset-1); + data->apply(); } void Fl_Osc_ListView::sendUpdate() const { - fprintf(stderr, "UNIMPLEMENTED\n"); } diff --git a/src/UI/Osc_ListModel.h b/src/UI/Osc_ListModel.h @@ -1,3 +1,4 @@ +#pragma once #include "Fl_Osc_Widget.H" #include <functional> #include <vector> diff --git a/src/UI/Osc_SimpleListModel.h b/src/UI/Osc_SimpleListModel.h @@ -0,0 +1,68 @@ +#pragma once +#include "Fl_Osc_Widget.H" +#include <functional> +#include <vector> +#include <rtosc/rtosc.h> + +class Osc_SimpleListModel:public Fl_Osc_Widget +{ + public: + Osc_SimpleListModel(Fl_Osc_Interface *osc_) + :Fl_Osc_Widget("", osc_), list_size(0) + { + assert(osc); + } + + typedef std::vector<std::string> list_t; + list_t list; + std::function<void(list_t)> callback; + unsigned list_size; + + void update(std::string url) + { + if(!ext.empty()) + osc->removeLink(this); + ext = url; + + oscRegister(ext.c_str()); + } + + void apply() + { + if(list.size() == 0) { + oscWrite("", "I"); + } + char types[list.size()+1]; + rtosc_arg_t args[list.size()]; + + //zero out data + memset(types, 0, sizeof(types)); + memset(args, 0, sizeof(args)); + + for(int i=0; i<(int)list.size(); ++i) { + types[i] = 's'; + args[i].s = list[i].c_str(); + } + char buffer[1024*5]; + rtosc_amessage(buffer, sizeof(buffer), ext.c_str(), types, args); + osc->writeRaw(buffer); + } + + //Raw messages + virtual void OSC_raw(const char *msg) + { + std::string args = rtosc_argument_string(msg); + const int list_size = args.length(); + for(int i=0; i<list_size; ++i) + if(args[i] != 's') + return; + + list.clear(); + list.resize(list_size); + + for(int idx=0; idx<list_size; ++idx) + list[idx] = rtosc_argument(msg, idx).s; + if(callback) + callback(list); + } +};