Class: Musa::Transcriptors::FromGDV::ToMIDI::Mordent

Inherits:
Musa::Transcription::FeatureTranscriptor show all
Defined in:
lib/musa-dsl/transcription/from-gdv-to-midi.rb

Overview

Mordent transcriptor for MIDI playback.

Expands mordent ornaments into a three-note sequence: main note, adjacent note (upper or lower), then main note. The mordent is a quick ornament typically used to emphasize a note.

Mordent Types

  • .mor or .mor(:up) - Upper mordent (main, upper neighbor, main)
  • .mor(:down) or .mor(:low) - Lower mordent (main, lower neighbor, main)

Processing

Given .mor on a note:

{ grade: 0, duration: 1r, mor: true }

Expands to three notes:

[
  { grade: 0, duration: 1/16r },    # Main note (short)
  { grade: 1, duration: 1/16r },    # Upper neighbor (short)
  { grade: 0, duration: 7/8r }      # Main note (remaining duration)
]

Duration Calculation

Short notes duration: base_duration * duration_factor (default 1/4) Final note gets remaining duration: original - 2 * short_duration

Process: .mor

Examples:

Upper mordent

mor = Mordent.new(duration_factor: 1/4r)
gdv = { grade: 0, duration: 1r, mor: true }
result = mor.transcript(gdv, base_duration: 1/4r, tick_duration: 1/96r)
# => [
#   { grade: 0, duration: 1/16r },
#   { grade: 1, duration: 1/16r },
#   { grade: 0, duration: 7/8r }
# ]

Lower mordent

gdv = { grade: 0, duration: 1r, mor: :down }
# Uses lower neighbor (grade: -1)

Instance Method Summary collapse

Constructor Details

#initialize(duration_factor: nil) ⇒ Mordent

Creates mordent transcriptor.

Parameters:

  • duration_factor (Rational) (defaults to: nil)

    factor for ornament note duration relative to base_duration (default: 1/4)



230
231
232
# File 'lib/musa-dsl/transcription/from-gdv-to-midi.rb', line 230

def initialize(duration_factor: nil)
  @duration_factor = duration_factor || 1/4r
end

Instance Method Details

#transcript(gdv, base_duration:, tick_duration:) ⇒ Array<Hash>, Hash

Transcribes mordent to three-note sequence.

Parameters:

  • gdv (Hash)

    GDV event possibly containing :mor

  • base_duration (Rational)

    base duration unit

  • tick_duration (Rational)

    minimum tick duration

Returns:

  • (Array<Hash>, Hash)

    array with mordent notes, or unchanged event



243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/musa-dsl/transcription/from-gdv-to-midi.rb', line 243

def transcript(gdv, base_duration:, tick_duration:)
  mor = gdv.delete :mor

  if mor
    direction = :up

    check(mor) do |mor|
      case mor
      when true, :up
        direction = :up
      when :down, :low
        direction = :down
      end
    end

    short_duration = [base_duration * @duration_factor, tick_duration].max

    gdvs = []

    gdvs << gdv.clone.tap { |gdv| gdv[:duration] = short_duration }

    case direction
    when :up
      gdvs << gdv.clone.tap { |gdv| gdv[:grade] += 1; gdv[:duration] = short_duration }
    when :down
      gdvs << gdv.clone.tap { |gdv| gdv[:grade] -= 1; gdv[:duration] = short_duration }
    end

    gdvs << gdv.clone.tap { |gdv| gdv[:duration] -= 2 * short_duration }

    super gdvs, base_duration: base_duration, tick_duration: tick_duration
  else
    super
  end
end