From d8caaed9c7d52df463429d73c79bc6e81bcc12ee Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Mon, 10 Oct 2011 09:54:45 +0100 Subject: More midi changes. Need to improve the display of active ticks. --- .../open/punchingbag/examples/MidiSequencer.java | 33 +++++++++++++--------- 1 file 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 -- cgit v1.2.3