Last active
August 29, 2015 14:02
-
-
Save colinbdclark/a96e4a8a6c54ce6abf0d to your computer and use it in GitHub Desktop.
Flocking MIDI example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
flock.midiAmp = function (velocity) { | |
return velocity / 127; | |
}; | |
flock.midiVibrato = function (value) { | |
return value / 32; | |
}; | |
var synth = flock.synth({ | |
synthDef: { | |
id: "carrier", | |
ugen: "flock.ugen.sinOsc", | |
freq: 440, | |
mul: { | |
id: "mod", | |
ugen: "flock.ugen.sinOsc", | |
freq: 1.0, | |
mul: { | |
ugen: "flock.ugen.env.simpleASR", | |
gate: 0, | |
attack: 0.25, | |
sustain: 1.0, | |
release: 0.5 | |
} | |
} | |
} | |
}); | |
var midiConnection = flock.midi.connection({ | |
// This should only be used if you know the port you want to use | |
// ahead of time. Otherwise, the system.ports object should be bound to a UI | |
// of some kind and the user should be allowed to select their ports. | |
// When a selection has been made, invoke .open() on this connection. | |
// Remember that the whole system is asynchronous, which means you have to wait | |
// for the ready() event to get the current list of ports. | |
openImmediately: true, | |
// This option is highly configurable. In the simplest case, | |
// you can specify a "manufacturer" properity, a port "name" property (e.g. QUNEO), or both. | |
// If you want more complex routings, you can specify "inputs" and "outputs" objects, | |
// which can contain "manufacturer" and "name" properties. This allows | |
// you to route input signals from a different device than the output. | |
// You can even specify arrays for the "input" and "output" properties | |
// if you want to listen for MIDI message on multiple ports or send broadcast | |
// messages to multiple device. | |
// But for most simple cases, you'll just want to refer to the device either | |
// by port name or manufacturer. | |
ports: { | |
manufacturer: "korg" | |
}, | |
listeners: { | |
noteOn: function (msg) { | |
synth.set({ | |
"carrier.freq": flock.midiFreq(msg.note), | |
"mod.mul.gate": 1.0, | |
"mod.mul.sustain": flock.midiAmp(msg.velocity) | |
}); | |
}, | |
noteOff: function () { | |
synth.set("mod.mul.gate", 0); | |
}, | |
control: function (msg) { | |
synth.set({ | |
"mod.freq": flock.midiVibrato(msg.value) | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment