class Musicality::NoteSequence

Constants

Element

Attributes

elements[RW]
offset[RW]
separation[RW]
start[RW]

Public Class Methods

adjust_duration(duration, separation) click to toggle source
# File lib/musicality/performance/model/note_sequence.rb, line 6
def self.adjust_duration duration, separation
  function = case separation
  when Separation::TENUTO
    DurationFunctions::TENUTO_DURATION
  when Separation::PORTATO
    DurationFunctions::PORTATO_DURATION
  when Separation::STACCATO
    DurationFunctions::STACCATO_DURATION
  when Separation::STACCATISSIMO
    DurationFunctions::STACCATISSIMO_DURATION
  else
    DurationFunctions::NORMAL_DURATION
  end

  function.at(duration)
end
new(offset, separation, elements = []) click to toggle source
# File lib/musicality/performance/model/note_sequence.rb, line 24
def initialize offset, separation, elements = []
  @offset = offset
  @separation = separation
  @elements = elements
end

Public Instance Methods

duration() click to toggle source
# File lib/musicality/performance/model/note_sequence.rb, line 66
def duration
  stop - offset
end
first_pitch() click to toggle source
# File lib/musicality/performance/model/note_sequence.rb, line 74
def first_pitch
  elements.first.pitch
end
full_duration() click to toggle source
# File lib/musicality/performance/model/note_sequence.rb, line 70
def full_duration
  @elements.map {|el| el.duration }.inject(0,:+)
end
last_attack() click to toggle source
# File lib/musicality/performance/model/note_sequence.rb, line 82
def last_attack
  elements.last.attack
end
last_pitch() click to toggle source
# File lib/musicality/performance/model/note_sequence.rb, line 78
def last_pitch
  elements.last.pitch
end
offsets() click to toggle source
# File lib/musicality/performance/model/note_sequence.rb, line 51
def offsets
  raise "contains no elements" if elements.empty?

  off = @offset
  elements.map do |e|
    x = off
    off += e.duration
    x
  end
end
simplify!() click to toggle source

any consecutive elements with the same pitch and no attack will be combined

# File lib/musicality/performance/model/note_sequence.rb, line 31
def simplify!
  return if @elements.none?

  prev_element = @elements[0]
  idx = 1

  while idx < @elements.size
    element = @elements[idx]
    if (element.pitch == prev_element.pitch) && (element.attack == Attack::NONE)
      prev_element.duration += element.duration
      @elements.delete_at(idx)
    else
      prev_element = element
      idx += 1
    end
  end
end
stop() click to toggle source
# File lib/musicality/performance/model/note_sequence.rb, line 62
def stop
  offsets.last + NoteSequence.adjust_duration(elements.last.duration, separation)
end