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

Step Sequencer

Discussion in 'Scripting Workshop' started by Carlos Butler, Sep 24, 2018.

  1. Carlos Butler

    Carlos Butler New Member

    Messages:
    8
    Hi, I'm trying to control the volume of an instrument with a step sequencer, but I get an error at line 9, can someone tell me what the problem is?
    Code:
    on init
    declare polyphonic $counter
    declare ui_menu $length
    declare ui_knob $numSteps(1,16,1)
    $numSteps := 16
    make_persistent($numSteps)
    declare ui_table %steps[16](4,4,127)
    end on
    
    on note(%steps)
    ignore_event($EVENT_ID)
    while($NOTE_HELD = 1)
    play_note($EVENT_NOTE,%steps[$counter],0,1)
    $counter := $counter + 1
    if($counter >= $numSteps) $counter := 0
    end if
    end while
    set_engine_par($ENGINE_PAR_VOLUME,%steps[$counter],-1,-1,-1)
    end on
     
  2. Lovechld2000

    Lovechld2000 NI Product Owner

    Messages:
    267
    your on note call back can't have a parameter
    you can't say
    on note ( do something)
    end on

    all ni callbacks have to be like
    on init
    end on

    on note
    end on

    etc
     
  3. Carlos Butler

    Carlos Butler New Member

    Messages:
    8
    Got it, thanks.
    I fixed the error, but the script still doesn't work.
    Any idea why?
     
  4. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    You're playing VERY short notes because your last play_note() argument is set to 1 microsecond :)
     
  5. Carlos Butler

    Carlos Butler New Member

    Messages:
    8
    Thanks, I didn't know that.
    My goal though is to control a parameter with the step sequencer, not playing notes with it.
    I put set_engine_par inside the while loop and got the volume to move to zero when I play a note, but it stops there.
    Any idea why it doesn't keep going?

    Code:
    on init
    declare polyphonic $counter
    declare ui_menu $length
    declare ui_knob $numSteps(1,16,1)
    $numSteps := 16
    make_persistent($numSteps)
    declare ui_table %steps[16](4,4,127)
    end on
    
    on note
    ignore_event($EVENT_ID)
    while($NOTE_HELD = 1)
    play_note($EVENT_NOTE,%steps[$counter],0,1000000)
    $counter := $counter + 1
    set_engine_par($ENGINE_PAR_VOLUME,%steps[$counter],-1,-1,-1)
    if($counter >= $numSteps) $counter := 0
    end if
    end while
    
    end on
     
  6. Lovechld2000

    Lovechld2000 NI Product Owner

    Messages:
    267
    not quite sure what you're up to here Carlos, but I can tell you that you shouldn't confuse velocity volume with engine par volume.
    engine par volume is an instruction to adjust an amplifier somewhere and in your case where you said -1,-1,-1), that is the master volume on the interface, whereas the velocity volume in play_note is an instruction to play a zone on a map at an agreed place. This has no effect on volume unless you set up the internal modulator to apply volume velocity. Hope this helps
     
  7. Carlos Butler

    Carlos Butler New Member

    Messages:
    8
    I'm just trying to learn how to modulate a parameter with a step sequencer. I chose the master volume because it's easier to test/see it.
    I thought ignore_event would prevent the notes to have the ordinary effect in order to be used to trigger the sequencer. Thanks for the help.
     
  8. Lovechld2000

    Lovechld2000 NI Product Owner

    Messages:
    267
    ok cool, well the table is only a possible front end for a step sequencer. A step sequencer is probably a few thousand lines of code, you can study one in the kontakt ksp templates.
     
  9. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Not really, the step sequencer is pretty simple. The main mistake here is that there's no a wait() command. This should work:

    Code:
    on init
        declare $counter
        declare ui_knob $numSteps (1,16,1)
        $numSteps := 16
        make_persistent($numSteps)
        declare ui_table %steps[16] (4,4,127)
        make_persistent(%steps)
    end on
    
    on note
        while($NOTE_HELD = 1)
            set_engine_par($ENGINE_PAR_VOLUME, %steps[$counter], -1, -1, -1)
            $counter := ($counter + 1) mod $numSteps
            wait($DURATION_SIXTEENTH)
        end while
    end on
    Note that this sequencer will stop the moment you release the key, so if you have some release time in your amp envelope, the volume modulation will abruptly stop...

    It would be better to do this with listener callback.
     
  10. Carlos Butler

    Carlos Butler New Member

    Messages:
    8
    Thanks for the code, but still doesn't work. You mean replacing on note for on listener?