class Alda::SetVariable

A set-variable event. Includes Alda::EventList.

An Alda::EventContainer containing an Alda::SetVariable can be derived using event list sugar. See Alda::EventList#method_missing.

There are several equivalent means of setting variable. Some of them can be ambiguous with Alda::InlineLisp or Alda::GetVariable, but it is intelligently chosen.

Alda::Score.new do
  p var.event.class               # => Alda::InlineLisp
  p((var c d e f).event.class)    # => Alda::SetVariable
  p var { c d e f }.event.class   # => Alda::SetVariable
  p((var__ c d e f).event.class)  # => Alda::SetVariable
  p var__ { c d e f }.event.class # => Alda::SetVariable
  p((var c d e f).event.class)    # => Alda::Sequence
  p var.event.class               # => Alda::GetVariable
  p var(1).event.class            # => Alda::InlineLisp
end

Attributes

name[RW]

The name of the variable.

Public Class Methods

new(name, *events, &block) → Alda::SetVariable click to toggle source

Creates an Alda::SetVariable.

Calls superclass method Alda::EventList::new
# File lib/alda-rb/event.rb, line 1205
def initialize name, *events, &block
  @name = name.to_sym
  @events = events
  super &block
end

Public Instance Methods

set_variable == other → true or false click to toggle source

Overrides Alda::EventList#==. Returns true if the super method returns true and other has the same name as set_variable (using ==).

Calls superclass method Alda::EventList#==
# File lib/alda-rb/event.rb, line 1237
def == other
  super && @name == other.name
end
on_contained() click to toggle source

See Alda::Event#on_contained.

Calls superclass method Alda::EventList#on_contained
# File lib/alda-rb/event.rb, line 1223
def on_contained
  super
  @parent.variables.add @name
  @events.detach_from_parent [self.class]
  @events.each { _1.parent = self if _1.is_a? Alda::Event }
end
to_alda_code() → String click to toggle source

Specially, the returned value ends with a newline ā€œ\nā€. Overrides Alda::Event#to_alda_code.

# File lib/alda-rb/event.rb, line 1217
def to_alda_code
  "#@name = #{events_alda_codes}\n"
end