alda-lang/alda

Capture Ctrl-C in the Alda REPL

Closed this issue · 4 comments

Moved from #190.

Quoting @heikkil:

Please capture Crtl-C in alda repl and kill the playback of the current score, instead. It is quite annoying when I try to stop the playing and have to restart the repl. ":quit" and Ctrl-D" should be enough to stop the repl.

I understand that capturing Ctrl-C in Java command line programs is not easy, but clojure repl can do it.

I feel that Ctrl-C should control the whole play/pause/resume cycle:

If there is playback going on, make Ctrl-C print out these options, and then act on the selection:

^C: pause playback
^X: stop playback

Back in REPL, if there is a paused playback process, make Ctrl-C call :resume.

Logically then, if there is no current playback or paused process, Ctrl-C should call :play.

Blocked on:

Thinking about this a little more:

I like the idea of easily pausing, stopping, and playing the current score in the REPL.

However, I'm not so sure I like the idea of capturing Ctrl-C, as it makes it more complicated to exit the program.

Another idea is to add our own custom keybindings. Maybe something like:

^P: start/pause/resume playback
^S: stop playback

One of the reasons that ctrl-c is a good idea for pausing (in my opinion) is that most people are going to try ctrl-c to stop playback anyway (since that's natrual). I think maybe we could have ctrl-c pause when playing, and display a "do you want to quit" when not playing. I think that a Ctrl-P play/pause shortcut would be nice in addition to this to supplement it, for those who want keybinds.

The issue of keybinds is that if they are added, people are probably going to want to configure them, so this is probabluy going to require some thought....

OK -- that's a good point. So far I've got 2 votes for using Ctrl-C, so let's go with that :)

We can still reserve Ctrl-D for exiting the process, so exiting the program won't be too complicated.

Maybe the default keybindings should be something like:

^D (anytime): hard exit (without confirming)

^C (while stopped): "press ^C again to exit"
^C (while playing): pause playback; "press ^C again to exit"
^C (while paused): exit

^P (while stopped): play from beginning
^P (while paused): resume playback