From 010432222a92f2232d07da80dee37ae3ae604111 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 28 May 2013 10:31:52 +0200 Subject: [PATCH] Update metadata title with timestamp. --- .../pterodactylus/sonitus/data/filter/TimeCounterFilter.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/TimeCounterFilter.java b/src/main/java/net/pterodactylus/sonitus/data/filter/TimeCounterFilter.java index a528200..faff0bd 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/TimeCounterFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/TimeCounterFilter.java @@ -19,6 +19,7 @@ package net.pterodactylus.sonitus.data.filter; import java.io.IOException; import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.atomic.AtomicReference; import net.pterodactylus.sonitus.data.Filter; import net.pterodactylus.sonitus.data.Metadata; @@ -35,9 +36,15 @@ public class TimeCounterFilter extends DummyFilter { /** The byte counter. */ private final AtomicLong counter = new AtomicLong(); + /** The parent’s metdata. */ + private final AtomicReference parentMetadata = new AtomicReference(); + /** Whether to reset the counter on a metadata update. */ private final boolean resetOnMetadataUpdate; + /** The last displayed timestamp. */ + private final AtomicLong lastTimestamp = new AtomicLong(0); + /** * Creates a new time counter filter that automatically resets the counter when * the metadata is {@link #metadataUpdated(Metadata) updated}. @@ -94,6 +101,7 @@ public class TimeCounterFilter extends DummyFilter { @Override public void metadataUpdated(Metadata metadata) { super.metadataUpdated(metadata); + parentMetadata.set(metadata); if (resetOnMetadataUpdate) { reset(); } @@ -103,6 +111,10 @@ public class TimeCounterFilter extends DummyFilter { public void process(byte[] buffer) throws IOException { super.process(buffer); counter.getAndAdd(buffer.length); + long timestamp = getMillis() / 1000; + if (lastTimestamp.get() != timestamp) { + super.metadataUpdated(parentMetadata.get().title(String.format("%s (%02d:%02d)", parentMetadata.get().title(), timestamp / 60, timestamp % 60))); + } } } -- 2.7.4