Skip to content
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
155 changes: 155 additions & 0 deletions docs/demo.cast
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
{"version": 2, "width": 82, "height": 30, "env": {"TERM": "xterm-256color", "SHELL": "/bin/zsh"}}
[0.0, "o", "\u001b[32m$\u001b[0m "]
[0.045, "o", "s"]
[0.09, "o", "a"]
[0.135, "o", "m"]
[0.18, "o", "p"]
[0.225, "o", "l"]
[0.27, "o", "e"]
[0.315, "o", "r"]
[0.36, "o", "d"]
[0.405, "o", "i"]
[0.45, "o", "s"]
[0.495, "o", "c"]
[0.54, "o", " "]
[0.585, "o", "i"]
[0.63, "o", "n"]
[0.675, "o", "f"]
[0.72, "o", "o"]
[0.765, "o", " "]
[0.81, "o", "\""]
[0.855, "o", "D"]
[0.9, "o", "e"]
[0.945, "o", "m"]
[0.99, "o", "o"]
[1.035, "o", " "]
[1.08, "o", "A"]
[1.125, "o", "K"]
[1.17, "o", "A"]
[1.215, "o", "I"]
[1.26, "o", " "]
[1.305, "o", "C"]
[1.35, "o", "D"]
[1.395, "o", "."]
[1.44, "o", "n"]
[1.485, "o", "r"]
[1.53, "o", "g"]
[1.575, "o", "\""]
[1.62, "o", "\r\n"]
[1.97, "o", "container nrg\r\nsize 524288 bytes (512.0 KB)\r\nsectors 256\r\nfilesystem akai at offset 0\r\n"]
[3.07, "o", "\u001b[32m$\u001b[0m "]
[3.115, "o", "s"]
[3.16, "o", "a"]
[3.205, "o", "m"]
[3.25, "o", "p"]
[3.295, "o", "l"]
[3.34, "o", "e"]
[3.385, "o", "r"]
[3.43, "o", "d"]
[3.475, "o", "i"]
[3.52, "o", "s"]
[3.565, "o", "c"]
[3.61, "o", " "]
[3.655, "o", "l"]
[3.7, "o", "i"]
[3.745, "o", "s"]
[3.79, "o", "t"]
[3.835, "o", " "]
[3.88, "o", "\""]
[3.925, "o", "D"]
[3.97, "o", "e"]
[4.015, "o", "m"]
[4.06, "o", "o"]
[4.105, "o", " "]
[4.15, "o", "A"]
[4.195, "o", "K"]
[4.24, "o", "A"]
[4.285, "o", "I"]
[4.33, "o", " "]
[4.375, "o", "C"]
[4.42, "o", "D"]
[4.465, "o", "."]
[4.51, "o", "n"]
[4.555, "o", "r"]
[4.6, "o", "g"]
[4.645, "o", "\""]
[4.69, "o", "\r\n"]
[5.04, "o", "1 partition\r\n\r\npartition 1\r\n SYNTH BASS (block 1, 2 files)\r\n PIANO C3 sample 342 bytes\r\n BASS PICK sample 310 bytes\r\n DRUM KIT 1 (block 4, 3 files)\r\n KICK 1 sample 278 bytes\r\n SNARE 1 sample 294 bytes\r\n HIHAT CL sample 246 bytes\r\n\r\n2 volumes, 5 sample\r\n"]
[6.14, "o", "\u001b[32m$\u001b[0m "]
[6.185, "o", "s"]
[6.23, "o", "a"]
[6.275, "o", "m"]
[6.32, "o", "p"]
[6.365, "o", "l"]
[6.41, "o", "e"]
[6.455, "o", "r"]
[6.5, "o", "d"]
[6.545, "o", "i"]
[6.59, "o", "s"]
[6.635, "o", "c"]
[6.68, "o", " "]
[6.725, "o", "e"]
[6.77, "o", "x"]
[6.815, "o", "t"]
[6.86, "o", "r"]
[6.905, "o", "a"]
[6.95, "o", "c"]
[6.995, "o", "t"]
[7.04, "o", " "]
[7.085, "o", "\""]
[7.13, "o", "D"]
[7.175, "o", "e"]
[7.22, "o", "m"]
[7.265, "o", "o"]
[7.31, "o", " "]
[7.355, "o", "A"]
[7.4, "o", "K"]
[7.445, "o", "A"]
[7.49, "o", "I"]
[7.535, "o", " "]
[7.58, "o", "C"]
[7.625, "o", "D"]
[7.67, "o", "."]
[7.715, "o", "n"]
[7.76, "o", "r"]
[7.805, "o", "g"]
[7.85, "o", "\""]
[7.895, "o", " "]
[7.94, "o", "o"]
[7.985, "o", "u"]
[8.03, "o", "t"]
[8.075, "o", "\r\n"]
[8.425, "o", "wrote 5 WAV files to out\r\n"]
[9.525, "o", "\u001b[32m$\u001b[0m "]
[9.57, "o", "f"]
[9.615, "o", "i"]
[9.66, "o", "n"]
[9.705, "o", "d"]
[9.75, "o", " "]
[9.795, "o", "o"]
[9.84, "o", "u"]
[9.885, "o", "t"]
[9.93, "o", " "]
[9.975, "o", "-"]
[10.02, "o", "n"]
[10.065, "o", "a"]
[10.11, "o", "m"]
[10.155, "o", "e"]
[10.2, "o", " "]
[10.245, "o", "'"]
[10.29, "o", "*"]
[10.335, "o", "."]
[10.38, "o", "w"]
[10.425, "o", "a"]
[10.47, "o", "v"]
[10.515, "o", "'"]
[10.56, "o", " "]
[10.605, "o", "|"]
[10.65, "o", " "]
[10.695, "o", "s"]
[10.74, "o", "o"]
[10.785, "o", "r"]
[10.83, "o", "t"]
[10.875, "o", "\r\n"]
[11.225, "o", "out/partition-1/DRUM KIT 1/HIHAT CL.wav\r\nout/partition-1/DRUM KIT 1/KICK 1.wav\r\nout/partition-1/DRUM KIT 1/SNARE 1.wav\r\nout/partition-1/SYNTH BASS/BASS PICK.wav\r\nout/partition-1/SYNTH BASS/PIANO C3.wav\r\n"]
[14.325, "o", ""]
18 changes: 14 additions & 4 deletions src/samplerdisc/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ def _human(n: int) -> str:
return f"{n} B"


