Minim help for changing speed for Sampler

Hi folks, I’ve been trying to build a midiDrum program for a while now. I got the pads to work with AudioSamples but I just switched to using UGens so that I can apply effects and change the speed of the samples. This code will play, but it gets very out of whack in terms of speed and I’m at a loss for next steps. The documentation for UGENs mostly puts effects on Oscil instead of Sampler. I find the documentation rather opaque. The Fields and Methods have no examples. Can anyone help troubleshoot or point me to better documentation or tutorials?

I’m trying my best to format the code below ( selecting it and clicking the </>)I hope this works. Many thanks in advance.

import themidibus.*;
MidiBus myBus;
float cc[] = new float[256]; 

import ddf.minim.*;
import ddf.minim.spi.*; // for AudioRecordingStream
import ddf.minim.ugens.*;
import ddf.minim.effects.*;

Minim minim;
TickRate rateControl;
static final int QTY = 16;
final Sampler[] samples = new Sampler[QTY];

AudioOutput out;
int index;
int nota; 


void setup()
{
  // setup the size of the app
  // size(640, 200);
  fullScreen();
  myBus = new MidiBus(this, "Port A", "Port A");
  minim = new Minim(this);
  noCursor();
  // create our Minim object for loading audio
  minim = new Minim(this);
  out   = minim.getLineOut();                            
  // this opens the file and puts it in the "play" state.                           
  samples[0] = new Sampler( "Kick Verb Databenders.wav", 1, minim );
  samples[1] = new Sampler ("Sub Short Databenders.wav", 1, minim);
  samples[2] = new Sampler("Rise FM Synare.wav", 1, minim);
  samples[3] = new Sampler("Tone Synare Res.wav", 1, minim);
  samples[4] = new Sampler("Snare Lo 2 Databenders.wav", 1, minim);
  samples[5] = new Sampler("FingerClick Tube.wav", 1, minim);
  samples[6] = new Sampler("WooshReversePipe DoubleSpeed.wav", 1, minim);
  samples[7] = new Sampler("Bleeps.wav", 1, minim);
  samples[8] = new Sampler("Mouth Pop.wav", 1, minim);
  samples[9] = new Sampler("Gun Shuck Short Clean.wav", 1, minim);
  samples[10] = new Sampler("Clap 808 Clean.wav", 1, minim);
  samples[11] = new Sampler("Wine Glass Metal.wav", 1, minim);
  samples[12] = new Sampler("Bell Modular Tight Glitch.wav", 1, minim);
  samples[13] = new Sampler("Clap Modular Alien Voice 05.wav", 1, minim);
  samples[14] = new Sampler("BD Modular Crushed Noise 04.wav", 1, minim);
  samples[15] = new Sampler("Cymbal 808 Clean Short.wav", 1, minim);
  // this creates a TickRate UGen with the default playback speed of 1.
  // ie, it will sound as if the file is patched directly to the output
  rateControl = new TickRate(1.f);

  // get a line out from Minim. It's important that the file is the same audio format 
  // as our output (i.e. same sample rate, number of channels, etc).
  samples[0].patch( out );

  // patch the file player through the TickRate to the output.
  rateControl.setInterpolation( true );
}







// draw is run many times
void draw()
{

  // change the rate control value based on mouse position
  float rate = map(cc[14], 0, 127, .99f, 2.99f);
  rateControl.value.setLastValue(rate);



  // erase the window to black
  background( 0 );
  // draw using a white stroke
  stroke( 255 );
  // draw the waveforms
  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 );
    // draw a line from one buffer position to the next for both channels
    line( x1, height/2  - out.left.get(i)*20, x2, height/2  - out.left.get(i+1)*20);
  }
}

void noteOn(int channel, int pitch, int velocity)
{ 
  nota = pitch;

  if ( nota == 36 ) { 
    samples[0].trigger();
    samples[0].patch(rateControl).patch(out);
  }
  if ( nota == 37 ) { 
    samples[1].trigger();
    samples[2].patch(rateControl).patch(out);
  }
  if ( nota == 38 ) { 
    samples[2].trigger();
    samples[2].patch(rateControl).patch(out);
  }
  if ( nota == 39 ) { 
    samples[3].trigger();
    samples[3].patch(rateControl).patch(out);
  }
  if ( nota == 40 ) { 
    samples[4].trigger();
    samples[4].patch(rateControl).patch(out);
  }
  if ( nota == 41 ) { 
    samples[5].trigger();
    samples[5].patch(rateControl).patch(out);
  }
  if ( nota == 42 ) { 
    samples[6].trigger();
    samples[6].patch(rateControl).patch(out);
  }
  if ( nota == 43 ) { 
    samples[7].trigger();
    samples[7].patch(rateControl).patch(out);
  }
  if ( nota == 44 ) {
    samples[8].trigger();
    samples[8].patch(rateControl).patch(out);
  }
  if ( nota == 45 ) { 
    samples[9].trigger();
    samples[9].patch(rateControl).patch(out);
  }
  if ( nota == 46 ) { 
    samples[10].trigger();
    samples[10].patch(rateControl).patch(out);
  }
  if ( nota == 47 ) { 
    samples[11].trigger();
    samples[11].patch(rateControl).patch(out);
  }
  if ( nota == 48 ) { 
    samples[12].trigger();
    samples[12].patch(rateControl).patch(out);
  }
  if ( nota == 49 ) { 
    samples[13].trigger();
    samples[13].patch(rateControl).patch(out);
  }
  if ( nota == 50 ) { 
    samples[14].trigger();
    samples[14].patch(rateControl).patch(out);
  }
  if ( nota == 51 ) { 
    samples[15].trigger();
    samples[15].patch(rateControl).patch(out);
  }
}
void controllerChange(int channel, int number, int value) {
  println();
  println("Controller Change:");  //
  println("--------");            //
  println("Channel:"+channel);    //  These print data from the midi controller in the console.
  println("Number:"+number);      //
  println("Value:"+value);        //
  cc[number] = value;
}

This is what the code does. Within a minute it is way out of sync. https://www.instagram.com/p/CGf7nGjFjPo/?utm_source=ig_web_copy_link

A friend and I think that I need to figure out how to unpatch as well as patch the UGen objects. Help on that would be very appreciated.