Class: Music::Performance::GlissandoConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/music-performance/conversion/glissando_converter.rb

Class Method Summary collapse

Class Method Details

.glissando_elements(start_pitch, target_pitch, duration, accented) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/music-performance/conversion/glissando_converter.rb', line 26

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

.glissando_pitches(start_pitch, target_pitch) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/music-performance/conversion/glissando_converter.rb', line 5

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