Skip to content

Commit

Permalink
first fb-range implementation in effect (wave)
Browse files Browse the repository at this point in the history
  • Loading branch information
YeonV committed Oct 14, 2021
1 parent b9ddc6b commit 621b648
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 44 deletions.
17 changes: 13 additions & 4 deletions renderer/components/Visualizer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PlayArrow, Stop } from '@material-ui/icons';
import { Button, MenuItem, TextField, Typography, Paper, Box, Slider } from '@material-ui/core';
import ColorPicker from './ColorPicker';
import useStore from '../store/store';
import Effect, { effects } from '../effects';
import Effect, { effects } from '../effects/effects';
import Toggle from './Toggle';
import useVisualizerStyles from './Visualizer.styles';

Expand Down Expand Up @@ -95,7 +95,7 @@ export default function Visualizer({
const [activeRightFb, setActiveRightFb] = useState(-1)
const [playing, setPlaying] = useState(false)
const [flipped, setFlipped] = useState(false)
const [effect, setEffect] = useState("BladePower")
const [effect, setEffect] = useState("BladePower (Left FB)")
const [volume, setVolume] = useState(0)
const [innerVolume, setInnerVolume] = useState(0)

Expand Down Expand Up @@ -165,6 +165,7 @@ export default function Visualizer({
color,
bgColor,
activeFb,
activeRightFb,
volume: volume
}
})
Expand Down Expand Up @@ -316,7 +317,15 @@ export default function Visualizer({
label="Effect"
value={effect}
style={{ width: '50%' }}
onChange={(e) => { setEffect(e.target.value) }}
onChange={(e) => {
if (e.target.value === 'BladeWave (Range)') {
setBgColor({r: 0, g: 0, b:0})
}
if (e.target.value === 'BladePower (Left FB)') {
setActiveRightFb(-1)
}
setEffect(e.target.value)
}}
>
{effects.map((d, i) =>
<MenuItem key={d} value={d}>
Expand All @@ -327,7 +336,7 @@ export default function Visualizer({
</div>
<div style={{ display: 'flex', paddingTop: 10 }}>
<ColorPicker label="COL" color={color} onChange={settingColor} />
{effect !== "BladeWave (Test)" &&
{effect !== "BladeWave (Range)" &&
<ColorPicker label="BG" color={bgColor} onChange={settingBgColor} />
}
<Toggle label="Flip" value={flipped} setValue={settingFlipped} />
Expand Down
47 changes: 47 additions & 0 deletions renderer/effects/effects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
export const effects = [
'BladePower (Left FB)',
'BladeWave (Range)',
'BladeWaveBg (Range)',
]

const BladePower = ({ ampValues, pixel_count, color, bgColor, activeFb, volume }) =>
activeFb > -1
? Array(pixel_count)
.fill([color.r, color.g, color.b])
.fill(
[bgColor.r, bgColor.g, bgColor.b],
(ampValues[activeFb] - volume * 2.55) > 0
? parseInt(pixel_count * ((ampValues[activeFb] - volume * 2.55) / 255))
: 0)
: null

const BladeWave = ({ ampValues, pixel_count, color, bgColor, activeFb, activeRightFb, volume }) =>
[...Array(pixel_count).keys()].map(v => [
((ampValues.slice(activeFb, activeRightFb + 1)[v] - volume * 2.55) / 255) * color.r,
((ampValues.slice(activeFb, activeRightFb + 1)[v] - volume * 2.55) / 255) * color.g,
((ampValues.slice(activeFb, activeRightFb + 1)[v] - volume * 2.55) / 255) * color.b])

const BladeWaveBg = ({ ampValues, pixel_count, color, bgColor, activeFb, activeRightFb, volume }) =>
[...Array(pixel_count).keys()].map(v => [
(((ampValues.slice(activeFb, activeRightFb + 1)[v] - volume * 2.55) / 255) * color.r + bgColor.r) / 2,
(((ampValues.slice(activeFb, activeRightFb + 1)[v] - volume * 2.55) / 255) * color.g + bgColor.g) / 2,
(((ampValues.slice(activeFb, activeRightFb + 1)[v] - volume * 2.55) / 255) * color.b + bgColor.b) / 2])


const Effect = ({ type, config }) => {
switch (type) {
case 'BladePower (Left FB)':
return BladePower(config)

case 'BladeWave (Range)':
return BladeWave(config)

case 'BladeWaveBg (Range)':
return BladeWaveBg(config)

default:
return BladePower(config)
}
}

export default Effect
40 changes: 0 additions & 40 deletions renderer/effects/index.js

This file was deleted.

0 comments on commit 621b648

Please sign in to comment.