Class: Zgomot::Midi::Time

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = nil) ⇒ Time

Returns a new instance of Time.



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

def initialize(args=nil)
  if args.kind_of?(Hash)
    [:measure, :beat, :tick].each{|a| raise(Zgomot::Error, "#{a} is a required argument") unless args.include?(a)}
    init_with_measure_beat_tick(args)
  elsif args.nil?; init_with_nil
  elsif args.kind_of?(Float); init_with_seconds(args); end
end

Instance Attribute Details

#beatObject (readonly)

Returns the value of attribute beat.



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

def beat
  @beat
end

#measureObject (readonly)

Returns the value of attribute measure.



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

def measure
  @measure
end

#secondsObject (readonly)

Returns the value of attribute seconds.



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

def seconds
  @seconds
end

#tickObject (readonly)

Returns the value of attribute tick.



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

def tick
  @tick
end

Instance Method Details

#+(add_time) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/zgomot/midi/clock.rb', line 20

def +(add_time)
  add_sec = if add_time.kind_of?(Float)
              add_time
            elsif add_time.kind_of?(Zgomot::Midi::Time)
              add_time.to_f
            else
              raise(Zgomot::Error, "#{add_time.class.name} is invalid. Must be Float or Zgomot::Midi::Time")
            end
  self.class.new(seconds+add_sec)
end

#to_fObject



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

def to_f
  seconds
end

#to_sObject



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

def to_s
  "%d:%d:%d" % [measure, beat, tick]
end