Class: Track

Inherits:
Object show all
Defined in:
lib/kuromusic/Track.rb

Instance Method Summary collapse

Constructor Details

#initialize(key, measures = []) ⇒ Track

Returns a new instance of Track.



6
7
8
9
# File 'lib/kuromusic/Track.rb', line 6

def initialize(key, measures = [])
  @key = key
  @measures = measures
end

Instance Method Details

#+(other) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/kuromusic/Track.rb', line 79

def +(other)
  tmp = []
  if other.class.to_s == "Track"
    tmp.push(@measures)
    other.each{|e|
      tmp.push(e)
    }
    tmp.flatten!
  else
    self.error_puts("ArgumentTypeError", "undefined method `+'")
  end
  Track.new(@key, tmp)
end

#[](index) ⇒ Object



11
12
13
# File 'lib/kuromusic/Track.rb', line 11

def [](index)
  @measures[index]
end

#[]=(index, obj) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/kuromusic/Track.rb', line 15

def []=(index, obj)
  if obj.class.to_s == "Measure"
    @measures[index] = obj
  else
    self.error_puts("ArgumentTypeError", "undefined method `+'")
  end
end

#eachObject



50
51
52
53
54
# File 'lib/kuromusic/Track.rb', line 50

def each()
  @measures.each {|e|
    yield(e)
  }
end

#each_with_indexObject



56
57
58
59
60
# File 'lib/kuromusic/Track.rb', line 56

def each_with_index()
  @measures.each {|e|
    yield(e)
  }
end

#insert(index, *objs) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/kuromusic/Track.rb', line 23

def insert(index, *objs)
  objs.each {|e|
    if e.class.to_s != "Measure"
      self.error_puts("ArgumentTypeError", "undefined method `+'")
    end
  }
  @measures.insert(index, *objs)
end

#inspectObject



93
94
95
96
97
98
99
100
101
# File 'lib/kuromusic/Track.rb', line 93

def inspect()
  "[
Track Meta: < key = #{@key} >
----------------------------------------------------------
" + @measures.each_with_index.map{|m, i|
  "Measure #{i+1}:\n" + m.inspect(@key)
}.join("\n  ----------------------------------------------------------\n  ") + "
]"
end

#lengthObject



75
76
77
# File 'lib/kuromusic/Track.rb', line 75

def length()
  @measure.length
end

#mapObject



62
63
64
65
66
67
# File 'lib/kuromusic/Track.rb', line 62

def map()
  result = @measures.map {|e|
    yield(e)
  }
  Track.new(result)
end

#map!Object



69
70
71
72
73
# File 'lib/kuromusic/Track.rb', line 69

def map!()
  @measures.map! {|e|
    yield(e)
  }
end

#push(obj) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/kuromusic/Track.rb', line 32

def push(obj)
  if obj.class.to_s == "Measure"
    @measures.push(obj)
  else
    self.error_puts("ArgumentTypeError", "undefined method `+'")
  end
  self
end

#unshift(obj) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/kuromusic/Track.rb', line 41

def unshift(obj)
  if obj.class.to_s == "Measure"
    @measures.unshift(obj)
  else
    self.error_puts("ArgumentTypeError", "undefined method `+'")
  end
  self
end