def _plural(count: int, noun: str) -> str:
"""``count`` and ``noun``, the noun pluralised for any count but one.

Every noun this is used with -- volume, file, partition, and the backends'
own kind words (sample, program, wav, aiff) -- pluralises with a plain -s,
so nothing cleverer is needed.
"""
return f"{count} {noun}" + ("" if count == 1 else "s")


def cmd_list(args: argparse.Namespace) -> int:
with open_image(args.image) as image:
origin = find_origin(image)
Expand Down Expand Up @@ -66,17 +76,17 @@ def cmd_list(args: argparse.Namespace) -> int:
note = f" -- {volume.note}" if volume.note else ""
print(
f"{indent}{volume.name} (block {volume.start_block}, "
f"{len(volume.files)} files){note}"
f"{_plural(len(volume.files), 'file')}){note}"
)
for entry in volume.files:
kinds[entry.kind] += 1
if not args.volumes_only:
print(f"{indent} {entry.name:<14} {entry.kind:<8} {entry.size:>9} bytes")
# Kinds are the backend's vocabulary, not ours: AKAI says sample and
# program, ISO 9660 says wav and aiff.
breakdown = ", ".join(f"{count} {kind}" for kind, count in sorted(kinds.items()))
across = f" across {partitions} partitions" if partitions > 1 else ""
print(f"\n{volumes} volumes{across}" + (f", {breakdown}" if breakdown else ""))
breakdown = ", ".join(_plural(count, kind) for kind, count in sorted(kinds.items()))
across = f" across {_plural(partitions, 'partition')}" if partitions > 1 else ""
print(f"\n{_plural(volumes, 'volume')}{across}" + (f", {breakdown}" if breakdown else ""))
return 0


Expand Down
40 changes: 40 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,46 @@ def test_parser_exposes_version_flag():
assert any(a.dest == "version" for a in parser._actions)


def test_list_summary_pluralises_counts(tmp_path, capsys):
"""'sample' is the backend's own word (ADR-0023), but '5 sample' is still a
bug, and so is '1 volumes'. Counts agree with English."""
from samplerdisc.cli import main
from tests import fixtures

def sample(name):
payload = fixtures.akai_sample(name, words=32)
return (name, 0x73, len(payload), payload)

disc = tmp_path / "many.iso"
disc.write_bytes(
fixtures.akai_partition(
[
("VOL 1", [sample("KICK 1"), sample("SNARE")]),
("VOL 2", [sample("HAT")]),
]
)
)
assert main(["list", str(disc)]) == 0
out = capsys.readouterr().out
assert "2 volumes, 3 samples" in out
assert "2 files)" in out
assert "1 file)" in out # the one-file volume, singular


def test_list_summary_uses_singular_for_one(tmp_path, capsys):
from samplerdisc.cli import main
from tests import fixtures

payload = fixtures.akai_sample("KICK 1", words=32)
disc = tmp_path / "one.iso"
entry = ("KICK 1", 0x73, len(payload), payload)
disc.write_bytes(fixtures.akai_partition([("VOL 1", [entry])]))
assert main(["list", str(disc)]) == 0
out = capsys.readouterr().out
assert "1 volume, 1 sample" in out
assert "volumes" not in out and "samples" not in out


def test_assume_audio_cd_refuses_a_stream_that_is_not_audio(tmp_path, capsys):
"""The flag is an assertion by the user, not an instruction to obey blindly.

Expand Down