feep 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1cf734b83d85cc000c7d442ab4dcd51dac1db397
4
- data.tar.gz: f174b0d4d3d0c23a3a474a6f26ab7537ef67064d
3
+ metadata.gz: afb4a7dc316220898ac338ec8b9882084dd6c200
4
+ data.tar.gz: 9de77f715508f1c8a8b63dfe51d37c9ac499cf16
5
5
  SHA512:
6
- metadata.gz: 8549da4394340c349d329944894cbe70044bd7a091b3ac4e11e2c25aacd43531f34547de2421494b6f948285781b3ec58ceb972820b193b955af32aec01bad81
7
- data.tar.gz: 04000a3960298bb291966b41c50f9cddbdca6660777a4fe40a91f6b69ac708b5eba11e70cb43548b3ccee8fd97f7b81cd88364807b1c7694af50bb23850d81b6
6
+ metadata.gz: e9ac4d7aaa80c2ae8052cd638bfd2a612ca6cf5765dc715ea1d7c6855d2cce3b1963dd500fedf1575bcc6ad9cff2f2ebe9b013634509adf0d2eafa10d4beba31
7
+ data.tar.gz: 6b3e938e4d7dcbbdd43c4faadce2bfecf2348335cfa58c4e82387675e5f50e9bdb4f98aad1b5e3c6e7d3a39366770054cfffce9df73cf4127c20fac0e64aa9d8
data/bin/feep CHANGED
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'optparse'
4
+ require 'pry'
5
+
4
6
  require_relative '../lib/feep'
5
7
  require_relative '../lib/feep/version'
6
8
 
@@ -8,30 +10,34 @@ def parse_options
8
10
  options = {:freq_or_note => '440.000', :scale => nil, :waveform => 'sine', :volume => 0.5, :duration => 100, :save => false, :loud => false, :usage => nil}
9
11
 
10
12
  optparse = OptionParser.new do |opts|
11
- opts.banner = 'usage: feep [-f, -n, --freq-or-note FREQUENCY|NOTE_NAME] [-s, --scale SCALE_ID] [-sd, --degrees NUMBER_OF_SCALE_DEGREES] [-w, --waveform WAVEFORM_ID] [-a, --amplitude MAX_AMPLITUDE] [-d, --duration DURATION] [--save] [--loud]'
13
+ opts.banner = 'usage: feep [-f, -n, --frequency, --note FREQUENCY|NOTE_NAME] [-s, --scale SCALE_ID] [-sd, --degrees NUMBER_OF_SCALE_DEGREES] [-w, --waveform WAVEFORM_ID] [-a, --amplitude MAX_AMPLITUDE] [-d, --duration DURATION] [--save] [--loud]'
12
14
 
13
- opts.on('-f', '-n', '--freq-or-note FREQUENCY|NOTE_NAME', 'One or more frequencies or note names to play at once, e.g. 440 or A4 or 220,440,880') do |f_or_n|
14
- options[:freq_or_note] = f_or_n
15
+ opts.on('-f', '--frequency FREQUENCY', 'One or more frequencies or to play at once, e.g. 440 or 220,440,880') do |frequency|
16
+ options[:freq_or_note] = frequency
17
+ end
18
+
19
+ opts.on('-n', '--note NOTE_NAME', 'One or more note names to play at once, e.g. A4 or A4,C5,E5') do |note|
20
+ options[:freq_or_note] = note
15
21
  end
16
22
 
17
- opts.on('-s', '--scale SCALE_ID', 'Name of a scale to play') do |s|
18
- options[:scale] = s
23
+ opts.on('-s', '--scale SCALE_ID', 'Name of a scale to play') do |scale_id|
24
+ options[:scale] = scale_id
19
25
  end
20
26
 
21
- opts.on('-sd', '--degrees SCALE_DEGREES', 'Number of degrees of the scale to play') do |sd|
22
- options[:degrees] = sd
27
+ opts.on('--degrees SCALE_DEGREES', 'Number of degrees of the scale to play') do |degrees|
28
+ options[:degrees] = degrees
23
29
  end
24
30
 
25
- opts.on('-w', '--waveform WAVEFORM', 'Waveform type to use for the sound') do |w|
26
- options[:waveform] = w
31
+ opts.on('-w', '--waveform WAVEFORM', 'Waveform type to use for the sound') do |waveform|
32
+ options[:waveform] = waveform
27
33
  end
28
34
 
29
- opts.on('-a', '--amplitude MAX_AMPLITUDE', 'Amplitude/volume (0.0 - 1.0) to play the sound(s) at') do |a|
30
- options[:volume] = a.to_f
35
+ opts.on('-a', '--amplitude MAX_AMPLITUDE', 'Amplitude/volume (0.0 - 1.0) to play the sound(s) at') do |amplitude|
36
+ options[:volume] = amplitude.to_f
31
37
  end
32
38
 
33
- opts.on('-d', '--duration DURATION', 'Duration in ms to play the sound(s)') do |d|
34
- options[:duration] = d.to_i
39
+ opts.on('-d', '--duration DURATION', 'Duration in ms to play the sound(s)') do |duration|
40
+ options[:duration] = duration.to_i
35
41
  end
