From 571d07e99bc0051ad51e1f5947a0ad28eefb557f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 30 Sep 2013 03:26:00 +0000 Subject: player: support seeking based on embedded cuesheet (FLAC) This adds the ability to seek internally within FLAC file based on the internal CUE sheet. Other formats may be supported in the future, but FLAC is the only one I know of which supports embedded cue sheets. Note: flac 1.3.0 is recommended for users of non-CDDA-compatible formats. See updates to dtas-player_protocol(7) for details. --- lib/dtas/source/file.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'lib/dtas/source/file.rb') diff --git a/lib/dtas/source/file.rb b/lib/dtas/source/file.rb index 3dadc67..8657b0c 100644 --- a/lib/dtas/source/file.rb +++ b/lib/dtas/source/file.rb @@ -5,6 +5,7 @@ require_relative '../source' require_relative '../command' require_relative '../format' require_relative '../process' +require_relative '../cue_index' module DTAS::Source::File # :nodoc: attr_reader :infile @@ -33,6 +34,7 @@ module DTAS::Source::File # :nodoc: @offset = offset @comments = nil @samples = nil + @cuebp = nil @rg = nil end @@ -90,4 +92,31 @@ module DTAS::Source::File # :nodoc: defaults = source_defaults # see dtas/source/{av,sox}.rb to_source_cat.delete_if { |k,v| v == defaults[k] } end + + 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 end -- cgit v1.2.3-24-ge0c7