Skip to content
Permalink
Browse files

oscillator-pulse: spawn from oscillator shape menu

  • Loading branch information...
mmckegg committed Nov 12, 2017
1 parent 8fd0eee commit e857c2a175b9b3cb18054304c2b005d3ca652e88
@@ -1,18 +1,15 @@
var h = require('lib/h')
var computed = require('mutant/computed')

module.exports = function (node) {
if (node && node.context && node.context.nodeInfo) {
// render whatever the node is when it is passed to the renderNode function
var descriptor = node()
if (node && node.context && node.context.nodeInfo && descriptor) {
var lookup = node.context.nodeInfo.lookup
var nodeType = computed([node], n => n.node)
var nodeInfo = computed([nodeType], n => lookup[node().node])

return computed([nodeInfo], function (info) {
if (info && info.render) {
return info.render(node)
} else {
return h('UnknownNode')
}
})
var info = lookup[descriptor.node]
if (info && info.render) {
return info.render(node)
} else {
return h('UnknownNode')
}
}
}
@@ -2,13 +2,7 @@ module.exports = {
name: 'Oscillator (pulse)',
node: 'source/oscillator-pulse',
group: 'sources',
spawn: {
amp: {
node: 'modulator/adsr',
value: 0.6,
release: 0.01
}
},
spawn: false, // spawned by source/oscillator by setting type
object: require('./object'),
render: require('./view')
}
@@ -2,14 +2,32 @@ var h = require('lib/h')
var Header = require('lib/widgets/header')

var ModRange = require('lib/params/mod-range')
var Select = require('lib/params/select')
var Value = require('mutant/value')
var extend = require('xtend')

var shapeChoices = require('../oscillator/shape-choices')

module.exports = function renderOscillator (node) {
return h('SourceNode -oscillator', [
var shape = Value('pulse')
shape(value => {
if (value !== 'pulse') {
node.set(extend(node(), {
node: 'source/oscillator',
shape: value
}))
}
})

return h('SourceNode -oscillatorPulse', [
Header(node, h('span', [
h('strong', 'Oscillator:'), ' ',
h('span', 'Pulse')
])),
h('ParamList', [
Select(shape, {
options: shapeChoices
}),
ModRange(node.amp, {
title: 'amp',
defaultValue: 1,
@@ -2,6 +2,7 @@ module.exports = [
['Basic Shapes', [
['Sine', 'sine'],
['Square', 'square'],
['Pulse', 'pulse'], // spawns source/oscillator-pulse
['Sawtooth', 'sawtooth'],
['Triangle', 'triangle']
]],
@@ -27,4 +28,4 @@ module.exports = [
['Ow', 'ow'],
['Ooh', 'ooh']
]]
]
]
@@ -3,11 +3,14 @@ var Header = require('lib/widgets/header')

var ModRange = require('lib/params/mod-range')
var Select = require('lib/params/select')
var extend = require('xtend')

var shapeChoices = require('./shape-choices')

module.exports = function renderOscillator (node) {
return h('SourceNode -oscillator', [
return h('SourceNode -oscillator', {
hooks: [SwitchNodeHook(node)]
}, [
Header(node, h('span', [
h('strong', 'Oscillator:'), ' ',
h('span', node.shape)
@@ -50,3 +53,15 @@ module.exports = function renderOscillator (node) {
])
])
}

function SwitchNodeHook (node) {
return function (element) {
return node.shape(value => {
if (value === 'pulse') {
node.set(extend(node(), {
node: 'source/oscillator-pulse'
}))
}
})
}
}

0 comments on commit e857c2a

Please sign in to comment.
You can’t perform that action at this time.