Add clip duration to title

This commit is contained in:
Victor 2018-04-06 20:19:18 +03:00
parent 21955413ed
commit cd40e5a37c
2 changed files with 17 additions and 1 deletions

View File

@ -54,7 +54,10 @@ public class MainController implements Initializable {
stage.titleProperty().bind(Bindings stage.titleProperty().bind(Bindings
.when(clipView.metadataProperty().isNull()) .when(clipView.metadataProperty().isNull())
.then(Main.getResources().getString("voicyanski")) .then(Main.getResources().getString("voicyanski"))
.otherwise(clipView.metadataProperty().asString()) .otherwise(Bindings.format("%s [%s]",
clipView.metadataProperty().asString(),
clipView.durationProperty()
))
); );
} }

View File

@ -5,6 +5,7 @@ import com.annimon.voicyanski.audio.Waveform;
import com.annimon.voicyanski.tasks.Metadata; import com.annimon.voicyanski.tasks.Metadata;
import java.io.IOException; import java.io.IOException;
import javafx.beans.binding.Bindings; import javafx.beans.binding.Bindings;
import javafx.beans.binding.DoubleBinding;
import javafx.beans.binding.ObjectBinding; import javafx.beans.binding.ObjectBinding;
import javafx.beans.property.ObjectProperty; import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleObjectProperty;
@ -33,6 +34,7 @@ public final class AudioClipView extends VBox {
private WaveformView waveform; private WaveformView waveform;
private final ObjectProperty<Metadata> metadataProperty = new SimpleObjectProperty<>(); private final ObjectProperty<Metadata> metadataProperty = new SimpleObjectProperty<>();
private final ObjectProperty<String> durationProperty = new SimpleObjectProperty<>();
private MediaPlayer mediaPlayer; private MediaPlayer mediaPlayer;
private FontIcon iconPlay; private FontIcon iconPlay;
@ -61,6 +63,10 @@ public final class AudioClipView extends VBox {
return metadataProperty; return metadataProperty;
} }
public ObjectProperty<String> durationProperty() {
return durationProperty;
}
public Waveform getWaveform() { public Waveform getWaveform() {
return waveform.getWaveform(); return waveform.getWaveform();
} }
@ -166,6 +172,13 @@ public final class AudioClipView extends VBox {
); );
waveform.visibleProperty().bind(waveformProperty().isNotNull()); waveform.visibleProperty().bind(waveformProperty().isNotNull());
durationProperty.bind(Bindings.createStringBinding(() -> {
double hi = rangeClip.highValueProperty().get();
double lo = rangeClip.lowValueProperty().get();
final int delta = (int) (hi - lo);
return String.format("%02d:%02d", (delta % 3600) / 60, delta % 60);
}, rangeClip.highValueProperty(), rangeClip.lowValueProperty()));
} }
public void initMarkButtons(Button markStart, Button markEnd) { public void initMarkButtons(Button markStart, Button markEnd) {