Пример #1
0
def test_time_signature_generator_run(time_signature_args, note_duration, num_time, last_time_args):
    time_signature = TimeSignature(*time_signature_args)
    time_iterator = list(time_signature.gen(note_duration))

    assert len(time_iterator) == num_time

    assert time_iterator[-1] == TimeContainer(*last_time_args)
Пример #2
0
def test_time_signature_generator_infinite_loop():
    time_signature = TimeSignature(4, 4)
    gen = time_signature.gen(Whole, go_on=True)

    for _ in range(10):
        time_section = next(gen)

    assert time_section == TimeContainer(10, 1, 1)
Пример #3
0
def test_time_signature_generator_stop_iteration():
    time_signature = TimeSignature(4, 4)
    gen = time_signature.gen(Whole)

    # Skip the first time_section which is 1/1
    next(gen)

    with raises(StopIteration):
        next(gen)
Пример #4
0
def test_time_container_start_offset(time_signature_args, tempo, note_duration, note_start_offset):
    time_signature = TimeSignature(*time_signature_args)
    tempo = Tempo(tempo)

    gen = time_signature.gen(note_duration)

    # Skip the first which is equal to 0.0
    next(gen)

    time_section = next(gen)

    assert time_section.start_offset(time_signature, tempo) == note_start_offset
Пример #5
0
def test_grid_part_repr():
    grid_part = GridPart(
        Scale("C", "ionian"),
        Chord("C", "maj7"),
        Whole,
        TimeSignature(4, 4),
        Tempo(60)
    )

    assert repr(grid_part) == "<GridPart : C ionian / Cmaj7 / Whole / 4/4 / 60>"
Пример #6
0
def test_create_grid_with_parts():
    parts = [
        {"scale": Scale("A", "major"), "chord": Chord("A", "maj")},
        {"chord": Chord("C", "min"), "tempo": Tempo(120)},
        {"chord": Chord("E", "maj"), "duration": Half},
        {"chord": Chord("G#", "dim"), "time_signature": TimeSignature(3, 2)}
    ]
    time_signature = TimeSignature(4, 4)
    tempo = Tempo(90)

    grid = Grid(
        time_signature=time_signature,
        tempo=tempo,
        duration=Whole
    )
    grid.set_parts(*parts)

    assert repr(grid) == "<Grid : 4 parts>"

    assert len(grid.parts) == 4

    assert grid.parts[0].tempo == tempo
    assert grid.parts[0].time_signature == time_signature
Пример #7
0
class Grid:
    DEFAULT_TIME_SIGNATURE = TimeSignature(4, 4)
    DEFAULT_TEMPO = Tempo(60)
    DEFAULT_DURATION = Whole

    def __init__(self,
                 time_signature=None,
                 tempo=None,
                 duration=None,
                 parts=None,
                 **kwargs):
        self.default_time_signature = time_signature or self.DEFAULT_TIME_SIGNATURE
        self.default_tempo = tempo or self.DEFAULT_TEMPO
        self.default_duration = duration or self.DEFAULT_DURATION

        self.parts = []
        if parts:
            self.set_parts(*parts)

    def set_parts(self, *parts):
        self.parts = []

        last_part = None
        for part in parts:
            if last_part:
                last_part = copy(last_part.to_dict())
                last_part.pop("duration", None)

                part = {**last_part, **part}

            part.setdefault("time_signature", self.default_time_signature)
            part.setdefault("tempo", self.default_tempo)

            grid_part = GridPart(**part)
            self.parts.append(grid_part)

            last_part = grid_part

    def __repr__(self):
        return str(self)

    def __str__(self):
        return f"<Grid : {len(self.parts)} parts>"
Пример #8
0
def validate_time_signature(string, loc, expr):
    TimeSignature(*expr)
Пример #9
0
from beethoven.common.tuning import Tuning
from beethoven.models import GridPart
from beethoven.players.drum import Drum
from beethoven.players.piano import Piano
from beethoven.sequencer.jam_room import JamRoom
from beethoven.sequencer.note_duration import Whole
from beethoven.sequencer.tempo import Tempo
from beethoven.sequencer.time_signature import TimeSignature
from beethoven.theory.scale import Scale

DEFAULT_CONFIG = {
    "scale": Scale("C", "major"),
    "duration": Whole,
    "tempo": Tempo(60),
    "time_signature": TimeSignature(4, 4)
}

DEFAULT_PROMPT_CONFIG = {"strict": True}


class State:
    def __init__(self, prompt_config=None):
        self.jam_room = JamRoom()

        self.grid_parts = {gp.name: gp for gp in GridPart.list()}

        self.jam_room.players.add(Piano())
        self.jam_room.players.add(Drum())

        self.config = DEFAULT_CONFIG
Пример #10
0
        scale_updated = True

    if tonic_name := parsed_config.get("note"):
        tonic_note = Note(tonic_name)
        scale_updated = True

    if scale_updated and scale_name and tonic_note:
        parsed["scale"] = Scale(tonic_note, scale_name)
    elif not current_scale:
        return parsed

    if progression := parsed_config.get("progression"):
        parsed["progression"] = progression

    if time_signature := parsed_config.get("time_signature"):
        parsed["time_signature"] = TimeSignature(*time_signature)

    if tempo := parsed_config.get("tempo"):
        parsed["tempo"] = Tempo(tempo)

    return parsed


def process_chord_config(parsed_config, current_scale=None):
    parsed = {}

    # GET CHORD DURATION
    if duration := parsed_config.get("duration"):
        chord_duration = {
            "W": Whole,
            "H": Half,
Пример #11
0
def test_time_signature_duration(args, tempo, duration):
    time_signature = TimeSignature(*args)
    tempo = Tempo(tempo)

    assert time_signature.duration(tempo) == duration
Пример #12
0
def test_time_signature_instanciation(args, display):
    time_signature = TimeSignature(*args)

    assert repr(time_signature) == f"<Time Signature : {display}>"
Пример #13
0
def test_time_signature_copy():
    time_signature = TimeSignature(3, 4)

    assert time_signature == time_signature.copy()
Пример #14
0
def test_time_signature_generator_with_note_range():
    time_signature = TimeSignature(4, 8)
    time_iterator = list(time_signature.gen(Quarter, Whole))

    assert time_iterator[-1] == TimeContainer(2, 3, 1)
Пример #15
0
     "chord": Chord("B", "maj7"),
     "scale": Scale("B", "aeolian")
 }]),
 ("n=A sc=major t=60 p=I;t=90 p=I", [{
     "chord": Chord("A", "maj7"),
     "scale": Scale("A", "ionian"),
     "tempo": Tempo(60),
 }, {
     "chord": Chord("A", "maj7"),
     "tempo": Tempo(90)
 }]),
 ("n=A sc=major ts=3/2 p=I;ts=7/8 p=I",
  [{
      "chord": Chord("A", "maj7"),
      "scale": Scale("A", "ionian"),
      "time_signature": TimeSignature(3, 2),
  }, {
      "chord": Chord("A", "maj7"),
      "time_signature": TimeSignature(7, 8)
  }]),
 ("n=A sc=major p=I:d=H,I:d=2Q,I", [{
     "chord": Chord("A", "maj7"),
     "scale": Scale("A", "ionian"),
     "duration": Half
 }, {
     "chord": Chord("A", "maj7"),
     "duration": Half
 }, {
     "chord": Chord("A", "maj7"),
 }]),
 ("n=C sc=major p=Amaj7:i=1,Bmin7:i=2",