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


#
# function to make the current filter drop controller number ``ictl''
# on the current input
#
proc ctldrop ctlno {
	for i in [ilist] {
		fmap {ctl $i $ctlno} {none}
	}
}


#
# function to make the current filter route controller number ``ictl''
# on the current input to controller ``octl'' on the current output
#
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]
}

#
# function to add a sysex that turns on general midi
#
proc gmon devnum {
	xnew gmon
	xadd $devnum { 0xF0 0x7E 0x7F 0x09 0x01 0xF7 }
}

#
# function to set program number of the current output to th given
# general midi program number
#
proc gmp patch {
	oaddev { pc [geto] ($patch - 1) }
}

#
# set volume (controller number 7) of the current output
#
proc vol val {
	oaddev {ctl [geto] 7  $val}
}

#
# set pan (controller number 10) of the current output
#
proc pan val {
	oaddev {ctl [geto] 10 $val}
}

#
# set reverb (controller number 91) of the current output
#
proc reverb val {
	oaddev {ctl [geto] 91 $val};
}

#
# set chorus (controller number 93) of the current output
#
proc chorus val {
	oaddev {ctl [geto] 93 $val};
}

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

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

#
# XV-2020 specific macros
#
# configures a instrument with the given bank/patch or bank rhythm
# bank 0,1,2,3 corresponds to preset A, B, C and D
# patches/rhythms are counted from 0 to 127
#
proc xvp bank patch {
	oaddev { xpc [geto] ($patch) (11200 + $bank) }
}
proc xvr bank patch { 
	oaddev { xpc [geto] ($patch) (11072 + $bank) }
}

#
# 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 }
}

