MIDIfilter/Processor Example 2

Filter out all MIDI events which are not sent on Channel 0

;
; MIDI Processor
;
; EXAMPLE 2: Filter out all MIDI events which are not sent on Channel 0
;
; Copyright 2001 by Thorsten Klose
; Commercial use without my permission is strictly forbidden!
;

;; --------------------------------------------------------------------------
;;  PROC Received 8n: called on a Note Off Event
;;  In:	MIDI_LASTEVENT0: 8n, n = midi channel
;;      MIDI_LASTEVENT1: note number
;;      MIDI_LASTEVENT2: velocity
;; --------------------------------------------------------------------------
PROC_Received8n
	;; check MIDI Channel, leave routine if channel != 0
	movf	MIDI_LASTEVENT0, W	; get event byte #0
	andlw	0x0f			; extract channel
	xorlw	0x00			; compare with 0
	skpz				; skip next command if equal
	return				; leave routine
					; else (if compare was true) continue here

	movf	MIDI_LASTEVENT0, W
	call	MIDI_SendByte
	movf	MIDI_LASTEVENT1, W
	call	MIDI_SendByte
	movf	MIDI_LASTEVENT2, W
	call	MIDI_SendByte
	return

;; --------------------------------------------------------------------------
;;  PROC Received 9n: called on a Note On Event
;;  In:	MIDI_LASTEVENT0: 9n, n = midi channel
;;      MIDI_LASTEVENT1: note number
;;      MIDI_LASTEVENT2: velocity
;; --------------------------------------------------------------------------
PROC_Received9n
	;; check MIDI Channel, leave routine if channel != 0
	movf	MIDI_LASTEVENT0, W	; get event byte #0
	andlw	0x0f			; extract channel
	xorlw	0x00			; compare with 0
	skpz				; skip next command if equal
	return				; leave routine
					; else (if compare was true) continue here

	movf	MIDI_LASTEVENT0, W
	call	MIDI_SendByte
	movf	MIDI_LASTEVENT1, W
	call	MIDI_SendByte
	movf	MIDI_LASTEVENT2, W
	call	MIDI_SendByte
	return

;; --------------------------------------------------------------------------
;;  PROC Received An: called on an Aftertouch Event
;;  In:	MIDI_LASTEVENT0: An, n = midi channel
;;      MIDI_LASTEVENT1: note number
;;      MIDI_LASTEVENT2: preasure
;; --------------------------------------------------------------------------
PROC_ReceivedAn
	;; check MIDI Channel, leave routine if channel != 0
	movf	MIDI_LASTEVENT0, W	; get event byte #0
	andlw	0x0f			; extract channel
	xorlw	0x00			; compare with 0
	skpz				; skip next command if equal
	return				; leave routine
					; else (if compare was true) continue here

	movf	MIDI_LASTEVENT0, W
	call	MIDI_SendByte
	movf	MIDI_LASTEVENT1, W
	call	MIDI_SendByte
	movf	MIDI_LASTEVENT2, W
	call	MIDI_SendByte
	return

;; --------------------------------------------------------------------------
;;  PROC Received Bn: called on a Controller Event
;;  In:	MIDI_LASTEVENT0: Bn, n = midi channel
;;      MIDI_LASTEVENT1: CC number
;;      MIDI_LASTEVENT2: CC value
;; --------------------------------------------------------------------------
PROC_ReceivedBn
	;; check MIDI Channel, leave routine if channel != 0
	movf	MIDI_LASTEVENT0, W	; get event byte #0
	andlw	0x0f			; extract channel
	xorlw	0x00			; compare with 0
	skpz				; skip next command if equal
	return				; leave routine
					; else (if compare was true) continue here

	movf	MIDI_LASTEVENT0, W
	call	MIDI_SendByte
	movf	MIDI_LASTEVENT1, W
	call	MIDI_SendByte
	movf	MIDI_LASTEVENT2, W
	call	MIDI_SendByte
	return

;; --------------------------------------------------------------------------
;;  PROC Received Cn: called on a Controller Event
;;  In:	MIDI_LASTEVENT0: Cn, n = midi channel
;;      MIDI_LASTEVENT2: program number (AND NOT MIDI_LASTEVENT1!)
;; --------------------------------------------------------------------------
PROC_ReceivedCn
	;; check MIDI Channel, leave routine if channel != 0
	movf	MIDI_LASTEVENT0, W	; get event byte #0
	andlw	0x0f			; extract channel
	xorlw	0x00			; compare with 0
	skpz				; skip next command if equal
	return				; leave routine
					; else (if compare was true) continue here

	movf	MIDI_LASTEVENT0, W
	call	MIDI_SendByte
	movf	MIDI_LASTEVENT2, W
	call	MIDI_SendByte
	return

;; --------------------------------------------------------------------------
;;  PROC Received Dn: called on a Poly Aftertouch Event
;;  In:	MIDI_LASTEVENT0: Dn, n = midi channel
;;      MIDI_LASTEVENT2: note number (AND NOT MIDI_LASTEVENT1!)
;; --------------------------------------------------------------------------
PROC_ReceivedDn
	;; check MIDI Channel, leave routine if channel != 0
	movf	MIDI_LASTEVENT0, W	; get event byte #0
	andlw	0x0f			; extract channel
	xorlw	0x00			; compare with 0
	skpz				; skip next command if equal
	return				; leave routine
					; else (if compare was true) continue here

	movf	MIDI_LASTEVENT0, W
	call	MIDI_SendByte
	movf	MIDI_LASTEVENT2, W
	call	MIDI_SendByte
	return

;; --------------------------------------------------------------------------
;;  PROC Received En: called on an Pitch Bender Event
;;  In:	MIDI_LASTEVENT0: En, n = midi channel
;;      MIDI_LASTEVENT1: Pitch Bender High Byte
;;      MIDI_LASTEVENT2: Pitch Bender Low Byte
;; --------------------------------------------------------------------------
PROC_ReceivedEn
	;; check MIDI Channel, leave routine if channel != 0
	movf	MIDI_LASTEVENT0, W	; get event byte #0
	andlw	0x0f			; extract channel
	xorlw	0x00			; compare with 0
	skpz				; skip next command if equal
	return				; leave routine
					; else (if compare was true) continue here

	movf	MIDI_LASTEVENT0, W
	call	MIDI_SendByte
	movf	MIDI_LASTEVENT1, W
	call	MIDI_SendByte
	movf	MIDI_LASTEVENT2, W
	call	MIDI_SendByte
	return

;; --------------------------------------------------------------------------
;;  PROC Received Fx: called on an System Event
;;  In: MIDI_LASTEVENT0: Fx, x = System Service
;;      MIDI_LASTEVENT1: contains the byte of a sysex or MTC stream when
;;                       MIDI_FxSTATUS != 0
;;      MIDI_FxSTATUS:   if 0, send MIDI_LASTEVENT0, else MIDI_LASTEVENT1
;; --------------------------------------------------------------------------
PROC_ReceivedFx
        ;; branch depending on MIDI_FxSTATUS
        movf    MIDI_FxSTATUS, W
        bnz     PROC_ReceivedFx_SendByte
        
PROC_ReceivedFx_SendCommand
        movf    MIDI_LASTEVENT0, W
        call    MIDI_SendByte
        return

PROC_ReceivedFx_SendByte
        movf    MIDI_LASTEVENT1, W
        call    MIDI_SendByte
        return



Last update: 2024-05-08

Copyright © 1998-2023, Thorsten Klose. All rights reserved.