Skip to content
This repository has been archived by the owner on Jun 15, 2024. It is now read-only.

Require accent sound & add 12/4 #200

Merged
merged 1 commit into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backend/src/playbacker/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class _Device(BaseModel):


class _MetronomePaths(BaseModel):
accent: Path
tick_1_4: Path = Field(alias="1/4")
tick_1_8: Path = Field(alias="1/8")
tick_1_16: Path = Field(alias="1/16")
Expand Down Expand Up @@ -104,6 +105,7 @@ def _convert_file_settings(settings: _FileSettings, device_name: str) -> Setting
channel_map=device.channel_map,
sounds=_Sounds(
metronome=MetronomeSounds(
accent=AudioFile(metronome.accent, device.sample_rate),
tick_1_4=AudioFile(metronome.tick_1_4, device.sample_rate),
tick_1_8=AudioFile(metronome.tick_1_8, device.sample_rate),
tick_1_16=AudioFile(metronome.tick_1_16, device.sample_rate),
Expand Down
2 changes: 1 addition & 1 deletion backend/src/playbacker/core/tempo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from pydantic import BaseModel

TimeSignature = Literal["4/4", "6/8"]
TimeSignature = Literal["4/4", "6/8", "12/4"]
Duration = Literal["1/4", "1/8", "1/16"]


Expand Down
8 changes: 8 additions & 0 deletions backend/src/playbacker/core/tracks/countdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,12 @@ class _Entry(NamedTuple):
_Entry(end=20, instruction=3),
_Entry(end=23, instruction=4),
],
"12/4": [
_Entry(end=5, instruction=1),
_Entry(end=11, instruction=2),
_Entry(end=14, instruction=1),
_Entry(end=17, instruction=2),
_Entry(end=20, instruction=3),
_Entry(end=23, instruction=4),
],
}
22 changes: 20 additions & 2 deletions backend/src/playbacker/core/tracks/metronome.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@


class MetronomeSounds(NamedTuple):
accent: AudioFile
tick_1_4: AudioFile
tick_1_8: AudioFile
tick_1_16: AudioFile


_Instruction = Literal[4, 8, 16]
_Instruction = Literal["accent", 4, 8, 16]


@dataclass
Expand All @@ -22,6 +23,7 @@ class MetronomeTrack(SoundTrack[MetronomeSounds]):
def __post_init__(self) -> None:
super().__post_init__()
self.instruction_to_sound = {
"accent": self.sounds.accent,
4: self.sounds.tick_1_4,
8: self.sounds.tick_1_8,
16: self.sounds.tick_1_16,
Expand All @@ -43,7 +45,11 @@ class _Entry(NamedTuple):
metronome_schemes: dict[TimeSignature, dict[Duration, list[_Entry]]] = {
"4/4": {
"1/4": [_Entry(divider=4, instruction=4)],
"1/8": [_Entry(divider=4, instruction=4), _Entry(divider=2, instruction=8)],
"1/8": [
_Entry(divider=16, instruction="accent"),
_Entry(divider=4, instruction=4),
_Entry(divider=2, instruction=8),
],
"1/16": [
_Entry(divider=4, instruction=4),
_Entry(divider=2, instruction=8),
Expand All @@ -59,6 +65,18 @@ class _Entry(NamedTuple):
_Entry(divider=1, instruction=16),
],
},
"12/4": {
"1/4": [_Entry(divider=12, instruction="accent")],
"1/8": [
_Entry(divider=12, instruction="accent"),
_Entry(divider=2, instruction=8),
],
"1/16": [
_Entry(divider=12, instruction="accent"),
_Entry(divider=2, instruction=8),
_Entry(divider=1, instruction=16),
],
},
}


Expand Down
7 changes: 5 additions & 2 deletions backend/tests/settings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import pytest
import sounddevice

from playbacker.core.settings import (
Settings,
_ChannelMap,
Expand Down Expand Up @@ -90,7 +89,10 @@ def file_settings(devices: list[_Device], tmp_path: pytest.TempPathFactory):
devices=devices,
sounds=_SoundPaths(
metronome=_MetronomePaths.construct(
tick_1_4=Path("1/4"), tick_1_8=Path("1/8"), tick_1_16=Path("1/16")
accent=Path("accent"),
tick_1_4=Path("1/4"),
tick_1_8=Path("1/8"),
tick_1_16=Path("1/16"),
),
countdown=_CountdownPaths.construct(
count_1=Path("count_1"),
Expand Down Expand Up @@ -123,6 +125,7 @@ def test_convert_file_settings(file_settings: _FileSettings):
assert settings.channel_map == device.channel_map
assert settings.channel_limit == 16

assert sounds.metronome.accent.path == file_settings.sounds.metronome.accent
assert sounds.metronome.tick_1_4.path == file_settings.sounds.metronome.tick_1_4
assert sounds.metronome.tick_1_8.path == file_settings.sounds.metronome.tick_1_8
assert sounds.metronome.tick_1_16.path == file_settings.sounds.metronome.tick_1_16
Expand Down
6 changes: 5 additions & 1 deletion backend/tests/tracks/metronome_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def metronome_track(stream_builder: StreamBuilder):
shared=Shared(),
stream_builder=stream_builder,
sounds=MetronomeSounds(
accent=AudioFile(path=Path("accent"), sample_rate=44100),
tick_1_4=AudioFile(path=Path("tick_1_4"), sample_rate=44100),
tick_1_8=AudioFile(path=Path("tick_1_8"), sample_rate=44100),
tick_1_16=AudioFile(path=Path("tick_1_16"), sample_rate=44100),
Expand All @@ -43,7 +44,10 @@ def audiofile_mock():
return mock

metronome_track.sounds = MetronomeSounds(
tick_1_4=audiofile_mock(), tick_1_8=audiofile_mock(), tick_1_16=audiofile_mock()
accent=audiofile_mock(),
tick_1_4=audiofile_mock(),
tick_1_8=audiofile_mock(),
tick_1_16=audiofile_mock(),
)
metronome_track.__post_init__()

Expand Down