Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.nio.file.Path;
import java.security.GeneralSecurityException;
import java.util.*;
import java.util.concurrent.TimeUnit;

import static com.codedead.opal.utils.SharedVariables.DEFAULT_LOCALE;

Expand All @@ -47,6 +48,8 @@ public final class MainWindowController implements IAudioTimer, TrayIconListener
@FXML
private SoundPane snpFastMetronome;
@FXML
private SoundPane snpFastestMetronome;
@FXML
private SoundPane snpSlowMetronome;
@FXML
private SoundPane snpTrain;
Expand Down Expand Up @@ -354,6 +357,7 @@ public void setControllers(final SettingsController settingsController, final Up
snpTrain.getNameLabel().textProperty().bind(resourceFactory.getStringBinding("Train"));
snpSlowMetronome.getNameLabel().textProperty().bind(resourceFactory.getStringBinding("SlowMetronome"));
snpFastMetronome.getNameLabel().textProperty().bind(resourceFactory.getStringBinding("FastMetronome"));
snpFastestMetronome.getNameLabel().textProperty().bind(resourceFactory.getStringBinding("FastestMetronome"));
}

/**
Expand Down Expand Up @@ -477,6 +481,18 @@ private List<SoundPane> getAllSoundPanes() {
return elements;
}

/**
* Get all {@link SoundPane} objects, including custom sounds
*
* @return The {@link List} of all {@link SoundPane} objects
*/
private List<SoundPane> getAllSoundPanesIncludingCustom() {
final List<SoundPane> elements = new ArrayList<>(getAllSoundPanes());
elements.addAll(getSoundPanes(grpCustom));

return elements;
}

/**
* Get all {@link SoundPane} objects from a {@link GridPane} object
*
Expand Down Expand Up @@ -828,13 +844,17 @@ private void saveSoundPresetAction() {
@FXML
private void playPauseAction() {
logger.info("Play / pause all media");
try {
for (final SoundPane soundPane : getAllSoundPanes()) {
soundPane.playPause();
}

for (final SoundPane soundPane : getSoundPanes(grpCustom)) {
soundPane.playPause();
final List<SoundPane> soundPanes = getAllSoundPanesIncludingCustom();
final boolean pauseAll = soundPanes.stream().anyMatch(SoundPane::isPlaying);

try {
for (final SoundPane soundPane : soundPanes) {
if (pauseAll) {
soundPane.pause();
} else if (soundPane.getSlider().getValue() > 0) {
soundPane.play();
}
}
} catch (final MediaPlayerException ex) {
logger.error("Unable to play / pause MediaPlayer", ex);
Expand Down Expand Up @@ -1145,18 +1165,18 @@ public void run() {
};

countDownTask = new TimerTask() {
final long seconds = delay / 1000;
int i = 0;
private final long startNanos = System.nanoTime();

@Override
public void run() {
i++;
long timeLeft = (seconds - (i % seconds));
final long elapsedMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNanos);
final long remainingMillis = Math.max(0, delay - elapsedMillis);
final long timeLeft = remainingMillis / 1000;

// Calculate hours, minutes and seconds
long hours = timeLeft / 3600;
long minutes = (timeLeft % 3600) / 60;
long seconds = timeLeft % 60;
final long hours = timeLeft / 3600;
final long minutes = (timeLeft % 3600) / 60;
final long seconds = timeLeft % 60;

// Format the values to HH:MM:SS with leading zeros if necessary
final String timeLeftFormatted = String.format("%02d:%02d:%02d", hours, minutes, seconds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,25 @@ public void setProperties(final Properties properties) {
* @throws IOException When the Properties object could not be stored
*/
public void saveProperties() throws IOException {
saveProperties(properties);
}

/**
* Save the provided properties and replace the in-memory properties once the write succeeds
*
* @param newProperties The properties that should be stored
* @throws IOException When the Properties object could not be stored
*/
public void saveProperties(final Properties newProperties) throws IOException {
if (newProperties == null)
throw new NullPointerException("Properties cannot be null!");

logger.info("Storing the Properties object");
try (final FileOutputStream fos = new FileOutputStream(getPropertiesFileLocation())) {
properties.store(fos, null);
newProperties.store(fos, null);
}

properties = newProperties;
}

/**
Expand Down
Loading
Loading