This source file includes following definitions.
- tmr2ticks
- poll_def_tmr
- tmr_reset
- def_tmr_open
- def_tmr_close
- def_tmr_event
- def_tmr_get_time
- def_tmr_ioctl
- def_tmr_arm
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 #define SEQUENCER_C
32 #include "sound_config.h"
33
34 #ifdef CONFIGURE_SOUNDCARD
35
36 #ifndef EXCLUDE_SEQUENCER
37
38 static volatile int opened = 0, tmr_running = 0;
39 static volatile time_t tmr_offs, tmr_ctr;
40 static volatile unsigned long ticks_offs;
41 static volatile int curr_tempo, curr_timebase;
42 static volatile unsigned long curr_ticks;
43 static volatile unsigned long next_event_time;
44 static unsigned long prev_event_time;
45
46 static void poll_def_tmr (unsigned long dummy);
47
48
49 static struct timer_list def_tmr =
50 {NULL, NULL, 0, 0, poll_def_tmr};
51
52 static unsigned long
53 tmr2ticks (int tmr_value)
54 {
55
56
57
58
59
60 return ((tmr_value * curr_tempo * curr_timebase) + (30 * HZ)) / (60 * HZ);
61 }
62
63 static void
64 poll_def_tmr (unsigned long dummy)
65 {
66
67 if (opened)
68 {
69
70 {
71 def_tmr.expires = (1) + jiffies;
72 add_timer (&def_tmr);
73 };
74
75 if (tmr_running)
76 {
77 tmr_ctr++;
78 curr_ticks = ticks_offs + tmr2ticks (tmr_ctr);
79
80 if (curr_ticks >= next_event_time)
81 {
82 next_event_time = 0xffffffff;
83 sequencer_timer (0);
84 }
85 }
86 }
87 }
88
89 static void
90 tmr_reset (void)
91 {
92 unsigned long flags;
93
94 save_flags (flags);
95 cli ();
96 tmr_offs = 0;
97 ticks_offs = 0;
98 tmr_ctr = 0;
99 next_event_time = 0xffffffff;
100 prev_event_time = 0;
101 curr_ticks = 0;
102 restore_flags (flags);
103 }
104
105 static int
106 def_tmr_open (int dev, int mode)
107 {
108 if (opened)
109 return -EBUSY;
110
111 tmr_reset ();
112 curr_tempo = 60;
113 curr_timebase = HZ;
114 opened = 1;
115
116
117 {
118 def_tmr.expires = (1) + jiffies;
119 add_timer (&def_tmr);
120 };
121
122 return 0;
123 }
124
125 static void
126 def_tmr_close (int dev)
127 {
128 opened = tmr_running = 0;
129 del_timer (&def_tmr);;
130 }
131
132 static int
133 def_tmr_event (int dev, unsigned char *event)
134 {
135 unsigned char cmd = event[1];
136 unsigned long parm = *(int *) &event[4];
137
138 switch (cmd)
139 {
140 case TMR_WAIT_REL:
141 parm += prev_event_time;
142 case TMR_WAIT_ABS:
143 if (parm > 0)
144 {
145 long time;
146
147 if (parm <= curr_ticks)
148 return TIMER_NOT_ARMED;
149
150 time = parm;
151 next_event_time = prev_event_time = time;
152
153 return TIMER_ARMED;
154 }
155 break;
156
157 case TMR_START:
158 tmr_reset ();
159 tmr_running = 1;
160 break;
161
162 case TMR_STOP:
163 tmr_running = 0;
164 break;
165
166 case TMR_CONTINUE:
167 tmr_running = 1;
168 break;
169
170 case TMR_TEMPO:
171 if (parm)
172 {
173 if (parm < 8)
174 parm = 8;
175 if (parm > 360)
176 parm = 360;
177 tmr_offs = tmr_ctr;
178 ticks_offs += tmr2ticks (tmr_ctr);
179 tmr_ctr = 0;
180 curr_tempo = parm;
181 }
182 break;
183
184 case TMR_ECHO:
185 seq_copy_to_input (event, 8);
186 break;
187
188 default:;
189 }
190
191 return TIMER_NOT_ARMED;
192 }
193
194 static unsigned long
195 def_tmr_get_time (int dev)
196 {
197 if (!opened)
198 return 0;
199
200 return curr_ticks;
201 }
202
203 static int
204 def_tmr_ioctl (int dev,
205 unsigned int cmd, ioctl_arg arg)
206 {
207 switch (cmd)
208 {
209 case SNDCTL_TMR_SOURCE:
210 return snd_ioctl_return ((int *) arg, TMR_INTERNAL);
211 break;
212
213 case SNDCTL_TMR_START:
214 tmr_reset ();
215 tmr_running = 1;
216 return 0;
217 break;
218
219 case SNDCTL_TMR_STOP:
220 tmr_running = 0;
221 return 0;
222 break;
223
224 case SNDCTL_TMR_CONTINUE:
225 tmr_running = 1;
226 return 0;
227 break;
228
229 case SNDCTL_TMR_TIMEBASE:
230 {
231 int val = get_fs_long ((long *) arg);
232
233 if (val)
234 {
235 if (val < 1)
236 val = 1;
237 if (val > 1000)
238 val = 1000;
239 curr_timebase = val;
240 }
241
242 return snd_ioctl_return ((int *) arg, curr_timebase);
243 }
244 break;
245
246 case SNDCTL_TMR_TEMPO:
247 {
248 int val = get_fs_long ((long *) arg);
249
250 if (val)
251 {
252 if (val < 8)
253 val = 8;
254 if (val > 250)
255 val = 250;
256 tmr_offs = tmr_ctr;
257 ticks_offs += tmr2ticks (tmr_ctr);
258 tmr_ctr = 0;
259 curr_tempo = val;
260 }
261
262 return snd_ioctl_return ((int *) arg, curr_tempo);
263 }
264 break;
265
266 case SNDCTL_SEQ_CTRLRATE:
267 if (get_fs_long ((long *) arg) != 0)
268 return -EINVAL;
269
270 return snd_ioctl_return ((int *) arg, ((curr_tempo * curr_timebase) + 30) / 60);
271 break;
272
273 case SNDCTL_TMR_METRONOME:
274
275 break;
276
277 default:;
278 }
279
280 return -EINVAL;
281 }
282
283 static void
284 def_tmr_arm (int dev, long time)
285 {
286 if (time < 0)
287 time = curr_ticks + 1;
288 else if (time <= curr_ticks)
289 return;
290
291 next_event_time = prev_event_time = time;
292
293 return;
294 }
295
296 struct sound_timer_operations default_sound_timer =
297 {
298 {"System clock", 0},
299 0,
300 0,
301 def_tmr_open,
302 def_tmr_close,
303 def_tmr_event,
304 def_tmr_get_time,
305 def_tmr_ioctl,
306 def_tmr_arm
307 };
308
309 #endif
310 #endif