LMMS
Loading...
Searching...
No Matches
Fl_Resonance_Graph.cpp
Go to the documentation of this file.
1/*
2 ZynAddSubFX - a software synthesizer
3
4 Fl_Resonance_Graph.cpp - OSC Resonance Graph View
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_Resonance_Graph.H"
13#include <FL/Fl.H>
14#include <FL/fl_draw.H>
15#include <FL/Fl_Value_Output.H>
16#include <rtosc/rtosc.h>
17using namespace zyncarla;
18
19Fl_Resonance_Graph::Fl_Resonance_Graph(int x,int y, int w, int h, const char *label)
20 :Fl_Box(x,y,w,h,label), Fl_Osc_Widget(this), khzvalue(NULL), dbvalue(NULL),
22 PmaxdB(0)
23{
24 memset(Prespoints, 64, N_RES_POINTS);
25 //Get values
26 oscRegister("Prespoints");
27 oscRegister("Pcenterfreq");
28 oscRegister("Poctavesfreq");
29 oscRegister("PmaxdB");
30
33}
34
38
39void Fl_Resonance_Graph::init(Fl_Value_Output *khzvalue_,Fl_Value_Output *dbvalue_)
40{
41 khzvalue=khzvalue_;
42 dbvalue=dbvalue_;
43 oldx=-1;
44 khzval=-1;
45}
46
48{
49 const float freqx=getfreqpos(freq);//XXX
50 switch(type){
51 case 0:fl_line_style(FL_SOLID);break;
52 case 1:fl_line_style(FL_DOT);break;
53 case 2:fl_line_style(FL_DASH);break;
54 }
55
56
57 if ((freqx>0.0)&&(freqx<1.0))
58 fl_line(x()+(int) (freqx*w()),y(),
59 x()+(int) (freqx*w()),y()+h());
60}
61
63{
64 const int ox=x(),oy=y(),lx=w(),ly=h();
65
66 fl_color(FL_DARK1);
67 fl_rectf(ox,oy,lx,ly);
68
69
70 //draw the lines
71 fl_color(FL_GRAY);
72
73 fl_line_style(FL_SOLID);
74 fl_line(ox+2,oy+ly/2,ox+lx-2,oy+ly/2);
75
76
77 //Draw 1kHz line
78 const float freqx=getfreqpos(1000.0);//XXX
79 if ((freqx>0.0)&&(freqx<1.0))
80 fl_line(ox+(int) (freqx*lx),oy,
81 ox+(int) (freqx*lx),oy+ly);
82
83 //Draw other frequency lines
84 for (int i=1; i<10; ++i){
85 if(i==1) {
86 draw_freq_line(i*100.0,0);
87 draw_freq_line(i*1000.0,0);
88 } else
89 if (i==5) {
90 draw_freq_line(i*100.0,2);
91 draw_freq_line(i*1000.0,2);
92 } else {
93 draw_freq_line(i*100.0,1);
94 draw_freq_line(i*1000.0,1);
95 }
96 }
97
98 draw_freq_line(10000.0,0);
99 draw_freq_line(20000.0,1);
100
101 //Draw dotted grid
102 fl_line_style(FL_DOT);
103 int GY=10;if (ly<GY*3) GY=-1;
104 for (int i=1; i<GY; ++i){
105 int tmp=(int)(ly/(float)GY*i);
106 fl_line(ox+2,oy+tmp,ox+lx-2,oy+tmp);
107 }
108
109
110
111 //draw the data
112 fl_color(FL_RED);
113 fl_line_style(FL_SOLID,2);
114 fl_begin_line();
115 int oiy = ly*Prespoints[0]/128.0;//XXX easy
116 for (int i=1; i<N_RES_POINTS; ++i){
117 const int ix=(i*1.0/N_RES_POINTS*lx);
118 const int iy= ly*Prespoints[i]/128.0;//XXX easy
119 fl_vertex(ox+ix,oy+ly-oiy);
120 oiy=iy;
121 }
122 fl_end_line();
123 fl_line_style(FL_SOLID,0);
124}
125
127{
128 int x_=Fl::event_x()-x();
129 int y_=Fl::event_y()-y();
130 if((x_>=0)&&(x_<w()) && (y_>=0)&&(y_<h())){
131 khzvalue->value(getfreqx(x_*1.0/w())/1000.0);//XXX
132 dbvalue->value((1.0-y_*2.0/h())*PmaxdB);//XXX
133 }
134
135 if((event==FL_PUSH)||(event==FL_DRAG)){
136 const bool leftbutton = Fl::event_button() == FL_LEFT_MOUSE;
137
138 if (x_<0) x_=0;if (y_<0) y_=0;
139 if (x_>=w()) x_=w();if (y_>=h()-1) y_=h()-1;
140
141 if ((oldx<0)||(oldx==x_)){
142 int sn=(int)(x_*1.0/w()*N_RES_POINTS);
143 int sp=127-(int)(y_*1.0/h()*127);
144 if(leftbutton)
145 setPoint(sn,sp);
146 //oscWrite("setpoint", "ii", sn, sp);//respar->setpoint(sn,sp);//XXX easy
147 else
148 setPoint(sn,sp);
149 //oscWrite("setpoint", "ii", sn, 64);//respar->setpoint(sn,64);//XXX easy
150 } else {
151 int x1=oldx;
152 int x2=x_;
153 int y1=oldy;
154 int y2=y_;
155 if (oldx>x_){
156 x1=x_;y1=y_;
157 x2=oldx;y2=oldy;
158 }
159 for (int i=0;i<x2-x1;i++){
160 int sn=(int)((i+x1)*1.0/w()*N_RES_POINTS);
161 float yy=(y2-y1)*1.0/(x2-x1)*i;
162 int sp=127-(int)((y1+yy)/h()*127);
163 if(leftbutton) //respar->setpoint(sn,sp);//XXX easy
164 setPoint(sn, sp);
165 //oscWrite("setpoint", "ii", sn, sp);
166 else //respar->setpoint(sn,64);//XXX easy
167 setPoint(sn, sp);
168 //oscWrite("setpoint", "ii", sn, sp);
169 }
170 }
171
172 oldx=x_;oldy=y_;
173 redraw();
174 }
175
176 if(event==FL_RELEASE) {
177 oldx=-1;
178 if(cbwidget) {
179 cbwidget->do_callback();
180 if(applybutton) {
181 applybutton->color(FL_RED);
182 applybutton->redraw();
183 }
184 }
185 }
186
187 return 1;
188}
189
191{
192 this->cbwidget=cbwidget;
193 this->applybutton=applybutton;
194}
195
197{
198 oscWrite("Prespoints");
199 oscWrite("Pcenterfreq");
200 oscWrite("Poctavesfreq");
201 oscWrite("PmaxdB");
202}
203
205{
206 //TODO check the types (OSC regex)
207 if(strstr(msg, "Prespoints")) {
209 assert(arg.len == N_RES_POINTS);
211 } else if(strstr(msg, "Pcenterfreq"))
213 else if(strstr(msg, "Poctavesfreq"))
215 else if(strstr(msg, "PmaxdB"))
217 else
218 puts("I got an unknown message...");
219
220 redraw();
221}
222
224{
225 const float octf = powf(2.0f, getoctavesfreq());
226 return getcenterfreq() / sqrt(octf) * powf(octf, limit(x, 0.0f, 1.0f));
227}
228
229/*
230 * Get the x coordinate from frequency (used by the UI)
231 */
233{
234 return (logf(freq) - logf(getfreqx(0.0f))) / logf(2.0f) / getoctavesfreq();
235}
236
237/*
238 * Get the center frequency of the resonance graph
239 */
241{
242 return 10000.0f * powf(10, -(1.0f - Pcenterfreq / 127.0f) * 2.0f);
243}
244
245/*
246 * Get the number of octave that the resonance functions applies to
247 */
249{
250 return 0.25f + 10.0f * Poctavesfreq / 127.0f;
251}
252
254{
255 Prespoints[idx] = val;
256 oscWrite(std::string("Prespoints")+to_s(idx), "c", val);
257 redraw();
258}
#define N_RES_POINTS
Definition Resonance.h:22
#define NULL
Definition CarlaBridgeFormat.cpp:30
assert(0)
uint8_t sp
Definition Spc_Cpu.h:145
CAdPlugDatabase::CRecord::RecordType type
Definition adplugdb.cpp:93
Fl_Osc_Widget(void)
Definition Fl_Osc_Widget.cpp:16
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
Fl_Value_Output * khzvalue
Definition Fl_Resonance_Graph.H:45
int handle(int event)
Definition Fl_Resonance_Graph.cpp:126
void draw_freq_line(float freq, int type)
Definition Fl_Resonance_Graph.cpp:47
void setcbwidget(Fl_Widget *cbwidget, Fl_Widget *applybutton)
Definition Fl_Resonance_Graph.cpp:190
Fl_Resonance_Graph(int x, int y, int w, int h, const char *label=0)
Definition Fl_Resonance_Graph.cpp:19
char PmaxdB
Definition Fl_Resonance_Graph.H:54
void update(void)
Definition Fl_Resonance_Graph.cpp:196
Fl_Value_Output * dbvalue
Definition Fl_Resonance_Graph.H:46
void init(Fl_Value_Output *khzvalue_, Fl_Value_Output *dbvalue_)
Definition Fl_Resonance_Graph.cpp:39
int oldx
Definition Fl_Resonance_Graph.H:47
float getcenterfreq() const
Definition Fl_Resonance_Graph.cpp:240
char Pcenterfreq
Definition Fl_Resonance_Graph.H:52
void OSC_raw(const char *msg)
Definition Fl_Resonance_Graph.cpp:204
void setPoint(int idx, int val)
Definition Fl_Resonance_Graph.cpp:253
void draw()
Definition Fl_Resonance_Graph.cpp:62
float khzval
Definition Fl_Resonance_Graph.H:33
float getfreqx(float x) const
Definition Fl_Resonance_Graph.cpp:223
unsigned char Prespoints[N_RES_POINTS]
Definition Fl_Resonance_Graph.H:51
int oldy
Definition Fl_Resonance_Graph.H:47
Fl_Widget * cbwidget
Definition Fl_Resonance_Graph.H:48
Fl_Widget * applybutton
Definition Fl_Resonance_Graph.H:48
float getfreqpos(float freq) const
Definition Fl_Resonance_Graph.cpp:232
float getoctavesfreq() const
Definition Fl_Resonance_Graph.cpp:248
virtual ~Fl_Resonance_Graph(void)
Definition Fl_Resonance_Graph.cpp:35
char Poctavesfreq
Definition Fl_Resonance_Graph.H:53
UINT_D64 w
Definition inflate.c:942
int y
Definition inflate.c:1588
int lx[BMAX+1]
Definition inflate.c:1578
register unsigned i
Definition inflate.c:1575
unsigned x[BMAX+1]
Definition inflate.c:1586
JHUFF_TBL long freq[]
Definition jchuff.h:50
int val
Definition jpeglib.h:956
const char * msg
Definition missing_descriptor.c:20
Definition zynaddsubfx-src.cpp:569
T limit(T val, T min, T max)
Definition Util.h:85
std::string to_s(T x)
Definition Util.h:67
float arg(const fft_t *freqs, off_t x)
Definition OscilGen.cpp:286
rtosc_arg_t rtosc_argument(const char *msg, unsigned idx)
Definition rtosc.c:732
Definition rtosc.h:41
int32_t i
Definition rtosc.h:47
rtosc_blob_t b
Definition rtosc.h:55
memcpy(hh, h, RAND_HEAD_LEN)
uch h[RAND_HEAD_LEN]
Definition crypt.c:459
typedef int(UZ_EXP MsgFn)()