11import React , { MouseEvent } from 'react' ;
22import './App.css' ;
3- import { SelectChangeEvent , Tab , Tabs } from '@mui/material' ;
3+ import {
4+ SelectChangeEvent ,
5+ Slider ,
6+ Tab ,
7+ Tabs ,
8+ Typography ,
9+ } from '@mui/material' ;
410import {
511 SortValue ,
612 SortName ,
@@ -25,21 +31,25 @@ import {
2531 RAINBOW_BACKGROUND_COLOR ,
2632 INIT_STATE ,
2733 INIT_SETTINGS ,
34+ SOUND_TYPE_OPTIONS ,
2835} from './constants' ;
2936import { SortAppBar } from './AppBar' ;
3037import { CanvasController } from './canvas-controller' ;
3138import { Colors } from './Colors' ;
3239import { ColumnSlider } from './ColumnSlider' ;
3340import { Options } from './Options' ;
34- import { ResetPresetSelect } from './ResetPresetSelect' ;
35- import { SortingAlgorithmSelect } from './SortingAlgorithmSelect' ;
3641import { TimeSlider } from './TimeSlider' ;
3742import { Audiotrack , BarChart , Palette } from '@mui/icons-material' ;
3843import { TabPanel } from './TabPanel' ;
44+ import { NonCustomOscillatorType } from 'tone/build/esm/source/oscillator/OscillatorInterface' ;
45+ import { TitledSelect } from './TitledSelect' ;
3946
4047type Props = {
4148 playSound : ( params : { frequency : number ; duration ?: string } ) => void ;
4249 stopSounds : ( ) => void ;
50+ soundType : NonCustomOscillatorType ;
51+ setSoundType : ( type : NonCustomOscillatorType ) => void ;
52+ setVolume : ( volume : number ) => void ;
4353} ;
4454
4555class App extends React . Component < Props > {
@@ -68,6 +78,8 @@ class App extends React.Component<Props> {
6878 columnColor2 : string ;
6979 backgroundColor : string ;
7080 highlightColor : string ;
81+ soundType : NonCustomOscillatorType ;
82+ soundVolume : number ;
7183 } ;
7284 } ;
7385 canvasController : CanvasController ;
@@ -109,6 +121,9 @@ class App extends React.Component<Props> {
109121 this . state . settings . columnColor2 ,
110122 this . state . settings . highlightColor ,
111123 ) ;
124+
125+ this . props . setVolume ( this . state . settings . soundVolume ) ;
126+ this . props . setSoundType ( this . state . settings . soundType ) ;
112127 }
113128
114129 setSettings = (
@@ -288,13 +303,13 @@ class App extends React.Component<Props> {
288303 this . setState ( { areSettingsOpen : false } ) ;
289304 } ;
290305
291- chooseSortAlg = ( event : SelectChangeEvent < SortName > ) => {
306+ chooseSortAlg = ( event : SelectChangeEvent < string > ) => {
292307 this . stopSorting ( ) ;
293308
294309 this . setSettings ( { chosenSortAlg : event . target . value as SortName } ) ;
295310 } ;
296311
297- chooseResetPreset = ( event : SelectChangeEvent < ResetPreset > ) => {
312+ chooseResetPreset = ( event : SelectChangeEvent < string > ) => {
298313 this . setSettings ( { resetPreset : event . target . value as ResetPreset } ) ;
299314 } ;
300315
@@ -418,6 +433,18 @@ class App extends React.Component<Props> {
418433 } ) ;
419434 } ;
420435
436+ setSoundType = ( event : SelectChangeEvent < string > ) => {
437+ const soundType = event . target . value as NonCustomOscillatorType ;
438+ this . props . setSoundType ( soundType ) ;
439+ this . setSettings ( { soundType } ) ;
440+ } ;
441+
442+ setVolume = ( _ : unknown , value : number | number [ ] ) => {
443+ const volume = value instanceof Array ? value [ 0 ] : value ;
444+ this . props . setVolume ( volume ) ;
445+ this . setSettings ( { soundVolume : volume } ) ;
446+ } ;
447+
421448 render ( ) {
422449 return (
423450 < div
@@ -470,9 +497,11 @@ class App extends React.Component<Props> {
470497 < Tab icon = { < Audiotrack /> } sx = { { minWidth : 0 } } />
471498 </ Tabs >
472499 < TabPanel value = { this . state . tabIndex } index = { 0 } >
473- < SortingAlgorithmSelect
474- chosenSortAlg = { this . state . settings . chosenSortAlg }
475- chooseSortAlg = { this . chooseSortAlg }
500+ < TitledSelect
501+ title = "Sorting Algorithm"
502+ value = { this . state . settings . chosenSortAlg }
503+ onChange = { this . chooseSortAlg }
504+ options = { Object . values ( SortName ) }
476505 />
477506 < Options
478507 chosenSortAlg = { this . state . settings . chosenSortAlg }
@@ -495,9 +524,11 @@ class App extends React.Component<Props> {
495524 time = { this . state . settings . compareTime }
496525 changeTime = { this . changeCompareTime }
497526 />
498- < ResetPresetSelect
499- resetPreset = { this . state . settings . resetPreset }
500- chooseResetPreset = { this . chooseResetPreset }
527+ < TitledSelect
528+ title = "Reset Preset"
529+ value = { this . state . settings . resetPreset }
530+ onChange = { this . chooseResetPreset }
531+ options = { Object . values ( ResetPreset ) }
501532 />
502533 </ TabPanel >
503534 < TabPanel value = { this . state . tabIndex } index = { 1 } >
@@ -514,7 +545,34 @@ class App extends React.Component<Props> {
514545 setHighlightColor = { this . setHighlightColor }
515546 />
516547 </ TabPanel >
517- < TabPanel value = { this . state . tabIndex } index = { 2 } > </ TabPanel >
548+ < TabPanel value = { this . state . tabIndex } index = { 2 } >
549+ < TitledSelect
550+ title = "Sound type"
551+ value = { this . props . soundType }
552+ onChange = { this . setSoundType }
553+ options = { SOUND_TYPE_OPTIONS }
554+ />
555+ < div >
556+ < Typography
557+ align = "left"
558+ variant = "subtitle1"
559+ color = "textSecondary"
560+ >
561+ Volume
562+ </ Typography >
563+ < div className = "col-slider" >
564+ < Slider
565+ defaultValue = { this . state . settings . soundVolume }
566+ aria-labelledby = "discrete-slider"
567+ valueLabelDisplay = "auto"
568+ min = { 0 }
569+ step = { 1 }
570+ max = { 100 }
571+ onChangeCommitted = { this . setVolume }
572+ />
573+ </ div >
574+ </ div >
575+ </ TabPanel >
518576 </ SideDrawer >
519577 </ div >
520578 </ div >
0 commit comments