Module: Musa::Datasets::AbsD

Includes:
Abs
Included in:
GDV, PDV, PS, Score
Defined in:
lib/musa-dsl/datasets/e.rb

Overview

Absolute events with duration.

AbsD represents absolute events that have duration - they occupy a time span rather than occurring at a single instant.

Natural Keys

  • :duration: Total duration of the event process
  • :note_duration: Actual note duration (may differ for staccato, etc.)
  • :forward_duration: Time until next event (may be 0 for simultaneous events)

Duration Types

duration: How long the event process lasts (note playing, dynamics change, etc.)

note_duration: Actual note length. For staccato, this is shorter than duration. Defaults to duration if not specified.

forward_duration: Time to wait before next event. Can be:

  • Same as duration (default): next event starts when this one ends
  • Less than duration: events overlap
  • Zero: next event starts simultaneously
  • More than duration: gap/rest before next event

Examples:

Basic duration

{ pitch: 60, duration: 1.0 }.extend(AbsD)
event.duration          # => 1.0
event.note_duration     # => 1.0 (defaults to duration)
event.forward_duration  # => 1.0 (defaults to duration)

Staccato note

{ pitch: 60, duration: 1.0, note_duration: 0.5 }.extend(AbsD)
# Note sounds for 0.5, but next event waits 1.0

Simultaneous events

{ pitch: 60, duration: 1.0, forward_duration: 0 }.extend(AbsD)
# Next event starts immediately (chord)

See Also:

Constant Summary collapse

NaturalKeys =

Natural keys including duration variants.

Returns:

(NaturalKeys +
[:duration, # duration of the process (note reproduction, dynamics evolution, etc)
 :note_duration, # duration of the note (a staccato note is effectively shorter than elapsed duration until next note)
 :forward_duration # duration to wait until next event (if 0 means the next event should be executed at the same time than this one)
]).freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.is_compatible?(thing) ⇒ Boolean

Checks if thing can be converted to AbsD.

Examples:

AbsD.is_compatible?({ duration: 1.0 })  # => true
AbsD.is_compatible?({ pitch: 60 })      # => false

Parameters:

  • thing (Object)

    object to check

Returns:

  • (Boolean)

    true if compatible



240
241
242
# File 'lib/musa-dsl/datasets/e.rb', line 240

def self.is_compatible?(thing)
  thing.is_a?(AbsD) || thing.is_a?(Hash) && thing.has_key?(:duration)
end

.to_AbsD(thing) ⇒ AbsD

Converts thing to AbsD if possible.

Examples:

AbsD.to_AbsD({ duration: 1.0 })  # => AbsD dataset

Parameters:

  • thing (Object)

    object to convert

Returns:

  • (AbsD)

    AbsD dataset

Raises:

  • (ArgumentError)

    if thing cannot be converted



252
253
254
255
256
257
258
259
260
# File 'lib/musa-dsl/datasets/e.rb', line 252

def self.to_AbsD(thing)
  if thing.is_a?(AbsD)
    thing
  elsif thing.is_a?(Hash) && thing.has_key?(:duration)
    thing.clone.extend(AbsD)
  else
    raise ArgumentError, "Cannot convert #{thing} to AbsD dataset"
  end
end

Instance Method Details

#durationNumeric

Returns event duration.

Examples:

event.duration  # => 1.0

Returns:

  • (Numeric)

    duration



228
229
230
# File 'lib/musa-dsl/datasets/e.rb', line 228

def duration
  self[:duration]
end

#forward_durationNumeric

Returns forward duration (time until next event).

Defaults to :duration if :forward_duration not specified.

Examples:

event.forward_duration  # => 1.0

Returns:

  • (Numeric)

    forward duration



206
207
208
# File 'lib/musa-dsl/datasets/e.rb', line 206

def forward_duration
  self[:forward_duration] || self[:duration]
end

#note_durationNumeric

Returns actual note duration.

Defaults to :duration if :note_duration not specified.

Examples:

event.note_duration  # => 0.5 (staccato)

Returns:

  • (Numeric)

    note duration



218
219
220
# File 'lib/musa-dsl/datasets/e.rb', line 218

def note_duration
  self[:note_duration] || self[:duration]
end

#valid?Boolean Originally defined in module E

Checks if event is valid.

Base implementation always returns true. Subclasses should override to implement specific validation logic.

Examples:

event.valid?  # => true

Returns:

  • (Boolean)

    true if valid

#validate!void Originally defined in module E

This method returns an undefined value.

Validates event, raising if invalid.

Examples:

event.validate!  # Raises if invalid

Raises:

  • (RuntimeError)

    if event is not valid