aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--PunchingBag/src/uk/ac/open/punchingbag/examples/MidiSequencer.java33
1 files changed, 19 insertions, 14 deletions
diff --git a/PunchingBag/src/uk/ac/open/punchingbag/examples/MidiSequencer.java b/PunchingBag/src/uk/ac/open/punchingbag/examples/MidiSequencer.java
index 6947778..e7cbfba 100644
--- a/PunchingBag/src/uk/ac/open/punchingbag/examples/MidiSequencer.java
+++ b/PunchingBag/src/uk/ac/open/punchingbag/examples/MidiSequencer.java
@@ -58,9 +58,9 @@ public class MidiSequencer implements ButtonListener, Runnable {
for (int y = 0; y < bag.buttonHeight; y++) {
trackList = new int[bag.buttonWidth];
- int key =0;
+ int key = 0;
if (y < instruments.length) {
- key = instruments[y];
+ key = instruments[y];
} else {
// key = instruments[y - instruments.length];
}
@@ -80,7 +80,7 @@ public class MidiSequencer implements ButtonListener, Runnable {
track.add(makeEvent(192, 9, 1, 0, 15));
try {
sequencer.setSequence(sequence);
- //sequencer.setLoopCount(sequencer.LOOP_CONTINUOUSLY);
+ // sequencer.setLoopCount(sequencer.LOOP_CONTINUOUSLY);
sequencer.setLoopCount(1);
sequencer.start();
sequencer.setTempoInBPM(tempo);
@@ -138,23 +138,28 @@ public class MidiSequencer implements ButtonListener, Runnable {
}
+ private void draw(int tick) {
+ bag.clearLEDs();
+ bag.fillRect(tick, 0, 2, bag.ledHeight, Color.green);
+ for (int x = 0; x < bag.buttonWidth; x++) {
+ for (int y = 0; y < bag.buttonHeight; y++) {
+ if (buttons[x][y]) {
+ // bag.fillRect(x, y, 2, 2, Color.red);
+ bag.setLED(x, y, Color.red);
+ bag.setLED(x + 1, y + 1, Color.red);
+ }
+ }
+ }
+ }
+
@Override
public void run() {
while (true) {
buildTrackAndStart();
try {
for (int x = 0; x < 8; x++) {
- bag.fillRect(x, 0, 2, 8, Color.green);
- for (int y = 0; y < bag.buttonHeight; y++) {
- if (buttons[x][y])
- bag.fillRect(x, y, 2, 2, Color.red);
- }
- Thread.sleep(60000 / 120 / 4);
- bag.fillRect(x, 0, 2, 8, Color.white);
- for (int y = 0; y < bag.buttonHeight; y++) {
- if (buttons[x][y])
- bag.fillRect(x, y, 2, 2, Color.red);
- }
+ draw(x);
+ Thread.sleep(60000 / 120 / 2);
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block