#
# midi devices config
#
#dnew 0 "/dev/rmidi4" rw
#dnew 1 "/dev/rmidi3" rw
#
#


#
# some filter rules
#
proc ctldrop ctlno {
	for i in [ilist] {
		fmap {ctl $i $ctlno} {none}
	}
}

proc ctlmap ic oc {
	for i in [ilist] {
		fmap {ctl $i $ic} {ctl [getc] $oc}
	}
}

#
# unmute all tracks
#
proc nomute {
	for i in [tlist] {
		unmute $i
	}
}

#
# mute all tracks but current
#
proc solo {
	for i in [tlist] {
		mute $i
	}
	unmute [gett]
}

#
# turn on general midi (send sysex)
#
proc gmon devnum {
	xnew gmon
	xadd $devnum { 0xF0 0x7E 0x7F 0x09 0x01 0xF7 }
}

#
# configure an instrument for a given general midi patch
#
proc gmp patch {
	oaddev { pc [geto] ($patch - 1) }
}

#
# XV-2020 specific macros
#
# configures a instrument with the given bank/patch or bank rhythm
# bank 1,2,3,4 corresponds to preset A,B,C,D
# patches/rhythmes are counted from 1 to 128
#
proc xvp bank patch {
	oaddev { xpc [geto] ($patch - 1) (87 * 128 + (64 + $bank - 1)) }
}
proc xvr bank patch { 
	oaddev { xpc [geto] ($patch - 1) (86 * 128 + (64 + $bank - 1)) }
}

#
# generate a sysex message that set parameter on 
# address (a0,a1,a2,a3) to val
#
proc xvparam a0 a1 a2 a3 val {
	return {  							\
		0xf0 0x41 0x7f 0x00 0x10 0x12 $a0 $a1 $a2 $a3 $val	\
		128 - ($a0 + $a1 + $a2 + $a3 + $val) % 128		\
		0xf7 }
}

#
# controllers config
#
proc vol    val { oaddev {ctl [geto] 7  $val}; }
proc bal    val { oaddev {ctl [geto] 8  $val}; }
proc pan    val { oaddev {ctl [geto] 10 $val}; }
proc reverb val { oaddev {ctl [geto] 91 $val}; }
proc chorus val { oaddev {ctl [geto] 93 $val}; }

#
# set RPN/NRPN to the given value for the current chan
#
proc rpn  addr val {
	oaddev {rpn [geto] $addr $val}
}
proc nrpn addr val { 
	oaddev {nrpn [geto] $addr $val}
}
