11import React , { MouseEvent } from 'react' ;
22import './App.css' ;
3- import { SelectChangeEvent , Tab , Tabs } from '@mui/material' ;
3+ import {
4+ Checkbox ,
5+ FormControlLabel ,
6+ SelectChangeEvent ,
7+ Stack ,
8+ Tab ,
9+ Tabs ,
10+ Typography ,
11+ } from '@mui/material' ;
412import {
513 SortValue ,
614 SortName ,
715 ResetPreset ,
816 ResetFunction ,
917 Operator ,
10- SortType ,
1118 AlgorithmOptions ,
1219 ColorPreset ,
1320} from './types' ;
1421import { SortingAlgorithms } from './sorting-algorithms' ;
15- import {
16- createArr ,
17- shuffleArray ,
18- sleep ,
19- sortNameToSortType ,
20- timeScale ,
21- toHz ,
22- } from './utils' ;
22+ import { createArr , shuffleArray , sleep , timeScale , toHz } from './utils' ;
2323import { SideDrawer } from './SideDrawer' ;
2424import {
2525 RAINBOW_BACKGROUND_COLOR ,
@@ -76,6 +76,8 @@ class App extends React.Component<Props> {
7676 soundType : NonCustomOscillatorType ;
7777 soundVolume : number ;
7878 frequencyRange : [ number , number ] ;
79+ playSoundOnSwap : boolean ;
80+ playSoundOnComparison : boolean ;
7981 } ;
8082 } ;
8183 canvasController : CanvasController ;
@@ -252,10 +254,7 @@ class App extends React.Component<Props> {
252254 await sleep ( this . state . settings . compareTime ) ;
253255 }
254256
255- if (
256- sortNameToSortType [ this . state . settings . chosenSortAlg ] ===
257- SortType . Comparison
258- ) {
257+ if ( this . state . settings . playSoundOnComparison ) {
259258 this . playSoundForColumn ( arr , i1 ) ;
260259 }
261260
@@ -289,10 +288,7 @@ class App extends React.Component<Props> {
289288 await sleep ( this . state . settings . compareTime ) ;
290289 }
291290
292- if (
293- sortNameToSortType [ this . state . settings . chosenSortAlg ] ===
294- SortType . Comparison
295- ) {
291+ if ( this . state . settings . playSoundOnComparison ) {
296292 this . playSoundForColumn ( arr , i ) ;
297293 }
298294
@@ -311,10 +307,7 @@ class App extends React.Component<Props> {
311307 public async swap ( arr : SortValue [ ] , i1 : number , i2 : number ) {
312308 if ( ! this . state . isSorting ) throw Error ( 'isSorting is false!' ) ;
313309
314- if (
315- sortNameToSortType [ this . state . settings . chosenSortAlg ] ===
316- SortType . Distribution
317- ) {
310+ if ( this . state . settings . playSoundOnSwap ) {
318311 this . playSoundForColumn ( arr , i1 ) ;
319312 }
320313
@@ -619,6 +612,59 @@ class App extends React.Component<Props> {
619612 disableSwap
620613 valueLabelFormat = { ( value : number ) => `${ value } Hz` }
621614 />
615+ < div >
616+ < Typography
617+ align = "left"
618+ variant = "subtitle1"
619+ color = "textSecondary"
620+ >
621+ Play sound on
622+ </ Typography >
623+ < Stack >
624+ < FormControlLabel
625+ control = {
626+ < Checkbox
627+ checked = { this . state . settings . playSoundOnComparison }
628+ onChange = { ( e ) =>
629+ this . setSettings ( {
630+ playSoundOnComparison : ! ! e . target . checked ,
631+ } )
632+ }
633+ />
634+ }
635+ label = {
636+ < Typography
637+ align = "left"
638+ variant = "subtitle1"
639+ color = "textSecondary"
640+ >
641+ Comparison
642+ </ Typography >
643+ }
644+ />
645+ < FormControlLabel
646+ control = {
647+ < Checkbox
648+ checked = { this . state . settings . playSoundOnSwap }
649+ onChange = { ( e ) =>
650+ this . setSettings ( {
651+ playSoundOnSwap : ! ! e . target . checked ,
652+ } )
653+ }
654+ />
655+ }
656+ label = {
657+ < Typography
658+ align = "left"
659+ variant = "subtitle1"
660+ color = "textSecondary"
661+ >
662+ Swap
663+ </ Typography >
664+ }
665+ />
666+ </ Stack >
667+ </ div >
622668 </ TabPanel >
623669 </ SideDrawer >
624670 </ div >
0 commit comments