Module: Musa::Datasets::PDV

Includes:
AbsD, Helper
Defined in:
lib/musa-dsl/datasets/pdv.rb

Constant Summary collapse

NaturalKeys =
(NaturalKeys + [:pitch, :velocity]).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AbsD

#duration, #forward_duration, is_compatible?, #note_duration, to_AbsD

Methods included from E

#valid?, #validate!

Instance Attribute Details

#base_durationObject

Returns the value of attribute base_duration.



14
15
16
# File 'lib/musa-dsl/datasets/pdv.rb', line 14

def base_duration
  @base_duration
end

Instance Method Details

#to_gdv(scale) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/musa-dsl/datasets/pdv.rb', line 16

def to_gdv(scale)
  gdv = {}.extend GDV
  gdv.base_duration = @base_duration

  if self[:pitch]
    if self[:pitch] == :silence
      gdv[:grade] = :silence
    else
      note = scale.note_of_pitch(self[:pitch], allow_chromatic: true)

      if background_note = note.background_note
        gdv[:grade] = background_note.grade
        gdv[:octave] = background_note.octave
        gdv[:sharps] = note.background_sharps
      else
        gdv[:grade] = note.grade
        gdv[:octave] = note.octave
      end
    end
  end

  gdv[:duration] = self[:duration] if self[:duration]

  if self[:velocity]
    # ppp = 16 ... fff = 127
    # TODO create a customizable MIDI velocity to score dynamics bidirectional conversor
    gdv[:velocity] = [1..1, 2..8, 9..16, 17..33, 34..49, 49..64, 65..80, 81..96, 97..112, 113..127].index { |r| r.cover? self[:velocity] } - 5
  end

  (keys - NaturalKeys).each { |k| gdv[k] = self[k] }

  gdv
end