Created
October 21, 2022 15:45
-
-
Save LevitatingBusinessMan/82dbddf417c5d4f7aefdb9e4ac392953 to your computer and use it in GitHub Desktop.
OSC to alsa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/ruby | |
| puts <<-"EOF" | |
| ____ _____ _____ __ _ _____ | |
| / __ \\ / ____|/ ____| \\ \\ /\\ | | / ____| /\\ | |
| | | | | (___ | | _____\\ \\ / \\ | | | (___ / \\ | |
| | | | |\\___ \\| | |______> > / /\\ \\ | | \\___ \\ / /\\ \\ | |
| | |__| |____) | |____ / / / ____ \\| |____ ____) / ____ \\ | |
| \\____/|_____/ \\_____| /_/ /_/ \\_\\______|_____/_/ \\_\\ | |
| by rein | |
| EOF | |
| OSC_PORT = 3333 | |
| require 'osc-ruby' | |
| require 'osc-ruby/em_server' | |
| @server = OSC::EMServer.new(OSC_PORT) | |
| def print_status | |
| puts `amixer -Mc 1 sget Headphone | grep "Mono: Playback"`.strip! | |
| end | |
| CARD=1 | |
| CONTROLLER="Headphone" | |
| @server.add_method '/alsa-volume/up' do |msg| | |
| arg = msg.to_a[0] | |
| puts "#{msg.ip_address}: up #{arg}" | |
| `amixer -Mc #{CARD} sset #{CONTROLLER} #{arg}%+` | |
| print_status | |
| end | |
| @server.add_method '/alsa-volume/down' do |msg| | |
| arg = msg.to_a[0] | |
| puts "#{msg.ip_address}: down #{arg}" | |
| `amixer -Mc #{CARD} sset #{CONTROLLER} #{arg}%-` | |
| print_status | |
| end | |
| @server.add_method '/alsa-volume/set' do |msg| | |
| arg = msg.to_a[0] | |
| puts "#{msg.ip_address}: set #{arg}" | |
| `amixer -Mc #{CARD} sset #{CONTROLLER} #{arg}%` | |
| print_status | |
| end | |
| @server.add_method '/alsa-volume/toggle' do |msg| | |
| puts "#{msg.ip_address}: toggle " | |
| `amixer -Mc #{CARD} sset #{CONTROLLER} toggle` | |
| print_status | |
| end | |
| puts "Listening to OSC on port #{OSC_PORT}" | |
| print_status | |
| @server.run |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/ruby | |
| require 'osc-ruby' | |
| require "readline" | |
| HOST = ARGV[0] || "192.168.1.17" | |
| PORT = ARGV[1] || 3333 | |
| puts "Using #{HOST}:#{PORT}" | |
| @client = OSC::Client.new(HOST,PORT) | |
| while msg = Readline.readline("> ", true) | |
| addr, *arg = msg.split " " | |
| puts "Sending \e[36m#{addr}\e[0m \e[92m#{arg.join(" ")}\e[0m" | |
| @client.send( OSC::Message.new(addr, arg.join(" ") )) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment