summaryrefslogtreecommitdiff
path: root/public/js
diff options
context:
space:
mode:
Diffstat (limited to 'public/js')
-rw-r--r--public/js/grid.js57
1 files changed, 55 insertions, 2 deletions
diff --git a/public/js/grid.js b/public/js/grid.js
index a646192..eeae315 100644
--- a/public/js/grid.js
+++ b/public/js/grid.js
@@ -6,14 +6,67 @@ var latency = 1000 * bufferSize / sampleRate;
var audioletReady = false;
var samples = [
- 'KickDrum0001.wav', 'Closed Hihat0001.wav', 'Open Hihat0001.wav', 'Clap.wav'
- 'Clav.wav', 'Mid Tom0001.wav', 'Rimshot.wav', 'SnareDrum0001.wav'
+ 'KickDrum0001.wav',
+ // 'Closed Hihat0001.wav', 'Open Hihat0001.wav', 'Clap.wav'
+ // 'Clav.wav', 'Mid Tom0001.wav', 'Rimshot.wav', 'SnareDrum0001.wav'
];
+function Sampler (audiolet, url) {
+ var base = this;
+ this.audiolet = audiolet;
+
+ // first get the sample and load it into a buffer
+ var buffer = new AudioletBuffer(1, 0);
+ buffer.load(sample, false);
+
+ // connect the buffer to a player and set up the objects we need
+ this.trigger = new TriggerControl(this.audiolet);
+ this.player = new BufferPlayer(this.audiolet, buffer, 1, 0, 0);
+ this.gain = new Gain(this.audiolet, 0.80);
+
+ // trigger -> player -> gain -> OUTPUT
+ trigger.connect(player, 0, 1);
+ player.connect(gain);
+ gain.connect(this.audiolet.output);
+
+ this.mute = function(){
+ base.gain.setValue(0);
+ }
+ this.unmute = function(){
+ base.gain.setValue(0.80);
+ }
+}
+
+function Sequencer (audiolet, instrument) {
+ var base = this;
+ this.instrument = instrument;
+ this.pattern = [0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0];
+
+ // building a sequencer ...
+ // this makes each note a sixteenth note, and sets up an empty bar
+ var durations = new PSequence([0.25], Infinity);
+ var sequence = new PSequence(this.pattern, Infinity);
+
+ this.audiolet.scheduler.play([sequence], durations, trigger);
+
+ function trigger (note, duration) {
+ if (note == 1) {
+ this.instrument.trigger.setValue(1);
+ }
+ }
+}
+
function AudioletApp () {
this.audiolet = new Audiolet(sampleRate, 2, bufferSize);
this.audiolet.scheduler.setTempo(90);
+ this.sequencers = [];
+ for (var i in samples) {
+ var sample = "/wav/" + samples[i];
+ var sampler = new Sampler(this.audiolet, sample);
+ var sequencer = new Sequencer(this.audiolet, sampler);
+ this.sequencers.push(sequencer);
+ }
}