-------------------------------------------------------------------------------- --! @title StepModulator --! @brief Per-Voice Step Modulation Through a Script Event Modulation Source --! @category VoiceEffects --! --! Turns the script into a polyphonic, tempo-synced step modulator. Each note --! walks an 8-step pattern of its own and sends the values to a Script Event --! Modulation source with sendScriptModulation, so every voice can open its own --! filter (or move any other modulatable parameter) independently. A second --! source receives the mod wheel in broadcast mode, with float precision and a --! linear ramp instead of 7-bit steps. --! --! Setup in Falcon: in the keygroup's modulation list add two "Script Event --! Modulation" sources. Set the first one's Event Id to 0, turn its Bipolar --! switch off (the pattern is in [0;1]) and connect it to, say, the filter --! cutoff. Set the second one's Event Id to 1, turn Bipolar off too, and connect --! it to whatever the mod wheel should drive. --! --! @demonstrates sendScriptModulation, waitBeat, beat2ms, getCC, isNoteHeld, Table -------------------------------------------------------------------------------- -- Event Ids of the two sources; they must match the "Event Id" set on each source. local STEP_SOURCE = 0 local WHEEL_SOURCE = 1 local NUM_STEPS = 8 local RATE_NAMES = {"1/8", "1/16", "1/32"} local RATE_BEATS = {0.5, 0.25, 0.125} local steps = Table("Steps", NUM_STEPS, 0.5, 0, 1) steps.bounds = {10, 10, 400, 100} local rate = Menu{"Rate", RATE_NAMES, selected = 2} rate.bounds = {430, 10, 100, 40} -- Fraction of each step spent ramping to the next value: 0 gives hard steps, -- 1 a continuous line through the pattern. local glide = Knob{"Glide", 0.2, 0, 1, unit = Unit.PercentNormalized} glide.bounds = {430, 60, 100, 50} function onNote(e) local id = postEvent(e) -- A broadcast only reaches the voices that are playing when it is sent: a new -- voice starts from the source's initial value. Seed it with the wheel's -- current position so it does not jump when the wheel next moves. sendScriptModulation(WHEEL_SOURCE, getCC(1) / 127, 0, id) -- Start on the first step at once; a ramp here would sweep the attack. local step = 1 sendScriptModulation(STEP_SOURCE, steps:getValue(step), 0, id) -- The pattern runs from each note's own start rather than from the bar, so -- chords played late still begin on step 1. The voice keeps the last value -- through its release. while isNoteHeld() do local stepBeats = RATE_BEATS[rate.value] waitBeat(stepBeats) if not isNoteHeld() then break end step = step % NUM_STEPS + 1 -- The ramp is expressed in ms, so convert the glide share of a step at -- the current tempo. local ramp = beat2ms(stepBeats) * glide.value sendScriptModulation(STEP_SOURCE, steps:getValue(step), ramp, id) end end function onController(e) if e.controller == 1 then -- No voice id: broadcast to every sounding voice. A 30 ms ramp smooths -- the 7-bit steps of the wheel into a continuous sweep. sendScriptModulation(WHEEL_SOURCE, e.value / 127, 30) end postEvent(e) -- keep the CC flowing so MIDI learn and CC modulations still work end setSize(550, 120) makePerformanceView()