emms-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emms-patches] darcs patch: refactor caching code into emms-cache.el


From: Damien Elmes
Subject: [Emms-patches] darcs patch: refactor caching code into emms-cache.el
Date: Wed, 7 Jun 2006 21:55:16 +0900 (JST)

Wed Jun  7 21:53:45 JST 2006  Damien Elmes <address@hidden>
  * refactor caching code into emms-cache.el
  * caching support is now provided via two function vars in emms.el,
    emms-cache-get-function and emms-cache-set-function
  * (emms-standard) or above will enable caching support
  * you'll need to remove .emms-cache or s/emms-info-cache/emms-cache-db/
New patches:

[refactor caching code into emms-cache.el
Damien Elmes <address@hidden>**20060607125345
 * caching support is now provided via two function vars in emms.el,
   emms-cache-get-function and emms-cache-set-function
 * (emms-standard) or above will enable caching support
 * you'll need to remove .emms-cache or s/emms-info-cache/emms-cache-db/
] {
addfile ./emms-cache.el
hunk ./emms-cache.el 1
+;;; emms-cache.el --- persistence for emms-track
+
+;; Copyright (C) 2006  Damien Elmes <address@hidden>
+
+;; Author: Damien Elmes <address@hidden>
+;; Keywords: emms, mp3, mpeg, multimedia
+
+;; This file is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; This file is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING.  If not, write to
+;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;;; Commentary:
+
+;; The cache is a mapping of a full path name to information, and so
+;; it is invalidated when you rename or move files about. It also does
+;; not differentiate between file or uri tracks.
+
+;; Because cache lookups are much faster than disk access, this works
+;; much better with a later-do-interval of something like 0.001. Also
+;; consider using synchronous mode, as it's quite fast now.
+
+;; This code is activated by (emms-standard) and above.
+
+;;; Code:
+
+(define-hash-table-test 'string-hash 'string= 'sxhash)
+(defvar emms-cache-db (make-hash-table :test 'string-hash)
+  "A mapping of paths to file info.
+This is used to cache over emacs sessions.")
+
+(defvar emms-cache-file "~/.emms-cache"
+  "A file used to store cached file info information over sessions")
+
+(defvar emms-cache-dirty nil
+  "True if the cache has been updated since init.")
+
+(defun emms-cache-get (path)
+  "Return a cache element for PATH, or nil."
+  (gethash path emms-cache-db))
+
+(defun emms-cache-set (path track)
+  "Set PATH to TRACK in the cache."
+  (puthash path track emms-cache-db)
+  (setq emms-cache-dirty t))
+
+(defun emms-cache-save ()
+  "Save the track cache to a file."
+  (when emms-cache-dirty
+    (message "Saving emms track cache...")
+    (set-buffer (get-buffer-create " emms-cache "))
+    (erase-buffer)
+    (maphash (lambda (k v)
+               (insert (format
+                        "(puthash %S '%S emms-cache-db)\n" k v)))
+             emms-cache-db)
+    (set-buffer-file-coding-system 'mule-utf-8)
+    (write-region (point-min) (point-max) emms-cache-file)
+    (kill-buffer (current-buffer))
+    (message "Saving emms track cache...done")
+    (setq emms-cache-dirty nil)))
+
+(defun emms-cache-restore ()
+  "Restore the track cache from a file."
+  (load emms-cache-file t nil t)
+  (setq emms-cache-dirty nil))
+
+(provide 'emms-cache)
+;;; emms-cache.el ends here
hunk ./emms-info.el 70
-;; cache support (break into a separate file and make
-;; emms-info-really-initialize-track into a variable controlling which
-;; function to use)?
-
-;; The cache is invalidated when track names are changed. It also does
-;; not differenciate between file or uri tracks, and relies on the
-;; uniqueness of the name.
-
-;; usage - in your .emacs
-
-;; (add-hook 'after-init-hook 'emms-info-cache-restore)
-;; (add-hook 'kill-emacs-hook 'emms-info-cache-save)
-
-;; this is works much better with a later-do-interval of something
-;; like 0.001
-
-(define-hash-table-test 'string-hash 'string= 'sxhash)
-(defvar emms-info-cache (make-hash-table :test 'string-hash)
-  "A mapping of paths to file info.
-This is used to cache file info over emacs sessions.")
-
-(defvar emms-info-cache-file "~/.emms-cache"
-  "A file used to store cached file info information over sessions")
-
-(defvar emms-info-cache-dirty nil
-  "True if the cache has been updated since init.")
-
hunk ./emms-info.el 83
-        (name (emms-track-get track 'name))
-        cached-track
-        updated)
-
-    (when (setq cached-track (gethash name emms-info-cache))
-      ;; We need to modify TRACK. This way we lose information already
-      ;; present in TRACK, which is not necessarily what we want, but
-      ;; it's efficient.
-      (setcar track (car cached-track))
-      (setcdr track (cdr cached-track)))
-
-    ;; if uncached, or cached and the time has changed
-    (when (or (not cached-track)
-              (and cached-track
-               emms-info-auto-update
-               (let ((info-mtime (emms-track-get track 'info-mtime)))
-                 (or (not (consp info-mtime))
-                     (emms-time-less-p info-mtime file-mtime)))))
-      (setq updated t)
-      (run-hook-with-args 'emms-info-functions track))
+        (info-mtime (emms-track-get track 'info-mtime))
+        (name (emms-track-get track 'name)))
hunk ./emms-info.el 86
-    (emms-track-set track 'info-mtime file-mtime)
-    (emms-track-updated track)
-
-    (when (or (not cached-track)
-            updated)
-        (puthash name track emms-info-cache)
-        (setq emms-info-cache-dirty t))
+    ;; if the file's been modified or is new
+    (when (or (not info-mtime)
+              (emms-time-less-p
+               info-mtime file-mtime))
+      (run-hook-with-args 'emms-info-functions track)
+      ;; not set by info functions
+      (emms-track-set track 'info-mtime file-mtime)
+      (funcall emms-cache-set-function name track)
+      (emms-track-updated track))
hunk ./emms-info.el 102
-(defun emms-info-cache-save ()
-  "Save the info cache to a file."
-  (when emms-info-cache-dirty
-    (message "Saving emms info cache...")
-    (set-buffer (get-buffer-create " emms-info-cache "))
-    (erase-buffer)
-    (maphash (lambda (k v)
-               (insert (format
-                        "(puthash %S '%S emms-info-cache)\n" k v)))
-             emms-info-cache)
-    (set-buffer-file-coding-system 'mule-utf-8)
-    (write-region (point-min) (point-max) emms-info-cache-file)
-    (kill-buffer (current-buffer))
-    (message "Saving emms info cache...done")
-    (setq emms-info-cache-dirty nil)))
-
-(defun emms-info-cache-restore ()
-  "Restore the info cache from a file."
-  (load emms-info-cache-file t nil t)
-  (setq emms-info-cache-dirty nil))
-
hunk ./emms-setup.el 67
-interactive playlist mode and reading information from tagged
-audio files."
+interactive playlist mode, reading information from tagged
+audio files, and a metadata cache."
hunk ./emms-setup.el 76
+  (require 'emms-cache)
hunk ./emms-setup.el 82
-  (setq emms-track-description-function 'emms-info-track-description))
+  (setq emms-track-description-function 'emms-info-track-description)
+  (add-hook 'after-init-hook 'emms-cache-restore)
+  (add-hook 'kill-emacs-hook 'emms-cache-save)
+  (setq emms-cache-get-function 'emms-cache-get)
+  (setq emms-cache-set-function 'emms-cache-set))
hunk ./emms.el 226
+(defvar emms-cache-get-function (lambda (path))
+  "A function to retrieve a track entry from the cache.")
+(defvar emms-cache-set-function (lambda (path track))
+  "A function to add/set a track entry from the cache.")
+
hunk ./emms.el 461
-  (let ((track (emms-dictionary '*track*)))
-    (emms-track-set track 'type type)
-    (emms-track-set track 'name name)
+  (let (track)
+    ;; we assume that name is unique across types, so type is not used
+    ;; if we find name in the cache
+    (unless (setq track (funcall emms-cache-get-function name))
+      (setq track (emms-dictionary '*track*))
+      (emms-track-set track 'type type)
+      (emms-track-set track 'name name))
+    ;; run any hooks regardless of a cache hit, as the entry may be
+    ;; old
}

Context:

[emms-info: Fix bug that occurs after clearing the current playlist and trying 
to re-add songs to it.
Michael Olson <address@hidden>**20060606144439] 
[emms-playlist-mode doesn't need overlay compatibility anymore
address@hidden 
[emms-playlist-mode.el - now with less overlay!
address@hidden 
[AUTHORS: fixed Lucas' e-mail address
address@hidden 
[AUTHORS: Damien Elmes address updated
address@hidden 
[info-cache-dirty/coding
Damien Elmes <address@hidden>**20060605163339
 
 * mark the info cache as dirty when it's modified, so we don't have to
   write it out all the time
 * save the cache as mule-utf-8 - comments? i'm not sure if this is
   correct
] 
[emms-info caching (thanks to Damien Elmes)
address@hidden 
[Sort file names from `emms-source-file-directory-tree-function'.
address@hidden 
[Add some sources for inserting playlists without inserting their contents, and 
likewise for directories of playlist files.  Exclude some files and directories 
from being added when walking directories.
Michael Olson <address@hidden>**20060604195602] 
[emms-player-mpd: Differentiate between files and URLs when it makes sense to 
do so.
Michael Olson <address@hidden>**20060604195449] 
[Miscellaneous minor cleanups.
Michael Olson <address@hidden>**20060604195311] 
[Make sure we never have an empty track description when inserting a song into 
a playlist buffer.
Michael Olson <address@hidden>**20060604194940] 
[Remove debian-extras package as requested by ftpmasters (debian)
address@hidden 
[Put volume options in their own customize group.
Martin Schoenmakers <address@hidden>**20060601193853
 
 Added a separate emms-volume group for customize and put things there instead
 of in the main thing.
] 
[Make handling of multiple playlist buffers less error-prone.
Michael Olson <address@hidden>**20060531203810] 
[emms-volume.el: Cosmetic stuff, defvar -> defcustom
address@hidden 
[emms-volume.el: Minor cosmetic cleanup
address@hidden 
[emms-volme.el: Add some requires.
address@hidden 
[emms-volume-amixer.el: Provide a way to set the control for amixer
address@hidden 
[AUTHORS: Add Martin Schoenmakers. Welcome! :-)
address@hidden 
[Add emms-volume and emms-volume-amixer.
Martin Schoenmakers <address@hidden>**20060530223500
 
 New files: emms-volume.el provides some general volume changing things,
 including a minor mode to more easily change volume when not in the
 EMMS buffer. emms-volume-amixer.el is a backend using amixer.
 
] 
[emms-streams: Re-add space after prompt and use completion for type.
Michael Olson <address@hidden>**20060530190620] 
[emms-streams: When the user wants emms-streams to play the selected stream 
instead of add it, create our own playlist buffer.  When quitting, if we own 
the current playlist buffer, kill it.
Michael Olson <address@hidden>**20060530144243] 
[allow nonzero ogginfo exit plus some reindenting
Martin Schoenmakers <address@hidden>**20060530130411
 
 When ogginfo gave a nonzero value on exit, any valid data would get tossed
 if there was any. This prevented emms from showing info for files that are
 tagged but a bit odd.
 
 Also reindented emms-info-ogginfo accordingly, which incidentally removed
 some tabs in favour of spaces.
 
] 
[emms-streams: Re-implement yank and kill so that they do the right thing with 
emms-stream-list.
Michael Olson <address@hidden>**20060530045429] 
[emms-streams: Implement kill and yank.
Michael Olson <address@hidden>**20060530040114] 
[emms-streams: Make hitting RET on a URL do the right thing, improve cursor 
movement, and mark the buffer as unmodified after performing a save.
Michael Olson <address@hidden>**20060529030043] 
[emms-player-mpd: Make seek work correctly.
Michael Olson <address@hidden>**20060525033120] 
[emms-player-mpd: Use more robust method of detecting whether we need to 
force-feed MusicPD our playlist.
Michael Olson <address@hidden>**20060525014253] 
[emms-playlist-mode: Make "d" kill the entire line.  This seems to be a good 
compromise of those who use C-k and those who want more standard object-killing 
behavior.
foo**20060524200008] 
[emms-player-mpd: When showing the currently-playing song, prepend the name of 
the radio station, if it exists.
foo**20060524195911] 
[emms-player-mpd: Fix bug that caused unconditional reloading of the entire 
MusicPD playlist whenever the track was changed manually.
Michael Olson <address@hidden>**20060524061655] 
[emms-player-mpd: Overhaul for streamlist support, and fix a few miscellaneous 
issues.
Michael Olson <address@hidden>**20060524055707] 
[emms-player-mpd: Add a few checks to make sure that the given buffer exists 
before trying to do anything with it.
Michael Olson <address@hidden>**20060517035419] 
[emms-source-playlist: Do not expand names of files in playlists, as this can 
cause problems with emms-player-mpd in some configurations.
Michael Olson <address@hidden>**20060516081257] 
[emms-playlist-mode: Implement the option (disabled by default) of opening a 
new EMMS buffer for a playlist, when hitting RET on one.
Michael Olson <address@hidden>**20060510040730] 
[emms-playlist-mode.el: Don't put a period after the mode map. This hangs 21.4 
on display.
address@hidden 
[TAG 2.0
address@hidden 
Patch bundle hash:
7c9455142cf52be9415935561279f69ce2a28fac

reply via email to

[Prev in Thread] Current Thread [Next in Thread]