Hack:favo-fiddle
From Music Player Daemon Community Wiki
fade and volume fiddle
this can do the following:
- kind of telnet to mpd (with working ctrl+d;)
- fade from current to given volume
- set random volumes (in a range from [min] till [max]) in given or random interval
- fade to random volumes (in a range)
#!/usr/bin/env ruby
host = ARGV[0] || 'localhost'
port = ( ARGV[1] || 6600 ).to_i
require 'socket'
socket = TCPSocket.new( host, port )
buffer = Array.new
quiet, @stop = false, false
password = 'foo'
tRecieve = Thread.start do
while input = socket.gets
puts input if not quiet
buffer.push input
end
end
def fade( socket, from, to )
if from < to
from.upto( to ) { |x|
break if @stop
socket.print "setvol #{x}\n"
sleep 0.1
}
else
from.downto( to ) { |x|
break if @stop
socket.print "setvol #{x}\n"
sleep 0.1
}
end
end
if password
socket.print "password #{password}\n"
end
begin
while output = $stdin.gets
local_command = output.chomp.split( ' ' )
case local_command.first
when 'quit', 'exit'
socket.close
exit
when 'stop'
@stop = true
sleep 3
@stop = false
when 'fade'
quiet = true
socket.print "status\n"
sleep 0.5
buffer.delete_if { |x| x !~ /volume/ }
from = buffer.last.slice( /[0-9]*$/ ).to_i
to = local_command.last.to_i
puts "- fading from #{from} to #{to}."
fade( socket, from, to )
puts "- finished."
quiet = false
when 'random-volume'
min = local_command[1].to_i
max = local_command[2].to_i
timeout = local_command[3]
if min == 0 and max == 0 and timeout == nil
puts '- usage: random-volume [min] [max] [interval]'
puts ' interval is in seconds and can be \'rand\' for random'
puts ' values between 0 and 0.5 seconds. end with typing \'stop\''
else
puts "- random volume: from #{min} till #{max}"
tRandomVolume = Thread.start do
while burp = rand( max )
break if @stop
if burp > min
socket.print "setvol #{burp}\n"
print "#{burp} "
if timeout == 'rand'
sleep rand( 0.5 )
else
sleep timeout.to_f
end
end
end
print "\n"
end
end
when 'fade-random'
min = local_command[1].to_i
max = local_command[2].to_i
if min == 0 and max == 0
puts '- usage: fade-random [min] [max]'
puts ' end with typing \'stop\''
else
from = min
socket.print "setvol #{min}"
tRandomVolume = Thread.start do
while to = rand( max )
break if @stop
if to > min
puts to
fade( socket, from, to )
from = to
end
end
end
end
when 'help'
puts '- commands:'
puts ' fade [target-value]'
puts ' random-volume [min] [max] [interval|rand]'
puts ' fade-random [min] [max]'
else
socket.print output
end
end
rescue Interrupt
socket.close
end
