zynaddsubfx

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

Fl_Osc_Widget.cpp (3473B)


      1 /*
      2   ZynAddSubFX - a software synthesizer
      3 
      4   Fl_Osc_Widget.cpp - OSC Widget Superclass
      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_Widget.H"
     13 #include "Fl_Osc_Pane.H"
     14 #include <rtosc/rtosc.h>
     15 
     16 Fl_Osc_Widget::Fl_Osc_Widget(void) //Deprecated
     17 :loc(), osc(NULL)
     18 {}
     19 
     20 Fl_Osc_Widget::Fl_Osc_Widget(std::string loc_, Fl_Osc_Interface *osc_)
     21 :loc(loc_), osc(osc_)
     22 {
     23     assert(osc);
     24 }
     25 Fl_Osc_Widget:: Fl_Osc_Widget(Fl_Widget *self)
     26 {
     27     assert(fetch_osc_pane(self));
     28     if(auto *pane = fetch_osc_pane(self)) {
     29         osc = pane->osc;
     30         loc = pane->loc();
     31     }
     32     assert(osc);
     33 }
     34 
     35 Fl_Osc_Widget::~Fl_Osc_Widget(void)
     36 {
     37     if(osc)
     38         osc->removeLink(this);
     39 };
     40 
     41 void Fl_Osc_Widget::OSC_value(float) {}
     42 void Fl_Osc_Widget::OSC_value(bool) {}
     43 void Fl_Osc_Widget::OSC_value(int) {}
     44 void Fl_Osc_Widget::OSC_value(char) {}
     45 void Fl_Osc_Widget::OSC_value(unsigned,void*) {}
     46 void Fl_Osc_Widget::OSC_value(const char *) {}
     47 
     48 //labeled forwarding methods
     49 void Fl_Osc_Widget::OSC_value(float x, const char *) {OSC_value(x);}
     50 void Fl_Osc_Widget::OSC_value(bool x, const char *) {OSC_value(x);}
     51 void Fl_Osc_Widget::OSC_value(int x, const char *) {OSC_value(x);}
     52 void Fl_Osc_Widget::OSC_value(char x, const char *) {OSC_value(x);}
     53 void Fl_Osc_Widget::OSC_value(unsigned x, void *v, const char *) {OSC_value(x,v);}
     54 void Fl_Osc_Widget::OSC_value(const char *x, const char *) {OSC_value(x);}
     55 
     56 void Fl_Osc_Widget::OSC_raw(const char *)
     57 {}
     58 
     59 
     60 void Fl_Osc_Widget::oscWrite(std::string path, const char *args, ...)
     61 {
     62     char buffer[1024];
     63     //puts("writing OSC");
     64     //printf("Path = '%s'\n", path.c_str());
     65 
     66     va_list va;
     67     va_start(va, args);
     68 
     69     if(rtosc_vmessage(buffer, 1024, (loc+path).c_str(), args, va))
     70         osc->writeRaw(buffer);
     71     else
     72         puts("Dangerous Event omission");
     73 
     74     va_end(va);
     75     ////Try to pretty print basic events
     76     //if(!strcmp(args, "c") || !strcmp(args, "i"))
     77     //    printf("Args = ['%d']\n", rtosc_argument(buffer, 0).i);
     78     //if(!strcmp(args, "f"))
     79     //    printf("Args = ['%f']\n", rtosc_argument(buffer, 0).f);
     80     //if(!strcmp(args, "T"))
     81     //    printf("Args = [True]\n");
     82     //if(!strcmp(args, "F"))
     83     //    printf("Args = [False]\n");
     84 }
     85 
     86 void Fl_Osc_Widget::oscWrite(std::string path)
     87 {
     88     osc->requestValue(loc+path);
     89 }
     90 
     91 void Fl_Osc_Widget::oscRegister(const char *path)
     92 {
     93     osc->createLink(loc+path, this);
     94     osc->requestValue(loc+path);
     95 }
     96 
     97 void Fl_Osc_Widget::update(void)
     98 {
     99     if(*((loc+ext).rbegin()) != '/' && osc)
    100         osc->requestValue(loc+ext);
    101 }
    102 
    103 Fl_Osc_Pane *Fl_Osc_Widget::fetch_osc_pane(Fl_Widget *w)
    104 {
    105     if(!w)
    106         return NULL;
    107 
    108     Fl_Osc_Pane *pane = dynamic_cast<Fl_Osc_Pane*>(w->parent());
    109     if(pane)
    110         return pane;
    111     return fetch_osc_pane(w->parent());
    112 }
    113 
    114 
    115 void Fl_Osc_Widget::rebase(std::string new_base)
    116 {
    117     osc->renameLink(loc+ext, new_base+ext, this);
    118     loc = new_base;
    119     osc->requestValue(loc+ext);
    120 }
    121 
    122 void Fl_Osc_Widget::oscMove(std::string new_ext)
    123 {
    124     osc->renameLink(loc+ext, loc+new_ext, this);
    125     ext = new_ext;
    126     osc->requestValue(loc+ext);
    127 }
    128 
    129 void Fl_Osc_Widget::oscMove(std::string old_loc, std::string new_loc)
    130 {
    131     osc->renameLink(old_loc, new_loc, this);
    132     osc->requestValue(new_loc);
    133 }