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
58d14801
Commit
58d14801
authored
11 years ago
by
Serene H
Browse files
Options
Downloads
Patches
Plain Diff
output key names and reduce computations
parent
6da0a6e3
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitignore
+2
-0
2 additions, 0 deletions
.gitignore
examples/node/midi_particles.coffee
+39
-30
39 additions, 30 deletions
examples/node/midi_particles.coffee
with
41 additions
and
30 deletions
.gitignore
+
2
−
0
View file @
58d14801
.DS_Store
.DS_Store
*.pyc
*.pyc
*.swp
*.swo
This diff is collapsed.
Click to expand it.
examples/node/midi_particles.coffee
+
39
−
30
View file @
58d14801
...
@@ -12,23 +12,18 @@
...
@@ -12,23 +12,18 @@
# Left hand -> Low frequency oscillators (wobble)
# Left hand -> Low frequency oscillators (wobble)
# Right hand -> Particles, shifting in color and pointiness
# Right hand -> Particles, shifting in color and pointiness
#
#
# 2014, Micah Elizabeth Scott &
~k
eroserene
# 2014, Micah Elizabeth Scott &
K
eroserene
#
#
flags
=
require
'flags'
flags
.
defineString
'layout'
,
'../layouts/grid32x16z.json'
,
'LED board layout'
flags
.
defineInteger
'midi'
,
0
,
'MIDI input port'
flags
.
parse
()
# Prepare MIDI input.
# Default MIDI input
# TODO: Intelligently find the right midi port instead of default to 0.
midi
=
require
'midi'
midi
=
require
'midi'
input
=
new
midi
.
input
input
=
new
midi
.
input
input
.
openPort
flags
.
get
(
'midi'
)
input
.
openPort
1
input
.
ignoreTypes
false
,
false
,
false
input
.
ignoreTypes
false
,
false
,
false
# Default OPC output
# Default OPC output
OPC
=
new
require
'./opc'
OPC
=
new
require
'./opc'
model
=
OPC
.
loadModel
flags
.
get
(
'layout'
)
model
=
OPC
.
loadModel
process
.
argv
[
2
]
||
'../layouts/grid32x16z.json'
client
=
new
OPC
'localhost'
,
7890
client
=
new
OPC
'localhost'
,
7890
# Live particles
# Live particles
...
@@ -49,12 +44,15 @@ wobbleAmount = 24.0
...
@@ -49,12 +44,15 @@ wobbleAmount = 24.0
origin
=
[
0
,
0
,
0
]
origin
=
[
0
,
0
,
0
]
# Physics
# Physics
numPhysicsTimesteps
=
1
#
numPhysicsTimesteps =
20 TODO: Re-enable when things become more complex
frameDelay
=
5
frameDelay
=
5
timestepSize
=
0.010
timestepSize
=
0.010
gain
=
0.1
gain
=
0.1
previousNow
=
0
# Derived values
particleDecay
=
timestepSize
/
particleLifetime
# Controlled by the Pitch Transpose Knob
spinAngle
=
0
spinAngle
=
0
# Time clock in seconds
# Time clock in seconds
...
@@ -66,20 +64,30 @@ midiToHz = (key) -> 440 * Math.pow 2, (key - 69) / 12
...
@@ -66,20 +64,30 @@ midiToHz = (key) -> 440 * Math.pow 2, (key - 69) / 12
# Midi note to angle, one rev per octave
# Midi note to angle, one rev per octave
midiToAngle
=
(
key
)
->
(
2
*
Math
.
PI
/
24
)
*
key
midiToAngle
=
(
key
)
->
(
2
*
Math
.
PI
/
24
)
*
key
# Musical Constants
# Boundary between the left-hand and right-hand patterns.
# Boundary between the left-hand and right-hand patterns.
LIMINAL_KEY
=
40
LIMINAL_KEY
=
40
MAX_VELOCITY
=
100
SHARP_NAMES
=
[
'A'
,
'A#'
,
'B'
,
'C'
,
'C#'
,
'D'
,
'D#'
,
'E'
,
'F'
,
'F#'
,
'G'
,
'G#'
]
FLAT_NAMES
=
[
'A'
,
'Bb'
,
'B'
,
'C'
,
'Db'
,
'D'
,
'Eb'
,
'E'
,
'F'
,
'Gb'
,
'G'
,
'Ab'
]
LOWEST_A
=
1
HIGHEST_C
=
124
getKeyName
=
(
key
)
->
FLAT_NAMES
[(
key
-
LOWEST_A
)
%
12
]
input
.
on
'message'
,
(
deltaTime
,
message
)
->
input
.
on
'message'
,
(
deltaTime
,
message
)
->
console
.
log
message
logMsg
=
message
msgType
=
Math
.
floor
parseInt
(
message
[
0
])
/
16
# Examine the 0xF0 byte.
switch
m
essage
[
0
]
switch
m
sgType
when
0x8
0
# Voice 0, note off
when
0x8
# Voice 0, note off
key
=
message
[
1
]
key
=
message
[
1
]
logMsg
+=
' : '
+
getKeyName
key
delete
lfoNotes
[
key
]
delete
lfoNotes
[
key
]
delete
particleNotes
[
key
]
delete
particleNotes
[
key
]
when
0x9
0
# Voice 0, note on
when
0x9
# Voice 0, note on
key
=
message
[
1
]
key
=
message
[
1
]
logMsg
+=
' : '
+
getKeyName
key
info
=
info
=
key
:
key
key
:
key
velocity
:
message
[
2
]
velocity
:
message
[
2
]
...
@@ -91,7 +99,7 @@ input.on 'message', (deltaTime, message) ->
...
@@ -91,7 +99,7 @@ input.on 'message', (deltaTime, message) ->
else
else
lfoNotes
[
key
]
=
info
lfoNotes
[
key
]
=
info
when
0xb
0
# Voice 0, Control Change
when
0xb
# 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
]
*
2.0
/
127
brightness
=
message
[
2
]
*
2.0
/
127
...
@@ -99,12 +107,12 @@ input.on 'message', (deltaTime, message) ->
...
@@ -99,12 +107,12 @@ input.on 'message', (deltaTime, message) ->
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
when
0xe
0
# Voice 0, Pitch Bend
when
0xe
# Voice 0, Pitch Bend
# Default spin 1.0, but allow forward/backward
# Default spin 1.0, but allow forward/backward
spinRate
=
(
message
[
2
]
-
64
)
*
10.0
/
64
spinRate
=
(
message
[
2
]
-
64
)
*
10.0
/
64
console
.
log
logMsg
draw
=
()
->
draw
=
->
# Time delta calculations
# Time delta calculations
now
=
clock
()
now
=
clock
()
...
@@ -141,12 +149,13 @@ draw = ->
...
@@ -141,12 +149,13 @@ draw = ->
# Hop around between almost-opposing colors, eventually going
# Hop around between almost-opposing colors, eventually going
# around the rainbow. These ratios control what kinds of color
# around the rainbow. These ratios control what kinds of color
# schemes we get for different chords.
# schemes we get for different chords. This operates by the circle of
# fifths.
hue
=
(
p
.
note
.
key
-
LIMINAL_KEY
+
0.1
)
*
(
7
/
12.0
)
hue
=
(
p
.
note
.
key
-
LIMINAL_KEY
+
0.1
)
*
(
7
/
12.0
)
p
.
color
=
OPC
.
hsv
hue
,
0.5
,
0.8
p
.
color
=
OPC
.
hsv
hue
,
0.5
,
0.8
# Intensity mapped to velocity, nonlinear
# Intensity mapped to velocity, nonlinear
p
.
intensity
=
Math
.
pow
(
p
.
note
.
velocity
/
100
,
2.0
)
*
0.2
*
brightness
p
.
intensity
=
Math
.
pow
(
p
.
note
.
velocity
/
MAX_VELOCITY
,
2.0
)
*
0.2
*
brightness
# Fade with age
# Fade with age
noteAge
=
now
-
p
.
note
.
timestamp
noteAge
=
now
-
p
.
note
.
timestamp
...
@@ -162,7 +171,7 @@ draw = ->
...
@@ -162,7 +171,7 @@ draw = ->
lfoAngle
=
midiToAngle
key
lfoAngle
=
midiToAngle
key
# Amplitude starts with left hand velocity
# Amplitude starts with left hand velocity
wobbleAmp
=
Math
.
pow
(
note
.
velocity
/
100
,
2.0
)
*
wobbleAmount
wobbleAmp
=
Math
.
pow
(
note
.
velocity
/
MAX_VELOCITY
,
2.0
)
*
wobbleAmount
# Scale based on particle fuzziness
# Scale based on particle fuzziness
wobbleAmp
/=
p
.
falloff
wobbleAmp
/=
p
.
falloff
...
@@ -178,16 +187,16 @@ draw = ->
...
@@ -178,16 +187,16 @@ draw = ->
y
+=
wobbleAmp
*
Math
.
sin
lfoAngle
y
+=
wobbleAmp
*
Math
.
sin
lfoAngle
# Update velocity; use the XZ plane
# Update velocity; use the XZ plane
p
.
velocity
[
0
]
+=
(
x
-
p
.
point
[
0
])
*
(
gain
/
numPhysicsTimesteps
)
p
.
velocity
[
0
]
+=
(
x
-
p
.
point
[
0
])
*
(
gain
)
#
/ numPhysicsTimesteps)
p
.
velocity
[
2
]
+=
(
y
-
p
.
point
[
2
])
*
(
gain
/
numPhysicsTimesteps
)
p
.
velocity
[
2
]
+=
(
y
-
p
.
point
[
2
])
*
(
gain
)
#
/ numPhysicsTimesteps)
# Fixed timestep physics
# Fixed timestep physics
for
i
in
[
1
..
numPhysicsTimesteps
]
# TODO: Re-enable this when it's not just re-adding the delta.
p
.
point
[
0
]
+=
p
.
velocity
[
0
]
# for i in [1 .. numPhysicsTimesteps
]
p
.
point
[
1
]
+=
p
.
velocity
[
1
]
p
.
point
[
0
]
+=
p
.
velocity
[
0
]
p
.
point
[
2
]
+=
p
.
velocity
[
2
]
p
.
point
[
1
]
+=
p
.
velocity
[
1
]
p
.
point
[
2
]
+=
p
.
velocity
[
2
]
p
.
life
-=
timestepSize
/
particleLifetime
p
.
life
-=
particleDecay
# Filter out dead particles
# Filter out dead particles
particles
=
particles
.
filter
(
p
)
->
p
.
life
>
0
particles
=
particles
.
filter
(
p
)
->
p
.
life
>
0
...
...
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