class MTK::Events::Rest
An interval of silence.
By convention, MTK
uses {Core::Duration}s with negative values for rests. This class forces the {#duration} to always have a negative value.
@note Because a negative durations indicate rests, other {Event} classes may represent rests too.
Therefore, you should always determine if an {Event} is a rest via the {#rest?} method, instead of seeing if the class is an MTK::Events::Rest
Public Class Methods
from_h(hash)
click to toggle source
# File lib/mtk/events/rest.rb, line 20 def self.from_h(hash) new(hash[:duration], hash[:channel]) end
new(duration, channel=nil)
click to toggle source
Calls superclass method
MTK::Events::Event::new
# File lib/mtk/events/rest.rb, line 15 def initialize(duration, channel=nil) super :rest, duration:duration, channel:channel self.duration = @duration # force to be a rest end
Public Instance Methods
duration=(duration)
click to toggle source
Assign the duration, forcing to a negative value to indicate this is a rest.
Calls superclass method
MTK::Events::Event#duration=
# File lib/mtk/events/rest.rb, line 25 def duration= duration super @duration = -@duration unless @duration.rest? # force to be a rest end
inspect()
click to toggle source
# File lib/mtk/events/rest.rb, line 44 def inspect "#<#{self.class}:#{object_id} @duration=#{@duration.inspect}" + if @channel then ", @channel=#{@channel}>" else '>' end end
midi_value()
click to toggle source
Rests don’t have a corresponding value in MIDI
, so this is nil @return nil
# File lib/mtk/events/rest.rb, line 32 def midi_value nil end
midi_value=(value)
click to toggle source
Rests don’t have a corresponding value in MIDI
, so this is a no-op
# File lib/mtk/events/rest.rb, line 37 def midi_value= value end
to_s()
click to toggle source
# File lib/mtk/events/rest.rb, line 40 def to_s "Rest(#{@duration})" end