; midi/midi.i

	ifnd	MIDI_MIDI_I
MIDI_MIDI_I set 1

; Definitions pertaining to MIDI are derived from MIDI 1.0 Detailed
; Specification v4.0 (published by the Internation MIDI Association)
; and is current as of June, 1988.

; v2.0 - 23-Oct-88


	ifnd	EXEC_LISTS_I
	include "exec/lists.i"
	endc

	ifnd	EXEC_PORTS_I
	include "exec/ports.i"
	endc


MIDINAME macro
	 dc.b	 'midi.library',0
	 endm

MIDIVERSION equ 7


; Routes

RIM_MAXCOUNT	equ  3

    STRUCTURE	RIMatch,0
	UBYTE	rim_Flags   ; flag bits defined below
	STRUCT	rim_Match,RIM_MAXCOUNT
	LABEL	sizeof_RIMatch


RIMF_COUNTBITS	equ  $03    ; mask for # of match values (0 for match all)

    BITDEF  RIM,EXTID,6     ; indicates all 3 bytes of rim_match = one 3 byte manuf. id
    BITDEF  RIM,EXCLUDE,7   ; reverses logic of RIMatch so that all except those specified pass


    STRUCTURE	MRouteInfo,0
	UWORD	ri_MsgFlags
	UWORD	ri_ChanFlags
	BYTE	ri_ChanOffset
	BYTE	ri_NoteOffset
	STRUCT	ri_SysExMatch,sizeof_RIMatch
	STRUCT	ri_CtrlMatch,sizeof_RIMatch
	LABEL	sizeof_MRouteInfo

; Midi Msg Type Flags for RouteInfo and returned by MidiMsgType

MMF_CHAN    equ  $00ff

    BITDEF  MM,NOTEOFF,0
    BITDEF  MM,NOTEON,1
    BITDEF  MM,POLYPRESS,2
    BITDEF  MM,CTRL,3
    BITDEF  MM,PROG,4
    BITDEF  MM,CHANPRESS,5
    BITDEF  MM,PITCHBEND,6
    BITDEF  MM,MODE,7

    BITDEF  MM,SYSCOM,8
    BITDEF  MM,SYSRT,9
    BITDEF  MM,SYSEX,10

MMF_ALL     equ  $07ff		; all normal messages


    STRUCTURE	MRoutePtr,MLN_SIZE
	APTR	rp_Route
	LABEL	sizeof_MRoutePtr

    STRUCTURE	MRoute,0
	APTR	mr_Source
	APTR	mr_Dest
	STRUCT	mr_SRoutePtr,sizeof_MRoutePtr
	STRUCT	mr_DRoutePtr,sizeof_MRoutePtr
	STRUCT	mr_RouteInfo,sizeof_MRouteInfo
	LABEL	sizeof_MRoute


; Nodes

    STRUCTURE	MSource,LN_SIZE
	APTR	ms_Image
	STRUCT	ms_RPList,MLH_SIZE
	APTR	ms_UserData
	UWORD	ms_RouteMsgFlags
	UWORD	ms_RouteChanFlags
	LABEL	sizeof_MSource

; Node Types for MSource nodes
NT_MSOURCE	equ  $20
NT_RESMSOURCE	equ  $21


    STRUCTURE	MDest,LN_SIZE
	APTR	md_Image
	STRUCT	md_RPList,MLH_SIZE
	APTR	md_DestPort
	APTR	md_UserData
	STRUCT	md_DefaultRouteInfo,sizeof_MRouteInfo
	LABEL	sizeof_MDest

; Node Types for MDest nodes
NT_MDEST	equ  $22
NT_RESMDEST	equ  $23


; MIDI Packet

    STRUCTURE	MidiPacket,MN_SIZE	; packet received by GetMidiPacket()
	UWORD	mpkt_Type		; MMF_ bits for this message (as returned by MidiMsgType())
	UWORD	mpkt_Length		; length of msg in bytes (as returned by MidiMsgLength())
	STRUCT	mpkt_reserved,4 	; reserved for future expansion
	STRUCT	mpkt_MidiMsg,4		; actual MIDI message
	LABEL	sizeof_MidiPacket


