zynaddsubfx

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

Osc_ListModel.h (1740B)


      1 /*
      2   ZynAddSubFX - a software synthesizer
      3 
      4   Osc_ListModel.h - OSC List View
      5   Copyright (C) 2016 Mark McCurry
      6 
      7   This program is free software; you can redistribute it and/or
      8   modify it under the terms of the GNU General Public License
      9   as published by the Free Software Foundation; either version 2
     10   of the License, or (at your option) any later version.
     11 */
     12 #pragma once
     13 #include "Fl_Osc_Widget.H"
     14 #include <functional>
     15 #include <vector>
     16 #include <rtosc/rtosc.h>
     17 
     18 class Osc_ListModel:public Fl_Osc_Widget
     19 {
     20     public:
     21         Osc_ListModel(Fl_Osc_Interface *osc_)
     22             :Fl_Osc_Widget("", osc_), list_size(0)
     23         {
     24             assert(osc);
     25         }
     26 
     27         typedef std::vector<std::tuple<std::string, std::string, std::string>> list_t;
     28         list_t list;
     29         std::function<void(list_t)> callback;
     30         unsigned list_size;
     31 
     32         void doUpdate(std::string url)
     33         {
     34             if(!ext.empty())
     35                 osc->removeLink(this);
     36             ext = url;
     37 
     38             oscRegister(ext.c_str());
     39         }
     40 
     41         //Raw messages
     42         virtual void OSC_raw(const char *msg)
     43         {
     44             std::string args = rtosc_argument_string(msg);
     45             if(args == "i") {
     46                 list_size = rtosc_argument(msg, 0).i;
     47                 list.clear();
     48                 list.resize(list_size);
     49             } else if(args == "isss") {
     50                 int idx = rtosc_argument(msg,0).i;
     51                 std::get<0>(list[idx]) = rtosc_argument(msg,1).s;
     52                 std::get<1>(list[idx]) = rtosc_argument(msg,2).s;
     53                 std::get<2>(list[idx]) = rtosc_argument(msg,3).s;
     54                 if(idx == (int)list_size-1 && callback)
     55                     callback(list);
     56             }
     57         }
     58 };