Class: Musicality::NoteSequence
- Inherits:
-
Object
- Object
- Musicality::NoteSequence
- Defined in:
- lib/musicality/performance/model/note_sequence.rb
Defined Under Namespace
Classes: Element
Instance Attribute Summary collapse
-
#elements ⇒ Object
Returns the value of attribute elements.
-
#offset ⇒ Object
(also: #start)
Returns the value of attribute offset.
-
#separation ⇒ Object
Returns the value of attribute separation.
Class Method Summary collapse
Instance Method Summary collapse
- #duration ⇒ Object
- #first_pitch ⇒ Object
- #full_duration ⇒ Object
-
#initialize(offset, separation, elements = []) ⇒ NoteSequence
constructor
A new instance of NoteSequence.
- #last_attack ⇒ Object
- #last_pitch ⇒ Object
- #offsets ⇒ Object
-
#simplify! ⇒ Object
any consecutive elements with the same pitch and no attack will be combined.
- #stop ⇒ Object
Constructor Details
#initialize(offset, separation, elements = []) ⇒ NoteSequence
Returns a new instance of NoteSequence.
24 25 26 27 28 |
# File 'lib/musicality/performance/model/note_sequence.rb', line 24 def initialize offset, separation, elements = [] @offset = offset @separation = separation @elements = elements end |
Instance Attribute Details
#elements ⇒ Object
Returns the value of attribute elements.
23 24 25 |
# File 'lib/musicality/performance/model/note_sequence.rb', line 23 def elements @elements end |
#offset ⇒ Object Also known as: start
Returns the value of attribute offset.
23 24 25 |
# File 'lib/musicality/performance/model/note_sequence.rb', line 23 def offset @offset end |
#separation ⇒ Object
Returns the value of attribute separation.
23 24 25 |
# File 'lib/musicality/performance/model/note_sequence.rb', line 23 def separation @separation end |
Class Method Details
.adjust_duration(duration, separation) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/musicality/performance/model/note_sequence.rb', line 6 def self.adjust_duration duration, separation function = case separation when Separation::TENUTO DurationFunctions::TENUTO_DURATION when Separation::PORTATO DurationFunctions::PORTATO_DURATION when Separation::STACCATO DurationFunctions::STACCATO_DURATION when Separation::STACCATISSIMO DurationFunctions::STACCATISSIMO_DURATION else DurationFunctions::NORMAL_DURATION end function.at(duration) end |
Instance Method Details
#duration ⇒ Object
66 67 68 |
# File 'lib/musicality/performance/model/note_sequence.rb', line 66 def duration stop - offset end |
#first_pitch ⇒ Object
74 75 76 |
# File 'lib/musicality/performance/model/note_sequence.rb', line 74 def first_pitch elements.first.pitch end |
#full_duration ⇒ Object
70 71 72 |
# File 'lib/musicality/performance/model/note_sequence.rb', line 70 def full_duration @elements.map {|el| el.duration }.inject(0,:+) end |
#last_attack ⇒ Object
82 83 84 |
# File 'lib/musicality/performance/model/note_sequence.rb', line 82 def last_attack elements.last.attack end |
#last_pitch ⇒ Object
78 79 80 |
# File 'lib/musicality/performance/model/note_sequence.rb', line 78 def last_pitch elements.last.pitch end |
#offsets ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/musicality/performance/model/note_sequence.rb', line 51 def offsets raise "contains no elements" if elements.empty? off = @offset elements.map do |e| x = off off += e.duration x end end |
#simplify! ⇒ Object
any consecutive elements with the same pitch and no attack will be combined
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/musicality/performance/model/note_sequence.rb', line 31 def simplify! return if @elements.none? prev_element = @elements[0] idx = 1 while idx < @elements.size element = @elements[idx] if (element.pitch == prev_element.pitch) && (element.attack == Attack::NONE) prev_element.duration += element.duration @elements.delete_at(idx) else prev_element = element idx += 1 end end end |
#stop ⇒ Object
62 63 64 |
# File 'lib/musicality/performance/model/note_sequence.rb', line 62 def stop offsets.last + NoteSequence.adjust_duration(elements.last.duration, separation) end |