1 /* 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2022 Goran Mekić 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28 #include <stdlib.h> 29 #include <stdio.h> 30 #include <fcntl.h> 31 32 #define CMD_MASK 0xF0 33 #define NOTE_ON 0x90 34 #define NOTE_OFF 0x80 35 #define CHANNEL_MASK 0xF 36 #define CONTROLER_ON 0xB0 37 38 typedef struct midi_event { 39 unsigned char type; 40 unsigned char channel; 41 union { 42 unsigned char note; 43 unsigned controller; 44 }; 45 union { 46 unsigned char velocity; 47 unsigned char value; 48 }; 49 } midi_event_t; 50 51 typedef struct midi_config { 52 char *device; 53 int fd; 54 } midi_config_t; 55 56 void 57 oss_midi_init(midi_config_t *config) 58 { 59 if ((config->fd = open(config->device, O_RDWR)) == -1) { 60 perror("Error opening MIDI device"); 61 exit(1); 62 } 63 } 64