1. IMPORTANT:
    We launched a new online community and this space is now closed. This community will be available as a read-only resources until further notice.
    JOIN US HERE

Scripting Beginner

Discussion in 'Scripting Workshop' started by Fletch88, Mar 24, 2010.

Thread Status:
Not open for further replies.
  1. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Yeah, so now I figured it out.

    That's even easier, you just need to tell me which groups rule over which. So you have Single note (3 groups), Bar Chords (3 groups) and Triad Chords (3 groups), or do you have Sustain (single, bar, triad), Stab (single, bar, triad) and Mute (single, bar, triad)?
     
  2. Fletch88

    Fletch88 New Member

    Messages:
    19
    Mmmm good thinkin : ) think id go for breakin it into Single Note, Bar Chords and Triads. What version of Kontakt do you because i cant open the test you sent me : (
     
  3. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
  4. Fletch88

    Fletch88 New Member

    Messages:
    19
    Ive got the latest update but its telling me to upgrade and there isnt anything else on the service centre.......
     
  5. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Too strange. :/
    ---
    Well, here's the script from that test file. Paste it in your NKI (make sure it has exactly 9 groups) and see what happens.

    Code:
    on init
    	message("")
    	make_perfview
    
    	declare $count
    	declare %var[9]
    	declare ui_button $G1
    	declare ui_button $G2
    	declare ui_button $G3
    	declare ui_button $G4
    	declare ui_button $G5
    	declare ui_button $G6
    	declare ui_button $G7
    	declare ui_button $G8
    	declare ui_button $G9
    	
    	declare %guid[9]
    	%guid[0] := (get_ui_id($G1))
    	%guid[1] := (get_ui_id($G2))
    	%guid[2] := (get_ui_id($G3))
    	%guid[3] := (get_ui_id($G4))
    	%guid[4] := (get_ui_id($G5))
    	%guid[5] := (get_ui_id($G6))
    	%guid[6] := (get_ui_id($G7))
    	%guid[7] := (get_ui_id($G8))
    	%guid[8] := (get_ui_id($G9))
    
    	declare ui_table %state[9](3,1,1)
    	hide_part(%state,$HIDE_WHOLE_CONTROL)
    
    	declare ui_label $text(3,1)
    	move_control($text,1,4)
    	set_text($text,"Group Switching Controls")
    	set_control_par(get_ui_id($text),$CONTROL_PAR_TEXT_ALIGNMENT,1)
    
    	$count := 0
    	while ($count < $NUM_GROUPS)
    		set_control_par_str(%guid[$count],$CONTROL_PAR_TEXT,group_name($count))
    		inc($count)
    	end while
    
    	$count := 0
    	while ($count < 9)
    		set_control_par(%guid[$count],$CONTROL_PAR_GRID_X,($count mod 3) + 1)
    		set_control_par(%guid[$count],$CONTROL_PAR_GRID_Y,($count / 3) + 1)
    		inc($count)
    	end while
    	
    	$G1 := 1
    	%state[0] := 1
    
    end on
    
    on ui_control($G1)
    	if ($G1 = 1)
    		%state[0] := 1
    		$count := 0
    		while ($count < 9)
    			if ($count # 0)
    				%state[$count] := 0
    			end if
    			inc($count)
    		end while
    	else
    		%state[0] := 0
    	end if
    	$G2 := 0
    	$G3 := 0
    	$G4 := 0
    	$G5 := 0
    	$G6 := 0
    	$G7 := 0
    	$G8 := 0
    	$G9 := 0
    end on
    
    on ui_control($G2)
    	if ($G2 = 1)
    		%state[1] := 1
    		$count := 0
    		while ($count < 9)
    			if ($count # 1)
    				%state[$count] := 0
    			end if
    			inc($count)
    		end while
    	else
    		%state[1] := 0
    	end if
    	$G1 := 0
    	$G3 := 0
    	$G4 := 0
    	$G5 := 0
    	$G6 := 0
    	$G7 := 0
    	$G8 := 0
    	$G9 := 0
    end on
    
    on ui_control($G3)
    	if ($G3 = 1)
    		%state[2] := 1
    		$count := 0
    		while ($count < 9)
    			if ($count # 2)
    				%state[$count] := 0
    			end if
    			inc($count)
    		end while
    	else
    		%state[2] := 0
    	end if
    	$G1 := 0
    	$G2 := 0
    	$G4 := 0
    	$G5 := 0
    	$G6 := 0
    	$G7 := 0
    	$G8 := 0
    	$G9 := 0
    end on
    
    on ui_control($G4)
    	if ($G4 = 1)
    		%state[3] := 1
    		$count := 0
    		while ($count < 9)
    			if ($count # 3)
    				%state[$count] := 0
    			end if
    			inc($count)
    		end while
    	else
    		%state[3] := 0
    	end if
    	$G1 := 0
    	$G2 := 0
    	$G3 := 0
    	$G5 := 0
    	$G6 := 0
    	$G7 := 0
    	$G8 := 0
    	$G9 := 0
    end on
    
    on ui_control($G5)
    	if ($G5 = 1)
    		%state[4] := 1
    		$count := 0
    		while ($count < 9)
    			if ($count # 4)
    				%state[$count] := 0
    			end if
    			inc($count)
    		end while
    	else
    		%state[4] := 0
    	end if
    	$G1 := 0
    	$G2 := 0
    	$G3 := 0
    	$G4 := 0
    	$G6 := 0
    	$G7 := 0
    	$G8 := 0
    	$G9 := 0
    end on
    
    on ui_control($G6)
    	if ($G6 = 1)
    		%state[5] := 1
    		$count := 0
    		while ($count < 9)
    			if ($count # 5)
    				%state[$count] := 0
    			end if
    			inc($count)
    		end while
    	else
    		%state[5] := 0
    	end if
    	$G1 := 0
    	$G2 := 0
    	$G3 := 0
    	$G4 := 0
    	$G5 := 0
    	$G7 := 0
    	$G8 := 0
    	$G9 := 0
    end on
    
    on ui_control($G7)
    	if ($G7 = 1)
    		%state[6] := 1
    		$count := 0
    		while ($count < 9)
    			if ($count # 6)
    				%state[$count] := 0
    			end if
    			inc($count)
    		end while
    	else
    		%state[6] := 0
    	end if
    	$G1 := 0
    	$G2 := 0
    	$G3 := 0
    	$G4 := 0
    	$G5 := 0
    	$G6 := 0
    	$G8 := 0
    	$G9 := 0
    end on
    
    on ui_control($G8)
    	if ($G8 = 1)
    		%state[7] := 1
    		$count := 0
    		while ($count < 9)
    			if ($count # 7)
    				%state[$count] := 0
    			end if
    			inc($count)
    		end while
    	else
    		%state[7] := 0
    	end if
    	$G1 := 0
    	$G2 := 0
    	$G3 := 0
    	$G4 := 0
    	$G5 := 0
    	$G6 := 0
    	$G7 := 0
    	$G9 := 0
    end on
    
    on ui_control($G9)
    	if ($G9 = 1)
    		%state[8] := 1
    		$count := 0
    		while ($count < 8)
    			if ($count # 0)
    				%state[$count] := 0
    			end if
    			inc($count)
    		end while
    	else
    		%state[8] := 0
    	end if
    	$G1 := 0
    	$G2 := 0
    	$G3 := 0
    	$G4 := 0
    	$G5 := 0
    	$G6 := 0
    	$G7 := 0
    	$G8 := 0
    end on
    
    on note
    	disallow_group($ALL_GROUPS)
    	$count := 0
    	while ($count < 9)
    		if (%state[$count] = 1)
    			allow_group($count)
    		end if
    		inc($count)
    	end while
    end on
    
     
  6. Fletch88

    Fletch88 New Member

    Messages:
    19
    Dude thats ****ing awesome! Thank you!
     
  7. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    No prob. Can you restructure the script so that it has 3 buttons only, and then each button disables 3 groups at once, or should I do it?
     
  8. Fletch88

    Fletch88 New Member

    Messages:
    19
    Yer maybe if you dont mind? If I wanted it to work with only 3 groups (different instrument) wud I just all the parts that say 4,5,6,7,8,9?
    ---
    meant to say delete all the parts that have 4,5,6,7,8,9
     
  9. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Yup, you would then delete everything that mentions $G4 to $G9. And some other tweaks in while loops etc. Needs some restructuring.
     
  10. Fletch88

    Fletch88 New Member

    Messages:
    19
    Nice one managed to get it to work with only two and three groups. Did you say you'd figured out how to have three knobs controlling three groups?

    Cheers buddy!
     
  11. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    It's not hard, just please tell me the exact ordering (plus names) of the groups, and which button you want to control which groups.

    -----

    Here's the script using ordering you previously stated (so the groups are sorted like this: Single note sust, Single note stab, Single note mute, Bar chords sust, stab, mute, Triads sust, stab, mute).

    Code:
    on init
    	message("")
    	make_perfview
    
    	declare $count
    	declare %var[3]
    	declare ui_button $G1
    	declare ui_button $G2
    	declare ui_button $G3
    	
    	declare %guid[3]
    	%guid[0] := (get_ui_id($G1))
    	%guid[1] := (get_ui_id($G2))
    	%guid[2] := (get_ui_id($G3))
    
    	declare ui_table %state[3](3,1,1)
    	hide_part(%state,$HIDE_WHOLE_CONTROL)
    
    	declare ui_label $text(3,1)
    	set_text($text,"Group Switching Controls")
    	set_control_par(get_ui_id($text),$CONTROL_PAR_TEXT_ALIGNMENT,1)
    
    	$count := 0
    	while ($count < 3)
    		set_control_par_str(%guid[$count],$CONTROL_PAR_TEXT,group_name($count))
    		inc($count)
    	end while
    
    	$count := 0
    	while ($count < 3)
    		set_control_par(%guid[$count],$CONTROL_PAR_GRID_X,($count mod 3) + 1)
    		set_control_par(%guid[$count],$CONTROL_PAR_GRID_Y,($count / 3) + 2)
    		inc($count)
    	end while
    	
    	$G1 := 1
    	%state[0] := 1
    
    end on
    
    on ui_control($G1)
    	if ($G1 = 1)
    		%state[0] := 1
    		$count := 0
    		while ($count < 3)
    			if ($count # 0)
    				%state[$count] := 0
    			end if
    			inc($count)
    		end while
    	else
    		%state[0] := 0
    	end if
    	$G2 := 0
    	$G3 := 0
    end on
    
    on ui_control($G2)
    	if ($G2 = 1)
    		%state[1] := 1
    		$count := 0
    		while ($count < 3)
    			if ($count # 1)
    				%state[$count] := 0
    			end if
    			inc($count)
    		end while
    	else
    		%state[1] := 0
    	end if
    	$G1 := 0
    	$G3 := 0
    end on
    
    on ui_control($G3)
    	if ($G3 = 1)
    		%state[2] := 1
    		$count := 0
    		while ($count < 3)
    			if ($count # 2)
    				%state[$count] := 0
    			end if
    			inc($count)
    		end while
    	else
    		%state[2] := 0
    	end if
    	$G1 := 0
    	$G2 := 0
    end on
    
    on note
    	disallow_group($ALL_GROUPS)
    	$count := 0
    	while ($count < 3)
    		if (%state[$count] = 1)
    			allow_group($count)
    			allow_group($count+3)
    			allow_group($count+6)
    		end if
    		inc($count)
    	end while
    end on
    
     
  12. Fletch88

    Fletch88 New Member

    Messages:
    19
    Hey mate,

    So I was thinking 3 knobs (look like guitar or amps knobs if possible)

    Knob 1: - "Single Notes" - Sustain, stab, muted
    Knob 2: - "Bar Chords" - Same as above
    Knob 3: - "Triad Chords" - same as above

    Thanks again for all your help buddy! :D
     
  13. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Ah, so like knob switches. You're gonna have to have your own graphics for the knobs, that's a bit more complicated to do. Also, the PNG files have to be in a special folder for everything to work. I suggest just use regular Kontakt knobs for now.
    ---
    Other than that, the script is even easier:

    Code:
    on init
    	message("")
    	make_perfview
    
    	declare $count
    	declare ui_knob $G1 (0,2,1)
    	declare ui_knob $G2 (0,2,1)
    	declare ui_knob $G3 (0,2,1)
    	
    	declare %guid[3]
    	%guid[0] := (get_ui_id($G1))
    	%guid[1] := (get_ui_id($G2))
    	%guid[2] := (get_ui_id($G3))
    
    	declare ui_label $text(3,1)
    	set_text($text,"Group Switching Controls")
    	set_control_par(get_ui_id($text),$CONTROL_PAR_TEXT_ALIGNMENT,1)
    
    	set_text($G1,"Singles")
    	set_text($G2,"Barre")
    	set_text($G3,"Triads")
    	set_knob_label($G1,"Sust")
    	set_knob_label($G2,"Sust")
    	set_knob_label($G3,"Sust")
    
    	$count := 0
    	while ($count < 3)
    		set_control_par(%guid[$count],$CONTROL_PAR_GRID_X,($count mod 3) + 1)
    		set_control_par(%guid[$count],$CONTROL_PAR_GRID_Y,($count/3) + 2)
    		inc($count)
    	end while
    	
    end on
    
    on ui_control($G1)
    	select ($G1)
    		case 0
    			set_knob_label($G1,"Sust")
    		case 1
    			set_knob_label($G1,"Stab")
    		case 2
    			set_knob_label($G1,"Mute")
    	end select
    end on
    
    on ui_control($G2)
    	select ($G2)
    		case 0
    			set_knob_label($G2,"Sust")
    		case 1
    			set_knob_label($G2,"Stab")
    		case 2
    			set_knob_label($G2,"Mute")
    	end select
    end on
    
    on ui_control($G3)
    	select ($G3)
    		case 0
    			set_knob_label($G3,"Sust")
    		case 1
    			set_knob_label($G3,"Stab")
    		case 2
    			set_knob_label($G3,"Mute")
    	end select
    end on
    
    on note
    	disallow_group($ALL_GROUPS)
    	allow_group($G1)
    	allow_group($G2+3)
    	allow_group($G3+6)
    end on

    You will need keyswitching, I hope you're using this, because the way this script works, 3 groups work at the same time - each is selected by one of the knobs. So, you have to have some way of switching between singles, barre chords, and triads. I hope you're using keyswitching or modwheel or whatever for that.

    Neat thing: right-click on each knob and you can MIDI learn them to a CC!
     
  14. stevewelburn

    stevewelburn NI Product Owner

    Messages:
    3
    Upgrading to the latest Kontakt installs the KSP Reference Manual. Unfortunately, it doesn't seem to appear as documentation updates (possibly 'cos it's not been updated, it's just missing for some people!). There's no tutorial available at the moment for Kontakt 4 KSP though... Not sure if it's just Komplete people that didn't get it, or whether people with an individual Kontakt miss it.
     
  15. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    There is no KSP tutorial yet. :(
     
  16. Fletch88

    Fletch88 New Member

    Messages:
    19
    Hey Mario,

    Hows things? The script you sent is working great! Thanks so much again! You know how to make the labels larger so they read Sustain instead of Sustai ? : )

    Cheers
     
  17. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Unfortunately, labels can't get larger, it's the limitation of the graphics that those knobs are based on. However, there are some other solutions possible, perhaps. I'll hack a script in a week (I hope), when I'm back from vacation ;)
     
  18. MikeNovy

    MikeNovy New Member

    Messages:
    16
  19. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Hey Fletch, sorry it took me a while, but this may work if you're so keen on having written "Sustain" instead of "Sust". However, visually it's not the same because the label overlapping with knob background makes a grayish color which is a bit harder to read. But, there you have it.

    Additionally, you can emulate the knob background via PNG image which would be loaded into NKI, and then you would just run the command to hide the knob background, and then it would be white all over. Suit yourself :)

    Code:
    on init
    	message("")
    	make_perfview
    
    	declare $count
    	declare ui_knob $G1 (0,2,1)
    	declare ui_knob $G2 (0,2,1)
    	declare ui_knob $G3 (0,2,1)
    
    	declare ui_label $sus1(1,1)
    	declare ui_label $sus2(1,1)
    	declare ui_label $sus3(1,1)
    	
    	declare %guid[6]
    	%guid[0] := (get_ui_id($G1))
    	%guid[1] := (get_ui_id($G2))
    	%guid[2] := (get_ui_id($G3))
    	%guid[3] := (get_ui_id($sus1))
    	%guid[4] := (get_ui_id($sus2))
    	%guid[5] := (get_ui_id($sus3))
    
    	declare ui_label $text(3,1)
    	set_text($text,"Group Switching Controls")
    	set_control_par(get_ui_id($text),$CONTROL_PAR_TEXT_ALIGNMENT,1)
    
    	$count := 3
    	while ($count < 6)
    		set_control_par(%guid[$count],$CONTROL_PAR_POS_X,104+(92*($count-3)))
    		set_control_par(%guid[$count],$CONTROL_PAR_POS_Y,44)
    		set_control_par(%guid[$count],$CONTROL_PAR_HIDE,$HIDE_PART_BG)
    		inc($count)
    	end while
    
    	set_text($G1,"Singles")
    	set_text($G2,"Barre")
    	set_text($G3,"Triads")
    
    	$count := 0
    	while ($count < 3)
    		set_control_par(%guid[$count],$CONTROL_PAR_GRID_X,($count mod 3) + 1)
    		set_control_par(%guid[$count],$CONTROL_PAR_GRID_Y,($count/3) + 2)
    		set_control_par(%guid[$count],$CONTROL_PAR_HIDE,$HIDE_PART_VALUE)
    		inc($count)
    	end while
    
    	make_persistent($G1)
    	make_persistent($G2)
    	make_persistent($G3)
    	read_persistent_var($G1)
    	read_persistent_var($G2)
    	read_persistent_var($G3)
    	
    	select ($G1)
    		case 0
    			set_text($sus1,"Sustain")
    		case 1
    			set_text($sus1,"Stab")
    		case 2
    			set_text($sus1,"Mute")
    	end select
    
    	select ($G2)
    		case 0
    			set_text($sus2,"Sustain")
    		case 1
    			set_text($sus2,"Stab")
    		case 2
    			set_text($sus2,"Mute")
    	end select
    
    	select ($G3)
    		case 0
    			set_text($sus3,"Sustain")
    		case 1
    			set_text($sus3,"Stab")
    		case 2
    			set_text($sus3,"Mute")
    	end select
    
    end on
    
    on ui_control($G1)
    	select ($G1)
    		case 0
    			set_text($sus1,"Sustain")
    		case 1
    			set_text($sus1,"Stab")
    		case 2
    			set_text($sus1,"Mute")
    	end select
    end on
    
    on ui_control($G2)
    	select ($G2)
    		case 0
    			set_text($sus2,"Sustain")
    		case 1
    			set_text($sus2,"Stab")
    		case 2
    			set_text($sus2,"Mute")
    	end select
    end on
    
    on ui_control($G3)
    	select ($G3)
    		case 0
    			set_text($sus3,"Sustain")
    		case 1
    			set_text($sus3,"Stab")
    		case 2
    			set_text($sus3,"Mute")
    	end select
    end on
    
    on note
    	disallow_group($ALL_GROUPS)
    	allow_group($G1)
    	allow_group($G2+3)
    	allow_group($G3+6)
    end on
     
Thread Status:
Not open for further replies.