{"id":17724370,"url":"https://github.com/jjgonecrypto/node-keyboard","last_synced_at":"2025-08-23T18:18:37.227Z","repository":{"id":65460798,"uuid":"58575889","full_name":"jjgonecrypto/node-keyboard","owner":"jjgonecrypto","description":"A REPL where music is simply streams of input in node (using soundfonts). Supports optional MIDI input and Rx.","archived":false,"fork":false,"pushed_at":"2020-04-02T08:34:09.000Z","size":143,"stargazers_count":54,"open_issues_count":5,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-17T17:58:08.544Z","etag":null,"topics":["midi","node-keyboard","nodejs","repl","soundfonts","streams2"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jjgonecrypto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-11T19:49:04.000Z","updated_at":"2023-08-23T16:00:05.000Z","dependencies_parsed_at":"2023-01-24T15:05:15.399Z","dependency_job_id":null,"html_url":"https://github.com/jjgonecrypto/node-keyboard","commit_stats":null,"previous_names":["justinjmoses/node-keyboard"],"tags_count":37,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jjgonecrypto%2Fnode-keyboard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jjgonecrypto%2Fnode-keyboard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jjgonecrypto%2Fnode-keyboard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jjgonecrypto%2Fnode-keyboard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jjgonecrypto","download_url":"https://codeload.github.com/jjgonecrypto/node-keyboard/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252802300,"owners_count":21806469,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["midi","node-keyboard","nodejs","repl","soundfonts","streams2"],"created_at":"2024-10-25T15:46:39.237Z","updated_at":"2025-05-07T02:40:24.412Z","avatar_url":"https://github.com/jjgonecrypto.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-keyboard\n\n[![Greenkeeper badge](https://badges.greenkeeper.io/justinjmoses/node-keyboard.svg)](https://greenkeeper.io/)\n\n[![npm version](https://badge.fury.io/js/node-keyboard.svg)](https://badge.fury.io/js/node-keyboard)\n\nA REPL where music is simply streams of input in node. Uses the awesome soundfonts of [midi-js-soundfonts](https://github.com/gleitz/midi-js-soundfonts). Supports optional MIDI input.\n\n![](https://media.giphy.com/media/l0MYPIsEjIrUFYNs4/giphy.gif)\n\n## Install via\n    npm install -g node-keyboard\n\n\u003e **Note: Installing node-keyboard will clone a soundfont library during install, resulting in an 800MB download.**\n\n## Run via\n    node-keyboard\n\n## Examples\nInside the REPL, the examples in the example folder are loaded as getters with the prefix `example_`. E.g. `example_01_scales.chromatic({ key: 'b', ms: 100 })`\n\n## Streaming Functionality tl;dr\n\n* [MIDI In](#midi-in) support by `midiIn`, pipe to audio via `.pipe(toAudio)`\n* [Create a stream](#create-a-stream) of notes using `from`\n* [Delay playing](#delay) across a cycle of intervals via `.pipe(delay(...))`\n* [Select instrument](#with-instrument) or play with a random one via `.pipe(on(...))`\n\n### MIDI In\nPipe the `midiIn` stream to a number of writable outputs. (*To function, your MIDI device must be on when node starts.*)\n\n`toAudio` will play the notes\n\n```javascript\nmidiIn.pipe(toAudio)\n```\n\n`toRepl` will output the notes in the REPL\n\n```javascript\nmidiIn.pipe(toRepl)\n```\n\n`toPiano` will draw the piano for each note played\n\n```javascript\nmidiIn.pipe(toPiano)\n```\n\n`toLogger` will console log the note (pipe after `toAudio` to see more information about the played note)\n\n```javascript\nmidiIn.pipe(toLogger)\n```\n\nOr pipe them through each other\n`midiIn.pipe(toPiano).pipe(toAudio)`\n\nAnd remove from MIDI input via `midiIn.unpipe()` (or `CTRL`+`C`)\n\n![node-keyboard](https://cloud.githubusercontent.com/assets/799038/20159751/b75032b8-a6b0-11e6-92ed-6b91814647f3.gif)\n\n### Create a Stream\nCreate an [infinite] stream of notes from an array using `from` (supports notes as variables).\n\n```javascript\nfrom(c, e, g).pipe(toAudio) // Hit CTRL+C (SIGINT) to unpipe immediately\n```\n\n\u003e Note: supports all notes A0 to Cs8/Db8 (Cs8 is the syntax-friendly version of 'C#8')\n\n### Delay\nUse `delay(...args)` to return a transform stream that will emit after the given delays (where the delays are cycled)\n\n```javascript\nfrom(c1, g1, c2, g2, c3, g3).pipe(delay(250, 250, 500)).pipe(toAudio)\n```\n\n### With Instrument\nUse `on(instrument)` to return a transform stream that will ensure the given instrument is used.\n\n```javascript\nfrom(c,e,g).pipe(on('guitar')).pipe(delay(200)).pipe(toAudio)\n```\n\n\u003e Note: Breaking via CTRL+C will stop the stream by unpiping **everything**\n\n## Functionality (sans streams)\nFunctionality, without the streams.\n\n### Properties\n* `instruments` list all instruments available\n* `scales` list all scales supported\n\n###Side effects\n* `play(note)` plays a note.\nEg.\n```javascript\n[c,e,g].forEach(play)\n```\n\n* `piano(note)` draws the piano playing that note\nEg.\n```javascript\n[c,e,g].forEach((note, i) =\u003e setTimeout(() =\u003e piano(note), 400 * i))\n```\n\n* `log(note)` logs the note to `stdout`. (Includes the instrument if chained after `play`)\nEg.\n```javascript\n[f,a,c].map(play).forEach(log)\n```\n\n### Projections\n* `chord(name)` projects a chord name out to an array of notes.\nEg.\n```javascript\nchord('cm9')\n// [ 'c4', 'eb4', 'g4', 'bb4', 'd5' ]\n```\n\n* `scale(note, name)` projects a note through the named scale\nEg.\n```javascript\nscale('a', 'flamenco')\n// [ 'a5', 'bb5', 'c#6', 'd6', 'e6', 'f6', 'g#6' ]\n```\n\n* `sequence(note, ...semitones)` projects a note through the given semitone sequence\nEg.\n```javascript\nsequence(c, 2, 1, 2, 2, 1, 2, 2) // c minor scale\n// [ 'c3', 'd3', 'eb3', 'f3', 'g3', 'g#3', 'a#3', 'c4' ]\n```\n\n### Functors\n* `instrument([name]])` returns mapping function to play on instrument. If no parameter provided it chooses a random instrument.\nEg.:\n```javascript\n[c,e,g].map(instrument('guitar')).forEach(play)\n```\n\n* `interval(...intervals)` returns mapping function to project intervals.\nEg.\n```javascript\n[c,e,g].map(interval('P1','P5')).reduce((acc, cur) =\u003e acc.concat(cur), [])\n// [ 'c3', 'g3', 'e3', 'b3', 'g3', 'd4' ]\n```\n\n* `only(...numbers)` returns filter predicate to filter out to required interval positions.\nEg.\n```javascript\nscale(c, 'major').filter(only(1,3,5,7)).map(play) // Cmaj7\n```\n\n## Plugins\n\n* RxJS support and examples via [node-keyboard-rx](https://github.com/justinjmoses/node-keyboard-rx)\n* Mouse support (OSX only) at [node-keyboard-mouse](https://github.com/justinjmoses/node-keyboard-mouse)\n* Twitter support at [node-keyboard-twitter](https://github.com/justinjmoses/node-keyboard-twitter)\n* MongoDB support at [node-keyboard-mongo](https://github.com/justinjmoses/node-keyboard-mongo)\n* Object to chords - shape mappings at [node-keyboard-shapes](https://github.com/justinjmoses/node-keyboard-shapes)\n\n## Known Issues\n* Reusing a stream and repiping it through transformers\nE.g.\n```javascript\nlet guitar = from(c,e,g).pipe(on('guitar')).pipe(delay(200))\nguitar.pipe(toAudio)\n// CTRL+C\nguitar.pipe(toAudio) // works\n// CTRL+C\nguitar.pipe(on()).pipe(toAudio) // works first time only\n// CTRL+C\nguitar.pipe(on()).pipe(toAudio) // won't play the guitar stream's final on() is still piped to the previous on()\n```\n\n-------\n\n## More info\nI spoke on node-keyboard at EmpireNode in November 2016 [![image](https://cloud.githubusercontent.com/assets/799038/20642823/a3e35b44-b3e7-11e6-9b1c-a358270daedf.png)](https://youtu.be/Wa5-DePTWdA?t=522 )\n\n## Changelog\n\n* ~~(see [commit log](https://github.com/justinjmoses/node-keyboard/commits/master) for earlier releases)~~\n* ~~`2.5.0` Support for switching instruments~~\n* ~~`2.5.5` Adding `every`~~\n* ~~`2.6.0` Persistent history for the REPL~~\n    * ~~`2.6.1` Adding eslint and ensuring `play` returns input~~\n* ~~`2.7.0` Support for MIDI input~~\n* ~~`2.8.0` Support for notes as first-class objects (Symbol-like)~~\n* ~~`2.9.0` Support for midi streams: `midiIn`, `toRepl`, `toAudio` and `toPiano`~~\n* ~~`3.0.0` Upgraded to stream-first, all stream variables are now factory functions (to reuse). Support for fromArray. Deprecated older array functionality.~~\n* ~~`3.1.0` Renamed `fromArray` to `from`, allow `from` to continue forever, limited `withDelay` to have a highWaterMark of 1 and play first immediately, brought in SIGINT support to unpipe streams when CTRL+C pressed~~\n* ~~`3.2.0` Renamed `withDelay` to `delay`. Added `toLogger`. Added `on` to play instruments.~~\n* ~~`3.3.0` Added base functions `chord()`, `scale`,  functors `instrument()` anf `interval()`, and properties `instruments` and `scales`. Many bug fixes.~~\n* ~~`3.4.0` Migrated to using getters for writable streams for brevity~~\n* ~~`3.5.0` Support for `only()`~~\n* ~~`3.6.0` Subscription removal on SIGINT for Rx, support for `piano` function, support for `runInThisContext`, and stream getter bugfix~~\n* ~~`3.7.0` Support for `log` function, removal of `runInThisContext` (not necessary)~~\n* ~~`3.8.0` Errors no longer thrown, just shown. Support for examples~~\n* ~~`3.9.0` Removed Rx support and [turned it into a plugin](https://github.com/justinjmoses/node-keyboard-rx)~~\n\n### FAQ\n\n1. When no octave is provided (e.g. `play(a)`) then 3rd octave (`a3` 220Hz) (starting at `c3` on an 8-octave piano) is the default.\n\n2. `a0`, `bb0` (`a#0`) and `b0` are the only notes below `c1`\n\n3. Sharp can be denoated by `s` when not surrounding note by strings (i.e. `as4 ==== 'a#4')`. Double-sharp is denoted with `x` as in `ax3` (enharmonically `b3`). Double-flat is denoted with `bb` as in `bbb3` (enharmonically `a3`)\n\n### Acknowledgements\n\n* The fantastic [midi-js-soundfonts](https://github.com/gleitz/midi-js-soundfonts) library for all the underlying recordings\n* The stunning [teoria library](https://github.com/saebekassebil/teoria) for note, chord and scale support\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjjgonecrypto%2Fnode-keyboard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjjgonecrypto%2Fnode-keyboard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjjgonecrypto%2Fnode-keyboard/lists"}