lib/mass/note.rb in mass-0.0.1 vs lib/mass/note.rb in mass-0.0.2

- old
+ new

@@ -1,6 +1,7 @@ require 'forwardable' +require 'mass/pitch' module Mass # Represents a single note in the pattern. class Note extend Forwardable @@ -47,10 +48,20 @@ # value. # # @attr_reader [Mass::Pitch] attr_reader :pitch + # Rhythmic duration value for this note. + # + # @attr_reader [Integer] + attr_reader :value + + # BPM passed in from the sequence. + # + # @attr_reader [Integer] + attr_reader :bpm + # Hex value for sending to +UniMIDI+ that signals when # this note should begin playing. # # @type [Fixnum] ON = 0x90 @@ -63,22 +74,19 @@ # @param [Integer] value # @param [String] pitch # @param [Symbol | Integer] exp - Can be expressed as either # @param [UniMIDI::Output] midi - def initialize(value: 1, pitch: nil, exp: :mp, midi: nil) + def initialize(value: 1, pitch: nil, exp: :mp, midi: nil, bpm: 100) @value = value + @name = pitch @pitch = Pitch.find pitch @expression = exp @midi = midi + @bpm = bpm end - # The given note name. - # - # @return [String] - def_delegator :pitch, :name, :id - # This note as expressed in a MIDI pitch value. # # @return [Integer] def_delegator :pitch, :to_i, :to_midi @@ -90,16 +98,22 @@ end # The given duration value divided by the BPM of # the current song. def duration - value / Mass.current_bpm + vpm * 0.01 end # Play the current note through the +UniMIDI+ output. def play - midi.puts ON, to_midi, to_velocity if pitch.present? + midi.puts ON, to_midi, to_velocity unless pitch.nil? sleep duration - midi.puts OFF, to_midi, to_velocity if pitch.present? + midi.puts OFF, to_midi, to_velocity unless pitch.nil? + end + + private + + def vpm + bpm / value end end end