1 /*
2 * 0BSD
3 *
4 * BSD Zero Clause License
5 *
6 * Copyright (c) 2020 Hermann Meyer
7 *
8 * Permission to use, copy, modify, and/or distribute this software for any
9 * purpose with or without fee is hereby granted.
10
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
18 *
19 */
20
21
22 /*---------------------------------------------------------------------
23 -----------------------------------------------------------------------
24 define PortIndex and plugin uri
25 -----------------------------------------------------------------------
26 ----------------------------------------------------------------------*/
27
28 #include "FatFrog.h"
29
30 /*---------------------------------------------------------------------
31 -----------------------------------------------------------------------
32 define controller numbers
33 -----------------------------------------------------------------------
34 ----------------------------------------------------------------------*/
35
36 #define CONTROLS 7
37
38 /*---------------------------------------------------------------------
39 -----------------------------------------------------------------------
40 include the LV2 interface
41 -----------------------------------------------------------------------
42 ----------------------------------------------------------------------*/
43
44 #include "lv2_plugin.cc"
45
46 /*---------------------------------------------------------------------
47 -----------------------------------------------------------------------
48 define the plugin settings
49 -----------------------------------------------------------------------
50 ----------------------------------------------------------------------*/
51
52 // setup a color theme
set_my_theme(Xputty * main)53 static void set_my_theme(Xputty *main) {
54 main->color_scheme->normal = (Colors) {
55 /* cairo / r / g / b / a / */
56 /*fg */ { 0.0, 0.0, 0.0, 1.0},
57 /*bg */ { 0.3, 0.3, 0.3, 1.0},
58 /*base */ { 0.35, 0.0, 0.0, 1.0},
59 /*text */ { 0.0, 0.0, 0.0, 1.0},
60 /*shadow */ { 0.0, 0.0, 0.0, 0.2},
61 /*frame */ { 0.0, 0.0, 0.0, 1.0},
62 /*light */ { 0.1, 0.1, 0.2, 1.0}
63 };
64
65 main->color_scheme->prelight = (Colors) {
66 /*fg */ { 0.0, 0.0, 0.0, 1.0},
67 /*bg */ { 0.25, 0.25, 0.25, 1.0},
68 /*base */ { 0.35, 0.13, 0.17, 1.0},
69 /*text */ { 0.0, 0.0, 0.0, 1.0},
70 /*shadow */ { 0.1, 0.1, 0.1, 0.4},
71 /*frame */ { 0.3, 0.3, 0.3, 1.0},
72 /*light */ { 0.3, 0.3, 0.3, 1.0}
73 };
74
75 main->color_scheme->selected = (Colors) {
76 /*fg */ { 0.0, 0.0, 0.0, 1.0},
77 /*bg */ { 0.9, 0.9, 0.9, 1.00 },
78 /*base */ { 0.35, 0.0, 0.0, 1.0},
79 /*text */ { 0.0, 0.0, 0.0, 1.0},
80 /*shadow */ { 0.0, 0.0, 0.0, 0.2},
81 /*frame */ { 0.18, 0.18, 0.18, 1.0},
82 /*light */ { 0.18, 0.18, 0.28, 1.0}
83 };
84
85 main->color_scheme->active = (Colors) {
86 /*fg */ { 0.0, 0.0, 0.0, 1.0},
87 /*bg */ { 0.9, 0.9, 0.9, 1.00 },
88 /*base */ { 0.35, 0.0, 0.0, 1.0},
89 /*text */ { 0.0, 0.0, 0.0, 1.0},
90 /*shadow */ { 0.18, 0.18, 0.18, 0.2},
91 /*frame */ { 0.18, 0.18, 0.18, 1.0},
92 /*light */ { 0.18, 0.18, 0.28, 1.0}
93 };
94 }
95
96 // draw the window
draw_my_window(void * w_,void * user_data)97 static void draw_my_window(void *w_, void* user_data) {
98 Widget_t *w = (Widget_t*)w_;
99 set_pattern(w,&w->app->color_scheme->selected,&w->app->color_scheme->normal,BACKGROUND_);
100 cairo_paint (w->crb);
101 set_pattern(w,&w->app->color_scheme->normal,&w->app->color_scheme->selected,BACKGROUND_);
102 cairo_set_line_width(w->crb,4);
103 cairo_rectangle (w->crb,4,4,w->width-8,w->height*0.48);
104 //cairo_set_source_rgb (w->crb, 0.6, 0.6, 0.6);
105 cairo_fill_preserve (w->crb);
106 cairo_set_source_rgb (w->crb, 0.0, 0.0, 0.0);
107 cairo_stroke(w->crb);
108
109 cairo_rectangle (w->crb,4,w->height*0.48,w->width-8,w->height*0.48);
110 cairo_stroke(w->crb);
111
112 cairo_text_extents_t extents;
113 use_text_color_scheme(w, get_color_state(w));
114 cairo_set_source_rgb (w->crb,0.0, 0.0, 0.0);
115 float font_size = min(20.0,((w->height/2.2 < (w->width*0.5)/3) ? w->height/2.2 : (w->width*0.5)/3));
116 cairo_set_font_size (w->crb, font_size);
117 cairo_text_extents(w->crb,w->label , &extents);
118 double tw = extents.width+60.0;
119 double th = extents.height;
120
121 widget_set_scale(w);
122 cairo_move_to (w->crb, w->scale.init_width-tw, 40 );
123 cairo_show_text(w->crb, w->label);
124 cairo_move_to (w->crb, w->scale.init_width-tw, 40+th );
125 cairo_set_font_size (w->crb, font_size*0.6);
126 cairo_show_text(w->crb, "HighGainAmplifier");
127 widget_reset_scale(w);
128 cairo_new_path (w->crb);
129 }
130
plugin_value_changed(X11_UI * ui,Widget_t * w,PortIndex index)131 void plugin_value_changed(X11_UI *ui, Widget_t *w, PortIndex index) {
132 // do special stuff when needed
133 }
134
plugin_set_window_size(int * w,int * h,const char * plugin_uri)135 void plugin_set_window_size(int *w,int *h,const char * plugin_uri) {
136 (*w) = 700; //set initial widht of main window
137 (*h) = 180; //set initial heigth of main window
138 }
139
plugin_set_name()140 const char* plugin_set_name() {
141 return "FatFrog"; //set plugin name to display on UI
142 }
143
plugin_create_controller_widgets(X11_UI * ui,const char * plugin_uri)144 void plugin_create_controller_widgets(X11_UI *ui, const char * plugin_uri) {
145 set_my_theme(&ui->main);
146 ui->win->func.expose_callback = draw_my_window;
147
148 ui->widget[0] = add_my_image_knob(ui->widget[0], VOLUME,"Volume", ui, 180, 100, 66, 66);
149 widget_get_png(ui->widget[0], LDVAR(knob_png));
150 set_adjustment(ui->widget[0]->adj,0.5, 0.5, 0.0, 1.0, 0.01, CL_CONTINUOS);
151
152 ui->widget[1] = add_my_image_knob(ui->widget[1], BASS,"Bass", ui, 280, 100, 66, 66);
153 widget_get_surface_ptr(ui->widget[1], ui->widget[0]);
154 set_adjustment(ui->widget[1]->adj,0.5, 0.5, 0.0, 1.0, 0.01, CL_CONTINUOS);
155
156 ui->widget[2] = add_my_image_knob(ui->widget[2], MIDDLE,"Middle", ui, 380, 100, 66, 66);
157 widget_get_surface_ptr(ui->widget[2], ui->widget[0]);
158 set_adjustment(ui->widget[2]->adj,0.5, 0.5, 0.0, 1.0, 0.01, CL_CONTINUOS);
159
160 ui->widget[3] = add_my_image_knob(ui->widget[3], TREBLE,"Treble", ui, 480, 100, 66, 66);
161 widget_get_surface_ptr(ui->widget[3], ui->widget[0]);
162 set_adjustment(ui->widget[3]->adj,0.5, 0.5, 0.0, 1.0, 0.01, CL_CONTINUOS);
163
164 ui->widget[4] = add_my_image_knob(ui->widget[4], MASTER,"Master", ui, 580, 100, 66, 66);
165 widget_get_surface_ptr(ui->widget[4], ui->widget[0]);
166 set_adjustment(ui->widget[4]->adj,0.5, 0.5, 0.0, 1.0, 0.01, CL_CONTINUOS);
167
168 ui->widget[5] = add_my_switch_image(ui->widget[5], BYPASS, "Off", ui,30, 96, 66, 70);
169 widget_get_png(ui->widget[5], LDVAR(pswitch_png));
170 strncpy(ui->widget[5]->input_label,"On",32);
171
172 ui->widget[6] = add_my_switch_image(ui->widget[6], BRIGHT, "Bright", ui,100, 96, 66, 70);
173 widget_get_surface_ptr(ui->widget[6], ui->widget[5]);
174 strncpy(ui->widget[6]->input_label,"Lead",32);
175 }
176
plugin_cleanup(X11_UI * ui)177 void plugin_cleanup(X11_UI *ui) {
178 // clean up used sources when needed
179 }
180
plugin_port_event(LV2UI_Handle handle,uint32_t port_index,uint32_t buffer_size,uint32_t format,const void * buffer)181 void plugin_port_event(LV2UI_Handle handle, uint32_t port_index,
182 uint32_t buffer_size, uint32_t format,
183 const void * buffer) {
184 X11_UI* ui = (X11_UI*)handle;
185 if (port_index == (uint32_t) BYPASS) ui->block_event = -1;
186 }
187
188