gibber-cc / gibberish

Fast, JavaScript DSP library that creates JIT optimized audio callbacks using code generation techniques
387 stars 35 forks source link

Question about playback callback #8

Closed pitrackster closed 9 years ago

pitrackster commented 9 years ago

Hi ! I'm currently trying to make a metronome using Gibberish which is really simple to do :

m = new Gibberish.Cowbell({ amp:0.5 }).connect();
o = new Gibberish.Sequencer({
  target:m, 
  key:'note',
  durations:[beats(1)]
});

function start(){
    o.start();
}

function stop(){
    o.stop();
}

function changeTempo(){
    Gibberish.Time.bpm = parseInt(document.getElementById('tempo-input').value);
}

Now I would like to show a flashing circle following the BPM, but can't find any method or callback that could help me doing it... Any Idea ?

Thanks.

charlieroberts commented 9 years ago

Hello,

You can create a sequencer that calls a function... just don't specify a target or a key. Example:

a = new Gibberish.Sequencer({
    values:[ function() { console.log( 'test' ) } ],
    durations:[ beats(1) ]
}).start()

Alternatively you could create an object with a method that updates the circle, and then set the target property of the sequencer to the object and the key to identify the method.

Hope that helps! - Charlie

pitrackster commented 9 years ago

Hi ! Thanks a lot ! that is exactly what I was looking for !