Skip to content

Pedals

Implements sustain (SUS, CC 64) and sostenuto (SOS, CC 67) pedal logic for

Import

import "_IVLS/std-library/nodes/voice-logics/pedals.ksp"

Node: Stl.Pedals

Uses: Init, NoteOn, NoteOff, CC

Overview

Implements sustain (SUS, CC 64) and sostenuto (SOS, CC 67) pedal logic for the IVLS voice system. Tracks per-channel, per-note key and pedal state and uses the IVLS runtime API to keep pedal-held notes alive after NoteOff.

Key design points:

- keys.pressed tracks whether the physical key is currently down
- keys.active tracks whether the note is audibly active (key OR pedal held)
- keys.pedal_type records which pedal (SUS or SOS) is currently holding a note
- keys.KeyBuffer is a 2-D list (channel x slot) of active voice references
- On pedal down, a new runtime is created and pedal-held notes are reparented
  into it so they survive NoteOff voice release

- On pedal up, notes are either restored to their original parents, removed
  from KeyBuffer (if the physical key was already released), or transferred
  to a remaining pedal's runtime

API

Nodes

Name Description
node Stl.Pedals Stl.Pedals Manages sustain and sostenuto pedal state across all MIDI channels, e...

Const Blocks

Name Description
const cc CC numbers associated with each pedal type: SUS maps to CC 64, SOS maps to CC 67.
const state Pedal position states: UP (pedal released) and DOWN (pedal depressed).
const type Enumeration of supported pedal types: SUS (sustain) and SOS (sostenuto).

Functions

Name Description
keys.get_pedal_state(midi_ch, type) -> return Returns the current up/down state of the specified pedal on a MIDI channel.
keys.get_pedal_value(midi_ch, type) -> return Returns the raw CC value of the specified pedal on a MIDI channel.
keys.pedal_changed(midi_ch, type) Responds to a pedal state transition for the given MIDI channel and pedal type.
Stl.Pedals.remove_runtime_notes_from_keybuffer(ch, note, runtime) Removes all voices in the given runtime whose note matches from the channel's Ke...
Stl.Pedals.reparent_notes_of_runtime(ch, note, runtime) Reparents all voices in KeyBuffer that match the given note into the specified r...
Stl.Pedals.restore_parents_of_runtime_notes(ch, note, runtime) Restores each voice in the given runtime whose note matches to its original pare...

Nodes

node Stl.Pedals

Callbacks: Init, NoteOn, NoteOff, CC

Stl.Pedals Manages sustain and sostenuto pedal state across all MIDI channels, extending note lifetimes when a pedal is held.


Const Blocks

const cc

CC numbers associated with each pedal type: SUS maps to CC 64, SOS maps to CC 67.


const state

Pedal position states: UP (pedal released) and DOWN (pedal depressed).


const type

Enumeration of supported pedal types: SUS (sustain) and SOS (sostenuto).


Functions

keys.get_pedal_state(midi_ch, type) -> return

Returns the current up/down state of the specified pedal on a MIDI channel.

Parameter Type Description
midi_ch integer MIDI channel index to query
type integer Pedal type index (pedal.type.SUS or pedal.type.SOS)

Returns: return — Current pedal state (pedal.state.UP or pedal.state.DOWN)


keys.get_pedal_value(midi_ch, type) -> return

Returns the raw CC value of the specified pedal on a MIDI channel.

Parameter Type Description
midi_ch integer MIDI channel index to query
type integer Pedal type index (pedal.type.SUS or pedal.type.SOS)

Returns: return — Raw MIDI CC value (0-127) for the pedal


keys.pedal_changed(midi_ch, type)

Responds to a pedal state transition for the given MIDI channel and pedal type.

Parameter Type Description
midi_ch integer MIDI channel on which the pedal changed
type integer Pedal type index (pedal.type.SUS or pedal.type.SOS)

Side effects:

Name Type Purpose
note_i integer Loop variable iterating over all 128 MIDI notes
idx integer Unused index placeholder reserved for future use

Stl.Pedals.remove_runtime_notes_from_keybuffer(ch, note, runtime)

Removes all voices in the given runtime whose note matches from the channel's KeyBuffer.

Parameter Type Description
ch integer MIDI channel whose KeyBuffer entries should be removed
note integer MIDI note number to match against voice note fields
runtime integer Runtime handle whose voice list is traversed

Side effects:

Name Type Purpose
current integer Entry reference to the current node being examined
next integer Entry reference to the next node, captured before potential deletion

Stl.Pedals.reparent_notes_of_runtime(ch, note, runtime)

Reparents all voices in KeyBuffer that match the given note into the specified runtime.

Parameter Type Description
ch integer MIDI channel whose KeyBuffer is searched
note integer MIDI note number to match against voice note fields
runtime integer Runtime handle to reparent matching voices into

Side effects: | Name | Type | Purpose | |------|------|---------| | idx | integer | Loop index iterating over KeyBuffer entries for the channel |


Stl.Pedals.restore_parents_of_runtime_notes(ch, note, runtime)

Restores each voice in the given runtime whose note matches to its original parent.

Parameter Type Description
ch integer MIDI channel (used for context; not directly consumed in traversal)
note integer MIDI note number to match against voice note fields
runtime integer Runtime handle whose voice list is traversed

Side effects:

Name Type Purpose
current integer Entry reference to the current node being examined
next integer Entry reference to the next node, captured before parent restoration

Example

// TODO: Add usage example

See Also