FreeBSD kernel sound device code
sequencer.c File Reference
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/ioccom.h>
#include <sys/filio.h>
#include <sys/lock.h>
#include <sys/sockio.h>
#include <sys/fcntl.h>
#include <sys/proc.h>
#include <sys/sysctl.h>
#include <sys/kernel.h>
#include <sys/module.h>
#include <sys/conf.h>
#include <sys/file.h>
#include <sys/uio.h>
#include <sys/syslog.h>
#include <sys/errno.h>
#include <sys/malloc.h>
#include <sys/bus.h>
#include <machine/resource.h>
#include <machine/bus.h>
#include <machine/clock.h>
#include <sys/soundcard.h>
#include <sys/rman.h>
#include <sys/mman.h>
#include <sys/poll.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/kthread.h>
#include <sys/unistd.h>
#include <sys/selinfo.h>
#include <dev/sound/midi/midi.h>
#include <dev/sound/midi/midiq.h>
#include "synth_if.h"
#include <dev/sound/midi/sequencer.h>
Include dependency graph for sequencer.c:

Go to the source code of this file.

Data Structures

struct  seq_softc
 

Macros

#define TMR_TIMERBASE   13
 
#define SND_DEV_SEQ
 
#define SND_DEV_MUSIC   8 /* /dev/music, level 2 interface */
 
#define EV_SZ   8
 
#define IEV_SZ   8
 
#define LOOKUP_EXIST   (0)
 
#define LOOKUP_OPEN   (1)
 
#define LOOKUP_CLOSE   (2)
 
#define PCMMKMINOR(u, d, c)    ((((c) & 0xff) << 16) | (((u) & 0x0f) << 4) | ((d) & 0x0f))
 
#define MIDIMKMINOR(u, d, c)   PCMMKMINOR(u, d, c)
 
#define MIDIUNIT(y)   ((dev2unit(y) >> 4) & 0x0f)
 
#define MIDIDEV(y)   (dev2unit(y) & 0x0f)
 
#define KOBJMETHOD_END   { NULL, NULL }
 
#define SEQ_RSIZE   32
 
#define SEQ_SYNC_TIMEOUT   8
 

Functions

 __FBSDID ("$FreeBSD$")
 
 SYSCTL_NODE (_hw_midi, OID_AUTO, seq, CTLFLAG_RD|CTLFLAG_MPSAFE, 0, "Midi sequencer")
 
 SYSCTL_INT (_hw_midi_seq, OID_AUTO, debug, CTLFLAG_RW, &seq_debug, 0, "")
 
 DEFINE_CLASS (sequencer, seq_methods, 0)
 
static int seq_convertold (u_char *event, u_char *out)
 
static void seq_reset (struct seq_softc *scp)
 
static int seq_sync (struct seq_softc *scp)
 
static int seq_processevent (struct seq_softc *scp, u_char *event)
 
static int seq_timing (struct seq_softc *scp, u_char *event)
 
static int seq_local (struct seq_softc *scp, u_char *event)
 
static int seq_chnvoice (struct seq_softc *scp, kobj_t md, u_char *event)
 
static int seq_chncommon (struct seq_softc *scp, kobj_t md, u_char *event)
 
static int seq_sysex (struct seq_softc *scp, kobj_t md, u_char *event)
 
static int seq_fetch_mid (struct seq_softc *scp, int unit, kobj_t *md)
 
void seq_copytoinput (struct seq_softc *scp, u_char *event, int len)
 
int seq_modevent (module_t mod, int type, void *data)
 
static void timer_start (struct seq_softc *t)
 
static void timer_stop (struct seq_softc *t)
 
static void timer_setvals (struct seq_softc *t, int tempo, int timerbase)
 
static void timer_wait (struct seq_softc *t, int ticks, int wait_abs)
 
static int timer_now (struct seq_softc *t)
 
static void timer_continue (struct seq_softc *t)
 
static void seq_eventthread (void *arg)
 
static int seq_addunit (void)
 
static int seq_delunit (int unit)
 
int mseq_open (struct cdev *i_dev, int flags, int mode, struct thread *td)
 
int mseq_close (struct cdev *i_dev, int flags, int mode, struct thread *td)
 
int mseq_read (struct cdev *i_dev, struct uio *uio, int ioflag)
 
int mseq_write (struct cdev *i_dev, struct uio *uio, int ioflag)
 
int mseq_ioctl (struct cdev *i_dev, u_long cmd, caddr_t arg, int mode, struct thread *td)
 
int mseq_poll (struct cdev *i_dev, int events, struct thread *td)
 
