{"id":13425373,"url":"https://github.com/rakyll/portmidi","last_synced_at":"2025-04-05T12:07:55.374Z","repository":{"id":43072464,"uuid":"14277666","full_name":"rakyll/portmidi","owner":"rakyll","description":"Go bindings for libportmidi","archived":false,"fork":false,"pushed_at":"2022-03-20T14:07:03.000Z","size":39,"stargazers_count":285,"open_issues_count":14,"forks_count":55,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-29T11:09:52.845Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rakyll.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":"2013-11-10T14:24:56.000Z","updated_at":"2025-02-21T07:39:07.000Z","dependencies_parsed_at":"2022-09-01T20:31:32.741Z","dependency_job_id":null,"html_url":"https://github.com/rakyll/portmidi","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rakyll%2Fportmidi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rakyll%2Fportmidi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rakyll%2Fportmidi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rakyll%2Fportmidi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rakyll","download_url":"https://codeload.github.com/rakyll/portmidi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247332612,"owners_count":20921853,"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-07-31T00:01:11.145Z","updated_at":"2025-04-05T12:07:55.328Z","avatar_url":"https://github.com/rakyll.png","language":"Go","funding_links":[],"categories":["Audio and Music","Audio/Music","音频和音乐","音頻和音樂","音频和音乐库","Uncategorized","\u003cspan id=\"音频和音乐-audio-and-music\"\u003e音频和音乐 Audio and Music\u003c/span\u003e","音频和视频"],"sub_categories":["Contents"],"readme":"# portmidi\nWant to output to an MIDI device or listen your MIDI device as an input? This\npackage contains Go bindings for PortMidi. `libportmidi` (v. 217) is required as a dependency, it's available via apt-get and brew.\n\n~~~ sh\napt-get install libportmidi-dev\n# or\nbrew install portmidi\n~~~\n\nOr, alternatively you can download the source and build it by yourself. See\nthe instructions on [PortMidi homepage](http://portmedia.sourceforge.net/portmidi/).\n\nIn order to start, go get this repository:\n~~~ sh\ngo get github.com/rakyll/portmidi\n~~~\n\n## Usage\n\n### Initialize\n~~~ go\nportmidi.Initialize()\n~~~\n\n### About MIDI Devices\n\n~~~ go\nportmidi.CountDevices() // returns the number of MIDI devices\nportmidi.Info(deviceID) // returns info about a MIDI device\nportmidi.DefaultInputDeviceID() // returns the ID of the system default input\nportmidi.DefaultOutputDeviceID() // returns the ID of the system default output\n~~~\n\n### Write to a MIDI Device\n\n~~~ go\nout, err := portmidi.NewOutputStream(deviceID, 1024, 0)\nif err != nil {\n    log.Fatal(err)\n}\n\n// note on events to play C major chord\nout.WriteShort(0x90, 60, 100)\nout.WriteShort(0x90, 64, 100)\nout.WriteShort(0x90, 67, 100)\n\n// notes will be sustained for 2 seconds\ntime.Sleep(2 * time.Second)\n\n// note off events\nout.WriteShort(0x80, 60, 100)\nout.WriteShort(0x80, 64, 100)\nout.WriteShort(0x80, 67, 100)\n\nout.Close()\n~~~\n\n### Read from a MIDI Device\n~~~ go\nin, err := portmidi.NewInputStream(deviceID, 1024)\nif err != nil {\n    log.Fatal(err)\n}\ndefer in.Close()\n\nevents, err := in.Read(1024)\nif err != nil {\n    log.Fatal(err)\n}\n\n// alternatively you can filter the input to listen\n// only a particular set of channels\nin.SetChannelMask(portmidi.Channel(1) | portmidi.Channel.(2))\nin.Read(1024) // will retrieve events from channel 1 and 2\n\n// or alternatively listen events\nch := in.Listen()\nevent := \u003c-ch\n~~~\n\n### Cleanup\nCleanup your input and output streams once you're done. Likely to be called on graceful termination.\n~~~ go\nportmidi.Terminate()\n~~~\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frakyll%2Fportmidi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frakyll%2Fportmidi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frakyll%2Fportmidi/lists"}