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 "sound_config.h"
34 #ifdef CONFIGURE_SOUNDCARD
36 #ifndef EXCLUDE_SEQUENCER
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
;
46 static void poll_def_tmr (unsigned long dummy
);
49 static struct timer_list def_tmr
=
50 {NULL
, NULL
, 0, 0, poll_def_tmr
};
53 tmr2ticks (int tmr_value
)
56 * Convert system timer ticks (HZ) to MIDI ticks
57 * (divide # of MIDI ticks/minute by # of system ticks/minute).
60 return ((tmr_value
* curr_tempo
* curr_timebase
) + (30 * HZ
)) / (60 * HZ
);
64 poll_def_tmr (unsigned long dummy
)
71 def_tmr
.expires
= (1) + jiffies
;
78 curr_ticks
= ticks_offs
+ tmr2ticks (tmr_ctr
);
80 if (curr_ticks
>= next_event_time
)
82 next_event_time
= 0xffffffff;
99 next_event_time
= 0xffffffff;
102 restore_flags (flags
);
106 def_tmr_open (int dev
, int mode
)
118 def_tmr
.expires
= (1) + jiffies
;
119 add_timer (&def_tmr
);
126 def_tmr_close (int dev
)
128 opened
= tmr_running
= 0;
129 del_timer (&def_tmr
);;
133 def_tmr_event (int dev
, unsigned char *event
)
135 unsigned char cmd
= event
[1];
136 unsigned long parm
= *(int *) &event
[4];
141 parm
+= prev_event_time
;
147 if (parm
<= curr_ticks
) /* It's the time */
148 return TIMER_NOT_ARMED
;
151 next_event_time
= prev_event_time
= time
;
178 ticks_offs
+= tmr2ticks (tmr_ctr
);
185 seq_copy_to_input (event
, 8);
191 return TIMER_NOT_ARMED
;
195 def_tmr_get_time (int dev
)
204 def_tmr_ioctl (int dev
,
205 unsigned int cmd
, ioctl_arg arg
)
209 case SNDCTL_TMR_SOURCE
:
210 return snd_ioctl_return ((int *) arg
, TMR_INTERNAL
);
213 case SNDCTL_TMR_START
:
219 case SNDCTL_TMR_STOP
:
224 case SNDCTL_TMR_CONTINUE
:
229 case SNDCTL_TMR_TIMEBASE
:
231 int val
= get_fs_long ((long *) arg
);
242 return snd_ioctl_return ((int *) arg
, curr_timebase
);
246 case SNDCTL_TMR_TEMPO
:
248 int val
= get_fs_long ((long *) arg
);
257 ticks_offs
+= tmr2ticks (tmr_ctr
);
262 return snd_ioctl_return ((int *) arg
, curr_tempo
);
266 case SNDCTL_SEQ_CTRLRATE
:
267 if (get_fs_long ((long *) arg
) != 0) /* Can't change */
270 return snd_ioctl_return ((int *) arg
, ((curr_tempo
* curr_timebase
) + 30) / 60);
273 case SNDCTL_TMR_METRONOME
:
284 def_tmr_arm (int dev
, long time
)
287 time
= curr_ticks
+ 1;
288 else if (time
<= curr_ticks
) /* It's the time */
291 next_event_time
= prev_event_time
= time
;
296 struct sound_timer_operations default_sound_timer
=
300 0, /* Local device link */