; Public List Change Signal

    STRUCTURE	MListSignal,MLN_SIZE
	APTR	mls_SigTask
	UBYTE	mls_SigBit
	UBYTE	mls_Flags
	LABEL	sizeof_MListSignal

	; user flags
    BITDEF  MLS,SOURCE,0
    BITDEF  MLS,DEST,1


; MIDI message definitions

; Status Bytes

   ; Channel Voice Messages (1sssnnnn)
MS_NOTEOFF    equ $80
MS_NOTEON     equ $90
MS_POLYPRESS  equ $A0
MS_CTRL       equ $B0
MS_MODE       equ $B0
MS_PROG       equ $C0
MS_CHANPRESS  equ $D0
MS_PITCHBEND  equ $E0

   ; System Common Messages
MS_SYSEX      equ $F0
MS_QTRFRAME   equ $F1
MS_SONGPOS    equ $F2
MS_SONGSELECT equ $F3
MS_TUNEREQ    equ $F6
MS_EOX	      equ $F7

   ; System Real Time Messages
MS_CLOCK      equ $F8
MS_START      equ $FA
MS_CONTINUE   equ $FB
MS_STOP       equ $FC
MS_ACTVSENSE  equ $FE
MS_RESET      equ $FF


; Miscellaneous

MIDDLEC 	equ 60	    ; middle C note value
DEFAULTVELOCITY equ 64	    ; default Note On or Off velocity
PITCHBENDCENTER equ $2000   ; pitch bend center position as a 14 bit word
MCLKSPERQTR	equ 24	    ; MIDI clocks per qtr-note
MCLKSPERSP	equ 6	    ; MIDI clocks per song position index
MCCENTER	equ 64	    ; center value for controllers like Pan and Balance


; Standard Controllers

   ; continuous 14 bit - MSB: 0-1f, LSB: 20-3f
MC_MODWHEEL  equ $01
MC_BREATH    equ $02
MC_FOOT      equ $04
MC_PORTATIME equ $05
MC_DATAENTRY equ $06
MC_VOLUME    equ $07
MC_BALANCE   equ $08
MC_PAN	     equ $0a
MC_EXPRESSION equ $0b
MC_GENERAL1  equ $10
MC_GENERAL2  equ $11
MC_GENERAL3  equ $12
MC_GENERAL4  equ $13

   ; continuous 7 bit (switches: 0-3f=off, 40-7f=on)
MC_SUSTAIN   equ $40
MC_PORTA     equ $41
MC_SUSTENUTO equ $42
MC_SOFTPEDAL equ $43
MC_HOLD2     equ $45
MC_GENERAL5  equ $50
MC_GENERAL6  equ $51
MC_GENERAL7  equ $52
MC_GENERAL8  equ $53
MC_EXTDEPTH  equ $5b
MC_TREMOLODEPTH equ $5c
MC_CHORUSDEPTH	equ $5d
MC_CELESTEDEPTH equ $5e
MC_PHASERDEPTH	equ $5f

    ; parameters
MC_DATAINCR  equ $60
MC_DATADECR  equ $61
MC_NRPNL     equ $62
MC_NRPNH     equ $63
MC_RPNL      equ $64
MC_RPNH      equ $65

MM_MAX	     equ $78


; Channel Modes

MM_MIN	   equ $79

MM_RESETCTRL equ $79
MM_LOCAL   equ $7a
MM_ALLOFF  equ $7b
MM_OMNIOFF equ $7c
MM_OMNION  equ $7d
MM_MONO    equ $7e
MM_POLY    equ $7f


; Registered Parameter Numbers

; These are 16 bit values that need to be separated into two bytes for use
; with the MC_RPNH & MC_RPNL messages using 8 bit math (as opposed to 7
; bit math).  This is done so that the defines match the numbers from the
; MMA.	See MIDI 1.0 Detailed Spec v4.0 pp 12, 23 for more info.

MRP_PBSENS	equ $0000
MRP_FINETUNE	equ $0001
MRP_COURSETUNE	equ $0002


; MTC Quarter Frame messages

; Qtr Frame message is F1 0nnndddd where
;
;     nnn is a message type defined below
;     dddd is 4 bit data nibble for those message types
;
; Each pair of nibbles is combined by the receiver into a single byte.
; There are masks and type values defined for some of these data bytes
; below.

    ; message types
