zynaddsubfx

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

Fl_Osc_Output.cpp (1530B)


      1 /*
      2   ZynAddSubFX - a software synthesizer
      3 
      4   Fl_Osc_Output.cpp - OSC Based Value Output
      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 #include "Fl_Osc_Output.H"
     13 #include <cstdlib>
     14 #include <cstring>
     15 #include <cmath>
     16 #include <cassert>
     17 #include <sstream>
     18 
     19 static void callback_fn_output(Fl_Widget *w, void *)
     20 {
     21     ((Fl_Osc_Output*)w)->cb();
     22 }
     23 
     24 Fl_Osc_Output::Fl_Osc_Output(int X, int Y, int W, int H, const char *label)
     25     :Fl_Value_Output(X,Y,W,H, label), Fl_Osc_Widget(this)
     26 {
     27     Fl_Value_Output::callback(callback_fn_output);
     28 }
     29 
     30 
     31 void Fl_Osc_Output::init(const char *path)
     32 {
     33     ext = path;
     34     oscRegister(path);
     35 };
     36 
     37 void Fl_Osc_Output::callback(Fl_Callback *cb, void *p)
     38 {
     39     cb_data.first = cb;
     40     cb_data.second = p;
     41 }
     42 
     43 void Fl_Osc_Output::OSC_value(char v)
     44 {
     45     newvalue_ = v;
     46     value(v);
     47 
     48     //Hide the fact that this widget is async
     49     if(cb_data.first)
     50         cb_data.first(this, cb_data.second);
     51 }
     52 
     53 void Fl_Osc_Output::OSC_value(float v)
     54 {
     55     newvalue_ = v;
     56     value(v);
     57 
     58     //Hide the fact that this widget is async
     59     if(cb_data.first)
     60         cb_data.first(this, cb_data.second);
     61 }
     62 
     63 void Fl_Osc_Output::update(void)
     64 {
     65     oscWrite(ext);
     66 }
     67 
     68 float Fl_Osc_Output::newvalue(void) const
     69 {
     70     return newvalue_;
     71 }
     72 
     73 void Fl_Osc_Output::cb(void)
     74 {
     75     oscWrite(ext);
     76 }