We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3444405 commit 15104f0Copy full SHA for 15104f0
2 files changed
external_library/java/minim/drum_machine.rb
@@ -14,6 +14,7 @@ class DrumMachine < Processing::App
14
java_import 'ddf.minim.ugens.Sampler'
15
attr_reader :minim, :out, :kick, :snare, :hat, :bpm, :buttons
16
attr_reader :kikRow, :snrRow, :hatRow
17
+ attr_accessor :beat
18
def setup
19
sketch_title 'Drum Machine'
20
minim = Minim.new(self)
@@ -23,7 +24,7 @@ def setup
23
24
@kikRow = Array.new(16, false)
25
@buttons = []
26
@bpm = 120
- $beat = 0
27
+ @beat = 0
28
# load all of our samples, using 4 voices for each.
29
# this will help ensure we have enough voices to handle even
30
# very fast tempos.
@@ -50,9 +51,9 @@ def draw
50
51
# text(frameRate, width - 60, 20)
52
buttons.each(&:draw)
53
stroke(128)
- ($beat % 4).zero? ? fill(200, 0, 0) : fill(0, 200, 0)
54
+ (beat % 4).zero? ? fill(200, 0, 0) : fill(0, 200, 0)
55
# beat marker
- rect(10 + $beat * 24, 35, 14, 9)
56
+ rect(10 + beat * 24, 35, 14, 9)
57
end
58
59
def mouse_pressed
external_library/java/minim/library/tick/lib/tick.rb
@@ -1,20 +1,21 @@
1
# frozen_string_literal: true
2
3
java_import 'ddf.minim.ugens.Instrument'
4
-
+# class Tick can access app variables by including Processing::App module
5
+# But we must use instance variable to set the beat
6
class Tick
7
include Instrument
8
include Processing::Proxy
9
10
def noteOn(_dur)
- hat.trigger if hatRow[$beat]
11
- snare.trigger if snrRow[$beat]
12
- kick.trigger if kikRow[$beat]
+ hat.trigger if hatRow[beat]
+ snare.trigger if snrRow[beat]
13
+ kick.trigger if kikRow[beat]
def noteOff
# next beat
- $beat = ($beat + 1) % 16
+ Processing.app.beat = (beat + 1) % 16
# set the new tempo
out.setTempo(bpm)
21
# play this again right now, with a sixteenth note duration
0 commit comments