#ifndef DEV_H
#define DEV_H
#include "abuf.h"
#include "dsp.h"
#include "siofile.h"
#include "dev_sioctl.h"
#include "opt.h"
#define DEV_NSLOT 32
#define DEV_NCTLSLOT 8
struct slotops
{
void (*onmove)(void *);
void (*onxrun)(void *);
void (*onvol)(void *);
void (*fill)(void *);
void (*flush)(void *);
void (*eof)(void *);
void (*exit)(void *);
};
struct ctlops
{
void (*exit)(void *);
void (*sync)(void *);
};
struct slot {
struct slotops *ops;
struct slot *next;
struct opt *opt;
void *arg;
struct aparams par;
struct {
int weight;
unsigned int vol;
struct abuf buf;
int bpf;
int nch;
struct cmap cmap;
struct resamp resamp;
struct conv dec;
int join;
int expand;
void *resampbuf, *decbuf;
} mix;
struct {
struct abuf buf;
int prime;
int bpf;
int nch;
struct cmap cmap_rec;
struct cmap cmap_mon;
struct resamp resamp;
struct conv enc;
void *resampbuf, *encbuf;
} sub;
int xrun;
int skip;
#define SLOT_BUFSZ(s) \
((s)->appbufsz + (s)->opt->dev->bufsz / (s)->opt->dev->round * (s)->round)
int appbufsz;
int round;
int rate;
int delta;
int delta_rem;
int mode;
#define SLOT_INIT 0
#define SLOT_START 1
#define SLOT_READY 2
#define SLOT_RUN 3
#define SLOT_STOP 4
int pstate;
int paused;
struct app *app;
};
struct ctl {
struct ctl *next;
#define CTL_NONE 0
#define CTL_NUM 2
#define CTL_SW 3
#define CTL_VEC 4
#define CTL_LIST 5
#define CTL_SEL 6
unsigned int type;
#define CTL_HW 0
#define CTL_DEV_MASTER 1
#define CTL_OPT_DEV 2
#define CTL_APP_LEVEL 3
unsigned int scope;
union {
struct {
void *arg0;
void *arg1;
} any;
struct {
struct dev *dev;
unsigned int addr;
} hw;
struct {
struct dev *dev;
} dev_master;
struct {
struct opt *opt;
struct app *app;
} app_level;
struct {
struct opt *opt;
struct dev *dev;
} opt_dev;
} u;
unsigned int addr;
#define CTL_NAMEMAX 12
#define CTL_DISPLAYMAX 24
char func[CTL_NAMEMAX];
char group[CTL_NAMEMAX];
char display[CTL_DISPLAYMAX];
struct ctl_node {
char name[CTL_NAMEMAX];
int unit;
} node0, node1;
#define CTL_DEVMASK (1 << 31)
#define CTL_SLOTMASK(i) (1 << (i))
unsigned int val_mask;
unsigned int desc_mask;
unsigned int refs_mask;
unsigned int maxval;
unsigned int curval;
int dirty;
};
struct ctlslot {
struct ctlops *ops;
void *arg;
struct opt *opt;
unsigned int self;
unsigned int mode;
};
struct mtc {
#define MTC_STOP 1
#define MTC_START 2
#define MTC_RUN 3
unsigned int tstate;
struct dev *dev;
unsigned int origin;
unsigned int fps;
#define MTC_FPS_24 0
#define MTC_FPS_25 1
#define MTC_FPS_30 3
unsigned int fps_id;
unsigned int hr;
unsigned int min;
unsigned int sec;
unsigned int fr;
unsigned int qfr;
int delta;
int refs;
};
struct dev {
struct dev *next;
struct slot *slot_list;
char name[CTL_NAMEMAX];
struct dev_sio sio;
struct dev_sioctl sioctl;
struct aparams par;
int pchan, rchan;
adata_t *rbuf;
adata_t *pbuf;
#define DEV_PBUF(d) ((d)->pbuf + (d)->poffs * (d)->pchan)
int poffs;
int psize;
struct conv enc;
struct conv dec;
unsigned char *encbuf;
unsigned char *decbuf;
int delta;
unsigned int reqmode;
struct aparams reqpar;
int reqpchan, reqrchan;
unsigned int reqbufsz;
unsigned int reqround;
unsigned int reqrate;
unsigned int hold;
unsigned int autovol;
unsigned int refcnt;
#define DEV_NMAX 16
unsigned int num;
#define DEV_CFG 0
#define DEV_INIT 1
#define DEV_RUN 2
unsigned int pstate;
char *path;
unsigned int mode;
unsigned int bufsz, round, rate;
unsigned int prime;
unsigned int idle;
unsigned int master;
unsigned int master_enabled;
};
extern struct dev *dev_list;
extern struct ctl *ctl_list;
extern struct slot slot_array[DEV_NSLOT];
extern struct ctlslot ctlslot_array[DEV_NCTLSLOT];
extern struct mtc mtc_array[1];
size_t chans_fmt(char *, size_t, int, int, int, int, int);
int dev_open(struct dev *);
void dev_close(struct dev *);
void dev_abort(struct dev *);
void dev_migrate(struct dev *);
struct dev *dev_new(char *, struct aparams *, unsigned int, unsigned int,
unsigned int, unsigned int, unsigned int, unsigned int);
struct dev *dev_bynum(int);
void dev_del(struct dev *);
void dev_adjpar(struct dev *, int, int, int);
int dev_init(struct dev *);
void dev_done(struct dev *);
int dev_ref(struct dev *);
void dev_unref(struct dev *);
unsigned int dev_roundof(struct dev *, unsigned int);
int dev_iscompat(struct dev *, struct dev *);
void dev_onmove(struct dev *, int);
void dev_cycle(struct dev *);
void dev_master(struct dev *, unsigned int);
void dev_midi_send(struct dev *, void *, int);
void dev_midi_master(struct dev *);
void mtc_midi_qfr(struct mtc *, int);
void mtc_midi_full(struct mtc *);
void mtc_trigger(struct mtc *);
void mtc_start(struct mtc *);
void mtc_stop(struct mtc *);
void mtc_loc(struct mtc *, unsigned int);
void mtc_setdev(struct mtc *, struct dev *);
struct slot *slot_new(struct opt *, unsigned int, char *,
struct slotops *, void *, int);
void slot_del(struct slot *);
void slot_setvol(struct slot *, unsigned int);
void slot_start(struct slot *);
void slot_stop(struct slot *, int);
void slot_read(struct slot *);
void slot_write(struct slot *);
void slot_initconv(struct slot *);
void slot_attach(struct slot *);
void slot_detach(struct slot *);
struct ctl *ctl_new(int, void *, void *,
int, char *, char *, char *, int, char *, char *, int, int, int);
int ctl_del(int, void *, void *);
size_t ctl_node_fmt(char *, size_t, struct ctl_node *);
size_t ctl_scope_fmt(char *, size_t, struct ctl *);
size_t ctl_fmt(char *, size_t, struct ctl *);
int ctl_setval(struct ctl *c, int val);
int ctl_match(struct ctl *, int, void *, void *);
struct ctl *ctl_find(int, void *, void *);
void ctl_update(struct ctl *);
int ctl_onval(int, void *, void *, int);
struct ctlslot *ctlslot_new(struct opt *, struct ctlops *, void *);
void ctlslot_del(struct ctlslot *);
int ctlslot_visible(struct ctlslot *, struct ctl *);
struct ctl *ctlslot_lookup(struct ctlslot *, int);
void ctlslot_update(struct ctlslot *);
char *dev_getdisplay(struct dev *);
void dev_ctlsync(struct dev *);
#endif