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

Please help "microtuning"

Discussion in 'Scripting Workshop' started by demahom, Mar 1, 2016.

  1. demahom

    demahom New Member

    Messages:
    8
    I want to turn "1" to "2", Look at the picture , note that the script for "1" is :
     

    Attached Files:

    Last edited: Mar 18, 2016
  2. Lindon

    Lindon NI Product Owner

    Messages:
    322
    First use the <code> tags in posts so we can see it formatted properly.

    OK you want to replace the table with a set of buttons right?

    So first declare a set of 12 buttons in the init
    work out what x,y position you want - and set that
    then assign a 6-image stacked png to the picture attribute in each button

    then remove the table.

    Once you have it laid out properly maybe repost your code and we can help with the on ui_contriol() for each button.
     
  3. demahom

    demahom New Member

    Messages:
    8
    How can I replace the table with a set of buttons ?
     
  4. Lindon

    Lindon NI Product Owner

    Messages:
    322
    Post the code you want to change, then and only then we can help you.
     
  5. demahom

    demahom New Member

    Messages:
    8
    the "code" is up , thanks.
     
  6. Lindon

    Lindon NI Product Owner

    Messages:
    322
    OK so...

    There's a ui_table object:
    Code:
    declare ui_table %tune_ui[12](4,5,-$TUNE_RANGE)
    you want to replace this with a set of buttons.

    first the table object is handling detuning, and you can move any one of the sliders in the table up to a value of 50 or down to value of -50, OR ANYWHERE INBETWEEN

    So a button has two states on and off, so what value do you want to set when the button is on? 50? something else?
     
  7. demahom

    demahom New Member

    Messages:
    8
    I want to set when the button is on, at -50 ,exactly lake this :
     

    Attached Files:

  8. Lindon

    Lindon NI Product Owner

    Messages:
    322
    Ok...

    lets look at the code:

    You will see that the table is used in the note on call back , to look up what value to use for the tuning for each note:
    Code:
    if ($ECO_MODE = 1)
            $helper_tune := (%tune_ui[($EVENT_NOTE + 12 - $key_knob) mod 12]*1000*$Amount)/100
            change_tune($EVENT_ID,$helper_tune,0)
        else
            while($NOTE_HELD= 1)
                $helper_tune := (%tune_ui[($EVENT_NOTE + 12 - $key_knob) mod 12]*1000*$Amount)/100
                change_tune($EVENT_ID,$helper_tune,0)
                wait(15000)
            end while
        end if
    So you will need to keep the array, so set it up as a standard array not a table, in the INIT section replace:

    Code:
    declare ui_table %tune_ui[12](4,5,-$TUNE_RANGE)
        make_persistent (%tune_ui)
        set_control_help (%tune_ui,"Tuning Table: Adjust the detuning for each of the twelve notes.") 
    with:
    Code:
     declare %tune_ui
    make_persistent (%tune_ui)
    
    So now all you need to do is declare 12 buttons, and in the UI call back for each button assign a value into %tune_ui
    Here's the first button as an example:

    in the INIT call back:
    Code:
    
    declare ui_button $myButton1
      set_control_par(get_ui_id($myButton1),$CONTROL_PAR_POS_X,1)
      set_control_par(get_ui_id($myButton1),$CONTROL_PAR_POS_Y,1)
      set_control_par(get_ui_id($myButton1),$CONTROL_PAR_HEIGHT,30)
      set_control_par(get_ui_id($myButton1),$CONTROL_PAR_WIDTH,30)
      set_control_par_str(get_ui_id($myButton1),$CONTROL_PAR_TEXT,"")
      set_control_par_str(get_ui_id($myButton1),$CONTROL_PAR_HELP,"help text here")
      set_control_par_str(get_ui_id($myButton1),$CONTROL_PAR_PICTURE,"Button picture")
      make_persistent($myButton1)
    
    you will need to work out where you want to put the buttons ( the x and y values ) and create a 6_image stacked picture for the buttons and save it in the pictures folder, and then modify the height and width to match the picture size + 2, so if your picture is 298 x 28 you assign the height and width to 30 x 30 as above.

    in the UI call back for each button:

    Code:
    on ui_control($myButton1)
      %tune_ui[0] := -50 * $myButton1
    end on
    
    where [0] increments by one for each button you create up to 12 buttons.

    If you dont know how to create the button pictures theres lots of threads here about that.
     
  9. demahom

    demahom New Member

    Messages:
    8
    I applied what you said, but in vain.,downright wrong to me
    As I said earlier, I am a novice in this area.
    if possible to write me an example of script Or that are reforming their script, which recently sent.
    Thank you for your tolerance me ..

    I found this stuff somewhere:
    ________________________________
    on init
    declare const $num_jaja := 3
    declare ui_switch $o
    declare %jaja_id[$num_jaja]
    %jaja_id[2] := get_ui_id($o)
    set_control_par_str (%jaja_id[2],$CONTROL_PAR_PICTURE,"pv_synth_button_small")
    end on
    __________________________________
    how to duplicate that trick 12 times ,and set -50 when the button is on
     
  10. Lindon

    Lindon NI Product Owner

    Messages:
    322
    I gave you a number of example scripts already. If this isnt sufficient then you have these alternatives:
    1. Learn to write KSP
    - Read the KSP Manual
    - read Nils on line tutorials for an introduction
    - buy the KSP programming book
    - Take one of the on line video courses (like Dave Healeys)
    2. Pay someone to write it for you.
     
  11. demahom

    demahom New Member

    Messages:
    8
    Thank you, I will work these tips:
     
  12. alswefi

    alswefi NI Product Owner

    Messages:
    51
    that exactly what u need.
    Code:
        on init
            make_perfview
            message("")
        
    set_ui_height_px(345)
    
    
           declare $i
           declare %black[5] := (1,3,6,8,10)
    
           declare ui_switch $C
           declare ui_switch $Db
           declare ui_switch $D
           declare ui_switch $Eb
           declare ui_switch $E
           declare ui_switch $F
           declare ui_switch $Gb
           declare ui_switch $G
           declare ui_switch $Ab
           declare ui_switch $A
           declare ui_switch $Bb
           declare ui_switch $B
    
           $i := 0
           while ($i < 12)
              if (search(%black,$i mod 12) # -1)
                 if ($i > 5)
                    set_control_par(get_ui_id($C) + $i,$CONTROL_PAR_POS_X,260 + (10 * $i))
                 else
                    set_control_par(get_ui_id($C) + $i,$CONTROL_PAR_POS_X,250 + (10 * $i))
                 end if
                 set_control_par(get_ui_id($C) + $i,$CONTROL_PAR_POS_Y,280)
              else
                 if ($i > 4)
                    set_control_par(get_ui_id($C) + $i,$CONTROL_PAR_POS_X,260 + (10 * $i))
                 else
                    set_control_par(get_ui_id($C) + $i,$CONTROL_PAR_POS_X,250 + (10 * $i))
                 end if
                 set_control_par(get_ui_id($C) + $i,$CONTROL_PAR_POS_Y,295)
              end if
              set_control_par(get_ui_id($C) + $i,$CONTROL_PAR_WIDTH,12)
              set_control_par(get_ui_id($C) + $i,$CONTROL_PAR_TEXT_ALIGNMENT,1)
              inc($i)
           end while
           make_persistent($C)
           make_persistent($Db)
           make_persistent($D)
           make_persistent($Eb)
           make_persistent($E)
           make_persistent($F)
           make_persistent($Gb)
           make_persistent($G)
           make_persistent($Ab)
           make_persistent($A)
           make_persistent($Bb)
           make_persistent($B)
    
           declare ui_knob $DETUNE (-100,0,1)
           $DETUNE := -50
    
           _read_persistent_var($DETUNE)
           set_control_help($DETUNE,"This knob controls tune amount in cents -50 +0") 
           set_text ($DETUNE, "  Cents")
           set_knob_defval($DETUNE,-50) 
           set_control_par(get_ui_id($DETUNE),$CONTROL_PAR_POS_X,270)
           set_control_par(get_ui_id($DETUNE),$CONTROL_PAR_POS_Y,240)
           make_persistent($DETUNE)
    
         
        end on
    
    
        on note
           if (get_control_par(get_ui_id($C) + $EVENT_NOTE mod 12,$CONTROL_PAR_VALUE) = 1)
              change_tune($EVENT_ID,$DETUNE * 1000,0)
           end if
        end on
    
     
  13. demahom

    demahom New Member

    Messages:
    8
    I found this script in "findasound"
    Thanks to you too :alswefi