[169] | 1 | //midi.h: |
---|
| 2 | |
---|
[668] | 3 | /* |
---|
| 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008 |
---|
| 5 | * |
---|
| 6 | * This file is part of roard a part of RoarAudio, |
---|
| 7 | * a cross-platform sound system for both, home and professional use. |
---|
| 8 | * See README for details. |
---|
| 9 | * |
---|
| 10 | * This file is free software; you can redistribute it and/or modify |
---|
| 11 | * it under the terms of the GNU General Public License version 3 |
---|
| 12 | * as published by the Free Software Foundation. |
---|
| 13 | * |
---|
| 14 | * RoarAudio is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this software; see the file COPYING. If not, write to |
---|
| 21 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 22 | * |
---|
| 23 | */ |
---|
| 24 | |
---|
[169] | 25 | #ifndef _MIDI_H_ |
---|
| 26 | #define _MIDI_H_ |
---|
| 27 | |
---|
| 28 | #include <roaraudio.h> |
---|
| 29 | |
---|
[188] | 30 | #ifdef __linux__ |
---|
| 31 | #include <sys/ioctl.h> |
---|
| 32 | #include <linux/kd.h> |
---|
| 33 | #endif |
---|
| 34 | |
---|
[189] | 35 | #define MIDI_CB_NOOVERRIDE 0 |
---|
| 36 | #define MIDI_CB_OVERRIDE 1 |
---|
| 37 | |
---|
[1848] | 38 | #define MIDI_RATE 31250 |
---|
| 39 | |
---|
[1852] | 40 | // standard MIDI commands: |
---|
[2408] | 41 | #define MIDI_TYPE_NOTE_OFF 0x80 |
---|
| 42 | #define MIDI_TYPE_NOTE_ON 0x90 |
---|
[1852] | 43 | #define MIDI_TYPE_PA 0xA0 |
---|
| 44 | #define MIDI_TYPE_CONTROLER 0xB0 |
---|
| 45 | #define MIDI_TYPE_PROGRAM 0xC0 |
---|
[1864] | 46 | #define MIDI_TYPE_MA 0xD0 |
---|
[1852] | 47 | #define MIDI_TYPE_PB 0xE0 |
---|
| 48 | #define MIDI_TYPE_SYSEX 0xF0 |
---|
| 49 | #define MIDI_TYPE_CLOCK_TICK 0xF8 |
---|
| 50 | #define MIDI_TYPE_CLOCK_START 0xFA |
---|
| 51 | #define MIDI_TYPE_CLOCK_STOP 0xFC |
---|
| 52 | |
---|
| 53 | // RoarAudio MIDI Commands: |
---|
| 54 | #define MIDI_TYPE_NONE 0x00 |
---|
| 55 | #define MIDI_TYPE_RAW_PASS 0x10 |
---|
| 56 | #define MIDI_TYPE_RAW_NOPASS 0x20 |
---|
| 57 | |
---|
[1892] | 58 | // controller events: |
---|
| 59 | #define MIDI_CCE_MAIN_VOL 7 |
---|
| 60 | #define MIDI_CCE_BALANCE 8 |
---|
| 61 | #define MIDI_CCE_PANORAMA 10 |
---|
| 62 | #define MIDI_CCE_LOCAL_CONTR 122 |
---|
| 63 | #define MIDI_CCE_ALL_NOTE_OFF 123 |
---|
| 64 | |
---|
| 65 | |
---|
[1852] | 66 | #define MIDI_MES_BUFSIZE 4 |
---|
[1858] | 67 | #define MIDI_READ_SIZE 256 /* this should be big enoth in both cfreq=20..100Hz mode */ |
---|
[1852] | 68 | |
---|
| 69 | #define MIDI_MFLAG_FREE_DP (1<<0) |
---|
| 70 | |
---|
[1924] | 71 | #define MIDI_INITED_MAIN 0x01 |
---|
| 72 | #define MIDI_INITED_CB 0x02 |
---|
| 73 | #define MIDI_INITED_CLOCK 0x04 |
---|
| 74 | |
---|
| 75 | struct { |
---|
| 76 | int init; |
---|
| 77 | int inited; |
---|
| 78 | int init_cb; |
---|
| 79 | char * console_dev; |
---|
| 80 | } midi_config; |
---|
| 81 | |
---|
[1852] | 82 | struct midi_message { |
---|
| 83 | unsigned char type; |
---|
| 84 | unsigned char channel; |
---|
| 85 | unsigned char flags; |
---|
| 86 | unsigned char kk; |
---|
| 87 | unsigned char vv; |
---|
| 88 | size_t datalen; |
---|
| 89 | unsigned char * dataptr; |
---|
| 90 | union { |
---|
| 91 | unsigned char ldata[MIDI_MES_BUFSIZE]; |
---|
| 92 | struct roar_note_octave note; |
---|
| 93 | } d; |
---|
| 94 | }; |
---|
| 95 | |
---|
[1863] | 96 | struct { |
---|
| 97 | struct roar_buffer * buf; |
---|
| 98 | } g_midi_mess; |
---|
[1852] | 99 | |
---|
[1853] | 100 | struct { |
---|
| 101 | int console; |
---|
| 102 | int stream; |
---|
| 103 | uint32_t stoptime; |
---|
| 104 | int playing; |
---|
| 105 | } g_midi_cb; |
---|
[1848] | 106 | |
---|
[1850] | 107 | struct { |
---|
| 108 | int stream; |
---|
| 109 | uint_least32_t bph; // beats per hour |
---|
[1852] | 110 | uint_least32_t spt; // samples per tick |
---|
| 111 | uint32_t nt; // time of next tick |
---|
[1850] | 112 | } g_midi_clock; |
---|
[192] | 113 | |
---|
[1858] | 114 | |
---|
| 115 | // general midi interface: |
---|
[1924] | 116 | int midi_init_config(void); |
---|
| 117 | |
---|
[185] | 118 | int midi_init (void); |
---|
| 119 | int midi_free (void); |
---|
| 120 | |
---|
[1841] | 121 | int midi_update(void); |
---|
[1855] | 122 | int midi_reinit(void); |
---|
[1841] | 123 | |
---|
[1858] | 124 | // streams: |
---|
[1841] | 125 | int midi_check_stream (int id); |
---|
| 126 | int midi_send_stream (int id); |
---|
| 127 | |
---|
[1858] | 128 | int midi_conv_midi2mes (int id); |
---|
| 129 | int midi_conv_mes2midi (int id); |
---|
| 130 | |
---|
[1863] | 131 | int midi_new_bufmes (struct roar_buffer ** buf, struct midi_message ** mes); |
---|
[1866] | 132 | int midi_add_buf (int id, struct roar_buffer * buf); |
---|
[1863] | 133 | |
---|
[1858] | 134 | // bridges: |
---|
[1848] | 135 | int midi_check_bridge (int id); |
---|
| 136 | |
---|
[1858] | 137 | // clock: |
---|
[1848] | 138 | int midi_clock_init (void); |
---|
[1852] | 139 | int midi_clock_set_bph (uint_least32_t bph); |
---|
| 140 | int midi_clock_tick (void); |
---|
[1848] | 141 | |
---|
[185] | 142 | // cb = console beep |
---|
[1843] | 143 | int midi_cb_init(void); |
---|
| 144 | int midi_cb_free(void); |
---|
[185] | 145 | int midi_cb_play(float t, float freq, int override); |
---|
[190] | 146 | int midi_cb_update (void); |
---|
[185] | 147 | int midi_cb_start(float freq); |
---|
| 148 | int midi_cb_stop (void); |
---|
[1882] | 149 | int midi_cb_readbuf(void); |
---|
[185] | 150 | |
---|
[1848] | 151 | // dummys: |
---|
| 152 | int midi_vio_set_dummy(int stream); |
---|
| 153 | int midi_vio_ok(struct roar_vio_calls * vio, ...); |
---|
| 154 | |
---|
[169] | 155 | #endif |
---|
| 156 | |
---|
| 157 | //ll |
---|