Class: Alda::SetVariable

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

Overview

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

Instance Attribute Summary collapse

Attributes included from EventList

#events, #variables

Attributes inherited from Event

#container, #parent

Instance Method Summary collapse

Methods included from EventList

#events_alda_codes, #has_variable?, #import, #method_missing, #to_a

Methods inherited from Event

#detach_from_parent, #is_event_of?

Constructor Details

#initialize(name, *events, &block) ⇒ SetVariable

:call-seq:

new(name, *events, &block) -> Alda::SetVariable

Creates an Alda::SetVariable.



1205
1206
1207
1208
1209
# File 'lib/alda-rb/event.rb', line 1205

def initialize name, *events, &block
	@name = name.to_sym
	@events = events
	super &block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Alda::EventList

Instance Attribute Details

#nameObject

The name of the variable.



1198
1199
1200
# File 'lib/alda-rb/event.rb', line 1198

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object

:call-seq:

set_variable == other -> true or false

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



1237
1238
1239
# File 'lib/alda-rb/event.rb', line 1237

def == other
	super && @name == other.name
end

#on_containedObject

See Alda::Event#on_contained.



1223
1224
1225
1226
1227
1228
# 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_codeObject

:call-seq:

to_alda_code() -> String

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



1217
1218
1219
# File 'lib/alda-rb/event.rb', line 1217

def to_alda_code
	"#@name = #{events_alda_codes}\n"
end