#30 First run libmpdel-playback-play-pause with error `apply: Wrong number of arguments: #<subr format>, 0`

Closed
opened 5 months ago by vonfry · 1 comments
vonfry commented 5 months ago

Description

It is showed only the first time running mpdel command. And after that, all command can work.

Repoduce

  1. open emacs with -q
  2. load libmpdel
  3. M-x libmpdel-playback-play-pause

other scenario

If a buffer related to mpdel has been opend at first, the problem misses. For example:

  1. open emacs with -q
  2. load mpdel
  3. M-x mpdel-song-open
  4. M-x libmpdel-playback-play-paus

Version

  • mpdel 20210107.1303
  • libmpd 20210107.950
  • mpd 0.22.6

mpd config

music_directory     ...
playlist_directory  ...
db_file             ...

state_file          ...
sticker_file        ...

bind_to_address ...


audio_output {
  ... pulseaudio
}
restore_paused "yes"

Debug trace

  Debugger entered--Lisp error: (wrong-number-of-arguments #<subr format> 0)
  format()
  apply(format nil)
  libmpdel--raw-send-command-with-handler(nil nil)
  libmpdel-send-command(nil)
  libmpdel-playback-play-pause()
  funcall-interactively(libmpdel-playback-play-pause)
  call-interactively(libmpdel-playback-play-pause nil nil)
  command-execute(libmpdel-playback-play-pause)


### Description It is showed only the first time running mpdel command. And after that, all command can work. #### Repoduce 1. open emacs with `-q` 2. load libmpdel 3. `M-x libmpdel-playback-play-pause` #### other scenario If a buffer related to mpdel has been opend at first, the problem misses. For example: 1. open emacs with `-q` 2. load mpdel 3. `M-x mpdel-song-open` 4. `M-x libmpdel-playback-play-paus` ### Version - mpdel `20210107.1303` - libmpd `20210107.950` - mpd `0.22.6` ### mpd config ``` music_directory ... playlist_directory ... db_file ... state_file ... sticker_file ... bind_to_address ... audio_output { ... pulseaudio } restore_paused "yes" ``` ### Debug trace ``` Debugger entered--Lisp error: (wrong-number-of-arguments #<subr format> 0) format() apply(format nil) libmpdel--raw-send-command-with-handler(nil nil) libmpdel-send-command(nil) libmpdel-playback-play-pause() funcall-interactively(libmpdel-playback-play-pause) call-interactively(libmpdel-playback-play-pause nil nil) command-execute(libmpdel-playback-play-pause) ```
Poster
Owner

Thank you very much for your the bug report. I confirm the bug exists and has always existed. It never bothered me though because it fixes itself immediately :-). What happens is that some command depend on the playback state, e.g., libmpdel-playback-play-pause:

(defun libmpdel-playback-play-pause ()
  "Toggle between play and pause.
See also `libmpdel-playback-stop'."
  (interactive)
  (libmpdel-send-command
   (cl-case libmpdel--play-state
     (play "pause 1")
     (pause "pause 0")
     (stop "play"))))

The variable libmpdel--play-state is nil by default and only gets a value after libmpdel has asked for the current status (through libmpdel-refresh-status). This is done when connecting to the MPD server. Unfortunately, this is asynchronous and, by the time the variable gets its value, the function libmpdel-playback-play-pause already read it and saw nil.

I think the way to fix that would be to rewrite state-dependent functions to something like:

(defun libmpdel-playback-play-pause ()
  "Toggle between play and pause.
See also `libmpdel-playback-stop'."
  (interactive)
  (libmpdel-get-state 'play-state
    (lambda (play-state)
      (libmpdel-send-command
        (cl-case play-state
          (play "pause 1")
          (pause "pause 0")
          (stop "play"))))))

This would require implementing the function libmpdel-get-state but it should be simple.

Do you want to try to implement that?

Thank you very much for your the bug report. I confirm the bug exists and has always existed. It never bothered me though because it fixes itself immediately :-). What happens is that some command depend on the playback state, e.g., `libmpdel-playback-play-pause`: ```emacs (defun libmpdel-playback-play-pause () "Toggle between play and pause. See also `libmpdel-playback-stop'." (interactive) (libmpdel-send-command (cl-case libmpdel--play-state (play "pause 1") (pause "pause 0") (stop "play")))) ``` The variable `libmpdel--play-state` is `nil` by default and only gets a value after libmpdel has asked for the current status (through `libmpdel-refresh-status`). This is done when connecting to the MPD server. Unfortunately, this is asynchronous and, by the time the variable gets its value, the function `libmpdel-playback-play-pause` already read it and saw `nil`. I think the way to fix that would be to rewrite state-dependent functions to something like: ```emacs (defun libmpdel-playback-play-pause () "Toggle between play and pause. See also `libmpdel-playback-stop'." (interactive) (libmpdel-get-state 'play-state (lambda (play-state) (libmpdel-send-command (cl-case play-state (play "pause 1") (pause "pause 0") (stop "play")))))) ``` This would require implementing the function `libmpdel-get-state` but it should be simple. Do you want to try to implement that?
DamienCassou closed this issue 4 months ago
Sign in to join this conversation.
No Label
No Milestone
No Assignees
2 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.