char * midi_cmdname (int cmd, midi_cmdtab *tab)
 

Variables

static d_open_t mseq_open
 
static d_close_t mseq_close
 
static d_ioctl_t mseq_ioctl
 
static d_read_t mseq_read
 
static d_write_t mseq_write
 
static d_poll_t mseq_poll
 
static struct cdevsw seq_cdevsw
 
int seq_debug
 
midi_cmdtab cmdtab_seqevent []
 
midi_cmdtab cmdtab_seqioctl []
 
midi_cmdtab cmdtab_timer []
 
midi_cmdtab cmdtab_seqcv []
 
midi_cmdtab cmdtab_seqccmn []
 
static kobj_method_t seq_methods []
 
struct seq_softcseqs [10]
 
static struct mtx seqinfo_mtx
 
static u_long nseq = 0
 

Macro Definition Documentation

◆ EV_SZ

#define EV_SZ   8

Definition at line 87 of file sequencer.c.

◆ IEV_SZ

#define IEV_SZ   8

Definition at line 88 of file sequencer.c.

◆ KOBJMETHOD_END

#define KOBJMETHOD_END   { NULL, NULL }

Definition at line 267 of file sequencer.c.

◆ LOOKUP_CLOSE

#define LOOKUP_CLOSE   (2)

Definition at line 93 of file sequencer.c.

◆ LOOKUP_EXIST

#define LOOKUP_EXIST   (0)

Definition at line 91 of file sequencer.c.

◆ LOOKUP_OPEN

#define LOOKUP_OPEN   (1)

Definition at line 92 of file sequencer.c.

◆ MIDIDEV

#define MIDIDEV (   y)    (dev2unit(y) & 0x0f)

Definition at line 99 of file sequencer.c.

◆ MIDIMKMINOR

#define MIDIMKMINOR (   u,
  d,
  c 
)    PCMMKMINOR(u, d, c)

Definition at line 97 of file sequencer.c.

◆ MIDIUNIT

#define MIDIUNIT (   y)    ((dev2unit(y) >> 4) & 0x0f)

Definition at line 98 of file sequencer.c.

◆ PCMMKMINOR

#define PCMMKMINOR (   u,
  d,
  c 
)     ((((c) & 0xff) << 16) | (((u) & 0x0f) << 4) | ((d) & 0x0f))

Definition at line 95 of file sequencer.c.

◆ SEQ_RSIZE

#define SEQ_RSIZE   32

◆ SEQ_SYNC_TIMEOUT

#define SEQ_SYNC_TIMEOUT   8

Definition at line 2010 of file sequencer.c.

◆ SND_DEV_MUSIC

#define SND_DEV_MUSIC   8 /* /dev/music, level 2 interface */

Definition at line 84 of file sequencer.c.

◆ SND_DEV_SEQ

#define SND_DEV_SEQ
Value:
1 /* Sequencer output /dev/sequencer (FM
* synthesizer and MIDI output) */

Definition at line 83 of file sequencer.c.

◆ TMR_TIMERBASE

#define TMR_TIMERBASE   13

Definition at line 81 of file sequencer.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ DEFINE_CLASS()

DEFINE_CLASS ( sequencer  ,
seq_methods  ,
 
)

◆ midi_cmdname()

char * midi_cmdname ( int  cmd,
midi_cmdtab tab 
)

Definition at line 2095 of file sequencer.c.

References _midi_cmdtab::cmd, and _midi_cmdtab::name.

Referenced by mseq_ioctl(), mseq_write(), seq_chncommon(), and seq_chnvoice().

Here is the caller graph for this function:

◆ mseq_close()

int mseq_close ( struct cdev *  i_dev,
int  flags,
int  mode,
struct thread *  td 
)

Definition at line 824 of file sequencer.c.

References midimapper_close(), SEQ_DEBUG, seq_reset(), seq_sync(), and timer_stop().

Here is the call graph for this function:

◆ mseq_ioctl()

int mseq_ioctl ( struct cdev *  i_dev,
u_long  cmd,
caddr_t  arg,
int  mode,
struct thread *  td 
)

◆ mseq_open()

int mseq_open ( struct cdev *  i_dev,
int  flags,
int  mode,
struct thread *  td 
)

Definition at line 741 of file sequencer.c.

References MIDIDEV, midimapper_fetch_synth(), midimapper_open(), MIDIQ_SIZE, SEQ_DEBUG, SND_DEV_MUSIC, timer_setvals(), timer_start(), and timer_stop().

Here is the call graph for this function:

◆ mseq_poll()

int mseq_poll ( struct cdev *  i_dev,
int  events,
struct thread *  td 
)

