diff options
| -rw-r--r-- | src/devmenu/DebugMenu.java | 2 | ||||
| -rw-r--r-- | src/devmenu/DiffEditor.java | 12 | ||||
| -rw-r--r-- | src/devmenu/NotesEditor.java | 13 | ||||
| -rw-r--r-- | src/gameplay/SongPlayer.java | 76 | ||||
| -rw-r--r-- | src/gui/Driver.java | 18 | ||||
| -rw-r--r-- | src/gui/GameOver.java | 6 | ||||
| -rw-r--r-- | src/gui/Leaderboard.java | 2 | ||||
| -rw-r--r-- | src/gui/LevelDetails.java | 4 | ||||
| -rw-r--r-- | src/gui/LevelSelector.java | 2 | ||||
| -rw-r--r-- | src/gui/LevelSurround.java | 2 | ||||
| -rw-r--r-- | src/gui/MainMenu.java | 6 | ||||
| -rw-r--r-- | src/gui/Settings.java | 16 | ||||
| -rw-r--r-- | src/main/ScoreController.java | 8 | ||||
| -rw-r--r-- | src/main/SettingsController.java | 9 | ||||
| -rw-r--r-- | src/main/SoundController.java | 66 | ||||
| -rw-r--r-- | src/sound/AudioFilePlayer.java | 148 | ||||
| -rw-r--r-- | src/sound/ShortAudioPlayer.java | 73 | 
17 files changed, 144 insertions, 319 deletions
| diff --git a/src/devmenu/DebugMenu.java b/src/devmenu/DebugMenu.java index 19fc8e1..654d15b 100644 --- a/src/devmenu/DebugMenu.java +++ b/src/devmenu/DebugMenu.java @@ -32,7 +32,7 @@ public class DebugMenu          Button testVol = new Button();          testVol.setText("print volumes"); -        testVol.setOnAction(e -> System.out.println("sfx:"+Driver.settingsController.effectsVol+" msc:"+Driver.settingsController.musicVol)); +        testVol.setOnAction(e -> System.out.println("setc:"+Driver.settingsController.effectsVol+" sndc:"+Driver.soundController.songMediaPlayer.getVolume()));          primaryPane.getChildren().addAll(wallpaperTest,wallpaperTest2,wallpaperTest3,testVol); diff --git a/src/devmenu/DiffEditor.java b/src/devmenu/DiffEditor.java index e2ce5d8..bf745e8 100644 --- a/src/devmenu/DiffEditor.java +++ b/src/devmenu/DiffEditor.java @@ -3,6 +3,10 @@ package devmenu;  import java.io.FileNotFoundException;  import java.io.UnsupportedEncodingException; +import gui.Driver; +import gui.LevelSelector; +import gui.LevelSurround; +import gui.MainMenu;  import javafx.scene.Scene;  import javafx.scene.control.Button;  import javafx.scene.control.TextField; @@ -44,7 +48,11 @@ public class DiffEditor              }          }); -        Button editScores = new Button("Edit leaderboard"); +        Button editScores = new Button("Clear leaderboard"); +        editScores.setOnAction(e -> diff.getLeaderboard().clear()); + +        Button playLevel = new Button("Launch level"); +        playLevel.setOnAction(e -> Driver.setMenu(new LevelSurround(diff.level, diff, new MainMenu())));          Button save = new Button("Save");          save.setOnAction(e -> { //assigns text feilds to values @@ -55,7 +63,7 @@ public class DiffEditor          });          VBox main = new VBox(); -        main.getChildren().addAll(folderNameLabel,folderName,titleLabel,title,bpmLabel,bpm,numBeatsLabel,numBeats,editNotes,editScores,save); +        main.getChildren().addAll(folderNameLabel,folderName,titleLabel,title,bpmLabel,bpm,numBeatsLabel,numBeats,editNotes,editScores,playLevel,save);          Scene scene = new Scene(main);          primaryStage.setScene(scene);          primaryStage.show(); diff --git a/src/devmenu/NotesEditor.java b/src/devmenu/NotesEditor.java index c3ce1fa..a0aa26a 100644 --- a/src/devmenu/NotesEditor.java +++ b/src/devmenu/NotesEditor.java @@ -9,6 +9,7 @@ import java.io.PrintWriter;  import java.io.UnsupportedEncodingException;  import gameplay.Timer; +import gui.Driver;  import javafx.scene.Scene;  import javafx.scene.control.Button;  import javafx.scene.input.KeyCode; @@ -20,16 +21,13 @@ import javafx.scene.media.MediaView;  import javafx.scene.text.Text;  import javafx.stage.Stage;  import main.Difficulty; -import sound.AudioFilePlayer;  public class NotesEditor  {      Text help; -    String t1 = "Press Start to begin recording. Use the same keys."; +    String t1 = "Press Start to begin recording. Use the same keys. Note: existing notes will be overwitten.";      String t2 = "Now recording. Press Stop or ESC to finish"; -    MediaPlayer mediaPlayer;      Difficulty diff; -    AudioFilePlayer music;      Timer timer;      PrintWriter writer;      public NotesEditor(Difficulty diff) throws FileNotFoundException, UnsupportedEncodingException @@ -37,7 +35,6 @@ public class NotesEditor          this.diff = diff;          help = new Text(t1); -          Text cur = new Text("-----");          Button start = new Button("Start"); @@ -49,8 +46,6 @@ public class NotesEditor          stop.setFocusTraversable(false);          Media song = new Media(diff.level.song.toURI().toString()); -        mediaPlayer = new MediaPlayer(song); -        new MediaView(mediaPlayer);          VBox main = new VBox();          main.getChildren().addAll(help,cur,start,stop); @@ -94,7 +89,7 @@ public class NotesEditor      private void start()      { -        mediaPlayer.play(); +        Driver.soundController.playSong(diff.level.song);          timer = new Timer(diff.bpm);          help.setText(t2);      } @@ -102,7 +97,7 @@ public class NotesEditor      private void stop()      {          try { -        mediaPlayer.stop(); +        Driver.soundController.endSong();          diff.numBeats = (int)timer.time();          timer = null;          writer.close(); diff --git a/src/gameplay/SongPlayer.java b/src/gameplay/SongPlayer.java index 985e5fb..3e465bd 100644 --- a/src/gameplay/SongPlayer.java +++ b/src/gameplay/SongPlayer.java @@ -3,7 +3,6 @@ package gameplay;  import java.io.File;  import java.io.FileNotFoundException;  import java.io.IOException; -import java.nio.file.Paths;  import java.util.ArrayList;  import java.util.LinkedList;  import java.util.Queue; @@ -20,15 +19,11 @@ import javafx.scene.layout.HBox;  import javafx.scene.layout.Pane;  import javafx.scene.layout.StackPane;  import javafx.scene.layout.VBox; -import javafx.scene.media.Media; -import javafx.scene.media.MediaPlayer; -import javafx.scene.media.MediaView;  import javafx.scene.paint.Color;  import javafx.animation.*;  import javafx.util.*;  import main.Difficulty;  import main.ScoreController; -import sound.AudioFilePlayer; @@ -111,15 +106,9 @@ public class SongPlayer extends Pane {  		}  	} -	public SongPlayer() { -	} -  	public SongPlayer(main.Level lvl, Difficulty d, Pane p, ScoreController cntrl) { -		gui.Driver.mediaPlayer.stop(); -		Media song = new Media(Paths.get(lvl.song.getPath()).toUri().toString()); -		gui.Driver.mediaPlayer = new MediaPlayer(song); -		new MediaView(gui.Driver.mediaPlayer); +		Driver.soundController.playSong(lvl.song);  		if (lvl.background != null) {  			Driver.setBackground(lvl.background.getUrl()); @@ -129,7 +118,7 @@ public class SongPlayer extends Pane {  		difficulty = d;  		pane = p; -		System.out.println(d.bpm + " " + d.numBeats); +		//System.out.println(d.bpm + " " + d.numBeats);  		songLength = d.numBeats;  		timer = new Timer(bpm);	//Sets the timer's bpm to that of the song @@ -157,7 +146,7 @@ public class SongPlayer extends Pane {  			 * The keyboard detection for the game: when a key is pressed it  			 * calls the checkNote() method for the corresponding lane  			 */ -			System.out.println(timer.time()); +			//System.out.println(timer.time());  			if (e.getCode() == KeyCode.D) {  				checkNote(dLane, dButton);  			} @@ -174,7 +163,7 @@ public class SongPlayer extends Pane {  				checkNote(kLane, kButton);  			}  			//prints the user's current score and combo, for debugging purposes -			System.out.println("Score: " + scoreCounter.getScore() + "\nCombo: " + scoreCounter.getCombo() + "\n"); +			//System.out.println("Score: " + scoreCounter.getScore() + "\nCombo: " + scoreCounter.getCombo() + "\n");  		});  		buttonBox.setAlignment(Pos.CENTER);		//puts the buttons in the center of the screen @@ -264,7 +253,6 @@ public class SongPlayer extends Pane {  				cancel();	  			}  			if (timer.time() > 0.0) { -				gui.Driver.mediaPlayer.play();  			}  		}  	}; @@ -284,12 +272,7 @@ public class SongPlayer extends Pane {  	public void cancel() {  		gui.Driver.setBackground("assets/forest.png");  		gameLoop.stop(); -		gui.Driver.mediaPlayer.stop(); -		Media song = new Media(Paths.get("src/assets/MenuMusicPlaceholder.wav").toUri().toString()); -        gui.Driver.mediaPlayer = new MediaPlayer(song); -		gui.Driver.mediaPlayer.setCycleCount(Integer.MAX_VALUE); -        new MediaView(gui.Driver.mediaPlayer); -		gui.Driver.mediaPlayer.play(); +		Driver.soundController.endSong();  	}  	/** @@ -326,31 +309,34 @@ public class SongPlayer extends Pane {  	 * @return 2 for a perfect hit, 1 for a good hit, 0 for a miss, and -1 if there are no notes to hit  	 */  	private int checkNote(ArrayList<Block> lane, TButton button) { -		double distance = distanceToGoal(lane.get(getClosestNote(lane))); -		if (lane.size() > 0 && distance < super.getHeight() / 3) { - -			FillTransition ft = new FillTransition(Duration.millis(500), button); -			ft.setToValue(button.getFillColor()); - -			super.getChildren().removeAll(lane.get(getClosestNote(lane))); -			lane.remove(lane.get(getClosestNote(lane))); -			if (distance < super.getHeight() / 16) { -				ft.setFromValue(Color.WHITE); -				ft.play(); -				scoreCounter.perfect(); -				return 2; -			} -			if (distance < super.getHeight() / 5) { -				ft.setFromValue(Color.CYAN); +		if (lane.size() != 0) +		{ +			double distance = distanceToGoal(lane.get(getClosestNote(lane))); +			if (lane.size() > 0 && distance < super.getHeight() / 3) { + +				FillTransition ft = new FillTransition(Duration.millis(500), button); +				ft.setToValue(button.getFillColor()); + +				super.getChildren().removeAll(lane.get(getClosestNote(lane))); +				lane.remove(lane.get(getClosestNote(lane))); +				if (distance < super.getHeight() / 16) { +					ft.setFromValue(Color.WHITE); +					ft.play(); +					scoreCounter.perfect(); +					return 2; +				} +				if (distance < super.getHeight() / 5) { +					ft.setFromValue(Color.CYAN); +					ft.play(); +					scoreCounter.good(); +					return 1; +				} +				ft.setFromValue(Color.RED);  				ft.play(); -				scoreCounter.good(); -				return 1; +				scoreCounter.miss(); +				return 0;  			} -			ft.setFromValue(Color.RED); -			ft.play(); -			scoreCounter.miss(); -			return 0; -		} +		}	  		return -1;  	} diff --git a/src/gui/Driver.java b/src/gui/Driver.java index d0a3256..00a71cf 100644 --- a/src/gui/Driver.java +++ b/src/gui/Driver.java @@ -21,8 +21,7 @@ import javafx.stage.Stage;  import javafx.util.Duration;  import main.LevelController;  import main.SettingsController; -import sound.AudioFilePlayer; -import sound.ShortAudioPlayer; +import main.SoundController;  import java.nio.file.Paths; @@ -40,15 +39,12 @@ import gameplay.SongPlayer;  public class Driver extends Application  -{ -    public static ShortAudioPlayer menuFx = new ShortAudioPlayer(); - -    public static MediaPlayer mediaPlayer; -     +{          public static Stage primaryStage;      static Pane primaryPane = new Pane();      public static SettingsController settingsController = new SettingsController(); +    public static SoundController soundController = new SoundController();      public static LevelController levelController = new LevelController();      public static DebugMenu debug = new DebugMenu(); @@ -67,15 +63,11 @@ public class Driver extends Application      @Override      public void start(Stage newPrimaryStage)      {    -        Media song = new Media(Paths.get("src/assets/fairyfountain.wav").toUri().toString()); -        mediaPlayer = new MediaPlayer(song); -        new MediaView(mediaPlayer); -        mediaPlayer.setCycleCount(Integer.MAX_VALUE); -        mediaPlayer.play(); +          primaryStage = newPrimaryStage; -        Scene primaryScene = new Scene(primaryPane, 800, 600); +        Scene primaryScene = new Scene(primaryPane, 800,600);          primaryScene.getStylesheets().add("gui/style.css");          primaryStage.setScene(primaryScene); diff --git a/src/gui/GameOver.java b/src/gui/GameOver.java index e504437..f5b46ec 100644 --- a/src/gui/GameOver.java +++ b/src/gui/GameOver.java @@ -70,7 +70,7 @@ public class GameOver extends Pane          save.setOnAction(new EventHandler<ActionEvent>() { //this is the same as the "e ->" thing but it allows more than one line to be added               @Override              public void handle(ActionEvent event) { -                Driver.menuFx.play("src/assets/MenuForward.wav"); +                Driver.soundController.playSfx("forward");                  save.setDisable(true);                  name.setDisable(true);                  diff.addToLeaderboard(name.getText(), score2); @@ -91,14 +91,14 @@ public class GameOver extends Pane          Button exit = new Button();          exit.setText("Back");          exit.setOnAction(e -> { -            Driver.menuFx.play("src/assets/MenuBackward.wav"); +            Driver.soundController.playSfx("backward");              Driver.setMenu(lastMenu);          });          Button replay = new Button();          replay.setText("Replay");          replay.setOnAction(e -> { -            Driver.menuFx.play("src/assets/MenuForward.wav"); +            Driver.soundController.playSfx("forward");              Driver.setMenu(new LevelSurround(level, diff, lastMenu));          }); diff --git a/src/gui/Leaderboard.java b/src/gui/Leaderboard.java index 4c7a1b5..39df409 100644 --- a/src/gui/Leaderboard.java +++ b/src/gui/Leaderboard.java @@ -50,7 +50,7 @@ public class Leaderboard extends Pane          Button exit = new Button();          exit.setText("Back");          exit.setOnAction(e -> { -            Driver.menuFx.play("src/assets/MenuBackward.wav"); +            Driver.soundController.playSfx("backward");              Driver.setMenu(prev);          }); diff --git a/src/gui/LevelDetails.java b/src/gui/LevelDetails.java index f9239e7..af55b9c 100644 --- a/src/gui/LevelDetails.java +++ b/src/gui/LevelDetails.java @@ -96,13 +96,13 @@ public class LevelDetails extends VBox              }              play.disableProperty().bind(diffToggleGroup.selectedToggleProperty().isNull()); //disables play button when no difficulty is selected              play.setOnAction(e -> { -                Driver.menuFx.play("src/assets/MenuForward.wav"); +                Driver.soundController.playSfx("forward");                  Driver.setMenu(new LevelSurround(level, (Difficulty)diffToggleGroup.getSelectedToggle().getUserData(), Driver.getMenu()));              });              leaderboard.disableProperty().bind(diffToggleGroup.selectedToggleProperty().isNull());              leaderboard.setOnAction(e -> { -                Driver.menuFx.play("src/assets/MenuForward.wav"); +                Driver.soundController.playSfx("forward");                  Driver.setMenu(new Leaderboard(level, (Difficulty)diffToggleGroup.getSelectedToggle().getUserData(), Driver.getMenu()));              }); diff --git a/src/gui/LevelSelector.java b/src/gui/LevelSelector.java index 2a95b6c..6fd6aca 100644 --- a/src/gui/LevelSelector.java +++ b/src/gui/LevelSelector.java @@ -44,7 +44,7 @@ public class LevelSelector extends Pane          Button exit = new Button();          exit.setText("Back");          exit.setOnAction(e -> {Driver.setMenu(new MainMenu()); -            Driver.menuFx.play("src/assets/MenuBackward.wav"); +            Driver.soundController.playSfx("backward");          });          VBox leftBox = new VBox(); diff --git a/src/gui/LevelSurround.java b/src/gui/LevelSurround.java index c89ef6d..8f7d831 100644 --- a/src/gui/LevelSurround.java +++ b/src/gui/LevelSurround.java @@ -35,7 +35,7 @@ public class LevelSurround extends Pane          exit.setText("Back");          exit.setOnAction(e -> {              Driver.setMenu(prev); -            Driver.menuFx.play("src/assets/MenuBackward.wav"); +            Driver.soundController.playSfx("backward");              game.cancel();          }); diff --git a/src/gui/MainMenu.java b/src/gui/MainMenu.java index 56a0a05..84a7508 100644 --- a/src/gui/MainMenu.java +++ b/src/gui/MainMenu.java @@ -32,19 +32,19 @@ public class MainMenu extends Pane          Button play = new Button();          play.setText("Play");          play.setOnAction(e -> {Driver.setMenu(new LevelSelector()); -            Driver.menuFx.play("src/assets/MenuForward.wav"); +            Driver.soundController.playSfx("forward");          });          Button settings = new Button();          settings.setText("Settings");          settings.setOnAction(e -> {Driver.setMenu(new Settings()); -            Driver.menuFx.play("src/assets/MenuForward.wav"); +            Driver.soundController.playSfx("forward");          });          Button exit = new Button();          exit.setText("Quit");          exit.setOnAction(e -> {Driver.quit(); -            Driver.menuFx.play("src/assets/MenuBackward.wav"); +            Driver.soundController.playSfx("backward");          });          VBox buttonBox = new VBox(); diff --git a/src/gui/Settings.java b/src/gui/Settings.java index 4e82056..2144e16 100644 --- a/src/gui/Settings.java +++ b/src/gui/Settings.java @@ -25,9 +25,9 @@ public class Settings extends Pane          musicText.getStyleClass().add("t3");          Slider musicSlider = new Slider(); -        musicSlider.setMax(100); -        musicSlider.setMin(0);          musicSlider.valueProperty().bindBidirectional(Driver.settingsController.musicVol); +        musicSlider.setMin(0.0); +        musicSlider.setMax(1.0);          VBox musicBox = new VBox();          musicBox.getChildren().addAll(musicText, musicSlider); @@ -40,9 +40,9 @@ public class Settings extends Pane          SFXText.getStyleClass().add("t3");          Slider SFXSlider = new Slider(); -        SFXSlider.setMax(100); -        SFXSlider.setMin(0);          SFXSlider.valueProperty().bindBidirectional(Driver.settingsController.effectsVol); +        SFXSlider.setMin(0.0); +        SFXSlider.setMax(1.0);          VBox SFXBox = new VBox();          SFXBox.getChildren().addAll(SFXText, SFXSlider); @@ -59,7 +59,7 @@ public class Settings extends Pane          fullscreen.getStyleClass().remove("toggle-button");          fullscreen.getStyleClass().add("button");          fullscreen.setOnAction(e -> { -            Driver.menuFx.play("src/assets/MenuForward.wav"); +            Driver.soundController.playSfx("forward");              Driver.primaryStage.setFullScreen(!Driver.primaryStage.isFullScreen());          }); @@ -74,14 +74,14 @@ public class Settings extends Pane          Button levelEdit = new Button("Level Utility");          levelEdit.setOnAction(e -> { -            Driver.menuFx.play("src/assets/MenuForward.wav"); +            Driver.soundController.playSfx("forward");              new devmenu.LevelList();          });          Button devMenu = new Button();          devMenu.setText("Debug Menu");          devMenu.setOnAction(e -> { -            Driver.menuFx.play("src/assets/MenuForward.wav"); +            Driver.soundController.playSfx("forward");              Driver.debug.show();          }); @@ -101,7 +101,7 @@ public class Settings extends Pane          Button exit = new Button();          exit.setText("Back");          exit.setOnAction(e -> { -            Driver.menuFx.play("src/assets/MenuBackward.wav"); +            Driver.soundController.playSfx("backward");              Driver.setMenu(new MainMenu());          }); 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<String,File> 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 diff --git a/src/sound/AudioFilePlayer.java b/src/sound/AudioFilePlayer.java deleted file mode 100644 index 9425881..0000000 --- a/src/sound/AudioFilePlayer.java +++ /dev/null @@ -1,148 +0,0 @@ -package sound; - -import java.io.File; -import java.io.IOException; -import javax.sound.sampled.AudioInputStream; -import javax.sound.sampled.AudioSystem; -import javax.sound.sampled.Clip; -import javax.sound.sampled.LineUnavailableException; -import javax.sound.sampled.UnsupportedAudioFileException; - -//Java program to play audio files. imports file scanning and various  -//methods from the java audio class in order to do so. -public class AudioFilePlayer  -{ -   -    // to store current position -    Long currentFrame; -    Clip clip; -       -    // current status of clip -    String status; -       -    AudioInputStream audioInputStream; -    private String filePath; -   -    File audioFile; -    // constructor to initialize streams and clip -    public AudioFilePlayer(String newFilePath) -    { -        filePath = newFilePath; -        audioFile = new File(filePath); -        // create AudioInputStream object -        try { -            audioInputStream = AudioSystem.getAudioInputStream(new File(filePath).getAbsoluteFile()); -        }  -        catch (UnsupportedAudioFileException e) { -            e.printStackTrace(); -        }  -        catch (IOException e) { -            e.printStackTrace(); -        } -           -        // create clip reference -        try { -            clip = AudioSystem.getClip(); -        }  -        catch (LineUnavailableException e) { -            e.printStackTrace(); -        } -           -        // open audioInputStream to the clip -        try { -            clip.open(audioInputStream); -        }  -        catch (LineUnavailableException e) { -            e.printStackTrace(); -        }  -        catch (IOException e) { -            e.printStackTrace(); -        } -         -         -    } -       -    // Method to play the audio -    public void play()  -    { -        //start the clip -        clip.start(); -           -        status = "play"; -    } -       -    // Method to pause the audio -    public void pause()  -    { -        if (status.equals("paused"))  -        { -            System.out.println("audio is already paused"); -            return; -        } -        this.currentFrame = this.clip.getMicrosecondPosition(); -        clip.stop(); -        status = "paused"; -    } -       -    // Method to resume the audio -    public void resumeAudio() throws UnsupportedAudioFileException, -                                IOException, LineUnavailableException  -    { -        if (status.equals("play"))  -        { -            System.out.println("Audio is already "+ -            "being played"); -            return; -        } -        clip.close(); -        resetAudioStream(); -        clip.setMicrosecondPosition(currentFrame); -        this.play(); -    } -       -    // Method to restart the audio -    public void restart() throws IOException, LineUnavailableException, -                                            UnsupportedAudioFileException  -    { -        clip.stop(); -        clip.close(); -        resetAudioStream(); -        currentFrame = 0L; -        clip.setMicrosecondPosition(0); -        this.play(); -    } -       -    // Method to stop the audio -    public void stop() throws UnsupportedAudioFileException, -    IOException, LineUnavailableException  -    { -        currentFrame = 0L; -        clip.stop(); -        clip.close(); -    } -       -    // Method to jump over a specific part -    public void jump(long c) throws UnsupportedAudioFileException, IOException, -                                                        LineUnavailableException  -    { -        if (c > 0 && c < clip.getMicrosecondLength())  -        { -            clip.stop(); -            clip.close(); -            resetAudioStream(); -            currentFrame = c; -            clip.setMicrosecondPosition(c); -            this.play(); -        } -    } -       -    // Method to reset audio stream -    public void resetAudioStream() throws UnsupportedAudioFileException, IOException, LineUnavailableException  -    { -        audioInputStream = AudioSystem.getAudioInputStream( -        new File(filePath).getAbsoluteFile()); -        clip.open(audioInputStream); -        clip.loop(Clip.LOOP_CONTINUOUSLY); -    } -   -}
\ No newline at end of file diff --git a/src/sound/ShortAudioPlayer.java b/src/sound/ShortAudioPlayer.java deleted file mode 100644 index 77fb52c..0000000 --- a/src/sound/ShortAudioPlayer.java +++ /dev/null @@ -1,73 +0,0 @@ -package sound; - -import java.io.File; -import java.io.IOException; - -import javax.sound.sampled.AudioFormat; -import javax.sound.sampled.AudioInputStream; -import javax.sound.sampled.AudioSystem; -import javax.sound.sampled.Clip; -import javax.sound.sampled.DataLine; -import javax.sound.sampled.LineEvent; -import javax.sound.sampled.LineListener; -import javax.sound.sampled.LineUnavailableException; -import javax.sound.sampled.UnsupportedAudioFileException; - -//Java program to play audio files. imports file scanning and various  -//methods from the java audio class in order to do so. -public class ShortAudioPlayer implements LineListener -{ -    //indicates whether the playback completes or not -    boolean playCompleted; -    Clip audioClip; -     -    public void play(String audioFilePath) -    { -        File audioFile = new File(audioFilePath); -         -        try -        { -            //creates an audioInput object using the file we -            //declared earlier -            AudioInputStream audioStream = AudioSystem.getAudioInputStream(audioFile); -             -            //gets the format of the audioStream object -            AudioFormat format = audioStream.getFormat(); -             -            DataLine.Info info = new DataLine.Info(Clip.class, format); -             -            audioClip = (Clip) AudioSystem.getLine(info); - -            audioClip.addLineListener(this); - -            audioClip.open(audioStream); -             -            audioClip.start(); -        } -        catch (UnsupportedAudioFileException ex)  -        { -            System.out.println("The specified audio file is not supported."); -            ex.printStackTrace(); -        } -        catch (LineUnavailableException ex)  -        { -            System.out.println("Audio line for playing back is unavailable."); -            ex.printStackTrace(); -        }  -        catch (IOException ex)  -        { -            System.out.println("Error playing the audio file."); -            ex.printStackTrace(); -        } -    } -     -     -    /** -     * Listens to the START and STOP events of the audio line. -     */ -    @Override -    public void update(LineEvent event) -    { -        //something should prolly go here -    }    -} | 
