ui_xy XY Pad, $NI_MOUSE_EVENT_TYPE and Pitch Bend on a Surface Pro 3

samriccijr
samriccijr Member Posts: 2 Member

Hi All! This is my first script post.

I am running Kontakt 5 on a Surface Pro 3 with Win10. I made a multi script that has 12 instrument program buttons, 6 cc knobs, a modulation slider and a XY Pad for pitch bend. I want to use the Surface instead of external controllers so I can be keyboard independent, i.e., I can walk into any gig, plug into any keyboard, and control my sounds.

I can select programs in the instrument bank, and I can transmit CCS using the script knobs. I can transmit pitch bend but I cannot re-center the XY pad.

When I lift the left mouse button, I want to center the X axis of the pad (0.5 or 8192). All other cases I want to transmit pitch bend.

Here is my script:

on init
	set_ui_height(6)
	declare ui_xy ?myXY[2]
	declare $xyID
	$xyID := get_ui_id(?myXY)		
	set_control_par_str_arr($xyID, $CONTROL_PAR_AUTOMATION_NAME, ...
	 	"Bend", 0)
	set_control_par_str_arr($xyID, $CONTROL_PAR_AUTOMATION_NAME, ...
	 	"Unused", 1)
	set_control_par($xyID, $CONTROL_PAR_MOUSE_MODE, 0)
	set_control_par($xyID, $CONTROL_PAR_MOUSE_BEHAVIOUR_X, 1000) 
	set_control_par($xyID, $CONTROL_PAR_MOUSE_BEHAVIOUR_Y, 10)
	set_control_par($xyID, $CONTROL_PAR_POS_X, 50)
	set_control_par($xyID, $CONTROL_PAR_POS_Y, 50)
	set_control_par($xyID, $CONTROL_PAR_WIDTH, 200)
	set_control_par($xyID, $CONTROL_PAR_HEIGHT, 50)
	{move the cursors to the center of the XY pad}
	?myXY[0] := 0.5 {1st cursor, X axis}
	?myXY[1] := 0.5 {1st cursor, Y axis}
	end on

on ui_control (?myXY)	
	if($NI_MOUSE_EVENT_TYPE = $NI_MOUSE_EVENT_TYPE_LEFT_BUTTON_UP)
		?myXY[0] :=0.5 {set pitch bend to neutral}
		set_midi(0,$MIDI_COMMAND_PITCH_BEND,lsb(real_to_int(16383.0 * ?myXY[0])),msb(real_to_int(16383.0 * ?myXY[0])))
	else
		set_midi(0,$MIDI_COMMAND_PITCH_BEND,lsb(real_to_int(16383.0 * ?myXY[0])),msb(real_to_int(16383.0 * ?myXY[0]))){transmit pitch bend}
	end if
	?myXY[1] := 0.5
	message( real_to_int(16383.0 * ?myXY[0]) )
end on

I think my mistake is with the "if $NI_MOUSE..." statement.

Thank you for your help!

Sam in NJ USA

Comments

  • EvilDragon
    EvilDragon Moderator Posts: 1,017 mod
    edited May 2022

    It seems to work just fine over here? Although you could in theory do it with just one set_midi() command (do it outside of if clause). And maybe use a helper variable to do the real_to_int() part only once.

  • samriccijr
    samriccijr Member Posts: 2 Member

    Thank you @EvilDragon! This script works in Kontakt 6. Kontakt 5.8.1 apparently does not like $NI_MOUSE_EVENT_TYPE_LEFT_BUTTON_UP. And I am still learning the type mismatches ~@$%

    Some tips when using knobs/sliders on a Surface Pro 3:

    1: Bigger is better. Make the knobs and sliders as big as you can manage.

    2: It's all in the technique. a: Touch and release the knob/slider, then b: within a half-second re-touch and drag the knob/slider. This gives the smoothest knob/slider response.

    3: Potayyto or Potahhto: Today I prefer touch sliders over touch knobs because you can see the position more clearly. Tomorrow I will prefer knobs because of space ergonomics.

    4: No Multi-Touch. The Surface Pro 3 does not have multi-touch, so you cannot hold a finger on the Kontakt (Surface) keyboard and turn a Kontakt (Surface) knob.

    5: Use ASIO4ALL to reduce latency on the Surface Pro.

    I like this setup more every day....

    here is the updated pitch bender code for Kontakt 6. Happy Surface Pitch Bends lol!

    Thank you! Sam in NJ USA

    on init
    	set_ui_height(6)
    	declare ui_xy ?myXY[2]
    	declare $xyID
    	$xyID := get_ui_id(?myXY)		
    	set_control_par_str_arr($xyID, $CONTROL_PAR_AUTOMATION_NAME, ...
    	 	"Bend", 0)
    	set_control_par_str_arr($xyID, $CONTROL_PAR_AUTOMATION_NAME, ...
    	 	"Unused", 1)
    	set_control_par($xyID, $CONTROL_PAR_MOUSE_MODE, 0)
    	set_control_par($xyID, $CONTROL_PAR_MOUSE_BEHAVIOUR_X, 1000) 
    	set_control_par($xyID, $CONTROL_PAR_MOUSE_BEHAVIOUR_Y, 10)
    	set_control_par($xyID, $CONTROL_PAR_POS_X, 50)
    	set_control_par($xyID, $CONTROL_PAR_POS_Y, 50)
    	set_control_par($xyID, $CONTROL_PAR_WIDTH, 200)
    	set_control_par($xyID, $CONTROL_PAR_HEIGHT, 50)
    	?myXY[0] := 0.5
    	?myXY[1] := 0.5
    	end on
    on ui_control (?myXY)
    	if($NI_MOUSE_EVENT_TYPE = $NI_MOUSE_EVENT_TYPE_LEFT_BUTTON_UP)
              {lift left mouse button}
    		?myXY[0] :=0.50005 {center pitch at 8192 0x00 0x64}
    	end if
    		set_midi(0,$MIDI_COMMAND_PITCH_BEND,lsb(real_to_int(16383.0 * ?myXY[0])),msb(real_to_int(16383.0 * ?myXY[0])))
    	?myXY[1] := 0.50005 {not using y axis}
    	message( real_to_int(16383.0 * ?myXY[0]) )
    end on
    


  • EvilDragon
    EvilDragon Moderator Posts: 1,017 mod

    It could be there were some bugfixes in ui_xy implementation between K5 and K6.

    Also multitouch won't work at all with Kontakt, even if your touchscreen supports it. It's purely a single cursor app.

Back To Top