Definition at line 1431 of file sequencer.c.

References MIDIQ_AVAIL, MIDIQ_LEN, and SEQ_DEBUG.

◆ mseq_read()

int mseq_read ( struct cdev *  i_dev,
struct uio *  uio,
int  ioflag 
)

Definition at line 862 of file sequencer.c.

References buf, MIDIQ_DEQ, MIDIQ_EMPTY, MIDIQ_LEN, SEQ_DEBUG, and SEQ_RSIZE.

◆ mseq_write()

int mseq_write ( struct cdev *  i_dev,
struct uio *  uio,
int  ioflag 
)

Definition at line 940 of file sequencer.c.

References buf, cmdtab_seqevent, count, error, EV_SZ, LOOKUP_OPEN, midi_cmdname(), MIDIQ_AVAIL, MIDIQ_ENQ, MIDIQ_LEN, seq_convertold(), SEQ_DEBUG, and seq_processevent().

Here is the call graph for this function:

◆ seq_addunit()

static int seq_addunit ( void  )
static

Definition at line 521 of file sequencer.c.

References buf, EV_SZ, free, midimapper_addseq(), MIDIMKMINOR, MIDIQ_INIT, nseq, seq_cdevsw, SEQ_DEBUG, seq_eventthread(), seqinfo_mtx, seqs, SND_DEV_MUSIC, SND_DEV_SEQ, and seq_softc::th_cv.

Referenced by seq_modevent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ seq_chncommon()

static int seq_chncommon ( struct seq_softc scp,
kobj_t  md,
u_char *  event 
)
static

Definition at line 1765 of file sequencer.c.

References cmdtab_seqccmn, key, midi_cmdname(), QUEUEFULL, and SEQ_DEBUG.

Referenced by seq_processevent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ seq_chnvoice()

static int seq_chnvoice ( struct seq_softc scp,
kobj_t  md,
u_char *  event 
)
static

Definition at line 1691 of file sequencer.c.

References cmdtab_seqcv, midi_cmdname(), and SEQ_DEBUG.

Referenced by seq_processevent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ seq_convertold()

static int seq_convertold ( u_char *  event,
u_char *  out 
)
static

Definition at line 1503 of file sequencer.c.

References dev, MORE, QUEUEFULL, seq_copytoinput(), and SEQ_DEBUG.

Referenced by mseq_ioctl(), and mseq_write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ seq_copytoinput()

void seq_copytoinput ( struct seq_softc scp,
u_char *  event,
int  len 
)

Definition at line 1672 of file sequencer.c.

References len, MIDIQ_AVAIL, MIDIQ_ENQ, and SEQ_DEBUG.

Referenced by seq_convertold(), and seq_timing().

Here is the caller graph for this function:

◆ seq_delunit()

static int seq_delunit ( int  unit)
static

Definition at line 629 of file sequencer.c.

References free, nseq, SEQ_DEBUG, seqinfo_mtx, seqs, and seq_softc::th_cv.

Referenced by seq_modevent().

Here is the caller graph for this function:

◆ seq_eventthread()

static void seq_eventthread ( void *  arg)
static

Definition at line 433 of file sequencer.c.

References EV_SZ, MIDIQ_AVAIL, MIDIQ_DEQ, MIDIQ_EMPTY, SEQ_DEBUG, seq_processevent(), and seq_softc::th_cv.

Referenced by seq_addunit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ seq_fetch_mid()

static int seq_fetch_mid ( struct seq_softc scp,
int  unit,
kobj_t *  md 
)
static

Definition at line 729 of file sequencer.c.

Referenced by mseq_ioctl(), and seq_processevent().

Here is the caller graph for this function:

◆ seq_local()

static int seq_local ( struct seq_softc scp,
u_char *  event 
)
static

Definition at line 1919 of file sequencer.c.

References SEQ_DEBUG.

Referenced by seq_processevent().

Here is the caller graph for this function:

◆ seq_modevent()

int seq_modevent ( module_t  mod,
int  type,
void *  data 
)

Definition at line 695 of file sequencer.c.

References nseq, r, seq_addunit(), seq_delunit(), seqinfo_mtx, and type.

Referenced by midi_modevent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ seq_processevent()

static int seq_processevent ( struct seq_softc scp,
u_char *  event 
)
static

Definition at line 478 of file sequencer.c.

References m, seq_chncommon(), seq_chnvoice(), SEQ_DEBUG, seq_fetch_mid(), seq_local(), seq_sysex(), and seq_timing().

Referenced by mseq_ioctl(), mseq_write(), and seq_eventthread().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ seq_reset()

