1993-10-23 10:55:52 +00:00
|
|
|
/*
|
1994-03-11 10:27:25 +00:00
|
|
|
* sound/sequencer.c
|
1997-10-31 17:25:35 +00:00
|
|
|
*
|
1993-10-23 10:55:52 +00:00
|
|
|
* The sequencer personality manager.
|
1997-10-31 17:25:35 +00:00
|
|
|
*
|
1993-10-29 03:44:07 +00:00
|
|
|
* Copyright by Hannu Savolainen 1993
|
1997-10-31 17:25:35 +00:00
|
|
|
*
|
1993-10-29 03:44:07 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met: 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer. 2.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
1997-10-31 17:25:35 +00:00
|
|
|
*
|
1993-10-29 03:44:07 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
|
|
|
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
1997-10-31 17:25:35 +00:00
|
|
|
*
|
1993-10-23 10:55:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define SEQUENCER_C
|
1996-09-10 08:32:01 +00:00
|
|
|
#include <i386/isa/sound/sound_config.h>
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
#if NSND > 0
|
|
|
|
|
|
|
|
#ifdef CONFIG_SEQUENCER
|
1995-11-24 15:08:07 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
#include <i386/isa/sound/midi_ctrl.h>
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1998-02-09 06:11:36 +00:00
|
|
|
static void seq_drain_midi_queues(void);
|
1997-11-10 18:31:35 +00:00
|
|
|
int
|
|
|
|
sequencer_poll (int dev, struct fileinfo *file, int events, select_table * wait);
|
1993-10-23 10:55:52 +00:00
|
|
|
static int sequencer_ok = 0;
|
1994-10-01 02:17:17 +00:00
|
|
|
static struct sound_timer_operations *tmr;
|
|
|
|
static int tmr_no = -1; /* Currently selected timer */
|
|
|
|
static int pending_timer = -1; /* For timer change operation */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local counts for number of synth and MIDI devices. These are initialized
|
|
|
|
* by the sequencer_open.
|
|
|
|
*/
|
|
|
|
static int max_mididev = 0;
|
|
|
|
static int max_synthdev = 0;
|
|
|
|
|
|
|
|
/*
|
1997-10-31 17:25:35 +00:00
|
|
|
* The seq_mode gives the operating mode of the sequencer: 1 = level1 (the
|
|
|
|
* default) 2 = level2 (extended capabilites)
|
1994-10-01 02:17:17 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define SEQ_1 1
|
|
|
|
#define SEQ_2 2
|
|
|
|
static int seq_mode = SEQ_1;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
static int *seq_sleeper = NULL;
|
|
|
|
static volatile struct snd_wait seq_sleep_flag = {0};
|
|
|
|
static int *midi_sleeper = NULL;
|
|
|
|
static volatile struct snd_wait midi_sleep_flag = {0};
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
static int midi_opened[MAX_MIDI_DEV] = {0};
|
|
|
|
static int midi_written[MAX_MIDI_DEV] = {0};
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1998-02-09 06:11:36 +00:00
|
|
|
static u_long prev_input_time = 0;
|
|
|
|
static int prev_event_time;
|
|
|
|
static u_long seq_time = 0;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1996-09-10 08:32:01 +00:00
|
|
|
#include <i386/isa/sound/tuning.h>
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
#define EV_SZ 8
|
1994-10-01 02:17:17 +00:00
|
|
|
#define IEV_SZ 8
|
1997-10-31 17:25:35 +00:00
|
|
|
static u_char *queue = NULL;
|
|
|
|
static u_char *iqueue = NULL;
|
1994-03-11 10:27:25 +00:00
|
|
|
|
1993-10-23 10:55:52 +00:00
|
|
|
static volatile int qhead = 0, qtail = 0, qlen = 0;
|
|
|
|
static volatile int iqhead = 0, iqtail = 0, iqlen = 0;
|
|
|
|
static volatile int seq_playing = 0;
|
1997-10-31 17:25:35 +00:00
|
|
|
static volatile int sequencer_busy = 0;
|
1993-10-23 10:55:52 +00:00
|
|
|
static int output_treshold;
|
1994-10-01 02:17:17 +00:00
|
|
|
static int pre_event_timeout;
|
1997-10-31 17:25:35 +00:00
|
|
|
static u_int synth_open_mask;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
static int seq_queue(u_char *note, char nonblock);
|
|
|
|
static void seq_startplay(void);
|
|
|
|
static int seq_sync(void);
|
|
|
|
static void seq_reset(void);
|
1993-10-23 10:55:52 +00:00
|
|
|
static int pmgr_present[MAX_SYNTH_DEV] =
|
|
|
|
{0};
|
1997-10-31 17:25:35 +00:00
|
|
|
static struct callout_handle sequencertimeout_ch
|
|
|
|
= CALLOUT_HANDLE_INITIALIZER(&sequencertimeout_ch);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
#if MAX_SYNTH_DEV > 15
|
1994-10-01 02:17:17 +00:00
|
|
|
#error Too many synthesizer devices enabled.
|
1993-10-23 10:55:52 +00:00
|
|
|
#endif
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
|
|
|
* sound_timer stuff -- originally in soundcard.c
|
|
|
|
*
|
|
|
|
* A negative value means a relative timeout in |count| ticks.
|
|
|
|
* A positive value is used for what ?
|
|
|
|
*
|
|
|
|
* In any case, this is only used in sequencer.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int timer_running = 0;
|
|
|
|
|
|
|
|
void
|
|
|
|
request_sound_timer(int count)
|
|
|
|
{
|
|
|
|
static int current = 0;
|
|
|
|
int tmp = count;
|
|
|
|
|
|
|
|
if (count < 0)
|
|
|
|
sequencertimeout_ch = timeout(sequencer_timer, 0, -count);
|
|
|
|
else {
|
|
|
|
|
|
|
|
if (count < current)
|
|
|
|
current = 0; /* Timer restarted */
|
|
|
|
|
|
|
|
count = count - current;
|
|
|
|
current = tmp;
|
|
|
|
if (!count)
|
|
|
|
count = 1;
|
|
|
|
sequencertimeout_ch = timeout(sequencer_timer, 0, count);
|
|
|
|
}
|
|
|
|
timer_running = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sound_stop_timer(void)
|
|
|
|
{
|
|
|
|
if (timer_running)
|
|
|
|
untimeout( sequencer_timer, 0, sequencertimeout_ch);
|
|
|
|
timer_running = 0;
|
|
|
|
}
|
|
|
|
|
1993-10-23 10:55:52 +00:00
|
|
|
int
|
1997-10-31 17:25:35 +00:00
|
|
|
sequencer_read(int dev, struct fileinfo * file, snd_rw_buf * buf, int count)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
int c = count, p = 0;
|
|
|
|
int ev_len;
|
|
|
|
u_long flags;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
dev = dev >> 4;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
ev_len = seq_mode == SEQ_1 ? 4 : 8;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (dev) /* Patch manager device */
|
|
|
|
return pmgr_read(dev - 1, file, buf, count);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
flags = splhigh();
|
|
|
|
if (!iqlen) {
|
|
|
|
int flag, chn;
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
midi_sleeper = &chn;
|
|
|
|
DO_SLEEP(chn, midi_sleep_flag, pre_event_timeout);
|
|
|
|
|
|
|
|
if (!iqlen) {
|
|
|
|
splx(flags);
|
|
|
|
return 0;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
1994-10-01 02:17:17 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
while (iqlen && c >= ev_len) {
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (uiomove((char *) &iqueue[iqhead * IEV_SZ], ev_len, buf))
|
|
|
|
printf("sb: Bad copyout()!\n");
|
|
|
|
p += ev_len;
|
|
|
|
c -= ev_len;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
iqhead = (iqhead + 1) % SEQ_MAX_QUEUE;
|
|
|
|
iqlen--;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
splx(flags);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
return count - c;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
1993-10-29 03:44:07 +00:00
|
|
|
static void
|
1997-10-31 17:25:35 +00:00
|
|
|
sequencer_midi_output(int dev)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
|
|
|
* Currently NOP
|
|
|
|
*/
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
1994-10-01 02:17:17 +00:00
|
|
|
void
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_copy_to_input(u_char *event, int len)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
u_long flags;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
1995-07-28 21:40:49 +00:00
|
|
|
* Verify that the len is valid for the current mode.
|
1997-10-31 17:25:35 +00:00
|
|
|
*/
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (len != 4 && len != 8)
|
|
|
|
return;
|
|
|
|
if ((seq_mode == SEQ_1) != (len == 4))
|
|
|
|
return;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (iqlen >= (SEQ_MAX_QUEUE - 1))
|
|
|
|
return; /* Overflow */
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
flags = splhigh();
|
|
|
|
bcopy(event, &iqueue[iqtail * IEV_SZ], len);
|
|
|
|
iqlen++;
|
|
|
|
iqtail = (iqtail + 1) % SEQ_MAX_QUEUE;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if ((midi_sleep_flag.mode & WK_SLEEP)) {
|
|
|
|
midi_sleep_flag.mode = WK_WAKEUP;
|
|
|
|
wakeup(midi_sleeper);
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
splx(flags);
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
1993-10-29 03:44:07 +00:00
|
|
|
static void
|
1997-10-31 17:25:35 +00:00
|
|
|
sequencer_midi_input(int dev, u_char data)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
u_int tstamp;
|
|
|
|
u_char event[4];
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (data == 0xfe) /* Ignore active sensing */
|
|
|
|
return;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
tstamp = get_time() - seq_time;
|
|
|
|
if (tstamp != prev_input_time) {
|
|
|
|
tstamp = (tstamp << 8) | SEQ_WAIT;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_copy_to_input((u_char *) &tstamp, 4);
|
|
|
|
prev_input_time = tstamp;
|
1994-10-01 02:17:17 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
event[0] = SEQ_MIDIPUTC;
|
|
|
|
event[1] = data;
|
|
|
|
event[2] = dev;
|
|
|
|
event[3] = 0;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_copy_to_input(event, 4);
|
1994-10-01 02:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_input_event(u_char *event, int len)
|
1994-10-01 02:17:17 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
u_long this_time;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (seq_mode == SEQ_2)
|
|
|
|
this_time = tmr->get_time(tmr_no);
|
|
|
|
else
|
|
|
|
this_time = get_time() - seq_time;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (this_time != prev_input_time) {
|
|
|
|
u_char tmp_event[8];
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
tmp_event[0] = EV_TIMING;
|
|
|
|
tmp_event[1] = TMR_WAIT_ABS;
|
|
|
|
tmp_event[2] = 0;
|
|
|
|
tmp_event[3] = 0;
|
|
|
|
*(u_long *) &tmp_event[4] = this_time;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_copy_to_input(tmp_event, 8);
|
|
|
|
prev_input_time = this_time;
|
1994-10-01 02:17:17 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_copy_to_input(event, len);
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1997-10-31 17:25:35 +00:00
|
|
|
sequencer_write(int dev, struct fileinfo * file, snd_rw_buf * buf, int count)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
u_char event[EV_SZ], ev_code;
|
|
|
|
int p = 0, c, ev_size;
|
|
|
|
int err;
|
|
|
|
int mode = file->mode & O_ACCMODE;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
dev = dev >> 4;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
DEB(printf("sequencer_write(dev=%d, count=%d)\n", dev, count));
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (mode == OPEN_READ)
|
|
|
|
return -(EIO);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (dev)
|
|
|
|
return pmgr_write(dev - 1, file, buf, count);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
c = count;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
while (c >= 4) {
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (uiomove((char *) event, 4, buf))
|
|
|
|
printf("sb: Bad copyin()!\n");
|
|
|
|
ev_code = event[0];
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (ev_code == SEQ_FULLSIZE) {
|
|
|
|
int err;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
dev = *(u_short *) &event[2];
|
|
|
|
if (dev < 0 || dev >= max_synthdev)
|
|
|
|
return -(ENXIO);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (!(synth_open_mask & (1 << dev)))
|
|
|
|
return -(ENXIO);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
err = synth_devs[dev]->load_patch(dev,
|
|
|
|
*(short *) &event[0], buf, p + 4, c, 0);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
if (ev_code >= 128) {
|
|
|
|
if (seq_mode == SEQ_2 && ev_code == SEQ_EXTENDED) {
|
|
|
|
printf("Sequencer: Invalid level 2 event %x\n", ev_code);
|
|
|
|
return -(EINVAL);
|
1994-10-01 02:17:17 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
ev_size = 8;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (c < ev_size) {
|
|
|
|
if (!seq_playing)
|
|
|
|
seq_startplay();
|
|
|
|
return count - c;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
if (uiomove((char *) &event[4], 4, buf))
|
|
|
|
printf("sb: Bad copyin()!\n");
|
|
|
|
} else {
|
|
|
|
if (seq_mode == SEQ_2) {
|
|
|
|
printf("Sequencer: 4 byte event in level 2 mode\n");
|
|
|
|
return -(EINVAL);
|
1994-10-01 02:17:17 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
ev_size = 4;
|
1994-10-01 02:17:17 +00:00
|
|
|
}
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (event[0] == SEQ_MIDIPUTC) {
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (!midi_opened[event[2]]) {
|
|
|
|
int mode;
|
|
|
|
int dev = event[2];
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (dev >= max_mididev) {
|
|
|
|
printf("Sequencer Error: Nonexistent MIDI device %d\n",dev);
|
|
|
|
return -(ENXIO);
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
mode = file->mode & O_ACCMODE;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if ((err = midi_devs[dev]->open(dev, mode,
|
|
|
|
sequencer_midi_input, sequencer_midi_output)) < 0) {
|
|
|
|
seq_reset();
|
|
|
|
printf("Sequencer Error: Unable to open Midi #%d\n", dev);
|
|
|
|
return err;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
midi_opened[dev] = 1;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
if (!seq_queue(event, 0)) {
|
|
|
|
int processed = count - c;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (!seq_playing)
|
|
|
|
seq_startplay();
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (!processed && 0)
|
|
|
|
return -(EAGAIN);
|
|
|
|
else
|
|
|
|
return processed;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
p += ev_size;
|
|
|
|
c -= ev_size;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (!seq_playing)
|
|
|
|
seq_startplay();
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
return count; /* This will "eat" chunks shorter than 4 bytes
|
|
|
|
* (if written alone) Should we really do that ?
|
|
|
|
*/
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_queue(u_char *note, char nonblock)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
|
|
|
* Test if there is space in the queue
|
|
|
|
*/
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (qlen >= SEQ_MAX_QUEUE)
|
|
|
|
if (!seq_playing)
|
|
|
|
seq_startplay(); /* Give chance to drain the queue */
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (!nonblock && qlen >= SEQ_MAX_QUEUE &&
|
|
|
|
!(seq_sleep_flag.mode & WK_SLEEP)) {
|
|
|
|
/*
|
|
|
|
* Sleep until there is enough space on the queue
|
|
|
|
*/
|
|
|
|
|
|
|
|
int chn;
|
|
|
|
|
|
|
|
|
|
|
|
seq_sleeper = &chn;
|
|
|
|
DO_SLEEP(chn, seq_sleep_flag, 0);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1995-07-28 21:40:49 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
if (qlen >= SEQ_MAX_QUEUE)
|
|
|
|
return 0; /* To be sure */
|
|
|
|
bcopy(note, &queue[qtail * EV_SZ], EV_SZ);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
qtail = (qtail + 1) % SEQ_MAX_QUEUE;
|
|
|
|
qlen++;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
return 1;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1997-10-31 17:25:35 +00:00
|
|
|
extended_event(u_char *q)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
int dev = q[2];
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (dev < 0 || dev >= max_synthdev)
|
|
|
|
return -(ENXIO);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (!(synth_open_mask & (1 << dev)))
|
|
|
|
return -(ENXIO);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
switch (q[1]) {
|
1993-10-23 10:55:52 +00:00
|
|
|
case SEQ_NOTEOFF:
|
1997-10-31 17:25:35 +00:00
|
|
|
synth_devs[dev]->kill_note(dev, q[3], q[4], q[5]);
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
case SEQ_NOTEON:
|
1997-10-31 17:25:35 +00:00
|
|
|
if (q[4] > 127 && q[4] != 255)
|
|
|
|
return 0;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
synth_devs[dev]->start_note(dev, q[3], q[4], q[5]);
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
case SEQ_PGMCHANGE:
|
1997-10-31 17:25:35 +00:00
|
|
|
synth_devs[dev]->set_instr(dev, q[3], q[4]);
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
case SEQ_AFTERTOUCH:
|
1997-10-31 17:25:35 +00:00
|
|
|
synth_devs[dev]->aftertouch(dev, q[3], q[4]);
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
case SEQ_BALANCE:
|
1997-10-31 17:25:35 +00:00
|
|
|
synth_devs[dev]->panning(dev, q[3], (char) q[4]);
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
case SEQ_CONTROLLER:
|
1997-10-31 17:25:35 +00:00
|
|
|
synth_devs[dev]->controller(dev, q[3], q[4], *(short *) &q[5]);
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1994-04-23 01:50:14 +00:00
|
|
|
case SEQ_VOLMODE:
|
1997-10-31 17:25:35 +00:00
|
|
|
if (synth_devs[dev]->volume_method != NULL)
|
|
|
|
synth_devs[dev]->volume_method(dev, q[3]);
|
|
|
|
break;
|
1994-04-23 01:50:14 +00:00
|
|
|
|
1993-10-23 10:55:52 +00:00
|
|
|
default:
|
1997-10-31 17:25:35 +00:00
|
|
|
return -(EINVAL);
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
return 0;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
1994-10-01 02:17:17 +00:00
|
|
|
static int
|
1997-10-31 17:25:35 +00:00
|
|
|
find_voice(int dev, int chn, int note)
|
1994-10-01 02:17:17 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
u_short key;
|
|
|
|
int i;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
key = (chn << 8) | (note + 1);
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
for (i = 0; i < synth_devs[dev]->alloc.max_voice; i++)
|
|
|
|
if (synth_devs[dev]->alloc.map[i] == key)
|
|
|
|
return i;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
return -1;
|
1994-10-01 02:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1997-10-31 17:25:35 +00:00
|
|
|
alloc_voice(int dev, int chn, int note)
|
1994-10-01 02:17:17 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
u_short key;
|
|
|
|
int voice;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
key = (chn << 8) | (note + 1);
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
voice = synth_devs[dev]->alloc_voice(dev, chn, note,
|
|
|
|
&synth_devs[dev]->alloc);
|
|
|
|
synth_devs[dev]->alloc.map[voice] = key;
|
|
|
|
synth_devs[dev]->alloc.alloc_times[voice] =
|
|
|
|
synth_devs[dev]->alloc.timestamp++;
|
|
|
|
return voice;
|
1994-10-01 02:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_chn_voice_event(u_char *event)
|
1994-10-01 02:17:17 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
u_char dev = event[1];
|
|
|
|
u_char cmd = event[2];
|
|
|
|
u_char chn = event[3];
|
|
|
|
u_char note = event[4];
|
|
|
|
u_char parm = event[5];
|
|
|
|
int voice = -1;
|
|
|
|
|
|
|
|
if ((int) dev > max_synthdev)
|
|
|
|
return;
|
|
|
|
if (!(synth_open_mask & (1 << dev)))
|
|
|
|
return;
|
|
|
|
if (!synth_devs[dev])
|
|
|
|
return;
|
1995-03-04 21:11:21 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (seq_mode == SEQ_2) {
|
|
|
|
if (synth_devs[dev]->alloc_voice)
|
|
|
|
voice = find_voice(dev, chn, note);
|
|
|
|
|
|
|
|
if (cmd == MIDI_NOTEON && parm == 0) {
|
|
|
|
cmd = MIDI_NOTEOFF;
|
|
|
|
parm = 64;
|
1995-07-28 21:40:49 +00:00
|
|
|
}
|
1994-10-01 02:17:17 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
switch (cmd) {
|
1994-10-01 02:17:17 +00:00
|
|
|
case MIDI_NOTEON:
|
1997-10-31 17:25:35 +00:00
|
|
|
if (note > 127 && note != 255) /* Not a seq2 feature */
|
|
|
|
return;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (voice == -1 && seq_mode == SEQ_2 && synth_devs[dev]->alloc_voice) {
|
|
|
|
/* Internal synthesizer (FM, GUS, etc) */
|
|
|
|
voice = alloc_voice(dev, chn, note);
|
1994-10-01 02:17:17 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
if (voice == -1)
|
|
|
|
voice = chn;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (seq_mode == SEQ_2 && (int) dev < num_synths) {
|
|
|
|
/*
|
|
|
|
* The MIDI channel 10 is a percussive channel. Use
|
|
|
|
* the note number to select the proper patch (128 to
|
|
|
|
* 255) to play.
|
|
|
|
*/
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (chn == 9) {
|
|
|
|
synth_devs[dev]->set_instr(dev, voice, 128 + note);
|
|
|
|
note = 60; /* Middle C */
|
1995-07-28 21:40:49 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
if (seq_mode == SEQ_2)
|
|
|
|
synth_devs[dev]->setup_voice(dev, voice, chn);
|
|
|
|
synth_devs[dev]->start_note(dev, voice, note, parm);
|
|
|
|
break;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
|
|
|
case MIDI_NOTEOFF:
|
1997-10-31 17:25:35 +00:00
|
|
|
if (voice == -1)
|
|
|
|
voice = chn;
|
|
|
|
synth_devs[dev]->kill_note(dev, voice, note, parm);
|
|
|
|
break;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
|
|
|
case MIDI_KEY_PRESSURE:
|
1997-10-31 17:25:35 +00:00
|
|
|
if (voice == -1)
|
|
|
|
voice = chn;
|
|
|
|
synth_devs[dev]->aftertouch(dev, voice, parm);
|
|
|
|
break;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
|
|
|
default:;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_chn_common_event(u_char *event)
|
1994-10-01 02:17:17 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
u_char dev = event[1];
|
|
|
|
u_char cmd = event[2];
|
|
|
|
u_char chn = event[3];
|
|
|
|
u_char p1 = event[4];
|
|
|
|
|
|
|
|
/* u_char p2 = event[5]; */
|
|
|
|
u_short w14 = *(short *) &event[6];
|
|
|
|
|
|
|
|
if ((int) dev > max_synthdev)
|
|
|
|
return;
|
|
|
|
if (!(synth_open_mask & (1 << dev)))
|
|
|
|
return;
|
|
|
|
if (!synth_devs[dev])
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (cmd) {
|
1994-10-01 02:17:17 +00:00
|
|
|
case MIDI_PGM_CHANGE:
|
1997-10-31 17:25:35 +00:00
|
|
|
if (seq_mode == SEQ_2) {
|
|
|
|
synth_devs[dev]->chn_info[chn].pgm_num = p1;
|
|
|
|
if ((int) dev >= num_synths)
|
|
|
|
synth_devs[dev]->set_instr(dev, chn, p1);
|
|
|
|
} else
|
|
|
|
synth_devs[dev]->set_instr(dev, chn, p1);
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
break;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
|
|
|
case MIDI_CTL_CHANGE:
|
1997-10-31 17:25:35 +00:00
|
|
|
if (seq_mode == SEQ_2) {
|
|
|
|
if (chn > 15 || p1 > 127)
|
|
|
|
break;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
synth_devs[dev]->chn_info[chn].controllers[p1] = w14 & 0x7f;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (p1 < 32) /* Setting MSB should clear LSB to 0 */
|
|
|
|
synth_devs[dev]->chn_info[chn].controllers[p1 + 32] = 0;
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if ((int) dev < num_synths) {
|
|
|
|
int val = w14 & 0x7f;
|
|
|
|
int i, key;
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (p1 < 64) { /* Combine MSB and LSB */
|
|
|
|
val = ((synth_devs[dev]->
|
|
|
|
chn_info[chn].controllers[p1 & ~32] & 0x7f) << 7)
|
|
|
|
| (synth_devs[dev]->
|
|
|
|
chn_info[chn].controllers[p1 | 32] & 0x7f);
|
|
|
|
p1 &= ~32;
|
|
|
|
}
|
|
|
|
/* Handle all playing notes on this channel */
|
|
|
|
|
|
|
|
key = ((int) chn << 8);
|
|
|
|
|
|
|
|
for (i = 0; i < synth_devs[dev]->alloc.max_voice; i++)
|
|
|
|
if ((synth_devs[dev]->alloc.map[i] & 0xff00) == key)
|
|
|
|
synth_devs[dev]->controller(dev, i, p1, val);
|
|
|
|
} else
|
|
|
|
synth_devs[dev]->controller(dev, chn, p1, w14);
|
|
|
|
} else /* Mode 1 */
|
|
|
|
synth_devs[dev]->controller(dev, chn, p1, w14);
|
|
|
|
break;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
|
|
|
case MIDI_PITCH_BEND:
|
1997-10-31 17:25:35 +00:00
|
|
|
if (seq_mode == SEQ_2) {
|
|
|
|
synth_devs[dev]->chn_info[chn].bender_value = w14;
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if ((int) dev < num_synths) { /* Handle all playing
|
|
|
|
* notes on this channel */
|
|
|
|
int i, key;
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
key = (chn << 8);
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
for (i = 0; i < synth_devs[dev]->alloc.max_voice; i++)
|
|
|
|
if ((synth_devs[dev]->alloc.map[i] & 0xff00) == key)
|
|
|
|
synth_devs[dev]->bender(dev, i, w14);
|
|
|
|
} else
|
|
|
|
synth_devs[dev]->bender(dev, chn, w14);
|
|
|
|
} else /* MODE 1 */
|
|
|
|
synth_devs[dev]->bender(dev, chn, w14);
|
|
|
|
break;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
|
|
|
default:;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_timing_event(u_char *event)
|
1994-10-01 02:17:17 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
u_char cmd = event[1];
|
|
|
|
u_int parm = *(int *) &event[4];
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (seq_mode == SEQ_2) {
|
|
|
|
int ret;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if ((ret = tmr->event(tmr_no, event)) == TIMER_ARMED) {
|
|
|
|
if ((SEQ_MAX_QUEUE - qlen) >= output_treshold) {
|
|
|
|
u_long flags;
|
|
|
|
|
|
|
|
flags = splhigh();
|
|
|
|
if ((seq_sleep_flag.mode & WK_SLEEP)) {
|
|
|
|
seq_sleep_flag.mode = WK_WAKEUP;
|
|
|
|
wakeup(seq_sleeper);
|
1994-10-01 02:17:17 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
splx(flags);
|
1994-10-01 02:17:17 +00:00
|
|
|
}
|
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
return ret;
|
1994-10-01 02:17:17 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
switch (cmd) {
|
1994-10-01 02:17:17 +00:00
|
|
|
case TMR_WAIT_REL:
|
1997-10-31 17:25:35 +00:00
|
|
|
parm += prev_event_time;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
|
|
|
* NOTE! No break here. Execution of TMR_WAIT_REL continues
|
|
|
|
* in the next case (TMR_WAIT_ABS)
|
|
|
|
*/
|
1994-10-01 02:17:17 +00:00
|
|
|
|
|
|
|
case TMR_WAIT_ABS:
|
1997-10-31 17:25:35 +00:00
|
|
|
if (parm > 0) {
|
|
|
|
long time;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_playing = 1;
|
|
|
|
time = parm;
|
|
|
|
prev_event_time = time;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
request_sound_timer(time);
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if ((SEQ_MAX_QUEUE - qlen) >= output_treshold) {
|
|
|
|
u_long flags;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
flags = splhigh();
|
|
|
|
if ((seq_sleep_flag.mode & WK_SLEEP)) {
|
|
|
|
seq_sleep_flag.mode = WK_WAKEUP;
|
|
|
|
wakeup(seq_sleeper);
|
1994-10-01 02:17:17 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
splx(flags);
|
1994-10-01 02:17:17 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
return TIMER_ARMED;
|
1994-10-01 02:17:17 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
break;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
|
|
|
case TMR_START:
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_time = get_time();
|
|
|
|
prev_input_time = 0;
|
|
|
|
prev_event_time = 0;
|
|
|
|
break;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
|
|
|
case TMR_STOP:
|
1997-10-31 17:25:35 +00:00
|
|
|
break;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
|
|
|
case TMR_CONTINUE:
|
1997-10-31 17:25:35 +00:00
|
|
|
break;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
|
|
|
case TMR_TEMPO:
|
1997-10-31 17:25:35 +00:00
|
|
|
break;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
|
|
|
case TMR_ECHO:
|
1997-10-31 17:25:35 +00:00
|
|
|
if (seq_mode == SEQ_2)
|
|
|
|
seq_copy_to_input(event, 8);
|
|
|
|
else {
|
|
|
|
parm = (parm << 8 | SEQ_ECHO);
|
|
|
|
seq_copy_to_input((u_char *) &parm, 4);
|
1994-10-01 02:17:17 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
break;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
|
|
|
default:;
|
|
|
|
}
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
return TIMER_NOT_ARMED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
seq_local_event(u_char *event)
|
|
|
|
{
|
|
|
|
u_char cmd = event[1];
|
|
|
|
u_int parm = *((u_int *) &event[4]);
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case LOCL_STARTAUDIO:
|
|
|
|
#ifdef CONFIG_AUDIO
|
|
|
|
DMAbuf_start_devices(parm);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:;
|
|
|
|
}
|
1994-10-01 02:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_sysex_message(u_char *event)
|
1994-10-01 02:17:17 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
int dev = event[1];
|
|
|
|
int i, l = 0;
|
|
|
|
u_char *buf = &event[2];
|
|
|
|
|
|
|
|
if ((int) dev > max_synthdev)
|
|
|
|
return;
|
|
|
|
if (!(synth_open_mask & (1 << dev)))
|
|
|
|
return;
|
|
|
|
if (!synth_devs[dev])
|
|
|
|
return;
|
|
|
|
if (!synth_devs[dev]->send_sysex)
|
|
|
|
return;
|
|
|
|
|
|
|
|
l = 0;
|
|
|
|
for (i = 0; i < 6 && buf[i] != 0xff; i++)
|
|
|
|
l = i + 1;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (l > 0)
|
|
|
|
synth_devs[dev]->send_sysex(dev, buf, l);
|
1994-10-01 02:17:17 +00:00
|
|
|
}
|
|
|
|
|
1995-07-28 21:40:49 +00:00
|
|
|
static int
|
1997-10-31 17:25:35 +00:00
|
|
|
play_event(u_char *q)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
|
|
|
* NOTE! This routine returns 0 = normal event played. 1 = Timer
|
|
|
|
* armed. Suspend playback until timer callback. 2 = MIDI output
|
|
|
|
* buffer full. Restore queue and suspend until timer
|
|
|
|
*/
|
|
|
|
u_long *delay;
|
|
|
|
|
|
|
|
switch (q[0]) {
|
1995-07-28 21:40:49 +00:00
|
|
|
case SEQ_NOTEOFF:
|
1997-10-31 17:25:35 +00:00
|
|
|
if (synth_open_mask & (1 << 0))
|
|
|
|
if (synth_devs[0])
|
|
|
|
synth_devs[0]->kill_note(0, q[1], 255, q[3]);
|
|
|
|
break;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1995-07-28 21:40:49 +00:00
|
|
|
case SEQ_NOTEON:
|
1997-10-31 17:25:35 +00:00
|
|
|
if (q[4] < 128 || q[4] == 255)
|
|
|
|
if (synth_open_mask & (1 << 0))
|
|
|
|
if (synth_devs[0])
|
|
|
|
synth_devs[0]->start_note(0, q[1], q[2], q[3]);
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1995-07-28 21:40:49 +00:00
|
|
|
case SEQ_WAIT:
|
1997-10-31 17:25:35 +00:00
|
|
|
delay = (u_long *) q; /* Bytes 1 to 3 are
|
|
|
|
* containing the * delay in
|
|
|
|
* get_time() */
|
|
|
|
*delay = (*delay >> 8) & 0xffffff;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (*delay > 0) {
|
|
|
|
long time;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_playing = 1;
|
|
|
|
time = *delay;
|
|
|
|
prev_event_time = time;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
request_sound_timer(time);
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if ((SEQ_MAX_QUEUE - qlen) >= output_treshold) {
|
|
|
|
u_long flags;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
flags = splhigh();
|
|
|
|
if ((seq_sleep_flag.mode & WK_SLEEP)) {
|
|
|
|
seq_sleep_flag.mode = WK_WAKEUP;
|
|
|
|
wakeup(seq_sleeper);
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
splx(flags);
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
|
|
|
* The timer is now active and will reinvoke this
|
|
|
|
* function after the timer expires. Return to the
|
|
|
|
* caller now.
|
|
|
|
*/
|
|
|
|
return 1;
|
1995-07-28 21:40:49 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1995-07-28 21:40:49 +00:00
|
|
|
case SEQ_PGMCHANGE:
|
1997-10-31 17:25:35 +00:00
|
|
|
if (synth_open_mask & (1 << 0))
|
|
|
|
if (synth_devs[0])
|
|
|
|
synth_devs[0]->set_instr(0, q[1], q[2]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SEQ_SYNCTIMER: /* Reset timer */
|
|
|
|
seq_time = get_time();
|
|
|
|
prev_input_time = 0;
|
|
|
|
prev_event_time = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SEQ_MIDIPUTC: /* Put a midi character */
|
|
|
|
if (midi_opened[q[2]]) {
|
|
|
|
int dev;
|
|
|
|
|
|
|
|
dev = q[2];
|
|
|
|
|
|
|
|
if (!midi_devs[dev]->putc(dev, q[1])) {
|
|
|
|
/*
|
|
|
|
* Output FIFO is full. Wait one timer cycle and try again.
|
|
|
|
*/
|
|
|
|
|
|
|
|
seq_playing = 1;
|
|
|
|
request_sound_timer(-1);
|
|
|
|
return 2;
|
|
|
|
} else
|
|
|
|
midi_written[dev] = 1;
|
1995-07-28 21:40:49 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1995-07-28 21:40:49 +00:00
|
|
|
case SEQ_ECHO:
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_copy_to_input(q, 4); /* Echo back to the process */
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1995-07-28 21:40:49 +00:00
|
|
|
case SEQ_PRIVATE:
|
1997-10-31 17:25:35 +00:00
|
|
|
if ((int) q[1] < max_synthdev)
|
|
|
|
synth_devs[q[1]]->hw_control(q[1], q);
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1995-07-28 21:40:49 +00:00
|
|
|
case SEQ_EXTENDED:
|
1997-10-31 17:25:35 +00:00
|
|
|
extended_event(q);
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1995-07-28 21:40:49 +00:00
|
|
|
case EV_CHN_VOICE:
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_chn_voice_event(q);
|
|
|
|
break;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1995-07-28 21:40:49 +00:00
|
|
|
case EV_CHN_COMMON:
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_chn_common_event(q);
|
|
|
|
break;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1995-07-28 21:40:49 +00:00
|
|
|
case EV_TIMING:
|
1997-10-31 17:25:35 +00:00
|
|
|
if (seq_timing_event(q) == TIMER_ARMED) {
|
|
|
|
return 1;
|
1995-07-28 21:40:49 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
break;
|
1995-07-28 21:40:49 +00:00
|
|
|
|
|
|
|
case EV_SEQ_LOCAL:
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_local_event(q);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EV_SYSEX:
|
|
|
|
seq_sysex_message(q);
|
|
|
|
break;
|
1995-07-28 21:40:49 +00:00
|
|
|
|
|
|
|
default:;
|
|
|
|
}
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
return 0;
|
1995-07-28 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_startplay(void)
|
1995-07-28 21:40:49 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
u_long flags;
|
|
|
|
int this_one, action;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
while (qlen > 0) {
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
flags = splhigh();
|
|
|
|
qhead = ((this_one = qhead) + 1) % SEQ_MAX_QUEUE;
|
|
|
|
qlen--;
|
|
|
|
splx(flags);
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_playing = 1;
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if ((action = play_event(&queue[this_one * EV_SZ]))) {
|
|
|
|
/*
|
|
|
|
* Suspend playback. Next timer routine invokes this routine again
|
|
|
|
*/
|
|
|
|
if (action == 2) {
|
|
|
|
qlen++;
|
|
|
|
qhead = this_one;
|
1995-07-28 21:40:49 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
return;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_playing = 0;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if ((SEQ_MAX_QUEUE - qlen) >= output_treshold) {
|
|
|
|
u_long flags;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
flags = splhigh();
|
|
|
|
if ((seq_sleep_flag.mode & WK_SLEEP)) {
|
|
|
|
seq_sleep_flag.mode = WK_WAKEUP;
|
|
|
|
wakeup(seq_sleeper);
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
splx(flags);
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-10-01 02:17:17 +00:00
|
|
|
static void
|
1997-10-31 17:25:35 +00:00
|
|
|
reset_controllers(int dev, u_char *controller, int update_dev)
|
1994-10-01 02:17:17 +00:00
|
|
|
{
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
int i;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
for (i = 0; i < 128; i++)
|
|
|
|
controller[i] = ctrl_def_values[i];
|
1994-10-01 02:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1997-10-31 17:25:35 +00:00
|
|
|
setup_mode2(void)
|
1994-10-01 02:17:17 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
int dev;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
max_synthdev = num_synths;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
for (dev = 0; dev < num_midis; dev++)
|
|
|
|
if (midi_devs[dev]->converter != NULL)
|
|
|
|
synth_devs[max_synthdev++] = midi_devs[dev]->converter;
|
|
|
|
for (dev = 0; dev < max_synthdev; dev++) {
|
|
|
|
int chn;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
for (chn = 0; chn < 16; chn++) {
|
|
|
|
synth_devs[dev]->chn_info[chn].pgm_num = 0;
|
|
|
|
reset_controllers(dev,
|
|
|
|
synth_devs[dev]->chn_info[chn].controllers, 0);
|
|
|
|
synth_devs[dev]->chn_info[chn].bender_value = (1<<7); /* Neutral */
|
1994-10-01 02:17:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
max_mididev = 0;
|
|
|
|
seq_mode = SEQ_2;
|
1994-10-01 02:17:17 +00:00
|
|
|
}
|
|
|
|
|
1993-10-23 10:55:52 +00:00
|
|
|
int
|
1997-10-31 17:25:35 +00:00
|
|
|
sequencer_open(int dev, struct fileinfo * file)
|
1994-03-11 10:27:25 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
int retval, mode, i;
|
|
|
|
int level, tmp;
|
|
|
|
u_long flags;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
level = ((dev & 0x0f) == SND_DEV_SEQ2) ? 2 : 1;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
dev = dev >> 4;
|
|
|
|
mode = file->mode & O_ACCMODE;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
DEB(printf("sequencer_open(dev=%d)\n", dev));
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (!sequencer_ok) {
|
|
|
|
printf("Soundcard: Sequencer not initialized\n");
|
|
|
|
return -(ENXIO);
|
1994-03-11 10:27:25 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
if (dev) { /* Patch manager device */
|
|
|
|
int err;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
printf("Patch manager interface is currently broken. Sorry\n");
|
|
|
|
return -(ENXIO);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
dev--;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (dev >= MAX_SYNTH_DEV)
|
|
|
|
return -(ENXIO);
|
|
|
|
if (pmgr_present[dev])
|
|
|
|
return -(EBUSY);
|
|
|
|
if ((err = pmgr_open(dev)) < 0)
|
|
|
|
return err;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
pmgr_present[dev] = 1;
|
|
|
|
return err;
|
1994-03-11 10:27:25 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
flags = splhigh();
|
|
|
|
if (sequencer_busy) {
|
|
|
|
printf("Sequencer busy\n");
|
|
|
|
splx(flags);
|
|
|
|
return -(EBUSY);
|
1994-03-11 10:27:25 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
sequencer_busy = 1;
|
|
|
|
splx(flags);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
max_mididev = num_midis;
|
|
|
|
max_synthdev = num_synths;
|
|
|
|
pre_event_timeout = 0;
|
|
|
|
seq_mode = SEQ_1;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (pending_timer != -1) {
|
|
|
|
tmr_no = pending_timer;
|
|
|
|
pending_timer = -1;
|
1994-10-01 02:17:17 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
if (tmr_no == -1) { /* Not selected yet */
|
|
|
|
int i, best;
|
|
|
|
|
|
|
|
best = -1;
|
|
|
|
for (i = 0; i < num_sound_timers; i++)
|
|
|
|
if (sound_timer_devs[i]->priority > best) {
|
|
|
|
tmr_no = i;
|
|
|
|
best = sound_timer_devs[i]->priority;
|
|
|
|
}
|
|
|
|
if (tmr_no == -1) /* Should not be */
|
|
|
|
tmr_no = 0;
|
1994-03-11 10:27:25 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
tmr = sound_timer_devs[tmr_no];
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (level == 2) {
|
|
|
|
if (tmr == NULL) {
|
|
|
|
printf("sequencer: No timer for level 2\n");
|
|
|
|
sequencer_busy = 0;
|
|
|
|
return -(ENXIO);
|
1994-03-11 10:27:25 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
setup_mode2();
|
1994-10-01 02:17:17 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
if (seq_mode == SEQ_1 && (mode == OPEN_READ || mode == OPEN_READWRITE))
|
|
|
|
if (!max_mididev) {
|
|
|
|
printf("Sequencer: No Midi devices. Input not possible\n");
|
|
|
|
sequencer_busy = 0;
|
|
|
|
return -(ENXIO);
|
|
|
|
}
|
|
|
|
if (!max_synthdev && !max_mididev)
|
|
|
|
return -(ENXIO);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
synth_open_mask = 0;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
for (i = 0; i < max_mididev; i++) {
|
|
|
|
midi_opened[i] = 0;
|
|
|
|
midi_written[i] = 0;
|
|
|
|
}
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
|
|
|
* if (mode == OPEN_WRITE || mode == OPEN_READWRITE)
|
|
|
|
*/
|
|
|
|
for (i = 0; i < max_synthdev; i++) /* Open synth devices */
|
|
|
|
if ((tmp = synth_devs[i]->open(i, mode)) < 0) {
|
|
|
|
printf("Sequencer: Warning! Cannot open synth device #%d (%d)\n",
|
|
|
|
i, tmp);
|
|
|
|
if (synth_devs[i]->midi_dev)
|
|
|
|
printf("(Maps to MIDI dev #%d)\n", synth_devs[i]->midi_dev);
|
|
|
|
} else {
|
|
|
|
synth_open_mask |= (1 << i);
|
|
|
|
if (synth_devs[i]->midi_dev) /* Is a midi interface */
|
|
|
|
midi_opened[synth_devs[i]->midi_dev] = 1;
|
|
|
|
}
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_time = get_time();
|
|
|
|
prev_input_time = 0;
|
|
|
|
prev_event_time = 0;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (seq_mode == SEQ_1 && (mode == OPEN_READ || mode == OPEN_READWRITE)) {
|
|
|
|
/* Initialize midi input devices */
|
|
|
|
for (i = 0; i < max_mididev; i++)
|
|
|
|
if (!midi_opened[i]) {
|
|
|
|
if ((retval = midi_devs[i]->open(i, mode,
|
1993-10-29 03:44:07 +00:00
|
|
|
sequencer_midi_input, sequencer_midi_output)) >= 0)
|
1997-10-31 17:25:35 +00:00
|
|
|
midi_opened[i] = 1;
|
|
|
|
}
|
1994-10-01 02:17:17 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
if (seq_mode == SEQ_2) {
|
|
|
|
tmr->open(tmr_no, seq_mode);
|
1994-03-11 10:27:25 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_sleep_flag.aborting = 0;
|
|
|
|
seq_sleep_flag.mode = WK_NONE;
|
|
|
|
midi_sleep_flag.aborting = 0;
|
|
|
|
midi_sleep_flag.mode = WK_NONE;
|
|
|
|
output_treshold = SEQ_MAX_QUEUE / 2;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
for (i = 0; i < num_synths; i++)
|
|
|
|
if (pmgr_present[i])
|
|
|
|
pmgr_inform(i, PM_E_OPENED, 0, 0, 0, 0);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
return 0;
|
1994-03-11 10:27:25 +00:00
|
|
|
}
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1998-02-09 06:11:36 +00:00
|
|
|
static void
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_drain_midi_queues(void)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
int i, n;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
|
|
|
* Give the Midi drivers time to drain their output queues
|
|
|
|
*/
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
n = 1;
|
|
|
|
|
|
|
|
while (!(seq_sleep_flag.aborting) && n) {
|
|
|
|
n = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < max_mididev; i++)
|
|
|
|
if (midi_opened[i] && midi_written[i])
|
|
|
|
if (midi_devs[i]->buffer_status != NULL)
|
|
|
|
if (midi_devs[i]->buffer_status(i))
|
|
|
|
n++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Let's have a delay
|
|
|
|
*/
|
|
|
|
if (n) {
|
|
|
|
int chn;
|
|
|
|
|
|
|
|
seq_sleeper = &chn;
|
|
|
|
DO_SLEEP(chn, seq_sleep_flag, hz / 10);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1997-10-31 17:25:35 +00:00
|
|
|
sequencer_release(int dev, struct fileinfo * file)
|
1994-03-11 10:27:25 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
int i;
|
|
|
|
int mode = file->mode & O_ACCMODE;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
dev = dev >> 4;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
DEB(printf("sequencer_release(dev=%d)\n", dev));
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (dev) { /* Patch manager device */
|
|
|
|
dev--;
|
|
|
|
pmgr_release(dev);
|
|
|
|
pmgr_present[dev] = 0;
|
|
|
|
return;
|
1994-03-11 10:27:25 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
|
|
|
* Wait until the queue is empty (if we don't have nonblock)
|
|
|
|
*/
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (mode != OPEN_READ && !0)
|
|
|
|
while (!(seq_sleep_flag.aborting) && qlen) {
|
|
|
|
seq_sync();
|
1994-10-01 02:17:17 +00:00
|
|
|
}
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (mode != OPEN_READ)
|
|
|
|
seq_drain_midi_queues(); /* Ensure the output queues are empty */
|
|
|
|
seq_reset();
|
|
|
|
if (mode != OPEN_READ)
|
|
|
|
seq_drain_midi_queues(); /* Flush the all notes off messages */
|
1994-03-11 10:27:25 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
for (i = 0; i < max_synthdev; i++)
|
|
|
|
if (synth_open_mask & (1 << i)) /* Actually opened */
|
|
|
|
if (synth_devs[i]) {
|
|
|
|
synth_devs[i]->close(i);
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (synth_devs[i]->midi_dev)
|
|
|
|
midi_opened[synth_devs[i]->midi_dev] = 0;
|
|
|
|
}
|
|
|
|
for (i = 0; i < num_synths; i++)
|
|
|
|
if (pmgr_present[i])
|
|
|
|
pmgr_inform(i, PM_E_CLOSED, 0, 0, 0, 0);
|
|
|
|
|
|
|
|
for (i = 0; i < max_mididev; i++)
|
|
|
|
if (midi_opened[i])
|
|
|
|
midi_devs[i]->close(i);
|
|
|
|
|
|
|
|
if (seq_mode == SEQ_2)
|
|
|
|
tmr->close(tmr_no);
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
sequencer_busy = 0;
|
1994-03-11 10:27:25 +00:00
|
|
|
}
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
static int
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_sync(void)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
u_long flags;
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (qlen && !seq_playing && !(seq_sleep_flag.aborting))
|
|
|
|
seq_startplay();
|
|
|
|
|
|
|
|
flags = splhigh();
|
|
|
|
if (qlen && !(seq_sleep_flag.mode & WK_SLEEP)) {
|
|
|
|
int chn;
|
|
|
|
|
|
|
|
seq_sleeper = &chn;
|
|
|
|
DO_SLEEP(chn, seq_sleep_flag, 0);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
splx(flags);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
return qlen;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1997-10-31 17:25:35 +00:00
|
|
|
midi_outc(int dev, u_char data)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
|
|
|
* NOTE! Calls sleep(). Don't call this from interrupt.
|
|
|
|
*/
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
int n;
|
|
|
|
u_long flags;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
|
|
|
* This routine sends one byte to the Midi channel. If the output
|
|
|
|
* Fifo is full, it waits until there is space in the queue
|
|
|
|
*/
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
n = 3 * hz; /* Timeout */
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
flags = splhigh();
|
|
|
|
while (n && !midi_devs[dev]->putc(dev, data)) {
|
|
|
|
int chn;
|
|
|
|
seq_sleeper = &chn;
|
|
|
|
DO_SLEEP(chn, seq_sleep_flag, 4);
|
|
|
|
|
|
|
|
n--;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
splx(flags);
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_reset(void)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
|
|
|
* NOTE! Calls sleep(). Don't call this from interrupt.
|
|
|
|
*/
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
int i;
|
|
|
|
int chn;
|
|
|
|
u_long flags;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
sound_stop_timer();
|
|
|
|
seq_time = get_time();
|
|
|
|
prev_input_time = 0;
|
|
|
|
prev_event_time = 0;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
qlen = qhead = qtail = 0;
|
|
|
|
iqlen = iqhead = iqtail = 0;
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
for (i = 0; i < max_synthdev; i++)
|
|
|
|
if (synth_open_mask & (1 << i))
|
1995-07-28 21:40:49 +00:00
|
|
|
if (synth_devs[i])
|
1997-10-31 17:25:35 +00:00
|
|
|
synth_devs[i]->reset(i);
|
|
|
|
|
|
|
|
if (seq_mode == SEQ_2) {
|
|
|
|
for (chn = 0; chn < 16; chn++)
|
|
|
|
for (i = 0; i < max_synthdev; i++)
|
|
|
|
if ( (synth_open_mask & (1 << i)) && (synth_devs[i]) ) {
|
|
|
|
synth_devs[i]->controller(i, chn,123,0);/* All notes off */
|
|
|
|
synth_devs[i]->controller(i, chn,121,0);/* Reset all ctl */
|
|
|
|
synth_devs[i]->bender(i, chn, 1 << 13); /* Bender off */
|
|
|
|
}
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
} else { /* seq_mode == SEQ_1 */
|
|
|
|
for (i = 0; i < max_mididev; i++)
|
|
|
|
if (midi_written[i]) {
|
|
|
|
/* Midi used. Some notes may still be playing */
|
|
|
|
/*
|
|
|
|
* Sending just a ACTIVE SENSING message
|
|
|
|
* should be enough to stop all playing
|
|
|
|
* notes. Since there are devices not
|
|
|
|
* recognizing the active sensing, we have to
|
|
|
|
* send some all notes off messages also.
|
|
|
|
*/
|
|
|
|
midi_outc(i, 0xfe);
|
|
|
|
|
|
|
|
for (chn = 0; chn < 16; chn++) {
|
|
|
|
midi_outc(i, (u_char) (0xb0 + (chn & 0x0f))); /* control change */
|
|
|
|
midi_outc(i, 0x7b); /* All notes off */
|
|
|
|
midi_outc(i, 0); /* Dummy parameter */
|
|
|
|
}
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
midi_devs[i]->close(i);
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
midi_written[i] = 0;
|
|
|
|
midi_opened[i] = 0;
|
|
|
|
}
|
1994-10-01 02:17:17 +00:00
|
|
|
}
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_playing = 0;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
flags = splhigh();
|
|
|
|
if ((seq_sleep_flag.mode & WK_SLEEP)) {
|
|
|
|
seq_sleep_flag.mode = WK_WAKEUP;
|
|
|
|
wakeup(seq_sleeper);
|
1995-07-28 21:40:49 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
splx(flags);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
1994-10-01 02:17:17 +00:00
|
|
|
static void
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_panic(void)
|
1994-10-01 02:17:17 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
|
|
|
* This routine is called by the application in case the user wants
|
|
|
|
* to reset the system to the default state.
|
|
|
|
*/
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_reset();
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
1995-07-28 21:40:49 +00:00
|
|
|
* Since some of the devices don't recognize the active sensing and
|
|
|
|
* all notes off messages, we have to shut all notes manually.
|
1997-10-31 17:25:35 +00:00
|
|
|
*
|
|
|
|
* TO BE IMPLEMENTED LATER
|
|
|
|
*/
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
1995-07-28 21:40:49 +00:00
|
|
|
* Also return the controllers to their default states
|
1997-10-31 17:25:35 +00:00
|
|
|
*/
|
1994-10-01 02:17:17 +00:00
|
|
|
}
|
|
|
|
|
1993-10-23 10:55:52 +00:00
|
|
|
int
|
1997-10-31 17:25:35 +00:00
|
|
|
sequencer_ioctl(int dev, struct fileinfo * file,
|
|
|
|
u_int cmd, ioctl_arg arg)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
int midi_dev, orig_dev;
|
|
|
|
int mode = file->mode & O_ACCMODE;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
orig_dev = dev = dev >> 4;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
switch (cmd) {
|
1994-10-01 02:17:17 +00:00
|
|
|
case SNDCTL_TMR_TIMEBASE:
|
|
|
|
case SNDCTL_TMR_TEMPO:
|
|
|
|
case SNDCTL_TMR_START:
|
|
|
|
case SNDCTL_TMR_STOP:
|
|
|
|
case SNDCTL_TMR_CONTINUE:
|
|
|
|
case SNDCTL_TMR_METRONOME:
|
|
|
|
case SNDCTL_TMR_SOURCE:
|
1997-10-31 17:25:35 +00:00
|
|
|
if (dev) /* Patch manager */
|
|
|
|
return -(EIO);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (seq_mode != SEQ_2)
|
|
|
|
return -(EINVAL);
|
|
|
|
return tmr->ioctl(tmr_no, cmd, arg);
|
|
|
|
break;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
|
|
|
case SNDCTL_TMR_SELECT:
|
1997-10-31 17:25:35 +00:00
|
|
|
if (dev) /* Patch manager */
|
|
|
|
return -(EIO);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (seq_mode != SEQ_2)
|
|
|
|
return -(EINVAL);
|
|
|
|
pending_timer = (*(int *) arg);
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (pending_timer < 0 || pending_timer >= num_sound_timers) {
|
|
|
|
pending_timer = -1;
|
|
|
|
return -(EINVAL);
|
1994-10-01 02:17:17 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
return *(int *) arg = pending_timer;
|
|
|
|
break;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
|
|
|
case SNDCTL_SEQ_PANIC:
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_panic();
|
|
|
|
break;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
|
|
|
case SNDCTL_SEQ_SYNC:
|
1997-10-31 17:25:35 +00:00
|
|
|
if (dev) /* Patch manager */
|
|
|
|
return -(EIO);
|
|
|
|
|
|
|
|
if (mode == OPEN_READ)
|
|
|
|
return 0;
|
|
|
|
while (qlen && !(seq_sleep_flag.aborting))
|
|
|
|
seq_sync();
|
|
|
|
if (qlen)
|
|
|
|
return -(EINTR);
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
case SNDCTL_SEQ_RESET:
|
1997-10-31 17:25:35 +00:00
|
|
|
if (dev) /* Patch manager */
|
|
|
|
return -(EIO);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_reset();
|
|
|
|
return 0;
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
case SNDCTL_SEQ_TESTMIDI:
|
1997-10-31 17:25:35 +00:00
|
|
|
if (dev) /* Patch manager */
|
|
|
|
return -(EIO);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
midi_dev = (*(int *) arg);
|
|
|
|
if (midi_dev >= max_mididev)
|
|
|
|
return -(ENXIO);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (!midi_opened[midi_dev]) {
|
|
|
|
int err, mode;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
mode = file->mode & O_ACCMODE;
|
|
|
|
if ((err = midi_devs[midi_dev]->open(midi_dev, mode,
|
|
|
|
sequencer_midi_input, sequencer_midi_output)) < 0)
|
|
|
|
return err;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
1997-10-31 17:25:35 +00:00
|
|
|
midi_opened[midi_dev] = 1;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
return 0;
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
case SNDCTL_SEQ_GETINCOUNT:
|
1997-10-31 17:25:35 +00:00
|
|
|
if (dev) /* Patch manager */
|
|
|
|
return -(EIO);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (mode == OPEN_WRITE)
|
|
|
|
return 0;
|
|
|
|
return *(int *) arg = iqlen;
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
case SNDCTL_SEQ_GETOUTCOUNT:
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (mode == OPEN_READ)
|
|
|
|
return 0;
|
|
|
|
return *(int *) arg = SEQ_MAX_QUEUE - qlen;
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
case SNDCTL_SEQ_CTRLRATE:
|
1997-10-31 17:25:35 +00:00
|
|
|
if (dev) /* Patch manager */
|
|
|
|
return -(EIO);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
|
|
|
* If *arg == 0, just return the current rate
|
|
|
|
*/
|
|
|
|
if (seq_mode == SEQ_2)
|
|
|
|
return tmr->ioctl(tmr_no, cmd, arg);
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if ((*(int *) arg) != 0)
|
|
|
|
return -(EINVAL);
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
return *(int *) arg = hz;
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
case SNDCTL_SEQ_RESETSAMPLES:
|
1997-10-31 17:25:35 +00:00
|
|
|
{
|
|
|
|
int err;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
dev = (*(int *) arg);
|
|
|
|
if (dev < 0 || dev >= num_synths)
|
|
|
|
return -(ENXIO);
|
|
|
|
if (!(synth_open_mask & (1 << dev)) && !orig_dev)
|
|
|
|
return -(EBUSY);
|
|
|
|
if (!orig_dev && pmgr_present[dev])
|
|
|
|
pmgr_inform(dev, PM_E_PATCH_RESET, 0, 0, 0, 0);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
err = synth_devs[dev]->ioctl(dev, cmd, arg);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
case SNDCTL_SEQ_NRSYNTHS:
|
1997-10-31 17:25:35 +00:00
|
|
|
return *(int *) arg = max_synthdev;
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
case SNDCTL_SEQ_NRMIDIS:
|
1997-10-31 17:25:35 +00:00
|
|
|
return *(int *) arg = max_mididev;
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
case SNDCTL_SYNTH_MEMAVL:
|
1997-10-31 17:25:35 +00:00
|
|
|
{
|
|
|
|
int dev = (*(int *) arg);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (dev < 0 || dev >= num_synths)
|
|
|
|
return -(ENXIO);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (!(synth_open_mask & (1 << dev)) && !orig_dev)
|
|
|
|
return -(EBUSY);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
return *(int *) arg = synth_devs[dev]->ioctl(dev, cmd, arg);
|
|
|
|
}
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
case SNDCTL_FM_4OP_ENABLE:
|
1997-10-31 17:25:35 +00:00
|
|
|
{
|
|
|
|
int dev = (*(int *) arg);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (dev < 0 || dev >= num_synths)
|
|
|
|
return -(ENXIO);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (!(synth_open_mask & (1 << dev)))
|
|
|
|
return -(ENXIO);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
synth_devs[dev]->ioctl(dev, cmd, arg);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
case SNDCTL_SYNTH_INFO:
|
1997-10-31 17:25:35 +00:00
|
|
|
{
|
|
|
|
struct synth_info inf;
|
|
|
|
int dev;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
bcopy(&(((char *) arg)[0]), (char *) &inf, sizeof(inf));
|
|
|
|
dev = inf.device;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (dev < 0 || dev >= max_synthdev)
|
|
|
|
return -(ENXIO);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (!(synth_open_mask & (1 << dev)) && !orig_dev)
|
|
|
|
return -(EBUSY);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
return synth_devs[dev]->ioctl(dev, cmd, arg);
|
|
|
|
}
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1995-07-28 21:40:49 +00:00
|
|
|
case SNDCTL_SEQ_OUTOFBAND:
|
1997-10-31 17:25:35 +00:00
|
|
|
{
|
|
|
|
struct seq_event_rec event;
|
|
|
|
u_long flags;
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
bcopy(&(((char *) arg)[0]), (char *) &event, sizeof(event));
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
flags = splhigh();
|
|
|
|
play_event(event.arr);
|
|
|
|
splx(flags);
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
1995-07-28 21:40:49 +00:00
|
|
|
|
1993-10-23 10:55:52 +00:00
|
|
|
case SNDCTL_MIDI_INFO:
|
1997-10-31 17:25:35 +00:00
|
|
|
{
|
|
|
|
struct midi_info inf;
|
|
|
|
int dev;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
bcopy(&(((char *) arg)[0]), (char *) &inf, sizeof(inf));
|
|
|
|
dev = inf.device;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (dev < 0 || dev >= max_mididev)
|
|
|
|
return -(ENXIO);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
bcopy((char *) &(midi_devs[dev]->info), &(((char *) arg)[0]), sizeof(inf));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
case SNDCTL_PMGR_IFACE:
|
1997-10-31 17:25:35 +00:00
|
|
|
{
|
|
|
|
struct patmgr_info *inf;
|
|
|
|
int dev, err;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if ((inf = (struct patmgr_info *) malloc(sizeof(*inf), M_TEMP, M_WAITOK)) == NULL) {
|
|
|
|
printf("patmgr: Can't allocate memory for a message\n");
|
|
|
|
return -(EIO);
|
|
|
|
}
|
|
|
|
bcopy(&(((char *) arg)[0]), (char *) inf, sizeof(*inf));
|
|
|
|
dev = inf->device;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (dev < 0 || dev >= num_synths) {
|
|
|
|
free(inf, M_TEMP);
|
|
|
|
return -(ENXIO);
|
|
|
|
}
|
|
|
|
if (!synth_devs[dev]->pmgr_interface) {
|
|
|
|
free(inf, M_TEMP);
|
|
|
|
return -(ENXIO);
|
|
|
|
}
|
|
|
|
if ((err = synth_devs[dev]->pmgr_interface(dev, inf)) == -1) {
|
|
|
|
free(inf, M_TEMP);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
bcopy((char *) inf, &(((char *) arg)[0]), sizeof(*inf));
|
|
|
|
free(inf, M_TEMP);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
case SNDCTL_PMGR_ACCESS:
|
|
|
|
{
|
|
|
|
struct patmgr_info *inf;
|
|
|
|
int dev, err;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if ((inf = (struct patmgr_info *) malloc(sizeof(*inf), M_TEMP, M_WAITOK)) == NULL) {
|
|
|
|
printf("patmgr: Can't allocate memory for a message\n");
|
|
|
|
return -(EIO);
|
|
|
|
}
|
|
|
|
bcopy(&(((char *) arg)[0]), (char *) inf, sizeof(*inf));
|
|
|
|
dev = inf->device;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (dev < 0 || dev >= num_synths) {
|
|
|
|
free(inf, M_TEMP);
|
|
|
|
return -(ENXIO);
|
|
|
|
}
|
|
|
|
if (!pmgr_present[dev]) {
|
|
|
|
free(inf, M_TEMP);
|
|
|
|
return -(ESRCH);
|
|
|
|
}
|
|
|
|
if ((err = pmgr_access(dev, inf)) < 0) {
|
|
|
|
free(inf, M_TEMP);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
bcopy((char *) inf, &(((char *) arg)[0]), sizeof(*inf));
|
|
|
|
free(inf, M_TEMP);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
case SNDCTL_SEQ_THRESHOLD:
|
|
|
|
{
|
|
|
|
int tmp = (*(int *) arg);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (dev)/* Patch manager */
|
|
|
|
return -(EIO);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (tmp < 1)
|
|
|
|
tmp = 1;
|
|
|
|
if (tmp >= SEQ_MAX_QUEUE)
|
|
|
|
tmp = SEQ_MAX_QUEUE - 1;
|
|
|
|
output_treshold = tmp;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
1994-10-01 02:17:17 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
case SNDCTL_MIDI_PRETIME:
|
|
|
|
{
|
|
|
|
int val = (*(int *) arg);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (val < 0)
|
|
|
|
val = 0;
|
1997-09-14 03:12:54 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
val = (hz * val) / 10;
|
|
|
|
pre_event_timeout = val;
|
|
|
|
return *(int *) arg = val;
|
|
|
|
}
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
default:
|
|
|
|
if (dev) /* Patch manager */
|
|
|
|
return -(EIO);
|
|
|
|
|
|
|
|
if (mode == OPEN_READ)
|
|
|
|
return -(EIO);
|
|
|
|
|
|
|
|
if (!synth_devs[0])
|
|
|
|
return -(ENXIO);
|
|
|
|
if (!(synth_open_mask & (1 << 0)))
|
|
|
|
return -(ENXIO);
|
|
|
|
return synth_devs[0]->ioctl(0, cmd, arg);
|
|
|
|
break;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
return -(EINVAL);
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
1997-11-10 18:31:35 +00:00
|
|
|
#ifdef ALLOW_POLL
|
|
|
|
int
|
|
|
|
sequencer_poll (int dev, struct fileinfo *file, int events, select_table * wait)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
int revents = 0;
|
|
|
|
|
|
|
|
dev = dev >> 4;
|
|
|
|
flags = splhigh();
|
|
|
|
|
|
|
|
|
|
|
|
if (events & (POLLIN | POLLRDNORM))
|
|
|
|
if (!iqlen)
|
|
|
|
selrecord(wait, &selinfo[dev]);
|
|
|
|
else {
|
|
|
|
revents |= events & (POLLIN | POLLRDNORM);
|
|
|
|
midi_sleep_flag.mode &= ~WK_SLEEP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (events & (POLLOUT | POLLWRNORM))
|
|
|
|
if (qlen >= SEQ_MAX_QUEUE)
|
|
|
|
selrecord(wait, &selinfo[dev]);
|
|
|
|
else {
|
|
|
|
revents |= events & (POLLOUT | POLLWRNORM);
|
|
|
|
seq_sleep_flag.mode &= ~WK_SLEEP;
|
|
|
|
}
|
|
|
|
|
|
|
|
splx(flags);
|
|
|
|
|
|
|
|
return (revents);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
void
|
1997-10-31 17:25:35 +00:00
|
|
|
sequencer_timer(void *dummy)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
seq_startplay();
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1997-10-31 17:25:35 +00:00
|
|
|
note_to_freq(int note_num)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
|
|
|
* This routine converts a midi note to a frequency (multiplied by
|
|
|
|
* 1000)
|
|
|
|
*/
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
int note, octave, note_freq;
|
|
|
|
int notes[] =
|
|
|
|
{
|
|
|
|
261632, 277189, 293671, 311132, 329632, 349232,
|
|
|
|
369998, 391998, 415306, 440000, 466162, 493880
|
|
|
|
};
|
1993-10-23 10:55:52 +00:00
|
|
|
|
|
|
|
#define BASE_OCTAVE 5
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
octave = note_num / 12;
|
|
|
|
note = note_num % 12;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
note_freq = notes[note];
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (octave < BASE_OCTAVE)
|
|
|
|
note_freq >>= (BASE_OCTAVE - octave);
|
|
|
|
else if (octave > BASE_OCTAVE)
|
|
|
|
note_freq <<= (octave - BASE_OCTAVE);
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
|
|
|
* note_freq >>= 1;
|
|
|
|
*/
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
return note_freq;
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
u_long
|
|
|
|
compute_finetune(u_long base_freq, int bend, int range)
|
1993-10-23 10:55:52 +00:00
|
|
|
{
|
1997-10-31 17:25:35 +00:00
|
|
|
u_long amount;
|
|
|
|
int negative, semitones, cents, multiplier = 1;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (!bend)
|
|
|
|
return base_freq;
|
|
|
|
if (!range)
|
|
|
|
return base_freq;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (!base_freq)
|
|
|
|
return base_freq;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (range >= 8192)
|
|
|
|
range = 8192;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
bend = bend * range / 8192;
|
|
|
|
if (!bend)
|
|
|
|
return base_freq;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
negative = bend < 0 ? 1 : 0;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (bend < 0)
|
|
|
|
bend *= -1;
|
|
|
|
if (bend > range)
|
|
|
|
bend = range;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
/*
|
|
|
|
* if (bend > 2399) bend = 2399;
|
|
|
|
*/
|
|
|
|
while (bend > 2399) {
|
|
|
|
multiplier *= 4;
|
|
|
|
bend -= 2400;
|
1994-04-23 01:50:14 +00:00
|
|
|
}
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
semitones = bend / 100;
|
|
|
|
cents = bend % 100;
|
1994-03-11 10:27:25 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
amount = (int) (semitone_tuning[semitones] * multiplier * cent_tuning[cents])
|
|
|
|
/ 10000;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
if (negative)
|
|
|
|
return (base_freq * 10000) / amount; /* Bend down */
|
|
|
|
else
|
|
|
|
return (base_freq * amount) / 10000; /* Bend up */
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
1997-10-31 17:25:35 +00:00
|
|
|
sequencer_init()
|
1994-03-11 10:27:25 +00:00
|
|
|
{
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
sequencer_ok = 1;
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
queue = (u_char *) malloc(SEQ_MAX_QUEUE * EV_SZ, M_DEVBUF, M_NOWAIT);
|
|
|
|
if (!queue)
|
|
|
|
panic("SOUND: Cannot allocate memory\n");
|
1993-10-23 10:55:52 +00:00
|
|
|
|
1997-10-31 17:25:35 +00:00
|
|
|
iqueue = (u_char *) malloc(SEQ_MAX_QUEUE * IEV_SZ, M_DEVBUF, M_NOWAIT);
|
|
|
|
if (!iqueue)
|
|
|
|
panic("SOUND: Cannot allocate memory\n");
|
1993-10-23 10:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
1995-07-28 21:40:49 +00:00
|
|
|
#endif
|