# Minim Loop Synchronization

**URL:** https://discourse.processing.org/t/minim-loop-synchronization/8261
**Category:** Libraries
**Created:** [February 10, 2019, 10:30am UTC](https://discourse.processing.org/t/minim-loop-synchronization/8261 "2019-02-10T10:30:27Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![spaceHolder](https://avatars.discourse-cdn.com/v4/letter/s/c89c15/32.png) [@spaceHolder](https://discourse.processing.org/u/spaceHolder)
#### Post date: [February 10, 2019, 10:30am UTC](https://discourse.processing.org/t/minim-loop-synchronization/8261/1 "2019-02-10T10:30:27Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [February 10, 2019, 12:45pm UTC](https://discourse.processing.org/t/minim-loop-synchronization/8261/2 "2019-02-10T12:45:15Z")

</div>

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

```auto
// 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();
}

```

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [February 15, 2019, 6:07pm UTC](https://discourse.processing.org/t/minim-loop-synchronization/8261/3 "2019-02-15T18:07:23Z")

</div>

> [@spaceHolder](#):
>
> looping pedal type program

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](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:

> **[GitHub - youandhubris/SuperLooper: \[Processing, Minim\] An audio looper.](https://github.com/youandhubris/SuperLooper)**
>
> \[Processing, Minim\] An audio looper. Contribute to youandhubris/SuperLooper development by creating an account on GitHub.
