about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-12-14 04:16:16 +0000
committerEric Wong <e@80x24.org>2016-01-22 06:12:58 +0000
commitde8d11790c6c20cda59ec14f4188cfbbba6b9eb2 (patch)
treeb82c2ee794a43c98641e43f7459e6e93c9895223
parent92b9c735c28a3a296cd4dd2f10bbdbac5febb2f8 (diff)
downloaddtas-de8d11790c6c20cda59ec14f4188cfbbba6b9eb2.tar.gz
This will allow us to implement the versioning policy of
mpd.  But perhaps that's a bad idea...
-rw-r--r--lib/dtas/track.rb4
-rw-r--r--lib/dtas/tracklist.rb13
2 files changed, 15 insertions, 2 deletions
diff --git a/lib/dtas/track.rb b/lib/dtas/track.rb
index e5a3051..e62a30e 100644
--- a/lib/dtas/track.rb
+++ b/lib/dtas/track.rb
@@ -6,9 +6,11 @@ require_relative '../dtas'
 class DTAS::Track # :nodoc:
   attr_reader :track_id
   attr_reader :to_path
+  attr_reader :version
 
-  def initialize(track_id, path)
+  def initialize(track_id, path, version)
     @track_id = track_id
     @to_path = path
+    @version = version
   end
 end
diff --git a/lib/dtas/tracklist.rb b/lib/dtas/tracklist.rb
index 6e0dd75..78be091 100644
--- a/lib/dtas/tracklist.rb
+++ b/lib/dtas/tracklist.rb
@@ -24,6 +24,7 @@ class DTAS::Tracklist # :nodoc:
     obj = new
     obj.instance_eval do
       list = hash['list'] and @list.replace(list.map { |s| new_track(s) })
+      _inc_version
       SIVS.each do |k|
         instance_variable_set("@#{k}", hash[k] || TL_DEFAULTS[k])
       end
@@ -62,6 +63,7 @@ class DTAS::Tracklist # :nodoc:
     @goto_off = @goto_pos = nil
     @track_nr = 0
     @shuffle = false
+    @version = 0
   end
 
   def new_track(path)
@@ -71,7 +73,7 @@ class DTAS::Tracklist # :nodoc:
     # avoid promoting to Bignum on 32-bit
     @track_nr = n = 1 if n >= 0x3fffffff
 
-    DTAS::Track.new(n, path)
+    DTAS::Track.new(n, path, @version)
   end
 
   def reset
@@ -147,6 +149,7 @@ class DTAS::Tracklist # :nodoc:
         _idx_of(@shuffle, after_track_id) or
                                   raise ArgumentError, 'after_track_id invalid'
       end
+      _inc_version
       @list[idx, 1] = [ @list[idx], track ]
 
       # add into random position if shuffling
@@ -161,6 +164,7 @@ class DTAS::Tracklist # :nodoc:
         @pos += 1 if @pos > idx
       end
     else # nil = first_track
+      _inc_version
       @list.unshift(track)
 
       if @shuffle
@@ -197,6 +201,7 @@ class DTAS::Tracklist # :nodoc:
     len = @list.size
     @pos = len - 1 if @pos >= len
     @goto_pos = @goto_pos = nil # TODO: reposition?
+    _inc_version
     track.to_path
   end
 
@@ -244,6 +249,12 @@ class DTAS::Tracklist # :nodoc:
         end
       end
     end
+    _inc_version
     true
   end
+
+  def _inc_version
+    @version += 1
+    @version = 0 if @version > 0xffffffff
+  end
 end