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

Solved Show generated notes in label

Discussion in 'Scripting Workshop' started by moosmahna, Oct 12, 2021.

  1. moosmahna

    moosmahna NI Product Owner

    Messages:
    23
    Hy,
    I am working on a simple harmonizer script. It works well, but I need your help please.
    Is it possible to show the generated notes in a label? But not the number of the Midi notes. I need the notes like C3, D#5, Ab4 and so on.

    Code:
    on note
    ignore_event($EVENT_ID)
    play_note($EVENT_NOTE + 0, $EVENT_VELOCITY, 0, -1)
    play_note($EVENT_NOTE + 1, $EVENT_VELOCITY, 0, -1)
    play_note($EVENT_NOTE + 2, $EVENT_VELOCITY, 0, -1)
    play_note($EVENT_NOTE + 3,$EVENT_VELOCITY, 0, -1)
    end on
    If I press C3, than the label should display: C3 - C#3 - D3 - D#3

    Thanks a lot
    Kind Regards
     
  2. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Yes, you should generate a string array with note names, then use that to print out the note names. Some factory scripts show you how (for example Performance>Constrain To Scale).
     
  3. moosmahna

    moosmahna NI Product Owner

    Messages:
    23
    Ok, thanks.
    I tried it and it works. But it only works on the note i press. How can I get the second note in the second label?
    Thanks again!

    Code:
    on init
    
    declare ui_label $label_1 (1,1)
    declare ui_label $label_2 (2,1)
    
    declare $count
    
    declare !note [12]
    !note[0] := "C"
    !note[1] := "C#"
    !note[2] := "D"
    !note[3] := "D#"
    !note[4] := "E"
    !note[5] := "F"
    !note[6] := "F#"
    !note[7] := "G"
    !note[8] := "G#"
    !note[9] := "A"
    !note[10] := "Bb"
    !note[11] := "B"
    
    
    declare !name[128]
    while ($count <128)
        !name[$count] :=!note[$count mod 12] & (($count/12)-2)
    inc ($count)
    end while
    end on
    
    on note
    play_note($EVENT_NOTE + 0, $EVENT_VELOCITY, 0 ,1)
    play_note($EVENT_NOTE + 3, $EVENT_VELOCITY ,0 ,1)
    set_text ($label_1,!name[$EVENT_NOTE])
    set_text ($label_2,!name[$EVENT_NOTE])
    end on
     
  4. moosmahna

    moosmahna NI Product Owner

    Messages:
    23
    Code:
    on note
    play_note($EVENT_NOTE + 0, $EVENT_VELOCITY, 0 ,1)
    play_note($EVENT_NOTE + 3, $EVENT_VELOCITY ,0 ,1)
    set_text ($label_1,!name[$EVENT_NOTE])
    set_text ($label_2,!name[$EVENT_NOTE+3])
    end on
    This works, but I have to do it manual if I change something on the intervals....
     
  5. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Use & to concatenate multiple texts into a single string.
     
  6. JForester

    JForester NI Product Owner

    Messages:
    68
    Code:
    on init
    set_key_pressed_support(1)
    
    declare ui_label $label_1 (1,1)
    set_control_par_str(get_ui_id($label_1), $CONTROL_PAR_TEXT, "")
    set_control_par(get_ui_id($label_1), $CONTROL_PAR_WIDTH, 150)
    
    declare $count
    declare $a
    declare $b
    declare !note [12]
            !note[0] := "C"
            !note[1] := "C#"
            !note[2] := "D"
            !note[3] := "D#"
            !note[4] := "E"
            !note[5] := "F"
            !note[6] := "F#"
            !note[7] := "G"
            !note[8] := "G#"
            !note[9] := "A"
            !note[10] := "Bb"
            !note[11] := "B"
            make_perfview
    
    declare !name[128]
        while ($count <128)
                !name[$count] :=!note[$count mod 12] & (($count/12)-2)
            inc ($count)
        end while
    end on
    
    on note
            $a := $EVENT_NOTE
            $b := $a +3
            play_note($a , $EVENT_VELOCITY, 0 ,-1)
            play_note($b, $EVENT_VELOCITY, 0 ,-1)
            set_key_pressed($a,1)
            set_key_pressed($b,1)
            set_text ($label_1,"Notes played: " & !name[$a] & "   " & !name[$a+3])
    
    end on
    on release
            set_key_pressed($a,0)
            set_key_pressed($b,0)       
    end on