class Musicality::Part

Attributes

dynamic_changes[RW]
notes[RW]
settings[RW]
start_dynamic[RW]

Public Class Methods

new(start_dynamic, notes: [], dynamic_changes: {}) { |self| ... } click to toggle source
# File lib/musicality/notation/model/part.rb, line 12
def initialize start_dynamic, notes: [], dynamic_changes: {}, settings: []
  @notes = notes
  @start_dynamic = start_dynamic
  @dynamic_changes = dynamic_changes
  @settings = settings

  yield(self) if block_given?
end

Public Instance Methods

==(other) click to toggle source
# File lib/musicality/notation/model/part.rb, line 33
def ==(other)
  return (@notes == other.notes) &&
  (@start_dynamic == other.start_dynamic) &&
  (@dynamic_changes == other.dynamic_changes)
end
check_dynamic_changes() click to toggle source
# File lib/musicality/notation/model/part.rb, line 49
def check_dynamic_changes
  outofrange = @dynamic_changes.values.select {|v| !v.end_value.between?(0,1) }
  if outofrange.any?
    raise RangeError, "dynamic change values #{outofrange} are not between 0 and 1"
  end
end
check_methods() click to toggle source
# File lib/musicality/notation/model/part.rb, line 21
def check_methods
  [:check_start_dynamic, :check_dynamic_changes]
end
check_start_dynamic() click to toggle source
# File lib/musicality/notation/model/part.rb, line 43
def check_start_dynamic
  unless @start_dynamic.between?(0,1)
    raise RangeError, "start dynamic #{@start_dynamic} is not between 0 and 1"
  end
end
clone() click to toggle source
# File lib/musicality/notation/model/part.rb, line 29
def clone
  Marshal.load(Marshal.dump(self))
end
duration() click to toggle source
# File lib/musicality/notation/model/part.rb, line 39
def duration
  return @notes.inject(0) { |sum, note| sum + note.duration }
end
dynamic_change(new_dynamic, transition_dur: 0, offset: 0) click to toggle source
# File lib/musicality/composition/dsl/part_methods.rb, line 4
def dynamic_change new_dynamic, transition_dur: 0, offset: 0
  if transition_dur == 0
    change = (transition_dur == 0) ? Change::Immediate.new(new_dynamic) : Change::Gradual.linear(new_dynamic, transition_dur)
    self.dynamic_changes[self.duration + offset] = change
  end
end
find_settings(settings_class) click to toggle source
# File lib/musicality/notation/model/part.rb, line 62
def find_settings settings_class
  settings.find {|s| s.is_a? settings_class }
end
lilypond_settings() click to toggle source
# File lib/musicality/printing/lilypond/lilypond_settings.rb, line 100
def lilypond_settings
  find_settings(LilypondSettings)
end
midi_settings() click to toggle source
# File lib/musicality/performance/midi/midi_settings.rb, line 122
def midi_settings
  find_settings(MidiSettings)
end
synthdef_settings() click to toggle source
# File lib/musicality/performance/supercollider/synthdef.rb, line 52
def synthdef_settings
  find_settings(SuperCollider::SynthDef::Settings)
end
transpose(interval) click to toggle source
# File lib/musicality/notation/model/part.rb, line 56
def transpose interval
  p = self.clone
  p.notes.each {|n| n.transpose!(interval) }
  return p
end
validatables() click to toggle source
# File lib/musicality/notation/model/part.rb, line 25
def validatables
  @notes
end