MTCQ_FRAMEL equ $00
MTCQ_FRAMEH equ $10
MTCQ_SECL   equ $20
MTCQ_SECH   equ $30
MTCQ_MINL   equ $40
MTCQ_MINH   equ $50
MTCQ_HOURL  equ $60
MTCQ_HOURH  equ $70	   ; also contains time code type

    ; message masks
MTCQ_TYPEMASK equ $70	   ; mask for type bits in message
MTCQ_DATAMASK equ $0f	   ; mask for data bits in message

    ; hour byte
MTCH_TYPEMASK equ $60	   ; mask for time code type
MTCH_HOURMASK equ $1f	   ; hours mask (range 0-23)

    ; time code type values for hour byte
MTCT_24FPS	    equ $00
MTCT_25FPS	    equ $20
MTCT_30FPS_DROP     equ $40
MTCT_30FPS_NONDROP  equ $60


; Sys/Ex ID numbers

; Now includes 3 byte extension for the American Group.  This new
; format uses a $00 as the sys/ex id followed by two additional bytes
; that actually identify the manufacturer.  These new extended id
; constants are 32 bit values (24 significant bits) that you will have
; to break apart manually.

; You can match or filter off one of the extended id's when using the
; RIMF_EXTID bit described above.

    ; American Group
MID_XAMERICA	    equ $00
MID_SEQUENTIAL	    equ $01
MID_IDP 	    equ $02
MID_OCTAVEPLATEAU   equ $03
MID_MOOG	    equ $04
MID_PASSPORT	    equ $05
MID_LEXICON	    equ $06
MID_KURZWEIL	    equ $07
MID_FENDER	    equ $08
MID_AKG 	    equ $0a
MID_VOYCE	    equ $0b
MID_WAVEFRAME	    equ $0c
MID_ADA 	    equ $0d
MID_GARFIELD	    equ $0e
MID_ENSONIQ	    equ $0f
MID_OBERHEIM	    equ $10
MID_APPLE	    equ $11
MID_GREYMATTER	    equ $12
MID_PALMTREE	    equ $14
MID_JLCOOPER	    equ $15
MID_LOWREY	    equ $16
MID_ADAMSSMITH	    equ $17
MID_EMU 	    equ $18
MID_HARMONY	    equ $19
MID_ART 	    equ $1a
MID_BALDWIN	    equ $1b
MID_EVENTIDE	    equ $1c
MID_INVENTRONICS    equ $1d
MID_CLARITY	    equ $1f

MIDX_DIGITALMUSIC   equ $000007
MIDX_IOTA	    equ $000008
MIDX_IVL	    equ $00000b
MIDX_SOUTHERNMUSIC  equ $00000c
MIDX_LAKEBUTLER     equ $00000d
MIDX_DOD	    equ $000010
MIDX_PERFECTFRET    equ $000014
MIDX_OPCODE	    equ $000016
MIDX_SPATIALSOUND   equ $000018
MIDX_KMX	    equ $000019
MIDX_AXXES	    equ $000020


    ; European Group
MID_PASSAC	    equ $20
MID_SIEL	    equ $21
MID_SYNTHAXE	    equ $22
MID_HOHNER	    equ $24
MID_TWISTER	    equ $25
MID_SOLTON	    equ $26
MID_JELLINGHAUS     equ $27
MID_SOUTHWORTH	    equ $28
MID_PPG 	    equ $29
MID_JEN 	    equ $2a
MID_SSL 	    equ $2b
MID_AUDIOVERITRIEB  equ $2c
MID_ELKA	    equ $2f
MID_DYNACORD	    equ $30

    ; Japanese Group
MID_KAWAI	    equ $40
MID_ROLAND	    equ $41
MID_KORG	    equ $42
MID_YAMAHA	    equ $43
MID_CASIO	    equ $44
MID_MORIDAIRA	    equ $45
MID_KAMIYA	    equ $46
MID_AKAI	    equ $47
MID_JAPANVICTOR     equ $48
MID_MEISOSHA	    equ $49
MID_HOSHINOGAKKI    equ $4a
MID_FUJITSU	    equ $4b
MID_SONY	    equ $4c
MID_NISSHINONPA     equ $4d
MID_SYSTEMPRODUCT   equ $4f

    ; Universal ID Numbers
MID_NC	    equ $7d
MID_NRT     equ $7e
MID_RT	    equ $7f

	endc
