Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
/ MIDI-MUG Public archive

Commit

Permalink
bugs fix
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddaytw committed Jul 7, 2020
1 parent ca00107 commit fa23645
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/david/midimug/PrimaryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void initialize(URL url, ResourceBundle rb) {
@FXML
private void openFile() {
try {
SheetUtils.pause();
File source = LoadFileRenderer.renderMidiChooser();
AbstractModeController controller = LoadFileRenderer.renderModeChooser();
GameModeUtils.setGameMode(controller);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/david/midimug/handler/MidiDevices.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.david.midimug.gamemode.AbstractModeController;
import java.util.ArrayList;
import java.util.prefs.Preferences;
import javax.sound.midi.MidiDevice;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;
Expand All @@ -32,6 +33,7 @@
public class MidiDevices {

private static MidiDevice selected = null;
private static Preferences prefs = Preferences.userNodeForPackage(MidiDevices.class);

public static ArrayList<MidiDevice> getDevices() {
ArrayList<MidiDevice> devicesList = new ArrayList<>();
Expand All @@ -43,6 +45,9 @@ public static ArrayList<MidiDevice> getDevices() {

// specify hardware MIDI port
if (!(device instanceof Sequencer) && !(device instanceof Synthesizer)) {
if(i.getName().equals(prefs.get("SELECTED", "NONE"))){
selectDevice(device);
}
devicesList.add(device);
}
} catch (MidiUnavailableException ex) {
Expand All @@ -58,6 +63,7 @@ public static void selectDevice(MidiDevice device) throws MidiUnavailableExcepti
if (selected.isOpen()) {
selected.close();
}
prefs.put("SELECTED", device.getDeviceInfo().getName());
selected.open();
}

Expand Down
8 changes: 5 additions & 3 deletions src/main/java/com/david/midimug/handler/SheetUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,21 @@
*/
public class SheetUtils {

private static Timeline timeline;
private static Timeline timeline = new Timeline();

public static void setupSheet(Pane pane, File source) throws InvalidMidiDataException, IOException {
Sheet music_sheet = MidiUtils.getSheet(source);
timeline = SheetRenderer.renderBarSheet(pane, music_sheet);
timeline.stop();
timeline.getKeyFrames().clear();
SheetRenderer.renderBarSheet(pane, music_sheet, timeline);
}

public static void play() {
timeline.play();
}

public static void pause() {
timeline.pause();
if(timeline != null) timeline.pause();
}

public static Duration getCurrentTime() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.david.midimug.gamemode.FluidModeController;
import com.david.midimug.gamemode.RealModeController;
import com.david.midimug.gamemode.ShowModeController;
import com.david.midimug.handler.SheetUtils;
import java.io.File;
import java.util.NoSuchElementException;
import java.util.Optional;
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/com/david/midimug/render/SheetRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class SheetRenderer {

private static Pane target;

public static Timeline renderBarSheet(Pane target, Sheet sheet) {
public static void renderBarSheet(Pane target, Sheet sheet, Timeline timeline) {
SheetRenderer.target = target;

// reset sheet
Expand All @@ -59,7 +59,6 @@ public static Timeline renderBarSheet(Pane target, Sheet sheet) {
target.setClip(clip);
Color white_key_color = Color.DODGERBLUE;

Timeline timeline = new Timeline();
AbstractModeController controller = GameModeUtils.getGameMode();

for (Channel channel : sheet.getChannels()) {
Expand Down Expand Up @@ -98,8 +97,6 @@ public static Timeline renderBarSheet(Pane target, Sheet sheet) {
}

target.getChildren().add(combo);

return timeline;
}

private static double computeTick(long tick, Sheet sheet) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
requires javafx.fxml;
requires java.base;
requires java.desktop;
requires java.prefs;

opens com.david.midimug to javafx.fxml;
exports com.david.midimug;
Expand Down

0 comments on commit fa23645

Please sign in to comment.