class Alda::Part

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

A part can have nickname.

Alda::Score.new do
  piano_ 'player1'
  c4 d e e e1
  piano_ 'player2'
  e4 d g g g1
end

You can use Alda::EventContainer#/ to have a set of instruments.

Alda::Score.new do
  violin_/viola_
  c2 d4 e2_4
end

A set of instruments can also have nickname. You can also access an instruments from a set. See method_missing.

Alda::Score.new do
  violin_/viola_/cello_('strings')
  g1_1_1
  strings_.cello_
  c1_1_1
end

Attributes

arg[RW]

The nickname of the part. nil if none.

names[RW]

The names of the part. To be joined with / as delimiter.

Public Class Methods

new(names, arg=nil) → Alda::Part click to toggle source

Creates an Alda::Part.

Calls superclass method
# File lib/alda-rb/event.rb, line 846
def initialize names, arg = nil
  super()
  @names = names.map { Alda::Utils.snake_to_slug _1 }
  @arg = arg
end

Public Instance Methods

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

Overrides Alda::Event#==. Returns true if other is an Alda::Part and has the same names and arg as part (using ==).

Calls superclass method Alda::Event#==
# File lib/alda-rb/event.rb, line 896
def == other
  super || other.is_a?(Alda::Part) && @names == other.names && @arg == other.arg
end
(component)_() → Alda::EventContainer or Alda::Part click to toggle source

Enables dot accessor.

Alda::Score.new do
  violin_/viola_/cello_('strings'); g1_1_1
  strings_.cello_; -o; c1_1_1
end.play
Calls superclass method
# File lib/alda-rb/event.rb, line 873
def method_missing name, *args
  str = name.to_s
  return super unless str[-1] == ?_
  str[-1] = ''
  @names.last.concat ?., str
  if args.size == 1
    arg = args.first.tap &:detach_from_parent
    detach_from_parent
    container = Alda::EventContainer.new Alda::Sequence.join(self, arg), @parent
    @parent.events.push container
    container
  else
    @container || self
  end
end
to_alda_code() → String click to toggle source

Overrides Alda::Event#to_alda_code.

# File lib/alda-rb/event.rb, line 857
def to_alda_code
  result = @names.join ?/
  result.concat " \"#{@arg}\"" if @arg
  result.concat ?:
end