Method: MTK.Note
- Defined in:
- lib/mtk/events/note.rb
.Note(*anything) ⇒ Object
Construct a MTK::Events::Note from a list of any supported type for the arguments: pitch, intensity, duration, channel
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/mtk/events/note.rb', line 72 def Note(*anything) anything = anything.first if anything.size == 1 case anything when MTK::Events::Note then anything when MTK::Core::Pitch then MTK::Events::Note.new(anything) when Array pitch = nil duration = nil intensity = nil channel = nil unknowns = [] anything.each do |item| case item when MTK::Core::Pitch then pitch = item when MTK::Core::Duration then duration = item when MTK::Core::Intensity then intensity = item else unknowns << item end end pitch = MTK.Pitch(unknowns.shift) if pitch.nil? and not unknowns.empty? raise "MTK::Note() couldn't find a pitch in arguments: #{anything.inspect}" if pitch.nil? duration = MTK.Duration(unknowns.shift) if duration.nil? and not unknowns.empty? intensity = MTK.Intensity(unknowns.shift) if intensity.nil? and not unknowns.empty? channel = unknowns.shift.to_i if channel.nil? and not unknowns.empty? duration ||= MTK::Events::Note::DEFAULT_DURATION intensity ||= MTK::Events::Note::DEFAULT_INTENSITY MTK::Events::Note.new( pitch, duration, intensity, channel ) else raise "MTK::Note() doesn't understand #{anything.class}" end end |