Class: Wavesync::Analyzer
- Inherits:
-
Object
- Object
- Wavesync::Analyzer
- Defined in:
- lib/wavesync/analyzer.rb
Constant Summary collapse
- CONFIRM_MESSAGE =
'wavesync analyze will add bpm meta data to files in library. Continue? [y/N] '- SETUP_INSTRUCTIONS =
'brew install python@3.11 && python3.11 -m venv ~/.wavesync-venv && ~/.wavesync-venv/bin/pip install essentia'
Instance Method Summary collapse
-
#analyze(overwrite: false) ⇒ Object
: (?overwrite: bool) -> void.
-
#initialize(library_path) ⇒ Analyzer
constructor
: (String library_path) -> void.
Constructor Details
#initialize(library_path) ⇒ Analyzer
: (String library_path) -> void
12 13 14 15 16 17 |
# File 'lib/wavesync/analyzer.rb', line 12 def initialize(library_path) @library_path = File.(library_path) #: String Logger.configure(@library_path) @audio_files = find_audio_files #: Array[String] @ui = UI.new #: UI end |
Instance Method Details
#analyze(overwrite: false) ⇒ Object
: (?overwrite: bool) -> void
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/wavesync/analyzer.rb', line 20 def analyze(overwrite: false) unless BpmDetector.available? puts "Error: essentia is not installed. Set up the Python venv with:\n #{SETUP_INSTRUCTIONS}" exit 1 end return unless @ui.confirm(CONFIRM_MESSAGE) start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) @audio_files.each_with_index do |file, index| audio = Audio.new(file) if audio.bpm && !overwrite @ui.analyze_progress(index, @audio_files.size) @ui.analyze_skip(file, audio.bpm) next end bpm = BpmDetector.detect(file) audio.write_bpm(bpm) if bpm @ui.analyze_progress(index, @audio_files.size) @ui.analyze_result(file, bpm) end elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time Logger.log_run_time(elapsed) end |