static void seq_reset ( struct seq_softc scp)
static

Definition at line 1965 of file sequencer.c.

References m, MIDIQ_CLEAR, and SEQ_DEBUG.

Referenced by mseq_close(), and mseq_ioctl().

Here is the caller graph for this function:

◆ seq_sync()

static int seq_sync ( struct seq_softc scp)
static

Definition at line 2012 of file sequencer.c.

References MIDIQ_CLEAR, MIDIQ_EMPTY, MIDIQ_LEN, SEQ_DEBUG, and SEQ_SYNC_TIMEOUT.

Referenced by mseq_close(), and mseq_ioctl().

Here is the caller graph for this function:

◆ seq_sysex()

static int seq_sysex ( struct seq_softc scp,
kobj_t  md,
u_char *  event 
)
static

Definition at line 1939 of file sequencer.c.

References SEQ_DEBUG.

Referenced by seq_processevent().

Here is the caller graph for this function:

◆ seq_timing()

static int seq_timing ( struct seq_softc scp,
u_char *  event 
)
static

Definition at line 1841 of file sequencer.c.

References param, seq_copytoinput(), SEQ_DEBUG, timer_continue(), timer_setvals(), timer_start(), timer_stop(), timer_wait(), and TMR_TIMERBASE.

Referenced by seq_processevent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SYSCTL_INT()

SYSCTL_INT ( _hw_midi_seq  ,
OID_AUTO  ,
debug  ,
CTLFLAG_RW  ,
seq_debug,
,
""   
)

◆ SYSCTL_NODE()

SYSCTL_NODE ( _hw_midi  ,
OID_AUTO  ,
seq  ,
CTLFLAG_RD|  CTLFLAG_MPSAFE,
,
"Midi sequencer"   
)

◆ timer_continue()

static void timer_continue ( struct seq_softc t)
static

Definition at line 320 of file sequencer.c.

Referenced by seq_timing().

Here is the caller graph for this function:

◆ timer_now()

static int timer_now ( struct seq_softc t)
static

Definition at line 405 of file sequencer.c.

Referenced by mseq_ioctl().

Here is the caller graph for this function:

◆ timer_setvals()

static void timer_setvals ( struct seq_softc t,
int  tempo,
int  timerbase 
)
static

Definition at line 340 of file sequencer.c.

Referenced by mseq_open(), and seq_timing().

Here is the caller graph for this function:

◆ timer_start()

static void timer_start ( struct seq_softc t)
static

Definition at line 313 of file sequencer.c.

Referenced by mseq_open(), and seq_timing().

Here is the caller graph for this function:

◆ timer_stop()

static void timer_stop ( struct seq_softc t)
static

Definition at line 333 of file sequencer.c.

Referenced by mseq_close(), mseq_open(), and seq_timing().

Here is the caller graph for this function:

◆ timer_wait()

static void timer_wait ( struct seq_softc t,
int  ticks,
int  wait_abs 
)
static

Definition at line 347 of file sequencer.c.

References SEQ_DEBUG.

Referenced by seq_timing().

Here is the caller graph for this function:

Variable Documentation

◆ cmdtab_seqccmn

midi_cmdtab cmdtab_seqccmn[]
Initial value:
= {
{MIDI_CTL_CHANGE, "MIDI_CTL_CHANGE"},
{MIDI_PGM_CHANGE, "MIDI_PGM_CHANGE"},
{MIDI_CHN_PRESSURE, "MIDI_CHN_PRESSURE"},
{MIDI_PITCH_BEND, "MIDI_PITCH_BEND"},
{MIDI_SYSTEM_PREFIX, "MIDI_SYSTEM_PREFIX"},
{-1, NULL},
}

Definition at line 257 of file sequencer.c.

Referenced by seq_chncommon().

◆ cmdtab_seqcv

midi_cmdtab cmdtab_seqcv[]
Initial value:
= {
{MIDI_NOTEOFF, "MIDI_NOTEOFF"},
{MIDI_NOTEON, "MIDI_NOTEON"},
{MIDI_KEY_PRESSURE, "MIDI_KEY_PRESSURE"},
{-1, NULL},
}

Definition at line 250 of file sequencer.c.

Referenced by seq_chnvoice().

◆ cmdtab_seqevent

