/*

"MIDI_ChannelRangeLimiter" - by: Sjoerd van Geffen (banned)
v0.01 (2009-06-07)

Restricts MIDI events by channel range; only events between low limit and high limit are allowed to pass thru.

*/

////////////////////////////////////////////////////////////////////////////////////////////
desc: MIDI: channel limiter.

////////////////////////////////////////////////////////////////////////////////////////////
slider1:1<1,16,1>Low Limit
slider2:2<1,16,1>High Limit

////////////////////////////////////////////////////////////////////////////////////////////
@init

ext_noinit = 1.0; //Set this variable to 1.0 in your @init section if you do not wish for @init to be called (and variables/RAM to be possibly cleared) on every transport start.

ext_nodenorm = 1.0; //Set this variable to 1.0 in your @init section if you do not wish to have anti-denormal noise added to input.

//MIDI messages:
//statNoteOff = 128; // (= 8 * 16)
//statNoteOn = 144; // (= 9 * 16)
//statControlChange = 176; // (= 11 * 16)
//statPitch = 224; // (=14 * 16)
//ccAllNotesOff = 123;

////////////////////////////////////////////////////////////////////////////////////////////
@slider

MIDIChannelLowLimit = slider1 - 1;
MIDIChannelHighLimit = slider2 - 1;

////////////////////////////////////////////////////////////////////////////////////////////
@block
while
(
	midirecv(offset,msg1,msg23) ?
	(
		//Check status byte
		//status = msg1 & 240;  //High four bits is message type (240 == 11110000)
		//Check MIDI channel
		channel = msg1 & 15;  //Low four bits is channel number (15 == 00001111)
		
		//Is the MIDI event's channel between the high and low limit? 
		(channel >= MIDIChannelLowLimit && channel <= MIDIChannelHighLimit) ?
		(
			midisend(offset,msg1,msg23); //Pass thru.
		);
	);
);