{"id":20026243,"url":"https://github.com/microsoft/pxt-midi","last_synced_at":"2025-10-04T20:32:41.096Z","repository":{"id":65976084,"uuid":"89033549","full_name":"microsoft/pxt-midi","owner":"microsoft","description":"A MIDI interface for MakeCode","archived":false,"fork":false,"pushed_at":"2023-06-03T14:37:54.000Z","size":81,"stargazers_count":34,"open_issues_count":1,"forks_count":21,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-04-30T12:49:01.719Z","etag":null,"topics":["makecode","microbit","midi"],"latest_commit_sha":null,"homepage":"https://makecode.microbit.org/pkg/microsoft/pxt-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/microsoft.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":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-22T00:26:45.000Z","updated_at":"2025-03-13T01:59:27.000Z","dependencies_parsed_at":"2024-11-12T19:41:17.180Z","dependency_job_id":null,"html_url":"https://github.com/microsoft/pxt-midi","commit_stats":null,"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2Fpxt-midi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2Fpxt-midi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2Fpxt-midi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2Fpxt-midi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/microsoft","download_url":"https://codeload.github.com/microsoft/pxt-midi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252427816,"owners_count":21746280,"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":["makecode","microbit","midi"],"created_at":"2024-11-13T09:05:56.709Z","updated_at":"2025-10-04T20:32:36.056Z","avatar_url":"https://github.com/microsoft.png","language":"TypeScript","readme":"# MIDI [![Build Status](https://travis-ci.org/Microsoft/pxt-midi.svg?branch=master)](https://travis-ci.org/Microsoft/pxt-midi)\n\nEmulates a MIDI output controller.\n\n## Usage\n\n### Setup\n\nYou will need to connect a MIDI via serial, radio or bluetooth get it to \"talk\" to the MIDI output device.\n\n* for Bluetooth, use the [bluetooth midi package](https://pxt.microbit.org/pkg/microsoft/pxt-bluetooth-midi).\n\n* for bridge applications like [Hairless MIDI](http://projectgus.github.io/hairless-midiserial/), call ``useRawSerial``\n\n```block\nmidi.useRawSerial()\n```\n\n### Playing tones\n\nPlace a ``||midi play tone||`` block to play a single note (on channel **1**). \nThe frequency is mapped to the nearest note.\n\n```block\nmidi.playTone(Note.A, music.beat(BeatFraction.Whole))\n```\n\n### Tone on / off\n\nPlace a ``||midi tone on||`` block to start a tone (on channel **1**).\nPlace a ``||midi tone off||`` to turn it off.\n\n```block\nmidi.toneOn(Note.A)\nmidi.toneOn(Note.B)\nbasic.pause(music.beat())\nmidi.toneOff(Note.A)\nmidi.toneOff(Note.B)\n```\n\n### Drums\n\nPlace a ``||midi play drum||`` block to play a drum sound. This blocks plays sounds on channel **10** which is reserved for drums.\n\n```block\nmidi.playDrum(DrumSound.HandClap)\n```\n\n### Pitch bending\n\nPlace a ``||midi pitch bend||`` block to applying a sound bending effect to channel **1**.\n\n```block\nmidi.pitchBend(8192 + input.acceleration(Dimension.X) * 8)\n```\n\n### Channels\n\nYou can access and manipulate individual channels using the ``||midi channel||`` block.\nChannels are indexed from **1 to 16** and mapped internally to **0..15**.\n\n```block\nlet piano = midi.channel(1);\n```\n\n#### play a note\n\n```block\nlet piano = midi.channel(1);\npiano.note(30, music.beat(BeatFraction.Whole));\n```\n\n#### play a note on / off\n\n```block\nlet piano = midi.channel(1);\npiano.noteOn(30);\nbasic.pause(100)\npiano.noteOff(30)\n```\n\n### change instrument\n\n```block\nlet trumpet = midi.channel(2);\ntrumpet.setInstrument(MidiInstrument.Trumpet);\n```\n\n#### change pitch bend\n\nThe pitch bend expects values between ``0..16383`` where ``8192`` means no bend.\n\n```block\nlet piano = midi.channel(1);\npiano.pitchBend(8192 + input.acceleration(Dimension.X) * 8)\n```\n\n## Radio serial\n\nYou can use radio to send MIDI messages from various @boardname@ and play them via  [Hairless MIDI](http://projectgus.github.io/hairless-midiserial/).\n\n```typescript\nradio.setGroup(10)\n// routes all radio messages via radio\nmidi.setTransport(function (data: Buffer) {\n    led.toggle(3, 4)\n    radio.sendBuffer(data);\n})\n\n// proxies all radio buffers to serial\nradio.onReceivedBuffer(function (buffer: Buffer) {\n    serial.writeBuffer(buffer);\n    led.toggle(4, 4);\n})\n\n// test send message\ninput.onButtonPressed(Button.A, function () {\n    led.toggle(0, 0)\n    midi.playTone(Note.C, 500)\n})\n```\n\n## License\n\nMIT\n\n## Supported targets\n\n* for PXT/microbit\n* for PXT/calliope\n\n(The metadata above is needed for package search.)\n\n## Code of Conduct\n\nThis project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrosoft%2Fpxt-midi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicrosoft%2Fpxt-midi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrosoft%2Fpxt-midi/lists"}