Module: MusicMaster

Defined in:
lib/MusicMaster/old/Common.rb,
lib/MusicMaster/Utils.rb,
lib/MusicMaster/Launcher.rb,
lib/MusicMaster/FilesNamer.rb,
lib/MusicMaster/Formats/MP3.rb,
lib/MusicMaster/Formats/Test.rb,
lib/MusicMaster/Formats/Wave.rb,
lib/MusicMaster/Processes/Cut.rb,
lib/MusicMaster/RakeProcesses.rb,
lib/MusicMaster/Processes/Test.rb,
lib/MusicMaster/Processes/GVerb.rb,
lib/MusicMaster/Processes/Custom.rb,
lib/MusicMaster/Processes/DCShifter.rb,
lib/MusicMaster/Processes/Normalize.rb,
lib/MusicMaster/Processes/Compressor.rb,
lib/MusicMaster/Processes/VolCorrection.rb,
lib/MusicMaster/Processes/ApplyVolumeFct.rb,
lib/MusicMaster/Processes/CutFirstSignal.rb,
lib/MusicMaster/Processes/SilenceInserter.rb

Overview

– Copyright © 2009 - 2012 Muriel Salvan ([email protected]) Licensed under the terms specified in LICENSE file. No warranty is provided. ++

Defined Under Namespace

Modules: FilesNamer, Formats, Processes, RakeProcesses, Utils Classes: Launcher

Class Method Summary collapse

Class Method Details

.applyProcesses(iEffects, iFileName, iDir) ⇒ Object

Apply given record effects on a Wave file. It modifies the given Wave file. It saves original and intermediate Wave files before modifications.

Parameters
  • iEffects (list<map<Symbol,Object>>): List of effects to apply

  • iFileName (String): File name to apply effects to

  • iDir (String): The directory where temporary files are stored



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/MusicMaster/old/Common.rb', line 16

def self.applyProcesses(iEffects, iFileName, iDir)
  lFileNameNoExt = File.basename(iFileName[0..-5])
  iEffects.each_with_index do |iEffectInfo, iIdxEffect|
    begin
      access_plugin('Processes', iEffectInfo[:Name]) do |ioActionPlugin|
        # Save the file before using the plugin
        lSave = true
        lSaveFileName = "#{iDir}/#{lFileNameNoExt}.Before_#{iIdxEffect}_#{iEffectInfo[:Name]}.wav"
        if (File.exists?(lSaveFileName))
          puts "!!! File #{lSaveFileName} already exists. Overwrite and apply effect ? [y='yes']"
          lSave = ($stdin.gets.chomp == 'y')
        end
        if (lSave)
          log_info "Saving file #{iFileName} to #{lSaveFileName} ..."
          FileUtils::mv(iFileName, lSaveFileName)
          log_info "===== Apply Effect #{iEffectInfo[:Name]} to #{iFileName} ====="
          ioActionPlugin.execute(lSaveFileName, iFileName, iDir, iEffectInfo.clone.delete_if{|iKey, iValue| next (iKey == :Name)})
        end
      end
    rescue Exception
      log_err "An error occurred while processing #{iFileName} with process #{iEffectInfo[:Name]}: #{$!}."
      raise
    end
  end
end

.src(iSrcFile, iDstFile, iParams) ⇒ Object

Convert a Wave file to another music file

Parameters
  • iSrcFile (String): Source WAVE file

  • iDstFile (String): Destination file

  • iParams (map<Symbol,Object>): The parameters:

    • :SampleRate (Integer): The new sample rate in Hz

    • :BitDepth (Integer): The new bit depth (only for Wave) [optional = nil]

    • :Dither (Boolean): Do we apply dither (only for Wave) ? [optional = false]

    • :BitRate (Integer): Bit rate in kbps (only for MP3) [optional = 320]

    • :FileFormat (Symbol): File format. Here are the possible values: [optional = :Wave]

      • :Wave: Uncompressed PCM Wave file

      • :MP3: MP3 file



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/MusicMaster/old/Common.rb', line 55

def self.src(iSrcFile, iDstFile, iParams)
  if ((iParams[:FileFormat] != nil) and
      (iParams[:FileFormat] == :MP3))
    # MP3 conversion
    lTranslatedParams = []
    iParams.each do |iParam, iValue|
      case iParam
      when :SampleRate
        lTranslatedParams << "Sample rate: #{iValue} Hz"
      when :BitRate
        lTranslatedParams << "Bit rate: #{iValue} kbps"
      when :FileFormat
        # Nothing to do
      else
        log_err "Unknown MP3 parameter: #{iParam} (value #{iValue.inspect}). Ignoring it."
      end
    end
    puts "Convert file #{iSrcFile} into file #{iDstFile} in MP3 format with following parameters: #{lTranslatedParams.join(', ')}"
    puts 'Press Enter when done.'
    $stdin.gets
  else
    # Wave conversion
    lTranslatedParams = [ '--profile standard', '--twopass' ]
    iParams.each do |iParam, iValue|
      case iParam
      when :SampleRate
        lTranslatedParams << "--rate #{iValue}"
      when :BitDepth
        lTranslatedParams << "--bits #{iValue}"
      when :Dither
        if (iValue == true)
          lTranslatedParams << '--dither 4'
        end
      when :FileFormat
        # Nothing to do
      else
        log_err "Unknown Wave parameter: #{iParam} (value #{iValue.inspect}). Ignoring it."
      end
    end
    FileUtils::mkdir_p(File.dirname(iDstFile))
    lCmd = "#{@MusicMasterConf[:SRCCmdLine]} #{lTranslatedParams.join(' ')} \"#{iSrcFile}\" \"#{iDstFile}\""
    log_info "=> #{lCmd}"
    system(lCmd)
  end
end