8000 Feature/lfo phase by funwithtriangles · Pull Request #90 · nudibranchrecords/hedron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Feature/lfo phase #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions example-projects/trig/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"nodes":{"sceneCrossfader":{"id":"sceneCrossfader","value":0,"inputLinkIds":[],"shotCount":0,"connectedMacroIds":[],"title":"Scene Crossfader","type":"param"},"viewerMode":{"id":"viewerMode","value":"mix","inputLinkIds":[],"shotCount":0,"connectedMacroIds":[],"title":"Viewer Mode","type":"select","options":[{"value":"mix","label":"Mix"},{"value":"A","label":"A"},{"value":"B","label":"B"}]},"audioNormalizeLevels":{"id":"audioNormalizeLevels","value":0.5,"inputLinkIds":[],"shotCount":0,"connectedMacroIds":[],"title":"Normalize Levels","type":"param"},"audioLevelsFalloff":{"id":"audioLevelsFalloff","value":1,"inputLinkIds":[],"shotCount":0,"connectedMacroIds":[],"title":"Levels Falloff","type":"param"},"4127fmo":{"id":"4127fmo","value":0.004277569313096086,"inputLinkIds":["26gjlp1"],"shotCount":0,"connectedMacroIds":[],"title":"Pos X","type":"param","key":"posX","openedLinkId":"26gjlp1","activeInputLinkId":"26gjlp1"},"1tuv4x5":{"id":"1tuv4x5","value":0.4369348682670615,"inputLinkIds":["iv80n1l"],"shotCount":0,"connectedMacroIds":[],"title":"Pos Y","type":"param","key":"posY","openedLinkId":"iv80n1l","activeInputLinkId":"iv80n1l"},"wdhgvg2":{"id":"wdhgvg2","value":0.5,"inputLinkIds":[],"shotCount":0,"connectedMacroIds":[],"title":"Pos Z","type":"param","key":"posZ"},"71ftemb":{"id":"71ftemb","value":0,"inputLinkIds":[],"shotCount":0,"connectedMacroIds":[],"key":"threshold","title":"Threshold","passToNext":false,"subNode":true},"grm7m9i":{"id":"grm7m9i","value":0,"inputLinkIds":[],"shotCount":0,"connectedMacroIds":[],"key":"range","title":"Lower Range","passToNext":true,"subNode":true},"fsdfv7n":{"id":"fsdfv7n","value":1,"inputLinkIds":[],"shotCount":0,"connectedMacroIds":[],"key":"range","title":"Upper Range","passToNext":false,"subNode":true},"3meb0s9":{"id":"3meb0s9","value":"sine","inputLinkIds":[],"shotCount":0,"connectedMacroIds":[],"title":"Shape","key":"shape","type":"select","subNode":true,"options":[{"value":"sine","label":"Sine"},{"value":"square","label":"Square"},{"value":"sawtooth","label":"Sawtooth"},{"value":"rSawtooth","label":"Revese Sawtooth"},{"value":"triangle","label":"Triangle"},{"value":"noise","label":"Noise"}]},"e0tqe94":{"id":"e0tqe94","value":0.25,"inputLinkIds":[],"shotCount":0,"connectedMacroIds":[],"title":"Rate","key":"rate","type":"select","subNode":true,"options":[{"value":32,"label":"32"},{"value":16,"label":"16"},{"value":8,"label":"8"},{"value":4,"label":"4"},{"value":2,"label":"2"},{"value":1,"label":"1"},{"value":0.5,"label":"1/2"},{"value":0.25,"label":"1/4"},{"value":0.125,"label":"1/8"},{"value":0.0625,"label":"1/16"},{"value":0.03125,"label":"1/32"}]},"8ku58x7":{"id":"8ku58x7","value":0,"inputLinkIds":[],"shotCount":0,"connectedMacroIds":[],"title":"Phase","key":"phase","subNode":true},"acbon8j":{"id":"acbon8j","value":0,"inputLinkIds":[],"shotCount":0,"connectedMacroIds":[],"key":"threshold","title":"Threshold","passToNext":false,"subNode":true},"b8yb2ym":{"id":"b8yb2ym","value":0,"inputLinkIds":[],"shotCount":0,"connectedMacroIds":[],"key":"range","title":"Lower Range","passToNext":true,"subNode":true},"abb5anj":{"id":"abb5anj","value":1,"inputLinkIds":[],"shotCount":0,"connectedMacroIds":[],"key":"range","title":"Upper Range","passToNext":false,"subNode":true},"6e1mta6":{"id":"6e1mta6","value":"sine","inputLinkIds":[],"shotCount":0,"connectedMacroIds":[],"title":"Shape","key":"shape","type":"select","subNode":true,"options":[{"value":"sine","label":"Sine"},{"value":"square","label":"Square"},{"value":"sawtooth","label":"Sawtooth"},{"value":"rSawtooth","label":"Revese Sawtooth"},{"value":"triangle","label":"Triangle"},{"value":"noise","label":"Noise"}]},"72p8iov":{"id":"72p8iov","value":0.25,"inputLinkIds":[],"shotCount":0,"connectedMacroIds":[],"title":"Rate","key":"rate","type":"select","subNode":true,"options":[{"value":32,"label":"32"},{"value":16,"label":"16"},{"value":8,"label":"8"},{"value":4,"label":"4"},{"value":2,"label":"2"},{"value":1,"label":"1"},{"value":0.5,"label":"1/2"},{"value":0.25,"label":"1/4"},{"value":0.125,"label":"1/8"},{"value":0.0625,"label":"1/16"},{"value":0.03125,"label":"1/32"}]},"3dpgn03":{"id":"3dpgn03","value":0.25,"inputLinkIds":[],"shotCount":0,"connectedMacroIds":[],"title":"Phase","key":"phase","subNode":true}},"scenes":{"items":{"doajdmy":{"id":"doajdmy","title":"Circle","selectedSketchId":"v66udcf","sketchIds":["v66udcf"],"linkableActionIds":{"addToA":"bxrvwbs","addToB":"lh468lq","addToActive":"4uw4m8l","addToOpposite":"j27mose","clear":"u566l3e"}}},"currentSceneId":"doajdmy","channels":{"A":"doajdmy","B":false}},"sketches":{"v66udcf":{"title":"Point","moduleId":"point","paramIds":["4127fmo","1tuv4x5","wdhgvg2"],"shotIds":[],"openedNodes":{"param":"1tuv4x5"}}},"project":{"filePath":"/Users/alex/Sites/GitHub/hedron/example-projects/trig/project.json","sketchesPath":"/Users/alex/Sites/GitHub/hedron/example-projects/trig/sketches","errors":[],"errorPopup":false},"inputs":{"audio_0":{"value":0.09192983671719823,"assignedLinkIds":[]},"audio_1":{"value":0.3920417479652838,"assignedLinkIds":[]},"audio_2":{"value":0.2800157346788512,"assignedLinkIds":[]},"audio_3":{"value":0.31956442755083536,"assignedLinkIds":[]},"lfo":{"value":218.91666666666666,"assignedLinkIds":["26gjlp1","iv80n1l"]}},"inputLinks":{"26gjlp1":{"title":"lfo","input":{"id":"lfo"},"id":"26gjlp1","nodeId":"4127fmo","nodeType":"param","modifierIds":["71ftemb","grm7m9i","fsdfv7n"],"lfoOptionIds":["3meb0s9","e0tqe94","8ku58x7"],"midiOptionIds":[],"linkableActions":{"toggleActivate":"27wt27g"},"linkType":"node"},"iv80n1l":{"title":"lfo","input":{"id":"lfo"},"id":"iv80n1l","nodeId":"1tuv4x5","nodeType":"param","modifierIds":["acbon8j","b8yb2ym","abb5anj"],"lfoOptionIds":["6e1mta6","72p8iov","3dpgn03"],"midiOptionIds":[],"linkableActions":{"toggleActivate":"p95mpjp"},"linkType":"node"}},"linkableActions":{"bxrvwbs":{"id":"bxrvwbs","action":{"type":"R_SCENE_SELECT_CHANNEL","payload":{"id":"doajdmy","channel":"A"}},"inputLinkIds":[]},"lh468lq":{"id":"lh468lq","action":{"type":"R_SCENE_SELECT_CHANNEL","payload":{"id":"doajdmy","channel":"B"}},"inputLinkIds":[]},"4uw4m8l":{"id":"4uw4m8l","action":{"type":"U_SCENE_SELECT_CHANNEL","payload":{"id":"doajdmy","type":"active"}},"inputLinkIds":[]},"j27mose":{"id":"j27mose","action":{"type":"U_SCENE_SELECT_CHANNEL","payload":{"id":"doajdmy","type":"opposite"}},"inputLinkIds":[]},"u566l3e":{"id":"u566l3e","action":{"type":"SCENE_CLEAR_CHANNEL","payload":{"id":"doajdmy"}},"inputLinkIds":[]},"27wt27g":{"id":"27wt27g","action":{"type":"NODE_ACTIVE_INPUT_LINK_TOGGLE","payload":{"nodeId":"4127fmo","linkId":"26gjlp1"}},"inputLinkIds":[]},"p95mpjp":{"id":"p95mpjp","action":{"type":"NODE_ACTIVE_INPUT_LINK_TOGGLE","payload":{"nodeId":"1tuv4x5","linkId":"iv80n1l"}},"inputLinkIds":[]}},"macros":{"learningId":false,"items":{}},"ui":{"panelWidths":{"left":39.47906026557712},"isEditing":false,"openedNode":false},"router":{"location":{"pathname":"/scenes/view/doajdmy","search":"","hash":"","key":"le4hx2"}},"settings":{"clockGenerated":true,"clockBpm":120,"aspectW":16,"aspectH":9,"antialias":false,"throttledFPS":60},"form":{}}
30 changes: 30 additions & 0 deletions example-projects/trig/sketches/point/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/** HEDRON TIP **
The config.js defines how the sketch file is used by Hedron.
**/

