From 344440597ba841f6fe04b2839862d878ffc1b01b Mon Sep 17 00:00:00 2001 From: Martin Prout Date: Sun, 15 Dec 2019 15:21:46 +0000 Subject: [PATCH] Use global $beat (not happy!) but it works --- external_library/java/minim/drum_machine.rb | 12 ++++-------- external_library/java/minim/library/tick/lib/tick.rb | 8 ++++---- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/external_library/java/minim/drum_machine.rb b/external_library/java/minim/drum_machine.rb index 9e83433..770a7d2 100644 --- a/external_library/java/minim/drum_machine.rb +++ b/external_library/java/minim/drum_machine.rb @@ -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' @@ -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. @@ -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 diff --git a/external_library/java/minim/library/tick/lib/tick.rb b/external_library/java/minim/library/tick/lib/tick.rb index 777ebae..bfc78e2 100644 --- a/external_library/java/minim/library/tick/lib/tick.rb +++ b/external_library/java/minim/library/tick/lib/tick.rb @@ -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