class Music::Transcription::NoteScore

Attributes

parts[RW]
program[RW]
start_tempo[RW]
tempo_changes[RW]

Public Class Methods

new(start_tempo, tempo_changes: {}) { |self| ... } click to toggle source
# File lib/music-transcription/model/note_score.rb, line 9
def initialize start_tempo, tempo_changes: {}, parts: {}, program: Program.new
  @start_tempo = start_tempo
  @tempo_changes = tempo_changes
  @parts = parts
  @program = program
  
  yield(self) if block_given?
end
unpack(packing) click to toggle source
# File lib/music-transcription/packing/note_score_packing.rb, line 27
def self.unpack packing
  unpacked_starttempo = Tempo.parse(packing["start_tempo"])
  unpacked_tcs = Hash[ packing["tempo_changes"].map do |k,v|
    v = v.clone
    v[0] = Tempo.parse(v[0])
    [k, Change.from_ary(v) ]
  end ]
  
  unpacked_parts = Hash[ packing["parts"].map do |name,packed|
    [name, Part.unpack(packed)]
  end ]
  
  unpacked_prog = Program.unpack packing["program"]
  
  new(unpacked_starttempo,
    tempo_changes: unpacked_tcs,
    program: unpacked_prog,
    parts: unpacked_parts
  )
end
valid_tempo_types() click to toggle source
# File lib/music-transcription/model/note_score.rb, line 26
def self.valid_tempo_types
  [ Tempo::QNPM, Tempo::NPM, Tempo::NPS ]
end

Public Instance Methods

==(other) click to toggle source
# File lib/music-transcription/model/note_score.rb, line 49
def ==(other)
  return @start_tempo == other.start_tempo &&
  @tempo_changes == other.tempo_changes &&
  @parts == other.parts &&
  @program == other.program
end
check_methods() click to toggle source
# File lib/music-transcription/model/note_score.rb, line 18
def check_methods
  [ :check_start_tempo_type, :check_tempo_change_types ]
end
check_start_tempo_type() click to toggle source
# File lib/music-transcription/model/note_score.rb, line 30
def check_start_tempo_type
  vtts = self.class.valid_tempo_types
  unless vtts.include?(@start_tempo.class)
    raise TypeError, "type of start tempo #{@start_tempo} is not one of valid tempo types: #{vtts}"
  end
end
check_tempo_change_types() click to toggle source
# File lib/music-transcription/model/note_score.rb, line 37
def check_tempo_change_types
  vtts = self.class.valid_tempo_types
  baddtypes = @tempo_changes.select {|k,v| !vtts.include?(v.value.class) }
  if baddtypes.any?
    raise NonPositiveError, "type of tempo change values #{baddtypes} are not one of valid tempo types: #{vtts}"
  end
end
clone() click to toggle source
# File lib/music-transcription/model/note_score.rb, line 45
def clone
  Marshal.load(Marshal.dump(self))
end
duration() click to toggle source
# File lib/music-transcription/model/note_score.rb, line 56
def duration
  @parts.map {|p| p.duration }.max
end
pack() click to toggle source
# File lib/music-transcription/packing/note_score_packing.rb, line 5
def pack
  packed_starttempo = start_tempo.to_s
  packed_tcs = Hash[ tempo_changes.map do |offset,change|
    a = change.pack
    a[0] = a[0].to_s
    [offset,a]
  end ]

  packed_parts = Hash[
    @parts.map do |name,part|
      [ name, part.pack ]
    end
  ]
  packed_prog = program.pack
  
  { "start_tempo" => packed_starttempo,
    "tempo_changes" => packed_tcs,
    "program" => packed_prog,
    "parts" => packed_parts,
  }
end
validatables() click to toggle source
# File lib/music-transcription/model/note_score.rb, line 22
def validatables
  [ @program ] + @parts.values
end