{"id":13768889,"url":"https://github.com/halvves/react-midi-device-provider","last_synced_at":"2025-04-14T02:29:38.284Z","repository":{"id":57334596,"uuid":"109626370","full_name":"halvves/react-midi-device-provider","owner":"halvves","description":"web midi utilities for react","archived":false,"fork":false,"pushed_at":"2021-09-02T17:24:17.000Z","size":40,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-11-17T04:34:50.493Z","etag":null,"topics":["midi","react","web-audio","web-midi"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/halvves.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":"2017-11-05T23:46:14.000Z","updated_at":"2021-09-02T17:24:19.000Z","dependencies_parsed_at":"2022-09-10T23:23:04.755Z","dependency_job_id":null,"html_url":"https://github.com/halvves/react-midi-device-provider","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halvves%2Freact-midi-device-provider","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halvves%2Freact-midi-device-provider/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halvves%2Freact-midi-device-provider/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halvves%2Freact-midi-device-provider/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/halvves","download_url":"https://codeload.github.com/halvves/react-midi-device-provider/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226780187,"owners_count":17680833,"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":["midi","react","web-audio","web-midi"],"created_at":"2024-08-03T16:01:27.633Z","updated_at":"2024-11-27T16:19:58.735Z","avatar_url":"https://github.com/halvves.png","language":"JavaScript","funding_links":[],"categories":["UI components and libraries"],"sub_categories":["React components"],"readme":"# MidiDeviceProvider\n\n[![Latest NPM release][npm-badge]][npm-badge-url]\n[![Build Status][travis-badge]][travis-badge-url]\n\n## Installation\n\n`yarn add react-midi-device-provider` or `npm i -P react-midi-device-provider`\n\n## Usage\n\nWrap all/part of your application in `\u003cMidiDeviceProvider /\u003e`.\n\n```javascript\nimport React from 'react'\nimport { render } from 'react-dom';\nimport { MidiDeviceProvider } from 'react-midi-device-provider';\n\nconst appElement = document.getElementById('app');\nrender(\n  \u003cMidiDeviceProvider sysex\u003e\n    \u003cApp /\u003e\n  \u003c/MidiDeviceProvider\u003e,\n  appElement\n);\n```\n\nThen... expose `midi`, `setMidiInput`, and `setMidiOutput` to your components using `withMidi(Component)`;\n\n### Examples:\n\n#### MidiDeviceSwitcher\n```javascript\nimport React, { PureComponent } from 'react';\nimport PropTypes from 'prop-types';\nimport { withMidi } from 'react-midi-device-provider';\n\nclass MidiDeviceSwitcher extends PureComponent {\n  constructor() {\n    super();\n\n    this.handleInputChange = this.handleInputChange.bind(this);\n    this.handleOutputChange = this.handleOutputChange.bind(this);\n  }\n\n  static propTypes = {\n    midi: PropTypes.object,\n    setMidiInput: PropTypes.func,\n    setMidiOutput: PropTypes.func\n  }\n\n  handleInputChange(e) {\n    const { setMidiInput } = this.props;\n    setMidiInput(e.target.value);\n  }\n\n  handleOutputChange(e) {\n    const { setMidiOutput } = this.props;\n    setMidiOutput(e.target.value);\n  }\n\n  render() {\n    const {\n      inputs,\n      outputs,\n      selectedInput,\n      selectedOutput\n    } = this.props.midi;\n    return (\n      \u003cdiv\u003e\n        \u003cdiv\u003e\n          \u003ch3\u003eInputs\u003c/h3\u003e\n          \u003cselect onChange={this.handleInputChange}\u003e\n            {inputs.map(i =\u003e \u003coption key={i.id} value={i.id}\u003e{i.name}\u003c/option\u003e)}\n          \u003c/select\u003e\n          \u003cspan\u003e{selectedInput \u0026\u0026 ` - ${selectedInput.name}`}\u003c/span\u003e\n        \u003c/div\u003e\n        \u003cdiv\u003e\n          \u003ch3\u003eOutputs\u003c/h3\u003e\n          \u003cselect onChange={this.handleOutputChange}\u003e\n            {outputs.map(o =\u003e \u003coption key={o.id} value={o.id}\u003e{o.name}\u003c/option\u003e)}\n          \u003c/select\u003e\n          \u003cspan\u003e{selectedOutput \u0026\u0026 ` - ${selectedOutput.name}`}\u003c/span\u003e\n        \u003c/div\u003e\n      \u003c/div\u003e\n    );\n  }\n}\n\nexport default withMidi(MidiDeviceSwitcher);\n```\n\n#### MidiParamSlider\n```javascript\nimport React, { PureComponent } from 'react';\nimport PropTypes from 'prop-types';\nimport { withMidi } from 'react-midi-device-provider';\n\nclass MidiParamSlider extends PureComponent {\n  constructor() {\n    super();\n\n    this.handleChange = this.handleChange.bind(this);\n  }\n\n  static propTypes = {\n    channel: PropTypes.number,\n    max: PropTypes.number,\n    min: PropTypes.number,\n    midi: PropTypes.object.isRequired\n  }\n\n  static defaultProps = {\n    channel: 0x10,\n    max: 127,\n    min: 0\n  }\n\n  handleChange(e) {\n    const { channel, midi } = this.props;\n    const { selectedOutput } = midi;\n    if (selectedOutput \u0026\u0026 typeof selectedOutput.send === 'function') {\n      selectedOutput.send([0xb0, channel, Math.floor(e.target.value)]);\n    }\n  }\n\n  render() {\n    const { max, min } = this.props;\n    return (\n      \u003cdiv\u003e\n        \u003cinput\n          type=\"range\"\n          max={max}\n          min={min}\n          onChange={this.handleChange}\n        /\u003e\n      \u003c/div\u003e\n    );\n  }\n}\n\nexport default withMidi(MidiParamSlider);\n```\n\n[npm-badge]: https://img.shields.io/npm/v/react-midi-device-provider.svg\n[npm-badge-url]: https://www.npmjs.com/package/react-midi-device-provider\n[travis-badge]: https://travis-ci.org/halvves/react-midi-device-provider.svg?branch=master\n[travis-badge-url]: https://travis-ci.org/halvves/react-midi-device-provider\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhalvves%2Freact-midi-device-provider","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhalvves%2Freact-midi-device-provider","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhalvves%2Freact-midi-device-provider/lists"}