/* MIDI.h

   Headerfile für MIDI.C

   (C) 1988 O.Wagner
*/

#ifndef MIDI_H
#define MIDI_H

#ifndef DEVICES_SERIAL_H
#include <devices/serial.h>
#endif !DEVICES_SERIAL_H

/* returnwerte von "MIDIOPEN" */
#define ERROR_OK 0
#define ERROR_NO_READ_DEVICE 1
#define ERROR_NO_WRITE_DEVICE 2

/* makro für die ausgabe eines mit null beendeten
   strings */
#define midiwrites(s) midiwrite(s,strlen(s))

/* makros für midi-befehle */
/* Voice Messages */
/* c=channel(0-15) */
#define BNOTE_ON 0x80
#define NOTE_ON(c,n,v) { midiput(0x80+c); midiput(n); midiput(v); }
#define NOTE_OFF(c,n) { midiput(0x80+c); midiput(n); midiput(0); }
#define BPOLYPRESSURE 0xa0
#define POLYPRESSURE(c,n,a) { midiput(0xa0+c); midiput(n); midiput(a); }
#define BCONTROL_CHANGE 0xb0
#define CONTROL_CHANGE(c,d,v) { midiput(0xb0+c); midiput(d); midiput(v); }
#define BPROGRAM_CHANGE 0xc0
#define PROGRAM_CHANGE(c,p) { midiput(0xc0+c); midiput(p); }
#define BPITCH 0xe0
#define PITCH(c,v) { midiput(0xe0+c); midiput(v&255); midiput(v<<8); }

/* Mode Messages */
#define LOCAL_ON(c) CONTROL_CHANGE(c,0x7a,0)
#define LOCAL_OFF(c) CONTROL_CHANGE(c,0x7a,0x7f)
#define ALL_NOTES_OFF(c) CONTROL_CHANGE(c,0x7b,0)
#define OMNI_OFF(c) CONTROL_CHANGE(c,0x7c,0)
#define OMNI_ON(c) CONTROL_CHANGE(c,0x7d,0)
#define MONO_ON(c,v) CONTROL_CHANGE(c,0x7e,v)
#define POLY_ON(c) CONTROL_CHANGE(c,0x7f,0)

/* Common Messages */
#define BSONG_POSITION 0xf2
#define SONG_POSITION(p) { midiput(0xf2); midiput(p&255); midiput(p<<8); }
#define BSONG_SELECT 0xf3
#define SONG_SELECT(n) { midiput(0xf3); midiput(n); }
#define BTUNE_REQUEST 0xf6
#define TUNE_REQUEST midiput(0xf6)
#define BSYSTEM_RESET 0xff
#define SYSTEM_RESET midiput(0xff)

/* "Realtime" Messages  */
#define BTIMING_CLOCK 0xf8
#define TIMING_CLOCK midiput(0xf8)
#define BSTART 0xfa
#define START midiput(0xfa)
#define BCONTINUE 0xfb
#define CONTINUE midiput(0xfb)
#define BSTOP 0xfc
#define STOP midiput(0xfc)
#define BACTIVE_SENSING 0xfe
#define ACTIVE_SENSING midiput(0xfe)

/* system exclusives */

#define BSYSTEM_EXCLUSIVE 0xf0
#define SYSTEM_EXCLUSIVE midiput(0xf0)
#define BEND_OF_EXCLUSIVE 0xf7
#define END_OF_EXCLUSIVE midiput(0xf7)

/* sys-ex ID's */
#define ID_CASIO 0x44
#define ID_YAMAHA 0x43
#define ID_KORG 0x42
#define ID_ROLAND 0x41
#define ID_OBERHEIM 0x10
#define ID_MOOG 0x4
#define ID_KURZWEIL 0x7
#define ID_BONTEMPI 0x20
#define ID_STEINWAY 0x9
#define ID_SEQUENTIAL 0x1
#define ID_BIGBRIAR 0x2
#define ID_OCTAVE 0x3
#define ID_PASSPORT 0x5
#define ID_LEXICON 0x6
#define ID_CBS 0x08
#define ID_SIEL 0x21

#endif !MIDI_H
