Class: LiveAPI::LiveObject
- Inherits:
-
Object
- Object
- LiveAPI::LiveObject
- Defined in:
- lib/live_api.rb
Overview
LiveObject is a base class for any type of object in Ableton Live
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#functions ⇒ Object
readonly
Returns the value of attribute functions.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#live_connection ⇒ Object
readonly
Returns the value of attribute live_connection.
-
#live_path ⇒ Object
readonly
Returns the value of attribute live_path.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(live_path, live_connection) ⇒ LiveObject
constructor
Initialize.
-
#inspect ⇒ Object
A nicer inspect method.
- #meta_eval(&blk) ⇒ Object
-
#metaclass ⇒ Object
Thanks _why.
-
#setup_object(info_list) ⇒ Object
Parse Live’s getinfo data to set up this object.
Constructor Details
#initialize(live_path, live_connection) ⇒ LiveObject
Initialize
158 159 160 161 162 |
# File 'lib/live_api.rb', line 158 def initialize(live_path, live_connection) @live_path = live_path @live_connection = live_connection setup_object(live_connection.request(live_path, 'getinfo')) end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
144 145 146 |
# File 'lib/live_api.rb', line 144 def children @children end |
#functions ⇒ Object (readonly)
Returns the value of attribute functions.
144 145 146 |
# File 'lib/live_api.rb', line 144 def functions @functions end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
144 145 146 |
# File 'lib/live_api.rb', line 144 def id @id end |
#live_connection ⇒ Object (readonly)
Returns the value of attribute live_connection.
144 145 146 |
# File 'lib/live_api.rb', line 144 def live_connection @live_connection end |
#live_path ⇒ Object (readonly)
Returns the value of attribute live_path.
144 145 146 |
# File 'lib/live_api.rb', line 144 def live_path @live_path end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
144 145 146 |
# File 'lib/live_api.rb', line 144 def properties @properties end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
144 145 146 |
# File 'lib/live_api.rb', line 144 def type @type end |
Instance Method Details
#inspect ⇒ Object
A nicer inspect method
152 153 154 |
# File 'lib/live_api.rb', line 152 def inspect "<#{@type} id: #{@id} #{name.first if self.respond_to?(:name)}>" end |
#meta_eval(&blk) ⇒ Object
148 |
# File 'lib/live_api.rb', line 148 def &blk; .instance_eval &blk; end |
#metaclass ⇒ Object
Thanks _why
147 |
# File 'lib/live_api.rb', line 147 def ; class << self; self; end; end |
#setup_object(info_list) ⇒ Object
Parse Live’s getinfo data to set up this object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/live_api.rb', line 166 def setup_object(info_list) @properties = [] @functions = [] @children = [] info_list.each do |info| info.shift case info.first when 'id' @id = info.last when 'type' @type = info.last when 'description' info.shift @description = info.join(' ').gsub('\\', ',') when 'children' info.shift @children << info[0] .class_eval do define_method(info[0].to_sym) do children = [] child_count = getcount(info[0].to_sym) 0.upto(child_count - 1) do |i| child = LiveObject.new("#{@live_path}/#{info.first}/#{i}", @live_connection) children << child end return children end end when 'child' info.shift @children << info[0] .class_eval do define_method(info[0].to_sym) do return LiveObject.new("#{@live_path}/#{info.first}", @live_connection) end end when 'property' @properties << info[1] ### Setup property get .class_eval do define_method(info[1].to_sym) do response = @live_connection.request(@live_path, 'get', info[1]).first # This may be wrong if a request ever returns more than a 2 element array [key,val] return response.last end end ### Setup property set .class_eval do define_method((info[1] + '=').to_sym) do |arg| @live_connection.request(@live_path, 'set', info[1], arg) end end when 'function' @functions << info[1] .class_eval do define_method(info[1].to_sym) do @live_connection.request(@live_path, 'call', info[1]) end end end end ### Add method for counting children .class_eval do define_method(:getcount) do |child| child = child.to_s return 0 unless @children.include?(child) and child.match(/s$/) count = @live_connection.request(@live_path, 'getcount', child) count.last.last end end end |