Osc_DataModel.h (1286B)
1 /* 2 ZynAddSubFX - a software synthesizer 3 4 Osc_DataModel.h - OSC Data 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_DataModel:public Fl_Osc_Widget 19 { 20 public: 21 Osc_DataModel(Fl_Osc_Interface *osc_) 22 :Fl_Osc_Widget("", osc_) 23 { 24 assert(osc); 25 } 26 27 typedef std::string value_t; 28 value_t value; 29 std::function<void(value_t)> callback; 30 31 void doUpdate(std::string url) 32 { 33 if(!ext.empty()) 34 osc->removeLink(this); 35 ext = url; 36 value = ""; 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 == "s") { 46 value = rtosc_argument(msg, 0).s; 47 if(callback) 48 callback(value); 49 } 50 } 51 };