Module: Feep::Utils
- Defined in:
- lib/feep/utils.rb
Class Method Summary collapse
-
.convert_note_to_freq(freq_or_note) ⇒ Object
makes sure that whatever kind of sound was entered on the CLI it is now a frequency to feed into the sample data generator.
-
.freq_to_midi(freq) ⇒ Object
convert frequencies to midi notes.
-
.midi_to_freq(midi_note) ⇒ Object
convert midi notes to frequencies.
-
.print_error(msg_id) ⇒ Object
displays error, usage, and exits.
Class Method Details
.convert_note_to_freq(freq_or_note) ⇒ Object
makes sure that whatever kind of sound was entered on the CLI it is now a frequency to feed into the sample data generator
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/feep/utils.rb', line 17 def self.convert_note_to_freq(freq_or_note) if freq_or_note.match(/[A-Za-z]/) if NOTE_FREQ.key?(freq_or_note) frequency = NOTE_FREQ[freq_or_note] else print_error(ERROR_MSG[:invalid_note]) end else frequency = freq_or_note end return frequency end |
.freq_to_midi(freq) ⇒ Object
convert frequencies to midi notes
11 12 13 |
# File 'lib/feep/utils.rb', line 11 def self.freq_to_midi(freq) (69 + 12 * (Math.log2(freq.to_i.abs / 440.0))).round end |
.midi_to_freq(midi_note) ⇒ Object
convert midi notes to frequencies
6 7 8 |
# File 'lib/feep/utils.rb', line 6 def self.midi_to_freq(midi_note) 440.0 * (2.0 ** ((midi_note.to_f-69)/12)) end |
.print_error(msg_id) ⇒ Object
displays error, usage, and exits
32 33 34 35 36 37 |
# File 'lib/feep/utils.rb', line 32 def self.print_error(msg_id) msg = ERROR_MSG[msg_id.to_sym] puts "#{File.basename($PROGRAM_NAME).split(".")[0]}: #{msg}" puts 'feep -h for usage' exit end |