Class: Volay::Mixer::Pulse
Overview
Pulse class for playing with pacmd command
Constant Summary collapse
- DEFAULT_VALUE =
2
- MAX_VALUE =
65_536
Instance Attribute Summary collapse
-
#cards ⇒ Object
Returns the value of attribute cards.
-
#default_sink_id ⇒ Object
readonly
Returns the value of attribute default_sink_id.
Instance Method Summary collapse
-
#change_card(newdefault) ⇒ Object
Change card.
- #current ⇒ Object
- #down(value = DEFAULT_VALUE) ⇒ Object
-
#initialize ⇒ Pulse
constructor
A new instance of Pulse.
-
#refresh ⇒ Object
Refresh cards data.
- #toggle ⇒ Object
- #up(value = DEFAULT_VALUE) ⇒ Object
- #value=(value) ⇒ Object
Methods inherited from Default
#max_value, #muted?, #percent, #value
Constructor Details
#initialize ⇒ Pulse
Returns a new instance of Pulse.
15 16 17 18 |
# File 'lib/volay/mixer/pulse.rb', line 15 def initialize @cards = {} refresh end |
Instance Attribute Details
#cards ⇒ Object
Returns the value of attribute cards.
13 14 15 |
# File 'lib/volay/mixer/pulse.rb', line 13 def cards @cards end |
#default_sink_id ⇒ Object (readonly)
Returns the value of attribute default_sink_id.
12 13 14 |
# File 'lib/volay/mixer/pulse.rb', line 12 def default_sink_id @default_sink_id end |
Instance Method Details
#change_card(newdefault) ⇒ Object
Change card
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/volay/mixer/pulse.rb', line 62 def change_card(newdefault) return unless @cards.key?(newdefault) # Change default sink command("set-default-sink #{@cards[newdefault]['sink']}") # Now to move all current playing stuff to the new sink.... dump = command('list-sink-inputs').lines dump.each do |line| args = line.split # We need to find the item index for each playing stream if args[0] == 'index:' # And now to shift them all to the new sink. command("move-sink-input #{args[1]} #{@cards[newdefault]['sink']}") end end refresh end |
#current ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/volay/mixer/pulse.rb', line 48 def current { value: current_sink.nil? ? 0 : current_sink['volume'], max_value: MAX_VALUE, percent: current_sink.nil? ? 0 : volume_percent(current_sink['volume']), muted: current_sink.nil? ? true : current_sink['muted'] == 'yes' } end |
#down(value = DEFAULT_VALUE) ⇒ Object
26 27 28 29 30 |
# File 'lib/volay/mixer/pulse.rb', line 26 def down(value = DEFAULT_VALUE) set_volume( volume_percent(@cards[@default_sink_id]['volume']) - value ) end |
#refresh ⇒ Object
Refresh cards data
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/volay/mixer/pulse.rb', line 85 def refresh cmd = command('dump') return unless cmd dump = cmd.lines dump.each do |line| args = line.split # We are using the id to actually enumerate all cards. if args[1] == 'module-alsa-card' number = args[2].sub('device_id="', '').sub('"', '').to_i @cards[number] = {} @cards[number]['name'] = args[3].sub('name="', '').sub('"', '') # we already have something in the array elsif @cards.keys.length.positive? set_data(args) end end set_long_names end |
#toggle ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/volay/mixer/pulse.rb', line 36 def toggle return if current_sink.nil? value = if current_sink['muted'] == 'yes' 'no' else 'yes' end current_sink['muted'] = value command("set-sink-mute #{@cards[@default_sink_id]['sink']} #{value}") end |
#up(value = DEFAULT_VALUE) ⇒ Object
20 21 22 23 24 |
# File 'lib/volay/mixer/pulse.rb', line 20 def up(value = DEFAULT_VALUE) set_volume( volume_percent(@cards[@default_sink_id]['volume']) + value ) end |
#value=(value) ⇒ Object
32 33 34 |
# File 'lib/volay/mixer/pulse.rb', line 32 def value=(value) set_volume(value.to_i) end |