Subsystem

subsequence.forms

The API reference for Section and Form.

Section

class Section(
    name: str,
    bars: int,
    energy: float = 0.5,
    key: typing.Optional[str] = None,
    scale: typing.Optional[str] = None,
)

One section of a form — the payload home.

Attributes

Members: bars, energy, key, name, scale

Section.name

Section.name: str

Section.bars

Section.bars: int

Section.energy

Section.energy: float = 0.5

Section.key

Section.key: typing.Optional[str] = None

Section.scale

Section.scale: typing.Optional[str] = None

Form

class Form(
    sections: typing.Iterable[typing.Any],
    key: typing.Optional[str] = None,
    scale: typing.Optional[str] = None,
)

A frozen sequence of Sections — the editable, bindable form value.

List-friendly: the constructor coerces ("name", bars) tuples, so Form([("verse", 8), ("chorus", 8)]) and Form([Section("verse", 8), Section("chorus", 8)]) are the same value. Repetition is Python list arithmetic before construction.

A form may carry its own key/scale — the form tier of the key-source chain (Section.key overrides it; it overrides the composition key). A whole AABA in one key with one section borrowing another is Form([...], key="A") plus a Section(..., key="F").

Coerce any iterable of Sections / (name, bars) tuples.

Members: bars, describe, insert, key, replace, scale, sections, with_energy

Form.sections

Form.sections: typing.Tuple[Section, ...]

Form.key

Form.key: typing.Optional[str] = None

Form.scale

Form.scale: typing.Optional[str] = None

Form.bars

property Form.bars: int

Total length in bars.

Form.replace

Form.replace(
    slot: int,
    section: typing.Optional[Section] = None,
    **changes: typing.Any,
) -> Form

Replace the section at a 1-based slot — whole, or by field.

form.replace(3, bars=16) stretches slot 3; form.replace(3, Section("drop", 16, energy=1.0)) swaps it out.

Form.insert

Form.insert(slot: int, section: typing.Any) -> Form

Insert a section at a 1-based slot (existing sections shift right).

slot may be len(form) + 1 to append.

Form.with_energy

Form.with_energy(energies: typing.Dict[str, float]) -> Form

Set the energy payload on named sections — {"chorus": 0.9}.

Every section whose name appears in the mapping takes the new value; naming a section the form does not contain raises. Energy ramps ((start, end) tuples) live in composition.energy(), not in the payload — a Section carries one number.

Form.describe

Form.describe() -> str

A readable one-section-per-line summary.