class MTK::Events::Note

A musical {Event} defined by a {Core::Pitch}, {Core::Intensity}, and {Core::Duration}

Constants

DEFAULT_DURATION
DEFAULT_INTENSITY

Public Class Methods

from_h(hash) click to toggle source
# File lib/mtk/events/note.rb, line 27
def self.from_h(hash)
  new(hash[:pitch]||hash[:number], hash[:duration], hash[:intensity]||hash[:value], hash[:channel])
end
from_midi(pitch, velocity, duration_in_beats, channel=0) click to toggle source
# File lib/mtk/events/note.rb, line 35
def self.from_midi(pitch, velocity, duration_in_beats, channel=0)
  new( MTK::Lang::Pitches::PITCHES[pitch.to_i], MTK::Core::Duration[duration_in_beats], MTK::Core::Intensity[velocity/127.0], channel )
end
new(pitch, duration=DEFAULT_DURATION, intensity=DEFAULT_INTENSITY, channel=nil) click to toggle source
Calls superclass method MTK::Events::Event::new
# File lib/mtk/events/note.rb, line 23
def initialize(pitch, duration=DEFAULT_DURATION, intensity=DEFAULT_INTENSITY, channel=nil)
  super :note, number:pitch, duration:duration, value:intensity, channel:channel
end

Public Instance Methods

==(other) click to toggle source
Calls superclass method MTK::Events::Event#==
# File lib/mtk/events/note.rb, line 53
def ==(other)
  ( other.respond_to? :pitch and pitch == other.pitch and
    other.respond_to? :intensity and intensity == other.intensity and
    other.respond_to? :duration and duration == other.duration
  ) or super
end
inspect() click to toggle source
# File lib/mtk/events/note.rb, line 64
def inspect
  "#<#{self.class}:#{object_id} @pitch=#{@number.inspect}, @duration=#{@duration.inspect}, @intensity=#{@value.inspect}>"
end
invert(around_pitch) click to toggle source
# File lib/mtk/events/note.rb, line 48
def invert(around_pitch)
  self.pitch = self.pitch.invert(around_pitch)
  self
end
midi_pitch() click to toggle source
# File lib/mtk/events/note.rb, line 39
def midi_pitch
  pitch.to_i
end
to_h() click to toggle source
Calls superclass method MTK::Events::Event#to_h
# File lib/mtk/events/note.rb, line 31
def to_h
  super.merge({ pitch: @number, intensity: @value })
end
to_s() click to toggle source
# File lib/mtk/events/note.rb, line 60
def to_s
  "Note(#{@number}, #{@duration}, #{@value.to_percent}%)"
end
transpose(interval) click to toggle source
# File lib/mtk/events/note.rb, line 43
def transpose(interval)
  self.pitch += interval
  self
end