[BACK]Return to midi.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / sndiod

Annotation of src/usr.bin/sndiod/midi.h, Revision 1.5

1.5     ! ratchov     1: /*     $OpenBSD: midi.h,v 1.4 2012/11/30 21:04:35 ratchov Exp $        */
1.1       ratchov     2: /*
                      3:  * Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
                      4:  *
                      5:  * Permission to use, copy, modify, and distribute this software for any
                      6:  * purpose with or without fee is hereby granted, provided that the above
                      7:  * copyright notice and this permission notice appear in all copies.
                      8:  *
                      9:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     10:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     11:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     12:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     13:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     14:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     15:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     16:  */
                     17: #ifndef MIDI_H
                     18: #define MIDI_H
                     19:
                     20: #include "abuf.h"
                     21: #include "miofile.h"
                     22:
                     23: /*
                     24:  * masks to extract command and channel of status byte
                     25:  */
                     26: #define MIDI_CMDMASK   0xf0
                     27: #define MIDI_CHANMASK  0x0f
                     28:
                     29: /*
                     30:  * MIDI status bytes of voice messages
                     31:  */
                     32: #define MIDI_NOFF      0x80            /* note off */
                     33: #define MIDI_NON       0x90            /* note on */
                     34: #define MIDI_KAT       0xa0            /* key after touch */
                     35: #define MIDI_CTL       0xb0            /* controller */
                     36: #define MIDI_PC                0xc0            /* program change */
                     37: #define MIDI_CAT       0xd0            /* channel after touch */
                     38: #define MIDI_BEND      0xe0            /* pitch bend */
                     39: #define MIDI_ACK       0xfe            /* active sensing message */
                     40:
                     41: /*
                     42:  * MIDI controller numbers
                     43:  */
                     44: #define MIDI_CTL_VOL   7               /* volume */
                     45:
                     46: /*
                     47:  * Max coarse value
                     48:  */
                     49: #define MIDI_MAXCTL            127
                     50:
                     51: /*
                     52:  * midi stream state structure
                     53:  */
                     54:
                     55: struct midiops
                     56: {
                     57:        void (*imsg)(void *, unsigned char *, int);
                     58:        void (*omsg)(void *, unsigned char *, int);
                     59:        void (*fill)(void *, int);
                     60:        void (*exit)(void *);
                     61: };
                     62:
                     63: struct midi {
                     64:        struct midiops *ops;            /* port/sock/dev callbacks */
                     65:        struct midi *owner;             /* current writer stream */
                     66:        unsigned int mode;              /* MODE_{MIDIIN,MIDIOUT} */
                     67:        void *arg;                      /* user data for callbacks */
                     68: #define MIDI_MSGMAX    16              /* max size of MIDI msg */
                     69:        unsigned char msg[MIDI_MSGMAX]; /* parsed input message */
                     70:        unsigned int st;                /* input MIDI running status */
                     71:        unsigned int used;              /* bytes used in ``msg'' */
                     72:        unsigned int idx;               /* current ``msg'' size */
                     73:        unsigned int len;               /* expected ``msg'' length */
                     74:        unsigned int txmask;            /* list of ep we send to */
1.2       ratchov    75:        unsigned int self;              /* equal (1 << index) */
                     76:        unsigned int tickets;           /* max bytes we can process */
1.1       ratchov    77:        struct abuf obuf;               /* output buffer */
                     78: };
                     79:
                     80: /*
                     81:  * midi port
                     82:  */
                     83: struct port {
                     84:        struct port *next;
                     85:        struct port_mio mio;
                     86: #define PORT_CFG       0
                     87: #define PORT_INIT      1
                     88: #define PORT_DRAIN     2
                     89:        unsigned int state;
1.4       ratchov    90:        char *path;                     /* hold the port open ? */
                     91:        int hold;
1.1       ratchov    92:        struct midi *midi;
                     93: };
                     94:
                     95: /*
                     96:  * midi control ports
                     97:  */
                     98: extern struct port *port_list;
                     99:
                    100: void midi_init(void);
                    101: void midi_done(void);
                    102: struct midi *midi_new(struct midiops *, void *, int);
                    103: void midi_del(struct midi *);
                    104: void midi_log(struct midi *);
1.2       ratchov   105: void midi_tickets(struct midi *);
                    106: void midi_in(struct midi *, unsigned char *, int);
1.1       ratchov   107: void midi_out(struct midi *, unsigned char *, int);
                    108: void midi_send(struct midi *, unsigned char *, int);
                    109: void midi_fill(struct midi *);
                    110: void midi_tag(struct midi *, unsigned int);
1.2       ratchov   111: void midi_link(struct midi *, struct midi *);
1.1       ratchov   112:
1.4       ratchov   113: struct port *port_new(char *, unsigned int, int);
1.1       ratchov   114: struct port *port_bynum(int);
                    115: void port_del(struct port *);
1.3       ratchov   116: int  port_ref(struct port *);
                    117: void port_unref(struct port *);
1.1       ratchov   118: int  port_init(struct port *);
                    119: void port_done(struct port *);
1.5     ! ratchov   120: void port_drain(struct port *);
1.1       ratchov   121: int  port_close(struct port *);
                    122:
                    123: #endif /* !defined(MIDI_H) */