# midi-file-io

> Reads, parses and writes MIDI files. Fork of NHQ's midi-file-parser.

Latest version **4.1.1** (published 2024-11-28) · see license license · 0 weekly downloads

## Install

```sh
npm install midi-file-io
pnpm add midi-file-io
yarn add midi-file-io
bun add midi-file-io
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.1.1 |
| Published | 2024-11-28 |
| First published | 2019-02-28 |
| Weekly downloads | 0 |
| License | see license |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=22.0.0 |
| Dependencies | 0 |
| Unpacked size | 40.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Curt Elsasser |
| Maintainers | celsasser |
| Keywords | midi, .mid, parse, read, write, file |

## Links

- npm: https://www.npmjs.com/package/midi-file-io
- Repository: https://github.com/celsasser/midi-file-io
- Homepage: https://github.com/celsasser/midi-file-io#readme
- Issues: https://github.com/celsasser/midi-file-io/issues
- npm.io page: https://npm.io/package/midi-file-io

## Alternatives

- [csv-to-markdown-table](https://npm.io/package/csv-to-markdown-table.md) — 47.0K weekly downloads
- [@sapphire/ratelimits](https://npm.io/package/@sapphire/ratelimits.md) — 4.4K weekly downloads
- [js-csvparser](https://npm.io/package/js-csvparser.md) — 2.0K weekly downloads
- [@adadapted/js-sdk](https://npm.io/package/@adadapted/js-sdk.md) — 251 weekly downloads
- [@grapecity/spread-sheets-sparklines](https://npm.io/package/@grapecity/spread-sheets-sparklines.md) — 103 weekly downloads

## Recent versions

- 4.1.1 (latest) — 2024-11-28
- 4.1.0 — 2024-11-28
- 4.0.0 — 2024-11-27
- 3.1.3 — 2021-09-18
- 3.1.2 — 2021-09-15
- 3.1.1 — 2021-09-09
- 3.1.0 — 2021-09-09
- 3.0.2 — 2021-08-23
- 3.0.1 — 2019-12-03
- 2.1.2 — 2019-08-25
- 2.0.0 — 2019-08-24
- 1.0.6 — 2019-02-28
- 1.0.5 — 2019-02-28
- 1.0.4 — 2019-02-28

## README

# midi-file-parser
```
npm install https://github.com/celsasser/midi-file-io
```
Forked from [midi-file-parser](https://github.com/NHQ/midi-file-parser). Special thanks to the authors.

Added write functionality, tests and made small additions/revisions to the read functionity. Probably not as portable as it was. File IO has dependencies on NodeJS's `fs`. Feel free to fork it and pull it out if this gets in your way.


## usage
Functionality is broken up into read and write. Each of these are broken up into a file operation and a buffer operation:
- `parseMidiBuffer` - parses the binary MIDI buffer into a [MidiIoSong](src/types.ts)
- `parseMidiFile` - parses the MIDI file at the specified path into a [MidiIoSong](src/types.ts)
- `writeMidiToBuffer` - writes the specified [MidiIoSong](src/types.ts) object to a returned  `Buffer`.
- `writeMidiToFile` -  writes the specified [MidiIoSong](src/types.ts) object to the specified path.

## parseMidiBuffer
```js
const midiFileIO = require('midi-file-parser');

const buffer = require('fs').readFileSync('rachnananov.mid', 'binary')
const parsed = parseMidiBuffer(buffer);
```

## parseMidiFile
```js
const midiFileIO = require('midi-file-parser');

const parsed = parseMidiFile('rachnananov.mid');
```

## writeMidiToBuffer
```js
const midiFileIO = require('midi-file-parser');

const parsed = parseMidiFile('rachnananov.mid');
const buffer = writeMidiToBuffer(parsed);
```

## writeMidiToFile
```js
const midiFileIO = require('midi-file-parser');

const parsed = parseMidiFile('rachnananov.mid');
const buffer = writeMidiToFile(parsed, 'rachnananov-copy.mid');
```

---
_Source: https://npm.io/package/midi-file-io · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
