char-slop/chordpad.vibed.software
git clone https://git.t4t.associates/char-slop/chordpad.vibed.software
040fec5
main
1import { assertEquals } from "@std/assert" ; 2import { chordsOf } from "./chords.ts" ; 3 4const note = ( start :number , dur :number , pitch :number ) => ({ start, dur, pitch, vel :1 }); 5const layout = ( notes :ReturnType < typeof note >[]) => 6chordsOf ( notes ). map ( c => [ c . start , c . start + c . dur , c . notes ]); 7 8Deno . test ( "block chords come out one chord each, leaving silences empty" , () => { 9assertEquals ( 10layout ([ 11note ( 0 , 2 , 64 ), 12note ( 0 , 2 , 60 ), 13note ( 0 , 2 , 67 ), 14note ( 3 , 1 , 65 ), 15note ( 3 , 1 , 69 ), 16note ( 3 , 1 , 60 ), 17]), 18[ 19[ 0 , 2 , [ 60 , 64 , 67 ]], 20[ 3 , 4 , [ 60 , 65 , 69 ]], 21], 22); 23}); 24 25Deno . test ( "a new chord starts wherever a note comes in or drops out" , () => { 26assertEquals ( layout ([ note ( 0 , 4 , 48 ), note ( 0 , 2 , 64 ), note ( 1 , 1 , 67 ), note ( 2 , 2 , 65 )]), [ 27[ 0 , 1 , [ 48 , 64 ]], 28[ 1 , 2 , [ 48 , 64 , 67 ]], 29[ 2 , 4 , [ 48 , 65 ]], 30]); 31}); 32 33Deno . test ( "the same notes struck again straight after carry on as one chord" , () => { 34assertEquals ( layout ([ note ( 0 , 1 , 60 ), note ( 0 , 1 , 64 ), note ( 1 , 1 , 64 ), note ( 1 , 1 , 60 )]), [ 35[ 0 , 2 , [ 60 , 64 ]], 36]); 37}); 38 39Deno . test ( "a pitch doubled across overlapping notes is one chord tone" , () => { 40assertEquals ( layout ([ note ( 0 , 2 , 60 ), note ( 1 , 2 , 60 ), note ( 1 , 1 , 67 )]), [ 41[ 0 , 1 , [ 60 ]], 42[ 1 , 2 , [ 60 , 67 ]], 43[ 2 , 3 , [ 60 ]], 44]); 45});