Class: Alda::Octave
Overview
An octave event. An Alda::EventContainer containing an Alda::Octave can be derived using event list sugar. See Alda::EventList#method_missing.
o!
means octave up, and o?
means octave down. You can also use #+@ and #-@ to denote octave up and down.
Instance Attribute Summary collapse
-
#num ⇒ Object
The string representing the octave’s number.
-
#up_or_down ⇒ Object
Positive for up, negative for down, and
0
as default.
Attributes inherited from Event
Instance Method Summary collapse
-
#+@ ⇒ Object
:call-seq: +octave -> octave.
-
#-@ ⇒ Object
:call-seq: -octave -> octave.
-
#==(other) ⇒ Object
:call-seq: octave == other -> true or false.
-
#initialize(num) ⇒ Octave
constructor
:call-seq: new(num) -> Alda::Octave.
-
#to_alda_code ⇒ Object
:call-seq: to_alda_code() -> String.
Methods inherited from Event
#detach_from_parent, #is_event_of?, #on_contained
Constructor Details
#initialize(num) ⇒ Octave
:call-seq:
new(num) -> Alda::Octave
Creates an Alda::Octave.
672 673 674 675 676 |
# File 'lib/alda-rb/event.rb', line 672 def initialize num super() @num = num.to_s @up_or_down = 0 end |
Instance Attribute Details
#num ⇒ Object
The string representing the octave’s number.
It can be empty, in which case it is purely serving for #+@ and #-@.
657 658 659 |
# File 'lib/alda-rb/event.rb', line 657 def num @num end |
Instance Method Details
#+@ ⇒ Object
688 689 690 691 |
# File 'lib/alda-rb/event.rb', line 688 def +@ @up_or_down += 1 self end |
#-@ ⇒ Object
:call-seq:
-octave -> octave
Octave down. See #+@.
699 700 701 702 |
# File 'lib/alda-rb/event.rb', line 699 def -@ @up_or_down -= 1 self end |
#==(other) ⇒ Object
:call-seq:
octave == other -> true or false
Overrides Alda::Event#==. Returns true if other
is an Alda::Octave and has the same #num and #up_or_down as octave
(using ==
).
727 728 729 |
# File 'lib/alda-rb/event.rb', line 727 def == other super || other.is_a?(Alda::Octave) && @num == other.num && @up_or_down == other.up_or_down end |
#to_alda_code ⇒ Object
:call-seq:
to_alda_code() -> String
Overrides Alda::Event#to_alda_code.
709 710 711 712 713 714 715 716 717 718 |
# File 'lib/alda-rb/event.rb', line 709 def to_alda_code case @up_or_down <=> 0 when 0 ?o + @num when 1 ?> * @up_or_down when -1 ?< * -@up_or_down end end |