Search in sources :

Example 1 with Envelope

use of net.beadsproject.beads.ugens.Envelope in project narchy by automenta.

the class UGen method crossfadeInput.

/**
 * Performs a crossfade from one UGen (which must already be connected) to another. Only works if you
 *
 * @param source        the UGen to crossfade away from (assumed to already be connected), will be disconnected once cross-fade is over.
 * @param destination   the UGen to crossfade towards.
 * @param crossoverTime the time taken.
 */
public synchronized void crossfadeInput(UGen source, final UGen destination, float crossoverTime) {
    removeAllConnections(source);
    // fade the old one out
    Envelope fadeOut = new Envelope(context, 1f);
    Gain gOut = new Gain(context, source.outs, fadeOut);
    fadeOut.add(0f, crossoverTime, new KillTrigger(gOut));
    gOut.in(source);
    in(gOut);
    // fade the new one in
    Envelope fadeIn = new Envelope(context, 0f);
    final Gain gIn = new Gain(context, destination.outs, fadeIn);
    fadeIn.add(1f, crossoverTime, new Auvent() {

        @Override
        public void on(Auvent message) {
            removeAllConnections(gIn);
            in(destination);
        }
    });
    gIn.in(source);
    in(gIn);
}
Also used : KillTrigger(net.beadsproject.beads.events.KillTrigger) Envelope(net.beadsproject.beads.ugens.Envelope) Gain(net.beadsproject.beads.ugens.Gain)

Example 2 with Envelope

use of net.beadsproject.beads.ugens.Envelope in project narchy by automenta.

the class drum_machine_01 method setup.

// construct the synthesizer
public void setup() {
    AudioContext ac = new AudioContext();
    // set up the envelope for kick gain
    kickGainEnvelope = new Envelope(ac, 0.0f);
    // construct the kick WavePlayer
    kick = new WavePlayer(ac, 100.0f, WaveFactory.SINE);
    // set up the filters
    kickFilter = new BiquadFilter(ac, BiquadFilter.BESSEL_LP, 500.0f, 1.0f);
    kickFilter.in(kick);
    // set up the Gain
    kickGain = new Gain(ac, 1, kickGainEnvelope);
    kickGain.in(kickFilter);
    // connect the gain to the main out
    ac.out.in(kickGain);
    // set up the snare envelope
    snareGainEnvelope = new Envelope(ac, 0.0f);
    // set up the snare WavePlayers
    snareNoise = new WavePlayer(ac, 1.0f, WaveFactory.NOISE);
    snareTone = new WavePlayer(ac, 200.0f, WaveFactory.SINE);
    // set up the filters
    snareFilter = new BiquadFilter(ac, BiquadFilter.BP_SKIRT, 2500.0f, 1.0f);
    snareFilter.in(snareNoise);
    snareFilter.in(snareTone);
    // set up the Gain
    snareGain = new Gain(ac, 1, snareGainEnvelope);
    snareGain.in(snareFilter);
    // connect the gain to the main out
    ac.out.in(snareGain);
    // set up the keyboard input
    // MidiKeyboard keys = new MidiKeyboard();
    // keys.addActionListener(new ActionListener(){
    // @Override
    // public void actionPerformed(ActionEvent e)
    // {
    // // if the event is not null
    // if( e != null )
    // {
    // // if the event is a MIDI event
    // if( e.getSource() instanceof ShortMessage)
    // {
    // // get the MIDI event
    // ShortMessage sm = (ShortMessage)e.getSource();
    // 
    // // if the event is a key down
    // if( sm.getCommand() == MidiKeyboard.NOTE_ON && sm.getData2() > 1 )
    // keyDown(sm.getData1());
    // // if the event is a key up
    // else if( sm.getCommand() == MidiKeyboard.NOTE_OFF )
    // keyUp(sm.getData1());
    // }
    // }
    // }
    // });
    ac.start();
    Util.sleep(100000L);
}
Also used : Envelope(net.beadsproject.beads.ugens.Envelope) BiquadFilter(net.beadsproject.beads.ugens.BiquadFilter) AudioContext(net.beadsproject.beads.core.AudioContext) WavePlayer(net.beadsproject.beads.ugens.WavePlayer) Gain(net.beadsproject.beads.ugens.Gain)

Aggregations

Envelope (net.beadsproject.beads.ugens.Envelope)2 Gain (net.beadsproject.beads.ugens.Gain)2 AudioContext (net.beadsproject.beads.core.AudioContext)1 KillTrigger (net.beadsproject.beads.events.KillTrigger)1 BiquadFilter (net.beadsproject.beads.ugens.BiquadFilter)1 WavePlayer (net.beadsproject.beads.ugens.WavePlayer)1