Class: Musicality::GlissandoConverter

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

Class Method Summary collapse

Class Method Details

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



25
26
27
28
29
30
31
# File 'lib/musicality/performance/conversion/glissando_converter.rb', line 25

def self.glissando_elements(start_pitch, target_pitch, duration, attack)
  pitches = glissando_pitches(start_pitch, target_pitch)
  subdur = Rational(duration, pitches.size)
  pitches.map do |pitch|
    NoteSequence::Element.new(subdur, pitch, attack)
  end
end

.glissando_pitches(start_pitch, target_pitch) ⇒ Object



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

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|
    Pitch.from_semitones(semitone)
  end
end