Class: Scissor::Tape

Inherits:
Object
  • Object
show all
Defined in:
lib/scissor/echonest.rb,
lib/scissor/echonest/tape_ext.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



7
8
9
# File 'lib/scissor/echonest/tape_ext.rb', line 7

def method_missing(name, *args, &block)
  @delegate.send(name, *args, &block)
end

Class Attribute Details

.echonest_api_keyObject

Returns the value of attribute echonest_api_key.



12
13
14
# File 'lib/scissor/echonest.rb', line 12

def echonest_api_key
  @echonest_api_key
end

Class Method Details

.echonestObject



14
15
16
# File 'lib/scissor/echonest.rb', line 14

def echonest
  @echonest ||= Echonest(echonest_api_key)
end

Instance Method Details

#barsObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/scissor/echonest.rb', line 19

def bars
  analyze do |analysis|
    bars = analysis.bars
    bars.inject([]) do |tapes, bar|
      tape = self[bar.start, bar.duration]
      tape.set_delegate(bar)
      tapes << tape
      tapes
    end
  end
end

#beatsObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/scissor/echonest.rb', line 31

def beats
  analyze do |analysis|
    tapes = []
    beats = analysis.beats

    if beats.size != 0
      tape = self[0, beats.first.start]
      beat = Beat.new(0.0, beats.first.start, 1.0)
      tape.set_delegate(beat)
      tapes << tape
    end

    beats.inject do |m, beat|
      tape = self[m.start, beat.start - m.start]
      tape.set_delegate(m)
      tapes << tape
      beat
    end

    tapes
  end
end

#segmentsObject



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/scissor/echonest.rb', line 54

def segments
  analyze do |analysis|
    segments = analysis.segments
    segments.inject([]) do |tapes, segment|
      tape = self[segment.start, segment.duration]
      tape.set_delegate(segment)
      tapes << tape
      tapes
    end
  end
end

#set_delegate(delegate) ⇒ Object



3
4
5
# File 'lib/scissor/echonest/tape_ext.rb', line 3

def set_delegate(delegate)
  @delegate = delegate
end