@@ -458,17 +458,20 @@ function SampleWidget() {
458458 this . _playbackBtn . id = "playbackBtn" ;
459459 this . _playbackBtn . classList . add ( "disabled" ) ;
460460
461- let is_recording = false ;
461+ this . is_recording = false ;
462462
463463 this . _recordBtn . onclick = async ( ) => {
464- if ( ! is_recording ) {
464+ if ( ! this . is_recording ) {
465465 await this . activity . logo . synth . startRecording ( ) ;
466- is_recording = true ;
466+ this . is_recording = true ;
467467 this . _recordBtn . getElementsByTagName ( 'img' ) [ 0 ] . src = "header-icons/record.svg" ;
468468 this . displayRecordingStartMessage ( ) ;
469+ this . activity . logo . synth . LiveWaveForm ( ) ;
470+
471+ // Display Live Waveform
469472 } else {
470473 this . recordingURL = await this . activity . logo . synth . stopRecording ( ) ;
471- is_recording = false ;
474+ this . is_recording = false ;
472475 this . _recordBtn . getElementsByTagName ( 'img' ) [ 0 ] . src = "header-icons/mic.svg" ;
473476 this . displayRecordingStopMessage ( ) ;
474477 this . _playbackBtn . classList . remove ( "disabled" ) ;
@@ -480,6 +483,7 @@ function SampleWidget() {
480483 this . sampleName = `Recorded Audio ${ this . recordingURL } ` ;
481484 this . _addSample ( ) ;
482485 this . activity . logo . synth . playRecording ( ) ;
486+ // Display Recorded Waveform
483487 } ;
484488
485489 widgetWindow . sendToCenter ( ) ;
@@ -910,13 +914,13 @@ function SampleWidget() {
910914
911915 const draw = ( ) => {
912916 this . drawVisualIDs [ turtleIdx ] = requestAnimationFrame ( draw ) ;
913- if ( this . pitchAnalysers [ turtleIdx ] && ( this . running || resized ) ) {
917+ if ( this . is_recording || ( this . pitchAnalysers [ turtleIdx ] && ( this . running || resized ) ) ) {
914918 canvasCtx . fillStyle = "#FFFFFF" ;
915919 canvasCtx . font = "10px Verdana" ;
916920 this . verticalOffset = - canvas . height / 4 ;
917921 this . zoomFactor = 40.0 ;
918922 canvasCtx . fillRect ( 0 , 0 , width , height ) ;
919-
923+
920924 let oscText ;
921925 if ( turtleIdx >= 0 ) {
922926 //.TRANS: The sound sample that the user uploads.
@@ -926,18 +930,27 @@ function SampleWidget() {
926930 //.TRANS: The reference tone is a sound used for comparison.
927931 canvasCtx . fillText ( _ ( "reference tone" ) , 10 , 10 ) ;
928932 canvasCtx . fillText ( oscText , 10 , canvas . height / 2 + 10 ) ;
929-
933+
930934 for ( let turtleIdx = 0 ; turtleIdx < 2 ; turtleIdx += 1 ) {
931- const dataArray = this . pitchAnalysers [ turtleIdx ] . getValue ( ) ;
935+ let dataArray ;
936+ if ( this . is_recording ) {
937+ dataArray = turtleIdx === 0
938+ ? this . pitchAnalysers [ 0 ] . getValue ( )
939+ : this . activity . logo . synth . getValues ( ) ;
940+ console . log ( dataArray ) ;
941+ } else {
942+ dataArray = this . pitchAnalysers [ turtleIdx ] . getValue ( ) ;
943+ }
944+
932945 const bufferLength = dataArray . length ;
933946 const rbga = SAMPLEOSCCOLORS [ turtleIdx ] ;
934947 const sliceWidth = ( width * this . zoomFactor ) / bufferLength ;
935948 canvasCtx . lineWidth = 2 ;
936949 canvasCtx . strokeStyle = rbga ;
937950 canvasCtx . beginPath ( ) ;
938-
951+
939952 let x = 0 ;
940-
953+
941954 for ( let i = 0 ; i < bufferLength ; i ++ ) {
942955 const y = ( height / 2 ) * ( 1 - dataArray [ i ] ) + this . verticalOffset ;
943956 if ( i === 0 ) {
0 commit comments