Skip to content

Commit

Permalink
Use global $beat (not happy!) but it works
Browse files Browse the repository at this point in the history
  • Loading branch information
monkstone committed Dec 15, 2019
1 parent efc49ab commit 3444405
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
12 changes: 4 additions & 8 deletions external_library/java/minim/drum_machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ class DrumMachine < Processing::App
load_libraries :minim, :tick
java_import 'ddf.minim.Minim'
java_import 'ddf.minim.ugens.Sampler'

attr_reader :minim, :out, :kick, :snare, :hat, :bpm, :beat, :buttons
attr_reader :minim, :out, :kick, :snare, :hat, :bpm, :buttons
attr_reader :kikRow, :snrRow, :hatRow
def setup
sketch_title 'Drum Machine'
Expand All @@ -24,7 +23,7 @@ def setup
@kikRow = Array.new(16, false)
@buttons = []
@bpm = 120
@beat = 0
$beat = 0
# load all of our samples, using 4 voices for each.
# this will help ensure we have enough voices to handle even
# very fast tempos.
Expand All @@ -49,14 +48,11 @@ def draw
background(0)
fill(255)
# text(frameRate, width - 60, 20)

buttons.each(&:draw)

stroke(128)
(beat % 4).zero? ? fill(200, 0, 0) : fill(0, 200, 0)

($beat % 4).zero? ? fill(200, 0, 0) : fill(0, 200, 0)
# beat marker
rect(10 + beat * 24, 35, 14, 9)
rect(10 + $beat * 24, 35, 14, 9)
end

def mouse_pressed
Expand Down
8 changes: 4 additions & 4 deletions external_library/java/minim/library/tick/lib/tick.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ class Tick
include Processing::Proxy

def noteOn(_dur)
hat.trigger if hatRow[beat]
snare.trigger if snrRow[beat]
kick.trigger if kikRow[beat]
hat.trigger if hatRow[$beat]
snare.trigger if snrRow[$beat]
kick.trigger if kikRow[$beat]
end

def noteOff
# next beat
@beat = (beat + 1) % 16
$beat = ($beat + 1) % 16
# set the new tempo
out.setTempo(bpm)
# play this again right now, with a sixteenth note duration
Expand Down

0 comments on commit 3444405

Please sign in to comment.