@@ -123,7 +123,9 @@ export function startPlaying(i, key, color = "red", gain = 1, skipDrawing = fals
123123 const rect = drawRect ( state . rects [ i ] , 10000 , color ) ;
124124 state . visualizerRects [ i ] . push ( {
125125 rect : rect ,
126- createdAt : Date . now ( )
126+ createdAt : Date . now ( ) ,
127+ i : i ,
128+ color : color
127129 } ) ;
128130 }
129131}
@@ -137,21 +139,10 @@ export function stopPlaying(i, key, color = "red", skipDestroy = false) {
137139 key . style . fill = key . dataset . fill ;
138140 key . setAttribute ( "class" , "unpressed" ) ;
139141 state . currentlyHeldDownKeys [ i ] = false ;
140-
141- // console.log(state.visualizerRects);
142142
143143 if ( ! skipDestroy ) {
144144 const rectObj = state . visualizerRects [ i ] . shift ( ) ;
145- const rect = rectObj . rect ;
146- const duration = Date . now ( ) - rectObj . createdAt ;
147-
148- const replacementRect = drawRect ( state . rects [ i ] , duration , color , { yPos : visualizerHeight - ( visualizerHeight * ( duration / 2000 ) ) } ) ;
149-
150- setTimeout ( function ( ) {
151- replacementRect . parentNode . removeChild ( replacementRect ) ;
152- } , duration + 2000 ) ;
153-
154- rect . parentNode . removeChild ( rect ) ;
145+ destroyRect ( rectObj ) ;
155146 }
156147
157148 if ( ! state . pedal ) {
@@ -165,6 +156,18 @@ export function stopPlaying(i, key, color = "red", skipDestroy = false) {
165156 }
166157}
167158
159+ export function destroyRect ( rectObj ) {
160+ const duration = Date . now ( ) - rectObj . createdAt ;
161+
162+ const replacementRect = drawRect ( state . rects [ rectObj . i ] , duration , rectObj . color , { yPos : visualizerHeight - ( visualizerHeight * ( duration / 2000 ) ) } ) ;
163+
164+ setTimeout ( function ( ) {
165+ replacementRect . parentNode . removeChild ( replacementRect ) ;
166+ } , duration + 2000 ) ;
167+
168+ rectObj . rect . parentNode . removeChild ( rectObj . rect ) ;
169+ }
170+
168171function noteStop ( note , noteBufferSource , endingVolume = 0.1 , noteFadeDuration = CONSTANTS . noteFade ) {
169172 try {
170173 note . gain . gain . setTargetAtTime ( endingVolume , state . audioContext . currentTime , noteFadeDuration ) ;
0 commit comments