mpdel.el 4.6 KB
Newer Older
1
;;; mpdel.el --- Play and control your MPD music  -*- lexical-binding: t; -*-
Damien Cassou's avatar
Damien Cassou committed
2

Damien Cassou's avatar
Damien Cassou committed
3
;; Copyright (C) 2018-2019  Damien Cassou
Damien Cassou's avatar
Damien Cassou committed
4 5 6

;; Author: Damien Cassou <damien@cassou.me>
;; Keywords: multimedia
7
;; Url: https://gitlab.petton.fr/mpdel/mpdel
Damien Cassou's avatar
Damien Cassou committed
8 9
;; Package-requires: ((emacs "25.1") (libmpdel "1.0.0"))
;; Version: 1.0.0
Damien Cassou's avatar
Damien Cassou committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

;; This program 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 3 of the License, or
;; (at your option) any later version.

;; This program 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 this program.  If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

26
;; MPDel is an Emacs client for Music Player Daemon (MPD), a flexible,
27 28 29 30
;; powerful, server-side application for playing music.  This project
;; provides an Emacs user interface including playlists, navigation in
;; the database and playback control.  Read the README.org file for
;; more information.
Damien Cassou's avatar
Damien Cassou committed
31 32 33 34

;;; Code:

(require 'libmpdel)
35
(require 'mpdel-core)
Damien Cassou's avatar
Damien Cassou committed
36 37
(require 'mpdel-playlist)
(require 'mpdel-song)
38
(require 'mpdel-nav)
Damien Cassou's avatar
Damien Cassou committed
39

Damien Cassou's avatar
Damien Cassou committed
40 41

;;; Customization
Damien Cassou's avatar
Damien Cassou committed
42 43 44 45 46 47 48 49
(defgroup mpdel nil
  "Configure mpdel's global minor mode."
  :group 'libmpdel)

(defcustom mpdel-prefix-key (kbd "C-x Z")
  "Prefix key to all global mpdel keybindings."
  :type 'key-sequence)

Damien Cassou's avatar
Damien Cassou committed
50 51

;;; Add features to all mpdel buffers
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
(defun mpdel-song-small-increment ()
  "Move forward by value of variable `mpdel-song-small-increment'."
  (interactive)
  (mpdel-song--seek mpdel-song-small-increment))

(define-key mpdel-core-map (kbd "F") #'mpdel-song-small-increment)

(defun mpdel-song-normal-increment ()
  "Move forward by value of variable `mpdel-song-normal-increment'."
  (interactive)
  (mpdel-song--seek mpdel-song-normal-increment))

(define-key mpdel-core-map (kbd "f") #'mpdel-song-normal-increment)

(defun mpdel-song-large-increment ()
  "Move forward by value of variable `mpdel-song-large-increment'."
  (interactive)
  (mpdel-song--seek mpdel-song-large-increment))

(define-key mpdel-core-map (kbd "M-f") #'mpdel-song-large-increment)

(defun mpdel-song-small-decrement ()
  "Move backward by value of variable `mpdel-song-small-decrement'."
  (interactive)
  (mpdel-song--seek mpdel-song-small-decrement))

(define-key mpdel-core-map (kbd "B") #'mpdel-song-small-decrement)

(defun mpdel-song-normal-decrement ()
  "Move backward by value of variable `mpdel-song-normal-decrement'."
  (interactive)
  (mpdel-song--seek mpdel-song-normal-decrement))

(define-key mpdel-core-map (kbd "b") #'mpdel-song-normal-decrement)

(defun mpdel-song-large-decrement ()
  "Move backward by value of variable `mpdel-song-large-decrement'."
  (interactive)
  (mpdel-song--seek mpdel-song-large-decrement))

(define-key mpdel-core-map (kbd "M-b") #'mpdel-song-large-decrement)
93

94
(cl-defmethod mpdel-core--open-entity ((entity t) &optional target)
95
  ;; By default, open any entity with a navigator
96
  (mpdel-nav--open entity target))
97

98
(cl-defmethod mpdel-core--open-entity ((song libmpdel-song) &optional _target)
99 100
  (mpdel-song-open song))

101 102
(define-key mpdel-core-map (kbd "l") #'mpdel-playlist-open)
(define-key mpdel-core-map (kbd "L") #'mpdel-playlist-open-stored-playlist)
103 104
(define-key mpdel-core-map (kbd "n") #'mpdel-nav-open-artists)
(define-key mpdel-core-map (kbd "N") #'mpdel-nav-open-stored-playlists)
105
(define-key mpdel-core-map (kbd "v") #'mpdel-song-open)
106 107 108 109
(define-key mpdel-core-map (kbd "s s") #'mpdel-nav-search-by-title)
(define-key mpdel-core-map (kbd "s l") #'mpdel-nav-search-by-album)
(define-key mpdel-core-map (kbd "s r") #'mpdel-nav-search-by-artist)

110 111

;;; Add features to the song buffers
112 113 114
(cl-defmethod mpdel-core--entity-at-point (_pos (_mode (derived-mode mpdel-song-mode)))
  (mpdel-song-buffer-song))

115 116 117 118 119
(defun mpdel-song-navigate ()
  "Open a navigator containing song at point."
  (interactive)
  (mpdel-nav--open (libmpdel-entity-parent (mpdel-song-buffer-song))))

120 121 122

;;; Define the global minor mode so users can control MPD from non-MPD
;;; buffers
Damien Cassou's avatar
Damien Cassou committed
123 124
(defvar mpdel-mode-map
  (let ((map (make-sparse-keymap)))
125
    (define-key map mpdel-prefix-key 'mpdel-core-map)
Damien Cassou's avatar
Damien Cassou committed
126
    map)
127
  "Keymap activating variable `mpdel-core-map'.")
Damien Cassou's avatar
Damien Cassou committed
128 129 130 131 132 133

(define-minor-mode mpdel-mode
  "Activate keybindings to play and control your MPD server.

\\{mpdel-mode-map}"
  :global t
134
  :require 'mpdel
Damien Cassou's avatar
Damien Cassou committed
135 136
  :lighter " MPDel")

137 138
(provide 'mpdel)
;;; mpdel.el ends here
Damien Cassou's avatar
Damien Cassou committed
139 140

;;; LocalWords:  Mpdel mpdel