From a14862a6bc0dbb1ae78cd4e2e4795d4194772583 Mon Sep 17 00:00:00 2001 From: sowgro Date: Mon, 5 Jun 2023 00:34:16 -0400 Subject: rewrote everything related to sound --- src/main/ScoreController.java | 8 ++--- src/main/SettingsController.java | 9 +++--- src/main/SoundController.java | 66 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 9 deletions(-) create mode 100644 src/main/SoundController.java (limited to 'src/main') diff --git a/src/main/ScoreController.java b/src/main/ScoreController.java index d2606a4..54dd960 100644 --- a/src/main/ScoreController.java +++ b/src/main/ScoreController.java @@ -1,8 +1,8 @@ package main; +import gui.Driver; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; -import sound.ShortAudioPlayer; public class ScoreController{ @@ -12,8 +12,6 @@ public class ScoreController{ public StringProperty scoreProperty = new SimpleStringProperty("0"); public StringProperty comboProperty = new SimpleStringProperty("0"); - sound.ShortAudioPlayer fx = new ShortAudioPlayer(); - /** * Called when the user performs a perfect hit */ @@ -40,7 +38,7 @@ public class ScoreController{ * Called when the user misses a note */ public void miss() { - fx.play("src/assets/Miss.wav"); + Driver.soundController.playSfx("miss"); combo = 0; comboMultiplier = 1; scoreProperty.setValue(score+""); @@ -52,7 +50,7 @@ public class ScoreController{ * Increments the combo by one */ private void combo() { - fx.play("src/assets/Hitsound.wav"); + Driver.soundController.playSfx("hit"); combo++; if (combo == 2) { diff --git a/src/main/SettingsController.java b/src/main/SettingsController.java index 4bd2b24..36fda40 100644 --- a/src/main/SettingsController.java +++ b/src/main/SettingsController.java @@ -9,12 +9,13 @@ import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; +import javafx.beans.property.SimpleDoubleProperty; import javafx.beans.property.SimpleIntegerProperty; public class SettingsController { - public SimpleIntegerProperty effectsVol = new SimpleIntegerProperty(0); - public SimpleIntegerProperty musicVol = new SimpleIntegerProperty(0); + public SimpleDoubleProperty effectsVol = new SimpleDoubleProperty(1); + public SimpleDoubleProperty musicVol = new SimpleDoubleProperty(1); private JSONObject settings; public void read() throws ParseException @@ -27,8 +28,8 @@ public class SettingsController settings = (JSONObject)(obj); //converts read object to a JSONObject - effectsVol.set((int) settings.get("effectsVol")); - musicVol.set((int) settings.get("musicVol")); + effectsVol.set((double) settings.get("effectsVol")); + musicVol.set((double) settings.get("musicVol")); } catch (FileNotFoundException e) { diff --git a/src/main/SoundController.java b/src/main/SoundController.java new file mode 100644 index 0000000..55d40f4 --- /dev/null +++ b/src/main/SoundController.java @@ -0,0 +1,66 @@ +package main; + +import java.io.File; +import java.util.HashMap; + +import gui.Driver; +import javafx.scene.media.Media; +import javafx.scene.media.MediaPlayer; + +public class SoundController +{ + public MediaPlayer songMediaPlayer; + public MediaPlayer sfxMediaPlayer; + private HashMap presets = new HashMap<>(); + private File mainMenuSong = new File("src/assets/MenuMusicPlaceholder.wav"); + + public SoundController() + { + presets.put("forward", new File("src/assets/MenuForward.wav")); + presets.put("backward", new File("src/assets/MenuBackward.wav")); + presets.put("hit", new File("src/assets/Hitsound.wav")); + presets.put("miss", new File("src/assets/Miss.wav")); + playMenuSong(); + } + + public void playSong(File songFile) + { + if (songMediaPlayer != null) + { + songMediaPlayer.stop(); + } + Media song = new Media(songFile.toURI().toString()); + songMediaPlayer = new MediaPlayer(song); + songMediaPlayer.volumeProperty().bind(Driver.settingsController.musicVol); + songMediaPlayer.play(); + } + + private void playMenuSong() + { + playSong(mainMenuSong); + songMediaPlayer.setCycleCount(MediaPlayer.INDEFINITE); + songMediaPlayer.play(); + } + + public void endSong() + { + playMenuSong(); + } + + public void playSfx(File sfxFile) + { + if (sfxMediaPlayer != null) + { + sfxMediaPlayer.stop(); + } + Media sound = new Media(sfxFile.toURI().toString()); + sfxMediaPlayer = new MediaPlayer(sound); + sfxMediaPlayer.volumeProperty().bind(Driver.settingsController.effectsVol); //not working yet + sfxMediaPlayer.play(); + } + + public void playSfx(String preset) + { + playSfx(presets.get(preset)); + } +} \ No newline at end of file -- cgit v1.2.3 From 874bbf24537caf0a89d7a88c622f846e8a5d0a0f Mon Sep 17 00:00:00 2001 From: sowgro Date: Mon, 5 Jun 2023 00:46:47 -0400 Subject: fix a dumb level validation bug --- src/main/Level.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/Level.java b/src/main/Level.java index a173191..eb1d92c 100644 --- a/src/main/Level.java +++ b/src/main/Level.java @@ -76,7 +76,7 @@ public class Level System.out.println(thisDir+" is missing background.png, though it is not required"); } - if (! new File(thisDir, "preview.png").exists()) + if (new File(thisDir, "preview.png").exists()) { preview = new Image(new File(thisDir,"preview.png").toURI().toString()); } -- cgit v1.2.3 From e444503c77120908126de325d86b32bd3fb327e0 Mon Sep 17 00:00:00 2001 From: sowgro Date: Mon, 5 Jun 2023 08:27:43 -0400 Subject: seperate end song and start menu song --- src/main/SoundController.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/main') diff --git a/src/main/SoundController.java b/src/main/SoundController.java index 55d40f4..0d2061c 100644 --- a/src/main/SoundController.java +++ b/src/main/SoundController.java @@ -35,7 +35,7 @@ public class SoundController songMediaPlayer.play(); } - private void playMenuSong() + public void playMenuSong() { playSong(mainMenuSong); songMediaPlayer.setCycleCount(MediaPlayer.INDEFINITE); @@ -44,7 +44,10 @@ public class SoundController public void endSong() { - playMenuSong(); + if (songMediaPlayer != null) + { + songMediaPlayer.stop(); + } } public void playSfx(File sfxFile) -- cgit v1.2.3