# Project with midi files

**URL:** https://discourse.processing.org/t/project-with-midi-files/3350
**Category:** Project Guidance
**Created:** [September 7, 2018, 4:12pm UTC](https://discourse.processing.org/t/project-with-midi-files/3350 "2018-09-07T16:12:37Z")
**Posts on this page:** 1
**Showing post:** 7

<div class="post-metadata">

### Author: ![arufer720](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@arufer720](https://discourse.processing.org/u/arufer720)
#### Post date: [September 12, 2018, 12:10pm UTC](https://discourse.processing.org/t/project-with-midi-files/3350/7 "2018-09-12T12:10:19Z")

</div>

To mesure the delay, I’ve made something like that:  
It gives me 17ms now constantly except sometimes gives me 1ms.

```auto
long last_click = 0;
long theorical_click = 0;

void draw(){
  
  if(millis()-last_click > 500){
    println("click audio");
    println("Delay :" + (millis() - theorical_click) );
    last_click = millis();
    theorical_click = last_click + 500;
  }
}

```

I’ve found that post, but it doesn’t work very well too.

> [@Inaccurate time intervals for a Metronome](https://discourse.processing.org/t/inaccurate-time-intervals-for-a-metronome/2463/10):
>
> Using TimerTask or another Thread for this is a daft idea that’s just going to tie the OP in knots trying to get things to synchronize. Please note the “I’m new to Processing” - consider half the seasoned developers on here can’t do multi-threaded programming right! wink There are a few things wrong with the initial code, but not that can’t easily be fixed. Try - int c = 0; float bpm = 120; long interval = (long) (1e9 / (bpm / 60)); long nextTime; void setup() { size(600, 600); nextT…

That’s the last code I made after reading the post. Maybe problem is audio?

```auto
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;

Minim min;
AudioPlayer down;
AudioPlayer up;
int cont = 0;
long last = 0;
long next = System.nanoTime() + 1000000000;

void setup(){
  min = new Minim(this);
  up = min.loadFile("C:/Users/Arnau/Desktop/sketch_180907a/MetronomeAM_v02/data/up2.wav");
  down = min.loadFile("C:/Users/Arnau/Desktop/sketch_180907a/MetronomeAM_v02/data/down2.wav");
  
}

void draw(){
  if(System.nanoTime() > next){
    next = next + 500*1000000;
    up.play(10);
    
    cont++;
  }
}

```

---

_[View the full topic](https://discourse.processing.org/t/project-with-midi-files/3350)._
