/** Use the sliders to chop up this looping sample from Again and Again by The Bird and The Bee. The Small, Medium, and Large buttons will change the max value of each slider to let you play with slicing up the sample at different granularities.

Use the LoopBegin and LoopEnd sliders to set the beginning and ending loop points within the sample. When you move either loop point slider, the other's range will be adjusted such that you can't put the end loop point before the begin loop point. */ import controlP5.*; import ddf.minim.signals.*; import ddf.minim.*; import ddf.minim.analysis.*; import ddf.minim.effects.*; import ddf.minim.ugens.*; Minim minim; AudioOutput out; FilePlayer again; GranulateSteady chopper; Constant grainLength; Constant grainSpacing; Constant grainFade; ControlP5 gui; Slider lengthSlider; Slider spacingSlider; Slider fadeSlider; Slider loopBegin; Slider loopEnd; void setup() { size( 640, 480 ); minim = new Minim(this); out = minim.getLineOut(); again = new FilePlayer( minim.loadFileStream("again_loop.aif", 1024, true) ); again.loop(); chopper = new GranulateSteady(); grainLength = new Constant(0.01f); grainSpacing = new Constant(0.02f); grainFade = new Constant(0.0025f); grainLength.patch( chopper.grainLen ); grainSpacing.patch( chopper.spaceLen ); grainFade.patch( chopper.fadeLen ); again.patch( chopper ); chopper.patch( out ); gui = new ControlP5(this); gui.addBang("Small", 10, 200, 30, 30); gui.addBang("Medium", 10, 250, 30, 30); gui.addBang("Large", 10, 300, 30, 30); float gmin = 0.0f; float gmax = 0.01f; float ghmax = gmax * 0.5f; lengthSlider = gui.addSlider("GrainLength", gmin, gmax, ghmax, 100, 200, 30, 250); lengthSlider.setSliderMode(Slider.FLEXIBLE); spacingSlider = gui.addSlider("GrainSpacing", gmin, gmax, ghmax, 200, 200, 30, 250); spacingSlider.setSliderMode(Slider.FLEXIBLE); fadeSlider = gui.addSlider("GrainFade", 0.f, ghmax, ghmax / 2.f, 300, 200, 30, 250); fadeSlider.setSliderMode(Slider.FLEXIBLE); loopBegin = gui.addSlider("LoopBegin", 0.f, again.length() - 100, 0.f, 400, 200, 30, 250); loopBegin.setSliderMode(Slider.FLEXIBLE); loopEnd = gui.addSlider("LoopEnd", 100.f, again.length(), again.length(), 500, 200, 30, 250); loopEnd.setSliderMode(Slider.FLEXIBLE); } public void GrainLength( float value ) { grainLength.setConstant( value ); fadeSlider.setBroadcast( false ); fadeSlider.setMax( value / 2.f ); fadeSlider.setBroadcast( true ); grainFade.setConstant( fadeSlider.value() ); } public void GrainSpacing( float value ) { grainSpacing.setConstant( value ); } public void GrainFade( float value ) { grainFade.setConstant( value ); } public void Small() { lengthSlider.setMax( 0.01f ); spacingSlider.setMax( 0.01f ); fadeSlider.setMax( 0.005f ); } public void Medium() { lengthSlider.setMax( 0.1f ); spacingSlider.setMax( 0.1f ); fadeSlider.setMax( 0.05f ); } public void Large() { lengthSlider.setMax( 1.f ); spacingSlider.setMax( 1.f ); fadeSlider.setMax( 0.5f ); } public void LoopBegin( float value ) { loopEnd.setBroadcast( false ); loopEnd.setMin( value + 100 ); loopEnd.setBroadcast( true ); again.setLoopPoints( (int)value, (int)loopEnd.value() ); } public void LoopEnd( float value ) { loopBegin.setBroadcast( false ); loopBegin.setMax( value - 100 ); loopBegin.setBroadcast( true ); again.setLoopPoints( (int)loopBegin.value(), (int)value ); } void draw() { background( 0 ); stroke( 255 ); for( int i = 0; i < out.bufferSize() - 1; i++ ) { float x1 = map( i, 0, out.bufferSize(), 0, width ); float x2 = map( i+1, 0, out.bufferSize(), 0, width ); line( x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50); line( x1, 150 + out.right.get(i)*50, x2, 150 + out.right.get(i+1)*50); } } void stop() { out.close(); minim.stop(); super.stop(); }