{"id":18057619,"url":"https://github.com/bring-shrubbery/polyrhythm","last_synced_at":"2025-04-11T04:41:44.207Z","repository":{"id":57307198,"uuid":"448773700","full_name":"bring-shrubbery/polyrhythm","owner":"bring-shrubbery","description":"Polyrhythm generation algorithm written in every language I need.","archived":false,"fork":false,"pushed_at":"2022-04-09T18:27:39.000Z","size":25,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-03T19:40:20.661Z","etag":null,"topics":["polyrhythm","rust","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bring-shrubbery.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["bring-shrubbery"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2022-01-17T06:08:42.000Z","updated_at":"2023-03-07T13:41:11.000Z","dependencies_parsed_at":"2022-09-06T19:21:14.276Z","dependency_job_id":null,"html_url":"https://github.com/bring-shrubbery/polyrhythm","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/bring-shrubbery%2Fpolyrhythm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bring-shrubbery%2Fpolyrhythm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bring-shrubbery%2Fpolyrhythm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bring-shrubbery%2Fpolyrhythm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bring-shrubbery","download_url":"https://codeload.github.com/bring-shrubbery/polyrhythm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248345276,"owners_count":21088242,"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":["polyrhythm","rust","swift"],"created_at":"2024-10-31T02:08:25.378Z","updated_at":"2025-04-11T04:41:44.186Z","avatar_url":"https://github.com/bring-shrubbery.png","language":"Swift","funding_links":["https://github.com/sponsors/bring-shrubbery"],"categories":[],"sub_categories":[],"readme":"# Polyrhythm\n\nPolyrhythm generation algorithm written in every language I need.\n\n## Motivation\n\n- [rythmic (App Store)](https://apps.apple.com/app/rythmic/id1515876711)\n\n## Algorithm\n\nComponents of the polyrhythms:\n\n- `N` number of simultaneous rhythms with each having:\n  - It's own `T_i` tempo.\n  - It's own number of beats per measure (time signature).\n- A way to measure time. In this case we use two (based on preference):\n  - Sample time based - returns specific integer that represents the sample time, given sample rate.\n  - Index based - one index step is the smallest step between beats. This is effectively just sample rate approach, with sample rate set to 1.\n\nBelow you can see the pseudocode for the algorithm in Python.\n\n```python\n# Pseudocode, does not actually run.\ndef getPolyrhythm(beats: int[]) -\u003e int[][]:\n  if len(config.beats) \u003c= 1: throw \"Need to have some beats\"\n\n  LCM = least_common_multiple(config.beats) # least common multiple (LCM) of all the beats\n\n  samples = []\n  for beat in config.beats:\n    # Find the index at which the beat will occur.\n    divisible_index = LCM / beat\n    beat_times = [1 if index % divisible_index == 0 else 0 for index in [0]*LCM]\n    samples.append(beat_times)\n\n  return samples\n  # Samples now look like this for beats=[2, 3]:\n  # [\n  #   [1, 0, 0, 1, 0, 0],\n  #   [1, 0, 1, 0, 1, 0]\n  # ]\n\ndef getPolyrhythmSampleTimes(samples: int[][], bpm: float, sample_rate: float): -\u003e float[][]:\n  pass\n  # TODO: Finish the func\n  # 1. Normalize samples values\n  # 2. Multiply by sample time\n```\n\n```bash\n$ python main.py -b 2,3\n\n[1, 0, 0, 1, 0, 0]\n[1, 0, 1, 0, 1, 0]\n```\n\n## Installation\n\n### Swift\n\nAdd following URL to Swift Package Manager in Xcode:\n\n```\nhttps://github.com/bring-shrubbery/polyrhythm/tree/main/polyrhythm-rust\n```\n\n### Rust\n\nAdd polyrhythm crate to your `Cargo.toml` file:\n\n```toml\npolyrhythm = \"x.x.x\"\n```\n\n## License\n\n[Mozilla Public License 2.0](https://github.com/bring-shrubbery/polyrhythm/blob/main/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbring-shrubbery%2Fpolyrhythm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbring-shrubbery%2Fpolyrhythm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbring-shrubbery%2Fpolyrhythm/lists"}