Module: DTAS::Source::File
- Included in:
- AvFfCommon, Sox
- Defined in:
- lib/dtas/source/file.rb
Overview
:nodoc:
Constant Summary collapse
- FILE_SIVS =
for the “current” command
%w(infile comments command env)- SRC_SIVS =
%w(command env tryorder)
Constants included from Process
Constants included from Command
Instance Attribute Summary collapse
-
#infile ⇒ Object
readonly
Returns the value of attribute infile.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#tryorder ⇒ Object
Returns the value of attribute tryorder.
Attributes included from Common
#dst, #dst_zero_byte, #requeued
Attributes included from Command
#command, #env, #pid, #spawn_at, #to_io
Instance Method Summary collapse
- #__file_init(infile, offset, trim) ⇒ Object
- #__offset_samples ⇒ Object
- #comments ⇒ Object
- #cuebreakpoints ⇒ Object
- #load!(src_hsh) ⇒ Object
-
#offset_samples ⇒ Object
returns any offset in samples (relative to the original source file), likely zero unless seek was used.
-
#offset_us ⇒ Object
this exists mainly to make the mpris interface easier, but it’s not necessary, the mpris interface also knows the sample rate.
- #replaygain ⇒ Object
-
#samples! ⇒ Object
A user may be downloading the file and start playing it before the download completes, this refreshes.
- #source_file_dup(infile, offset, trim) ⇒ Object
- #to_hash ⇒ Object
- #to_source_cat ⇒ Object
- #to_state_hash ⇒ Object
-
#trimfx ⇒ Object
creates the effect to fill the TRIMFX env.
Methods included from Mp3gain
#__mp3gain_peak, #mp3gain_comments
Methods included from Process
#dtas_spawn, #env_expand, #env_expand_ary, #env_expand_i, #qx, reaper
Methods included from DTAS::SpawnFix
Methods included from XS
Methods included from Common
Methods included from Command
#command_init, #command_string, #on_death
Methods included from DTAS::Serialize
Instance Attribute Details
#infile ⇒ Object (readonly)
Returns the value of attribute infile.
11 12 13 |
# File 'lib/dtas/source/file.rb', line 11 def infile @infile end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
12 13 14 |
# File 'lib/dtas/source/file.rb', line 12 def offset @offset end |
#tryorder ⇒ Object
Returns the value of attribute tryorder.
13 14 15 |
# File 'lib/dtas/source/file.rb', line 13 def tryorder @tryorder end |
Instance Method Details
#__file_init(infile, offset, trim) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/dtas/source/file.rb', line 30 def __file_init(infile, offset, trim) @env = @env.dup @format = nil @infile = infile @offset = offset @trim = trim @comments = nil @samples = nil @cuebp = nil @rg = nil end |
#__offset_samples ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/dtas/source/file.rb', line 57 def __offset_samples return 0 unless @offset case @offset when /\A\d+s\z/ @offset.to_i else format.hhmmss_to_samples(@offset) end end |
#comments ⇒ Object
84 85 86 |
# File 'lib/dtas/source/file.rb', line 84 def comments @comments ||= __load_comments end |
#cuebreakpoints ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/dtas/source/file.rb', line 114 def cuebreakpoints rv = @cuebp and return rv rv = [] begin str = qx(@env, %W(metaflac --export-cuesheet-to=- #@infile)) rescue return rv end str.scan(/^ INDEX (\d+) (\S+)/) do |m| index = m[0] time = m[1].dup case time when /\A\d+\z/ time << "s" # sample count (flac 1.3.0) else # HH:MM:SS:FF # FF/75 CDDA frames per second, convert to fractional seconds time.sub!(/:(\d+)\z/, "") frames = $1.to_f if frames > 0 time = sprintf("#{time}.%0.6g", frames / 75.0) end end rv << DTAS::CueIndex.new(index, time) end @cuebp = rv end |
#load!(src_hsh) ⇒ Object
103 104 105 106 107 |
# File 'lib/dtas/source/file.rb', line 103 def load!(src_hsh) SRC_SIVS.each do |field| val = src_hsh[field] and instance_variable_set("@#{field}", val) end end |
#offset_samples ⇒ Object
returns any offset in samples (relative to the original source file), likely zero unless seek was used
50 51 52 53 54 55 |
# File 'lib/dtas/source/file.rb', line 50 def offset_samples off = __offset_samples return off unless @trim tbeg = @trim[0] * format.rate tbeg < off ? off : tbeg end |
#offset_us ⇒ Object
this exists mainly to make the mpris interface easier, but it’s not necessary, the mpris interface also knows the sample rate
44 45 46 |
# File 'lib/dtas/source/file.rb', line 44 def offset_us (offset_samples / format.rate.to_f) * 1000000 end |
#replaygain ⇒ Object
94 95 96 97 |
# File 'lib/dtas/source/file.rb', line 94 def replaygain @rg ||= DTAS::ReplayGain.new(comments) || DTAS::ReplayGain.new(mp3gain_comments) end |
#samples! ⇒ Object
A user may be downloading the file and start playing it before the download completes, this refreshes
79 80 81 82 |
# File 'lib/dtas/source/file.rb', line 79 def samples! @samples = nil samples end |
#source_file_dup(infile, offset, trim) ⇒ Object
24 25 26 27 28 |
# File 'lib/dtas/source/file.rb', line 24 def source_file_dup(infile, offset, trim) rv = dup rv.__file_init(infile, offset, trim) rv end |
#to_hash ⇒ Object
88 89 90 91 92 |
# File 'lib/dtas/source/file.rb', line 88 def to_hash rv = ivars_to_hash(FILE_SIVS) rv["samples"] = samples rv end |
#to_source_cat ⇒ Object
99 100 101 |
# File 'lib/dtas/source/file.rb', line 99 def to_source_cat ivars_to_hash(SRC_SIVS) end |
#to_state_hash ⇒ Object
109 110 111 112 |
# File 'lib/dtas/source/file.rb', line 109 def to_state_hash defaults = source_defaults # see dtas/source/{av,sox}.rb to_source_cat.delete_if { |k,v| v == defaults[k] } end |
#trimfx ⇒ Object
creates the effect to fill the TRIMFX env
68 69 70 71 72 73 74 75 |
# File 'lib/dtas/source/file.rb', line 68 def trimfx return unless @offset || @trim fx = "trim #{offset_samples}s" if @trim && @trim[1] fx << sprintf(' =%0.9gs', (@trim[0] + @trim[1]) * format.rate) end fx end |