1 /* Main menu
2
3 * Copyright (C) 1998 J.A. Bezemer
4 *
5 * Licensed under the terms of the GNU General Public License.
6 * ABSOLUTELY NO WARRANTY.
7 * See the file `COPYING' in this directory.
8 */
9
10 /* Mouse support here only? Kinda confusing... So don't support mouse. */
11 #define DONT_USE_MOUSE
12
13 #include "mainmenu.h"
14 #include "reclp_main.h"
15 #include "textwindow.h"
16 #include "signpr_main.h"
17 #include "clrscr.h"
18 #include "helpline.h"
19 #include "errorwindow.h"
20 #include "playwav.h"
21 #include "tracksplit.h"
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <string.h>
25 #ifndef OLD_CURSES
26 #include <ncurses.h>
27 #else
28 #include <curses.h>
29 #endif
30
31
32 void
displaymenu_onscreen(char ** options,char ** helptext,int number,int selected,int y,int x,int distance)33 displaymenu_onscreen (char **options, char **helptext,
34 int number, int selected,
35 int y, int x, int distance)
36 { /* (y,x): upper left position */
37 int i;
38
39 for (i = 0; i < number; i++)
40 {
41 mvprintw (y + i * distance, x, "%d.", i + 1);
42
43 if (i == selected)
44 attron (A_STANDOUT);
45 mvaddstr (y + i * distance, x + 3, options[i]);
46 if (i == selected)
47 attroff (A_STANDOUT);
48 }
49
50 mvaddstr (16, 1, options[selected]);
51
52 display_textwin (helptext[selected], 17, 2, 5, 76);
53
54 move (0, 79);
55
56 refresh ();
57 }
58
59
60 int
displaymenu(char ** options,char ** helptext,int number,int preselected)61 displaymenu (char **options, char **helptext, int number, int preselected)
62 /* Returns: -1 if Escape pressed,
63 >=0 Enter or 1..9 */
64 {
65 int i;
66 int selected;
67 int exitfunc = 0;
68 int in_ch;
69
70 #ifdef NCURSES_MOUSE_VERSION
71 MEVENT mouse_event;
72 #endif
73
74 #ifdef NCURSES_MOUSE_VERSION
75 #ifndef DONT_USE_MOUSE
76 mousemask (ALL_MOUSE_EVENTS, NULL);
77 #endif
78 #endif
79
80 selected = preselected;
81
82 do
83 {
84 displaymenu_onscreen (options, helptext, number, selected,
85 DISPLAYMENU_Y,
86 DISPLAYMENU_X,
87 DISPLAYMENU_DISTANCE);
88
89 in_ch = getch ();
90
91 #ifdef NCURSES_MOUSE_VERSION
92 if (in_ch == KEY_MOUSE)
93 {
94 getmouse (&mouse_event);
95
96 if (mouse_event.bstate == BUTTON1_CLICKED
97 ||
98 mouse_event.bstate == BUTTON1_DOUBLE_CLICKED)
99 {
100 for (i = 0; i < number; i++)
101 if (mouse_event.y == DISPLAYMENU_Y +
102 i * DISPLAYMENU_DISTANCE
103 &&
104 mouse_event.x >= DISPLAYMENU_X
105 &&
106 mouse_event.x < DISPLAYMENU_X + 3 +
107 strlen (options[i])
108 )
109 {
110 displaymenu_onscreen (options, helptext,
111 number,
112 i,
113 DISPLAYMENU_Y,
114 DISPLAYMENU_X,
115 DISPLAYMENU_DISTANCE);
116 usleep (100000);
117 selected = i;
118 exitfunc = TRUE;
119 }
120
121 }
122 }
123 #endif /* NCURSES_MOUSE_VERSION */
124
125 switch (in_ch)
126 {
127 case 'k': /* Support some `less' keys. But only here... */
128 case 'K':
129 case KEY_UP:
130 selected--;
131 break;
132
133 case 'j':
134 case 'J':
135 case KEY_DOWN:
136 selected++;
137 break;
138
139 case 9: /* TAB */
140 selected++;
141 if (selected >= number)
142 selected = 0;
143 break;
144
145 case 13: /* Enter/Return */
146 case KEY_ENTER:
147 exitfunc = TRUE;
148 break;
149 }
150
151 if (in_ch >= '1' && in_ch <= '9')
152 {
153 selected = in_ch - '1';
154 if (selected < number)
155 {
156 displaymenu_onscreen (options, helptext, number,
157 selected,
158 DISPLAYMENU_Y,
159 DISPLAYMENU_X,
160 DISPLAYMENU_DISTANCE);
161 usleep (100000);
162 exitfunc = TRUE;
163 }
164 }
165
166 if (selected < 0)
167 selected = 0;
168 if (selected >= number)
169 selected = number - 1;
170
171 if (in_ch == 27 /* Escape */
172 || in_ch == 'q' || in_ch == 'Q' || in_ch == '0')
173 {
174 selected = -1;
175 exitfunc = TRUE;
176 }
177 }
178 while (!exitfunc);
179
180 #ifdef NCURSES_MOUSE_VERSION
181 mousemask (0, NULL);
182 #endif
183
184 return selected;
185 }
186
187 void
mainmenu(char * startdir)188 mainmenu (char *startdir)
189 {
190 int selected = 0;
191
192 #define MAINMENU_OPTIONS 6
193 char *menu_options[MAINMENU_OPTIONS] =
194 {
195 "Record audio to a sound file ",
196 "[Copy sound from an audio CD to a file]",
197 "Locate tracks ",
198 "Process the audio signal ",
199 "[Write an audio CD] ",
200 "Play a sound file "};
201
202 char *menu_helptext[MAINMENU_OPTIONS]
203 =
204 {
205 "With this option, audio from various sources (like gramophone records) \
206 can be recorded (sampled). The digital audio data is stored in a sound file \
207 (.wav format) on the harddisk.",
208
209 "This option is not implemented yet. You can use the `cdda2wav' \
210 or `cdparanoia' program to copy digital audio from a CD to a sound file \
211 (.wav format) on the harddisk.",
212
213 "The starts and ends of tracks in a large sound file can be \
214 detected automatically with this option. The `process signal' \
215 option uses the resulting .tracks file to actually split tracks.",
216
217 "With this option, the digital audio from a sound file on the harddisk \
218 can be processed. For example, ticks may be filtered out. If track \
219 separation points are computed (previous option), separate audio files \
220 will be generated, each containing one track.",
221
222 "This option is not implemented yet. You can use the `cdrecord' \
223 or `xcdroast' program to create CDs from sound files on the harddisk.",
224
225 "(Parts of) sound files can be played with this option."
226 };
227
228
229 do
230 {
231 clearscreen ("Main Menu");
232 helpline (
233 " Arrows/TAB: Navigate Enter: Select option 0/Q/Escape: Exit ");
234
235 selected = displaymenu (menu_options, menu_helptext,
236 MAINMENU_OPTIONS, selected);
237
238 switch (selected)
239 {
240 case 0:
241 record_from_lp (startdir);
242 break;
243
244 case 1:
245 error_window ("This option has not yet been implemented.");
246 break;
247
248 case 2:
249 tracksplit_main (startdir);
250 break;
251
252 case 3:
253 signproc_main (startdir);
254 break;
255
256 case 4:
257 error_window ("This option has not yet been implemented.");
258 break;
259
260 case 5:
261 playwav_main (startdir);
262 break;
263 }
264 }
265 while (selected != -1);
266 }
267