36
42
 
37
43
  opts.on('--save', 'Save the resulting WAV file in the current directory') do
@@ -248,8 +248,9 @@ module Feep
248
248
 
249
249
  # error messages
250
250
  ERROR_MSG = Hash[
251
- :invalid_note => 'Note name argument is invalid.',
252
- :invalid_scale => "Scale ID is invalid. Valid IDs are: #{SCALES.keys}",
251
+ :invalid_note => 'Note name argument is invalid.',
252
+ :invalid_scale => "Scale ID is invalid. Valid IDs are: #{SCALES.keys}",
253
+ :invalid_scale_root_note => 'Scale cannot start with that note/frequency.',
253
254
  :invalid_waveform => "Waveform type is invalid. Valid waveform types are: #{WAVE_TYPES}",
254
255
  :scale_needs_note => 'You need to enter a valid note (-n) if you want to play a scale.'
255
256
  ]
data/lib/feep/scale.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # lib/feep/scale.rb
2
+
2
3
  require_relative '../feep'
4
+ require_relative 'utils'
3
5
  require_relative 'constants'
4
6
 
5
7
  module Feep
@@ -11,40 +13,47 @@ module Feep
11
13
  Utils.print_error(:invalid_scale)
12
14
  end
13
15
 
14
- unless NOTES.include?(options[:freq_or_note]) && NOTES_ALT.include?(options[:freq_or_note])
15
- Utils.print_error(:invalid_note)
16
- end
17
-
18
- steps = SCALES[options[:scale].to_sym].split(',')
16
+ valid_notes = NOTES | NOTES_ALT | FREQS
17
+ freq = Utils::convert_note_to_freq(options[:freq_or_note]).to_f
19
18
 
20
- note = options[:freq_or_note]
21
- note_index = NOTES.index(note)
22
- freq = FREQS[NOTES.index(note)]
19
+ if valid_notes.include?(freq)
20
+ steps = SCALES[options[:scale].to_sym].split(',')
23
21
 
24
- feep_options = {:freq_or_note => note, :waveform => options[:waveform], :volume => options[:volume], :duration => options[:duration], :save => options[:save], :loud => options[:loud]}
22
+ freq_index = FREQS.index(freq)
25
23
 
26
- # play number of degrees of scale supplied or one octave by default
27
- degrees = options[:degrees] || steps.length
24
+ feep_options = {
25
+ :freq_or_note => freq.to_s,
26
+ :waveform => options[:waveform],
27
+ :volume => options[:volume],
28
+ :duration => options[:duration],
29
+ :save => options[:save],
30
+ :loud => options[:loud]
31
+ }
28
32
 
29
- if options[:loud]
30
- puts "Playing a #{options[:scale]} scale..."
31
- end
33
+ # play number of degrees of scale supplied or one octave by default
34
+ degrees = options[:degrees] || steps.length
32
35
 
33
- 1.upto(degrees.to_i) {|deg|
34
36
  if options[:loud]
35
- puts "note: #{note}, freq: #{freq}"
37
+ puts "Playing a #{options[:scale]} scale..."
36
38
  end
37
-
38
- # play note
39
- Feep::Base.new(feep_options)
40
-
41
- # go to the next note in the scale
42
- note_index += steps[deg].to_i
43
39
 
44
- # set new note to play next time around
45
- note = feep_options[:freq_or_note] = NOTES[note_index]
46
- freq = FREQS[note_index]
47
- }
40
+ 1.upto(degrees.to_i) {|deg|
41
+ if options[:loud]
42
+ puts "note: #{NOTE_FREQ.key(freq)}, freq: #{freq}"
43
+ end
44
+
45
+ # play note
46
+ Feep::Base.new(feep_options)
47
+
48
+ # go to the next note in the scale
49
+ freq_index += steps[deg].to_i
50
+
51
+ # set new note to play next time around
52
+ freq = feep_options[:freq_or_note] = FREQS[freq_index].to_s
53
+ }
54
+ else
55
+ Utils.print_error(:invalid_scale_root_note)
56
+ end
48
57
  end
49
58
 
50
59
  end
data/lib/feep/utils.rb CHANGED
@@ -32,7 +32,7 @@ module Feep
32
32
  def self.print_error(msg_id)
33
33
  msg = ERROR_MSG[msg_id.to_sym]
34
34
  puts "#{File.basename($PROGRAM_NAME).split(".")[0]}: #{msg}"
35
- puts 'usage: feep [frequency|note-name|list-of-frequencies-or-note-names] [scale] [scale-degrees] [sine|square|saw|triangle|noise] [volume] [duration] [save] [loud]'
35
+ puts 'feep -h for usage'
36
36
  exit
37
37
  end
38
38
 
data/lib/feep/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Feep
2
- VERSION = '0.0.9'
2
+ VERSION = '0.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: feep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Chadwick
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-06 00:00:00.000000000 Z
11
+ date: 2015-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: wavefile