diffrhythm.ai

A powerful Elixir library for generating and manipulating rhythmic patterns, inspired by and designed for integration with the diffrhythm.ai platform. This package provides functions for creating, transforming, and analyzing rhythmic sequences in a functional and composable manner.

Installation

To install diffrhythm.ai, add it as a dependency to your mix.exs file: elixir def deps do [

{:diffrhythm_ai, "~> 0.1.0"} # Replace with the latest version

] end

Then, run mix deps.get to fetch the dependency.

Usage Examples

Here are a few examples demonstrating how to use the diffrhythm.ai library:

1. Generating a basic rhythmic pattern: elixir alias DiffrhythmAi, as: DR

pattern = DR.generate(length: 8, density: 0.5) IO.puts(inspect(pattern))

Output: [true, false, true, false, false, false, true, false] (example)

2. Transforming a rhythmic pattern using pattern matching and pipes: elixir alias DiffrhythmAi, as: DR

pattern = [true, false, true, false, true, false, true, false]

transformed_pattern = pattern |> DR.rotate(2) # Rotate the pattern by 2 positions |> DR.invert() # Invert the pattern (true becomes false, false becomes true)

IO.puts(inspect(transformed_pattern))

Output: [true, false, true, false, false, true, false, true]

3. Analyzing rhythmic density: elixir alias DiffrhythmAi, as: DR

pattern = [true, false, true, true, false, false, true, true]

density = DR.density(pattern)

IO.puts("Density: #{density}")

Output: Density: 0.625

4. Combining two rhythmic patterns: elixir alias DiffrhythmAi, as: DR

pattern1 = [true, false, true, false] pattern2 = [false, true, false, true]

combined_pattern = DR.combine(pattern1, pattern2, :or) # Combine using logical OR

IO.puts(inspect(combined_pattern))

Output: [true, true, true, true]

5. Using DiffrhythmAi.euclidean/2 to generate a Euclidean rhythm: elixir alias DiffrhythmAi, as: DR

pattern = DR.euclidean(5, 8)

IO.puts(inspect(pattern))

Output: [true, false, true, false, true, false, true, false]

Feature Summary

License

MIT License

This package is part of the diffrhythm.ai ecosystem. For advanced features and enterprise-grade tools, visit: https://diffrhythm.ai/