From d8ee19e2f86b1b92bb440ea24497d79d060cc3cb Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Fri, 21 Jul 2023 09:34:26 +0100 Subject: [PATCH] update rakefile rework examples --- README.md | 28 +++++++++++++++++++--------- examples/events/main.rb | 7 ++++--- examples/midi/main.rb | 4 ++-- examples/obs/Gemfile | 4 ---- examples/obs/main.rb | 4 ++-- main.rb | 23 +++++++++++++++++++++++ rakefile | 16 ++++++++++++++++ 7 files changed, 66 insertions(+), 20 deletions(-) create mode 100644 main.rb diff --git a/README.md b/README.md index 345d2ef..abdeda6 100644 --- a/README.md +++ b/README.md @@ -38,17 +38,27 @@ Login and logout are handled for you in this scenario. ```ruby require "voicemeeter" -Voicemeeter::Remote - .new(:banana) - .run do |vm| - # mute the leftmost strip - vm.strip[0].mute = true - puts vm.strip[0].mute +class Main + def run + Voicemeeter::Remote + .new(:banana) + .run do |vm| + vm.strip[0].label = "podmic" + vm.strip[0].mute = true + puts "strip 0 #{vm.strip[0].label} mute was set to #{vm.strip[0].mute}" - # disable eq for second from left bus - vm.bus[1].eq.on = false - puts vm.bus[1].eq.on + vm.bus[3].gain = -6.3 + vm.bus[4].eq.on = true + info = [ + "bus 3 gain has been set to #{vm.bus[3].gain}", + "bus 4 eq has been set to #{vm.bus[4].eq.on}" + ] + puts info + end end +end + +Main.new.run if $PROGRAM_NAME == __FILE__ ``` Otherwise you must remember to call `vm.login` `vm.logout` at the start/end of your code. diff --git a/examples/events/main.rb b/examples/events/main.rb index 69d04f7..bf34286 100644 --- a/examples/events/main.rb +++ b/examples/events/main.rb @@ -7,7 +7,8 @@ class Main end def run - exit if gets.chomp.empty? + puts "press to quit" + loop { break if gets.chomp.empty? } end def on_pdirty @@ -20,7 +21,7 @@ class Main def on_midi current = @vm.midi.current - puts "Value of midi button #{current}: #{@vm.midi.get(current)}" + puts "Value of midi input #{current}: #{@vm.midi.get(current)}" end def on_ldirty @@ -30,7 +31,7 @@ class Main end end -if $0 == __FILE__ +if $PROGRAM_NAME == __FILE__ Voicemeeter::Remote.new(:potato, pdirty: true, mdirty: true, midi: true, ldirty: true).run do |vm| Main.new(vm).run end diff --git a/examples/midi/main.rb b/examples/midi/main.rb index 83420e0..e17b453 100644 --- a/examples/midi/main.rb +++ b/examples/midi/main.rb @@ -10,7 +10,7 @@ class Main def run puts "press to quit" - loop { exit if gets.chomp.empty? } + loop { break if gets.chomp.empty? } end def on_update(event) @@ -28,7 +28,7 @@ class Main end -if $0 == __FILE__ +if $PROGRAM_NAME == __FILE__ Voicemeeter::Remote.new(:potato, midi: true).run do |vm| Main.new(vm).run end diff --git a/examples/obs/Gemfile b/examples/obs/Gemfile index 37e5a6d..8779099 100644 --- a/examples/obs/Gemfile +++ b/examples/obs/Gemfile @@ -2,8 +2,4 @@ source "https://rubygems.org" -gem "voicemeeter", path: "../.." - gem "obsws", "~> 0.1.3" - -gem "pathname", "~> 0.2.1" diff --git a/examples/obs/main.rb b/examples/obs/main.rb index 437d074..6b7cc74 100644 --- a/examples/obs/main.rb +++ b/examples/obs/main.rb @@ -1,4 +1,4 @@ -require "voicemeeter" +require_relative "../../lib/voicemeeter" require "obsws" require "yaml" require "pathname" @@ -59,7 +59,7 @@ def conn_from_yml end -if $0 == __FILE__ +if $PROGRAM_NAME == __FILE__ Voicemeeter::Remote.new(:potato).run do |vm| Main.new(vm, **conn_from_yml).run end diff --git a/main.rb b/main.rb new file mode 100644 index 0000000..b35f7b2 --- /dev/null +++ b/main.rb @@ -0,0 +1,23 @@ +require "voicemeeter" + +class Main + def run + Voicemeeter::Remote + .new(:banana) + .run do |vm| + vm.strip[0].label = "podmic" + vm.strip[0].mute = true + puts "strip 0 #{vm.strip[0].label} mute was set to #{vm.strip[0].mute}" + + vm.bus[3].gain = -6.3 + vm.bus[4].eq.on = true + info = [ + "bus 3 gain has been set to #{vm.bus[3].gain}", + "bus 4 eq has been set to #{vm.bus[4].eq.on}" + ] + puts info + end + end +end + +Main.new.run if $PROGRAM_NAME == __FILE__ diff --git a/rakefile b/rakefile index 7991eda..9396115 100644 --- a/rakefile +++ b/rakefile @@ -1,6 +1,22 @@ require "rake/testtask" +HERE = __dir__ + Rake::TestTask.new do |t| t.pattern = "test/**/*_test.rb" end + task default: :test +task :events do + filepath = File.join(HERE, "examples", "events", "main.rb") + ruby filepath +end +task :midi do + filepath = File.join(HERE, "examples", "midi", "main.rb") + ruby filepath +end +task :obs do + targetdir = File.join(HERE, "examples", "obs") + Dir.chdir(targetdir) + bundle exec ruby File.join(targetdir, "main.rb") +end