1 /*
2  * Copyright (C) 2020 Hermann Meyer, Andreas Degert
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  * --------------------------------------------------------------------------
18  */
19 
20 /*---------------------------------------------------------------------
21 -----------------------------------------------------------------------
22                 define PortIndex and plugin uri
23 -----------------------------------------------------------------------
24 ----------------------------------------------------------------------*/
25 
26 #include "gx_studiopre_st.h"
27 
28 /*---------------------------------------------------------------------
29 -----------------------------------------------------------------------
30                 define controller numbers
31 -----------------------------------------------------------------------
32 ----------------------------------------------------------------------*/
33 
34 #define CONTROLS 12
35 
36 /*---------------------------------------------------------------------
37 -----------------------------------------------------------------------
38                 include the LV2 interface
39 -----------------------------------------------------------------------
40 ----------------------------------------------------------------------*/
41 
42 #include "lv2_plugin.cc"
43 
44 /*---------------------------------------------------------------------
45 -----------------------------------------------------------------------
46                 define the plugin settings
47 -----------------------------------------------------------------------
48 ----------------------------------------------------------------------*/
49 
50 typedef struct {
51     cairo_surface_t *screw;
52     cairo_surface_t *logo;
53 } X11_UI_Private_t;
54 
55 // setup a color theme
set_my_theme(Xputty * main)56 static void set_my_theme(Xputty *main) {
57     main->color_scheme->normal = (Colors) {
58          /* cairo    / r  / g  / b  / a  /  */
59         .fg =       { 0.85, 0.85, 0.85, 1.00},
60         .bg =       { 0.1, 0.1, 0.1, 1.0},
61         .base =     { 0.1, 0.1, 0.1, 1.0},
62         .text =     { 0.85, 0.85, 0.85, 1.00},
63         .shadow =   { 0.1, 0.1, 0.1, 0.2},
64         .frame =    { 0.0, 0.0, 0.0, 1.0},
65         .light =    { 0.1, 0.1, 0.1, 1.0}
66     };
67 
68     main->color_scheme->prelight = (Colors) {
69         .fg =       { 1.0, 1.0, 1.0, 1.0},
70         .bg =       { 0.25, 0.25, 0.25, 1.0},
71         .base =     { 0.2, 0.2, 0.2, 1.0},
72         .text =     { 0.7, 0.7, 0.7, 1.0},
73         .shadow =   { 0.1, 0.1, 0.1, 0.4},
74         .frame =    { 0.3, 0.3, 0.3, 1.0},
75         .light =    { 0.3, 0.3, 0.3, 1.0}
76     };
77 
78     main->color_scheme->selected = (Colors) {
79         .fg =       { 0.9, 0.9, 0.9, 1.0},
80         .bg =       { 0.2, 0.2, 0.2, 1.0},
81         .base =     { 0.1, 0.1, 0.1, 1.0},
82         .text =     { 1.0, 1.0, 1.0, 1.0},
83         .shadow =   { 0.18, 0.18, 0.18, 0.2},
84         .frame =    { 0.18, 0.18, 0.18, 1.0},
85         .light =    { 0.18, 0.18, 0.28, 1.0}
86     };
87 }
88 
89 // draw the window
draw_my_window(void * w_,void * user_data)90 static void draw_my_window(void *w_, void* user_data) {
91     Widget_t *w = (Widget_t*)w_;
92     X11_UI* ui = (X11_UI*)w->parent_struct;
93     X11_UI_Private_t *ps = (X11_UI_Private_t*)ui->private_ptr;
94     widget_set_scale(w);
95     cairo_set_source_surface (w->crb, w->image,0,0);
96     cairo_paint (w->crb);
97 
98     cairo_set_source_surface (w->crb, ps->logo,35,40);
99     cairo_paint (w->crb);
100 
101     cairo_set_source_surface (w->crb, ps->screw,10,10);
102     cairo_paint (w->crb);
103     cairo_set_source_surface (w->crb, ps->screw,10,w->scale.init_height-34);
104     cairo_paint (w->crb);
105     cairo_set_source_surface (w->crb, ps->screw,w->scale.init_width-34,w->scale.init_height-34);
106     cairo_paint (w->crb);
107     cairo_set_source_surface (w->crb, ps->screw,w->scale.init_width-34,10);
108     cairo_paint (w->crb);
109     widget_reset_scale(w);
110 }
111 
plugin_value_changed(X11_UI * ui,Widget_t * w,PortIndex index)112 void plugin_value_changed(X11_UI *ui, Widget_t *w, PortIndex index) {
113     // do special stuff when needed
114 }
115 
plugin_set_window_size(int * w,int * h,const char * plugin_uri)116 void plugin_set_window_size(int *w,int *h,const char * plugin_uri) {
117     (*w) = 1000; //initial width of main window
118     (*h) = 100; //initial height of main window
119 }
120 
plugin_set_name()121 const char* plugin_set_name() {
122     return "GxStudioPreSt"; //plugin name to display on UI
123 }
124 
plugin_create_controller_widgets(X11_UI * ui,const char * plugin_uri)125 void plugin_create_controller_widgets(X11_UI *ui, const char * plugin_uri) {
126     set_my_theme(&ui->main);
127     widget_get_png(ui->win, LDVAR(studiopre_png));
128     X11_UI_Private_t *ps =(X11_UI_Private_t*)malloc(sizeof(X11_UI_Private_t));;
129     ps->screw = surface_get_png(ui->win,ps->screw,LDVAR(screwhead_png));
130     ps->logo = surface_get_png(ui->win,ps->logo,LDVAR(redeyelogo_png));
131     ui->private_ptr = (void*)ps;
132     ui->win->func.expose_callback = draw_my_window;
133 
134     ui->widget[0] = add_my_switch_image(ui->widget[0], BRIGHT_L, "Bright", ui,165, 15, 64, 74);
135     widget_get_png(ui->widget[0], LDVAR(switch_png));
136 
137     ui->widget[1] = add_my_image_knob(ui->widget[1], VOLUME_L,"Volume", ui,220, 15, 64, 74);
138     set_adjustment(ui->widget[1]->adj,0.5, 0.5, 0.0, 1.0, 0.01, CL_CONTINUOS);
139     widget_get_png(ui->widget[1], LDVAR(studiopreknob_png));
140 
141     ui->widget[2] = add_my_image_knob(ui->widget[2], BASS_L,"Bass", ui,290, 15, 64, 74);
142     set_adjustment(ui->widget[2]->adj,0.5, 0.5, 0.0, 1.0, 0.01, CL_CONTINUOS);
143     widget_get_surface_ptr(ui->widget[2], ui->widget[1]);
144 
145     ui->widget[3] = add_my_image_knob(ui->widget[3], MIDDLE_L,"Middle", ui,360, 15, 64, 74);
146     set_adjustment(ui->widget[3]->adj,0.5, 0.5, 0.0, 1.0, 0.01, CL_CONTINUOS);
147     widget_get_surface_ptr(ui->widget[3], ui->widget[1]);
148 
149     ui->widget[4] = add_my_image_knob(ui->widget[4], TREBLE_L,"Treble", ui,430, 15, 64, 74);
150     set_adjustment(ui->widget[4]->adj,0.5, 0.5, 0.0, 1.0, 0.01, CL_CONTINUOS);
151     widget_get_surface_ptr(ui->widget[4], ui->widget[1]);
152 
153     ui->widget[5] = add_my_image_knob(ui->widget[5], MASTER_L,"Master", ui, 500, 15, 64, 74);
154     set_adjustment(ui->widget[5]->adj,0.5, 0.5, 0.0, 1.0, 0.01, CL_CONTINUOS);
155     widget_get_surface_ptr(ui->widget[5], ui->widget[1]);
156 
157     ui->widget[6] = add_my_switch_image(ui->widget[6], BRIGHT_R, "Bright", ui,565, 15, 64, 74);
158     widget_get_surface_ptr(ui->widget[6], ui->widget[0]);
159 
160     ui->widget[7] = add_my_image_knob(ui->widget[7], VOLUME_R,"Volume", ui,620, 15, 64, 74);
161     set_adjustment(ui->widget[7]->adj,0.5, 0.5, 0.0, 1.0, 0.01, CL_CONTINUOS);
162     widget_get_surface_ptr(ui->widget[7], ui->widget[1]);
163 
164     ui->widget[8] = add_my_image_knob(ui->widget[8], BASS_R,"Bass", ui,690, 15, 64, 74);
165     set_adjustment(ui->widget[8]->adj,0.5, 0.5, 0.0, 1.0, 0.01, CL_CONTINUOS);
166     widget_get_surface_ptr(ui->widget[8], ui->widget[1]);
167 
168     ui->widget[9] = add_my_image_knob(ui->widget[9], MIDDLE_R,"Middle", ui,760, 15, 64, 74);
169     set_adjustment(ui->widget[9]->adj,0.5, 0.5, 0.0, 1.0, 0.01, CL_CONTINUOS);
170     widget_get_surface_ptr(ui->widget[9], ui->widget[1]);
171 
172     ui->widget[10] = add_my_image_knob(ui->widget[10], TREBLE_R,"Treble", ui,830, 15, 64, 74);
173     set_adjustment(ui->widget[10]->adj,0.5, 0.5, 0.0, 1.0, 0.01, CL_CONTINUOS);
174     widget_get_surface_ptr(ui->widget[10], ui->widget[1]);
175 
176     ui->widget[11] = add_my_image_knob(ui->widget[11], MASTER_R,"Master", ui,900, 15, 64, 74);
177     set_adjustment(ui->widget[11]->adj,0.5, 0.5, 0.0, 1.0, 0.01, CL_CONTINUOS);
178     widget_get_surface_ptr(ui->widget[11], ui->widget[1]);
179 
180 }
181 
plugin_cleanup(X11_UI * ui)182 void plugin_cleanup(X11_UI *ui) {
183     X11_UI_Private_t *ps = (X11_UI_Private_t*)ui->private_ptr;
184     cairo_surface_destroy(ps->screw);
185     cairo_surface_destroy(ps->logo);
186     free(ps);
187     ui->private_ptr = NULL;
188 }
189 
plugin_port_event(LV2UI_Handle handle,uint32_t port_index,uint32_t buffer_size,uint32_t format,const void * buffer)190 void plugin_port_event(LV2UI_Handle handle, uint32_t port_index,
191                         uint32_t buffer_size, uint32_t format,
192                         const void * buffer) {
193 }
194