summaryrefslogtreecommitdiff
path: root/src/win_main.c
blob: 01d556143a17e892fd75e69df7ae79cbacdde9df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
    Instru2Light - Illumine un instrument de musique en temps réel
    Copyright (C) 2012 Ludovic Pouzenc <lpouzenc@gmail.com>    

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "win_main.h"
#include "gtkvumeter.h"

#define FUNC_COUNT 4

GtkBuilder *builder=NULL;
GtkWidget *vumeter_sound, *vumeter_r, *vumeter_g, *vumeter_b, *vumeter_h, *vumeter_s, *vumeter_v;

void add_custom_widgets();

// Applicative actions
void switch_to_func(gint func_id) {
	printf("switch_to_func(%i)\n", func_id);
}

// GUI events
void on_win_main_destroy(GtkObject *object, gpointer user_data) {
	gtk_main_quit();
}

void on_mi_about_activate(GtkObject *object, gpointer user_data) {
	GtkDialog *dialog;

	g_return_if_fail(builder!=NULL);

	dialog = GTK_DIALOG(gtk_builder_get_object(builder, "win_about"));
	g_return_if_fail(dialog!=NULL);

	g_signal_connect_swapped (dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog);
	gtk_widget_show_all(GTK_WIDGET(dialog));
}

void on_action1_activate(GtkObject *object, gpointer user_data) { switch_to_func(0); }
void on_action2_activate(GtkObject *object, gpointer user_data) { switch_to_func(1); }
void on_action3_activate(GtkObject *object, gpointer user_data) { switch_to_func(2); }
void on_action4_activate(GtkObject *object, gpointer user_data) { switch_to_func(3); }


void on_radbut_func_realize(GtkObject *object, gpointer user_data) {
	// This makes the radio buttons look like a Toogle Button (that's a fucking trick)
	gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(object),FALSE);
}

GtkWidget *win_main_build() {
	GtkWidget *window;
	
	builder = gtk_builder_new();
	gtk_builder_add_from_file(builder, "gui.glade", NULL);
	
	window = GTK_WIDGET(gtk_builder_get_object(builder, "win_main"));
	gtk_builder_connect_signals(builder, NULL);

	add_custom_widgets();
	//FIXME : to be done at the right place
	//g_object_unref(G_OBJECT(builder));
	return window;
}

void add_custom_widgets() {
	GtkContainer *c;
	GdkColor f_gradient_red[2] = {{0,65535,0,0},{0,32767,0,0}};
	GdkColor b_gradient_red[2] = {{0,49151,0,0},{0,24575,0,0}};
	GdkColor f_gradient_green[2] = {{0,0,65535,0},{0,0,32767,0}};
	GdkColor b_gradient_green[2] = {{0,0,49151,0},{0,0,24575,0}};
	GdkColor f_gradient_blue[2] = {{0,0,0,65535},{0,0,0,32767}};
	GdkColor b_gradient_blue[2] = {{0,0,0,49151},{0,0,0,24575}};
	GdkColor f_gradient_hue[7] = {{0,65535,0,0},{0,65535,0,65535},{0,0,0,65535},{0,0,65535,65535},{0,0,65535,0},{0,65535,65535,0},{0,65535,0,0}};
	GdkColor b_gradient_hue[7] = {{0,49151,0,0},{0,49151,0,49151},{0,0,0,49151},{0,0,49151,49151},{0,0,49151,0},{0,49151,49151,0},{0,49151,0,0}};
	GdkColor f_gradient_value[2] = {{0,65535,0,0},{0,16384,0,0}};
	GdkColor b_gradient_value[2] = {{0,49151,0,0},{0,0,0,0}};
	GdkColor f_gradient_saturation[2] = {{0,32767,0,0},{0,32767,32767,32767}};
	GdkColor b_gradient_saturation[2] = {{0,24575,0,0},{0,24575,24575,24575}};

	vumeter_sound = gtk_vu_meter_new(TRUE);
	gtk_vu_meter_set_min_max(GTK_VU_METER(vumeter_sound), -50, 0);
	c=GTK_CONTAINER(gtk_builder_get_object(builder, "a_in_sound"));
	gtk_container_add(c,vumeter_sound);

	vumeter_h = gtk_vu_meter_new (TRUE);
	gtk_vu_meter_set_min_max(GTK_VU_METER(vumeter_h), 0, 255);
	gtk_vu_meter_set_gradient(GTK_VU_METER(vumeter_h), 7, f_gradient_hue, 7, b_gradient_hue);
	vumeter_s = gtk_vu_meter_new (TRUE);
	gtk_vu_meter_set_min_max(GTK_VU_METER(vumeter_s), 0, 255);
	gtk_vu_meter_set_gradient(GTK_VU_METER(vumeter_s), 2, f_gradient_value, 2, b_gradient_value);
	vumeter_v = gtk_vu_meter_new (TRUE);
	gtk_vu_meter_set_min_max(GTK_VU_METER(vumeter_v), 0, 255);
	gtk_vu_meter_set_gradient(GTK_VU_METER(vumeter_v), 2, f_gradient_saturation, 2, b_gradient_saturation);
	c=GTK_CONTAINER(gtk_builder_get_object(builder, "hb_out_hsv"));
	gtk_container_add(c,vumeter_h);
	gtk_container_add(c,vumeter_s);
	gtk_container_add(c,vumeter_v);

	vumeter_r = gtk_vu_meter_new (TRUE);
	gtk_vu_meter_set_min_max(GTK_VU_METER(vumeter_r), 0, 255);
	gtk_vu_meter_set_gradient(GTK_VU_METER(vumeter_r), 2, f_gradient_red, 2, b_gradient_red);
	vumeter_g = gtk_vu_meter_new (TRUE);
	gtk_vu_meter_set_min_max(GTK_VU_METER(vumeter_g), 0, 255);
	gtk_vu_meter_set_gradient(GTK_VU_METER(vumeter_g), 2, f_gradient_green, 2, b_gradient_green);
	vumeter_b = gtk_vu_meter_new (TRUE);
	gtk_vu_meter_set_min_max(GTK_VU_METER(vumeter_b), 0, 255);
	gtk_vu_meter_set_gradient(GTK_VU_METER(vumeter_b), 2, f_gradient_blue, 2, b_gradient_blue);
	c=GTK_CONTAINER(gtk_builder_get_object(builder, "hb_out_rgb"));
	gtk_container_add(c,vumeter_r);
	gtk_container_add(c,vumeter_g);
	gtk_container_add(c,vumeter_b);
}

gboolean win_main_update_vumeters(gpointer vals) {
	gtk_vu_meter_set_level(GTK_VU_METER(vumeter_sound), ((gint*)vals)[0]);
	gtk_vu_meter_set_level(GTK_VU_METER(vumeter_h), ((gint*)vals)[1]);
	gtk_vu_meter_set_level(GTK_VU_METER(vumeter_s), ((gint*)vals)[2]);
	gtk_vu_meter_set_level(GTK_VU_METER(vumeter_v), ((gint*)vals)[3]);
	gtk_vu_meter_set_level(GTK_VU_METER(vumeter_r), ((gint*)vals)[4]);
	gtk_vu_meter_set_level(GTK_VU_METER(vumeter_g), ((gint*)vals)[5]);
	gtk_vu_meter_set_level(GTK_VU_METER(vumeter_b), ((gint*)vals)[6]);
	return TRUE;
}