{"id":18034758,"url":"https://github.com/possseidon/lua-midi","last_synced_at":"2025-09-12T03:19:49.411Z","repository":{"id":53874432,"uuid":"328737218","full_name":"Possseidon/lua-midi","owner":"Possseidon","description":"A pure Lua implementation to read midi files using a callback function.","archived":false,"fork":false,"pushed_at":"2024-10-01T09:21:43.000Z","size":23,"stargazers_count":11,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-09T05:33:49.430Z","etag":null,"topics":["lua","lua-library","midi","midi-processor"],"latest_commit_sha":null,"homepage":"","language":"Lua","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/Possseidon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-01-11T17:15:03.000Z","updated_at":"2024-11-18T21:22:32.000Z","dependencies_parsed_at":"2022-09-05T01:41:49.992Z","dependency_job_id":null,"html_url":"https://github.com/Possseidon/lua-midi","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Possseidon/lua-midi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Possseidon%2Flua-midi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Possseidon%2Flua-midi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Possseidon%2Flua-midi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Possseidon%2Flua-midi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Possseidon","download_url":"https://codeload.github.com/Possseidon/lua-midi/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Possseidon%2Flua-midi/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274747686,"owners_count":25341936,"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","status":"online","status_checked_at":"2025-09-12T02:00:09.324Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["lua","lua-library","midi","midi-processor"],"created_at":"2024-10-30T11:13:59.946Z","updated_at":"2025-09-12T03:19:49.149Z","avatar_url":"https://github.com/Possseidon.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lua-midi\n\nA pure Lua implementation to read midi files using a callback function.\n\n## Usage\n\nThe library allows not only reading all tracks in a midi file at once, but also reading only the header (e.g. to a find out the track count) and then reading a single, specific midi track.\n\nReading all tracks in a midi file:\n\n```lua\nlocal midi = require \"midi\"\n\nlocal file = assert(io.open(\"short-tune.mid\"))\nmidi.process(file, print)\n\nfile:close()\n```\n\nReading only the last track in a midi file:\n\n```lua\nlocal midi = require \"midi\"\n\nlocal file = assert(io.open(\"short-tune.mid\"))\nlocal tracks = midi.processHeader(file) -- find number of tracks\n\nfile:seek(\"set\") -- seek back to the beginning of the file\nmidi.processTrack(file, print, tracks)\n\nfile:close()\n```\n\n---\n\n## Library\n\nThe library consists of a single Lua file, namely [midi.lua](lib/midi.lua).\n\n### Reading full midi files\n\nThe following functions require a stream of a real midi file and use a callback to report individual midi events:\n\n```lua\nfunction midi.process(stream, callback, onlyHeader, onlyTrack)\nfunction midi.processHeader(stream, callback)\nfunction midi.processTrack(stream, callback, track)\n```\n\nAll functions return the total number of tracks in the midi file.\n\n| Parameter    | Description                                                                                           |              |\n| ------------ | ----------------------------------------------------------------------------------------------------- | ------------ |\n| `stream`     | A stream (e.g. `file*`) that points to the start of a midi file.                                      | **required** |\n| `callback`   | A callback function which is invoked for all midi events.                                             | *optional*   |\n| `onlyHeader` | When set to `true`, only the header chunk will be processed.                                          | *optional*   |\n| `onlyTrack`  | When set to any integer, only the header chunk and track with this one-based index will be processed. | *optional*   |\n| `track`      | Same as `onlyTrack` but required.                                                                     | **required** |\n\n### Reading single midi events\n\nThe following function simply reads a single midi event (excluding the usually preceeding delta-time) from the given stream:\n\n```lua\nfunction midi.processEvent(stream, callback, runningStatus)\n```\n\nIt returns how many bytes it had to read from the stream, followed by the updated runningStatus.\n\n| Parameter       | Description                                              |              |\n| --------------- | -------------------------------------------------------- | ------------ |\n| `stream`        | A stream (e.g. `file*`) that points to a midi event.     | **required** |\n| `callback`      | A callback function which is invoked for the midi event. | **required** |\n| `runningStatus` | The running status of a previous midi event.             | *optional*   |\n\n---\n\n## Examples\n\n### [1-read-full-midi.lua](examples/1-read-full-midi.lua)\n\nPrints all midi events in the given midi file.\n\n### [2-read-single-track.lua](examples/2-read-single-track.lua)\n\nPrints only the midi events of a single track in the midi file.\n\n### [3-dispatch-table.lua](examples/3-dispatch-table.lua)\n\nHandles only specific midi events using a dispatch table.\n\n### [4-event-signatures.lua](examples/4-event-signatures.lua)\n\nLists the signatures, on how the callback is invoked, for each midi event.\n\n### [5-single-events.lua](examples/5-single-events.lua)\n\nShows how to read single events from a stream.\n\n### [6-timing.lua](examples/6-timing.lua)\n\nCalculates the total length of a midi file in seconds.\n\nAlso outlines how to convert midi ticks to seconds in general.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpossseidon%2Flua-midi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpossseidon%2Flua-midi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpossseidon%2Flua-midi/lists"}