File: signals.C

package info (click to toggle)
gmod 3.1-11
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,352 kB
  • ctags: 809
  • sloc: cpp: 7,772; makefile: 77
file content (193 lines) | stat: -rw-r--r-- 3,545 bytes parent folder | download | duplicates (7)
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
// -*-C++-*-
// This file is part of the gmod package
// Copyright (C) 1997 by Andrew J. Robinson

#ifndef USE_X

#include <sys/ioctl.h>
#include <signal.h>
#include <stdio.h>
#include <sys/time.h>

#ifdef USE_LOCAL
#include "soundcard.h"
#else
#include <sys/soundcard.h>
#endif

#include <sys/types.h>
#include <unistd.h>


#include "CursesScr.h"
#include "SampleShell.h"

#include "defines.h"
#include "structs.h"
#include "globals.h"
#include "protos.h"

#include "Sequencer.h"

void
timerHandler (int sig)
{
  extern CursesScr *cursScreen;
#ifdef USE_NCURSES
  extern SampleShell *sampleShell;
#endif

  int keypress = EOF;
  unsigned int volume;
  int tmpVolume;
  static int resetArg = MY_FALSE;
  /*
     char message[80];
     */
  static unsigned int keyedArg = 0;

  extern Sequencer *seq;

  if (sig != -1)
    signal (sig, timerHandler);

  switch (sig)
    {
    case -1:
      keypress = cursScreen->getChar();
      break;
    case SIGTERM:
      keypress = 'q';
      break;
    case SIGUSR1:
      keypress = 'p';
      break;
    case SIGUSR2:
      keypress = 'n';
      break;
    }

  while (keypress != EOF)
    {
      switch (keypress)
	{
#ifdef USE_NCURSES
	case KEY_LEFT:
#endif
	case 'b':
	  if (keyedArg == 0)
	    positionChange--;
	  else
	    positionChange -= keyedArg;
	  resetArg = MY_TRUE;
	  stopFlag = STOP_FORWBACK;
	  seq->stopPlayback ();
	  break;
#ifdef USE_NCURSES
	case KEY_RIGHT:
#endif
	case 'f':
	  if (keyedArg == 0)
	    positionChange++;
	  else
	    positionChange += keyedArg;
	  resetArg = MY_TRUE;
	  stopFlag = STOP_FORWBACK;
	  seq->stopPlayback ();
	  break;
#ifdef USE_NCURSES
	case KEY_NPAGE:
#endif
	case 'n':
	  stopFlag = STOP_NEXT;
	  seq->stopPlayback ();
	  break;
#ifdef USE_NCURSES
	case KEY_PPAGE:
#endif
	case 'p':
	  stopFlag = STOP_PREV;
	  seq->stopPlayback ();
	  break;
	case 'q':
	  stopFlag = STOP_EXIT;
	  seq->stopPlayback ();
	  break;
	  //#ifdef USE_NCURSES
	  //	case KEY_UP:
	  //#endif
	case '+':
	  if (mixerfd != -1)
	    {
	      ioctl (mixerfd, MIXER_READ (SOUND_MIXER_SYNTH), &volume);
	      volume &= 0xff;
	      if (keyedArg == 0)
		tmpVolume = (int) volume + 1;
	      else
		tmpVolume = (int) volume + keyedArg;
	      if (tmpVolume > MIXER_MAX_VOL)
		tmpVolume = MIXER_MAX_VOL;
	      volume = tmpVolume * 256 + tmpVolume;
	      ioctl (mixerfd, MIXER_WRITE (SOUND_MIXER_SYNTH), &volume);
	    }
	  resetArg = MY_TRUE;
	  break;
	  //#ifdef USE_NCURSES
	  //	case KEY_DOWN:
	  //#endif
	case '-':
	  if (mixerfd != -1)
	    {
	      ioctl (mixerfd, MIXER_READ (SOUND_MIXER_SYNTH), &volume);
	      volume &= 0xff;
	      if (keyedArg == 0)
		tmpVolume = (int) volume - 1;
	      else
		tmpVolume = (int) volume - keyedArg;
	      if (tmpVolume < MIXER_MIN_VOL)
		tmpVolume = MIXER_MIN_VOL;
	      volume = tmpVolume * 256 + tmpVolume;
	      ioctl (mixerfd, MIXER_WRITE (SOUND_MIXER_SYNTH), &volume);
	    }
	  resetArg = MY_TRUE;
	  break;
#ifdef USE_NCURSES
	case KEY_UP:
	  sampleShell->scrollSamples(-1);
	  break;
	case KEY_DOWN:
	  sampleShell->scrollSamples(1);
	  break;
#endif
	case '0':
	case '1':
	case '2':
	case '3':
	case '4':
	case '5':
	case '6':
	case '7':
	case '8':
	case '9':
	  if (resetArg == MY_TRUE)
	    {
	      resetArg = MY_FALSE;
	      keyedArg = 0;
	    }
	  keyedArg = (keyedArg * 10) + (keypress - '0');
	  break;
	}

      keypress = cursScreen->getChar();
    }
}

void
setSignals (void)
{
  signal (SIGTERM, timerHandler);
  signal (SIGUSR1, timerHandler);
  signal (SIGUSR2, timerHandler);
}

#endif /* USE_X */