Indispensability

Example script (scamp_extensions): examples/Composition & form/Algorithmic approaches/indispensibility_example.py

Download: indispensibility_example.py

Requires the scamp_extensions package (pip install scamp_extensions).

Mouse position controls a rhythmic texture based on Barlow’s beat indispensability (barlicity extension).

Topics: Interactivity & visualization › Mouse input, Composition & form › Algorithmic approaches

from scamp import *
from scamp_extensions.composers.barlicity import *
import random


threshold = 0
syncopation_chance = 0


def mouse_move(x, y):
    global threshold, syncopation_chance
    syncopation_chance = x
    threshold = y


s = Session()

s.register_mouse_listener(on_move=mouse_move, relative_coordinates=True)

drum = s.new_part("taiko", (0, 116), num_channels=150)
violin = s.new_part("violin")

indispensibilities = get_indispensability_array(((2, 3), 2, 3, (2, 3), (2, 3, 2), (3, 2, 3, 3)), True)  # (5, 7), (7, 11)

handle = None
pitch = None

while True:
    for indispensibility in indispensibilities:
        if indispensibility > 0.9:
            if handle is None:
                pitch = 65 + (1 - threshold) * 25
                handle = violin.start_note(pitch, 0.8)
            elif random.random() < 0.6:
                handle.end()
                handle = None
        elif handle is not None:
            handle.change_pitch(pitch + (1 - indispensibility) * random.uniform(-syncopation_chance * 15, syncopation_chance * 15), 0.15)

        if random.random() < syncopation_chance:
            indispensibility = 1 - indispensibility
        if indispensibility > threshold:
            drum.play_note(40 + int(80 * (1 - indispensibility)),
                           0.5 + 0.5 * (indispensibility - threshold) / (1 - threshold), 0.1)
        else:
            wait(0.1)