# EvilDragon introduces (pt. 3) - Simple keyrange display/coloring



## EvilDragon (Jun 24, 2010)

Yeah I know this is easy. I just made standard keycoloring easier with MIDI learning and color selection, and a neat line/dot keyrange display! Here's how it looks:

http://img194.imageshack.us/img194/9057/keyrange.gif

And the script looks like this. NOTE: this script relies on my constants library available here!


```
import "Constants.txt"

on init
    Constants.OnInit
    declare count
    declare learn_counter
    declare a
    declare last
    declare !char[4]
    !char[0] := "."
    !char[1] := "["
    !char[2] := "]"
    !char[3] := "|"
    declare @t
    
    declare ui_label text (3,1)
    declare ui_value_edit Low (0,127,NOTE)
    declare ui_value_edit High (0,127,NOTE)
    declare ui_button Learn
    declare ui_menu Color
    add_menu_item(Color,"Color",-2)
    add_menu_item(Color,"------------",-1)
    add_menu_item(Color,"None",0)
    add_menu_item(Color,"White",1)
    add_menu_item(Color,"Yellow",2)
    add_menu_item(Color,"Green",3)
    add_menu_item(Color,"Red",4)
    add_menu_item(Color,"Blue",5)
    add_menu_item(Color,"Cyan",6)
    
    move_control(text,1,1)
    move_control(Low,4,1)
    move_control(High,5,1)
    move_control(Learn,6,1)
    move_control(Color,6,2)
    
    set_text(Low,"Low Key")
    set_text(High,"High Key")
    set_text(Learn,"Learn Keyrange")
    
    make_persistent(Low)
    make_persistent(High)
    
    read_persistent_var(Low)
    read_persistent_var(High)
    
    Low := 0
    High := 127
    DisplayRange
    ColorRange
    
    message("")
end on

on ui_control (Low)
    if (Low > High)
        High := Low
    end if

    DisplayRange
    ColorRange
end on

on ui_control (High)
    if (High < Low)
        Low := High
    end if
    
    DisplayRange
    ColorRange
end on

on note
    LearnRange
end on

on ui_control (Learn)  
    if (Learn = 1)
        learn_counter := 0
        set_text(Learn,"Learn Low Key")
    end if
    if (Learn = 0)
        learn_counter := 0
        set_text(Learn,"Learn Keyrange")
        Low := 0
        High := 127
        DisplayRange
        ColorRange
	end if 
end on

on ui_control(Color)
    if (Color < 0)
        Color := last
    end if
    select (Color)
        case 0
            last := 0
        case 1
            last := 1
        case 2
            last := 2
        case 3
            last := 3
        case 4
            last := 4
        case 5
            last := 5
        case 6
            last := 6
    end select
    ColorRange
end on

function LearnRange
    if (Learn = 1)
        if (learn_counter = 0)
            if (Low > High)
                High := Low
            end if
            Low := EVENT_NOTE
            DisplayRange
            set_text(Learn,"Learn High Key")
            inc(learn_counter)
            ignore_event(EVENT_ID)
            set_event_par(EVENT_ID,0,4)
            ColorRange
            exit
        end if
        if (learn_counter = 1)
            High := EVENT_NOTE
            DisplayRange
            learn_counter := 0
            Learn := 0
            set_text(Learn,"Learn Keyrange")
                ignore_event(EVENT_ID)
                set_event_par(EVENT_ID,0,4)
            ColorRange
            if (Low > High)
                a := High
                High := Low
                Low := a
                set_text(Learn,"Range Adapted!")
                ColorRange
                wait(1000000)
                set_text(Learn,"Learn Keyrange")
            end if
            exit
        end if
    end if
end function

function DisplayRange
    count := 0
    @t := ""
    while (count < 128)
        if (count = Low and count = High)
            @t := @t & !char[3]
        else
            if (count = Low)
                if (Low < High)
                    @t := @t & !char[1]
                else
                    @t := @t & !char[2]
                end if
            else
                if (count = High)
                    if (High > Low)
                        @t := @t & !char[2]
                    else
                        @t := @t & !char[1]
                    end if
                else
                    @t := @t & !char[0]
                end if
            end if
        end if
        inc(count)
    end while

    set_text(text,@t)
end function

function ColorRange
    count := 0
    while (count < 128)
        set_key_color(count,NONE)
        inc(count)
    end while
    count := Low
    while (count <= High)
        set_key_color(count,last)
        inc(count)
    end while
end function
```


----------



## TechLo (Jun 24, 2010)

The dot/line display is groovy! What software do you use for screen video capture? I've got to start looking into the best options for putting videos together that combine screen capture, recorded video and voiceover.


----------



## EvilDragon (Jun 24, 2010)

For screen capture: http://www.cockos.com/licecap/

Basic and free! Doesn't record audio though, and supports only 2 formats. But free and works well!

If you wanna pay for something, then Camtasia Studio.


----------



## damstraversaz (Oct 4, 2010)

first sorry for my poor english...
it seems to be a very useful script. as I know nothing about scripting, where must Icopy the constant.txt ? I copy it in the script folder but kontakt does not find it.

a litle suggestion:
it could be amazing to have a velocity fade in-out with this script. for exemple, for creating a woodwind ensemble multi with individual instruments, with soft crossfade between the differents patch... of course I have no idea if it's possible with scripting. it could be amazing for creating sort of orchestral symphobia patch with other library.

thanks a lot for sharing your work !

damien


----------



## EvilDragon (Oct 4, 2010)

You need to have KScript editor to be able to compile this script correctly for Kontakt.

http://nils.se/ksp



Also, I think you've mixed up something. This script is only to DISPLAY a keyrange, not to split different groups to different MIDI notes!


----------



## Hannes_F (Oct 4, 2010)

Cool little thing!


----------



## damstraversaz (Oct 4, 2010)

:oops: sorry , I miss this...thanks a lot for the answer !
damien


----------



## victorv (Dec 23, 2010)

Noooo, is not working in my Kontakt, think I forgot something.I want only the display keyrange, but is not working in my Kontakt, I would use for drums.I went to the KScript but nothing happened. "File does not exist: Constants.txt"(sorry for my poor english)


----------



## EvilDragon (Dec 23, 2010)

Read the first post again 



EvilDragon @ 24.6.2010 said:


> NOTE: this script relies on my constants library available here!


----------

