This repository has been archived by the owner on Dec 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
/
PrimaryLight.js
132 lines (110 loc) · 3.41 KB
/
PrimaryLight.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import React from 'react';
import { connect } from 'react-redux';
import { useSpring, animated } from 'react-spring/three';
import { getColorForItem } from '../../helpers/colors.helpers';
import { getCursorPositionInBeats } from '../../reducers/navigation.reducer';
import { convertMillisecondsToBeats } from '../../helpers/audio.helpers';
import { getUsableProcessingDelay } from '../../reducers/user.reducer';
import { getTracks } from '../../reducers/editor-entities.reducer/events-view.reducer';
import useOnChange from '../../hooks/use-on-change.hook';
import {
findMostRecentEventInTrack,
getSpringConfigForLight,
} from './Preview.helpers';
import Glow from './Glow';
const ON_PROPS = { emissiveIntensity: 0.75, opacity: 0.75 };
const OFF_PROPS = { emissiveIntensity: 0, opacity: 0 };
const BRIGHT_PROPS = { emissiveIntensity: 1, opacity: 1 };
const PrimaryLight = ({ song, isPlaying, isBlooming, lastEvent }) => {
// TODO: laser beams for along the side and maybe along the bottom too?
const status = lastEvent ? lastEvent.type : 'off';
const lastEventId = lastEvent ? lastEvent.id : null;
const color =
status === 'off' ? '#000000' : getColorForItem(lastEvent.colorType, song);
const springConfig = getSpringConfigForLight(
[ON_PROPS, OFF_PROPS, BRIGHT_PROPS],
status
);
useOnChange(() => {
if (!isPlaying) {
return;
}
const statusShouldReset = status === 'flash' || status === 'fade';
springConfig.reset = statusShouldReset;
}, lastEventId);
const spring = useSpring(springConfig);
const z = -85;
const hatSideLength = 5;
const hatThickness = 0.5;
return (
<>
<group position={[0, 0, z]} rotation={[0, 0, -Math.PI * 0.25]}>
<mesh position={[0, hatSideLength / 2 + hatThickness / 2, 0]}>
<boxGeometry
attach="geometry"
args={[hatSideLength, hatThickness, hatThickness]}
/>
<animated.meshLambertMaterial
attach="material"
emissive={color}
transparent
{...spring}
/>
</mesh>
<mesh
position={[
-hatSideLength / 2 + hatThickness / 2,
hatThickness / 2,
0,
]}
rotation={[0, 0, Math.PI * 0.5]}
>
<boxGeometry
attach="geometry"
args={[hatSideLength - hatThickness, hatThickness, hatThickness]}
/>
<animated.meshLambertMaterial
attach="material"
emissive={color}
transparent
{...spring}
/>
</mesh>
</group>
<Glow
color={color}
x={0}
y={0}
z={z}
size={40}
status={status}
lastEventId={lastEvent ? lastEvent.id : null}
isPlaying={isPlaying}
isBlooming={isBlooming}
/>
</>
);
};
const mapStateToProps = (state, { song }) => {
if (!song) {
return;
}
const trackId = 'primaryLight';
const tracks = getTracks(state);
const events = tracks[trackId];
const currentBeat = getCursorPositionInBeats(state);
const processingDelay = getUsableProcessingDelay(state);
const processingDelayInBeats = convertMillisecondsToBeats(
processingDelay,
song.bpm
);
const lastEvent = findMostRecentEventInTrack(
events,
currentBeat,
processingDelayInBeats
);
return {
lastEvent,
};
};
export default connect(mapStateToProps)(PrimaryLight);