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

Key Mapping Feature *HELP*

Discussion in 'Scripting Workshop' started by Mr.Lion, Apr 18, 2015.

  1. Big Bob

    Big Bob Forum Member

    Messages:
    606
    Hi Robin,

    In addition to posting the completed script, I'll attach the KSE source code file for you in case you can't lift it from the text itself. I haven't had much time to test but, I'm sure you will do that for me:).

    There are a few preference issues that always arise with something like this but I just made an executive decision for now. After you have a chance to play with it, let me know if you want me to change the way something works.

    { Key Learn Demo Script by RDV 4-26-15 }
    on init
    ``message('')
    ``set_ui_height_px(200)
    ``make_perfview
    ``declare const X := 50```{ sub-panel coordinates }
    ``declare const Y := 30
    ``declare const dY := 20``{ row spacing }
    ````{ Default instrument drum-sound/trigger keys }
    ``declare const NumSounds := 3
    ``declare const DS0 := 36``{ Rimshot }
    ``declare const DS1 := 37``{ Rim Click }
    ``declare const DS2 := 38``{ SideStick }
    ``declare const BlueKey := 5``{ key colors }
    ``declare const CyanKey := 6
    ``declare const GreenKey := 3
    ``declare const YellowKey := 2
    ``declare const RedKey := 4
    ``declare KeyColor[3] := (0,RedKey,BlueKey) { not assigned, mono, poly }
    ````
    ``
    declare DTKey[NumSounds] := (DS0,DS1,DS2) { default trigger keys }
    ``declare TKey[NumSounds] := (DS0,DS1,DS2)``{ current trigger keys }
    ````make_persistent(TKey)
    ``
    ``
    declare EBoxID[NumSounds]``{ ids for value edits }
    ``declare LBtnID[NumSounds]``{ ids for Learn Btns }
    ``
    ``
    declare idx
    ``declare key
    ``declare learn_idx := -1````{ learn inactive }
    ``
    ``
    for idx := 0 to 127
    ````set_key_color(idx,0)`````{ clear keyboard coloring }
    ``end for
    ``
    ``
    { Fixed caption labels, these can all be in the wallpaper instead }
    ``declare ui_label Header(1,1)
    ````set_text(Header,'Drum Sound Trigger Keys')
    ````move_control_px(Header,X,Y)
    ````Header->width := 155
    ````Header->hide := 1
    ````Header->font_type := 16
    ````Header->text_alignment := 2
    ``line_caption(0,'Rimshot')
    ``line_caption(1,'Rim Click')
    ``line_caption(2,'Side Stick')
    ``
    ``
    key_learn(0)``{ Key/Learn btn sets }
    ``key_learn(1)
    ``key_learn(2)
    ``
    ``
    read_persistent_var(TKey)
    ``{ set the edit box and learn btn attributes }
    ``for idx := 0 to NumSounds - 1
    ````EBoxID[idx]->text := ''
    ````EBoxID[idx]->pos_x := X+65
    ````EBoxID[idx]->pos_y := Y + dY*(idx+1)
    ````EBoxID[idx]->width := 45
    ````EBoxID[idx]->value := TKey[idx]
    ````LBtnID[idx]->text := 'Learn'
    ````LBtnID[idx]->pos_x := X+115
    ````LBtnID[idx]->pos_y := Y + dY*(idx+1)
    ````LBtnID[idx]->text_alignment := 1
    ````LBtnID[idx]->width := 40
    ````key := TKey[idx]
    ````color_key
    ``end for
    end on { init callback }

    on_learn_btn(0)```{ learn btn callback handlers }
    on_learn_btn(1)
    on_learn_btn(2)

    on_learn_edit(0)``{ edit box callback handlers }
    on_learn_edit(1)
    on_learn_edit(2)

    on note
    ``ignore_event(EVENT_ID)```{ recreate or replace as necessary }
    ``if learn_idx = -1``{ in play mode }
    ````idx := search(TKey,EVENT_NOTE)
    ````if idx = -1``
    ``````
    exit```{ note is not assigned, do nothing }
    ````end if
    ````while idx < NumSounds``{ play all sounds layered on this key }
    ``````if TKey[idx] = EVENT_NOTE
    ````````play_note(DTKey[idx],EVENT_VELOCITY,0,-1)
    ``````end if
    ``````inc(idx)
    ````end while
    ``else { learn mode active }
    ````EBoxID[learn_idx]->value := EVENT_NOTE``{ update edit box }
    ````key := TKey[learn_idx]```{ remember prior key }
    ````TKey[learn_idx] := EVENT_NOTE``{ update TKey with new key }
    ````call color_key```````````{ color prior key }````
    ````
    key := EVENT_NOTE
    ````call color_key```````````{ color new key }
    ````LBtnID[learn_idx]->value := 0 { cancel Learn btn }
    ````learn_idx := -1``````````{ de-activate learn index }
    ``end if
    end on { note callback }

    {-------------------------------------------------------------------------
    Support Functions and Macros
    --------------------------------------------------------------------------}``
    function color_key { none, mono, poly }
    ``declare sx
    ``declare cx
    ``cx := search(TKey,key)+1 { cx=0 if none }
    ``if cx # 0``````````{ mono or poly }
    ````sx := cx - 1`````{ index of 1st }
    ````TKey[sx] := -1```{ remove temporarily }
    ````cx := sh_right(search(TKey,key),31) + 2
    ````{ cx=1 if no more, cx=2 if more }
    ````TKey[sx] := key``{ replace key }
    ``end if
    ``set_key_color(key,KeyColor[cx])
    end function

    function learn_btn_change
    ``if LBtnID[idx]->value # 0``{ btn on }
    ````if learn_idx # -1```{ turn off any prior on btn }
    ``````LBtnID[learn_idx]->value := 0
    ````end if
    ````learn_idx := idx````{ update learn index }
    ``else``{ btn off }
    ````learn_idx := -1`````{ de-activate learn index }
    ``end if
    end function

    function learn_edit_change
    ``key := TKey[idx] { old key }
    ``TKey[idx] := EBoxID[idx]->value
    ``call color_key```{ color old key }
    ``key := TKey[idx]
    ``call color_key```{ color new key }
    end function

    macro key_learn(#index#)``{ assigned key and learn btn combo }
    ``declare ui_value_edit LE#index# (0,127,0)
    ````EBoxID[#index#] := get_ui_id(LE#index#)``{ learn edit box }
    ````make_persistent(LE#index#)
    ``declare ui_switch LB#index#
    ````LBtnID[#index#] := get_ui_id(LB#index#)``{ learn btn }
    end macro

    macro line_caption(#index#,caption)``{ not needed if on wallpaper }
    ``declare ui_label CL#index#(1,1)
    ``set_text(CL#index#,caption)
    ``move_control_px(CL#index#,X,Y + dY*(#index#+1))
    ``CL#index#->hide := 1```````````{ transparent }
    ``CL#index#->font_type := 16
    ``CL#index#->text_alignment := 2 { right justified }
    ``CL#index#->width := 65
    end macro

    macro on_learn_btn(#index#)``{ create learn btn handler }
    ``on ui_control(LB#index#)
    ````idx := #index#
    ````call learn_btn_change
    ``end on
    end macro

    macro on_learn_edit(#index#) { create edit box handler }
    ``on ui_control(LE#index#)
    ````idx := #index#
    ````call learn_edit_change
    ``end on
    end macro



    The way I coded it, you can assign a key to several drum sounds if you like for a layered effect. When only one sound is assigned to a key, the key is colored Red. If 2 or more sounds are assigned to a key, the key is colored Blue.

    Have fun testing and studying the code.

    Bob
     

    Attached Files:

    Last edited: Apr 27, 2015
  2. Big Bob

    Big Bob Forum Member

    Messages:
    606
    Hi Robin,

    I found a couple of typos and such so I'll repost here upload the corrected .ksp file.

    { Key Learn Demo Script by RDV(2) 4-26-15 }
    on init
    ``message('')
    ``set_ui_height_px(200)
    ``make_perfview
    ``declare const X := 50```{ sub-panel coordinates }
    ``declare const Y := 30
    ``declare const dY := 20``{ row spacing }
    ````{ Default instrument drum-sound/trigger keys }
    ``declare const NumSounds := 3
    ``declare const DS0 := 36``{ Rimshot }
    ``declare const DS1 := 37``{ Rim Click }
    ``declare const DS2 := 38``{ SideStick }
    ``declare const BlueKey := 5``{ key colors }
    ``declare const CyanKey := 6
    ``declare const GreenKey := 3
    ``declare const YellowKey := 2
    ``declare const RedKey := 4
    ``declare KeyColor[3] := (0,RedKey,BlueKey) { not assigned, mono, poly }
    ````
    ``
    declare DTKey[NumSounds] := (DS0,DS1,DS2) { default trigger keys }
    ``declare TKey[NumSounds] := (DS0,DS1,DS2)``{ current trigger keys }
    ````make_persistent(TKey)
    ``
    ``
    declare EBoxID[NumSounds]``{ ids for value edits }
    ``declare LBtnID[NumSounds]``{ ids for Learn Btns }
    ``
    ``
    declare idx
    ``declare key
    ``declare learn_idx := -1````{ learn inactive }
    ``
    ``
    for idx := 0 to 127
    ````set_key_color(idx,0)`````{ clear keyboard coloring }
    ``end for
    ``
    ``
    { Fixed caption labels, these can all be in the wallpaper instead }
    ``declare ui_label Header(1,1)
    ````set_text(Header,'Drum Sound Trigger Keys')
    ````move_control_px(Header,X,Y)
    ````Header->width := 155
    ````Header->hide := 1
    ````Header->font_type := 16
    ````Header->text_alignment := 2
    ``line_caption(0,'Rimshot')
    ``line_caption(1,'Rim Click')
    ``line_caption(2,'Side Stick')
    ``
    ``
    key_learn(0)``{ Key/Learn btn sets }
    ``key_learn(1)
    ``key_learn(2)
    ``
    ``
    read_persistent_var(TKey)
    ``{ set the edit box and learn btn attributes }
    ``for idx := 0 to NumSounds - 1
    ````EBoxID[idx]->text := ''
    ````EBoxID[idx]->pos_x := X+65
    ````EBoxID[idx]->pos_y := Y + dY*(idx+1)
    ````EBoxID[idx]->width := 45
    ````EBoxID[idx]->value := TKey[idx]
    ````LBtnID[idx]->text := 'Learn'
    ````LBtnID[idx]->pos_x := X+115
    ````LBtnID[idx]->pos_y := Y + dY*(idx+1)
    ````LBtnID[idx]->text_alignment := 1
    ````LBtnID[idx]->width := 40
    ````key := TKey[idx]
    ````color_key
    ``end for
    end on
    { init callback }

    on_learn_btn(0)```{ learn btn callback handlers }
    on_learn_btn(1)
    on_learn_btn(2)

    on_learn_edit(0)``{ edit box callback handlers }
    on_learn_edit(1)
    on_learn_edit(2)

    on note
    ``ignore_event(EVENT_ID)```{ recreate or replace as necessary }
    ``if learn_idx = -1``{ in play mode }
    ````idx := search(TKey,EVENT_NOTE)
    ````if idx = -1``
    ``````
    exit```{ note is not assigned, do nothing }
    ````end if
    ````while idx < NumSounds``{ play all sounds layered on this key }
    ``````if TKey[idx] = EVENT_NOTE
    ````````play_note(DTKey[idx],EVENT_VELOCITY,0,-1)
    ``````end if
    ``````inc(idx)
    ````end while
    ``else { learn mode active }
    ````EBoxID[learn_idx]->value := EVENT_NOTE``{ update edit box }
    ````key := TKey[learn_idx]```{ remember prior key }
    ````TKey[learn_idx] := EVENT_NOTE``{ update TKey with new key }
    ````call color_key```````````{ color prior key }````
    ````
    key := EVENT_NOTE
    ````call color_key```````````{ color new key }
    ````LBtnID[learn_idx]->value := 0 { cancel Learn btn }
    ````learn_idx := -1``````````{ de-activate learn index }
    ``end if
    end on
    { note callback }

    {-------------------------------------------------------------------------
    Support Functions and Macros
    --------------------------------------------------------------------------}
    ``
    function color_key { none, mono, poly }
    ``declare sx
    ``declare cx
    ``cx := search(TKey,key)+1 { cx=0 if none }
    ``if cx # 0``````````{ mono or poly }
    ````sx := cx - 1`````{ index of 1st }
    ````TKey[sx] := -1```{ remove temporarily }
    ````cx := sh_right(search(TKey,key),31) + 2
    ````{ cx=1 if no more, cx=2 if more }
    ````TKey[sx] := key``{ replace key }
    ``end if
    ``set_key_color(key,KeyColor[cx])
    end function

    function learn_btn_change
    ``if LBtnID[idx]->value # 0``{ btn on }
    ````if learn_idx # -1```{ turn off any prior on btn }
    ``````LBtnID[learn_idx]->value := 0
    ````end if
    ````learn_idx := idx````{ update learn index }
    ``else``{ btn off }
    ````learn_idx := -1`````{ de-activate learn index }
    ``end if
    end
    function

    function learn_edit_change
    ``key := TKey[idx] { old key }
    ``TKey[idx] := EBoxID[idx]->value
    ``call color_key```{ color old key }
    ``key := TKey[idx]
    ``call color_key```{ color new key }
    end function

    macro key_learn(#index#)``{ assigned key and learn btn combo }
    ``declare ui_value_edit LE#index# (0,127,0)
    ````EBoxID[#index#] := get_ui_id(LE#index#)``{ learn edit box }
    ``declare ui_switch LB#index#
    ````LBtnID[#index#] := get_ui_id(LB#index#)``{ learn btn }
    end macro

    macro line_caption(#index#,caption)``{ not needed if on wallpaper }
    ``declare ui_label CL#index#(1,1)
    ``set_text(CL#index#,caption)
    ``move_control_px(CL#index#,X,Y + dY*(#index#+1))
    ``CL#index#->hide := 1```````````{ transparent }
    ``CL#index#->font_type := 16
    ``CL#index#->text_alignment := 2 { right justified }
    ``CL#index#->width := 65
    end macro

    macro on_learn_btn(#index#)``{ create learn btn handler }
    ``on ui_control(LB#index#)
    ````idx := #index#
    ````call learn_btn_change
    ``end on
    end macro

    macro on_learn_edit(#index#) { create edit box handler }
    ``on ui_control(LE#index#)
    ````idx := #index#
    ````call learn_edit_change
    ``end on
    end macro


    The only non-trivial change I made was to remove the persistence of the value_edits. They were no longer needed but I forgot to remove them. The only persistent var now is TKey array and all other stuff is initialized from it.

    I'm going to be quiting for the day now but I'll check back in tomorrow morning to see if any issues have arisen :)

    Rejoice,

    Bob
     

    Attached Files:

  3. Mr.Lion

    Mr.Lion NI Product Owner

    Messages:
    159
    Hello Bob!

    The Sqript works PERFECTLY! Exactly what I was after, And I really like the key colour for original notes so if you need to change back I can do that without being confused or anything!

    I'm gonna take a closer look on the script when I've got back from todays studio pass with my solo project!

    EDIT:
    To answear the last post on the first page, I think I'll use Nils's editor. Find the view more compact and easier to keep track of stuff when you don't need to scroll 2 miles to get to the bottom of the script like in Sublime haha

    Big Thanks for the help, this has been more than helpfull!
    Best Regards
    Robin
     
    Last edited: Apr 27, 2015
  4. Big Bob

    Big Bob Forum Member

    Messages:
    606
    I hate to belabor this but, I want to be sure that it's clear. They are both Nils' Editor and I call both the KSE.

    I think you are saying you prefer working with the V152 (Scintilla-based) Editor because of the nice navigation panel. That's fine. I don't know if you are on a Mac or on a PC but some Mac users used to experience some problems with V152.

    The important point here is that you can't just use the Basic Sublime Text. If you want to use Sublime, you need to first obtain and then install Nils' plugin for it. I have both but I generally prefer to use V152 for most things. On the other hand, Mario and others seem to prefer the Sublime host. Different strokes for different folks:)

    Just to finish the KSE discussion, when you set your preferences, please be sure to enable these three:

    1. Optimize compiled code
    2. Extra syntax checks
    3. Compact output

    and of course be sure that 'Use old compiler version' is turned off. These settings are important for when you compile any of my code.

    I'm glad you like it. Hopefully it will be fairly easy to extend or modify as needed but please let me know if I can clarify anything for you.

    Rejoice,

    Bob
     
    Last edited: Apr 27, 2015
  5. Mr.Lion

    Mr.Lion NI Product Owner

    Messages:
    159
    Oh NOW I get it!

    I'm on PC and the V152 works perfectly (so far) !

    I had those 3 checked and also:
    - Compact Variables

    Best Regards
     
  6. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Err... use Ctrl+End on your keyboard (like in almost any text editor, anyways)?

    Also, Sublime has a stupidly awesome feature. Pressing Alt+- (minus) brings you back to the previous cursor position you clicked. Alt+Shift+minus to the newest position. Easy to jump between two specific positions in the script, much easier than in KSE in fact, since it doesn't have that.
     
  7. Big Bob

    Big Bob Forum Member

    Messages:
    606
    That of course is optional (as are the other preferences). I usually leave Compact variables off until I'm truly done with a script in case I need to read the compiled code for some reason.

    I should also mention that with the V152 update of the KSE, the Replace/Find machinery got broken a little in that the Match checkboxes are ignored. This worked correctly with V151 but unfortunately V151 doesn't handle MinInt correctly and I think nested macros weren't supported until V152. However, you may want to keep a copy of V151 handy in case you need to do a lot of text replacement and don't want to change editing environments.

    Rejoice,

    Bob
     
  8. Mr.Lion

    Mr.Lion NI Product Owner

    Messages:
    159
    Thank you very much for all the helpful information Bob!

    You've been more than kind!

    Best Regards
    Robin
     
  9. Big Bob

    Big Bob Forum Member

    Messages:
    606
    You are very welcome Robin, glad I could help.

    When I wrote this script I wasn't sure whether you would want the key coloring or not so I did it rather quickly.

    But, since you seem to like that feature, I got to thinking about it a little and when I get another block of time I'm going to make a few improvements to it (and while I'm at it I'll tighten up the code a little). When I've accomplished that, I'll post it for you.

    Rejoice,

    Bob
     
  10. Mr.Lion

    Mr.Lion NI Product Owner

    Messages:
    159
    Hello Bob!

    I really like the colouring, makes it easier to now where it was originally!

    That would be really nice of you, looking forward to it!

    Best Regards
     
  11. Big Bob

    Big Bob Forum Member

    Messages:
    606
    Hi Robin,

    I'm attaching Demo#3 for you. Among other things, I added a compiler switch that will determine how Kontakt's default key coloring is affected. I think Kontakt colors blue any keys for which playable zones are present and you may or may not want to retain that indication.

    So, for example, if you change say the rimshot on key c0 to c5, do you want to still see Kontakt's blue coloring for c0? The compiler switch is a constant named KeyColorMode and if you set it to zero before compiling the script, Kontakt's default coloring will be retained. Their blue coloring will be overridden by the scripts coloring for the 'assigned' keys but when you change the trigger note, the old default trigger note will still be shown with Kontakt's default color (blue).

    On the other hand, if you set KeyColorMode to any value other than zero, Kontakt's default coloring will be removed and only the script's coloring will be used.

    { Script + this text is apparently too big to post, I'll try posting the script by itself in the next post but meanwhile I've attached the ksp file }

    You also may want to choose two colors other than the Red and Blue that I initially used. If you retain Kontakt's default coloring, the Blue for layered keys (PolyColor) may get confused with Kontakt's default coloring. Also, since it's more or less conventional to show keyswitches in Red, you may also want to change the MonoColor. For the attached script #3 I temporarily set the MonoColor to Green and the PolyColor to Yellow but you can easily change these of course.

    Rejoice,

    Bob
     

    Attached Files:

  12. Big Bob

    Big Bob Forum Member

    Messages:
    606
    { Key Learn Demo Script by RDV(3) 4-27-15 }
    on init
    ``message('')
    ``set_ui_height_px(200)
    ``make_perfview
    ``{------------------------- Configuration Constants -----------------------}
    ``declare const X := 50```{ sub-panel coordinates }
    ``declare const Y := 30
    ``declare const dY := 20``{ row spacing }
    ``declare const KeyColorMode := 0``{ 0=leave default coloring, #0=remove }
    ``{ ksp key colors: 0=default, 1=Wht, 2=Yel, 3=Grn, 4=Red, 5=Blu, 6=Cyan, 7=Blk }
    ``declare const MonoKey := 3 { Green for one assigned sound }
    ``declare const PolyKey := 2 { Yellow for two or more assigned sounds }
    ``declare const NoColor := Bool(KeyColorMode)``````{ Default or White }

    ```````{ Default instrument drum-sound/trigger keys }
    ``declare const NumSounds := 3
    ``declare const DS0 := 36````{ Rimshot }
    ``declare const DS1 := 37````{ Rim Click }
    ``declare const DS2 := 38````{ SideStick }
    ``````````````{ arrays }
    ``declare DTKey[NumSounds] := (DS0,DS1,DS2) { default trigger keys }
    ``declare EBoxID[NumSounds]`````{ ids for value edits }
    ``declare KeyColor[3] := (NoColor,MonoKey,PolyKey) { unassigned, mono, or poly }
    ``declare LBtnID[NumSounds]`````{ ids for Learn Btns }
    ``declare TKey[NumSounds] := (DS0,DS1,DS2)``{ current trigger keys }
    ````make_persistent(TKey)
    `````````````{ simple variables }
    ``declare idx```````````````{ general index }
    ``declare key```````````````{ color_key function parameter }
    ``declare learn_idx := -1```{ learn index initially inactive }
    ``
    ``
    for idx := 0 to 127
    ````set_key_color(idx,NoColor)``{ clear keyboard coloring }
    ``end for
    ``
    ``
    { Fixed caption labels, these can all be in the wallpaper instead }
    ``declare ui_label Header(1,1)
    ````set_text(Header,'Drum Sound Trigger Keys')
    ````move_control_px(Header,X,Y)
    ````Header->width := 155
    ````Header->hide := 1
    ````Header->font_type := 16
    ````Header->text_alignment := 2
    ``declare_line_caption(0,'Rimshot')
    ``declare_line_caption(1,'Rim Click')
    ``declare_line_caption(2,'Side Stick')
    ``
    ``
    declare_key_learn(0)``{ Key/Learn btn sets }
    ``declare_key_learn(1)
    ``declare_key_learn(2)
    ``
    ``
    { set the edit box and learn btn attributes }
    ``read_persistent_var(TKey)
    ``for idx := 0 to NumSounds - 1
    ````key := TKey[idx]``{ assigned key for this sound }
    ````EBoxID[idx]->text := ''
    ````EBoxID[idx]->pos_x := X+65
    ````EBoxID[idx]->pos_y := Y + dY*(idx+1)
    ````EBoxID[idx]->width := 45
    ````EBoxID[idx]->value := key
    ````LBtnID[idx]->text := 'Learn'
    ````LBtnID[idx]->pos_x := X+115
    ````LBtnID[idx]->pos_y := Y + dY*(idx+1)
    ````LBtnID[idx]->text_alignment := 1
    ````LBtnID[idx]->width := 40
    ````TKey[idx] := -1``{ remove key, then test for more hits }
    ````{ if more set to poly color, if not use mono color }
    ````set_key_color(key,KeyColor[hit(key)+2])
    ````TKey[idx] := key { replace removed key }
    ``end for
    end on
    { init callback }

    on_learn_btn(0)```{ learn btn callback handlers }
    on_learn_btn(1)
    on_learn_btn(2)

    on_learn_edit(0)``{ edit box callback handlers }
    on_learn_edit(1)
    on_learn_edit(2)

    on note
    ``ignore_event(EVENT_ID)```{ recreate or replace as necessary }
    ``if learn_idx = -1``{ in play mode }
    ````idx := search(TKey,EVENT_NOTE)
    ````if idx = -1``
    ``````
    exit```{ note is not assigned, do nothing }
    ````end if
    ````while idx < NumSounds``{ play all sounds layered on this key }
    ``````if TKey[idx] = EVENT_NOTE
    ````````play_note(DTKey[idx],EVENT_VELOCITY,0,-1)
    ``````end if
    ``````inc(idx)
    ````end while
    ``else { learn mode active }
    ````EBoxID[learn_idx]->value := EVENT_NOTE``{ update edit box }
    ````key := TKey[learn_idx]```{ remember prior key }
    ````TKey[learn_idx] := EVENT_NOTE``{ update TKey with new key }
    ````call color_key```````````{ color prior key }````
    ````
    key := EVENT_NOTE
    ````call color_key```````````{ color new key }
    ````LBtnID[learn_idx]->value := 0 { cancel Learn btn }
    ````learn_idx := -1``````````{ de-activate learn index }
    ``end if
    end on
    { note callback }
     
  13. Big Bob

    Big Bob Forum Member

    Messages:
    606
    {-------------------------------------------------------------------------
    Support Functions and Macros
    --------------------------------------------------------------------------}

    function Bool(X) -> result```{ 0 if X=0, 1 otherwise }
    ``result := 1+sh_right(abs(X)-1,31)
    end function

    function color_key { key }
    ``declare cx
    ``cx := search(TKey,key)+1``{ cx=0 if key not in TKey }
    ``if cx # 0``{ one or more occurences of key exist }
    ````TKey[cx-1] := -1``````````````{ remove 1st hit }
    ````{ compute cx=1 if no more hits, cx=2 if more }
    ````cx := hit(key) + 2 { cx=1 if no more hits, cx=2 otherwise }
    ````TKey[search(TKey,-1)] := key``{ replace 1st hit }
    ``end if
    ``set_key_color(key,KeyColor[cx]) { none, mono, or poly}
    end function

    function hit(tnote)->result``{ 0 if tnote is in TKey, -1 otherwise }
    ``result := sh_right(search(TKey,tnote),31)
    end function

    function learn_btn_change
    ``if LBtnID[idx]->value # 0``{ btn on }
    ````if learn_idx # -1```{ turn off any prior on btn }
    ``````LBtnID[learn_idx]->value := 0
    ````end if
    ````learn_idx := idx````{ update learn index }
    ``else``{ btn off }
    ````learn_idx := -1`````{ de-activate learn index }
    ``end if
    end
    function

    function learn_edit_change
    ``key := TKey[idx] { old key }
    ``TKey[idx] := EBoxID[idx]->value
    ``call color_key```{ color old key }
    ``key := TKey[idx]
    ``call color_key```{ color new key }
    end function

    macro declare_key_learn(#index#)``{ create assigned key and learn btn combo }
    ``declare ui_value_edit LE#index# (0,127,0)
    ````EBoxID[#index#] := get_ui_id(LE#index#)``{ learn edit box }
    ``declare ui_switch LB#index#
    ````LBtnID[#index#] := get_ui_id(LB#index#)``{ learn btn }
    end macro

    macro declare_line_caption(#index#,caption)``{ not needed if on wallpaper }
    ``declare ui_label CL#index#(1,1)
    ``set_text(CL#index#,caption)
    ``move_control_px(CL#index#,X,Y + dY*(#index#+1))
    ``CL#index#->hide := 1```````````{ transparent }
    ``CL#index#->font_type := 16
    ``CL#index#->text_alignment := 2 { right justified }
    ``CL#index#->width := 65
    end macro

    macro on_learn_btn(#index#)``{ create learn btn handler }
    ``on ui_control(LB#index#)
    ````idx := #index#
    ````call learn_btn_change
    ``end on
    end macro

    macro on_learn_edit(#index#) { create edit box handler }
    ``on ui_control(LE#index#)
    ````idx := #index#
    ````call learn_edit_change
    ``end on
    end macro
     
  14. Mr.Lion

    Mr.Lion NI Product Owner

    Messages:
    159
    Hello Bob!

    So if I change KeyColorMode to for example 5 (blue), the new key will be blue and the original key won't have any colour?

    Best Regards

    Robin
     
  15. Big Bob

    Big Bob Forum Member

    Messages:
    606
    Morning Robin,

    No, KeyColorMode is a switch (either zero or non-zero).

    If you want only the script coloring and want to discard Kontakt's default coloring), you would set KeyColorMode to one (or anything other than zero). Then if you want singly assigned keys to be Blue set MonoKey = 6. Just read the script comments by these constants.

    Rejoice,

    Bob
     
  16. Mr.Lion

    Mr.Lion NI Product Owner

    Messages:
    159
    Hello Bob!

    Yes I got it all wrong haha, didn't read so properly ! Got it all figured out now thank youe!

    Best Regards

    Robin
     
  17. Mr.Lion

    Mr.Lion NI Product Owner

    Messages:
    159
    Hello again Bob!

    I'm trying to figure out how to change the placement for certain elements of the function.

    I've managed to figure out how to add more than just 3 but I would like to now how I can change the placement for only Rimshot and have the others stay were they are.

    Best Regards
    Robin
     
  18. Big Bob

    Big Bob Forum Member

    Messages:
    606
    HI Robin,

    Your question is not clear.

    By placement are you talking about the xy coordinates of the Rimshot button? Or, are you talking about re-labeling the buttons or re-assigning the drum sounds associated with each button or what?

    Perhaps you should give me the list of buttons from top to bottom along with the captions you want for them and the MIDI notes that they respond to by default. Then, I can illustrate what you would need to do to the code to accomplish that.

    Rejoice,

    Bob

    BTW I'm about to quit for the day but, I'll check back after breakfast tomorrow.
     
  19. Mr.Lion

    Mr.Lion NI Product Owner

    Messages:
    159
    Hello Bob!

    I'm sorry that I was unclear!

    The thing i meant is to change the Row Spacing but not change the row spacing between all but for example like this:

    [​IMG]

    Hope that clears it out for you!
    The rest of the functions are fenomenal, i just want to now how to change the spacing between certain parts insted of between every button etc!

    Best of Regards
    Robin
     
  20. Big Bob

    Big Bob Forum Member

    Messages:
    606
    Good Morning Robin,

    The simplest and most general way to do that will require a minor design change. Instead of using the fixed constant dY in the initialization for-loop, declare an array for dY filled with the custom Y coordinates you require.

    For example, your screenshot above looks like you have retained dY=20 between DS0 and DS1 and between DS2, DS3, and DS4 while you have perhaps a dY=130 between DS1 and DS2. The idea would be to create a dY array like this:
    Code:
    declare dY[NumSounds] := (20,40,170,190,210)
    Then, in the init for-loop, the code lines such as:
    Code:
    EBoxID[idx]->pos_y := Y + dY*(idx+1)
    would be changed to something like:
    Code:
    EBoxID[idx]->pos_y := Y + dY[idx]
    If this isn't clear, let me know and I can post an example for your specific situation if you give me the Y values you want for each button.

    Rejoice,

    Bob
     
    Last edited: May 11, 2015