Bonjour,
Ce que je cherche à faire c'est une boîte à rythmes. git@gitlab.com:Graphics3D/MyLittleSynth.git
J'ai l'interface avec les wav en boutons, un tempo réglage et une ligne du temps. Vu que j'essaie d'améliorer mon code il y a des choses qui ne vont pas bien.
Le Timer une classe de base avec une méthode getTimeElapsedNanoSec() qui relève le temps depuis l'initialisation du timer.
Le LoopTimer qui ne fonctionne pas bien contient une méthode getTimeOnTimelineSec() qui renvoie la position cyclique sur la ligne du temps en fonction du tempo.
Le ThreadPlaying qui boucle (et loupe) en permanence pour jouer les samples sur la ligne du temps.
Je vous montre quelques extraits de code que je n'arrive pas à fixer.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 public synchronized void run() { while (running) { this.timeline.getTimes().forEach( (time3PC, file) -> { double time = (double) time3PC * timeline.getDuration(); if (time < timer.getCurrentTimeOnLineSec() && time>timeline.hasPlayed((File)file)) { try { System.out.println("Play at " + time + " on timeline of duration" + timeline.getDuration()); timeline.setPlayed((File)file); (new PlayWave(AudioSystem.getAudioInputStream((File) file))).start(); } catch (UnsupportedAudioFileException | IOException ex) { ex.printStackTrace(); } } }); } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 package be.manudahmen.mylittlesynth; public class Timer { private long timeStartSystemNanoSec = 0L; private long timePause = 0L; private long definitiveTime = -1L; public void init() { this.timeStartSystemNanoSec = System.nanoTime(); this.definitiveTime = -1L; } public void pause() { this.timePause = System.nanoTime(); } public void resume() { this.timePause = 0L; } public long getTotalTimeElapsedNanoSec() { return System.nanoTime() - this.timeStartSystemNanoSec; } public void stop() { this.definitiveTime = (long)((double)this.getTotalTimeElapsedNanoSec()); } public long getDefinitiveTime() { return this.definitiveTime; } public long getInitTime() { return this.timeStartSystemNanoSec; } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package be.manudahmen.mylittlesynth.rythms; import be.manudahmen.mylittlesynth.Timer; public class LoopTimer extends Timer { private final RythmPanel panel; public LoopTimer(RythmPanel rythmPanel) { super(); this.panel = rythmPanel; } public double getCurrentTimeOnLineSec() { double remainder = Math.IEEEremainder((getTotalTimeElapsedNanoSec()), panel.timelineTimeSec()*1E9d)/1E9d; return remainder; } }Problème 1) Il y a des valeurs de temps négatives sur la listePlay arabicperc3-37.wav at -1,239836 on timeline of duration 3,000000
Play arabicperc3-37.wav at -1,239836 on timeline of duration 3,000000
Play arabicperc3-3.wav at 0,264093 on timeline of duration 3,000000
Play arabicperc3-15.wav at 0,408686 on timeline of duration 3,000000
Play arabicperc3-15.wav at 0,408686 on timeline of duration 3,000000
Play arabicperc3-3.wav at 0,264093 on timeline of duration 3,000000
Play arabicperc3-28.wav at -0,107622 on timeline of duration 3,000000
Play arabicperc3-22.wav at -1,243741 on timeline of duration 3,000000
Problème 2) Des fichiers identiques sont joués plusieurs fois en même temps
Problème 3) Le temps de répétition des notes jouées ne correspond pas au tempo imposé
Partager