Skip to content

Commit 9ea43af

Browse files
committed
fix(cli): a track with no beats answers an empty result, not an error
1 parent 845bd63 commit 9ea43af

3 files changed

Lines changed: 34 additions & 7 deletions

File tree

‎docs/packages/cli.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,8 +776,8 @@ into the audio; `strength` (0–1) is relative loudness. Beats you add, move, or
776776
delete in Studio save back to the same file.
777777

778778
A track without a steady beat (ambient, rubato, too short) gets no beat file:
779-
the command fails and writes nothing rather than inventing a grid. Results
780-
match Studio's to within a frame or two — Studio decodes in the browser, often
779+
the command answers an empty result (`count: 0`, exit 0) and writes nothing rather
780+
than inventing a grid. Results match Studio's to within a frame or two — Studio decodes in the browser, often
781781
at a different sample rate, which can shift a beat slightly.
782782

783783
### `audio`

‎packages/cli/src/commands/beats.test.ts‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,31 @@ describe.skipIf(!canDecode)("hyperframes beats", () => {
132132
expect(out).toMatch(/No music track found/);
133133
});
134134

135-
it("writes nothing for a track with no steady beat", async () => {
135+
it("answers a track with no steady beat with an empty result and writes nothing", async () => {
136136
const dir = project("silent", null);
137137
const { exitCode, out } = await runBeats(dir);
138-
expect(exitCode).toBe(1);
139-
expect(out).toMatch(/No beats detected in assets\/song\.wav/);
138+
expect(exitCode).toBe(0);
139+
expect(JSON.parse(out)).toEqual({
140+
ok: true,
141+
track: "assets/song.wav",
142+
file: null,
143+
count: 0,
144+
bpm: null,
145+
});
140146
expect(existsSync(join(dir, "beats"))).toBe(false);
141147
});
142148

149+
it("answers one ambient file with an empty beat list, for a person and for --json", async () => {
150+
const dir = project("silent-file", null);
151+
const song = join(dir, "assets", "song.wav");
152+
const json = await runBeats(song);
153+
expect(json.exitCode).toBe(0);
154+
expect(JSON.parse(json.out)).toMatchObject({ ok: true, file: song, count: 0, beatTimes: [] });
155+
const person = await runBeats(song, false);
156+
expect(person.exitCode).toBe(0);
157+
expect(person.out).toMatch(/No beats in /);
158+
});
159+
143160
it("refuses a music src that resolves outside the project", async () => {
144161
// An encoded `../` survives URL normalization and decodes to a parent path, so
145162
// without a containment check the command reads ../../secret.wav and writes

‎packages/cli/src/commands/beats.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ function report(file: string, result: MusicBeatAnalysis, json: boolean): void {
9898

9999
async function analyzeFile(audioPath: string, json: boolean): Promise<void> {
100100
const result = await analyzeMusicFromSignal(await decode(audioPath));
101-
if (result.beatTimes.length === 0) fail(`No beats detected in ${audioPath}.`);
102101
if (json) {
103102
console.log(
104103
JSON.stringify(
@@ -115,6 +114,10 @@ async function analyzeFile(audioPath: string, json: boolean): Promise<void> {
115114
);
116115
return;
117116
}
117+
if (result.beatTimes.length === 0) {
118+
console.log(c.dim(`No beats in ${audioPath}.`));
119+
return;
120+
}
118121
console.log(
119122
c.success(
120123
`✓ ${result.beatTimes.length} beats in ${audioPath} (bpm ${result.bpm ?? "?"}, ${result.bpmConfidence})`,
@@ -154,7 +157,14 @@ export default defineCommand({
154157
const result = await analyzeMusicFromSignal(await decode(audioPath));
155158
// The Studio ignores a 0-beat file (treats it as a stale seed), so don't write one.
156159
if (result.beatTimes.length === 0) {
157-
fail(`No beats detected in ${rel} — nothing written. (Track may be silent/ambient.)`);
160+
if (args.json) {
161+
console.log(
162+
JSON.stringify({ ok: true, track: rel, file: null, count: 0, bpm: null }, null, 2),
163+
);
164+
} else {
165+
console.log(c.dim(`No beats in ${rel}; nothing written.`));
166+
}
167+
return;
158168
}
159169

160170
const outPath = join(project.dir, "beats", `${rel}.json`);

0 commit comments

Comments
 (0)