Class: HeadMusic::Content::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/head_music/content/player.rb

Overview

A player is a chair in a project: "Flute 1", "Piano".

The chair is project-level and the music is per-flow, which is what makes "the flute plays in movements 1 and 3" expressible without a nullable join -- there is simply no part for that player in movement 2 -- and what makes an instrument change within a part honest, since conceptually it is still the same player.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project: nil, name: nil) ⇒ Player

Returns a new instance of Player.



15
16
17
18
# File 'lib/head_music/content/player.rb', line 15

def initialize(project: nil, name: nil)
  @project = project
  @name = name
end

Instance Attribute Details

#name ⇒ Object

Returns the value of attribute name.



13
14
15
# File 'lib/head_music/content/player.rb', line 13

def name
  @name
end

#project ⇒ Object (readonly)

Returns the value of attribute project.



12
13
14
# File 'lib/head_music/content/player.rb', line 12

def project
  @project
end

Instance Method Details

#instruments ⇒ Object

Every instrument this player plays, across the project's flows.

Derived rather than stored: a stored field would drift from the parts that actually carry the instrument, and an instrument change lives on a part.



31
32
33
# File 'lib/head_music/content/player.rb', line 31

def instruments
  parts.flat_map(&:instruments).uniq
end

#parts ⇒ Object

This player's parts across the project's flows, in flow order.



21
22
23
24
25
# File 'lib/head_music/content/player.rb', line 21

def parts
  return [] if project.nil?

  project.flows.flat_map(&:parts).select { |part| part.player == self }
end

#primary_instrument ⇒ Object

What this player picks up first: the instrument in force at the opening of their first part. What a score order sorts by.



37
38
39
# File 'lib/head_music/content/player.rb', line 37

def primary_instrument
  parts.first&.instrument
end

#to_s ⇒ Object



41
42
43
# File 'lib/head_music/content/player.rb', line 41

def to_s
  name.to_s
end