From 4121ac91ee14a78e16db4d514a0a42a66d742c59 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Sun, 31 Dec 2023 12:11:08 +0100 Subject: [PATCH] fix: graceful handling of invalid chord symbols --- packages/tonal/voicings.mjs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/tonal/voicings.mjs b/packages/tonal/voicings.mjs index a99a043b..f93a54d0 100644 --- a/packages/tonal/voicings.mjs +++ b/packages/tonal/voicings.mjs @@ -4,7 +4,7 @@ Copyright (C) 2022 Strudel contributors - see . */ -import { stack, register } from '@strudel.cycles/core'; +import { stack, register, silence, logger } from '@strudel.cycles/core'; import { renderVoicing } from './tonleiter.mjs'; import _voicings from 'chord-voicings'; import { complex, simple } from './ireal.mjs'; @@ -199,11 +199,15 @@ export const voicing = register('voicing', function (pat) { let { dictionary = 'default', chord, anchor, offset, mode, n, octaves, ...rest } = value; dictionary = typeof dictionary === 'string' ? voicingRegistry[dictionary] : { dictionary, mode: 'below', anchor: 'c5' }; - let notes = renderVoicing({ ...dictionary, chord, anchor, offset, mode, n, octaves }); - - return stack(...notes) - .note() - .set(rest); // rest does not include voicing controls anymore! + try { + let notes = renderVoicing({ ...dictionary, chord, anchor, offset, mode, n, octaves }); + return stack(...notes) + .note() + .set(rest); // rest does not include voicing controls anymore! + } catch (err) { + logger(`[voicing]: unknown chord "${chord}"`); + return silence; + } }) .outerJoin(); });