{"id":20630459,"url":"https://github.com/mkj-is/combinemidi","last_synced_at":"2025-04-15T18:19:59.910Z","repository":{"id":43055331,"uuid":"257858348","full_name":"mkj-is/CombineMIDI","owner":"mkj-is","description":"Connect MIDI using async-await to SwiftUI (or UIKit)","archived":false,"fork":false,"pushed_at":"2022-01-26T15:48:27.000Z","size":70,"stargazers_count":67,"open_issues_count":3,"forks_count":6,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-15T18:19:55.864Z","etag":null,"topics":["async-await","asyncstream","combine","midi","swift","swift-concurrency","swiftui"],"latest_commit_sha":null,"homepage":"https://youtu.be/2jTtqoYwQF0","language":"Swift","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/mkj-is.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":".github/CODEOWNERS","security":null,"support":null}},"created_at":"2020-04-22T09:47:34.000Z","updated_at":"2025-02-23T00:26:05.000Z","dependencies_parsed_at":"2022-09-24T05:40:56.598Z","dependency_job_id":null,"html_url":"https://github.com/mkj-is/CombineMIDI","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkj-is%2FCombineMIDI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkj-is%2FCombineMIDI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkj-is%2FCombineMIDI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkj-is%2FCombineMIDI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mkj-is","download_url":"https://codeload.github.com/mkj-is/CombineMIDI/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249126054,"owners_count":21216715,"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":["async-await","asyncstream","combine","midi","swift","swift-concurrency","swiftui"],"created_at":"2024-11-16T14:07:55.671Z","updated_at":"2025-04-15T18:19:59.884Z","avatar_url":"https://github.com/mkj-is.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CombineMIDI\n\n![Build](https://github.com/mkj-is/CombineMIDI/workflows/Build/badge.svg)\n\nSwift package made for easy connection of MIDI controllers to SwiftUI\n(or UIKit) using Combine and async-await.\n\nThis package was created as a part of [UIKonf 2020](https://uikonf.com)\ntalk **Combine: Connect MIDI signals to SwiftUI**.\nIt's main goal is to read messages from all MIDI sources\nand to be able to present these values in the user interface.\n\nFor more guidance, demos and history see materials for the talk:\n\n- [Video](https://youtu.be/2jTtqoYwQF0)\n- [Slides](https://speakerdeck.com/mkj/combine-connect-midi-signals-to-swiftui)\n- [Proposal](Proposal.md)\n\n## Installation\n\nAdd this package to your Xcode project or add following line\nto your `Package.swift` file:\n\n```swift\n.package(url: \"https://github.com/mkj-is/CombineMIDI.git\", from: \"0.3.0\")\n```\n\n## Features\n\n- Supports macOS 10.15+ and iOS 13.0+.\n- Type-safe wrapper for MIDI messages (events).\n- Wrapper for the C-style MIDI client in CoreMIDI.\n- Combine Publisher for listening to MIDI messages.\n- MIDI AsyncStream for processing MIDI messages.\n\n## Usage\n\nFirst you need to create a MIDI client, it should be sufficient to create\nonly one client per app\n(you can optionally pass name of the client as the initializer parameter):\n\n```swift\nlet client = MIDIClient(name: \"My app MIDI client\")\n```\n\n### Async-await\n\nThe first thing you probably want to do is to filter the messages\nwhich are relevant to you and get the values.\n\n```swift\nlet stream = client.stream\n    .filter { $0.status == .controlChange }\n    .compactMap(\\.data2)\n```\n\nThe you can process messages in a simple for-loop.\n*The loop will be running indefinitely until the task\nenclosing it will be cancelled.*\n\n```\nfor await message in stream {\n    ...\n}\n```\n\n### Combine\n\nWhen using Combine, you create a publisher and it automatically connects\nto all sources and listens to all messages on subscribtion.\n\n*Do not forget to receive those events on the main thread when subscribing\non the user interface. To prevent dispatching too soon the publisher is\nemitting on the thread used by CoreMIDI, so you can quickly filter all\nthe messages.*\n\n```swift\ncancellable = client\n    .publisher()\n    .filter { $0.status == .controlChange }\n    .compactMap(\\.data2)\n    .receive(on: RunLoop.main)\n    .sink { value in\n        ...\n    }\n```\n\n## Next steps\n\nThis library is small on purpose and there is a large potential for improvement:\n\n- [ ] New MIDI controllers are not detected when the subscription was already made.\n- [ ] All MIDI sources are connected during the first subscription,\n      there is currently no way to select a particular device.\n- [ ] Sending messages back to other destinations using the client is not possible.\n\n## Contributing\n\nAll contributions are welcome.\n\nProject was created by [Matěj Kašpar Jirásek](https://twitter.com/mkj_is).\n\nProject is licensed under [MIT license](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkj-is%2Fcombinemidi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmkj-is%2Fcombinemidi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkj-is%2Fcombinemidi/lists"}