Class: Wavesync::Analyzer
- Inherits:
-
Object
- Object
- Wavesync::Analyzer
- Defined in:
- lib/wavesync/analyzer.rb
Constant Summary collapse
- 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, path: nil) ⇒ Object
: (?overwrite: bool, ?path: String?) -> void.
-
#initialize(library_path) ⇒ Analyzer
constructor
: (String library_path) -> void.
Constructor Details
#initialize(library_path) ⇒ Analyzer
: (String library_path) -> void
11 12 13 14 15 16 |
# File 'lib/wavesync/analyzer.rb', line 11 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, path: nil) ⇒ Object
: (?overwrite: bool, ?path: String?) -> void
19 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 19 def analyze(overwrite: false, path: nil) unless BpmDetector.available? puts "Error: essentia is not installed. Set up the Python venv with:\n #{SETUP_INSTRUCTIONS}" exit 1 end files = files_for(path) return unless @ui.confirm((path)) start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) files.each_with_index do |file, index| audio = Audio.new(file) if audio.bpm && !overwrite @ui.analyze_progress(index, files.size) @ui.analyze_skip(file, audio.bpm) next end bpm = BpmDetector.detect(file) audio.write_bpm(bpm) if bpm @ui.analyze_progress(index, files.size) @ui.analyze_result(file, bpm) end elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time Logger.log_run_time(elapsed) end |