File: Fl_Osc_Dial.cpp

package info (click to toggle)
zynaddsubfx 3.0.6-7.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 65,848 kB
  • sloc: cpp: 124,436; ansic: 39,936; objc: 2,496; makefile: 1,369; python: 567; sh: 566; ruby: 178; javascript: 50
file content (72 lines) | stat: -rw-r--r-- 1,611 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "Fl_Osc_Dial.H"
#include "Fl_Osc_Interface.H"
#include "Fl_Osc_Pane.H"
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <sstream>

template<typename A, typename B>
B string_cast(const A &a)
{
    std::stringstream s;
    s.precision(3);
    B b;
    s << " " << a << " ";
    s >> b;
    return b;
}

Fl_Osc_Dial::Fl_Osc_Dial(int X, int Y, int W, int H, string n,
        const char *m)
    :Fl_Dial(X,Y,W,H), Fl_Osc_Widget(n,m)
{
    bounds(0.0f,1.0f);
    callback(Fl_Osc_Dial::_cb);

    Fl_Osc_Pane *pane = dynamic_cast<Fl_Osc_Pane*>(parent());
    assert(pane);
    osc = pane->osc;
    osc->createLink(full_path, this);
    osc->requestValue(full_path);
};

Fl_Osc_Dial::~Fl_Osc_Dial(void)
{
    osc->removeLink(full_path, this);
}

void Fl_Osc_Dial::OSC_value(float v)
{
    printf("setting osc value via '%f'\n", v);
    real_value = v;

    const float val = Fl_Osc_Widget::inv_translate(v);

    Fl_Dial::value(val);
    string tmp = string_cast<float,string>(v);
    memset(label_str, 0, sizeof(label_str));
    strncpy(label_str, tmp.c_str(), sizeof(label_str)-1);
    label("                ");
    label(label_str);
}

void Fl_Osc_Dial::cb(void)
{
    const float val = translate(Fl_Dial::value());

    osc->writeValue(full_path, val);
    OSC_value(val);

    string tmp = string_cast<float,string>(val);
    memset(label_str, 0, sizeof(label_str));
    strncpy(label_str, tmp.c_str(), sizeof(label_str)-1);
    label("                ");
    label(label_str);
}

void Fl_Osc_Dial::_cb(Fl_Widget *w, void *)
{
    static_cast<Fl_Osc_Dial*>(w)->cb();
}