Giter Site home page Giter Site logo

polyrhythm's Introduction

Polyrhythm

Polyrhythm generation algorithm written in every language I need.

Motivation

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.

# 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
$ 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:

polyrhythm = "x.x.x"

License

Mozilla Public License 2.0

polyrhythm's People

Contributors

bring-shrubbery avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.