From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?ISO-8859-1?Q?C=E9dric_Ch=E9pied?= Newsgroups: gmane.emacs.devel Subject: Re: ampc back on elpa? Date: Wed, 27 Jul 2016 15:58:48 +0200 Message-ID: <5798be19.c186c20a.290aa.275b@mx.google.com> References: <573736bd.442cc20a.8d117.ffff9cd7@mx.google.com> <5745411e.aaf0c20a.8e140.4623@mx.google.com> <575abfdd.697ac20a.d9403.5ca0@mx.google.com> <576428ac.aa29c20a.20e25.fffff88b@mx.google.com> <5767d7d0.cf2d1c0a.1c4a7.38a5@mx.google.com> <5776531f.871a1c0a.c1eab.ffffc3b6@mx.google.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1469627949 19190 80.91.229.3 (27 Jul 2016 13:59:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 27 Jul 2016 13:59:09 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Jul 27 15:59:09 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1bSPMa-0002YH-1x for ged-emacs-devel@m.gmane.org; Wed, 27 Jul 2016 15:59:08 +0200 Original-Received: from localhost ([::1]:46690 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSPMZ-0006Py-2n for ged-emacs-devel@m.gmane.org; Wed, 27 Jul 2016 09:59:07 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47381) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSPMM-0006MA-AV for emacs-devel@gnu.org; Wed, 27 Jul 2016 09:58:59 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bSPMK-0006Yk-0I for emacs-devel@gnu.org; Wed, 27 Jul 2016 09:58:53 -0400 Original-Received: from mail-wm0-x232.google.com ([2a00:1450:400c:c09::232]:37051) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSPMJ-0006YE-LH for emacs-devel@gnu.org; Wed, 27 Jul 2016 09:58:51 -0400 Original-Received: by mail-wm0-x232.google.com with SMTP id i5so63974848wmg.0 for ; Wed, 27 Jul 2016 06:58:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:to:subject:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=1cNn8s2NSzseJ9HkeABayyPTW8DGNrSSHDx2xeojiB8=; b=OC1a/29Nv4KkwppIEZh7wae2ibBdcRMsVJydRrwea+BxNTQA/1dqFxjbpx/95z1O55 IK4P+NeD4zGzlnFJnEfS/VXoBFlvm5aU/m8vov9/+QQdMGV08uWsX2KJpTyNvyBy4xXT bV6jAxYOofxzYOwUq4iMfZpBaUMnLGMQzZxpsD+RNpv6C7I0t2vQhkzGv+bGjgeg4Bju rZNCWNSAKntvgwMaVAVaV3R/4wj5cWKCHkJaEEfoP8dkr6qeESa7CVHAiplI+GpHo14Y HNnI+0IfITqmH82KIc8NCot3mRHx348zXUpGKFRLbs+LpwhswQkXkfYlF3KtC5bYd4Cu OCjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:to:subject:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=1cNn8s2NSzseJ9HkeABayyPTW8DGNrSSHDx2xeojiB8=; b=bgMVF5HhJuYzSld06hrj6BR3xxiRV+ZIphmW0/H091M0z2UogJmU6acjQootYfAvX4 NkA9elB9JVakunNK01YX5tM1NjwfTTQ/8K64W5siZObAcUcd0yhAKo8HEIomm1szRRqx yu3ubfVUZGTL1K3PbOFvSRodyAcxM2AOZ2XpE5fR/VCGNh2MFBNTOCsCeih2p2QHNQYb wLWP9Zd6DhteDnHwkimQNpOKKSpk1A/rpc4utiLkUPoSXMNxsmG8AjMkKmYoGl0NRJTn gSgkd3tk27+DQ6mbTaZ4UhRL+3v5Y6xnHycbbm9aHtSPulIM24nVI3lR1kct6jfbAiQJ sq7g== X-Gm-Message-State: AEkooutmPrZJhnkcVQPDnoncDfj7lC+KIWOQU1InNsypKym6P1FQrhgxCiYDhqhub21knA== X-Received: by 10.28.152.5 with SMTP id a5mr33530498wme.76.1469627930407; Wed, 27 Jul 2016 06:58:50 -0700 (PDT) Original-Received: from Aman.gmail.com ([2a01:cb19:82c0:3800:15:9ff:fe42:4cf4]) by smtp.gmail.com with ESMTPSA id pm1sm6528389wjb.40.2016.07.27.06.58.49 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 27 Jul 2016 06:58:49 -0700 (PDT) In-Reply-To: <5776531f.871a1c0a.c1eab.ffffc3b6@mx.google.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM/1.14.9 (=?ISO-8859-4?Q?Goj=F2?=) APEL/10.8 EasyPG/1.0.0 Emacs/25.1.50 (x86_64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::232 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:206179 Archived-At: Hi, Here is a new patch for ampc. It shows a progress bar in the status output. I don't know if there is something in emacs to display progress bars so I wrote my own code for this. -- Cédric Chépied >From 7279b36094aec5b6ec32a5d57cdf00e29e8476e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Ch=C3=A9pied?= Date: Fri, 17 Jun 2016 11:18:04 +0200 Subject: [PATCH 2/2] ampc: add current song time in status display --- packages/ampc/ampc.el | 92 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 82 insertions(+), 10 deletions(-) diff --git a/packages/ampc/ampc.el b/packages/ampc/ampc.el index c09323b..c133337 100644 --- a/packages/ampc/ampc.el +++ b/packages/ampc/ampc.el @@ -548,21 +548,21 @@ modified." ,(kbd "J") horizontal (0.4 vertical - (6 status) + (10 status) (1.0 current-playlist ,@pl-prop)) ,rs_a) ("Current playlist view (Genre|Album|Artist)" ,(kbd "M") horizontal (0.4 vertical - (6 status) + (10 status) (1.0 current-playlist ,@pl-prop)) ,rs_b) ("Playlist view (Genre|Artist|Album)" ,(kbd "K") horizontal (0.4 vertical - (6 status) + (10 status) (1.0 vertical (0.4 current-playlist ,@pl-prop) (0.4 playlist ,@pl-prop) @@ -572,7 +572,7 @@ modified." ,(kbd "<") horizontal (0.4 vertical - (6 status) + (10 status) (1.0 vertical (0.4 current-playlist ,@pl-prop) (0.4 playlist ,@pl-prop) @@ -582,7 +582,7 @@ modified." ,(kbd "F") horizontal (0.4 vertical - (6 status) + (10 status) (1.0 current-playlist ,@pl-prop)) ,search-view) ("Outputs view" @@ -610,6 +610,7 @@ modified." (defvar ampc-internal-db nil) (defvar ampc-status nil) +(defvar ampc-status-timer nil) (defvar ampc-tagger-previous-configuration nil) (defvar ampc-tagger-version-verified nil) @@ -1860,7 +1861,7 @@ modified." (erase-buffer) (funcall (or (plist-get (cadr ampc-type) :filler) (lambda (_) - (insert (ampc-status t) "\n"))) + (insert (ampc-status t (window-width (get-buffer-window))) "\n"))) ampc-status) (ampc-set-dirty nil))) @@ -2007,13 +2008,13 @@ modified." (cl-callf2 assq-delete-all s ampc-status)))) (defun ampc-handle-current-song () - (ampc-fill-status-var (append ampc-status-tags '("Artist" "Title" "file"))) + (ampc-fill-status-var (append ampc-status-tags '("Artist" "Title" "file" "Time"))) (ampc-fill-status) (run-hook-with-args ampc-status-changed-hook ampc-status)) (defun ampc-handle-status () (ampc-fill-status-var '("volume" "repeat" "random" "consume" "xfade" "state" - "song" "playlistlength")) + "song" "playlistlength" "elapsed")) (ampc-with-buffer 'current-playlist (if (fboundp 'font-lock-flush) (font-lock-flush) @@ -2810,7 +2811,70 @@ If ARG is omitted, use the selected entries in the current buffer." (ampc-with-selection arg (ampc-add-impl))) -(defun ampc-status (&optional no-print) +(defun ampc-restart-status-timer () + (when ampc-status-timer + (cancel-timer ampc-status-timer) + (setq ampc-status-timer nil)) + (setq ampc-status-timer + (run-at-time + nil + 0.9 + (lambda () + (when (ampc-on-p) + (ampc-send-command 'status)))))) + + +(defun ampc-time-to-progress-bar (elapsed total width) + "Creates a progess bar like this: |=========>----| +ELAPSED is the number of seconds represented by '=' signs +TOTAL is the number of seconds represented by the entire bar +WIDTH is the max width of the bar. If < 2, 2 characters will be used anyway" + (setq width (- width 2)) ;; 2 characters for '||' + + (let ((result "|")) + (when (> width 0) + (let* ((e (/ (* elapsed width) total)) ;; number of '=' signs + (r (- width e))) ;; number of '-' signs + (setq result (concat result + (make-string (max 0 (1- e)) ?=) + ">" + (make-string r ?-))))) + + (concat result "|"))) + +(defun ampc-current-song-time (elapsed total width) + "Creates an ASCII representation of elapsed time of the current song. +ELAPSED is the current time of the song in seconds +TOTAL is the total time of the song in seconds +WIDTH is the max desired length of the result" + (setq elapsed (truncate elapsed)) + (when (> elapsed total) + (setq elapsed total)) + + (let* ((hours (/ elapsed 3600)) + (minutes (- (/ elapsed 60) (* 60 hours))) + (seconds (mod elapsed 60)) + (result "")) + (when (> hours 0) + (setq result (format "%d:%s" + hours + (if (< minutes 10) + "0" + "") + ))) + (setq result (format "%s%d:%s%d" + result + minutes + (if (< seconds 10) + "0" + "") + seconds)) + + (concat (ampc-time-to-progress-bar elapsed total (1- (- width (length result)))) + " " + result))) + +(cl-defun ampc-status (&optional no-print (width 50)) "Display and return the information that is displayed in the status window. If optional argument NO-PRINT is non-nil, just return the text. If NO-PRINT is nil, the display may be delayed if ampc does not @@ -2845,6 +2909,10 @@ have enough information yet." (ampc-clean-tag 'Title (cdr (assq 'Title ampc-status))) + "\n" + (ampc-current-song-time (string-to-number (cdr (assq 'elapsed ampc-status))) + (string-to-number (cdr (assq 'Time ampc-status))) + width) "\n")) "Volume: " (cdr (assq 'volume ampc-status)) "\n" "Crossfade: " (cdr (assq 'xfade ampc-status)) @@ -3102,6 +3170,9 @@ ampc is connected to." (delete-process ampc-connection)) (when ampc-working-timer (cancel-timer ampc-working-timer)) + (when ampc-status-timer + (cancel-timer ampc-status-timer) + (setq ampc-status-timer nil)) (ampc-suspend nil) (setf ampc-connection nil ampc-internal-db nil @@ -3166,7 +3237,8 @@ default to the ones specified in `ampc-default-server'." (run-hooks 'ampc-connected-hook) (when suspend (ampc-suspend)) - (ampc-filter (process-buffer ampc-connection) nil)) + (ampc-filter (process-buffer ampc-connection) nil) + (ampc-restart-status-timer)) (provide 'ampc) -- 2.8.3