Sha256: 04001947b7b4b92e11e2cb35c603316cbe6ed5c56137c9cc3562a33412f4f6a7

Contents?: true

Size: 727 Bytes

Versions: 1

Compression:

Stored size: 727 Bytes

Contents

module Clef

  class Sequence < Array

    include Clef::Utils

    def initialize(elements)
      elements = [ elements ] unless elements.is_a?(Array)
      super(elements)
    end

    def +(rhs)
      Sequence.new(map {|note| note + rhs})
    end

    def &(rhs)
      sequences = [ self, rhs ] 
      sequences = rotate_matrix(sequences, :right)
      Sequence.new(sequences.map {|row| Harmony.new(row)})
    end

    def -(rhs)
      Sequence.new(map {|note| note - rhs})
    end

    def /(rhs)
      result = []
      each do |note|
        result << note
        (rhs-1).times { result << Rest.new }
      end
      Sequence.new(result)
    end

    def to_s
      "[#{map {|n| n.to_s}.join(' ')}]"
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
teejayvanslyke-clef-0.0.0 lib/clef/sequence.rb