Class: Alda::Event
- Inherits:
-
Object
- Object
- Alda::Event
- Defined in:
- lib/alda-rb/event.rb
Overview
The class of elements of Alda::EventList#events.
Direct Known Subclasses
AtMarker, Chord, Cram, EventContainer, GetVariable, InlineLisp, LispIdentifier, Marker, Note, Octave, Part, Raw, Rest, Sequence, SetVariable, Voice
Instance Attribute Summary collapse
-
#container ⇒ Object
The Alda::EventContainer object that contains it.
-
#parent ⇒ Object
The Alda::EventList object that contains it.
Instance Method Summary collapse
-
#==(other) ⇒ Object
:call-seq: event == other -> true or false.
-
#detach_from_parent(except = []) ⇒ Object
Delete itself (or its topmost container if it has) from its #parent.
-
#is_event_of?(klass) ⇒ Boolean
:call-seq: is_event_of?(klass) -> true or false.
-
#on_contained ⇒ Object
The callback invoked when it is contained in an Alda::EventContainer.
-
#to_alda_code ⇒ Object
:call-seq: to_alda_code() -> String.
Instance Attribute Details
#container ⇒ Object
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.
16 17 18 |
# File 'lib/alda-rb/event.rb', line 16 def container @container end |
#parent ⇒ Object
The Alda::EventList object that contains it.
Note that it may not be directly contained, but with an Alda::EventContainer object in the middle.
10 11 12 |
# File 'lib/alda-rb/event.rb', line 10 def parent @parent end |
Instance Method Details
#==(other) ⇒ Object
:call-seq:
event == other -> true or false
Whether it is equal to other
. To be overriden.
Note that #parent and #container should not be taken into account when comparing two events.
94 95 96 |
# File 'lib/alda-rb/event.rb', line 94 def == other super end |
#detach_from_parent(except = []) ⇒ Object
Delete itself (or its topmost container if it has) 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:
-
Using the sequence sugar when operating an Alda::EventList.
-
Using Alda::EventContainer#/ to create chords or parts of multiple instruments.
-
Using dot accessor of Alda::Part. See Alda::Part#method_missing.
-
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.
The parameter except
specifies an Array of classes. If #parent is an instance of any of the classes in except
, the method does nothing.
67 68 69 70 71 72 73 |
# File 'lib/alda-rb/event.rb', line 67 def detach_from_parent except = [] event = self event = event.container while event.container if @parent && except.none? { @parent.is_a? _1 } && event != (got = @parent.events.pop) raise Alda::OrderError.new event, got end end |
#is_event_of?(klass) ⇒ Boolean
:call-seq:
is_event_of?(klass) -> true or false
Whether it is an event of the given class (klass
). By default, this is the same as is_a?(klass). It is overridden in Alda::EventContainer.
82 83 84 |
# File 'lib/alda-rb/event.rb', line 82 def is_event_of? klass is_a? klass end |
#on_contained ⇒ Object
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"
30 31 |
# File 'lib/alda-rb/event.rb', line 30 def on_contained end |
#to_alda_code ⇒ Object
:call-seq:
to_alda_code() -> String
Converts to alda code. To be overridden in subclasses.
38 39 40 |
# File 'lib/alda-rb/event.rb', line 38 def to_alda_code '' end |