{"id":14007117,"url":"https://github.com/Tonejs/Midi","last_synced_at":"2025-07-24T01:30:44.966Z","repository":{"id":40802377,"uuid":"38941065","full_name":"Tonejs/Midi","owner":"Tonejs","description":"Convert MIDI into Tone.js-friendly JSON","archived":false,"fork":false,"pushed_at":"2023-07-19T09:10:52.000Z","size":2836,"stargazers_count":891,"open_issues_count":16,"forks_count":119,"subscribers_count":28,"default_branch":"master","last_synced_at":"2024-11-21T09:23:29.185Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://tonejs.github.io/Midi/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Tonejs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2015-07-11T21:28:53.000Z","updated_at":"2024-11-19T16:05:32.000Z","dependencies_parsed_at":"2023-02-09T10:15:41.340Z","dependency_job_id":"ec52de19-4855-4548-a941-a12f27a74052","html_url":"https://github.com/Tonejs/Midi","commit_stats":{"total_commits":249,"total_committers":28,"mean_commits":8.892857142857142,"dds":0.357429718875502,"last_synced_commit":"db985dbb89dcb7327c44e7666dcc6c9e0c8c0a91"},"previous_names":["tonejs/miditoscore","tonejs/midiconvert"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tonejs%2FMidi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tonejs%2FMidi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tonejs%2FMidi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tonejs%2FMidi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Tonejs","download_url":"https://codeload.github.com/Tonejs/Midi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227370755,"owners_count":17770706,"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":[],"created_at":"2024-08-10T10:01:50.239Z","updated_at":"2024-11-30T17:31:56.143Z","avatar_url":"https://github.com/Tonejs.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","License"],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/Tonejs/Midi.svg?branch=master)](https://travis-ci.org/Tonejs/Midi)\n[![codecov](https://codecov.io/gh/Tonejs/Midi/branch/master/graph/badge.svg)](https://codecov.io/gh/Tonejs/Midi)\n\n## Installation\n\n`npm install @tonejs/midi`\n\n## [DEMO](https://tonejs.github.io/Midi/)\n\nMidi makes it straightforward to read and write MIDI files with Javascript. It uses [midi-file](https://github.com/carter-thaxton/midi-file) for parsing and writing. \n\n## Import\n\nNode.js:\n\n```javascript\nconst { Midi } = require('@tonejs/midi')\n```\n\nTypescript / ES6\n\n```javascript\nimport { Midi } from '@tonejs/midi'\n```\n\nBrowser\n\n```html\n\u003cscript src=\"https://unpkg.com/@tonejs/midi\"\u003e\u003c/script\u003e\n```\n```javascript\nconst midi = new Midi()\n```\n\n## Basic Example\n\n\n```javascript\n// load a midi file in the browser\nconst midi = await Midi.fromUrl(\"path/to/midi.mid\")\n//the file name decoded from the first track\nconst name = midi.name\n//get the tracks\nmidi.tracks.forEach(track =\u003e {\n  //tracks have notes and controlChanges\n\n  //notes are an array\n  const notes = track.notes\n  notes.forEach(note =\u003e {\n    //note.midi, note.time, note.duration, note.name\n  })\n\n  //the control changes are an object\n  //the keys are the CC number\n  track.controlChanges[64]\n  //they are also aliased to the CC number's common name (if it has one)\n  track.controlChanges.sustain.forEach(cc =\u003e {\n    // cc.ticks, cc.value, cc.time\n  })\n\n  //the track also has a channel and instrument\n  //track.instrument.name\n})\n```\n\n### Format\n\nThe data parsed from the midi file looks like this:\n\n```javascript\n{\n  // the transport and timing data\n  header: {\n    name: String,                     // the name of the first empty track, \n                                      // which is usually the song name\n    tempos: TempoEvent[],             // the tempo, e.g. 120\n    timeSignatures: TimeSignatureEvent[],  // the time signature, e.g. [4, 4],\n\n    PPQ: Number                       // the Pulses Per Quarter of the midi file\n                                      // this is read only\n  },\n\n  duration: Number,                   // the time until the last note finishes\n\n  // an array of midi tracks\n  tracks: [\n    {\n      name: String,                   // the track name if one was given\n\n      channel: Number,                // channel\n                                      // the ID for this channel; 9 and 10 are\n                                      // reserved for percussion\n      notes: [\n        {\n          midi: Number,               // midi number, e.g. 60\n          time: Number,               // time in seconds\n          ticks: Number,              // time in ticks\n          name: String,               // note name, e.g. \"C4\",\n          pitch: String,              // the pitch class, e.g. \"C\",\n          octave : Number,            // the octave, e.g. 4\n          velocity: Number,           // normalized 0-1 velocity\n          duration: Number,           // duration in seconds between noteOn and noteOff\n        }\n      ],\n\n      // midi control changes\n      controlChanges: {\n        // if there are control changes in the midi file\n        '91': [\n          {\n            number: Number,           // the cc number\n            ticks: Number,            // time in ticks\n            time: Number,             // time in seconds\n            value: Number,            // normalized 0-1\n          }\n        ],\n      },\n\n      instrument: {                   // and object representing the program change events\n        number : Number,              // the instrument number 0-127\n        family: String,               // the family of instruments, read only.\n        name : String,                // the name of the instrument\n        percussion: Boolean,          // if the instrument is a percussion instrument\n      },          \n    }\n  ]\n}\n```\n\n### Raw Midi Parsing\n\nIf you are using Node.js or have the raw binary string from the midi file, just use the `parse` method:\n\n```javascript\nconst midiData = fs.readFileSync(\"test.mid\")\nconst midi = new Midi(midiData)\n```\n\n### Encoding Midi\n\nYou can also create midi files from scratch or by modifying an existing file.\n\n```javascript\n// create a new midi file\nvar midi = new Midi()\n// add a track\nconst track = midi.addTrack()\ntrack.addNote({\n  midi : 60,\n  time : 0,\n  duration: 0.2\n})\n.addNote({\n  name : 'C5',\n  time : 0.3,\n  duration: 0.1\n})\n.addCC({\n  number : 64,\n  value : 127,\n  time : 0.2\n})\n \n// write the output\nfs.writeFileSync(\"output.mid\", new Buffer(midi.toArray()))\n```\n\n### Acknowledgment\n\nThank you [midi-file](https://github.com/carter-thaxton/midi-file)!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTonejs%2FMidi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FTonejs%2FMidi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTonejs%2FMidi/lists"}