Class: Echonest::Analysis
- Inherits:
-
Object
- Object
- Echonest::Analysis
- Defined in:
- lib/echonest/analysis.rb
Constant Summary collapse
- CHROMATIC =
%w(C C# D D# E F F# G G# A A# B).freeze
Class Method Summary collapse
Instance Method Summary collapse
- #bars ⇒ Object
- #beats ⇒ Object
- #duration ⇒ Object
- #end_of_fade_in ⇒ Object
-
#initialize(json) ⇒ Analysis
constructor
A new instance of Analysis.
- #key ⇒ Object
-
#key_letter ⇒ Object
Returns the corresponding letter for the key number value.
- #loudness ⇒ Object
- #major? ⇒ Boolean
- #minor? ⇒ Boolean
- #mode ⇒ Object
- #sections ⇒ Object
- #segments ⇒ Object
- #start_of_fade_out ⇒ Object
- #tatums ⇒ Object
- #tempo ⇒ Object
- #time_signature ⇒ Object
- #track_info ⇒ Object
Constructor Details
#initialize(json) ⇒ Analysis
Returns a new instance of Analysis.
8 9 10 |
# File 'lib/echonest/analysis.rb', line 8 def initialize(json) @body = JSON.parse(json) end |
Class Method Details
.new_from_url(url) ⇒ Object
12 13 14 |
# File 'lib/echonest/analysis.rb', line 12 def self.new_from_url(url) new(open(url).read) end |
Instance Method Details
#bars ⇒ Object
61 62 63 64 65 |
# File 'lib/echonest/analysis.rb', line 61 def @body['bars'].map do || Bar.new(['start'], ['duration'], ['confidence']) end end |
#beats ⇒ Object
67 68 69 70 71 |
# File 'lib/echonest/analysis.rb', line 67 def beats @body['beats'].map do |beat| Beat.new(beat['start'], beat['duration'], beat['confidence']) end end |
#duration ⇒ Object
20 21 22 |
# File 'lib/echonest/analysis.rb', line 20 def duration track_info['duration'] end |
#end_of_fade_in ⇒ Object
24 25 26 |
# File 'lib/echonest/analysis.rb', line 24 def end_of_fade_in track_info['end_of_fade_in'] end |
#key ⇒ Object
28 29 30 |
# File 'lib/echonest/analysis.rb', line 28 def key track_info['key'] end |
#key_letter ⇒ Object
Returns the corresponding letter for the key number value.
33 34 35 |
# File 'lib/echonest/analysis.rb', line 33 def key_letter CHROMATIC[key] end |
#loudness ⇒ Object
37 38 39 |
# File 'lib/echonest/analysis.rb', line 37 def loudness track_info['loudness'] end |
#major? ⇒ Boolean
49 50 51 |
# File 'lib/echonest/analysis.rb', line 49 def major? !minor? end |
#minor? ⇒ Boolean
45 46 47 |
# File 'lib/echonest/analysis.rb', line 45 def minor? mode == 0 end |
#mode ⇒ Object
41 42 43 |
# File 'lib/echonest/analysis.rb', line 41 def mode track_info['mode'] end |
#sections ⇒ Object
73 74 75 76 77 |
# File 'lib/echonest/analysis.rb', line 73 def sections @body['sections'].map do |section| Section.new(section['start'], section['duration'], section['confidence']) end end |
#segments ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/echonest/analysis.rb', line 85 def segments @body['segments'].map do |segment| loudness = Loudness.new(0.0, segment['loudness_start']) max_loudness = Loudness.new(segment['loudness_max_time'], segment['loudness_max']) Segment.new( segment['start'], segment['duration'], segment['confidence'], loudness, max_loudness, segment['pitches'], segment['timbre'] ) end end |
#start_of_fade_out ⇒ Object
53 54 55 |
# File 'lib/echonest/analysis.rb', line 53 def start_of_fade_out track_info['start_of_fade_out'] end |
#tatums ⇒ Object
79 80 81 82 83 |
# File 'lib/echonest/analysis.rb', line 79 def tatums @body['tatums'].map do |tatum| Tatum.new(tatum['start'], tatum['duration'], tatum['confidence']) end end |
#tempo ⇒ Object
16 17 18 |
# File 'lib/echonest/analysis.rb', line 16 def tempo track_info['tempo'] end |
#time_signature ⇒ Object
57 58 59 |
# File 'lib/echonest/analysis.rb', line 57 def time_signature track_info['time_signature'] end |
#track_info ⇒ Object
102 103 104 |
# File 'lib/echonest/analysis.rb', line 102 def track_info @body['track'] end |