@@ -835,15 +835,17 @@ const getIndex = node => {
835
835
return i ;
836
836
}
837
837
838
- // returns the text of the selected option in a `select` or custom radio element
838
+ // returns the text/label of a settings control
839
839
const getText = el => {
840
- let text = '' ;
840
+ let text = el . value ?? '' ;
841
841
if ( isCustomRadio ( el ) ) {
842
842
const option = el . querySelector ( ':checked ~ label' ) ;
843
843
if ( option )
844
844
text = option . textContent ;
845
845
}
846
- else
846
+ else if ( el . type == 'range' )
847
+ text = translateRangeValue ( el ) ;
848
+ else if ( el . tagName == 'SELECT' )
847
849
text = el [ el . selectedIndex ] . text ;
848
850
return text ;
849
851
}
@@ -1064,7 +1066,7 @@ const setControlValue = ( el, val ) => {
1064
1066
if ( el . selectedIndex == - 1 ) // fix invalid values in select elements
1065
1067
el . selectedIndex = 0 ;
1066
1068
}
1067
- updateRangeValue ( el ) ;
1069
+ updateRangeValue ( el == elFreqScale ? elBandCount : el ) ;
1068
1070
}
1069
1071
1070
1072
// update configuration options from an existing preset
@@ -1089,6 +1091,9 @@ const toggleDisplay = ( el, status ) => {
1089
1091
el . style . display = status ? '' : 'none' ;
1090
1092
}
1091
1093
1094
+ // capitalize first letter of a string
1095
+ const ucFirst = str => str . charAt ( 0 ) . toUpperCase ( ) + str . slice ( 1 ) ;
1096
+
1092
1097
// promise-compatible `onloadeddata` event handler for media elements
1093
1098
const waitForLoadedData = async audioEl => new Promise ( ( resolve , reject ) => {
1094
1099
audioEl . onerror = ( ) => {
@@ -3796,6 +3801,7 @@ function setProperty( elems, save = true ) {
3796
3801
3797
3802
case elFreqScale :
3798
3803
audioMotion . frequencyScale = getControlValue ( elFreqScale ) ;
3804
+ updateRangeValue ( elBandCount ) ;
3799
3805
break ;
3800
3806
3801
3807
case elFsHeight :
@@ -4804,6 +4810,30 @@ function toggleMute( mute ) {
4804
4810
audioMotion . connectOutput ( ) ;
4805
4811
}
4806
4812
4813
+ /**
4814
+ * Convert value of a range control to a friendly text label
4815
+ */
4816
+ function translateRangeValue ( el ) {
4817
+ const val = el . value ,
4818
+ { abs, sign } = Math ;
4819
+
4820
+ if ( el == elBandCount ) {
4821
+ const isOctaves = getControlValue ( elFreqScale ) == SCALE_LOG ,
4822
+ bands = isOctaves
4823
+ ? [ '' , '' , 'half-' , '1/3rd-' , '1/4th-' , '1/6th-' , '1/8th-' , '1/12th-' , '1/24th-' ]
4824
+ : [ '' , '10' , '20' , '30' , '40' , '60' , '80' , '120' , '240' ] ;
4825
+
4826
+ return ucFirst ( bands [ + val || 0 ] + ( isOctaves ? 'octave' : '' ) + ' bands' ) ;
4827
+ }
4828
+ else if ( el == elBarSpace )
4829
+ return val == 0 ? 'None' : ( val == 1 ? 'Legacy' : `${ val * 100 | 0 } %` ) ;
4830
+ else if ( el == elFillAlpha )
4831
+ return val == 0 ? 0 : `${ val * 100 | 0 } %` ;
4832
+ else if ( el == elSpin )
4833
+ return val == 0 ? 'OFF' : abs ( val ) + ' RPM' + ( sign ( val ) == - 1 ? ' (CCW)' : '' ) ;
4834
+ return val ;
4835
+ }
4836
+
4807
4837
/**
4808
4838
* Update last used configuration
4809
4839
*/
@@ -4824,31 +4854,7 @@ function updateRangeValue( el ) {
4824
4854
if ( ! elVal || elVal . className != 'value' )
4825
4855
return ;
4826
4856
4827
- const translation = val => {
4828
- const { abs, sign } = Math ;
4829
- if ( el == elBandCount ) {
4830
- return [
4831
- '' ,
4832
- '10 bands (octaves)' ,
4833
- '20 bands (half octaves)' ,
4834
- '30 bands (1/3rd oct.)' ,
4835
- '40 bands (1/4th oct.)' ,
4836
- '60 bands (1/6th oct.)' ,
4837
- '80 bands (1/8th oct.)' ,
4838
- '120 bands (1/12th oct.)' ,
4839
- '240 bands (1/24th oct.)'
4840
- ] [ + val || 0 ] ;
4841
- }
4842
- else if ( el == elBarSpace )
4843
- return val == 0 ? 'None' : ( val == 1 ? 'Legacy' : `${ val * 100 | 0 } %` ) ;
4844
- else if ( el == elFillAlpha )
4845
- return val == 0 ? 0 : `${ val * 100 | 0 } %` ;
4846
- else if ( el == elSpin )
4847
- return val == 0 ? 'OFF' : abs ( val ) + ' RPM' + ( sign ( val ) == - 1 ? ' (CCW)' : '' ) ;
4848
- return val ;
4849
- }
4850
-
4851
- elVal . innerText = translation ( el . value ) ;
4857
+ elVal . innerText = translateRangeValue ( el ) ;
4852
4858
}
4853
4859
4854
4860
@@ -4996,7 +5002,7 @@ function updateRangeValue( el ) {
4996
5002
drawText ( getSelectedGradients ( ) , centerPos , topLine1 , maxWidthTop ) ;
4997
5003
4998
5004
canvasCtx . textAlign = 'left' ;
4999
- drawText ( getText ( elMode ) , baseSize , topLine1 , maxWidthTop ) ;
5005
+ drawText ( getText ( getControlValue ( elMode ) == MODE_BARS ? elBandCount : elMode ) , baseSize , topLine1 , maxWidthTop ) ;
5000
5006
drawText ( `Randomize: ${ getText ( elRandomMode ) } ` , baseSize , topLine2 , maxWidthTop ) ;
5001
5007
5002
5008
canvasCtx . textAlign = 'right' ;
0 commit comments