Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

defaultxr/piano-mode

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Piano-Mode

Piano-Mode is a minor mode for Emacs that turns your keyboard into a “piano” keyboard. It is modeled after the same behavior commonly included in music trackers or digital audio workstations. Each “note on” (piano key press) event is sent to the function specified by the piano-key-down-function variable, and each “note off” is sent to the function specified by piano-key-up-function. See the included piano-mode-cl-collider.el for an example of functions that could be set for these variables.

Example Configuration

Using use-package to load piano-mode and the piano-mode-cl-collider functionality:

(use-package piano-mode
  :custom
  (piano-key-down-function 'piano-cl-collider-play-note)
  (piano-key-up-function 'piano-cl-collider-release-note)
  :bind (("C-c k" . piano-mode)
         :map piano-mode-map
         ("\\" . piano-cl-collider-change-instrument)
         ("|" . piano-cl-collider-change-parameters))
  :config
  (require 'piano-mode-cl-collider))

Caveats

Since (to the best of my knowledge) Emacs does not provide any way to differentiate between a user’s keystrokes and OS-generated key repeat events, and doesn’t expose key release events to Elisp at all, this mode uses the time between events to determine whether a key is still “pressed”. Obviously, this is a very hacky solution, so expect glitchy behavior to occur sometimes. You may want to tune the piano-key-repeat-delay and piano-key-repeat-rate variables based on your OS settings.

Right now, this will only work if you’re using a QWERTY keyboard layout, but you can edit piano-ascii-to-note-translation-table to match your keyboard layout. (Pull requests for alternate layouts are welcome!)

Future

  • “mono mode”
  • record mode
  • better heuristic for note auto-release; take into account whether the key is “repeating” or not.

About

Turn your keyboard into a "piano" in Emacs

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.