Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ android {
}

dependencies {
annotationProcessor libs.auto.value
implementation(libs.appcompat)
implementation(libs.fragment)
implementation(libs.navigation.fragment)
Expand All @@ -122,4 +123,5 @@ dependencies {
implementation(libs.gson)
implementation(libs.room.runtime)
annotationProcessor(libs.room.compiler)
compileOnly libs.auto.value.annotations
}
Original file line number Diff line number Diff line change
Expand Up @@ -944,19 +944,19 @@ public void onMetronomePreTick(Tick tick) {
if (binding == null || getMetronomeEngine() == null) {
return;
}
View beat = binding.linearMainBeats.getChildAt(tick.beat - 1);
if (beat instanceof BeatView && tick.subdivision == 1 && !tick.isPoly) {
View beat = binding.linearMainBeats.getChildAt(tick.beat() - 1);
if (beat instanceof BeatView && tick.subdivision() == 1 && !tick.isPoly()) {
resetActiveBeats();
ViewUtil.scrollToViewMinimal(binding.scrollHorizMainBeats, beat);
if (activeBeat) {
((BeatView) beat).setActive(true);
}
((BeatView) beat).beat();
}
View subdivision = binding.linearMainSubs.getChildAt(tick.subdivision - 1);
View subdivision = binding.linearMainSubs.getChildAt(tick.subdivision() - 1);
if (!(subdivision instanceof BeatView)) {
return;
} else if (getMetronomeEngine().getConfig().usePolyrhythm() && !tick.isPoly) {
} else if (getMetronomeEngine().getConfig().usePolyrhythm() && !tick.isPoly()) {
return;
}
ViewUtil.scrollToViewMinimal(binding.scrollHorizMainSubs, subdivision);
Expand All @@ -972,7 +972,7 @@ public void onMetronomeTick(Tick tick) {
}
if (flashScreen) {
int color;
switch (tick.type) {
switch (tick.type()) {
case TICK_TYPE.STRONG:
color = colorFlashStrong;
break;
Expand All @@ -984,7 +984,7 @@ public void onMetronomeTick(Tick tick) {
color = colorFlashNormal;
break;
}
if (tick.isMuted) {
if (tick.isMuted()) {
color = colorFlashMuted;
}
if (isLandTablet && binding.cardMainContainerEnd != null) {
Expand All @@ -1003,7 +1003,7 @@ public void onMetronomeTick(Tick tick) {
}, 100); // flash screen for 100 milliseconds
}
}
if (tick.subdivision == 1) {
if (tick.subdivision() == 1) {
if (!reduceAnimations) {
logoUtil.nextBeat(getMetronomeEngine().getInterval());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import xyz.zedler.patrick.tack.fragment.SongsFragmentDirections.ActionSongsToSong;
import xyz.zedler.patrick.tack.metronome.MetronomeEngine;
import xyz.zedler.patrick.tack.metronome.MetronomeEngine.MetronomeListener;
import xyz.zedler.patrick.tack.metronome.MetronomeEngine.MetronomeListenerAdapter;
import xyz.zedler.patrick.tack.recyclerview.adapter.SongAdapter;
import xyz.zedler.patrick.tack.recyclerview.adapter.SongAdapter.OnSongClickListener;
import xyz.zedler.patrick.tack.recyclerview.layoutmanager.WrapperLinearLayoutManager;
Expand Down Expand Up @@ -212,7 +211,7 @@ public void onTopScroll() {
ViewUtil.setTooltipText(binding.buttonSongsBack, R.string.action_back);
ViewUtil.setTooltipText(binding.buttonSongsMenu, R.string.action_more);

metronomeListener = new MetronomeListenerAdapter() {
metronomeListener = new MetronomeListener() {
@Override
public void onMetronomeStart() {
activity.runOnUiThread(() -> adapter.setPlaying(true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,12 @@ public boolean getIgnoreFocus() {
}

public void playTick(Tick tick) {
if (!playing || !isInitialized() || muted || tick.isMuted) {
if (!playing || !isInitialized() || muted || tick.isMuted()) {
return;
}

int nativeTickType;
switch (tick.type) {
switch (tick.type()) {
case TICK_TYPE.STRONG:
nativeTickType = NATIVE_TICK_TYPE_STRONG;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@
import android.os.Handler;
import android.os.HandlerThread;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.PreferenceManager;

import com.google.auto.value.AutoValue;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
Expand All @@ -40,6 +44,7 @@
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import xyz.zedler.patrick.tack.Constants;
import xyz.zedler.patrick.tack.Constants.BEAT_MODE;
import xyz.zedler.patrick.tack.Constants.DEF;
Expand Down Expand Up @@ -577,7 +582,7 @@ public void run() {
if (config.isMuteActive() && config.getMuteUnit().equals(UNIT.BEATS)) {
muted = random.nextInt(100) < config.getMuteMute();
}
Tick tick = new Tick(
Tick tick = Tick.create(
tickIndexPoly, 1, subdivisionPoly, tickTypePoly, muted, true
);

Expand Down Expand Up @@ -626,13 +631,13 @@ public void run() {
if (config.isMuteActive() && config.getMuteUnit().equals(UNIT.BEATS)) {
muted = random.nextInt(100) < config.getMuteMute();
}
Tick tick = new Tick(tickIndex, beat, subdivision, tickType, muted, false);
Tick tick = Tick.create(tickIndex, beat, subdivision, tickType, muted, false);

long interval = config.usePolyrhythm()
? getInterval()
: getInterval() / config.getSubdivisionsCount();
tickHandler.postDelayed(this, interval);
if (tick.beat == 1 && config.usePolyrhythm()) {
if (tick.beat() == 1 && config.usePolyrhythm()) {
// start polyrhythm subdivisions every new bar
tickHandler.post(tickRunnablePoly);
}
Expand Down Expand Up @@ -1371,7 +1376,7 @@ private boolean performTick(Tick tick) {
long barIndexWithoutCountIn = barIndex - config.getCountIn();
boolean isCountIn = barIndex < config.getCountIn();

boolean isBeat = tick.subdivision == 1;
boolean isBeat = tick.subdivision() == 1;
boolean isFirstBeat = isBeat && (beatIndex % config.getBeatsCount()) == 0;

if (config.isTimerActive() && config.getTimerUnit().equals(UNIT.BARS) && !isCountIn) {
Expand Down Expand Up @@ -1456,8 +1461,8 @@ private boolean performTick(Tick tick) {
}
}, Math.max(0, latency - Constants.BEAT_ANIM_OFFSET));
latencyHandler.postDelayed(() -> {
if (!beatMode.equals(BEAT_MODE.SOUND) && !tick.isMuted) {
switch (tick.type) {
if (!beatMode.equals(BEAT_MODE.SOUND) && !tick.isMuted()) {
switch (tick.type()) {
case TICK_TYPE.STRONG:
hapticUtil.heavyClick();
break;
Expand Down Expand Up @@ -1493,13 +1498,13 @@ private void performTickPoly(Tick tick) {
boolean shouldVibrate = !beatMode.equals(BEAT_MODE.SOUND) && !isMuted;
if (shouldVibrate) {
// check whether any poly subdivision collides with a beat
long product = (long) (tick.subdivision - 1) * config.getBeatsCount();
long product = (long) (tick.subdivision() - 1) * config.getBeatsCount();
if (product % config.getSubdivisionsCount() == 0) {
shouldVibrate = false;
}
}
if (shouldVibrate) {
switch (tick.type) {
switch (tick.type()) {
case TICK_TYPE.STRONG:
hapticUtil.heavyClick();
break;
Expand Down Expand Up @@ -1571,67 +1576,60 @@ private String getCurrentTickTypePoly() {
}

public interface MetronomeListener {
void onMetronomeStart();
void onMetronomeStop();
void onMetronomePreTick(Tick tick);
void onMetronomeTick(Tick tick);
void onMetronomeTempoChanged(int tempoOld, int tempoNew);
void onMetronomeElapsedTimeSecondsChanged();
void onMetronomeTimerStarted();
void onMetronomeTimerSecondsChanged();
void onMetronomeTimerProgressOneTime(boolean withTransition);
void onMetronomeConfigChanged();
void onMetronomeSongOrPartChanged(@Nullable SongWithParts song, int partIndex);
void onMetronomePermissionMissing();
}

public static class MetronomeListenerAdapter implements MetronomeListener {
public void onMetronomeStart() {}
public void onMetronomeStop() {}
public void onMetronomePreTick(Tick tick) {}
public void onMetronomeTick(Tick tick) {}
public void onMetronomeTempoChanged(int tempoOld, int tempoNew) {}
public void onMetronomeElapsedTimeSecondsChanged() {}
public void onMetronomeTimerStarted() {}
public void onMetronomeTimerSecondsChanged() {}
public void onMetronomeTimerProgressOneTime(boolean withTransition) {}
public void onMetronomeConfigChanged() {}
public void onMetronomeSongOrPartChanged(@Nullable SongWithParts song, int partIndex) {}
public void onMetronomePermissionMissing() {}
}

public static class Tick {
public final long index;
public final int beat, subdivision;
@NonNull
public final String type;
public final boolean isMuted, isPoly;

public Tick(
long index,
int beat,
int subdivision,
@NonNull String type,
boolean isMuted,
boolean isPoly
) {
this.index = index;
this.beat = beat;
this.subdivision = subdivision;
this.type = type;
this.isMuted = isMuted;
this.isPoly = isPoly;
default void onMetronomeStart() {
}

@NonNull
@Override
public String toString() {
return "Tick{index = " + index +
", beat=" + beat +
", sub=" + subdivision +
", type=" + type +
", isPoly=" + isPoly +
", muted=" + isMuted + '}';
default void onMetronomeStop() {
}

default void onMetronomePreTick(Tick tick) {
}

default void onMetronomeTick(Tick tick) {
}

default void onMetronomeTempoChanged(int tempoOld, int tempoNew) {
}

default void onMetronomeElapsedTimeSecondsChanged() {
}

default void onMetronomeTimerStarted() {
}

default void onMetronomeTimerSecondsChanged() {
}

default void onMetronomeTimerProgressOneTime(boolean withTransition) {
}

default void onMetronomeConfigChanged() {
}

default void onMetronomeSongOrPartChanged(@Nullable SongWithParts song, int partIndex) {
}

default void onMetronomePermissionMissing() {
}
}

@AutoValue
public static abstract class Tick {
static Tick create(long index, int beat, int subdivision, @NonNull String type, boolean isMuted, boolean isPoly) {
return new AutoValue_MetronomeEngine_Tick(index, beat, subdivision, type, isMuted, isPoly);
}

public abstract long index();

public abstract int beat();

public abstract int subdivision();

@NonNull
public abstract String type();

public abstract boolean isMuted();

public abstract boolean isPoly();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import xyz.zedler.patrick.tack.Constants.EXTRA;
import xyz.zedler.patrick.tack.Constants.PREF;
import xyz.zedler.patrick.tack.metronome.MetronomeEngine;
import xyz.zedler.patrick.tack.metronome.MetronomeEngine.MetronomeListenerAdapter;
import xyz.zedler.patrick.tack.metronome.MetronomeEngine.MetronomeListener;
import xyz.zedler.patrick.tack.util.NotificationUtil;
import xyz.zedler.patrick.tack.util.PrefsUtil;

Expand All @@ -58,7 +58,7 @@ public void onCreate() {

notificationUtil = new NotificationUtil(this);
metronomeEngine = new MetronomeEngine(this);
metronomeEngine.addListener(new MetronomeListenerAdapter() {
metronomeEngine.addListener(new MetronomeListener() {
@Override
public void onMetronomeStart() {
if (permNotification && hasPermission()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import xyz.zedler.patrick.tack.fragment.SettingsFragment;
import xyz.zedler.patrick.tack.metronome.MetronomeEngine;
import xyz.zedler.patrick.tack.metronome.MetronomeEngine.MetronomeListener;
import xyz.zedler.patrick.tack.metronome.MetronomeEngine.MetronomeListenerAdapter;
import xyz.zedler.patrick.tack.metronome.MetronomeEngine.Tick;
import xyz.zedler.patrick.tack.util.DialogUtil;
import xyz.zedler.patrick.tack.util.ResUtil;
Expand Down Expand Up @@ -69,7 +68,7 @@ public LatencyDialogUtil(MainActivity activity, SettingsFragment fragment) {
colorBg = ResUtil.getColor(activity, R.attr.colorSurfaceBright);
colorBgFlash = ResUtil.getColor(activity, R.attr.colorTertiaryContainer);

latencyListener = new MetronomeListenerAdapter() {
latencyListener = new MetronomeListener() {
@Override
public void onMetronomeTick(Tick tick) {
activity.runOnUiThread(() -> {
Expand Down
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ compose-navigation = "1.5.6"
compose-foundation = "1.5.6"
compose-activity = "1.12.2"
compose-constraintlayout = "1.1.1"
auto-value = "1.11.1"

[libraries]
appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
Expand Down Expand Up @@ -60,6 +61,8 @@ compose-animation-graphics = { group = "androidx.compose.animation", name = "ani
compose-navigation = { group = "androidx.wear.compose", name = "compose-navigation", version.ref = "compose-navigation" }
compose-activity = { group = "androidx.activity", name = "activity-compose", version.ref = "compose-activity" }
compose-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout-compose", version.ref = "compose-constraintlayout" }
auto-value-annotations = { group = "com.google.auto.value", name = "auto-value-annotations", version.ref = "auto-value" }
auto-value = { group = "com.google.auto.value", name = "auto-value", version.ref = "auto-value" }

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class MainActivity : ComponentActivity(), ServiceConnection {
setTheme(android.R.style.Theme_DeviceDefault)

metronomeEngine = MetronomeEngine(this, false)
metronomeEngine.addListener(object : MetronomeEngine.MetronomeListenerAdapter() {
metronomeEngine.addListener(object : MetronomeEngine.MetronomeListener {
override fun onMetronomePreTick(tick: MetronomeEngine.Tick) {
runOnUiThread {
viewModel.onPreTick(tick)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,21 +307,12 @@ class MetronomeEngine(
}

interface MetronomeListener {
fun onMetronomeStart()
fun onMetronomeStop()
fun onMetronomePreTick(tick: Tick)
fun onMetronomeTick(tick: Tick)
fun onFlashScreenEnd()
fun onPermissionMissing()
}

open class MetronomeListenerAdapter : MetronomeListener {
override fun onMetronomeStart() {}
override fun onMetronomeStop() {}
override fun onMetronomePreTick(tick: Tick) {}
override fun onMetronomeTick(tick: Tick) {}
override fun onFlashScreenEnd() {}
override fun onPermissionMissing() {}
fun onMetronomeStart() {}
fun onMetronomeStop() {}
fun onMetronomePreTick(tick: Tick) {}
fun onMetronomeTick(tick: Tick) {}
fun onFlashScreenEnd() {}
fun onPermissionMissing() {}
}

data class Tick(
Expand Down
Loading