Fl_Osc_DialF.cpp (2376B)
1 /* 2 ZynAddSubFX - a software synthesizer 3 4 Fl_Osc_DialF.cpp - OSC Powered Real Valued Dial 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_DialF.H" 13 #include "Fl_Osc_Interface.h" 14 #include "Fl_Osc_Pane.H" 15 #include <cstdlib> 16 #include <cstring> 17 #include <cmath> 18 #include <cassert> 19 #include <sstream> 20 21 template<typename A, typename B> 22 B string_cast(const A &a) 23 { 24 std::stringstream s; 25 s.precision(3); 26 B b; 27 s << " " << a << " "; 28 s >> b; 29 return b; 30 } 31 32 static void callback_fn_dialf(Fl_Widget *w, void *) 33 { 34 ((Fl_Osc_DialF*)w)->cb(); 35 } 36 37 Fl_Osc_DialF::Fl_Osc_DialF(int X, int Y, int W, int H, const char *label) 38 :WidgetPDial(X,Y,W,H, label), Fl_Osc_Widget() 39 { 40 //bounds(0.0, 127.0f); 41 WidgetPDial::callback(callback_fn_dialf); 42 } 43 44 45 void Fl_Osc_DialF::init(const char *path) 46 { 47 Fl_Osc_Pane *pane = fetch_osc_pane(this); 48 assert(pane); 49 osc = pane->osc; 50 ext = path; 51 loc = pane->base; 52 oscRegister(path); 53 integer_step = false; 54 }; 55 56 Fl_Osc_DialF::~Fl_Osc_DialF(void) 57 {} 58 59 void Fl_Osc_DialF::callback(Fl_Callback *cb, void *p) 60 { 61 cb_data.first = cb; 62 cb_data.second = p; 63 } 64 65 int Fl_Osc_DialF::handle(int ev) 66 { 67 bool middle_mouse = (ev == FL_PUSH && Fl::event_state(FL_BUTTON2) && !Fl::event_shift()); 68 bool ctl_click = (ev == FL_PUSH && Fl::event_state(FL_BUTTON3) && Fl::event_ctrl()); 69 bool shift_middle = (ev == FL_PUSH && Fl::event_state(FL_BUTTON2) && Fl::event_shift()); 70 if(middle_mouse || ctl_click) { 71 printf("Trying to learn...\n"); 72 osc->write("/learn", "s", (loc+ext).c_str()); 73 return 1; 74 } else if(shift_middle) { 75 osc->write("/unlearn", "s", (loc+ext).c_str()); 76 return 1; 77 } 78 return WidgetPDial::handle(ev); 79 } 80 81 void Fl_Osc_DialF::OSC_value(float v) 82 { 83 value(v); 84 } 85 86 void Fl_Osc_DialF::update(void) 87 { 88 oscWrite(ext); 89 } 90 91 void Fl_Osc_DialF::cb(void) 92 { 93 assert(osc); 94 95 oscWrite(ext, "f", (float)value()); 96 97 if(cb_data.first) 98 cb_data.first(this, cb_data.second); 99 // label_str = string_cast<float,string>(val); 100 // label(" "); 101 // label(label_str.c_str()); 102 }