Skip to content

Commit

Permalink
refactor: code review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Maciej Makowski committed Jul 25, 2024
1 parent 1e61c13 commit 276d5f0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 29 deletions.
2 changes: 1 addition & 1 deletion android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ add_library(react-native-audio-context SHARED
src/main/cpp/OnLoad.cpp
src/main/cpp/AudioContext
src/main/cpp/OscillatorNode
src/main/cpp/AudioDestinationNode
src/main/cpp/AudioDestinationNode.h
src/main/cpp/AudioNode
src/main/cpp/GainNode

Expand Down
1 change: 0 additions & 1 deletion android/src/main/cpp/AudioDestinationNode.cpp

This file was deleted.

52 changes: 25 additions & 27 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,27 @@ const App = () => {
gainRef.current.connect(destination);
};

const handleSliderChange = (
value: number[],
defaultValue: number,
setValue: (value: number) => void,
ref: React.MutableRefObject<{ [key: string]: any } | null>,
propName: string
) => {
const newValue = value[0] || defaultValue;
setValue(newValue);
if (ref.current) {
ref.current[propName] = newValue;
const handleGainChange = (value: number[]) => {
const newValue = value[0] || 0.0;
setGain(newValue);
if (gainRef.current) {
gainRef.current.gain = newValue;
}
};

const handleFrequencyChange = (value: number[]) => {
const newValue = value[0] || 440;
setFrequency(newValue);
if (oscillatorRef.current) {
oscillatorRef.current.frequency = newValue;
}
};

const handleDetuneChange = (value: number[]) => {
const newValue = value[0] || 0;
setDetune(newValue);
if (oscillatorRef.current) {
oscillatorRef.current.detune = newValue;
}
};

Expand Down Expand Up @@ -83,28 +93,18 @@ const App = () => {
<Slider
containerStyle={styles.slider}
value={gain}
onValueChange={(value) =>
handleSliderChange(value, 0.0, setGain, gainRef, 'gain')
}
onValueChange={handleGainChange}
minimumValue={0.0}
maximumValue={1.0}
step={0.1}
step={0.01}
/>
</View>
<View style={styles.container}>
<Text>Frequency: {frequency.toFixed(0)}</Text>
<Slider
containerStyle={styles.slider}
value={frequency}
onValueChange={(value) =>
handleSliderChange(
value,
440,
setFrequency,
oscillatorRef,
'frequency'
)
}
onValueChange={handleFrequencyChange}
minimumValue={120}
maximumValue={1200}
step={10}
Expand All @@ -115,9 +115,7 @@ const App = () => {
<Slider
containerStyle={styles.slider}
value={detune}
onValueChange={(value) =>
handleSliderChange(value, 0, setDetune, oscillatorRef, 'detune')
}
onValueChange={handleDetuneChange}
minimumValue={0}
maximumValue={100}
step={1}
Expand Down

0 comments on commit 276d5f0

Please sign in to comment.