zynaddsubfx

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

Osc_IntModel.h (1641B)


      1 /*
      2   ZynAddSubFX - a software synthesizer
      3 
      4   Osc_IntModel.h - OSC Updated Integer
      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_IntModel:public Fl_Osc_Widget
     19 {
     20     public:
     21         Osc_IntModel(Fl_Osc_Interface *osc_)
     22             :Fl_Osc_Widget("", osc_), value(0)
     23         {
     24             assert(osc);
     25         }
     26 
     27         typedef int value_t;
     28         value_t value;
     29         std::function<void(value_t)> callback;
     30 
     31         void updateVal(value_t v)
     32         {
     33             value = v;
     34             oscWrite(ext, "i", v);
     35         }
     36 
     37         void doUpdate(std::string url)
     38         {
     39             if(!ext.empty())
     40                 osc->removeLink(this);
     41             ext = url;
     42 
     43             oscRegister(ext.c_str());
     44         }
     45 
     46         //Raw messages
     47         virtual void OSC_raw(const char *msg)
     48         {
     49             std::string args = rtosc_argument_string(msg);
     50             if(args == "i") {
     51                 value = rtosc_argument(msg, 0).i;
     52                 if(callback)
     53                     callback(value);
     54             } else if(args == "T") {
     55                 value = 1;
     56                 if(callback)
     57                     callback(value);
     58             }  else if(args == "F") {
     59                 value = 0;
     60                 if(callback)
     61                     callback(value);
     62             }
     63         }
     64 };