[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.11

1.11    ! ratchov     1: /*     $OpenBSD: midi.h,v 1.10 2019/09/21 04:42:46 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 */
1.11    ! ratchov    71:        unsigned int last_st;           /* backup of st during sysex */
1.1       ratchov    72:        unsigned int used;              /* bytes used in ``msg'' */
                     73:        unsigned int idx;               /* current ``msg'' size */
                     74:        unsigned int len;               /* expected ``msg'' length */
                     75:        unsigned int txmask;            /* list of ep we send to */
1.2       ratchov    76:        unsigned int self;              /* equal (1 << index) */
1.8       ratchov    77:        int tickets;                    /* max bytes we can process */
1.1       ratchov    78:        struct abuf obuf;               /* output buffer */
                     79: };
                     80:
                     81: /*
                     82:  * midi port
                     83:  */
                     84: struct port {
                     85:        struct port *next;
                     86:        struct port_mio mio;
                     87: #define PORT_CFG       0
                     88: #define PORT_INIT      1
                     89: #define PORT_DRAIN     2
                     90:        unsigned int state;
1.7       ratchov    91:        unsigned int num;               /* port serial number */
1.10      ratchov    92:        struct name *path_list;
1.9       ratchov    93:        int hold;                       /* hold the port open ? */
1.1       ratchov    94:        struct midi *midi;
                     95: };
                     96:
                     97: /*
                     98:  * midi control ports
                     99:  */
                    100: extern struct port *port_list;
                    101:
                    102: void midi_init(void);
                    103: void midi_done(void);
                    104: struct midi *midi_new(struct midiops *, void *, int);
                    105: void midi_del(struct midi *);
                    106: void midi_log(struct midi *);
1.2       ratchov   107: void midi_tickets(struct midi *);
                    108: void midi_in(struct midi *, unsigned char *, int);
1.1       ratchov   109: void midi_out(struct midi *, unsigned char *, int);
                    110: void midi_send(struct midi *, unsigned char *, int);
                    111: void midi_fill(struct midi *);
                    112: void midi_tag(struct midi *, unsigned int);
1.2       ratchov   113: void midi_link(struct midi *, struct midi *);
1.1       ratchov   114:
1.6       ratchov   115: void port_log(struct port *);
1.4       ratchov   116: struct port *port_new(char *, unsigned int, int);
1.1       ratchov   117: struct port *port_bynum(int);
                    118: void port_del(struct port *);
1.3       ratchov   119: int  port_ref(struct port *);
                    120: void port_unref(struct port *);
1.1       ratchov   121: int  port_init(struct port *);
                    122: void port_done(struct port *);
1.5       ratchov   123: void port_drain(struct port *);
1.1       ratchov   124: int  port_close(struct port *);
1.10      ratchov   125: int  port_reopen(struct port *);
1.1       ratchov   126:
                    127: #endif /* !defined(MIDI_H) */