Class: Brevity::Itemization
- Inherits:
-
Object
- Object
- Brevity::Itemization
- Defined in:
- lib/brevity/itemization.rb
Instance Attribute Summary collapse
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#dynamic_changes ⇒ Object
readonly
Returns the value of attribute dynamic_changes.
-
#notes ⇒ Object
readonly
Returns the value of attribute notes.
-
#tempo_changes ⇒ Object
readonly
Returns the value of attribute tempo_changes.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #append(other) ⇒ Object
- #append!(other) ⇒ Object
- #calc_duration ⇒ Object
- #clone ⇒ Object
- #eql?(other) ⇒ Boolean
-
#initialize(notes: [], dynamic_changes: {}, tempo_changes: {}) ⇒ Itemization
constructor
A new instance of Itemization.
- #stretch(ratio) ⇒ Object
- #stretch!(ratio) ⇒ Object
- #transpose(diff) ⇒ Object
- #transpose!(diff) ⇒ Object
Constructor Details
#initialize(notes: [], dynamic_changes: {}, tempo_changes: {}) ⇒ Itemization
Returns a new instance of Itemization.
5 6 7 8 9 10 |
# File 'lib/brevity/itemization.rb', line 5 def initialize notes:[], dynamic_changes:{}, tempo_changes:{} @notes = notes @dynamic_changes = dynamic_changes @tempo_changes = tempo_changes @duration = @notes.map{ |n| n.duration }.each.inject(0.to_r,:+) end |
Instance Attribute Details
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
3 4 5 |
# File 'lib/brevity/itemization.rb', line 3 def duration @duration end |
#dynamic_changes ⇒ Object (readonly)
Returns the value of attribute dynamic_changes.
3 4 5 |
# File 'lib/brevity/itemization.rb', line 3 def dynamic_changes @dynamic_changes end |
#notes ⇒ Object (readonly)
Returns the value of attribute notes.
3 4 5 |
# File 'lib/brevity/itemization.rb', line 3 def notes @notes end |
#tempo_changes ⇒ Object (readonly)
Returns the value of attribute tempo_changes.
3 4 5 |
# File 'lib/brevity/itemization.rb', line 3 def tempo_changes @tempo_changes end |
Instance Method Details
#==(other) ⇒ Object
20 21 22 23 24 |
# File 'lib/brevity/itemization.rb', line 20 def ==(other) (self.notes == other.notes) && (self.dynamic_changes == other.dynamic_changes) && (self.tempo_changes == other.tempo_changes) end |
#append(other) ⇒ Object
26 27 28 |
# File 'lib/brevity/itemization.rb', line 26 def append other self.clone.append! other end |
#append!(other) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/brevity/itemization.rb', line 30 def append! other other.dynamic_changes.each do |offset,change| @dynamic_changes[offset + @duration] = change end other.tempo_changes.each do |offset,change| @tempo_changes[offset + @duration] = change end @notes += other.notes @duration += other.duration return self end |
#calc_duration ⇒ Object
43 44 45 |
# File 'lib/brevity/itemization.rb', line 43 def calc_duration @notes.each.inject(0.to_r,:+) end |
#clone ⇒ Object
16 17 18 |
# File 'lib/brevity/itemization.rb', line 16 def clone Marshal.load(Marshal.dump(self)) end |
#eql?(other) ⇒ Boolean
12 13 14 |
# File 'lib/brevity/itemization.rb', line 12 def eql?(other) self == other end |
#stretch(ratio) ⇒ Object
47 48 49 |
# File 'lib/brevity/itemization.rb', line 47 def stretch ratio self.clone.stretch! ratio end |
#stretch!(ratio) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/brevity/itemization.rb', line 51 def stretch! ratio @notes.each_index do |i| n1 = @notes[i] @notes[i] = Music::Transcription::Note.new(n1.duration * ratio, n1.pitches, links: n1.links, accent: n1.accent) end @dynamic_changes = Hash[ @dynamic_changes.map {|k,v| [k*ratio,v] }] @tempo_changes = Hash[ @tempo_changes.map {|k,v| [k*ratio,v] }] return self end |
#transpose(diff) ⇒ Object
61 62 63 |
# File 'lib/brevity/itemization.rb', line 61 def transpose diff self.clone.transpose! diff end |
#transpose!(diff) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/brevity/itemization.rb', line 65 def transpose! diff @notes[0...-1].each do |note| note.transpose_pitches_and_links! diff end @notes[-1].transpose_pitches_only! diff return self end |