]> rhodes.io Git - squeeze-el.git/commitdiff
Christophe Weblog Wiki Code Publications Music
mouse events for mixer sliders
authorChristophe Rhodes <csr21@cantab.net>
Wed, 26 Mar 2014 11:07:02 +0000 (11:07 +0000)
committerChristophe Rhodes <csr21@cantab.net>
Wed, 26 Mar 2014 11:07:02 +0000 (11:07 +0000)
Sure, why not?

squeeze.el

index d71a50337d921cd1a15e917b973be3f64453ea2f..5ca2f7cb41492ec9eeadfbfef579396ee8be6e66 100644 (file)
 
 (defvar squeeze-control-mixer-map
   (let ((map (make-sparse-keymap)))
-    (define-key map (kbd "RET") 'squeeze-control-mixer-foo)
+    (define-key map (kbd "RET") 'squeeze-control-mixer-set-volume)
+    (define-key map [mouse-1] 'squeeze-control-mixer-mouse-1)
     map))
 
-(defun squeeze-control-mixer-foo ()
+(defun squeeze-control-compute-volume (pos)
+  (let* ((end (next-single-property-change pos 'keymap))
+         (start (previous-single-property-change end 'keymap)))
+    (/ (* 100 (- (point) start)) (- end start 1))))
+
+(defun squeeze-control-mixer-mouse-1 (event)
+  (interactive "e")
+  (let* ((pos (cadadr event))
+         (val (squeeze-control-compute-volume pos))
+         (id (get-text-property pos 'squeeze-playerid)))
+    (squeeze-control-volume-set id val)))
+
+(defun squeeze-control-mixer-set-volume ()
   (interactive)
-  (let* ((end (next-single-property-change (point) 'keymap))
-         (start (previous-single-property-change end 'keymap))
-         (val (/ (* 100 (- (point) start)) (- end start 1)))
+  (let* ((val (squeeze-control-compute-volume (point)))
          (id (get-text-property (point) 'squeeze-playerid)))
-    (message "start %d, end %d, val %d" start end val)
     (squeeze-control-volume-set id val)))
 
 (defun squeeze-control-display-players ()
           (insert (propertize (squeeze-mixer-make-bar (squeeze-player-volume player) 28)
                               'squeeze-playerid (squeeze-player-playerid player)
                               'keymap squeeze-control-mixer-map
+                              'pointer 'hdrag
                               'rear-nonsticky '(keymap))))
         (insert (propertize "\n" 'intangible t)))
       (read-only-mode 1))))