4 * The default timer for the Level 2 sequencer interface.
5 * Uses the (100hz) timer of kernel.
7 * Copyright by Hannu Savolainen 1993
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are
11 * met: 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 2.
13 * Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <i386/isa/sound/sound_config.h>
36 #if defined(CONFIG_SEQUENCER)
38 static volatile int opened = 0, tmr_running = 0;
39 static volatile time_t tmr_offs, tmr_ctr;
40 static volatile u_long ticks_offs;
41 static volatile int curr_tempo, curr_timebase;
42 static volatile u_long curr_ticks;
43 static volatile u_long next_event_time;
44 static u_long prev_event_time;
46 static void poll_def_tmr(void *dummy);
49 tmr2ticks(int tmr_value)
52 * Convert system timer ticks (hz) to MIDI ticks (divide # of MIDI
53 * ticks/minute by # of system ticks/minute).
56 return ((tmr_value * curr_tempo * curr_timebase) + (30 * hz)) / (60 * hz);
60 poll_def_tmr(void *dummy)
65 timeout( poll_def_tmr, 0, 1);;
69 curr_ticks = ticks_offs + tmr2ticks(tmr_ctr);
71 if (curr_ticks >= next_event_time) {
72 next_event_time = 0xffffffff;
88 next_event_time = 0xffffffff;
95 def_tmr_open(int dev, int mode)
105 timeout( poll_def_tmr, 0, 1);;
111 def_tmr_close(int dev)
113 opened = tmr_running = 0;
117 def_tmr_event(int dev, u_char *event)
119 u_char cmd = event[1];
120 u_long parm = *(int *) &event[4];
124 parm += prev_event_time;
129 if (parm <= curr_ticks) /* It's the time */
130 return TIMER_NOT_ARMED;
133 next_event_time = prev_event_time = time;
154 RANGE (parm, 8, 360) ;
156 ticks_offs += tmr2ticks(tmr_ctr);
163 seq_copy_to_input(event, 8);
169 return TIMER_NOT_ARMED;
173 def_tmr_get_time(int dev)
182 def_tmr_ioctl(int dev, u_int cmd, ioctl_arg arg)
185 case SNDCTL_TMR_SOURCE:
186 return *(int *) arg = TMR_INTERNAL;
189 case SNDCTL_TMR_START:
195 case SNDCTL_TMR_STOP:
200 case SNDCTL_TMR_CONTINUE:
205 case SNDCTL_TMR_TIMEBASE:
207 int val = (*(int *) arg);
210 RANGE (val, 1, 1000) ;
213 return *(int *) arg = curr_timebase;
217 case SNDCTL_TMR_TEMPO:
219 int val = (*(int *) arg);
222 RANGE (val, 8, 250) ;
224 ticks_offs += tmr2ticks(tmr_ctr);
228 return *(int *) arg = curr_tempo;
232 case SNDCTL_SEQ_CTRLRATE:
233 if ((*(int *) arg) != 0) /* Can't change */
236 return *(int *) arg = ((curr_tempo * curr_timebase) + 30) / 60;
239 case SNDCTL_TMR_METRONOME:
250 def_tmr_arm(int dev, long time)
253 time = curr_ticks + 1;
254 else if (time <= curr_ticks) /* It's the time */
257 next_event_time = prev_event_time = time;
262 struct sound_timer_operations default_sound_timer =
266 0, /* Local device link */
276 #endif /* NSND > 0 */