Skip to content

Commit

Permalink
Switched back to seconds only, added fork button in finish window and…
Browse files Browse the repository at this point in the history
… made it work on linux
  • Loading branch information
marios8543 committed Oct 21, 2018
1 parent 2537c10 commit f015087
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 54 deletions.
Binary file modified out/artifacts/BongoMidi_jar/BongoMidi.jar
Binary file not shown.
67 changes: 29 additions & 38 deletions src/com/bongo/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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){
Expand All @@ -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() {
Expand Down
18 changes: 2 additions & 16 deletions src/com/bongo/Renderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f015087

Please sign in to comment.