Class: AudioPlayback::Device::Output
- Inherits:
-
Object
- Object
- AudioPlayback::Device::Output
- Defined in:
- lib/audio-playback/device/output.rb
Overview
An output device
Instance Attribute Summary collapse
-
#id ⇒ Integer
readonly
ID of the device.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Class Method Summary collapse
-
.all ⇒ Array<Output>
All output devices.
-
.by_id(id) ⇒ Output
Select an output device by ID.
-
.by_name(name) ⇒ Output
Select an output device by name.
-
.gets ⇒ Output
Streamlined console prompt that asks the user (via standard in) to select a device When their input is received, the device is selected and enabled.
-
.list ⇒ Array<String>
Prints ids and names of each device to standard out.
Instance Method Summary collapse
-
#initialize(id, options = {}) ⇒ Output
constructor
A new instance of Output.
-
#latency ⇒ Float
Device latency in seconds.
-
#num_channels ⇒ Integer
Number of channels the device supports.
Constructor Details
#initialize(id, options = {}) ⇒ Output
Returns a new instance of Output.
61 62 63 64 65 |
# File 'lib/audio-playback/device/output.rb', line 61 def initialize(id, = {}) # Init audio output resource AudioPlayback.ensure_initialized populate(id, ) end |
Instance Attribute Details
#id ⇒ Integer (readonly)
ID of the device
81 82 83 |
# File 'lib/audio-playback/device/output.rb', line 81 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/audio-playback/device/output.rb', line 7 def name @name end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
7 8 9 |
# File 'lib/audio-playback/device/output.rb', line 7 def resource @resource end |
Class Method Details
.all ⇒ Array<Output>
All output devices
11 12 13 |
# File 'lib/audio-playback/device/output.rb', line 11 def self.all Device.outputs end |
.by_id(id) ⇒ Output
Select an output device by ID
47 48 49 |
# File 'lib/audio-playback/device/output.rb', line 47 def self.by_id(id) Device.by_id(id) end |
.by_name(name) ⇒ Output
Select an output device by name
54 55 56 |
# File 'lib/audio-playback/device/output.rb', line 54 def self.by_name(name) Device.by_name(name) end |
.gets ⇒ Output
Streamlined console prompt that asks the user (via standard in) to select a device When their input is received, the device is selected and enabled
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/audio-playback/device/output.rb', line 28 def self.gets device = nil puts "" puts "Select an audio output..." while device.nil? list print "> " selection = $stdin.gets.chomp if selection != "" selection = Integer(selection) rescue nil device = all.find { |d| d.id == selection } unless selection.nil? end end device end |
.list ⇒ Array<String>
Prints ids and names of each device to standard out
17 18 19 20 21 22 23 |
# File 'lib/audio-playback/device/output.rb', line 17 def self.list all.map do |device| name = "#{device.id}. #{device.name}" $>.puts(name) name end end |
Instance Method Details
#latency ⇒ Float
Device latency in seconds
69 70 71 |
# File 'lib/audio-playback/device/output.rb', line 69 def latency @resource[:suggestedLatency] end |
#num_channels ⇒ Integer
Number of channels the device supports
75 76 77 |
# File 'lib/audio-playback/device/output.rb', line 75 def num_channels @resource[:channelCount] end |