Skip to content

Commit

Permalink
Wave file and Metronome(mediaplayer, tempo) implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
bowla petunia committed Apr 3, 2022
1 parent 65cd81e commit 2f6ff39
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>11</maven.compiler.release>
<javafx.version>15</javafx.version>
<maven.compiler.source>18</maven.compiler.source>
<maven.compiler.target>18</maven.compiler.target>
</properties>

<dependencies>
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/com/utsusynth/utsu/engine/Engine.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.utsusynth.utsu.engine;

import com.google.common.base.Function;
import com.utsusynth.utsu.common.utils.RegionBounds;
import com.utsusynth.utsu.common.StatusBar;
import com.utsusynth.utsu.common.data.LyricConfigData;
import com.utsusynth.utsu.common.exception.ErrorLogger;
import com.utsusynth.utsu.common.quantize.Quantizer;
import com.utsusynth.utsu.common.utils.PitchUtils;
import com.utsusynth.utsu.common.utils.RegionBounds;
import com.utsusynth.utsu.files.CacheManager;
import com.utsusynth.utsu.files.PreferencesManager;
import com.utsusynth.utsu.files.PreferencesManager.CacheMode;
import com.utsusynth.utsu.model.song.Metronome;
import com.utsusynth.utsu.model.song.Note;
import com.utsusynth.utsu.model.song.NoteIterator;
import com.utsusynth.utsu.model.song.Song;
Expand Down Expand Up @@ -140,6 +141,13 @@ public boolean startPlayback(
instrumentalPlayer.dispose();
}
});
//Metronome
Metronome metro_gnome = new Metronome(
"file:C:\\Users\\pedro\\source\\src\\main\\resources\\boop.wav",
mediaPlayer,
173
);

mediaPlayer.play();
}
return finalSong.isPresent();
Expand Down
73 changes: 73 additions & 0 deletions src/main/java/com/utsusynth/utsu/model/song/Metronome.java
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 added src/main/resources/boop.wav
Binary file not shown.

0 comments on commit 2f6ff39

Please sign in to comment.