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.

original_events[R]

The events passed to it using arguments instead of a block.

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 906
def initialize name, *events, &block
  @name = name.to_sym
  @original_events = events
  @events = events.clone
  super &block
end

Public Instance Methods

on_contained() click to toggle source
Calls superclass method Alda::EventList#on_contained
# File lib/alda-rb/event.rb, line 919
def on_contained
  super
  @parent.variables.add @name
  @original_events.detach_from_parent
end
to_alda_code() click to toggle source

Specially, the returned value ends with a newline ā€œ\nā€.

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