Skip to content
Snippets Groups Projects
Commit e8148508 authored by tobias's avatar tobias
Browse files

Waveform (native)

parent 7c1d3de7
No related branches found
No related tags found
No related merge requests found
...@@ -37,7 +37,7 @@ public class PeakTrack extends HBox { ...@@ -37,7 +37,7 @@ public class PeakTrack extends HBox {
label.minHeightProperty().bind(minHeightProperty()); label.minHeightProperty().bind(minHeightProperty());
label.prefHeightProperty().bind(prefHeightProperty()); label.prefHeightProperty().bind(prefHeightProperty());
label.prefWidthProperty().bind(widthProperty().multiply(0.05).subtract(2)); label.prefWidthProperty().bind(widthProperty().multiply(0.05).subtract(3));
label.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, new CornerRadii(5), new BorderWidths(0.5)))); label.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, new CornerRadii(5), new BorderWidths(0.5))));
if (i < 0.75) if (i < 0.75)
......
No preview for this file type
package de.tobias.playpad.view;
import javafx.scene.shape.LineTo;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.Path;
public class WaveformView extends Path {
public WaveformView(float[] data) {
getElements().add(new MoveTo(0, 0));
for (int i = 0; i < data.length; i++) {
LineTo lineTo = new LineTo(i, data[i] * 50.0);
MoveTo moveTo = new MoveTo(i, data[i] * 50.0);
getElements().addAll(lineTo, moveTo);
}
for (int i = data.length - 1; i >= 0; i--) {
LineTo lineTo = new LineTo(i, -data[i] * 50.0);
MoveTo moveTo = new MoveTo(i, -data[i] * 50.0);
getElements().addAll(lineTo, moveTo);
}
getElements().add(new LineTo(0, 0));
getElements().add(new MoveTo(0, 0));
setScaleX(0.5);
}
}
package de.tobias.playpad; package de.tobias.playpad;
import de.tobias.playpad.Waveform.WaveformDelegate; import de.tobias.playpad.Waveform.WaveformDelegate;
import de.tobias.playpad.view.WaveformView;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class WaveformTest implements WaveformDelegate { public class WaveformTest extends Application {
private static float[] data;
public static void main(String[] args) { public static void main(String[] args) {
System.load("/Users/tobias/Documents/Programmieren/Java/git/PlayWall/PlayWallNative/libNativeAudio.dylib"); System.load("/Users/tobias/Documents/Programmieren/Java/git/PlayWall/PlayWallNative/libNativeAudio.dylib");
new WaveformTest(); WaveformTest.data = new Test().data;
launch(args);
} }
public WaveformTest() { @Override
public void start(Stage primaryStage) throws Exception {
WaveformView view = new WaveformView(WaveformTest.data);
VBox root = new VBox(view);
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
}
public static class Test implements WaveformDelegate {
public Test() {
Waveform.initialize(); Waveform.initialize();
Waveform.setDelegate(this); Waveform.setDelegate(this);
Waveform.createWaveform("/Users/tobias/Downloads/Short.mp3"); Waveform.createWaveform("/Users/tobias/Downloads/03%20Hymn%20for%20the%20Weekend.mp3.wav");
synchronized (this) { synchronized (this) {
try { try {
...@@ -24,14 +45,14 @@ public class WaveformTest implements WaveformDelegate { ...@@ -24,14 +45,14 @@ public class WaveformTest implements WaveformDelegate {
} }
} }
float[] data;
@Override @Override
public void sampleProcessed(float[] data) { public void sampleProcessed(float[] data) {
System.out.println(data.length); this.data = data;
for (int i = 0; i < data.length; i++) {
System.out.println(data[i]);
}
synchronized (this) { synchronized (this) {
notify(); notify();
} }
} }
} }
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment