-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wave file and Metronome(mediaplayer, tempo) implementation
- Loading branch information
bowla petunia
committed
Apr 3, 2022
1 parent
65cd81e
commit 2f6ff39
Showing
4 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/main/java/com/utsusynth/utsu/model/song/Metronome.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.utsusynth.utsu.model.song; | ||
|
||
import javafx.collections.ModifiableObservableListBase; | ||
import javafx.collections.ObservableList; | ||
import javafx.scene.media.Media; | ||
import javafx.scene.media.MediaMarkerEvent; | ||
import javafx.scene.media.MediaPlayer; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class Metronome { | ||
Media click; | ||
MediaPlayer songPlayer; | ||
|
||
public Metronome( | ||
String clickUri, | ||
MediaPlayer mp, | ||
Integer t | ||
) { | ||
this.click = new Media( | ||
clickUri | ||
); | ||
this.songPlayer = mp; | ||
attach(generateMarkers(mp.getTotalDuration().toSeconds(), t)); | ||
} | ||
|
||
public void attach( | ||
ObservableList<MediaMarkerEvent> markers | ||
) { | ||
// songPlayer.getMarkers().put(markers); | ||
songPlayer.setOnMarker((MediaMarkerEvent mme) -> { | ||
// this.click.boop | ||
|
||
}); | ||
} | ||
|
||
private ObservableList<MediaMarkerEvent> generateMarkers( | ||
double duration, | ||
int tempo | ||
) { | ||
|
||
ArrayList<MediaMarkerEvent> events = new ArrayList<MediaMarkerEvent>(); | ||
int steps = Math.floorDiv((int)duration, tempo); | ||
|
||
// Not thread safe | ||
return new ModifiableObservableListBase<MediaMarkerEvent>() { | ||
@Override | ||
public MediaMarkerEvent get(int i) { | ||
return events.get(i); | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return events.size(); | ||
} | ||
|
||
@Override | ||
protected void doAdd(int i, MediaMarkerEvent mediaMarkerEvent) { | ||
events.add(i, mediaMarkerEvent); | ||
} | ||
|
||
@Override | ||
protected MediaMarkerEvent doSet(int i, MediaMarkerEvent mediaMarkerEvent) { | ||
return events.set(i, mediaMarkerEvent); | ||
} | ||
|
||
@Override | ||
protected MediaMarkerEvent doRemove(int i) { | ||
return events.remove(i); | ||
} | ||
}; | ||
} | ||
} |
Binary file not shown.