Debian Codegraph @

contrib/vu/vu.c

raw symbols SCIP
1 /*
2 * Copyright (C) 1995 Mark Boyns <[email protected]>
3 *
4 * This file is part of rplay.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include <X11/forms.h>
22 #include <rplay.h>
23
24 #define NBOXES 8
25
26 typedef struct
27 {
28 FL_OBJECT *obj;
29 int level;
30 FL_PD_COL color;
31 } BOX;
32
33 FL_FORM *form;
34 FL_OBJECT *w, *input;
35
36 BOX left[] =
37 {
38 { 0, 0, FL_GREEN },
39 { 0, 32, FL_GREEN },
40 { 0, 64, FL_GREEN },
41 { 0, 96, FL_GREEN },
42 { 0, 128, FL_YELLOW },
43 { 0, 160, FL_YELLOW },
44 { 0, 192, FL_RED },
45 { 0, 224, FL_RED }
46 };
47 BOX right[] =
48 {
49 { 0, 0, FL_GREEN },
50 { 0, 32, FL_GREEN },
51 { 0, 64, FL_GREEN },
52 { 0, 96, FL_GREEN },
53 { 0, 128, FL_YELLOW },
54 { 0, 160, FL_YELLOW },
55 { 0, 192, FL_RED },
56 { 0, 224, FL_RED }
57 };
58
59 int stereo = 1;
60 float scale = 1.0;
61
62 void do_form ();
63 void do_rptp ();
64 void event_callback (int fd, int event, char *line);
65
66 main (int argc, char **argv)
67 {
68 #if 1
69 fl_flip_yorigin ();
70 fl_initialize (&argc, argv, "VU", 0, 0);
71 #else
72 fl_initialize (argv[0], "VU", 0, 0, &argc, argv);
73 #endif
74 do_form ();
75 do_rptp ();
76 rptp_main_loop ();
77 }
78
79 void
80 do_form ()
81 {
82 int i, width, x, y;
83
84 if (stereo)
85 {
86 width = 200;
87 }
88 else
89 {
90 width = 100;
91 }
92
93 form = fl_bgn_form (FL_NO_BOX, width, 260);
94 w = fl_add_box (FL_UP_BOX, 0, 0, width, 260, "");
95 input = fl_add_input (FL_HIDDEN_INPUT, 0, 0, width, 260, "");
96 fl_set_input_return (input, FL_RETURN_ALWAYS);
97 fl_set_input (input, "");
98
99 x = 10;
100 y = 10;
101 for (i = 0; i < NBOXES; i++, y += 30)
102 {
103 left[i].obj = fl_add_box (FL_DOWN_BOX, x, y, 80, 30, "");
104 if (stereo)
105 {
106 right[i].obj = fl_add_box (FL_DOWN_BOX, 100+x, y, 80, 30, "");
107 }
108 }
109
110 fl_end_form ();
111 fl_show_form (form, FL_FREE_SIZE, FL_FULLBORDER, "VU");
112 fl_check_forms ();
113 }
114
115 void
116 do_rptp ()
117 {
118 char buf[RPTP_MAX_LINE];
119 int fd;
120
121 fd = rptp_open (rplay_default_host (), RPTP_PORT, buf, sizeof (buf));
122 rptp_async_notify (fd, RPTP_EVENT_LEVEL|RPTP_EVENT_CLOSE, event_callback);
123 }
124
125 void
126 event_callback (int fd, int event, char *line)
127 {
128 FL_OBJECT *obj;
129 int left_level, right_level, i;
130
131 switch (event)
132 {
133 case RPTP_EVENT_LEVEL:
134 left_level = atoi (rptp_parse (line, "left"));
135 right_level = atoi (rptp_parse (0, "right"));
136
137 for (i = 0; i < NBOXES; i++)
138 {
139 if (left_level > left[i].level)
140 {
141 fl_set_object_color (left[i].obj, left[i].color, FL_COL1);
142 }
143 else
144 {
145 fl_set_object_color (left[i].obj, FL_COL1, FL_COL1);
146 }
147 if (stereo)
148 {
149 if (right_level > right[i].level)
150 {
151 fl_set_object_color (right[i].obj, right[i].color, FL_COL1);
152 }
153 else
154 {
155 fl_set_object_color (right[i].obj, FL_COL1, FL_COL1);
156 }
157 }
158 }
159 break;
160
161 case RPTP_EVENT_CLOSE:
162 exit (1);
163 }
164
165 obj = fl_check_forms ();
166 if (obj == input)
167 {
168 float new_scale = scale;
169 char *key = fl_get_input (obj);
170 if (*key == '<')
171 {
172 new_scale *= 0.8;
173 }
174 else if (*key == '>')
175 {
176 new_scale *= (1/0.8);
177 }
178 if (new_scale != scale)
179 {
180 fl_scale_form (form, new_scale/scale, new_scale/scale);
181 scale = new_scale;
182 }
183 fl_set_input (input, "");
184 }
185 }
186
187