Drum Machine that works like an arranger

rankatz97
rankatz97 Member Posts: 1 Newcomer
edited October 2024 in Scripting Workshop

What i have achieved:

-Instrument that triggers drum sample loops that sync to tempo And end at sample end point

What i WANT to achieve:

-I want the drum loop to play Endlessly untill i press the NOTE it was triggered by or by another note (But it will let the sample Finish before going to the next one)

-If it's possible to make some Notes(FILLS) go back to the main loop after finishing one cycle and some notes(MAIN DRUM Varients)keep going after being triggered

What im trying to replicate:

-Arrangers Accompaniment Drums that you can trigger and they go on and if you want for example to trigger a FILL Drum loop you press another button and then it goes back to the main loop.For example KORG PA 700 .

——THANK YOU SO MUCH FOR ANY HELP

I am learning KSP Atm, but i think it will take alot of time,meanwhile i will keep on learning but if anyone can help with this it will be great.

Comments

  • theodorech
    theodorech Member Posts: 72 Member
    edited May 2024

    To stop the loop from playing when you hit the note that started it, you need to ignore the event in the release callback. This way, you won't release the event that triggered the loop. You'll need a flag to check if the loop is triggered, and then use note_off or ignore_event in the note callback to stop the loop. Here's an example:

    on init
    declare $loop_flag
    declare $loop_id
    declare const $loop_key := 36
    end on on note ignore_event($EVENT_ID) if ($EVENT_NOTE=$loop_key and ($loop_flag=0))
    $loop_id := play_note($EVENT_NOTE,$EVENT_VELOCITY,0,0)
    end if if ($EVENT_NOTE=$loop_key and ($loop_flag=1))
    $loop_flag := -1
    fade_out($loop_id,100000,1)
    end if end on on release ignore_event($EVENT_ID) if ($EVENT_NOTE=$loop_key and ($loop_flag=0))
    $loop_flag := 1
    end if if ($EVENT_NOTE=$loop_key and ($loop_flag=-1))
    $loop_flag := 0
    end if end on

    The second part with the fills is a bit trickier. You'll either need to track the timing of the fill to restart the loop after the fill sample plays or use the on listener callback for accurate timing. However, the listener approach can be more complex. A simpler workaround might look like this:

    on note
    
    if ($EVENT_NOTE=$fill_id)
    fade_out($loop_id,100000,1)
    $fill_id := play_note($EVENT_NOTE,$EVENT_VELOCITY,0,0)
    wait($DURATION_QUARTER)
    fade_out($fill_id,10000,1)
    $loop_id := play_note($EVENT_NOTE,$EVENT_VELOCITY,0,0)
    end if
    end on on release ignore_event($EVENT_ID) end on

This discussion has been closed.
Back To Top