Debian Codegraph @

contrib/pos/pos.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 TITLE "<silence>"
25
26 FL_FORM *form;
27 FL_OBJECT *window, *slider;
28
29 typedef struct
30 {
31 int id;
32 char name[1024];
33 double position;
34 double seconds;
35 }
36 SOUND;
37
38 #define MAX_SOUNDS 12
39 SOUND sounds[MAX_SOUNDS];
40
41 #define SOUND_INIT(i)\
42 sounds[i].id = 0; \
43 sounds[i].name[0] = '\0'; \
44 sounds[i].position = 0; \
45 sounds[i].seconds = 0;
46
47 double max_seconds = 0.0;
48
49 void do_form ();
50 void do_rptp ();
51 void event_callback (int fd, int event, char *line);
52 void set_title (char *title);
53
54 main (int argc, char **argv)
55 {
56 #if 1
57 fl_flip_yorigin ();
58 fl_initialize (&argc, argv, "POS", 0, 0);
59 #else
60 fl_initialize (argv[0], "??", 0, 0, &argc, argv);
61 #endif
62 do_form ();
63 do_rptp ();
64 rptp_main_loop ();
65 }
66
67 void
68 do_form ()
69 {
70 int i;
71
72 #define W 300
73 #define H 50
74
75 form = fl_bgn_form (FL_NO_BOX, W, H);
76 window = fl_add_box (FL_UP_BOX, 0, 0, W, H, "");
77 slider = fl_add_valslider (FL_HOR_FILL_SLIDER, 0, 0, W, H, "");
78 /* fl_set_object_align (slider, FL_ALIGN_LEFT); */
79 fl_set_object_color (slider, FL_COL1, FL_GREEN);
80 fl_set_slider_bounds (slider, 0.0, 1.0);
81 fl_set_slider_value (slider, 0.0);
82
83 for (i = 0; i < MAX_SOUNDS; i++)
84 {
85 SOUND_INIT(i);
86 }
87
88 fl_end_form ();
89 fl_show_form (form, FL_FREE_SIZE, FL_FULLBORDER, TITLE);
90 fl_check_forms ();
91 }
92
93 void
94 do_rptp ()
95 {
96 char buf[RPTP_MAX_LINE];
97 int fd;
98
99 fd = rptp_open (rplay_default_host (), RPTP_PORT, buf, sizeof (buf));
100 rptp_async_notify (fd, RPTP_EVENT_POSITION|RPTP_EVENT_PLAY|RPTP_EVENT_DONE|RPTP_EVENT_CLOSE, event_callback);
101 rptp_async_putline (fd, NULL, "set notify-rate=1.0");
102 }
103
104 void
105 event_callback (int fd, int event, char *line)
106 {
107 FL_OBJECT *obj;
108 double position, seconds;
109 char *sec;
110 char buf[RPTP_MAX_LINE];
111 int i, j, id, max_index;
112
113 rptp_parse (line, 0);
114 id = atoi (1 + rptp_parse (0, "id"));
115
116 switch (event)
117 {
118 case RPTP_EVENT_PLAY:
119 for (i = 0; i < MAX_SOUNDS; i++)
120 {
121 if (sounds[i].id == 0)
122 {
123 sscanf (rptp_parse (0, "seconds"), "%lf", &seconds);
124 sounds[i].id = id;
125 sounds[i].seconds = seconds;
126 strcpy (sounds[i].name, rptp_parse (0, "sound"));
127
128 if (seconds > max_seconds)
129 {
130 max_seconds = seconds;
131 fl_set_slider_bounds (slider, 0.0, max_seconds);
132 fl_set_slider_value (slider, 0.0);
133 set_title (sounds[i].name);
134 }
135 break;
136 }
137 }
138 break;
139
140 case RPTP_EVENT_DONE:
141 for (i = 0; i < MAX_SOUNDS; i++)
142 {
143 if (sounds[i].id == id && sounds[i].seconds == max_seconds)
144 {
145 max_seconds = 0.0;
146 max_index = -1;
147 for (j = 0; j < MAX_SOUNDS; j++)
148 {
149 if (j == i)
150 {
151 continue;
152 }
153 if (sounds[j].seconds > max_seconds)
154 {
155 max_seconds = sounds[j].seconds;
156 max_index = j;
157 }
158 }
159 if (max_index == -1)
160 {
161 fl_set_slider_bounds (slider, 0.0, 1.0);
162 fl_set_slider_value (slider, 0.0);
163 set_title (TITLE);
164 }
165 else
166 {
167 fl_set_slider_bounds (slider, 0.0, sounds[max_index].seconds);
168 fl_set_slider_value (slider, sounds[max_index].position);
169 set_title (sounds[max_index].name);
170 }
171 SOUND_INIT(i);
172 break;
173 }
174 }
175 break;
176
177 case RPTP_EVENT_POSITION:
178 for (i = 0; i < MAX_SOUNDS; i++)
179 {
180 if (sounds[i].id == id && sounds[i].seconds == max_seconds)
181 {
182 sscanf (rptp_parse (0, "position"), "%lf", &position);
183 fl_set_slider_value (slider, position);
184 break;
185 }
186 }
187 break;
188
189 case RPTP_EVENT_CLOSE:
190 exit (1);
191 }
192
193 obj = fl_check_forms ();
194 }
195
196 void
197 set_title (char *title)
198 {
199 XTextProperty windowName;
200
201 XStringListToTextProperty(&title, 1, &windowName);
202 XSetWMName(fl_display, form->window, &windowName);
203 XFlush (fl_display);
204 }