Minim Loop Synchronization

Hey there! This is my first post here so please excuse me if it’s in the wrong place.

I’m thinking of putting together a really simple little 4 track looping pedal type program using minim but I’m not quite sure if there’s a way to synchronize the looped playback of multiple audio files of the same length. Is there a way to listen for the end/beginning of a file’s loop and run a function when that happens?

1 Like

if you not use the “loop” function
and make with

  • a little logic and
  • check on player position

your own auto play you have full control
and can add graphic features…

example for a easy two song auto play

// https://discourse.processing.org/t/minim-loop-synchronization/8261
import ddf.minim.*;
Minim minim;
AudioPlayer player1, player2;
int play = 0;  // 1 2 

void setup() {
  size(512, 200, P3D);
  minim = new Minim(this);
  player1 = minim.loadFile("groove1.mp3");
  player2 = minim.loadFile("groove2.mp3");          // i make just a rename and a copy from original example
}

void draw() {
  background(200, 200, 0);
  //_____________________________________________________________________ graphic position info
  float pos1x = map(player1.position(), 0, player1.length(), 0, width);
  stroke(0, 0, 200);
  line(pos1x, height/2, pos1x, height/2 -20);
  float pos2x = map(player2.position(), 0, player2.length(), 0, width);
  stroke(200, 0, 200);
  line(pos2x, height/2, pos2x, height/2 +20);
  //_____________________________________________________________________ text info  
  if      ( player1.isPlaying() )    text("song 1", 10, 20 );
  else if ( player2.isPlaying() )    text("song 2", 10, 20 );
  else                               text("press a key to start", 10, 20);
  //_____________________________________________________________________ play next auto at end
  if ( play == 1 && ( player1.position() == player1.length() ) ) song2();
  if ( play == 2 && ( player2.position() == player2.length() ) ) song1();
}


void song1() {
  play = 1; 
  player1.rewind(); 
  player1.play();
}

void song2() {
  play = 2; 
  player2.rewind(); 
  player2.play();
}

void keyPressed() { //___________________________________________________ manual start required
  song1();
}


1 Like

Rather than AudioPlayer, you might be interested in using Sampler – depending on your loop length and what effects you have in mind (like if you want to be able to do layering).

http://code.compartmental.net/minim/sampler_class_sampler.html

You might also be interested in past work. It would probably need to be updated for the current minim library and Processing 3.x: