File: signpr_filtmenu.c

package info (click to toggle)
gramofile 1.6-7
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 840 kB
  • ctags: 538
  • sloc: ansic: 10,238; makefile: 55
file content (612 lines) | stat: -rw-r--r-- 14,701 bytes parent folder | download | duplicates (6)
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
/* Signal Processing - Filter 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.
 */

#include "signpr_filtmenu.h"
#include "signpr_general.h"
#include "buttons.h"
#include "boxes.h"
#include "helpline.h"
#include "clrscr.h"
#include "errorwindow.h"
#include "stringinput.h"
#include "secshms.h"
#include <stdlib.h>
#include <string.h>
#ifndef OLD_CURSES
#include <ncurses.h>
#else
#include <curses.h>
#endif


int
signproc_select_filters (scrollmenu_t * filtlist,
			 int *filtnumbers,
			 char **helptexts,
			 scrollmenu_t * selectedfilts,
			 int *usetracktimes, int *usebeginendtime,
			 double *begintime, double *endtime)
/* Returns 0: canceled, 1: PrevScreen, 2: NextScreen */
{
  button_t next_button, cancel_button, prev_button;
  button_t beginend_check, tracktimes_check;
  stringinput_t begintimestring, endtimestring;
  int dont_stop = TRUE;
  int returnval = 0;
  int focus = 0;
  int in_ch;
  int i;
  double tempdouble = 0;
  char tempstring[250];

  char *emptyhelpline =
  "                                                                TAB: Next field";

  int maxhelplength = 62;
  char helphelpline[100];

  char *helplines[9] =
  {
    " Enter: Add selected filter.                                    TAB: Next field",
    " Enter: Parameters   U/D: Move   R/Del: Delete                  TAB: Next field",
    " Use the .tracks file to split tracks.                          TAB: Next field",
    " Process only the specified part of the sound.                  TAB: Next field",
    " Enter begin time of part to be processed.                      TAB: Next field",
    " Enter end time of part to be processed.                        TAB: Next field",
    " To Signal Processing - Source File.                            TAB: Next field",
    " Back to main menu.                                             TAB: Next field",
    " To Signal Processing - Destination File.                       TAB: Next field"};

  char *helpcharptr;
  int helpint;
  parampointer_t helpparampointer;


  filtlist->y = 3;
  filtlist->x = 5;
  filtlist->h = 12;
  filtlist->w = 32;
  filtlist->firstonscreen = 0;
  filtlist->selected = 0;

  selectedfilts->y = 3;
  selectedfilts->x = 43;
  selectedfilts->h = 12;
  selectedfilts->w = 32;
  selectedfilts->firstonscreen = 0;
  selectedfilts->selected = 0;


  begintimestring.maxlen = 500;
  begintimestring.string = (char *) malloc (
				    begintimestring.maxlen * sizeof (char));
  fsec2hmsf (*begintime, begintimestring.string);
  begintimestring.y = 17;
  begintimestring.x = 59;
  begintimestring.w = 18;
  begintimestring.cursorpos = strlen (begintimestring.string);
  begintimestring.firstcharonscreen = 0;

  endtimestring.maxlen = 500;
  endtimestring.string = (char *) malloc (
				      endtimestring.maxlen * sizeof (char));
  fsec2hmsf (*endtime, endtimestring.string);
  endtimestring.y = 18;
  endtimestring.x = 59;
  endtimestring.w = 18;
  endtimestring.cursorpos = strlen (endtimestring.string);
  endtimestring.firstcharonscreen = 0;

  prev_button.text = " < Previous screen ";
  prev_button.y = 20;
  prev_button.x = 5;
  prev_button.selected = FALSE;

  next_button.text = " Next screen > ";
  next_button.y = 20;
  next_button.x = 60;
  next_button.selected = FALSE;

  cancel_button.text = " Cancel ";
  cancel_button.y = 20;
  cancel_button.x = 36;
  cancel_button.selected = FALSE;

  tracktimes_check.text = "";	/* see below */
  tracktimes_check.y = 16;
  tracktimes_check.x = 4;
  tracktimes_check.selected = FALSE;

  beginend_check.text = "";	/* see below */
  beginend_check.y = 16;
  beginend_check.x = 42;
  beginend_check.selected = FALSE;

  clearscreen (SIGNPR_FILTMENU_HEADERTEXT);

  do
    {
      header (SIGNPR_FILTMENU_HEADERTEXT);

      if (*usetracktimes)
	tracktimes_check.text = "[X] Split tracks";
      else
	tracktimes_check.text = "[ ] Split tracks";

      if (*usebeginendtime)
	beginend_check.text = "[X] Use begin and end times";
      else
	beginend_check.text = "[ ] Use begin and end times";

      if (focus == 2)
	tracktimes_check.selected = TRUE;
      else
	tracktimes_check.selected = FALSE;

      if (focus == 3)
	beginend_check.selected = TRUE;
      else
	beginend_check.selected = FALSE;

      if (focus == 6)
	prev_button.selected = TRUE;
      else
	prev_button.selected = FALSE;

      if (focus == 7)
	cancel_button.selected = TRUE;
      else
	cancel_button.selected = FALSE;

      if (focus == 8)
	next_button.selected = TRUE;
      else
	next_button.selected = FALSE;

      filtlist->hasfocus = (focus == 0);
      selectedfilts->hasfocus = (focus == 1);

      scrollmenu_display (filtlist);
      mybox (filtlist->y - 1, filtlist->x - 1,
	     filtlist->h + 2, filtlist->w + 2);
      mvprintw (filtlist->y - 1, filtlist->x + 1,
		"Available filters:");

      scrollmenu_display (selectedfilts);
      mybox (selectedfilts->y - 1, selectedfilts->x - 1,
	     selectedfilts->h + 2, selectedfilts->w + 2);
      mvprintw (selectedfilts->y - 1, selectedfilts->x + 1,
		"Selected filters:");

      stringinput_display (&begintimestring);
      mvprintw (begintimestring.y, begintimestring.x - 12,
		"Begin time:");

      stringinput_display (&endtimestring);
      mvprintw (endtimestring.y, endtimestring.x - 12,
		"End time  :");

      button_display (&prev_button);
      mybox (prev_button.y - 1, prev_button.x - 1,
	     3, strlen (prev_button.text) + 2);
      button_display (&cancel_button);
      mybox (cancel_button.y - 1, cancel_button.x - 1,
	     3, strlen (cancel_button.text) + 2);
      button_display (&next_button);
      mybox (next_button.y - 1, next_button.x - 1,
	     3, strlen (next_button.text) + 2);

      button_display (&tracktimes_check);
      button_display (&beginend_check);

      if (focus == 0)
	{
	  strcpy (helphelpline, emptyhelpline);

	  i = 0;
	  while (i < strlen (helptexts[filtlist->selected])
		 && i < maxhelplength)
	    {
	      helphelpline[i + 1] = helptexts[filtlist->selected][i];
	      i++;
	    }

	  helpline (helphelpline);
	}
      else
	helpline (helplines[focus]);

      if (focus == 4)
	stringinput_display (&begintimestring);
      else if (focus == 5)
	stringinput_display (&endtimestring);
      else
	move (0, 79);

      refresh ();

      in_ch = getch ();

      switch (focus)
	{
	case 0:		/* filtlist */
	  if (scrollmenu_stdkeys (in_ch, filtlist) >= 0)
	    {
	      if (selectedfilts->number < MAX_FILTERS)
		{
		  selectedfilts->items[number_of_filters] =
		    filtlist->items[filtlist->selected];
		  filter_type[number_of_filters] =
		    filtnumbers[filtlist->selected];
		  parampointerarray[number_of_filters] =
		    (parampointer_t) malloc (
					      sizeof (param_t));
		  param_defaults (
				   parampointerarray[number_of_filters],
				   filtnumbers[filtlist->selected]);
		  number_of_filters++;
		  selectedfilts->number = number_of_filters;
		  selectedfilts->selected = number_of_filters - 1;
		}
	      else
		error_window ("The maximum number of filters has been \
reached. No more filters can be added.");
	    }
	  else
	    switch (in_ch)
	      {
	      case KEY_LEFT:
		focus--;
		break;
	      case KEY_RIGHT:
		focus++;
		break;
	      }
	  break;

	case 1:		/* selectedfilts */
	  if (scrollmenu_stdkeys (in_ch, selectedfilts) >= 0)
	    {
	      if (number_of_filters > 0)
		;
	      param_screen (
			     parampointerarray[selectedfilts->selected],
			     filter_type[selectedfilts->selected]);
	    }
	  else
	    switch (in_ch)
	      {
	      case 'u':
	      case 'U':
		if (selectedfilts->selected > 0)
		  {
		    helpcharptr = selectedfilts->items[
					       selectedfilts->selected - 1];
		    selectedfilts->items[selectedfilts->selected - 1] =
		      selectedfilts->items[selectedfilts->selected];
		    selectedfilts->items[selectedfilts->selected] =
		      helpcharptr;

		    helpint = filter_type[selectedfilts->selected - 1];
		    filter_type[selectedfilts->selected - 1] =
		      filter_type[selectedfilts->selected];
		    filter_type[selectedfilts->selected] =
		      helpint;

		    helpparampointer = parampointerarray[
					       selectedfilts->selected - 1];
		    parampointerarray[selectedfilts->selected - 1] =
		      parampointerarray[selectedfilts->selected];
		    parampointerarray[selectedfilts->selected] =
		      helpparampointer;

		    selectedfilts->selected--;
		  }
		break;

	      case 'd':
	      case 'D':
		if (selectedfilts->selected <
		    number_of_filters - 1)
		  {
		    helpcharptr = selectedfilts->items[
					       selectedfilts->selected + 1];
		    selectedfilts->items[selectedfilts->selected + 1] =
		      selectedfilts->items[selectedfilts->selected];
		    selectedfilts->items[selectedfilts->selected] =
		      helpcharptr;

		    helpint = filter_type[selectedfilts->selected + 1];
		    filter_type[selectedfilts->selected + 1] =
		      filter_type[selectedfilts->selected];
		    filter_type[selectedfilts->selected] =
		      helpint;

		    helpparampointer = parampointerarray[
					       selectedfilts->selected + 1];
		    parampointerarray[selectedfilts->selected + 1] =
		      parampointerarray[selectedfilts->selected];
		    parampointerarray[selectedfilts->selected] =
		      helpparampointer;

		    selectedfilts->selected++;
		  }
		break;

	      case KEY_BACKSPACE:
	      case 127:
	      case 'r':
	      case 'R':
		if (number_of_filters > 0)
		  {
		    free (parampointerarray[selectedfilts->selected]);

		    for (i = selectedfilts->selected;
			 i < number_of_filters - 1; i++)
		      {
			selectedfilts->items[i] =
			  selectedfilts->items[i + 1];

			filter_type[i] = filter_type[i + 1];

			parampointerarray[i] =
			  parampointerarray[i + 1];
		      }
		    number_of_filters--;
		    selectedfilts->number = number_of_filters;
		  }
		break;

	      case KEY_LEFT:
		focus--;
		break;
	      case KEY_RIGHT:
		focus++;
		break;
	      }
	  break;

	case 2:		/* Use tracksplitting data */
	  switch (in_ch)
	    {
	    case KEY_ENTER:
	    case 13:
	    case ' ':
	    case 'x':
	    case 'X':
	      *usetracktimes = 1 - *usetracktimes;
	      if (*usetracktimes)
		*usebeginendtime = 0;
	      break;

	    case KEY_LEFT:
	    case KEY_UP:
	      focus--;
	      break;
	    case KEY_RIGHT:
	    case KEY_DOWN:
	      focus++;
	      break;
	    }
	  break;

	case 3:		/* Use begin/end times */
	  switch (in_ch)
	    {
	    case KEY_ENTER:
	    case 13:
	    case ' ':
	    case 'x':
	    case 'X':
	      *usebeginendtime = 1 - *usebeginendtime;
	      if (*usebeginendtime)
		*usetracktimes = 0;
	      break;

	    case KEY_LEFT:
	    case KEY_UP:
	      focus--;
	      break;
	    case KEY_RIGHT:
	    case KEY_DOWN:
	      focus++;
	      break;
	    }
	  break;

	case 4:		/* begin time */
	  stringinput_stdkeys (in_ch, &begintimestring);
	  switch (in_ch)
	    {
	    case KEY_ENTER:
	    case 13:
	      strcpy (tempstring, begintimestring.string);
	      if (!hmsf2fsec (tempstring, &tempdouble))
		{
		  error_window ("Enter the time in the format hours:\
minutes:seconds.fractions, for example 0:04:26.740");
		  begintimestring.cursorpos =
		    strlen (begintimestring.string);
		}
	      else
		{
		  *begintime = tempdouble;
		  fsec2hmsf (tempdouble, begintimestring.string);
		  begintimestring.cursorpos =
		    strlen (begintimestring.string);
		  focus++;
		}
	      break;

	    case KEY_UP:
	      focus--;
	      break;
	    case KEY_DOWN:
	      focus++;
	      break;
	    }
	  break;

	case 5:		/* end time */
	  stringinput_stdkeys (in_ch, &endtimestring);
	  switch (in_ch)
	    {
	    case KEY_ENTER:
	    case 13:
	      strcpy (tempstring, endtimestring.string);
	      if (!hmsf2fsec (tempstring, &tempdouble))
		{
		  error_window ("Enter the time in the format hours:\
minutes:seconds.fractions, for example 0:04:26.740");
		  endtimestring.cursorpos =
		    strlen (endtimestring.string);
		}
	      else
		{
		  *endtime = tempdouble;
		  fsec2hmsf (tempdouble, endtimestring.string);
		  endtimestring.cursorpos =
		    strlen (endtimestring.string);
		  focus = 8;
		}
	      break;

	    case KEY_UP:
	      focus--;
	      break;
	    case KEY_DOWN:
	      focus++;
	      break;
	    }
	  break;


	case 6:		/* < Previous */
	  if (in_ch == KEY_ENTER || in_ch == 13)
	    {
	      returnval = 1;
	      dont_stop = FALSE;
	    }
	  else
	    switch (in_ch)
	      {
	      case KEY_LEFT:
	      case KEY_UP:
		focus--;
		break;
	      case KEY_RIGHT:
	      case KEY_DOWN:
		focus++;
		break;
	      }
	  break;

	case 7:		/* Cancel */
	  if (in_ch == KEY_ENTER || in_ch == 13)
	    {
	      returnval = 0;
	      dont_stop = FALSE;
	    }
	  else
	    switch (in_ch)
	      {
	      case KEY_LEFT:
	      case KEY_UP:
		focus--;
		break;
	      case KEY_RIGHT:
	      case KEY_DOWN:
		focus++;
		break;
	      }
	  break;

	case 8:		/* Next > */
	  if (in_ch == KEY_ENTER || in_ch == 13)
	    {
	      if (number_of_filters < 1)
		{
		  error_window ("No filters have been selected.");
		  focus = 0;
		  break;
		}

	      strcpy (tempstring, begintimestring.string);
	      if (!hmsf2fsec (tempstring, &tempdouble))
		{
		  error_window ("Enter the begin time in the format hours:\
minutes:seconds.fractions, for example 0:04:26.740");
		  begintimestring.cursorpos =
		    strlen (begintimestring.string);
		  focus = 4;
		  break;
		}

	      *begintime = tempdouble;

	      strcpy (tempstring, endtimestring.string);
	      if (!hmsf2fsec (tempstring, &tempdouble))
		{
		  error_window ("Enter the end time in the format hours:\
minutes:seconds.fractions, for example 0:04:26.740");
		  endtimestring.cursorpos =
		    strlen (endtimestring.string);
		  focus = 5;
		  break;
		}

	      *endtime = tempdouble;

	      if (*begintime > *endtime)
		{
		  error_window ("The begin time is larger than the end time.");
		  fsec2hmsf (*begintime, begintimestring.string);
		  begintimestring.cursorpos =
		    strlen (begintimestring.string);
		  fsec2hmsf (*endtime, endtimestring.string);
		  endtimestring.cursorpos =
		    strlen (endtimestring.string);
		  focus = 4;
		  break;
		}

	      returnval = 2;
	      dont_stop = FALSE;
	    }
	  else
	    switch (in_ch)
	      {
	      case KEY_LEFT:
	      case KEY_UP:
		focus--;
		break;
	      case KEY_RIGHT:
	      case KEY_DOWN:
		focus++;
		break;
	      }
	  break;

	}			/* switch(focus) */

      if (in_ch == 9)		/* TAB */
	focus++;

      if (in_ch == 27)
	dont_stop = FALSE;

      if (focus > 8)
	focus -= 9;
      if (focus < 0)
	focus += 9;
    }
  while (dont_stop);

  return returnval;
}