aud 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/lib/aud/cli.rb +59 -48
  2. data/lib/aud/tick.rb +4 -10
  3. data/lib/aud/version.rb +1 -1
  4. metadata +51 -2
data/lib/aud/cli.rb CHANGED
@@ -8,67 +8,78 @@ module Aud
8
8
  desc 'listen', 'Listens to STDIN or a file'
9
9
 
10
10
  method_option :octave,
11
- default: 3,
12
- aliases: '-o',
13
- banner: 'Set an octave [1-5]'
11
+ :default => 3,
12
+ :aliases => '-o',
13
+ :type => :numeric,
14
+ :banner => 'Set an octave [1-5]'
15
+
16
+ method_option :note,
17
+ :default => 'C',
18
+ :aliases => '-n',
19
+ :banner => 'The note to play [A-G]'
14
20
 
15
21
  method_option :file,
16
- aliases: '-f',
17
- banner: 'A file to listen to'
22
+ :aliases => '-f',
23
+ :banner => 'A file to listen to'
18
24
 
19
25
  method_option :channel,
20
- default: 1,
21
- aliases: '-c',
22
- type: :numeric,
23
- banner: 'Set a MIDI channel [1-16]'
26
+ :default => 1,
27
+ :aliases => '-c',
28
+ :type => :numeric,
29
+ :banner => 'Set a MIDI channel [1-16]'
24
30
 
25
31
  method_option :delay,
26
- default: 50,
27
- aliases: '-d',
28
- type: :numeric,
29
- banner: 'Minimum delay in milliseconds between sounds'
32
+ :default => 50,
33
+ :aliases => '-d',
34
+ :type => :numeric,
35
+ :banner => 'Minimum delay in milliseconds between sounds'
30
36
 
31
37
  method_option :strategy,
32
- default: 'tick',
33
- aliases: '-s',
34
- banner: 'A strategy for making sounds, currently only tick'
38
+ :default => 'tick',
39
+ :aliases => '-s',
40
+ :banner => 'A strategy for making sounds, currently only tick'
35
41
 
36
- method_option :notext,
37
- type: :boolean,
38
- default: false,
39
- aliases: '-n',
40
- banner: 'Suppress text output'
42
+ method_option :silent,
43
+ :type => :boolean,
44
+ :banner => 'Silence printing of input'
41
45
 
42
46
  def listen
43
- output = UniMIDI::Output.first
47
+ case options[:strategy]
44
48
 
45
- if options[:strategy] == 'tick'
46
- aud = Aud::Tick.new(output, options)
47
- else
48
- raise 'Only tick strategy is supported, but feel free to contribute another!'
49
- end
49
+ when 'test'
50
+ return [nil, options]
51
+
52
+ when 'tick'
53
+
54
+ _exit = false
55
+ Signal.trap(:INT) do _exit = true end
56
+ Signal.trap(:TERM) do _exit = true end
57
+
58
+ output = UniMIDI::Output.first
59
+ aud = Aud::Tick.new(output, options)
60
+
61
+ process_line = lambda { |line|
62
+ line = line.strip
63
+ aud.process(line)
64
+ puts line unless options[:silent]
65
+ sleep(options[:delay] / 1000.0)
66
+ }
67
+
68
+ if options[:file]
69
+ File.open(options[:file]).each do |line|
70
+ process_line.call(line) unless _exit
71
+ end
72
+ else
73
+ # fixup ARGF
74
+ ARGV.clear
75
+ ARGF.each_line do |line|
76
+ process_line.call(line) unless _exit
77
+ end
78
+ end
79
+
80
+ else
81
+ raise 'Only tick strategy is supported, but feel free to contribute another!'
50
82
 
51
- _exit = false
52
- Signal.trap(:INT) do _exit = true end
53
- Signal.trap(:TERM) do _exit = true end
54
-
55
- process_line = lambda { |line|
56
- line = line.strip
57
- aud.process(line)
58
- puts line unless options[:notext]
59
- sleep(options[:delay] / 1000.0)
60
- }
61
-
62
- if options[:file]
63
- File.open(options[:file]).each do |line|
64
- process_line.call(line) unless _exit
65
- end
66
- else
67
- # fixup ARGF
68
- ARGV.clear
69
- ARGF.each_line do |line|
70
- process_line.call(line) unless _exit
71
- end
72
83
  end
73
84
  end
74
85
  end
data/lib/aud/tick.rb CHANGED
@@ -7,21 +7,15 @@ module Aud
7
7
  attr_accessor :output
8
8
  attr_accessor :properties
9
9
 
10
- def initialize(output, properties)
11
- self.midi = MIDI::IO.new(output)
10
+ def initialize(output, properties, _midi=nil)
11
+ self.midi = _midi || MIDI::IO.new(output)
12
12
  self.properties = properties
13
13
  end
14
14
 
15
15
  def process(line)
16
- self.midi.octave properties[:octave] || 3
17
- self.midi.note(to_note(line), :channel => properties[:channel])
16
+ self.midi.octave(properties[:octave])
17
+ self.midi.note(properties[:note], :channel => properties[:channel])
18
18
  self.midi.off
19
19
  end
20
-
21
- private
22
-
23
- def to_note(line)
24
- "C"
25
- end
26
20
  end
27
21
  end
data/lib/aud/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Aud
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-04 00:00:00.000000000 Z
12
+ date: 2013-12-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -43,6 +43,54 @@ dependencies:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
45
  version: 0.0.9
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: guard
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: guard-rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
46
94
  - !ruby/object:Gem::Dependency
47
95
  name: debugger
48
96
  requirement: !ruby/object:Gem::Requirement
@@ -98,3 +146,4 @@ signing_key:
98
146
  specification_version: 3
99
147
  summary: Audibilize text files
100
148
  test_files: []
149
+ has_rdoc: