Module: Musa::Datasets::AbsD
Overview
Absolute events with duration.
AbsD represents absolute events that have duration - they occupy a time span rather than occurring at a single instant.
What a duration is measured in
A BAR. 1r is one bar, 1/4r is a quarter of a bar, 2r is two bars.
That is what the sequencer counts -- position 1 is bar 1, position 2 is bar
2 -- and every duration in the library is a fraction of it.
It is NOT a fraction of a whole note, and that distinction only shows itself outside 4/4, where a bar and a whole note stop being the same length:
- in 4/4,
1/4rlasts a quarter note, and1ra whole one; - in 3/4,
1/4rlasts three quarters of a beat, and a quarter note is1/3r; the bar,1r, is a dotted half; - in 6/8, a beat is
1/6rand is written as an eighth.
So "1/4r is a quarter note" is true of 4/4 and of nothing else. It is the meter's coincidence rather than a definition, and the documentation of this library stated it as a rule for a long time.
The only place that needs to know about whole notes is Score::ToMXML, which has to name figures, and it converts there.
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)
None of the three is required: an event belongs here as soon as it declares
ANY of them. :duration and :forward_duration are what make it occupy
time, and either one alone is enough -- an impulse (a click, a percussive
attack that frees itself) has no sounding length of its own and does have a
distance to the next event, and that is a well formed event of the domain.
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
Constant Summary collapse
- NaturalKeys =
Natural keys including duration variants.
(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
-
.is_compatible?(thing) ⇒ Boolean
Checks if thing can be converted to AbsD.
-
.to_AbsD(thing) ⇒ AbsD
Converts thing to AbsD if possible.
Instance Method Summary collapse
-
#duration ⇒ Numeric
Returns event duration.
-
#forward_duration ⇒ Numeric
Returns forward duration (time until next event).
-
#note_duration ⇒ Numeric
Returns actual note duration.
-
#valid? ⇒ Boolean
included
from E
Checks if event is valid.
-
#validate! ⇒ void
included
from E
Validates event, raising if invalid.
Class Method Details
.is_compatible?(thing) ⇒ Boolean
Checks if thing can be converted to AbsD.
Either duration key is enough: what makes an event occupy time is that it declares how long it lasts, or how long until the next one, and it need not declare both.
289 290 291 292 |
# File 'lib/musa-dsl/datasets/e.rb', line 289 def self.is_compatible?(thing) thing.is_a?(AbsD) || thing.is_a?(Hash) && (thing.has_key?(:duration) || thing.has_key?(:forward_duration)) end |
.to_AbsD(thing) ⇒ AbsD
Converts thing to AbsD if possible.
303 304 305 306 307 308 309 310 311 |
# File 'lib/musa-dsl/datasets/e.rb', line 303 def self.to_AbsD(thing) if thing.is_a?(AbsD) thing elsif thing.is_a?(Hash) && (thing.has_key?(:duration) || thing.has_key?(:forward_duration)) thing.clone.extend(AbsD) else raise ArgumentError, "Cannot convert #{thing} to AbsD dataset" end end |
Instance Method Details
#duration ⇒ Numeric
Returns event duration.
272 273 274 |
# File 'lib/musa-dsl/datasets/e.rb', line 272 def duration self[:duration] end |
#forward_duration ⇒ Numeric
Returns forward duration (time until next event).
Defaults to :duration if :forward_duration not specified. This is the
value play waits on in :wait mode, so it is what advances a serie.
250 251 252 |
# File 'lib/musa-dsl/datasets/e.rb', line 250 def forward_duration self[:forward_duration] || self[:duration] end |
#note_duration ⇒ Numeric
Returns actual note duration.
Defaults to :duration if :note_duration not specified.
262 263 264 |
# File 'lib/musa-dsl/datasets/e.rb', line 262 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.
#validate! ⇒ void Originally defined in module E
This method returns an undefined value.
Validates event, raising if invalid.