fix: note2oct

This commit is contained in:
Felix Roos 2023-07-17 23:10:13 +02:00
parent 584d469a73
commit f2c16a06a1
4 changed files with 5 additions and 5 deletions

View File

@ -11,7 +11,7 @@ export const tokenizeNote = (note) => {
if (typeof note !== 'string') {
return [];
}
const [pc, acc = '', oct] = note.match(/^([a-gA-G])([#bsf]*)([0-9])?$/)?.slice(1) || [];
const [pc, acc = '', oct] = note.match(/^([a-gA-G])([#bsf]*)([0-9]*)$/)?.slice(1) || [];
if (!pc) {
return [];
}

View File

@ -88,7 +88,7 @@ describe('tonleiter', () => {
expect(note2oct('C5')).toBe(5);
expect(note2oct('Bb3')).toBe(3);
expect(note2oct('C7')).toBe(7);
//expect(note2oct('C10')).toBe(10); // <- 2 digits fail
expect(note2oct('C10')).toBe(10);
});
test('midi2note', () => {
expect(midi2note(60)).toBe('C4');

View File

@ -1,4 +1,4 @@
import { isNote, isNoteWithOctave, _mod, noteToMidi } from '@strudel.cycles/core';
import { isNote, isNoteWithOctave, _mod, noteToMidi, tokenizeNote } from '@strudel.cycles/core';
import { Interval } from '@tonaljs/tonal';
// https://codesandbox.io/s/stateless-voicings-g2tmz0?file=/src/lib.js:0-2515
@ -28,7 +28,7 @@ export function tokenizeChord(chord) {
return match.slice(1);
}
export const note2pc = (note) => note.match(/^[A-G][#b]?/i)[0];
export const note2oct = (note) => Number(note.slice(-1));
export const note2oct = (note) => tokenizeNote(note)[2];
export const note2chroma = (note) => {
return pc2chroma(note2pc(note));

View File

@ -1,4 +1,4 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
// Vitest Snapshot v1
exports[`renders tunes > tune: amensister 1`] = `
[