Browse Source

Set up defaults based on the hostname, correctly find the screen

offset if there are more than 2 screens
master
Peter J. Jones 6 years ago
parent
commit
2fe388e6c7
1 changed files with 31 additions and 9 deletions
  1. 31
    9
      bin/record-screen.rb

+ 31
- 9
bin/record-screen.rb View File

@@ -15,20 +15,42 @@ class Driver
15 15
     :x_display     => "0.0",
16 16
     :fps           => '25',
17 17
     :video_bitrate => '256k',
18
-    :audio         => false,
18
+    :audio         => true,
19
+    :audio_hw      => 'hw:0,0',
19 20
     :audio_bitrate => '64k',
20 21
   }
21 22
 
23
+  ##############################################################################
24
+  DEFAULTS = {
25
+    # My desktop.
26
+    'hawkins' => {
27
+      :audio_hw => 'hw:2,0',
28
+      :screen   => 3,
29
+    },
30
+
31
+    # My laptop.
32
+    'seward' => {
33
+      :audio_hw => 'hw:0,0',
34
+      :screen   => 2,
35
+    },
36
+  }
37
+
22 38
   ##############################################################################
23 39
   attr_reader(:options)
24 40
 
25 41
   ##############################################################################
26 42
   def initialize
27 43
     @options = OpenStruct.new(OPTIONS)
44
+    @hostname = `hostname`.chomp
45
+
46
+    if DEFAULTS.has_key?(@hostname)
47
+      DEFAULTS[@hostname].each {|k, v| options.send("#{k}=", v)}
48
+    end
28 49
 
29 50
     OptionParser.new do |op|
30
-      op.on('--screen=N', "Record screen number N") {|n| options.screen = n.to_i}
31
-      op.on('--audio', "Enable mic") {|a| options.audio = a}
51
+      op.on('--screen=N', 'Record screen number N') {|n| options.screen = n.to_i}
52
+      op.on('--[no-]audio', 'Enable/disable mic') {|a| options.audio = a}
53
+      op.on('--audio-hw=DEVICE', 'Set audio device') {|h| options.audio_hw = h}
32 54
     end.parse(ARGV)
33 55
   end
34 56
 
@@ -49,7 +71,7 @@ class Driver
49 71
     ]
50 72
 
51 73
     if options.audio
52
-      cmd.concat(%w(-f alsa -i hw:2,0 -ac 1 -strict experimental))
74
+      cmd.concat(%W(-f alsa -i #{options.audio_hw} -ac 1 -strict experimental))
53 75
     end
54 76
 
55 77
     cmd << File.expand_path(options.file)
@@ -62,14 +84,14 @@ class Driver
62 84
 
63 85
   ##############################################################################
64 86
   def screen_x_offset (screen_num)
65
-    x = 0
87
+    offset = 0
66 88
 
67
-    if screen_num > 1
68
-      (x, y) = screen_size(screen_num - 1).split('x')
69
-      x = x.to_i
89
+    (screen_num - 1).times do |n|
90
+      (x, y) = screen_size(n + 1).split('x')
91
+      offset += x.to_i
70 92
     end
71 93
 
72
-    x
94
+    offset
73 95
   end
74 96
 
75 97
   ##############################################################################

Loading…
Cancel
Save