Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bring-shrubbery/polyrhythm
Polyrhythm generation algorithm written in every language I need.
https://github.com/bring-shrubbery/polyrhythm
polyrhythm rust swift
Last synced: 13 days ago
JSON representation
Polyrhythm generation algorithm written in every language I need.
- Host: GitHub
- URL: https://github.com/bring-shrubbery/polyrhythm
- Owner: bring-shrubbery
- License: mpl-2.0
- Created: 2022-01-17T06:08:42.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-04-09T18:27:39.000Z (over 2 years ago)
- Last Synced: 2024-10-07T01:18:49.547Z (about 1 month ago)
- Topics: polyrhythm, rust, swift
- Language: Swift
- Homepage:
- Size: 24.4 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Polyrhythm
Polyrhythm generation algorithm written in every language I need.
## Motivation
- [rythmic (App Store)](https://apps.apple.com/app/rythmic/id1515876711)
## Algorithm
Components of the polyrhythms:
- `N` number of simultaneous rhythms with each having:
- It's own `T_i` tempo.
- It's own number of beats per measure (time signature).
- A way to measure time. In this case we use two (based on preference):
- Sample time based - returns specific integer that represents the sample time, given sample rate.
- Index based - one index step is the smallest step between beats. This is effectively just sample rate approach, with sample rate set to 1.Below you can see the pseudocode for the algorithm in Python.
```python
# Pseudocode, does not actually run.
def getPolyrhythm(beats: int[]) -> int[][]:
if len(config.beats) <= 1: throw "Need to have some beats"LCM = least_common_multiple(config.beats) # least common multiple (LCM) of all the beats
samples = []
for beat in config.beats:
# Find the index at which the beat will occur.
divisible_index = LCM / beat
beat_times = [1 if index % divisible_index == 0 else 0 for index in [0]*LCM]
samples.append(beat_times)return samples
# Samples now look like this for beats=[2, 3]:
# [
# [1, 0, 0, 1, 0, 0],
# [1, 0, 1, 0, 1, 0]
# ]def getPolyrhythmSampleTimes(samples: int[][], bpm: float, sample_rate: float): -> float[][]:
pass
# TODO: Finish the func
# 1. Normalize samples values
# 2. Multiply by sample time
``````bash
$ python main.py -b 2,3[1, 0, 0, 1, 0, 0]
[1, 0, 1, 0, 1, 0]
```## Installation
### Swift
Add following URL to Swift Package Manager in Xcode:
```
https://github.com/bring-shrubbery/polyrhythm/tree/main/polyrhythm-rust
```### Rust
Add polyrhythm crate to your `Cargo.toml` file:
```toml
polyrhythm = "x.x.x"
```## License
[Mozilla Public License 2.0](https://github.com/bring-shrubbery/polyrhythm/blob/main/LICENSE)