Exemplo n.º 1
0
def test_tempo_comparison():
    assert Tempo(30) == Tempo(30)

    assert Tempo(30) != Tempo(60)

    assert Tempo(30) < Tempo(60)

    assert Tempo(30) <= Tempo(30)

    assert Tempo(30) <= Tempo(60)
Exemplo n.º 2
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>"
Exemplo n.º 3
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
Exemplo n.º 4
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
Exemplo n.º 5
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>"
Exemplo n.º 6
0
def validate_tempo(string, loc, expr):
    Tempo(expr[0])
Exemplo n.º 7
0
def test_note_duration_with_different_tempos(note_duration):
    assert note_duration.duration(bpm=Tempo(50)) != note_duration.duration(
        bpm=Tempo(40))
Exemplo n.º 8
0
from os import environ

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())
Exemplo n.º 9
0
        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,
            "Q": Quarter,
            "E": Eighths,
            "S": Sixteenths,
Exemplo n.º 10
0
def test_tempo_instanciation(tempo_arg):
    tempo = Tempo(tempo_arg)

    assert tempo

    assert repr(tempo) == f"<Tempo : {tempo_arg} bpm>"
Exemplo n.º 11
0
def test_time_signature_duration(args, tempo, duration):
    time_signature = TimeSignature(*args)
    tempo = Tempo(tempo)

    assert time_signature.duration(tempo) == duration
Exemplo n.º 12
0
     "chord": Chord("A", "min7"),
     "scale": Scale("A", "ionian"),
 }, {
     "chord": Chord("C", "min7")
 }]),
 ("n=A sc=major p=I;n=B sc=minor p=I", [{
     "chord": Chord("A", "maj7"),
     "scale": Scale("A", "ionian"),
 }, {
     "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"),