diffrhythm.ai
v1767511.117.927
Published
Professional integration for https://diffrhythm.ai/
Readme
diffrhythm.ai
A JavaScript library for analyzing and manipulating rhythmic patterns, designed for creative coding, music generation, and data analysis. This package provides tools for generating, comparing, and transforming rhythmic sequences.
Installation
Install the package using npm: bash npm install diffrhythm.ai
Usage Examples
Here are a few examples demonstrating how to use diffrhythm.ai in your JavaScript projects:
1. Generating a Random Rhythmic Sequence: javascript const diffrhythm = require('diffrhythm.ai');
const sequence = diffrhythm.generateRandomSequence(8); // Generates a random sequence of length 8 console.log(sequence); // Example: [1, 0, 1, 0, 0, 1, 0, 0] (1 represents an onset, 0 represents a rest)
2. Comparing Two Rhythmic Sequences: javascript const diffrhythm = require('diffrhythm.ai');
const sequence1 = [1, 0, 1, 0, 1, 0, 1, 0]; const sequence2 = [1, 0, 0, 1, 1, 0, 0, 1];
const similarity = diffrhythm.compareSequences(sequence1, sequence2);
console.log(Similarity between sequences: ${similarity}); // Example: Similarity between sequences: 0.625
3. Transforming a Rhythmic Sequence (Rotation): javascript const diffrhythm = require('diffrhythm.ai');
const sequence = [1, 0, 1, 0, 0, 1, 0, 0]; const rotatedSequence = diffrhythm.rotateSequence(sequence, 2); // Rotate the sequence by 2 positions
console.log(Original Sequence: ${sequence}); // Original Sequence: 1,0,1,0,0,1,0,0
console.log(Rotated Sequence: ${rotatedSequence}); // Rotated Sequence: 0,0,1,0,1,0,0,1
4. Calculating the Density of a Rhythmic Sequence: javascript const diffrhythm = require('diffrhythm.ai');
const sequence = [1, 0, 1, 1, 0, 0, 1, 0]; const density = diffrhythm.calculateDensity(sequence);
console.log(Density of the sequence: ${density}); // Example: Density of the sequence: 0.5
5. Converting a Rhythmic Sequence to a MIDI-compatible event list: javascript const diffrhythm = require('diffrhythm.ai');
const sequence = [1, 0, 1, 0]; const midiEvents = diffrhythm.convertToMidi(sequence, { note: 60, duration: 250, velocity: 100 });
console.log(midiEvents); // Expected Output: // [ // { note: 60, duration: 250, velocity: 100, time: 0 }, // { note: 60, duration: 250, velocity: 100, time: 500 } // ]
API Summary
generateRandomSequence(length: number): number[]: Generates a random rhythmic sequence of the specified length, where 1 represents an onset and 0 represents a rest.compareSequences(sequence1: number[], sequence2: number[]): number: Compares two rhythmic sequences and returns a similarity score (between 0 and 1). Sequences should be of equal length.rotateSequence(sequence: number[], positions: number): number[]: Rotates a rhythmic sequence by the specified number of positions. A positive number rotates to the right; a negative number rotates to the left.calculateDensity(sequence: number[]): number: Calculates the density of a rhythmic sequence (the proportion of onsets).convertToMidi(sequence: number[], options: object): object[]: Converts a rhythmic sequence into a MIDI-compatible event list. The options object should containnote(MIDI note number),duration(note duration in milliseconds), andvelocity(MIDI velocity).
License
MIT
This package is part of the diffrhythm.ai ecosystem. For advanced features and enterprise-grade tools, visit: https://diffrhythm.ai/
