class Alda::Chord
A chord event. Includes Alda::EventList
.
An Alda::EventContainer
containing an Alda::Chord
can be created using event list sugar. See Alda::EventList#method_missing
.
Alda::Score.new do p x{ c; e; g }.event.class # => Alda::Chord end
The event contained by an Alda::EventContainer
can become an Alda::Chord
by using Alda::EventContainer#/
.
Public Class Methods
There is an event list sugar invoking this method. See Alda::EventList#method_missing
.
In most cases, events
should be empty. Note that events
cannot be specified using the sugar. block
is to be passed with the chord object as self
.
Alda::Score.new { piano_; x { c; -e; g } }.play # (plays chord Cm)
Alda::EventList::new
# File lib/alda-rb/event.rb, line 762 def initialize *events, &block events.each { _1.parent = self if _1.is_a? Alda::Event } @events = events super &block end
Public Instance Methods
Overrides Alda::Event#to_alda_code
.
Behaves differently for Alda 1 and Alda 2: because Alda 2 does not allow octave changes as part of a chord (something like a/>/c
, and we have to write a>/c
or a/>c
instead) (alda-lang/alda#383), the code generated by this method will omit the slash before an octave change.
Alda.generation = :v1 Alda::Score.new { a/o!/c; a/o5/c }.to_s # => "a/>/c a/o5/c" Alda.generation = :v2 Alda::Score.new { a/o!/c; a/o5/c }.to_s # => "a>/c a o5/c"
# File lib/alda-rb/event.rb, line 784 def to_alda_code return events_alda_codes ?/ if Alda.v1? @events.each_with_index.with_object '' do |(event, i), result| if i == 0 # concat nothing elsif event.is_event_of? Alda::Octave result.concat ' ' unless event.num.empty? else result.concat '/' end result.concat event.to_alda_code end end