mirror of
https://github.com/eliasstepanik/strudel.git
synced 2026-01-17 08:28:51 +00:00
fix: note2oct
This commit is contained in:
parent
584d469a73
commit
f2c16a06a1
@ -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 [];
|
||||
}
|
||||
|
||||
@ -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');
|
||||
|
||||
@ -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));
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||
// Vitest Snapshot v1
|
||||
|
||||
exports[`renders tunes > tune: amensister 1`] = `
|
||||
[
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user