Skip to content

Commit 3444405

Browse files
committed
Use global $beat (not happy!) but it works
1 parent efc49ab commit 3444405

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

external_library/java/minim/drum_machine.rb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ class DrumMachine < Processing::App
1212
load_libraries :minim, :tick
1313
java_import 'ddf.minim.Minim'
1414
java_import 'ddf.minim.ugens.Sampler'
15-
16-
attr_reader :minim, :out, :kick, :snare, :hat, :bpm, :beat, :buttons
15+
attr_reader :minim, :out, :kick, :snare, :hat, :bpm, :buttons
1716
attr_reader :kikRow, :snrRow, :hatRow
1817
def setup
1918
sketch_title 'Drum Machine'
@@ -24,7 +23,7 @@ def setup
2423
@kikRow = Array.new(16, false)
2524
@buttons = []
2625
@bpm = 120
27-
@beat = 0
26+
$beat = 0
2827
# load all of our samples, using 4 voices for each.
2928
# this will help ensure we have enough voices to handle even
3029
# very fast tempos.
@@ -49,14 +48,11 @@ def draw
4948
background(0)
5049
fill(255)
5150
# text(frameRate, width - 60, 20)
52-
5351
buttons.each(&:draw)
54-
5552
stroke(128)
56-
(beat % 4).zero? ? fill(200, 0, 0) : fill(0, 200, 0)
57-
53+
($beat % 4).zero? ? fill(200, 0, 0) : fill(0, 200, 0)
5854
# beat marker
59-
rect(10 + beat * 24, 35, 14, 9)
55+
rect(10 + $beat * 24, 35, 14, 9)
6056
end
6157

6258
def mouse_pressed

external_library/java/minim/library/tick/lib/tick.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ class Tick
77
include Processing::Proxy
88

99
def noteOn(_dur)
10-
hat.trigger if hatRow[beat]
11-
snare.trigger if snrRow[beat]
12-
kick.trigger if kikRow[beat]
10+
hat.trigger if hatRow[$beat]
11+
snare.trigger if snrRow[$beat]
12+
kick.trigger if kikRow[$beat]
1313
end
1414

1515
def noteOff
1616
# next beat
17-
@beat = (beat + 1) % 16
17+
$beat = ($beat + 1) % 16
1818
# set the new tempo
1919
out.setTempo(bpm)
2020
# play this again right now, with a sixteenth note duration

0 commit comments

Comments
 (0)