module.exports = {
// Default title when sketch is loaded in (can be changed by user)
defaultTitle: 'Point',
// Params are values between 0 and 1 that can be manipulated by the user
// these values are sent to the sketch every frame
// e.g. Speed, scale, colour
params: [
{
key: 'posX', // needs to be unique
title: 'Pos X', // should be human
defaultValue: 0.5 // must be between 0 and 1
},
{
key: 'posY',
title: 'Pos Y',
defaultValue: 0.5
},
{
key: 'posZ',
title: 'Pos Z',
defaultValue: 0.5
}
],
shots: [
]
}
24 changes: 24 additions & 0 deletions example-projects/trig/sketches/point/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const THREE = require('three')

class Point {

constructor (scene, meta, params) {
this.root = new THREE.Group()
const geom = new THREE.IcosahedronGeometry(100)
const mat = new THREE.MeshNormalMaterial()
this.mesh = new THREE.Mesh(geom, mat)

this.root.add(this.mesh)
}

update (params, time, frameDiff, allParams) {
const rad = 1500

this.mesh.position.x = (rad * params.posX) - rad / 2
this.mesh.position.y = (rad * params.posY) - rad / 2
this.mesh.position.z = (rad * params.posZ) - rad / 2
}

}

module.exports = Point
5 changes: 3 additions & 2 deletions src/store/inputs/_test/sagas.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,13 @@ test('(Saga) handleInput (lfo)', (t) => {

const optionValues = {
shape: 'sine',
rate: 2
rate: 2,
phase: 0.25
}

t.deepEqual(
generator.next(optionValues).value,
call(lfoProcess, 0.555, 'sine', 2),
call(lfoProcess, 0.555, 'sine', 2, 0.25),
'3. get value after going through first modifier'
)

Expand Down
2 changes: 1 addition & 1 deletion src/store/inputs/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function* handleInput (action) {

if (p.inputId === 'lfo') {
let o = yield select(getNodesValues, links[i].lfoOptionIds)
value = yield call(lfoProcess, value, o.shape, o.rate)
value = yield call(lfoProcess, value, o.shape, o.rate, o.phase)
}

if (links[i].modifierIds && links[i].modifierIds.length) {
Expand Down
8 changes: 8 additions & 0 deletions src/utils/lfoGenerateOptions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ export default () => {
label: '1/32'
}
]
},
{
title: 'Phase',
id: uid(),
key: 'phase',
value: 0,
inputLinkIds: [],
subNode: true
}
]
}
22 changes: 22 additions & 0 deletions src/utils/lfoProcess/_test/lfoProcess.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import test from 'tape'
import lfoProcess from '../'

