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 }
# => { grade: 0, duration: 1r, note_duration: 1/4r }

Very short note (minimum enforced)

gdv = { grade: 0, duration: 1/16r, st: true }
# note_duration clamped to base_duration * 1/8 (minimum)

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)



591
592
593
# File 'lib/musa-dsl/transcription/from-gdv-to-midi.rb', line 591

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



604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
# File 'lib/musa-dsl/transcription/from-gdv-to-midi.rb', line 604

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