Module: Musa::Datasets::P
- Includes:
- Dataset
- Defined in:
- lib/musa-dsl/datasets/p.rb
Defined Under Namespace
Classes: PtoTimedSerie
Instance Method Summary collapse
- #map(&block) ⇒ Object
- #to_ps_serie(base_duration: nil) ⇒ Object
- #to_timed_serie(time_start: nil, time_start_component: nil, base_duration: nil) ⇒ Object
Instance Method Details
#map(&block) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/musa-dsl/datasets/p.rb', line 34 def map(&block) i = 0 clone.map! do |element| # Process with block only the values (values are the alternating elements because P # structure is <value> <duration> <value> <duration> <value>) # if (i += 1) % 2 == 1 block.call(element) else element end end end |
#to_ps_serie(base_duration: nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/musa-dsl/datasets/p.rb', line 11 def to_ps_serie(base_duration: nil) base_duration ||= 1/4r # TODO review incoherence between neumalang 1/4r base duration for quarter notes and general 1r size of bar # TODO if instead of using clone (needed because of p.shift) we use index counter the P elements would be evaluated on the last moment Musa::Series::Constructors.E(clone, base_duration) do |p, base_duration| (p.size >= 3) ? { from: p.shift, duration: p.shift * base_duration, to: p.first, right_open: (p.length > 1) }.extend(PS).tap { |_| _.base_duration = base_duration } : nil end end |
#to_timed_serie(time_start: nil, time_start_component: nil, base_duration: nil) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/musa-dsl/datasets/p.rb', line 25 def to_timed_serie(time_start: nil, time_start_component: nil, base_duration: nil) time_start ||= 0r time_start += self.first[time_start_component] if time_start_component base_duration ||= 1/4r # TODO review incoherence between neumalang 1/4r base duration for quarter notes and general 1r size of bar PtoTimedSerie.new(self, base_duration, time_start) end |