const PI2 = Math.PI * 2

const roundFix = v => Math.round(v * 10000000000) / 10000000000

test('(Util) lfoProcess - get sin value when using sine', (t) => {
const actual = lfoProcess(0.123, 'sine', 1, 0)
const expected = Math.sin(0.123 * PI2) * 0.5 + 0.5

t.equal(roundFix(actual), roundFix(expected))
t.end()
})

test('(Util) lfoProcess - get cos value when using sine and phase of 0.25', (t) => {
const actual = lfoProcess(0.123, 'sine', 1, 0.25)
const expected = Math.cos(0.123 * PI2) * 0.5 + 0.5

t.equal(roundFix(actual), roundFix(expected))
t.end()
})
7 changes: 4 additions & 3 deletions src/utils/lfoProcess/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import OneDimensionalNoise from '../oneDimensionalNoise'
const Noise = new OneDimensionalNoise()
const PI2 = Math.PI * 2

export default (delta, shape, rate) => {
let x = delta * rate
export default (delta, shape, rate, phase) => {
const x = delta * rate + phase
let y

switch (shape) {
case 'sine':
y = Math.cos(x * 6.28318530718) * 0.5 + 0.5
y = Math.sin(x * PI2) * 0.5 + 0.5
break
case 'sawtooth':
y = x % 1
Expand Down
0