Builtin procedures#

class bmusic.proc.Intensity(**kwargs)#

Bases: ForEachProc

Base intensity procedure.

Parameters:

  • animkey: Animation key with the following keys:
    • basis: Resting (intensity 0) position.

    • on: Playing (intensity max) position.

    • Type: AnimKey

  • max_intensity (inherited)

  • midi (inherited)

  • min_intensity (inherited)

class bmusic.proc.IntensityOnOff(**kwargs)#

Bases: Intensity

Turns on when a note starts and off when it ends.

Keyframe types:
  • JITTER: Resting (intensity = 0).

  • BREAKDOWN: Playing.

Parameters:

  • duration: Time, in seconds, to spend interpolating between states.

    • Type: float

    • Default: 0.05

  • vector_handles: Whether to use vector handles (no easing in or out).

    • Type: bool

    • Default: False

  • animkey (inherited)

  • max_intensity (inherited)

  • midi (inherited)

  • min_intensity (inherited)

animate()#

Do all animation.

class bmusic.proc.IntensityFade(**kwargs)#

Bases: Intensity

Turns on when a note starts and fades away.

Keyframe types:
  • JITTER: Resting (intensity = 0).

  • BREAKDOWN: Fading.

  • EXTREME: Max intensity.

Parameters:

  • fade_func: Function that curves linear time to fade intensity. Takes parameters (t,) (time in seconds since note start) and returns between 0 and 1, where 0 is off and 1 is max intensity. There are a few predefined functions bmusic.utils

    • Type: Callable

    • Default: <staticmethod(<function IntensityFade._default_fade_func at 0x7f68e9d49f80>)>

  • key_interval: Interval in seconds for decay keyframes. Avoids unneccessary keyframing on every frame.

    • Type: float

    • Default: 0.3

  • max_len: Maximum length of note, in seconds. Keyframing will stop after this time, even if the note is still playing.

    • Type: float

    • Default: 60

  • note_end: Whether to cut intensity to 0 at end of note. If false, the note will keep fading until next play, even if the note was released.

    • Type: bool

    • Default: True

  • off_thres: Threshold for intensity to be considered off. Keyframing will stop at this point. If using a custom fade_func that is NOT monotonically decreasing, set this to 0 (or negative).

    • Type: float

    • Default: 0.001

  • start_time: Time, in seconds, from off to initial on.

    • Type: float

    • Default: 0.05

  • animkey (inherited)

  • max_intensity (inherited)

  • midi (inherited)

  • min_intensity (inherited)

animate()#

Do all animation.

class bmusic.proc.Hammer(**kwargs)#

Bases: ForEachProc

Hammer movement: Resting, preparing, hitting, recoil, wobbling.

Keyframe types:
  • JITTER: Resting.

  • BREAKDOWN: Preparing to hit.

  • EXTREME: Hitting.

  • KEYFRAME: Recoil and oscillating.

Parameters:

  • animkey: Animation key:
    • hit: Hitting.

    • prepare: Preparing to hit.

    • recoil: Bounce back after hit.

    • Type: AnimKey

  • hit_time: Duration (sec) of prepare to hit movement.

    • Type: float

    • Default: 0.08

  • osc_count: Number of oscillations to perform.

    • Type: int

    • Default: 4

  • osc_decay: Factor by which oscillation intensity decays each time.

    • Type: float

    • Default: 0.5

  • osc_period: Duration (sec) of each oscillation after hit.

    • Type: float

    • Default: 0.35

  • prepare_time: Duration (sec) of rest to prepare.

    • Type: float

    • Default: 0.15

  • recoil_time: Duration (sec) of hit to recoil movement.

    • Type: float

    • Default: 0.13

  • max_intensity (inherited)

  • midi (inherited)

  • min_intensity (inherited)

animate()#

Do all animation.

class bmusic.proc.Scheduling(**kwargs)#

Bases: MusicProc

Schedule limited number of agents (e.g. hammers) to switch between more notes to play.

This procedure only moves the agents, but does not play the notes. You may want to combine it with something else e.g. Hammer.

This is the base class; subclasses define the particular scheduling algorithm. Override the schedule method to implement an algorithm.

Parameters:

  • animkeys: List of animation keys, each corresponding to an agent. Naturally, len(animkeys) is how many agents are available. Keys:

    • note0, note1, note2, …: Move to note index i. i.e. Message(note=24, ...) corresponds to key note24.

    • Type: list

  • cost_func: Function to get cost between two notes. Costs are additive, and path of least cost is chosen. Args:

    (self, i, j). i and j are notes (e.g. 21 = lowest A on piano).

    • Type: Callable

    • Default: <staticmethod(<function Scheduling._default_cost_func at 0x7f68e9d4a2a0>)>

  • idle_time: Time (sec) of pause when playing a message before available to move to next message.

    • Type: float

    • Default: 0.1

  • stay_to_end: If true, hold an agent to a message until it ends. Else, agent can move as soon as it plays (i.e. when idle_time elapses).

    • Type: bool

    • Default: False

  • midi (inherited)

animate() list[MessageList]#

Animates movement of each agent to their messages. Returns which messages were scheduled to each agent.

Returns:

A list of :class:`bmusic.MessageList`s, each corresponding to which messages the agent was scheduled to play.

compute_cost(msg1: Message, msg2: Message) float#

Compute cost of playing msg1 and msg2.

msg1.start < msg2.start.

Uses velocity; i.e. cost = velocity = distance / time distance = self.cost_func(...)

schedule() list[MessageList]#

Compute which messages were scheduled to each agent.

class bmusic.proc.GreedyScheduling(**kwargs)#

Bases: Scheduling

Greedy algorithm: Select agent with lowest cost for each message.

Parameters:

  • animkeys (inherited)

  • cost_func (inherited)

  • idle_time (inherited)

  • midi (inherited)

  • stay_to_end (inherited)

schedule()#

Compute which messages were scheduled to each agent.

class bmusic.proc.ChordScheduling(**kwargs)#

Bases: Scheduling

Greedy scheduling operating on chords instead of messages.

Parameters:

  • chord_threshold: Passed to bmusic.midi.split_chords(). Units are seconds.

    • Type: float

    • Default: 0.1

  • animkeys (inherited)

  • cost_func (inherited)

  • idle_time (inherited)

  • midi (inherited)

  • stay_to_end (inherited)

schedule()#

Compute which messages were scheduled to each agent.

class bmusic.proc.ToNote(**kwargs)#

Bases: MusicProc

Transition between notes (i.e. pitches).

Parameters:

  • animkey: Keys:
    • 0, 1, etc.: Key for that note.

    Keys are strings, not ints.

    • Type: AnimKey

  • idle_time: For each message, amount of time (sec) to wait before transitioning to the next message.

    • Type: float

    • Default: 0.1

  • midi (inherited)

animate()#

Do all animation.