Skip to content

Commit

Permalink
Added controls for bar style
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-schroeder committed Feb 13, 2015

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 9632f61 commit 94bf163
Showing 9 changed files with 135 additions and 12 deletions.
5 changes: 5 additions & 0 deletions src/main/java/com/soniccandle/controller/MainController.java
Original file line number Diff line number Diff line change
@@ -26,6 +26,9 @@ public class MainController implements ActionListener {
public static final String SET_BG_OTHER_IMAGE = "SET_BG_OTHER_IMAGE";
public static final String RENDER = "RENDER";
public static final String CANCEL_RENDER = "CANCEL_RENDER";
public static final String BAR_STYLE_THICK_BROCK = "01 thick block";
public static final String BAR_STYLE_OUTLINE_BLOCK = "02 outline block";
public static final String BAR_STYLE_THIN = "03 thin";

public MainModel m;
public MainView v;
@@ -200,6 +203,7 @@ public void lockWhileRendering() {
m.bgBuiltIn.setEnabled(false);
m.otherImageRb.setEnabled(false);
m.setBgOtherImageButton.setEnabled(false);
m.barStyle.setEnabled(false);
}

public void unlockAfterRender() {
@@ -216,5 +220,6 @@ public void unlockAfterRender() {
m.bgBuiltIn.setEnabled(true);
m.otherImageRb.setEnabled(true);
m.setBgOtherImageButton.setEnabled(true);
m.barStyle.setEnabled(true);
}
}
11 changes: 7 additions & 4 deletions src/main/java/com/soniccandle/controller/RenderSwingWorker.java
Original file line number Diff line number Diff line change
@@ -30,7 +30,9 @@ public Boolean doInBackground() {
try {
renderer = new SimpleRenderer(audioFile, videoFrameRate, width, height, outputTo);
renderer.backgroundImage = backgroundImage;
renderer.barStyle = (String) m.barStyle.getSelectedItem();
renderer.outputter = outputter;
m.progressBar.setValue(1);
renderer.start();
while (!renderer.isDone && !Thread.currentThread().isInterrupted()) {
renderer.renderNextFrame();
@@ -52,14 +54,15 @@ protected void process(List<Integer> progresses) {
@Override
public void done() {
c.unlockAfterRender();
if (m.progressBar.getValue() < 99) {
JOptionPane.showMessageDialog(null, "Canceled - may not have created entire video =\\");
return;
}
if (outputter instanceof XuggleVideoOutputter && outputTo.length() < 100) {
JOptionPane.showMessageDialog(null, "Ooof - looks like there was a problem, sorry. Please check that your adio file is 16-bit wav, not 24 or 32, thanks! Other bitrates coming soon, hopefully.");
return;
}
if (m.progressBar.getValue() < 99) {
JOptionPane.showMessageDialog(null, "Canceled - may not have created entire video =\\");
return;
}


JOptionPane.showMessageDialog(null, "Done!");
}
16 changes: 16 additions & 0 deletions src/main/java/com/soniccandle/model/BarDrawer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.soniccandle.model;

import java.awt.Graphics2D;

public abstract class BarDrawer {

public Graphics2D g;
public int half;

public BarDrawer(Graphics2D g, int half) {
this.g = g;
this.half = half;
}

public abstract void drawBar(int height, int x);
}
1 change: 1 addition & 0 deletions src/main/java/com/soniccandle/model/MainModel.java
Original file line number Diff line number Diff line change
@@ -39,4 +39,5 @@ public class MainModel {
public JRadioButton flatColorRb;
public JRadioButton builtInImageRb;
public JRadioButton otherImageRb;
public JComboBox<String> barStyle;
}
23 changes: 23 additions & 0 deletions src/main/java/com/soniccandle/model/OutlinBlockBarDrawer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.soniccandle.model;

import java.awt.BasicStroke;
import java.awt.Graphics2D;
import java.awt.Stroke;

public class OutlinBlockBarDrawer extends BarDrawer {

public OutlinBlockBarDrawer(Graphics2D g, int half) { super(g, half); }

@Override
public void drawBar(int height, int x) {
Stroke str = new BasicStroke(1);
g.setStroke(str);
g.drawLine(x+2, half, x+2, half+height); // draws down
g.drawLine(x-2, half, x-2, half+height); // draws down
g.drawLine(x-2, half+height, x+2, half+height); // draws across
g.drawLine(x+2, half, x+2, half-height); // draws up
g.drawLine(x-2, half, x-2, half-height); // draws up
g.drawLine(x-2, half-height, x+2, half-height); // draws across
}

}
19 changes: 13 additions & 6 deletions src/main/java/com/soniccandle/model/SimpleRenderer.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.soniccandle.model;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Stroke;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
@@ -12,12 +10,14 @@

import co.uk.labbookpages.WavFileException;

import com.soniccandle.controller.MainController;
import com.soniccandle.util.StereoData;
import com.soniccandle.util.Utils;

public class SimpleRenderer extends SpectrumRenderer {

public BufferedImage backgroundImage;
public String barStyle;

public SimpleRenderer(File audioFile, int frameRate, int width, int height, File outputTo) throws IOException, WavFileException {
super(audioFile, frameRate, width, height, outputTo);
@@ -71,15 +71,22 @@ public BufferedImage renderVFrame(long vFrameNum) throws IOException, WavFileExc
g.drawImage(backgroundImage, 0, 0, width, height, 0, 0, width, height, null);
Color white = new Color(255,255,255);
g.setColor(white);
Stroke str = new BasicStroke(7);
g.setStroke(str);
i = 0;
int x;
int half = height/2;

BarDrawer barDrawer = null;
if (barStyle.equals(MainController.BAR_STYLE_THICK_BROCK)) {
barDrawer = new ThickBlockBarDrawer(g, half);
} else if (barStyle.equals(MainController.BAR_STYLE_OUTLINE_BLOCK)) {
barDrawer = new OutlinBlockBarDrawer(g, half);
} else if (barStyle.equals(MainController.BAR_STYLE_THIN)) {
barDrawer = new ThinBarDrawer(g, half);
}

while (i < barCount) {
x = 40+(i*12);
g.drawLine(x, half, x, half+bars[i]); // draws down
g.drawLine(x, half, x, half-bars[i]); // draws up
barDrawer.drawBar(bars[i], x);
i ++;
}
return img;
19 changes: 19 additions & 0 deletions src/main/java/com/soniccandle/model/ThickBlockBarDrawer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.soniccandle.model;

import java.awt.BasicStroke;
import java.awt.Graphics2D;
import java.awt.Stroke;

public class ThickBlockBarDrawer extends BarDrawer {

public ThickBlockBarDrawer(Graphics2D g, int half) { super(g, half); }

@Override
public void drawBar(int height, int x) {
Stroke str = new BasicStroke(7);
g.setStroke(str);
g.drawLine(x, half, x, half+height); // draws down
g.drawLine(x, half, x, half-height); // draws up
}

}
19 changes: 19 additions & 0 deletions src/main/java/com/soniccandle/model/ThinBarDrawer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.soniccandle.model;

import java.awt.BasicStroke;
import java.awt.Graphics2D;
import java.awt.Stroke;

public class ThinBarDrawer extends BarDrawer {

public ThinBarDrawer(Graphics2D g, int half) { super(g, half); }

@Override
public void drawBar(int height, int x) {
Stroke str = new BasicStroke(2);
g.setStroke(str);
g.drawLine(x, half, x, half+height); // draws down
g.drawLine(x, half, x, half-height); // draws up
}

}
34 changes: 32 additions & 2 deletions src/main/java/com/soniccandle/view/MainView.java
Original file line number Diff line number Diff line change
@@ -213,6 +213,13 @@ public void createAndShowGUI() {
topC.gridx = 0;
topC.gridy = 2;
m.pane.add(bgPanel, topC);

JPanel barsPanel = makeBarsPanel();
topC.weightx = 1;
topC.gridx = 0;
topC.gridy = 3;
m.pane.add(barsPanel, topC);


JPanel renderPanel = new JPanel();
renderPanel.setLayout(new GridBagLayout());
@@ -243,7 +250,7 @@ public void createAndShowGUI() {

topC.weightx = 1;
topC.gridx = 0;
topC.gridy = 3;
topC.gridy = 4;
m.pane.add(renderPanel, topC);

m.fc = new JFileChooser();
@@ -254,7 +261,7 @@ public void createAndShowGUI() {
frame.pack();
frame.setVisible(true);
}

private JLabel getHeaderLabel() {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
BufferedImage header;
@@ -266,5 +273,28 @@ private JLabel getHeaderLabel() {
JLabel headerLabel = new JLabel(new ImageIcon(header));
return headerLabel;
}

private JPanel makeBarsPanel() {
JPanel barsPanel = new JPanel();
barsPanel.setLayout(new GridBagLayout());
barsPanel.setBorder(BorderFactory.createTitledBorder("bars"));
GridBagConstraints barsC = new GridBagConstraints();
barsC.insets = new Insets(5, 5, 5, 5);
barsC.fill = GridBagConstraints.BOTH;

JLabel label = new JLabel("bar style:");
barsC.gridwidth = 1;
barsC.gridx = 0;
barsC.gridy = 0;
barsPanel.add(label, barsC);

String[] barStyles = {MainController.BAR_STYLE_THICK_BROCK, MainController.BAR_STYLE_OUTLINE_BLOCK, MainController.BAR_STYLE_THIN};
m.barStyle = new JComboBox<String>(barStyles);
barsC.gridx = 1;
barsC.gridy = 0;
barsPanel.add(m.barStyle, barsC);

return barsPanel;
}

}

0 comments on commit 94bf163

Please sign in to comment.