File: mainmenu.c

package info (click to toggle)
gramofile 1.6-11
  • links: PTS
  • area: main
  • in suites: buster, stretch
  • size: 1,436 kB
  • ctags: 1,125
  • sloc: ansic: 11,252; makefile: 60
file content (266 lines) | stat: -rw-r--r-- 5,664 bytes parent folder | download | duplicates (2)
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/* Main menu

 * Copyright (C) 1998 J.A. Bezemer
 *
 * Licensed under the terms of the GNU General Public License.
 * ABSOLUTELY NO WARRANTY.
 * See the file `COPYING' in this directory.
 */

/* Mouse support here only? Kinda confusing... So don't support mouse. */
#define DONT_USE_MOUSE

#include "mainmenu.h"
#include "reclp_main.h"
#include "textwindow.h"
#include "signpr_main.h"
#include "clrscr.h"
#include "helpline.h"
#include "errorwindow.h"
#include "playwav.h"
#include "tracksplit.h"
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#ifndef OLD_CURSES
#include <ncurses.h>
#else
#include <curses.h>
#endif


void
displaymenu_onscreen (char **options, char **helptext,
		      int number, int selected,
		      int y, int x, int distance)
{				/* (y,x): upper left position */
  int i;

  for (i = 0; i < number; i++)
    {
      mvprintw (y + i * distance, x, "%d.", i + 1);

      if (i == selected)
	attron (A_STANDOUT);
      mvaddstr (y + i * distance, x + 3, options[i]);
      if (i == selected)
	attroff (A_STANDOUT);
    }

  mvaddstr (16, 1, options[selected]);

  display_textwin (helptext[selected], 17, 2, 5, 76);

  move (0, 79);

  refresh ();
}


int
displaymenu (char **options, char **helptext, int number, int preselected)
/* Returns:  -1   if Escape pressed,
   >=0  Enter or 1..9 */
{
  int i;
  int selected;
  int exitfunc = 0;
  int in_ch;

#ifdef NCURSES_MOUSE_VERSION
  MEVENT mouse_event;
#endif

#ifdef NCURSES_MOUSE_VERSION
#ifndef DONT_USE_MOUSE
  mousemask (ALL_MOUSE_EVENTS, NULL);
#endif
#endif

  selected = preselected;

  do
    {
      displaymenu_onscreen (options, helptext, number, selected,
			    DISPLAYMENU_Y,
			    DISPLAYMENU_X,
			    DISPLAYMENU_DISTANCE);

      in_ch = getch ();

#ifdef NCURSES_MOUSE_VERSION
      if (in_ch == KEY_MOUSE)
	{
	  getmouse (&mouse_event);

	  if (mouse_event.bstate == BUTTON1_CLICKED
	      ||
	      mouse_event.bstate == BUTTON1_DOUBLE_CLICKED)
	    {
	      for (i = 0; i < number; i++)
		if (mouse_event.y == DISPLAYMENU_Y +
		    i * DISPLAYMENU_DISTANCE
		    &&
		    mouse_event.x >= DISPLAYMENU_X
		    &&
		    mouse_event.x < DISPLAYMENU_X + 3 +
		    strlen (options[i])
		  )
		  {
		    displaymenu_onscreen (options, helptext,
					  number,
					  i,
					  DISPLAYMENU_Y,
					  DISPLAYMENU_X,
					  DISPLAYMENU_DISTANCE);
		    usleep (100000);
		    selected = i;
		    exitfunc = TRUE;
		  }

	    }
	}
#endif /* NCURSES_MOUSE_VERSION */

      switch (in_ch)
	{
	case 'k':		/* Support some `less' keys. But only here... */
	case 'K':
	case KEY_UP:
	  selected--;
	  break;

	case 'j':
	case 'J':
	case KEY_DOWN:
	  selected++;
	  break;

	case 9:		/* TAB */
	  selected++;
	  if (selected >= number)
	    selected = 0;
	  break;

	case 13:		/* Enter/Return */
	case KEY_ENTER:
	  exitfunc = TRUE;
	  break;
	}

      if (in_ch >= '1' && in_ch <= '9')
	{
	  selected = in_ch - '1';
	  if (selected < number)
	    {
	      displaymenu_onscreen (options, helptext, number,
				    selected,
				    DISPLAYMENU_Y,
				    DISPLAYMENU_X,
				    DISPLAYMENU_DISTANCE);
	      usleep (100000);
	      exitfunc = TRUE;
	    }
	}

      if (selected < 0)
	selected = 0;
      if (selected >= number)
	selected = number - 1;

      if (in_ch == 27		/* Escape */
	  || in_ch == 'q' || in_ch == 'Q' || in_ch == '0')
	{
	  selected = -1;
	  exitfunc = TRUE;
	}
    }
  while (!exitfunc);

#ifdef NCURSES_MOUSE_VERSION
  mousemask (0, NULL);
#endif

  return selected;
}

void
mainmenu (char *startdir)
{
  int selected = 0;

#define MAINMENU_OPTIONS 6
  char *menu_options[MAINMENU_OPTIONS] =
  {
    "Record audio to a sound file           ",
    "[Copy sound from an audio CD to a file]",
    "Locate tracks                          ",
    "Process the audio signal               ",
    "[Write an audio CD]                    ",
    "Play a sound file                      "};

  char *menu_helptext[MAINMENU_OPTIONS]
  =
  {
    "With this option, audio from various sources (like gramophone records) \
can be recorded (sampled). The digital audio data is stored in a sound file \
(.wav format) on the harddisk.",

    "This option is not implemented yet. You can use the `cdda2wav' \
or `cdparanoia' program to copy digital audio from a CD to a sound file \
(.wav format) on the harddisk.",

    "The starts and ends of tracks in a large sound file can be \
detected automatically with this option. The `process signal' \
option uses the resulting .tracks file to actually split tracks.",

    "With this option, the digital audio from a sound file on the harddisk \
can be processed. For example, ticks may be filtered out. If track \
separation points are computed (previous option), separate audio files \
will be generated, each containing one track.",

    "This option is not implemented yet. You can use the `wodim' \
or `xcdroast' program to create CDs from sound files on the harddisk.",

    "(Parts of) sound files can be played with this option."
  };


  do
    {
      clearscreen ("Main Menu");
      helpline (
		 " Arrows/TAB: Navigate           Enter: Select option           0/Q/Escape: Exit ");

      selected = displaymenu (menu_options, menu_helptext,
			      MAINMENU_OPTIONS, selected);

      switch (selected)
	{
	case 0:
	  record_from_lp (startdir);
	  break;

	case 1:
	  error_window ("This option has not yet been implemented.");
	  break;

	case 2:
	  tracksplit_main (startdir);
	  break;

	case 3:
	  signproc_main (startdir);
	  break;

	case 4:
	  error_window ("This option has not yet been implemented.");
	  break;

	case 5:
	  playwav_main (startdir);
	  break;
	}
    }
  while (selected != -1);
}