Class: Alda::Rest

Inherits:
Event
  • Object
show all
Defined in:
lib/alda-rb/event.rb

Overview

A rest event. An Alda::EventContainer containing an Alda::Rest can be created using event list sugar. See Alda::EventList#method_missing.

When using event list sugar, its duration can be specified just like that of Alda::Note.

Alda::Score.new do
  piano_ c8 r4 c8 r4 c4
end

Instance Attribute Summary collapse

Attributes inherited from Event

#container, #parent

Instance Method Summary collapse

Methods inherited from Event

#detach_from_parent, #is_event_of?, #on_contained

Constructor Details

#initialize(duration) ⇒ Rest

:call-seq:

new(duration) -> Alda::Rest

Creates an Alda::Rest.

Underlines “_” in duration will be converted to tildes “~”.



617
618
619
620
# File 'lib/alda-rb/event.rb', line 617

def initialize duration
	super()
	@duration = duration.to_s.tr ?_, ?~
end

Instance Attribute Details

#durationObject

The string representing a duration.



608
609
610
# File 'lib/alda-rb/event.rb', line 608

def duration
  @duration
end

Instance Method Details

#==(other) ⇒ Object

:call-seq:

rest == other -> true or false

Overrides Alda::Event#==. Returns true if other is an Alda::Rest and has the same #duration as rest (using ==).



638
639
640
# File 'lib/alda-rb/event.rb', line 638

def == other
	super || other.is_a?(Alda::Rest) && @duration == other.duration
end

#to_alda_codeObject

:call-seq:

to_alda_code() -> String

Overrides Alda::Event#to_alda_code.



627
628
629
# File 'lib/alda-rb/event.rb', line 627

def to_alda_code
	?r + @duration
end