Class: Archaeopteryx::Midi::Clock

Inherits:
Object
  • Object
show all
Defined in:
lib/midi/clock.rb

Overview

< Singleton

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Clock) initialize(bpm)



6
7
8
9
10
11
# File 'lib/midi/clock.rb', line 6

def initialize(bpm)
 # assumes 16-step step sequencer, 4/4 beat, etc.
  self.bpm = bpm
  @start = Time.now.to_f
  @time = 0
end

Instance Attribute Details

- (Object) interval (readonly)

Returns the value of attribute interval



5
6
7
# File 'lib/midi/clock.rb', line 5

def interval
  @interval
end

- (Object) start (readonly)

Returns the value of attribute start



5
6
7
# File 'lib/midi/clock.rb', line 5

def start
  @start
end

- (Object) time (readonly)

Returns the value of attribute time



5
6
7
# File 'lib/midi/clock.rb', line 5

def time
  @time
end

Instance Method Details

- (Object) bpm=(bpm)



12
13
14
15
16
# File 'lib/midi/clock.rb', line 12

def bpm=(bpm)
  seconds_in_a_minute = 60.0
  beats_in_a_measure = 4.0
  @interval = seconds_in_a_minute / bpm.to_f / beats_in_a_measure
end

- (Object) tick



17
18
19
20
# File 'lib/midi/clock.rb', line 17

def tick
  @time += @interval
  @time
end