Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Fadecandy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
scanlime
Fadecandy
Commits
42136762
Commit
42136762
authored
11 years ago
by
Micah Elizabeth Scott
Browse files
Options
Downloads
Patches
Plain Diff
Different kind of left-hand wobble, closer to what we wanted
parent
87da0ecc
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/node/midi_particles.coffee
+45
-36
45 additions, 36 deletions
examples/node/midi_particles.coffee
with
45 additions
and
36 deletions
examples/node/midi_particles.coffee
+
45
−
36
View file @
42136762
...
@@ -41,14 +41,21 @@ particleLifetime = 1.0
...
@@ -41,14 +41,21 @@ particleLifetime = 1.0
brightness
=
1.0
brightness
=
1.0
spinRate
=
1.0
spinRate
=
1.0
midiTime
=
0
previousNow
=
0
previousNow
=
0
spinAngle
=
0
spinAngle
=
0
input
.
on
'message'
,
(
deltaTime
,
message
)
->
# Time clock in seconds
clock
=
()
->
0.001
*
new
Date
().
getTime
()
# Midi to frequency
midiToHz
=
(
key
)
->
440
*
Math
.
pow
2
,
(
key
-
69
)
/
12
# Keep time
# Midi note to angle, one rev per octave
midiTime
+=
deltaTime
midiToAngle
=
(
key
)
->
(
2
*
Math
.
PI
/
12
)
*
key
input
.
on
'message'
,
(
deltaTime
,
message
)
->
console
.
log
message
switch
message
[
0
]
switch
message
[
0
]
when
0x80
# Voice 0, note off
when
0x80
# Voice 0, note off
...
@@ -61,7 +68,7 @@ input.on 'message', (deltaTime, message) ->
...
@@ -61,7 +68,7 @@ input.on 'message', (deltaTime, message) ->
info
=
info
=
key
:
key
key
:
key
velocity
:
message
[
2
]
velocity
:
message
[
2
]
timestamp
:
midiTime
timestamp
:
clock
()
# Split keyboard into particles and LFOs
# Split keyboard into particles and LFOs
if
key
>=
60
if
key
>=
60
...
@@ -72,7 +79,7 @@ input.on 'message', (deltaTime, message) ->
...
@@ -72,7 +79,7 @@ input.on 'message', (deltaTime, message) ->
when
0xb0
# Voice 0, Control Change
when
0xb0
# Voice 0, Control Change
switch
message
[
1
]
switch
message
[
1
]
when
7
# "Data entry" slider, brightness
when
7
# "Data entry" slider, brightness
brightness
=
message
[
2
]
*
3
.0
/
127
brightness
=
message
[
2
]
*
2
.0
/
127
when
1
# "Modulation" slider, particle speed
when
1
# "Modulation" slider, particle speed
particleLifetime
=
0.1
+
message
[
2
]
*
2.0
/
127
particleLifetime
=
0.1
+
message
[
2
]
*
2.0
/
127
...
@@ -85,7 +92,7 @@ input.on 'message', (deltaTime, message) ->
...
@@ -85,7 +92,7 @@ input.on 'message', (deltaTime, message) ->
draw
=
()
->
draw
=
()
->
# Time delta calculations
# Time delta calculations
now
=
0.001
*
new
Date
().
getTime
()
now
=
clock
()
timeStep
=
now
-
previousNow
timeStep
=
now
-
previousNow
previousNow
=
now
previousNow
=
now
...
@@ -103,47 +110,49 @@ draw = () ->
...
@@ -103,47 +110,49 @@ draw = () ->
for
p
in
particles
for
p
in
particles
# Angle: Global spin, thne positional mapping to key
# Angle: Global spin, thne positional mapping to key
theta
=
spinAngle
+
(
Math
.
PI
/
5
)
*
p
.
note
.
key
theta
=
midiToAngle
p
.
note
.
key
# Positioned in polar coordinates, on unit circle
# Radius: Particles spawn in center, fly outward
x
=
Math
.
cos
theta
radius
=
3.0
*
(
1
-
p
.
life
)
y
=
Math
.
sin
theta
# Add influence of LFOs
# Positioned in polar coordinates
for
key
,
note
of
lfoNotes
x
=
radius
*
Math
.
cos
theta
y
=
radius
*
Math
.
sin
theta
# Down several octaves, to useful LFO frequencies
# One rainbow per octave
transpose
=
-
12
*
5
hue
=
(
p
.
note
.
key
-
60
+
0.1
)
/
12.0
p
.
color
=
OPC
.
hsv
hue
,
0.3
,
0.8
# Midi note to frequency
# Intensity mapped to velocity, nonlinear
hz
=
440
*
Math
.
pow
2
,
(
note
.
key
-
69
+
transpose
)
/
12
p
.
intensity
=
Math
.
pow
(
p
.
note
.
velocity
/
100
,
3.0
)
*
0.25
*
brightness
# Wobble amplitude driven by LFO
# Falloff gets sharper as the note gets higher
wobbleAmp
=
Math
.
sin
Math
.
PI
*
2
*
now
*
hz
p
.
falloff
=
20
+
(
p
.
note
.
key
-
60
)
*
20
# Wobble angle driven by LFO note and particle life
# Add influence of LFOs
wobbleAngle
=
10.0
*
p
.
life
+
(
Math
.
PI
/
5
)
*
p
.
note
.
key
for
key
,
note
of
lfoNotes
age
=
now
-
note
.
timestamp
hz
=
midiToHz
key
lfoAngle
=
midiToAngle
key
x
+=
wobbleAmp
*
Math
.
cos
wobbleAngle
# Amplitude starts with left hand velocity
y
+=
wobbleAmp
*
Math
.
sin
wobbleAngle
wobbleAmp
=
Math
.
pow
(
note
.
velocity
/
100
,
3.0
)
# Radius: Particles spawn in center, fly outward
# Scale based on particle fuzziness
radius
=
3.0
*
(
1
-
p
.
life
)
wobbleAmp
*=
100.0
/
p
.
falloff
x
*=
radius
y
*=
radius
# Use the XZ plan
e
# Fade over tim
e
p
.
point
=
[
x
,
0
,
y
]
wobbleAmp
/=
1
+
age
# One rainbow per octave
# Wobble
hue
=
(
p
.
note
.
key
-
60
)
/
12.0
wobbleAmp
*=
Math
.
sin
(
p
.
life
*
Math
.
pow
(
3
,
(
p
.
note
.
key
-
35
)
/
12.0
))
p
.
color
=
OPC
.
hsv
hue
,
0.5
,
0.8
# Intensity mapped to velocity, nonlinear
# Wobble angle driven by LFO note and particle life
p
.
intensity
=
Math
.
pow
(
p
.
note
.
velocity
/
100
,
5.0
)
*
brightness
x
+=
wobbleAmp
*
Math
.
cos
lfoAngle
y
+=
wobbleAmp
*
Math
.
sin
lfoAngle
#
Falloff gets sharper as the note gets higher
#
Use the XZ plane
p
.
falloff
=
20
+
(
p
.
note
.
key
-
60
)
*
20
p
.
point
=
[
x
,
0
,
y
]
p
.
life
-=
timeStep
/
particleLifetime
p
.
life
-=
timeStep
/
particleLifetime
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment