class Alda::Event

The class of elements of Alda::EventList#events.

Attributes

container[RW]

The Alda::EventContainer object that contains it. It may be nil if there is not a container containing it, especially probably when it itself is an Alda::EventContainer.

parent[RW]

The Alda::EventList object that contains it.

Note that it may not be directly contained, but with an Alda::EventContainer object in the middle.

Public Instance Methods

detach_from_parent() click to toggle source

Delete itself from its parent. If it is not at its parent's end, raises Alda::OrderError.

Here is a list of cases where the method is invoked:

  1. Using the sequence sugar when operating an Alda::EventList.

  2. Using Alda::EventContainer#/ to create chords or parts of multiple instruments.

  3. Using dot accessor of Alda::Part. See Alda::Part#method_missing.

  4. Using the inline lisp sugar. See Alda::InlineLisp.

This method needs invoking in these cases because if an event is created using Alda::EventList sugars (see Alda::EventList#method_missing), it is automatically pushed to its parent. However, the cases above requires the event be contained in another object.

# File lib/alda-rb/event.rb, line 63
def detach_from_parent
  if @parent && self != (got = @parent.events.pop)
    raise Alda::OrderError.new self, got
  end
end
on_contained() click to toggle source

The callback invoked when it is contained in an Alda::EventContainer. It is overridden in Alda::InlineLisp and Alda::EventList. It is called in Alda::EventContainer#on_containing.

class Alda::Note
  def on_contained
    super
    puts 'a note contained'
  end
end
Alda::Score.new { c } # => outputs "a note contained"
# File lib/alda-rb/event.rb, line 30
def on_contained
end
to_alda_code() → String click to toggle source

Converts to alda code. To be overridden in subclasses.

# File lib/alda-rb/event.rb, line 38
def to_alda_code
  ''
end