Emacs user interface for Music Player Daemon (https://www.musicpd.org/), a flexible, powerful, server-side application for playing music.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

191 lines
6.3KB

  1. ;;; mpdel-core.el --- Provide code to be reused by mpdel modes -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2018-2020 Damien Cassou
  3. ;; Author: Damien Cassou <damien@cassou.me>
  4. ;; Keywords: multimedia
  5. ;; Url: https://gitlab.petton.fr/mpdel/mpdel
  6. ;; Package-requires: ((emacs "25.1"))
  7. ;; Version: 1.0.0
  8. ;; This program is free software; you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation, either version 3 of the License, or
  11. ;; (at your option) any later version.
  12. ;; This program is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;; GNU General Public License for more details.
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. ;;; Commentary:
  19. ;; This file provides some common ground for all MPDel
  20. ;; user-interfaces.
  21. ;;; Code:
  22. (require 'libmpdel)
  23. (require 'navigel)
  24. ;;; `navigel' general configuration
  25. (navigel-method mpdel navigel-name (entity)
  26. (libmpdel-entity-name entity))
  27. (navigel-method mpdel navigel-children (entity callback)
  28. (libmpdel-list entity callback))
  29. (navigel-method mpdel navigel-equal (entity1 entity2)
  30. (libmpdel-equal entity1 entity2))
  31. (navigel-method mpdel navigel-parent (entity)
  32. (libmpdel-entity-parent entity))
  33. ;;; Public functions
  34. (defun mpdel-core-open (entity &optional target)
  35. "Open a buffer showing ENTITY.
  36. If TARGET is non nil and visible on the buffer, move point to
  37. it."
  38. (let ((navigel-app 'mpdel))
  39. (navigel-open entity target)))
  40. (defun mpdel-core-selected-entities ()
  41. "Return the selected entities in the current buffer.
  42. If any entity is marked, return the list of all marked entities.
  43. If no entity is marked but there is an entity at point, return a
  44. list with this entity. Otherwise, return nil."
  45. (navigel-marked-entities t))
  46. (defun mpdel-core-add-to-current-playlist ()
  47. "Add selected entities to current playlist."
  48. (interactive)
  49. (libmpdel-current-playlist-add (mpdel-core-selected-entities)))
  50. (defun mpdel-core-add-to-stored-playlist ()
  51. "Add selected entities to a stored playlist."
  52. (interactive)
  53. (libmpdel-stored-playlist-add (mpdel-core-selected-entities)))
  54. (defun mpdel-core-replace-current-playlist ()
  55. "Replace current playlist with selected entities."
  56. (interactive)
  57. (libmpdel-current-playlist-replace (mpdel-core-selected-entities)))
  58. (defun mpdel-core-replace-stored-playlist ()
  59. "Replace a stored playlist with selected entities."
  60. (interactive)
  61. (libmpdel-stored-playlist-replace (mpdel-core-selected-entities)))
  62. (defun mpdel-core-insert-current-playlist ()
  63. "Insert selected entities after currently-played song.
  64. Start playing the first.
  65. If no entity is selected, restart playing the current song."
  66. (interactive)
  67. (let ((entities (mpdel-core-selected-entities)))
  68. (if (not entities)
  69. (libmpdel-playback-seek "0")
  70. (libmpdel-current-playlist-insert entities))))
  71. (defun mpdel-core-dired ()
  72. "Open dired on the entity at point."
  73. (interactive)
  74. (libmpdel-dired (navigel-entity-at-point)))
  75. ;;;###autoload
  76. (defun mpdel-core-open-artists ()
  77. "Display all artists in the MPD database."
  78. (interactive)
  79. (mpdel-core-open 'artists))
  80. ;;;###autoload
  81. (defun mpdel-core-open-stored-playlists ()
  82. "Display all stored playlists in MPD."
  83. (interactive)
  84. (mpdel-core-open 'stored-playlists))
  85. ;;;###autoload
  86. (defun mpdel-core-open-albums ()
  87. "Display all albums in the MPD database."
  88. (interactive)
  89. (mpdel-core-open 'albums))
  90. ;;;###autoload
  91. (defun mpdel-core-open-directories ()
  92. "Display all top-level directories in the MPD database."
  93. (interactive)
  94. (mpdel-core-open 'directories))
  95. ;;;###autoload
  96. (defun mpdel-core-search-by-artist (name)
  97. "Display all songs whose artist's name match NAME.
  98. Interactively, ask for NAME."
  99. (interactive (list (read-from-minibuffer "Search for artist: ")))
  100. (mpdel-core-open (libmpdel-search-criteria-create :type "artist" :what name)))
  101. ;;;###autoload
  102. (defun mpdel-core-search-by-album (name)
  103. "Display all songs whose album's name match NAME.
  104. Interactively, ask for NAME."
  105. (interactive (list (read-from-minibuffer "Search for album: ")))
  106. (mpdel-core-open (libmpdel-search-criteria-create :type "album" :what name)))
  107. ;;;###autoload
  108. (defun mpdel-core-search-by-title (title)
  109. "Display all songs matching TITLE.
  110. Interactively, ask for TITLE."
  111. (interactive (list (read-from-minibuffer "Search for title: ")))
  112. (mpdel-core-open (libmpdel-search-criteria-create :type "title" :what title)))
  113. ;;;###autoload
  114. (defun mpdel-core-search-by-filter (filter)
  115. "Display all songs matching the mpd filter expression FILTER.
  116. Interactively, ask for FILTER.
  117. Example: ((artist == 'name') AND (any contains 'text'))
  118. Documentation: https://www.musicpd.org/doc/html/protocol.html#filters"
  119. (interactive (list (read-from-minibuffer "Search with filter: ")))
  120. (mpdel-core-open (libmpdel-filter-create :text filter)))
  121. ;;; Mode
  122. (defvar mpdel-core-map
  123. (let ((map (make-sparse-keymap)))
  124. (define-key map (kbd "SPC") #'libmpdel-playback-play-pause)
  125. (define-key map (kbd "M-n") #'libmpdel-playback-next)
  126. (define-key map (kbd "M-p") #'libmpdel-playback-previous)
  127. (define-key map (kbd "a") #'mpdel-core-add-to-current-playlist)
  128. (define-key map (kbd "A") #'mpdel-core-add-to-stored-playlist)
  129. (define-key map (kbd "r") #'mpdel-core-replace-current-playlist)
  130. (define-key map (kbd "R") #'mpdel-core-replace-stored-playlist)
  131. (define-key map (kbd "P") #'mpdel-core-insert-current-playlist)
  132. (define-key map (kbd "C-x C-j") #'mpdel-core-dired)
  133. (define-key map (kbd "N") #'mpdel-core-open-artists)
  134. (define-key map (kbd "L") #'mpdel-core-open-stored-playlists)
  135. (define-key map (kbd "s s") #'mpdel-core-search-by-title)
  136. (define-key map (kbd "s l") #'mpdel-core-search-by-album)
  137. (define-key map (kbd "s r") #'mpdel-core-search-by-artist)
  138. (define-key map (kbd "^") #'navigel-open-parent)
  139. (define-key map (kbd "n") #'next-line)
  140. (define-key map (kbd "p") #'previous-line)
  141. map)
  142. "Keybindings for all MPDel buffers.")
  143. ;; Make it possible to activate `mpdel-core-map' from a keybinding:
  144. (fset 'mpdel-core-map mpdel-core-map)
  145. (provide 'mpdel-core)
  146. ;;; mpdel-core.el ends here
  147. ;; Local Variables:
  148. ;; checkdoc-symbol-words: ("top-level")
  149. ;; End: