@@ -46,6 +46,49 @@ test("midi events", async function () {
4646 expect ( round ( take ( outs [ 1 ] , 8 ) ) ) . toMatchObject ( [ 1 , 1 , 1 , 1 , 0 , 0 , 0 , 0 ] ) ;
4747} ) ;
4848
49+ test ( "midi cc events" , async function ( ) {
50+ let core = new OfflineRenderer ( ) ;
51+
52+ await core . initialize ( {
53+ numInputChannels : 0 ,
54+ numOutputChannels : 1 ,
55+ sampleRate : 44100 ,
56+ blockSize : 128 ,
57+ } ) ;
58+
59+ // Graph with raw CC output (0-127)
60+ core . render ( el . midicc ( { control : 1 , channel : 2 } ) ) ;
61+
62+ // Data
63+ let inps = [ ] ;
64+ let outs = [ new Float32Array ( 128 ) ] ;
65+
66+ // Get past the fade-in
67+ for ( let i = 0 ; i < 20 ; ++ i ) {
68+ core . process ( inps , outs ) ;
69+ }
70+
71+ // Now we push a CC event (CC 1, value 127) and study the outputs
72+ core . pushMidiEvent ( 0 , new Uint8Array ( [ 0xb2 , 1 , 127 ] ) ) ;
73+ core . process ( inps , outs ) ;
74+
75+ // Should see raw value of 127
76+ expect ( round ( take ( outs [ 0 ] , 8 ) ) ) . toMatchObject ( repeat ( 8 , 127 ) ) ;
77+
78+ // On the next block we should see that the value is still held
79+ core . process ( inps , outs ) ;
80+ expect ( round ( take ( outs [ 0 ] , 8 ) ) ) . toMatchObject ( repeat ( 8 , 127 ) ) ;
81+
82+ // Now we'll push a new CC value (64) 4 samples into the next block
83+ core . pushMidiEvent ( 4 , new Uint8Array ( [ 0xb2 , 1 , 64 ] ) ) ;
84+ core . process ( inps , outs ) ;
85+
86+ // Should see transition from 127 to 64 at sample 4
87+ expect ( round ( take ( outs [ 0 ] , 8 ) ) ) . toMatchObject ( [
88+ 127 , 127 , 127 , 127 , 64 , 64 , 64 , 64 ,
89+ ] ) ;
90+ } ) ;
91+
4992test ( "param value events" , async function ( ) {
5093 let core = new OfflineRenderer ( ) ;
5194
0 commit comments