Sha256: 4ad5524df820c290dbee75bf74a84dd5e4815b6b930d6efe6cc72edb20b7174e

Contents?: true

Size: 915 Bytes

Versions: 5

Compression:

Stored size: 915 Bytes

Contents

module Music
module Performance

class GlissandoConverter
  def self.glissando_pitches(start_pitch, target_pitch)
    start, finish = start_pitch.total_semitones, target_pitch.total_semitones
    if finish >= start
      semitones = start.ceil.upto(finish.floor).to_a
    else
      semitones = start.floor.downto(finish.ceil).to_a
    end
    
    if semitones.empty? || semitones[0] != start
      semitones.unshift(start)
    end
    
    if semitones.size > 1 && semitones[-1] == finish
      semitones.pop
    end
    
    semitones.map do |semitone|
      Music::Transcription::Pitch.from_semitones(semitone)
    end
  end

  def self.glissando_elements(start_pitch, target_pitch, duration, accented)
    pitches = glissando_pitches(start_pitch, target_pitch)
    subdur = Rational(duration, pitches.size)
    pitches.map do |pitch|
      LegatoElement.new(subdur, pitch, accented)
    end
  end
end

end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
music-performance-0.4.2 lib/music-performance/conversion/glissando_converter.rb
music-performance-0.4.1 lib/music-performance/conversion/glissando_converter.rb
music-performance-0.4.0 lib/music-performance/conversion/glissando_converter.rb
music-performance-0.3.0 lib/music-performance/conversion/glissando_converter.rb
music-performance-0.2.1 lib/music-performance/conversion/glissando_converter.rb