Skip to content

Commit

Permalink
Allow multi-track queueing (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
27justin committed Dec 13, 2023
1 parent 9aa2edd commit 43812b7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,13 @@ To search for tracks, run <kbd>M-x smudge-track-search</kbd> and type in your
query. The results will be displayed in a separate buffer with the following
key bindings:

| Key | Description |
|:-----------------|:-----------------------------------------------------------------|
| <kbd>a</kbd> | Adds track to a playlist |
| <kbd>l</kbd> | Loads the next page of results (pagination) |
| <kbd>g</kbd> | Clears the results and reloads the first page of results |
| <kbd>k</kbd> | Adds track to the queue |
| <kbd>M-RET</kbd> | Plays the track under the cursor in the context of its album [1] |
| Key | Description |
|:-----------------|:---------------------------------------------------------------------|
| <kbd>a</kbd> | Adds track to a playlist |
| <kbd>l</kbd> | Loads the next page of results (pagination) |
| <kbd>g</kbd> | Clears the results and reloads the first page of results |
| <kbd>k</kbd> | Adds track(s) under the cursor (or inside the region) to the queue |
| <kbd>M-RET</kbd> | Plays the track under the cursor in the context of its album [1] |

[1] D-Bus implementation for GNU/Linux do not support passing the context, so
only the track under the cursor will be played
Expand Down Expand Up @@ -330,7 +330,7 @@ bindings in the resulting buffer:
| <kbd>g</kbd> | Clears the results and reloads the first page of results |
| <kbd>f</kbd> | Follows the current playlist |
| <kbd>u</kbd> | Unfollows the current playlist |
| <kbd>k</kbd> | Adds track to the queue |
| <kbd>k</kbd> | Adds track(s) under the cursor (or inside the region) to the queue |
| <kbd>M-RET</kbd> | Plays the track under the cursor in the context of the playlist [1] |

Both buffers load the `global-smudge-remote-mode` by default.
Expand Down
10 changes: 5 additions & 5 deletions smudge-api.el
Original file line number Diff line number Diff line change
Expand Up @@ -632,11 +632,11 @@ Call CALLBACK if provided."
;; Thus we have to synchronously add the tracks
;; one by one to the queue.
(if (car track-ids)
(smudge-api-queue-add-track (car track-ids)
(lambda (_)
(smudge-api-queue-add-tracks (cdr track-ids)
nil)))
(funcall callback)))
(smudge-api-queue-add-track
(car track-ids)
(lambda (_)
(smudge-api-queue-add-tracks (cdr track-ids) callback)))
(when callback (funcall callback))))

(provide 'smudge-api)
;;; smudge-api.el ends here
29 changes: 24 additions & 5 deletions smudge-track.el
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,33 @@ Default to sortin tracks by number when listing the tracks from an album."
(message "Cannot remove a track from a playlist from here")))

(defun smudge-track-add-to-queue ()
"Add the track under the cursor to the queue."
"Add the track(s) under the cursor (or inside the active region) to the queue."
(interactive)
(let ((selected-track (tabulated-list-get-id)))
(let ((track-id (smudge-api-get-item-uri selected-track)))
(smudge-api-queue-add-track
;; Check whether the mark is active and if so, queue all the tracks in the
;; region. If not, queue the track under the cursor.
(if (null mark-active)
(let ((selected-track (tabulated-list-get-id)))
(setq track-id (smudge-api-get-item-uri selected-track))
(smudge-api-queue-add-track
track-id
(lambda(_)
(message "Added \"%s\" to your queue." (smudge-api-get-item-name selected-track)))))))
(message "Added \"%s\" to your queue." (smudge-api-get-item-name selected-track)))))
(let((start (region-beginning))
(end (region-end))
(tracks '()))
(save-excursion
(goto-char start)
(while (< (point) end)
(setq selected-track (tabulated-list-get-id))
(setq track-id (smudge-api-get-item-uri selected-track))
(setq tracks (cons track-id tracks))
(forward-line 1)))
(smudge-api-queue-add-tracks
(reverse tracks)
nil)
;; Send the message here instead of in the callback
;; because the API call has to sequentially add each song which might take some time.
(message "Added %d tracks to your queue." (length tracks)))))


(provide 'smudge-track)
Expand Down

0 comments on commit 43812b7

Please sign in to comment.