Class: Zgomot::Midi::Clock
Class Attribute Summary collapse
-
.beat_note ⇒ Object
Returns the value of attribute beat_note.
-
.beat_sec ⇒ Object
Returns the value of attribute beat_sec.
-
.beats_per_measure ⇒ Object
Returns the value of attribute beats_per_measure.
-
.beats_per_minute ⇒ Object
Returns the value of attribute beats_per_minute.
-
.measure_sec ⇒ Object
Returns the value of attribute measure_sec.
-
.resolution ⇒ Object
Returns the value of attribute resolution.
-
.tick_sec ⇒ Object
Returns the value of attribute tick_sec.
-
.ticks_per_beat ⇒ Object
Returns the value of attribute ticks_per_beat.
-
.time_signature ⇒ Object
Returns the value of attribute time_signature.
-
.whole_note_sec ⇒ Object
Returns the value of attribute whole_note_sec.
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#current_time ⇒ Object
readonly
Returns the value of attribute current_time.
Class Method Summary collapse
Instance Method Summary collapse
- #+(add_clock) ⇒ Object
- #absolute_sec ⇒ Object
- #ceil ⇒ Object
-
#initialize ⇒ Clock
constructor
A new instance of Clock.
- #to_s ⇒ Object
- #update(time = nil) ⇒ Object
Constructor Details
Class Attribute Details
.beat_note ⇒ Object
Returns the value of attribute beat_note.
48 49 50 |
# File 'lib/zgomot/midi/clock.rb', line 48 def beat_note @beat_note end |
.beat_sec ⇒ Object
Returns the value of attribute beat_sec.
48 49 50 |
# File 'lib/zgomot/midi/clock.rb', line 48 def beat_sec @beat_sec end |
.beats_per_measure ⇒ Object
Returns the value of attribute beats_per_measure.
48 49 50 |
# File 'lib/zgomot/midi/clock.rb', line 48 def beats_per_measure @beats_per_measure end |
.beats_per_minute ⇒ Object
Returns the value of attribute beats_per_minute.
48 49 50 |
# File 'lib/zgomot/midi/clock.rb', line 48 def beats_per_minute @beats_per_minute end |
.measure_sec ⇒ Object
Returns the value of attribute measure_sec.
48 49 50 |
# File 'lib/zgomot/midi/clock.rb', line 48 def measure_sec @measure_sec end |
.resolution ⇒ Object
Returns the value of attribute resolution.
48 49 50 |
# File 'lib/zgomot/midi/clock.rb', line 48 def resolution @resolution end |
.tick_sec ⇒ Object
Returns the value of attribute tick_sec.
48 49 50 |
# File 'lib/zgomot/midi/clock.rb', line 48 def tick_sec @tick_sec end |
.ticks_per_beat ⇒ Object
Returns the value of attribute ticks_per_beat.
48 49 50 |
# File 'lib/zgomot/midi/clock.rb', line 48 def ticks_per_beat @ticks_per_beat end |
.time_signature ⇒ Object
Returns the value of attribute time_signature.
48 49 50 |
# File 'lib/zgomot/midi/clock.rb', line 48 def time_signature @time_signature end |
.whole_note_sec ⇒ Object
Returns the value of attribute whole_note_sec.
48 49 50 |
# File 'lib/zgomot/midi/clock.rb', line 48 def whole_note_sec @whole_note_sec end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
64 65 66 |
# File 'lib/zgomot/midi/clock.rb', line 64 def created_at @created_at end |
#current_time ⇒ Object (readonly)
Returns the value of attribute current_time.
64 65 66 |
# File 'lib/zgomot/midi/clock.rb', line 64 def current_time @current_time end |
Class Method Details
.set_config(config) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/zgomot/midi/clock.rb', line 51 def set_config(config) @time_signature = config[:time_signature] || '4/4' @beats_per_minute = (config[:beats_per_minute] || '120').to_f @resolution = (config[:resolution] || '1/32').split('/').last.to_f @beats_per_measure, @beat_note = @time_signature.split('/').map{|v| v.to_f} @ticks_per_beat = @resolution/@beats_per_measure @beat_sec= 60.0/@beats_per_minute @whole_note_sec = @beat_sec*@beat_note @measure_sec = @beat_sec*@beats_per_measure @tick_sec = @whole_note_sec/(@resolution);nil end |
Instance Method Details
#+(add_clock) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/zgomot/midi/clock.rb', line 71 def +(add_clock) @current_time + if add_clock.knd_of(Float) or add_time.kind_of?(Zgomot::Midi::Time) add_clock elsif add_time.kind_of?(Zgomot::Midi::Clock) add_clock.current_time else raise(Zgomot::Error, "#{add_clock.class.name} is invalid. Must be Float, Zgomot::Midi::Time or Zgomot::Midi::Clock") end end |
#absolute_sec ⇒ Object
80 81 82 |
# File 'lib/zgomot/midi/clock.rb', line 80 def absolute_sec @current_time + created_at end |
#ceil ⇒ Object
83 84 85 86 87 |
# File 'lib/zgomot/midi/clock.rb', line 83 def ceil Time.new(:measure => @current_time.measure + 1, :beat => 0, :tick => 0) end |
#to_s ⇒ Object
68 69 70 |
# File 'lib/zgomot/midi/clock.rb', line 68 def to_s @current_time.to_s end |
#update(time = nil) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/zgomot/midi/clock.rb', line 88 def update(time=nil) csecs = if time.kind_of?(Float) current_time.to_f + time elsif time.kind_of?(Zgomot::Midi::Time) current_time.to_f + time.to_f elsif time.nil? current_time.to_f + Clock.tick_sec else raise(Zgomot::Error, "argument must by of type Float or Zgomot::Midi::Time") end @current_time = Time.new(csecs) end |