Class: Musa::Transcriptors::FromGDV::ToMIDI::Staccato

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

Overview

Staccato transcriptor for MIDI playback.

Applies staccato articulation by shortening note duration. Instead of creating multiple notes, staccato modifies the :note_duration attribute to create a gap between note-off and the next note-on.

Staccato Levels

  • .st or .st(true) - Half duration (1/2)
  • .st(1) - Half duration (1/2)
  • .st(2) - Quarter duration (1/4)
  • .st(3) - Eighth duration (1/8)
  • .st(n) - Duration divided by 2^n

Processing

Staccato sets :note_duration attribute (actual sounding duration) while preserving :duration (rhythmic position duration). The gap between these creates the staccato articulation.

Given .st on a note:

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

Results in:

{ grade: 0, duration: 1r, note_duration: 1/2r }
  • duration: 1r - Next note starts after 1 beat
  • note_duration: 1/2r - Note sounds for 1/2 beat (staccato gap)

Minimum Duration

A minimum duration (base_duration * min_duration_factor, default 1/8) prevents extremely short notes that might sound like clicks.

Process: .st .st(1) .st(2) .st(3): staccato level 1 2 3

Examples:

Basic staccato

staccato = Staccato.new
gdv = { grade: 0, duration: 1r, st: true }
result = staccato.transcript(gdv, base_duration: 1/4r, tick_duration: 1/96r)
# => { grade: 0, duration: 1r, note_duration: 1/2r }

Staccato level 2

gdv = { grade: 0, duration: 1r, st: 2 }
staccato.transcript(gdv, base_duration: 1/4r, tick_duration: 1/96r)
# => { grade: 0, duration: 1r, note_duration: 1/4r }

Very short note (minimum enforced)

gdv = { grade: 0, duration: 1/16r, st: true }
staccato.transcript(gdv, base_duration: 1/4r, tick_duration: 1/96r)
# => { grade: 0, duration: 1/16r, note_duration: 1/32r }
# Halving 1/16r would give 1/32r anyway; the minimum, base_duration/8,
# is also 1/32r here, so this is where the clamp starts to bite.

Instance Method Summary collapse

Constructor Details

#initialize(min_duration_factor: nil) ⇒ Staccato

Creates staccato transcriptor.

Parameters:

  • min_duration_factor (Rational) (defaults to: nil)

    minimum duration factor relative to base_duration to prevent click-like short notes (default: 1/8)



664
665
666
# File 'lib/musa-dsl/transcription/from-gdv-to-midi.rb', line 664

def initialize(min_duration_factor: nil)
  @min_duration_factor = min_duration_factor || 1/8r
end

Instance Method Details

#transcript(gdv, base_duration:, tick_duration:) ⇒ Hash

Transcribes staccato by setting note_duration.

Parameters:

  • gdv (Hash)

    GDV event possibly containing :st

  • base_duration (Rational)

    base duration unit

  • tick_duration (Rational)

    minimum tick duration

Returns:

  • (Hash)

    event with :note_duration set if staccato, or unchanged



677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
# File 'lib/musa-dsl/transcription/from-gdv-to-midi.rb', line 677

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

  if st
    calculated = 0

    check(st) do |st|
      case st
      when true
        calculated = gdv[:duration] / 2r
      when Numeric
        calculated = gdv[:duration] / 2**st if st >= 1
      end
    end

    gdv[:note_duration] = [calculated, base_duration * @min_duration_factor].max
  end

  super
end