[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 |
---|
[3517] | 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
[668] | 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
[169] | 26 | #ifndef _MIDI_H_ |
---|
| 27 | #define _MIDI_H_ |
---|
| 28 | |
---|
| 29 | #include <roaraudio.h> |
---|
| 30 | |
---|
[2500] | 31 | // CB has MIDI as dep |
---|
| 32 | #if defined(ROAR_WITHOUT_DCOMP_MIDI) && !defined(ROAR_WITHOUT_DCOMP_CB) |
---|
| 33 | #define ROAR_WITHOUT_DCOMP_CB |
---|
| 34 | #endif |
---|
| 35 | |
---|
| 36 | #ifndef ROAR_WITHOUT_DCOMP_MIDI |
---|
| 37 | |
---|
[2499] | 38 | #ifndef ROAR_WITHOUT_DCOMP_CB |
---|
[188] | 39 | #ifdef __linux__ |
---|
| 40 | #include <sys/ioctl.h> |
---|
| 41 | #include <linux/kd.h> |
---|
| 42 | #endif |
---|
| 43 | |
---|
[189] | 44 | #define MIDI_CB_NOOVERRIDE 0 |
---|
| 45 | #define MIDI_CB_OVERRIDE 1 |
---|
[2487] | 46 | #endif |
---|
[189] | 47 | |
---|
[1848] | 48 | #define MIDI_RATE 31250 |
---|
| 49 | |
---|
[1852] | 50 | // standard MIDI commands: |
---|
[2408] | 51 | #define MIDI_TYPE_NOTE_OFF 0x80 |
---|
| 52 | #define MIDI_TYPE_NOTE_ON 0x90 |
---|
[1852] | 53 | #define MIDI_TYPE_PA 0xA0 |
---|
| 54 | #define MIDI_TYPE_CONTROLER 0xB0 |
---|
| 55 | #define MIDI_TYPE_PROGRAM 0xC0 |
---|
[1864] | 56 | #define MIDI_TYPE_MA 0xD0 |
---|
[1852] | 57 | #define MIDI_TYPE_PB 0xE0 |
---|
| 58 | #define MIDI_TYPE_SYSEX 0xF0 |
---|
| 59 | #define MIDI_TYPE_CLOCK_TICK 0xF8 |
---|
| 60 | #define MIDI_TYPE_CLOCK_START 0xFA |
---|
| 61 | #define MIDI_TYPE_CLOCK_STOP 0xFC |
---|
| 62 | |
---|
| 63 | // RoarAudio MIDI Commands: |
---|
| 64 | #define MIDI_TYPE_NONE 0x00 |
---|
| 65 | #define MIDI_TYPE_RAW_PASS 0x10 |
---|
| 66 | #define MIDI_TYPE_RAW_NOPASS 0x20 |
---|
| 67 | |
---|
[1892] | 68 | // controller events: |
---|
| 69 | #define MIDI_CCE_MAIN_VOL 7 |
---|
| 70 | #define MIDI_CCE_BALANCE 8 |
---|
| 71 | #define MIDI_CCE_PANORAMA 10 |
---|
| 72 | #define MIDI_CCE_LOCAL_CONTR 122 |
---|
| 73 | #define MIDI_CCE_ALL_NOTE_OFF 123 |
---|
| 74 | |
---|
| 75 | |
---|
[1852] | 76 | #define MIDI_MES_BUFSIZE 4 |
---|
[1858] | 77 | #define MIDI_READ_SIZE 256 /* this should be big enoth in both cfreq=20..100Hz mode */ |
---|
[1852] | 78 | |
---|
| 79 | #define MIDI_MFLAG_FREE_DP (1<<0) |
---|
| 80 | |
---|
[1924] | 81 | #define MIDI_INITED_MAIN 0x01 |
---|
| 82 | #define MIDI_INITED_CB 0x02 |
---|
| 83 | #define MIDI_INITED_CLOCK 0x04 |
---|
| 84 | |
---|
| 85 | struct { |
---|
| 86 | int init; |
---|
| 87 | int inited; |
---|
[2487] | 88 | |
---|
| 89 | #ifndef ROAR_WITHOUT_DCOMP_CB |
---|
[1924] | 90 | int init_cb; |
---|
| 91 | char * console_dev; |
---|
[2487] | 92 | #endif |
---|
[1924] | 93 | } midi_config; |
---|
| 94 | |
---|
[1852] | 95 | struct midi_message { |
---|
| 96 | unsigned char type; |
---|
| 97 | unsigned char channel; |
---|
| 98 | unsigned char flags; |
---|
| 99 | unsigned char kk; |
---|
| 100 | unsigned char vv; |
---|
| 101 | size_t datalen; |
---|
| 102 | unsigned char * dataptr; |
---|
| 103 | union { |
---|
| 104 | unsigned char ldata[MIDI_MES_BUFSIZE]; |
---|
| 105 | struct roar_note_octave note; |
---|
| 106 | } d; |
---|
| 107 | }; |
---|
| 108 | |
---|
[1863] | 109 | struct { |
---|
| 110 | struct roar_buffer * buf; |
---|
| 111 | } g_midi_mess; |
---|
[1852] | 112 | |
---|
[2487] | 113 | #ifndef ROAR_WITHOUT_DCOMP_CB |
---|
[1853] | 114 | struct { |
---|
| 115 | int console; |
---|
| 116 | int stream; |
---|
| 117 | uint32_t stoptime; |
---|
| 118 | int playing; |
---|
| 119 | } g_midi_cb; |
---|
[2487] | 120 | #endif |
---|
[1848] | 121 | |
---|
[1850] | 122 | struct { |
---|
| 123 | int stream; |
---|
| 124 | uint_least32_t bph; // beats per hour |
---|
[1852] | 125 | uint_least32_t spt; // samples per tick |
---|
| 126 | uint32_t nt; // time of next tick |
---|
[1850] | 127 | } g_midi_clock; |
---|
[192] | 128 | |
---|
[2941] | 129 | struct { |
---|
| 130 | int stream; |
---|
| 131 | } g_midi_mixer; |
---|
| 132 | |
---|
[1858] | 133 | |
---|
| 134 | // general midi interface: |
---|
[1924] | 135 | int midi_init_config(void); |
---|
| 136 | |
---|
[185] | 137 | int midi_init (void); |
---|
| 138 | int midi_free (void); |
---|
| 139 | |
---|
[1841] | 140 | int midi_update(void); |
---|
[1855] | 141 | int midi_reinit(void); |
---|
[1841] | 142 | |
---|
[1858] | 143 | // streams: |
---|
[1841] | 144 | int midi_check_stream (int id); |
---|
| 145 | int midi_send_stream (int id); |
---|
| 146 | |
---|
[1858] | 147 | int midi_conv_midi2mes (int id); |
---|
| 148 | int midi_conv_mes2midi (int id); |
---|
| 149 | |
---|
[2461] | 150 | int midi_conv_mes2ssynth(void); |
---|
| 151 | |
---|
[1863] | 152 | int midi_new_bufmes (struct roar_buffer ** buf, struct midi_message ** mes); |
---|
[1866] | 153 | int midi_add_buf (int id, struct roar_buffer * buf); |
---|
[1863] | 154 | |
---|
[1858] | 155 | // bridges: |
---|
[1848] | 156 | int midi_check_bridge (int id); |
---|
| 157 | |
---|
[1858] | 158 | // clock: |
---|
[1848] | 159 | int midi_clock_init (void); |
---|
[1852] | 160 | int midi_clock_set_bph (uint_least32_t bph); |
---|
| 161 | int midi_clock_tick (void); |
---|
[1848] | 162 | |
---|
[185] | 163 | // cb = console beep |
---|
[2487] | 164 | #ifndef ROAR_WITHOUT_DCOMP_CB |
---|
[1843] | 165 | int midi_cb_init(void); |
---|
| 166 | int midi_cb_free(void); |
---|
[185] | 167 | int midi_cb_play(float t, float freq, int override); |
---|
[190] | 168 | int midi_cb_update (void); |
---|
[185] | 169 | int midi_cb_start(float freq); |
---|
| 170 | int midi_cb_stop (void); |
---|
[1882] | 171 | int midi_cb_readbuf(void); |
---|
[2487] | 172 | #endif |
---|
[185] | 173 | |
---|
[1848] | 174 | // dummys: |
---|
| 175 | int midi_vio_set_dummy(int stream); |
---|
| 176 | int midi_vio_ok(struct roar_vio_calls * vio, ...); |
---|
| 177 | |
---|
[169] | 178 | #endif |
---|
| 179 | |
---|
[2500] | 180 | #endif |
---|
| 181 | |
---|
[169] | 182 | //ll |
---|