diff --git a/out/artifacts/BongoMidi_jar/BongoMidi.jar b/out/artifacts/BongoMidi_jar/BongoMidi.jar index 12060f8..ce610e1 100644 Binary files a/out/artifacts/BongoMidi_jar/BongoMidi.jar and b/out/artifacts/BongoMidi_jar/BongoMidi.jar differ diff --git a/src/com/bongo/Main.java b/src/com/bongo/Main.java index 31c5980..3fdb78d 100644 --- a/src/com/bongo/Main.java +++ b/src/com/bongo/Main.java @@ -2,6 +2,7 @@ import java.awt.*; import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.io.File; import java.io.IOException; @@ -52,10 +53,9 @@ class Main{ long ms = (long) ((1. / ((double) refreshRate)) * 1000); while (true){ try { - Main.timeLabel.setText(String.format("%02d:%02d.%03d/%s", + Main.timeLabel.setText(String.format("%02d:%02d/%s", TimeUnit.MICROSECONDS.toMinutes(Main.parser.sequencer.getMicrosecondPosition()), TimeUnit.MICROSECONDS.toSeconds(Main.parser.sequencer.getMicrosecondPosition()) % 60, - Main.parser.sequencer.getMicrosecondPosition() % 1000, Main.lenstr)); Main.seekslider.setValue((int)Main.parser.sequencer.getMicrosecondPosition()); Main.seekselftrigger=true; @@ -88,17 +88,29 @@ private static void togglePlayPause() { } private static void finish() { + JButton forkButton = new JButton("Fork me on GitHub!"); + forkButton.addActionListener(e -> { + if (Desktop.isDesktopSupported()) { + try { + Desktop.getDesktop().browse(new URI("https://github.com/marios8543/BongoMidi")); + } catch (Exception ex) { + Runtime runtime = Runtime.getRuntime(); + try { + runtime.exec("xdg-open https://github.com/marios8543/BongoMidi"); + } catch (IOException ee) { + JOptionPane.showMessageDialog(window, ee.getMessage(), "Browser open error", JOptionPane.ERROR_MESSAGE); + } + } + } + }); pauseButton.setText("Restart"); pauseButton.setActionCommand("restart"); parser.sequencer.stop(); bongos = new Renderer.Bongo[16]; window.repaint(); finishTrigger = false; - int ok = JOptionPane.showOptionDialog(window, - "BongoCat MIDI Player\nhttps://github.com/marios8543/BongoMidi\nRestart?", - "Thanks for playing!",JOptionPane.YES_NO_OPTION,JOptionPane.PLAIN_MESSAGE, - new FinishAnimation(), - null,null); + Integer ok = JOptionPane.showOptionDialog(window, "BongoCat MIDI Player\nhttps://github.com/marios8543/BongoMidi\n\nRestart?", + "Thanks for playing!",JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, new FinishAnimation(), new Object[]{"Yes","No",forkButton},null); if(ok==JOptionPane.YES_OPTION){ restart(); } @@ -155,10 +167,9 @@ private static MidiParser init_player(){ } window.setName("Bongo Cat MIDI Player - " + file.getName()); window.setTitle("Bongo Cat MIDI Player - " + file.getName()); - lenstr = String.format("%02d:%02d.%03d", + lenstr = String.format("%02d:%02d", TimeUnit.MICROSECONDS.toMinutes(private_parser.sequencer.getMicrosecondLength()), - TimeUnit.MICROSECONDS.toSeconds(private_parser.sequencer.getMicrosecondLength()) % 60, - private_parser.sequencer.getMicrosecondLength() % 1000); + TimeUnit.MICROSECONDS.toSeconds(private_parser.sequencer.getMicrosecondLength()) % 60); seekslider.setMaximum((int)private_parser.sequencer.getMicrosecondLength()); return private_parser; } @@ -247,31 +258,11 @@ public static void main(String[] args) { } }); - JButton forkButton = new JButton("Fork me on GitHub!"); - forkButton.addActionListener(e -> { - switch (e.getActionCommand()) { - case "fork": { - if (Desktop.isDesktopSupported()) { - try { - Desktop.getDesktop().browse(new URI("https://github.com/marios8543/BongoMidi")); - } catch (Exception ex) { - JOptionPane.showMessageDialog(window, ex.getMessage(), "Error opening GitHub page", - JOptionPane.ERROR_MESSAGE); - } - } - } - } - }); - forkButton.setActionCommand("fork"); - openButton.setAlignmentX(Component.RIGHT_ALIGNMENT); - buttonPanel.add(Box.createRigidArea(new Dimension(5,0))); buttonPanel.add(openButton); buttonPanel.add(Box.createRigidArea(new Dimension(30, 0))); buttonPanel.add(pauseButton); buttonPanel.add(Box.createRigidArea(new Dimension(30, 0))); - buttonPanel.add(forkButton); - buttonPanel.add(Box.createRigidArea(new Dimension(30, 0))); buttonPanel.add(loop); buttonPanel.add(Box.createRigidArea(new Dimension(30, 0))); buttonPanel.add(timeLabel); @@ -301,6 +292,9 @@ public static void main(String[] args) { } class FinishAnimation implements Icon { + private Boolean lhand = true; + private Boolean rhand = false; + FinishAnimation() { final Thread renderThread = new Thread(() -> { while (true){ @@ -319,16 +313,13 @@ class FinishAnimation implements Icon { public void paintIcon(Component c, Graphics g, int x, int y) { if (FinishAnimation.component == null) FinishAnimation.component = c; g.clearRect(0,0, c.getWidth(), c.getHeight()); - // TODO: Actually get the bongo image to load/display here - // I simply use "Percussion" for now - g.drawImage(bongo.note.cpatch.getAsset(), x, y, c); - g.drawImage(Renderer.get_lhand(bongo.l_hand), x, y, c); - g.drawImage(Renderer.get_rhand(bongo.r_hand), x, y, c); - bongo.swap(); + g.drawImage(Renderer.Instr_Categ.Bongo.getAsset(), x, y, c); + g.drawImage(Renderer.get_lhand(lhand), x, y, c); + g.drawImage(Renderer.get_rhand(rhand), x, y, c); + lhand=!lhand; + rhand=!rhand; } - private Renderer.Bongo bongo = new Renderer.Bongo(); - private static Component component; public int getIconWidth() { diff --git a/src/com/bongo/Renderer.java b/src/com/bongo/Renderer.java index 87993d2..c9d0743 100644 --- a/src/com/bongo/Renderer.java +++ b/src/com/bongo/Renderer.java @@ -34,21 +34,6 @@ public static class Bongo { Boolean l_hand=false; Boolean r_hand=false; - // only use this with the final animation - Bongo() { - x = 0; - y = 0; - lastSecondValue = 0L; - note = new Note(); - l_hand = true; - } - - // same goes here - void swap() { - l_hand = !l_hand; - r_hand = !r_hand; - } - Bongo(Note note) { if(note.status){ if(note.cpatch==Instr_Categ.Percussion || note.cpatch==Instr_Categ.CPerc){ @@ -114,7 +99,8 @@ public enum Instr_Categ{ Synth_fx(load_asset("keyboard.png")), Ethnic(load_asset("ensemble.png")), Percussion(load_asset("drums.png")), - FX(load_asset("ensemble.png")); + FX(load_asset("ensemble.png")), + Bongo(load_asset("bongo.png")); private final Image asset; Instr_Categ(Image s){ this.asset = s;