LMMS
Loading...
Searching...
No Matches
Fl_Osc_Dial.cpp
Go to the documentation of this file.
1/*
2 ZynAddSubFX - a software synthesizer
3
4 Fl_Osc_Dial.cpp - OSC Controlled 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/Fl.H>
13#include "Fl_Osc_Dial.H"
14#include "Fl_Osc_Interface.h"
15#include "Fl_Osc_Pane.H"
16#include <cstdlib>
17#include <cstring>
18#include <cmath>
19#include <cassert>
20#include <sstream>
21
22static void callback_fn_dial(Fl_Widget *w, void *)
23{
24 ((Fl_Osc_Dial*)w)->cb();
25}
26
28{
29 if(!w)
30 return NULL;
31
32 Fl_Osc_Pane *pane = dynamic_cast<Fl_Osc_Pane*>(w->parent());
33 if(pane)
34 return pane;
35 return fetch_osc_pane(w->parent());
36}
37
38Fl_Osc_Dial::Fl_Osc_Dial(int X, int Y, int W, int H, const char *label)
39 :WidgetPDial(X,Y,W,H, label), Fl_Osc_Widget(this), alt_style(false), dead(false)
40{
41 bounds(0.0, 127.0f);
42 WidgetPDial::callback(callback_fn_dial);
43}
44
45
46void Fl_Osc_Dial::init(std::string path_)
47{
48 assert(osc);
49 ext = path_;
50 oscRegister(path_.c_str());
51};
52
53void Fl_Osc_Dial::alt_init(std::string base, std::string path_)
54{
55 Fl_Osc_Pane *pane = fetch_osc_pane(this);
56 assert(pane);
57 osc = pane->osc;
58 assert(osc);
59 loc = base;
60 oscRegister(path_.c_str());
61 ext = path_;
62 alt_style = true;
63}
64
67
68void Fl_Osc_Dial::callback(Fl_Callback *cb, void *p)
69{
70 cb_data.first = cb;
71 cb_data.second = p;
72}
73
75{
76 bool middle_mouse = (ev == FL_PUSH && Fl::event_state(FL_BUTTON2) && !Fl::event_shift());
77 bool ctl_click = (ev == FL_PUSH && Fl::event_state(FL_BUTTON3) && Fl::event_ctrl());
78 bool shift_middle = (ev == FL_PUSH && Fl::event_state(FL_BUTTON2) && Fl::event_shift());
79 if(middle_mouse || ctl_click) {
80 printf("Trying to learn...\n");
81 osc->write("/learn", "s", (loc+ext).c_str());
82 return 1;
83 } else if(shift_middle) {
84 osc->write("/unlearn", "s", (loc+ext).c_str());
85 return 1;
86 }
87 return WidgetPDial::handle(ev);
88}
89
91{
92 value(v + value() - floorf(value()) +
93 (minimum() == 64 ? 0 : minimum()));
94}
95
97{
98 value(v + value() - floorf(value()) +
99 minimum());
100}
101
103{
104 osc->requestValue(loc+ext);
105}
106
108{
109 assert(osc);
110
111 if(64 != (int)minimum())
112 oscWrite(ext, "i", (int)(value()-minimum()));
113 else
114 oscWrite(ext, "i", (int)(value()));
115
116 if(cb_data.first)
117 cb_data.first(this, cb_data.second);
118}
119
121{
122 dead = true;
123}
124
125#define VEL_PFX "VelocityScale"
126
127void Fl_Osc_Dial::rebase(std::string new_base)
128{
129 if(dead || loc == "/")
130 return;
131 if(!alt_style) {
132 Fl_Osc_Widget::rebase(new_base);
133 return;
134 }
135
136 //ok, for a simple hack here lets just assume that there is one branch
137 //missing
138 int depth = 0;
139 for(int i=0; i<(int)loc.size(); ++i)
140 depth += loc[i] == '/';
141 int match_depth = 0;
142 int match_pos = 0;
143 for(int i=0; i<(int)new_base.size(); ++i) {
144 match_depth += new_base[i] == '/';
145 if(match_depth == depth) {
146 match_pos = i;
147 break;
148 }
149 }
150
151 if(match_pos == 0) {
152 //well, that didn't work
153 assert(!"good enough hack");
154 }
155
156 std::string new_loc = new_base.substr(0, match_pos+1);
157 if (!strncmp(ext.c_str(), VEL_PFX, sizeof(VEL_PFX)-1) &&
158 strstr(loc.c_str(), "/VoicePar"))
159 new_loc = new_loc + "PFilter";
160 // printf("Moving '%s' to\n", (loc+ext).c_str());
161 // printf(" '%s'\n", (new_loc+ext).c_str());
162 // printf("Ext: %s\n", ext.c_str());
163 oscMove(loc+ext, new_loc+ext);
164 loc = new_loc;
165}
#define NULL
Definition CarlaBridgeFormat.cpp:30
#define VEL_PFX
Definition Fl_Osc_Dial.cpp:125
Fl_Osc_Pane * fetch_osc_pane(Fl_Widget *w)
Definition Fl_Osc_Dial.cpp:27
static void callback_fn_dial(Fl_Widget *w, void *)
Definition Fl_Osc_Dial.cpp:22
assert(0)
Definition Fl_Osc_Dial.H:19
void update(void)
Definition Fl_Osc_Dial.cpp:102
virtual void rebase(std::string new_base) override
Definition Fl_Osc_Dial.cpp:127
virtual ~Fl_Osc_Dial(void)
Definition Fl_Osc_Dial.cpp:65
void OSC_value(int)
Definition Fl_Osc_Dial.cpp:90
void init(std::string path)
Definition Fl_Osc_Dial.cpp:46
bool alt_style
Definition Fl_Osc_Dial.H:48
void cb(void)
Definition Fl_Osc_Dial.cpp:107
bool dead
Definition Fl_Osc_Dial.H:49
std::pair< Fl_Callback *, void * > cb_data
Definition Fl_Osc_Dial.H:50
void callback(Fl_Callback *cb, void *p=NULL)
Definition Fl_Osc_Dial.cpp:68
Fl_Osc_Dial(int X, int Y, int W, int H, const char *label=NULL)
Definition Fl_Osc_Dial.cpp:38
int handle(int)
Definition Fl_Osc_Dial.cpp:74
void mark_dead(void)
Definition Fl_Osc_Dial.cpp:120
void alt_init(std::string base, std::string path_)
Definition Fl_Osc_Dial.cpp:53
Definition Fl_Osc_Pane.H:20
class Fl_Osc_Interface * osc
Definition Fl_Osc_Pane.H:23
Fl_Osc_Interface * osc
Definition Fl_Osc_Widget.H:65
std::string ext
Definition Fl_Osc_Widget.H:64
Fl_Osc_Widget(void)
Definition Fl_Osc_Widget.cpp:16
std::string loc
Definition Fl_Osc_Widget.H:62
void oscMove(std::string new_ext)
Definition Fl_Osc_Widget.cpp:122
virtual void rebase(std::string new_base)
Definition Fl_Osc_Widget.cpp:115
void oscRegister(const char *path)
Definition Fl_Osc_Widget.cpp:91
void oscWrite(std::string path, const char *args,...)
Definition Fl_Osc_Widget.cpp:60
class Fl_Osc_Pane * fetch_osc_pane(Fl_Widget *w)
Definition Fl_Osc_Widget.cpp:103
int handle(int event)
Definition WidgetPDial.cpp:54
WidgetPDial(int x, int y, int w, int h, const char *label=0)
Definition WidgetPDial.cpp:29
UINT_D64 w
Definition inflate.c:942
unsigned v[N_MAX]
Definition inflate.c:1584
register unsigned i
Definition inflate.c:1575
static PuglViewHint int value
Definition pugl.h:1708
#define X(str)
Definition juce_LV2Common.h:197
#define false
Definition ordinals.h:83
uch * p
Definition crypt.c:594
typedef int(UZ_EXP MsgFn)()