midi_cmdtab cmdtab_seqevent[]
Initial value:
= {
{SEQ_NOTEOFF, "SEQ_NOTEOFF"},
{SEQ_NOTEON, "SEQ_NOTEON"},
{SEQ_WAIT, "SEQ_WAIT"},
{SEQ_PGMCHANGE, "SEQ_PGMCHANGE"},
{SEQ_SYNCTIMER, "SEQ_SYNCTIMER"},
{SEQ_MIDIPUTC, "SEQ_MIDIPUTC"},
{SEQ_DRUMON, "SEQ_DRUMON"},
{SEQ_DRUMOFF, "SEQ_DRUMOFF"},
{SEQ_ECHO, "SEQ_ECHO"},
{SEQ_AFTERTOUCH, "SEQ_AFTERTOUCH"},
{SEQ_CONTROLLER, "SEQ_CONTROLLER"},
{SEQ_BALANCE, "SEQ_BALANCE"},
{SEQ_VOLMODE, "SEQ_VOLMODE"},
{SEQ_FULLSIZE, "SEQ_FULLSIZE"},
{SEQ_PRIVATE, "SEQ_PRIVATE"},
{SEQ_EXTENDED, "SEQ_EXTENDED"},
{EV_SEQ_LOCAL, "EV_SEQ_LOCAL"},
{EV_TIMING, "EV_TIMING"},
{EV_CHN_COMMON, "EV_CHN_COMMON"},
{EV_CHN_VOICE, "EV_CHN_VOICE"},
{EV_SYSEX, "EV_SYSEX"},
{-1, NULL},
}

Definition at line 168 of file sequencer.c.

Referenced by mseq_write().

◆ cmdtab_seqioctl

midi_cmdtab cmdtab_seqioctl[]

Definition at line 193 of file sequencer.c.

Referenced by mseq_ioctl().

◆ cmdtab_timer

midi_cmdtab cmdtab_timer[]
Initial value:
= {
{TMR_WAIT_REL, "TMR_WAIT_REL"},
{TMR_WAIT_ABS, "TMR_WAIT_ABS"},
{TMR_STOP, "TMR_STOP"},
{TMR_START, "TMR_START"},
{TMR_CONTINUE, "TMR_CONTINUE"},
{TMR_TEMPO, "TMR_TEMPO"},
{TMR_ECHO, "TMR_ECHO"},
{TMR_CLOCK, "TMR_CLOCK"},
{TMR_SPP, "TMR_SPP"},
{TMR_TIMESIG, "TMR_TIMESIG"},
{-1, NULL},
}

Definition at line 236 of file sequencer.c.

◆ mseq_close

d_close_t mseq_close
static

Definition at line 103 of file sequencer.c.

◆ mseq_ioctl

d_ioctl_t mseq_ioctl
static

Definition at line 104 of file sequencer.c.

◆ mseq_open

d_open_t mseq_open
static

Definition at line 102 of file sequencer.c.

◆ mseq_poll

d_poll_t mseq_poll
static

Definition at line 107 of file sequencer.c.

◆ mseq_read

d_read_t mseq_read
static

Definition at line 105 of file sequencer.c.

◆ mseq_write

d_write_t mseq_write
static

Definition at line 106 of file sequencer.c.

◆ nseq

u_long nseq = 0
static

Definition at line 304 of file sequencer.c.

Referenced by seq_addunit(), seq_delunit(), and seq_modevent().

◆ seq_cdevsw

struct cdevsw seq_cdevsw
static
Initial value:
= {
.d_version = D_VERSION,
.d_open = mseq_open,
.d_close = mseq_close,
.d_read = mseq_read,
.d_write = mseq_write,
.d_ioctl = mseq_ioctl,
.d_poll = mseq_poll,
.d_name = "sequencer",
}
static d_poll_t mseq_poll
Definition: sequencer.c:107
static d_read_t mseq_read
Definition: sequencer.c:105
static d_open_t mseq_open
Definition: sequencer.c:102
static d_write_t mseq_write
Definition: sequencer.c:106
static d_close_t mseq_close
Definition: sequencer.c:103
static d_ioctl_t mseq_ioctl
Definition: sequencer.c:104

Definition at line 109 of file sequencer.c.

Referenced by seq_addunit().

◆ seq_debug

int seq_debug

Definition at line 164 of file sequencer.c.

◆ seq_methods

kobj_method_t seq_methods[]
static
Initial value:
= {
}
#define KOBJMETHOD_END
Definition: sequencer.c:267

Definition at line 274 of file sequencer.c.

◆ seqinfo_mtx

struct mtx seqinfo_mtx
static

Definition at line 303 of file sequencer.c.

Referenced by seq_addunit(), seq_delunit(), and seq_modevent().

◆ seqs

struct seq_softc* seqs[10]

Definition at line 302 of file sequencer.c.

Referenced by seq_addunit(), and seq_delunit().