1 /*
2  *                           0BSD
3  *
4  *                    BSD Zero Clause License
5  *
6  *  Copyright (c) 2019 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 #include "lv2/lv2plug.in/ns/lv2core/lv2.h"
23 #include "lv2/lv2plug.in/ns/extensions/ui/ui.h"
24 
25 // xwidgets.h includes xputty.h and all defined widgets from Xputty
26 #include "xwidgets.h"
27 
28 #pragma once
29 
30 #ifndef LV2_PLUGIN_H_
31 #define LV2_PLUGIN_H_
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 // struct to define the knob pattern colors
38 typedef struct {
39     double p1f[4];
40     double p2f[4];
41     double p3f[4];
42     double p4f[4];
43     double p5f[4];
44     double p1k[4];
45     double p2k[4];
46     double p3k[4];
47     double p4k[4];
48     double p5k[4];
49 } KnobColors;
50 
51 
52 // main window struct
53 typedef struct {
54     void *parentXwindow;
55     Xputty main;
56     Widget_t *win;
57     Widget_t *widget[CONTROLS];
58     KnobColors *kp;
59     void *private_ptr;
60     int block_event;
61     int need_resize;
62 
63     void *controller;
64     LV2UI_Write_Function write_function;
65     LV2UI_Resize* resize;
66 } X11_UI;
67 
68 // controller value changed, forward value to host when needed
69 void plugin_value_changed(X11_UI *ui, Widget_t *w, PortIndex index);
70 
71 // set the plugin initial window size
72 void plugin_set_window_size(int *w,int *h,const char * plugin_uri);
73 
74 // set the plugin name
75 const char* plugin_set_name();
76 
77 // create all needed controller
78 void plugin_create_controller_widgets(X11_UI *ui, const char * plugin_uri);
79 
80 // add a knob to the main window
81 Widget_t* add_my_knob(Widget_t *w, PortIndex index, const char * label,
82                                 X11_UI* ui, int x, int y, int width, int height);
83 
84 // add a image knob to the main window
85 Widget_t* add_my_image_knob(Widget_t *w, PortIndex index, const char * label,
86                                 X11_UI* ui, int x, int y, int width, int height);
87 
88 // add a image knob with value to the main window
89 Widget_t* add_my_value_knob(Widget_t *w, PortIndex index, const char * label,
90                                 X11_UI* ui, int x, int y, int width, int height);
91 // add a image toggle button to the main window
92 Widget_t* add_my_switch_image(Widget_t *w, PortIndex index, const char * label,
93                                 X11_UI* ui, int x, int y, int width, int height);
94 
95 // add a combobox to the main window
96 Widget_t* add_my_combobox(Widget_t *w, PortIndex index, const char * label, const char** items,
97                                 size_t len, int active, X11_UI* ui, int x, int y, int width, int height);
98 
99 // free used mem on exit
100 void plugin_cleanup(X11_UI *ui);
101 
102 // controller value changed message from host
103 void plugin_port_event(LV2UI_Handle handle, uint32_t port_index,
104                         uint32_t buffer_size, uint32_t format,
105                         const void * buffer);
106 #ifdef __cplusplus
107 }
108 #endif
109 
110 #endif //LV2_PLUGIN_H_
111