#ifndef MIDI_H
#define MIDI_H
#include "abuf.h"
#include "miofile.h"
#define MIDI_CMDMASK 0xf0
#define MIDI_CHANMASK 0x0f
#define MIDI_NOFF 0x80
#define MIDI_NON 0x90
#define MIDI_KAT 0xa0
#define MIDI_CTL 0xb0
#define MIDI_PC 0xc0
#define MIDI_CAT 0xd0
#define MIDI_BEND 0xe0
#define MIDI_ACK 0xfe
#define MIDI_CTL_VOL 7
#define MIDI_MAXCTL 127
struct midiops
{
void (*imsg)(void *, unsigned char *, int);
void (*omsg)(void *, unsigned char *, int);
void (*fill)(void *, int);
void (*exit)(void *);
};
struct midi {
struct midiops *ops;
struct midi *owner;
unsigned int mode;
void *arg;
#define MIDI_MSGMAX 16
unsigned char msg[MIDI_MSGMAX];
unsigned int st;
unsigned int last_st;
unsigned int used;
unsigned int idx;
unsigned int len;
unsigned int txmask;
unsigned int num;
unsigned int self;
int tickets;
struct abuf obuf;
};
struct port {
struct port *next;
struct port_mio mio;
#define PORT_CFG 0
#define PORT_INIT 1
#define PORT_DRAIN 2
unsigned int state;
unsigned int num;
char *path;
int hold;
int refcnt;
struct midi *midi;
};
struct midithru {
unsigned int portmask;
unsigned int progmask;
unsigned int prefportmask;
int refcnt;
int thru;
};
extern struct port *port_list;
#define MIDITHRU_NMAX 32
extern struct midithru midithru_array[MIDITHRU_NMAX];
void midi_init(void);
void midi_done(void);
struct midi *midi_new(struct midiops *, void *, int);
void midi_del(struct midi *);
size_t midiev_fmt(char *, size_t, unsigned char *, size_t);
void midi_tickets(struct midi *);
void midi_in(struct midi *, unsigned char *, int);
void midi_out(struct midi *, unsigned char *, int);
void midi_send(struct midi *, unsigned char *, int);
void midi_fill(struct midi *);
unsigned int midi_rxmask(struct midi *);
void midi_link(struct midi *, struct midi *);
void midi_unlink(struct midi *, struct midi *);
void midi_abort(struct midi *);
void midi_migrate(struct midi *, struct midi *);
struct port *port_new(char *, unsigned int, int);
struct port *port_bynum(int);
void port_del(struct port *);
int port_ref(struct port *);
void port_unref(struct port *);
int port_init(struct port *);
void port_done(struct port *);
void port_drain(struct port *);
int port_open(struct port *);
int port_close(struct port *);
struct port *port_alt_ref(int);
void port_abort(struct port *p);
void midithru_ref(struct midithru *);
void midithru_unref(struct midithru *);
void midithru_addport(struct midithru *, struct port *);
void midithru_addprog(struct midithru *, struct midi *);
void midithru_rm(struct midithru *, struct midi *);
int midithru_setport(struct midithru *, struct port *, int);
int midithru_setthru(struct midithru *, int);
void midithru_scanports(void);
#endif