Skip to content

Commit 621b648

Browse files
committed
first fb-range implementation in effect (wave)
1 parent b9ddc6b commit 621b648

File tree

3 files changed

+60
-44
lines changed

3 files changed

+60
-44
lines changed

renderer/components/Visualizer.jsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { PlayArrow, Stop } from '@material-ui/icons';
55
import { Button, MenuItem, TextField, Typography, Paper, Box, Slider } from '@material-ui/core';
66
import ColorPicker from './ColorPicker';
77
import useStore from '../store/store';
8-
import Effect, { effects } from '../effects';
8+
import Effect, { effects } from '../effects/effects';
99
import Toggle from './Toggle';
1010
import useVisualizerStyles from './Visualizer.styles';
1111

@@ -95,7 +95,7 @@ export default function Visualizer({
9595
const [activeRightFb, setActiveRightFb] = useState(-1)
9696
const [playing, setPlaying] = useState(false)
9797
const [flipped, setFlipped] = useState(false)
98-
const [effect, setEffect] = useState("BladePower")
98+
const [effect, setEffect] = useState("BladePower (Left FB)")
9999
const [volume, setVolume] = useState(0)
100100
const [innerVolume, setInnerVolume] = useState(0)
101101

@@ -165,6 +165,7 @@ export default function Visualizer({
165165
color,
166166
bgColor,
167167
activeFb,
168+
activeRightFb,
168169
volume: volume
169170
}
170171
})
@@ -316,7 +317,15 @@ export default function Visualizer({
316317
label="Effect"
317318
value={effect}
318319
style={{ width: '50%' }}
319-
onChange={(e) => { setEffect(e.target.value) }}
320+
onChange={(e) => {
321+
if (e.target.value === 'BladeWave (Range)') {
322+
setBgColor({r: 0, g: 0, b:0})
323+
}
324+
if (e.target.value === 'BladePower (Left FB)') {
325+
setActiveRightFb(-1)
326+
}
327+
setEffect(e.target.value)
328+
}}
320329
>
321330
{effects.map((d, i) =>
322331
<MenuItem key={d} value={d}>
@@ -327,7 +336,7 @@ export default function Visualizer({
327336
</div>
328337
<div style={{ display: 'flex', paddingTop: 10 }}>
329338
<ColorPicker label="COL" color={color} onChange={settingColor} />
330-
{effect !== "BladeWave (Test)" &&
339+
{effect !== "BladeWave (Range)" &&
331340
<ColorPicker label="BG" color={bgColor} onChange={settingBgColor} />
332341
}
333342
<Toggle label="Flip" value={flipped} setValue={settingFlipped} />

renderer/effects/effects.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
export const effects = [
2+
'BladePower (Left FB)',
3+
'BladeWave (Range)',
4+
'BladeWaveBg (Range)',
5+
]
6+
7+
const BladePower = ({ ampValues, pixel_count, color, bgColor, activeFb, volume }) =>
8+
activeFb > -1
9+
? Array(pixel_count)
10+
.fill([color.r, color.g, color.b])
11+
.fill(
12+
[bgColor.r, bgColor.g, bgColor.b],
13+
(ampValues[activeFb] - volume * 2.55) > 0
14+
? parseInt(pixel_count * ((ampValues[activeFb] - volume * 2.55) / 255))
15+
: 0)
16+
: null
17+
18+
const BladeWave = ({ ampValues, pixel_count, color, bgColor, activeFb, activeRightFb, volume }) =>
19+
[...Array(pixel_count).keys()].map(v => [
20+
((ampValues.slice(activeFb, activeRightFb + 1)[v] - volume * 2.55) / 255) * color.r,
21+
((ampValues.slice(activeFb, activeRightFb + 1)[v] - volume * 2.55) / 255) * color.g,
22+
((ampValues.slice(activeFb, activeRightFb + 1)[v] - volume * 2.55) / 255) * color.b])
23+
24+
const BladeWaveBg = ({ ampValues, pixel_count, color, bgColor, activeFb, activeRightFb, volume }) =>
25+
[...Array(pixel_count).keys()].map(v => [
26+
(((ampValues.slice(activeFb, activeRightFb + 1)[v] - volume * 2.55) / 255) * color.r + bgColor.r) / 2,
27+
(((ampValues.slice(activeFb, activeRightFb + 1)[v] - volume * 2.55) / 255) * color.g + bgColor.g) / 2,
28+
(((ampValues.slice(activeFb, activeRightFb + 1)[v] - volume * 2.55) / 255) * color.b + bgColor.b) / 2])
29+
30+
31+
const Effect = ({ type, config }) => {
32+
switch (type) {
33+
case 'BladePower (Left FB)':
34+
return BladePower(config)
35+
36+
case 'BladeWave (Range)':
37+
return BladeWave(config)
38+
39+
case 'BladeWaveBg (Range)':
40+
return BladeWaveBg(config)
41+
42+
default:
43+
return BladePower(config)
44+
}
45+
}
46+
47+
export default Effect

renderer/effects/index.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)