### Chord Notation in Lua Source: https://github.com/renoise/pattrns/blob/master/docs/src/quickstart.md Demonstrates using chord notation shortcuts in Lua to define musical chords within a pattern. It shows examples for major, minor, and dominant 7th chords, and suggests trying other modes and inversions. ```lua -- Using chord notation shortcuts return pattern { unit = "1/1", event = { "c4'M", -- C major using ' chord notation "d4'm", -- D minor "g4'dom7" -- G dominant 7th } } ``` -------------------------------- ### Probability-Based Emitting in Lua Source: https://github.com/renoise/pattrns/blob/master/docs/src/quickstart.md Shows how to emit notes with a specific probability using a Lua function and a gate in pattrns. It provides an example of a 30% chance to emit a note and suggests varying probability based on step position or downbeats. ```lua -- Emit notes with certain probability return pattern { unit = "1/8", pulse = {1, 1, 1, 1}, -- Regular pattern event = function(context) if math.random() < 0.3 then -- 30% chance to emit return "c4" end end } ``` -------------------------------- ### Working with Scales and Chords in Lua Source: https://github.com/renoise/pattrns/blob/master/docs/src/quickstart.md Illustrates how to work with scales and generate chords from scale degrees using Lua. It shows creating chords from named scales and custom intervals, and deriving chords from scale degrees. ```lua -- Advanced chord and scale operations return pattern { unit = "1/1", event = { chord("c4", "major"), -- C major via the chord function chord("c4", {0, 4, 7}), -- C major via custom intervals scale("c", "major"):chord(1), -- C major from 1st degree of C major scale scale("c", "major"):chord(5) -- G major from 5th degree of C major scale } } ``` -------------------------------- ### Create Triplet Feel Rhythm in Lua Source: https://github.com/renoise/pattrns/blob/master/docs/src/quickstart.md Enables triplet feels, swing rhythms, and polyrhythms by adjusting the 'resolution' parameter. This example sets a triplet feel (3 notes in the space of 2) and applies it to a sequence of notes with volume variations. ```lua -- Create swing or triplet feel return pattern { unit = "1/8", resolution = 2/3, -- Triplet feel (3 notes in space of 2) event = {"c4 v0.3", "e4 v0.5", "g4 v0.8"} -- v specifies volume, d delay, p panning } ``` -------------------------------- ### Modify Note Properties in Lua Source: https://github.com/renoise/pattrns/blob/master/docs/src/quickstart.md Demonstrates how to modify individual note events with properties like volume, panning, delay, and instrument. This allows for more nuanced control over note playback within a pattern. ```lua return pattern { unit = "1/8", event = { "c4 v0.2", "off d0.5", "g4 v0.8" } } ``` -------------------------------- ### Create Basic Note Stacks (Chords) in Lua Source: https://github.com/renoise/pattrns/blob/master/docs/src/quickstart.md Generates chords by providing a table of notes as the 'event' parameter. This allows multiple notes to be played simultaneously on a single pattern step. The example creates a C major chord followed by a single C4. ```lua -- Simple chord by stacking notes return pattern { unit = "1/1", event = {{"c4", "e4", "g4"}, "c4"} -- C major chord followed by a single C4 } ``` -------------------------------- ### Generative Melody with Constraints in Lua Source: https://github.com/renoise/pattrns/blob/master/docs/src/quickstart.md Creates melodies that adhere to musical rules, such as preferring smaller intervals for smoother transitions. This example generates melodies using a pentatonic scale, with logic to favor steps of 1 or 2 scale degrees. ```lua -- Create melodies that follow musical rules return pattern { unit = "1/8", event = function(init_context) local pentatonic = scale("c4", "pentatonic minor").notes local last_note = 1 return function(context) local next_note = math.random(#pentatonic) -- Prefer steps of 1 or 2 scale degrees (smoother melodies) while math.abs(next_note - last_note) > 2 do next_note = math.random(#pentatonic) end last_note = next_note return pentatonic[next_note] end end } ``` -------------------------------- ### Random Note Selection in Lua Source: https://github.com/renoise/pattrns/blob/master/docs/src/quickstart.md Demonstrates how to dynamically select random notes from a list using a Lua function within a pattrns pattern. It suggests using notes from a scale and adding amplitude variation. ```lua -- Randomly select notes from a list local notes = {"c4", "d4", "e4", "g4"} return pattern { unit = "1/8", event = function(context) return notes[math.random(#notes)] -- Pick random note from array end } ``` -------------------------------- ### Install simple-http-server with Cargo Source: https://github.com/renoise/pattrns/blob/master/examples/playground/README.md This snippet demonstrates how to install the `simple-http-server` utility using Cargo, a package manager for Rust. This is a prerequisite for running the pattrns playground demo. ```bash cargo [b]install simple-http-server ``` -------------------------------- ### Run Rust Live Coding Example with Cargo Source: https://github.com/renoise/pattrns/blob/master/examples/README.md Compiles and runs the 'play-script.rs' Rust example, which utilizes the pattrns Lua API for live music coding. Requires Rust toolchain and specific features enabled. ```bash cargo run --release --example=play-script --features=player,cpal-output ``` -------------------------------- ### Run Rust Example with Cargo Source: https://github.com/renoise/pattrns/blob/master/examples/README.md Compiles and runs the 'play.rs' Rust example using the pattrns Rust library. Requires Rust toolchain and specific features enabled. ```bash cargo run --release --example=play --features=player,cpal-output ``` -------------------------------- ### Alternating Cycles in Tidal Cycles Lua Source: https://github.com/renoise/pattrns/blob/master/docs/src/quickstart.md Explains and demonstrates how to use the pipe symbol `|` within Tidal Cycles mini-notation in Lua to randomly select between different patterns or chords. It provides an example of switching between two chords. ```lua -- Switching between different patterns return pattern { unit = "1/4", event = cycle("[c4 e4 g4]|[d4 f4 a4]") -- Randomly select one of two chords } ``` -------------------------------- ### Stateful Arpeggiator in Lua Source: https://github.com/renoise/pattrns/blob/master/docs/src/quickstart.md Illustrates creating stateful emitters in Lua for pattrns, enabling patterns that remember their previous state, such as an arpeggiator. It shows cycling through a list of notes and suggests adding direction changes or generating notes from a scale. ```lua -- Create patterns that remember previous states return pattern { unit = "1/8", event = function(init_context) local notes = {"c4", "e4", "g4", "b4"} local index = 1 return function(context) local note = notes[index] index = math.imod(index + 1, #notes) -- Cycle through notes return note end end } ``` -------------------------------- ### Create Euclidean Rhythms in Lua Source: https://github.com/renoise/pattrns/blob/master/docs/src/quickstart.md Distributes notes evenly across a specified number of steps using the `pulse.euclidean()` function. This is common in various music traditions and allows for the creation of naturally pleasing rhythmic patterns. The example distributes 3 hits over 8 steps. ```lua -- Distributes notes evenly across steps (common in many music traditions) return pattern { unit = "1/16", pulse = pulse.euclidean(3, 8), -- 3 hits spread over 8 steps event = "c4" -- Basic note } ``` -------------------------------- ### Dynamic Cycles in Lua Source: https://github.com/renoise/pattrns/blob/master/docs/src/quickstart.md Dynamically maps identifiers within cycles to different musical elements, such as chords based on scale degrees. This example demonstrates creating chord progressions by mapping Roman numeral identifiers to actual chords from a specified scale. ```lua -- Identifiers in cycles can be dynamically mapped to something else local s = scale("C4", "minor") return pattern { unit = "1/4", event = cycle("I III V VII"):map(function(context, value) -- value here is a single roman number from the cycle above local degree = value -- apply value as roman number chord degree return s:chord(degree) end) } ``` -------------------------------- ### Euclidean Rhythms in Tidal Cycles Lua Source: https://github.com/renoise/pattrns/blob/master/docs/src/quickstart.md Illustrates the use of Euclidean rhythm notation within Tidal Cycles mini-notation in Lua. It shows how to specify the number of notes, steps, and an optional offset to create specific rhythmic distributions. ```lua -- Euclidean patterns in tidal cycles notation return cycle("c4(3,8) e4(5,8) g4(7,8)") -- Different Euclidean rhythms ``` -------------------------------- ### Create Basic Quarter Note Pulse in Lua Source: https://github.com/renoise/pattrns/blob/master/docs/src/quickstart.md Generates a steady quarter note rhythm playing a specified note. It uses the 'unit' to set the timing grid and 'event' to define the note to play. This is the most fundamental pattern. ```lua -- The most basic rhythm: steady quarter notes return pattern { unit = "1/4", -- Quarter note timing grid event = "c4" -- Play middle C on each pulse } ``` -------------------------------- ### Basic Tidal Cycles Notation in Lua Source: https://github.com/renoise/pattrns/blob/master/docs/src/quickstart.md Shows the basic usage of Tidal Cycles' mini-notation in Lua for creating concise musical patterns, specifically an arpeggio. It demonstrates defining a pattern that emits a cycle every beat. ```lua -- Using tidal cycles notation for concise patterns return pattern { unit = "1/4", -- Emit a cycle every beat event = cycle("c4 e4 g4") -- C major arpeggio } ``` ```lua -- The simplified notation emits a cycle **per bar** return cycle("c4 e4 g4") ``` -------------------------------- ### Run pattrns playground demo with Bash Source: https://github.com/renoise/pattrns/blob/master/examples/playground/README.md This snippet shows the command to serve the pattrns playground demo locally using a simple HTTP server. It assumes the demo has been built and a server like `simple-http-server` is installed. ```bash ./serve.sh ``` -------------------------------- ### Create Subdivided Pulses Rhythm in Lua Source: https://github.com/renoise/pattrns/blob/master/docs/src/quickstart.md Generates complex rhythms by using nested arrays within the 'pulse' parameter, allowing for subdivisions of the main timing unit. This example shows a quarter note followed by four sixteenth notes. ```lua -- Pattern with mixed note lengths return pattern { unit = "1/4", pulse = {1, {1, 1, 1, 1}}, -- One quarter note, then four sixteenth notes event = {"c4", "c5", "e4", "g4", "d4"} -- c4 (quarter), c5, e4, g4, d4 (sixteenth notes) } ``` -------------------------------- ### Install mdBook and Plugins Source: https://github.com/renoise/pattrns/blob/master/docs/README.md Installs the mdBook documentation generator and several useful plugins (mdbook-linkcheck, mdbook-toc, mdbook-alerts) using Cargo, Rust's package manager. This is a prerequisite for building and serving the documentation locally. ```shell cargo install mdbook mdbook-linkcheck mdbook-toc mdbook-alerts ``` -------------------------------- ### Build pattrns playground demo with Bash Source: https://github.com/renoise/pattrns/blob/master/examples/playground/README.md This snippet shows the command to build the pattrns playground demo using the provided build script. It assumes prerequisites like Emscripten SDK and Rust targets are already installed. ```bash ./build.sh ``` -------------------------------- ### Advanced Cycle Pattern Examples (Lua) Source: https://github.com/renoise/pattrns/blob/master/docs/src/guide/cycles.md Provides examples of advanced cycle pattern usage, including chord progressions, polyrhythms, alternate panning with note attributes, and mapped multi-channel beats using Lua. ```lua return cycle("[c'M g'M a'm f'M]/4") ``` ```lua return cycle("[C3 D#4 F3 G#4], [[D#3?0.2 G4 F4]/64]*63") ``` ```lua cycle("c4:") ``` ```lua return cycle([=[ [

*12], [kd ~]*2 ~ [~ kd] ~, [~ s1]*2, [~ s2]*8 ]=]):map({ kd = "c4 #0", -- Kick s1 = "c4 #1", -- Snare s2 = "c4 #1 v0.1", -- Ghost snare h1 = "c4 #2", -- Hat h2 = "c4 #2 v0.2" -- Hat }) ``` -------------------------------- ### Create Alternating Notes Pattern in Lua Source: https://github.com/renoise/pattrns/blob/master/docs/src/quickstart.md Creates a rhythmic pattern that alternates between playing and resting, and cycles through a list of notes. The 'pulse' array controls the play/rest sequence, and 'event' provides the notes to cycle through. ```lua -- Create a pattern that alternates between notes return pattern { unit = "1/8", -- Eighth note timing grid pulse = {1, 0, 1, 1}, -- Play-rest-play-play pattern event = {"c4", "d4"} -- Alternates between C4 and D4 } ``` -------------------------------- ### Lua PatternOptions Examples Source: https://github.com/renoise/pattrns/blob/master/docs/src/API/pattern.md Illustrates how to configure pattern timing and resolution using the PatternOptions. Examples show setting a slightly off-beat pulse using 'beats' as the unit and a resolution factor, and creating a triplet rhythm using '1/16' as the unit with a specific resolution. ```lua -- slightly off beat pulse unit = "beats", resolution = 1.01 ``` ```lua -- triplet unit = "1/16", resolution = 2/3 ``` ```lua -- slightly off beat pulse unit = "beats", resolution = 1.01 ``` ```lua -- triplet unit = "1/16", resolution = 2/3 ``` ```lua -- start emitting after 4*4 beats unit = "1/4", resolution = 4, offset = 4 ``` -------------------------------- ### Create Chord Sequence Pattern Source: https://github.com/renoise/pattrns/blob/master/docs/src/API/pattern.md This example shows how to create a pattern that triggers a chord sequence every few bars, with an initial offset. It defines the unit, resolution, offset, and the chord events. ```lua return pattern { unit = "bars", resolution = 4, offset = 1, event = { note("c4'm"), note("g3'm7"):transpose({ 0, 12, 0, 0 }) } } ``` -------------------------------- ### Conditional Gate in Lua Source: https://github.com/renoise/pattrns/blob/master/docs/src/quickstart.md Filters which notes are played based on gate conditions. It can use probability values or specific context triggers to decide whether a note should sound. This allows for dynamic and rule-based note filtering in patterns. ```lua -- Filter which notes actually play using gates return pattern { unit = "1/8", pulse = {1, 0.1, 1, 0.5, 1, 0.2, 1, 0.1}, -- probability values gate = function(context) -- always play on even-numbered step values return (context.pulse_step - 1) % 2 == 0 or -- else use pulse values as probablities context.pulse_value >= math.random() end, event = "c4" } ``` -------------------------------- ### Add rust-src component for Cargo build-std Source: https://github.com/renoise/pattrns/blob/master/examples/playground/README.md This command adds the `rust-src` component to your Rust installation, which is required by `cargo build-std`. This is often needed for compiling with features like pthread support. ```bash rustup component add rust-src ``` -------------------------------- ### Create Euclidean Triplet Pattern with Notes Source: https://github.com/renoise/pattrns/blob/master/docs/src/API/pattern.md This example demonstrates creating a pattern that triggers notes in an Euclidean triplet rhythm. It specifies the unit, resolution, pulse, and event sequence. ```lua return pattern { unit = "1/16", resolution = 2/3, pulse = pulse.euclidean(12, 16), event = { "c4", "g4", { "c5 v0.7", "g5 v0.4" }, "a#4" } } ``` -------------------------------- ### Euclidean Pattern Generator with Configurable Parameters in Lua Source: https://github.com/renoise/pattrns/blob/master/docs/src/guide/parameters.md A Lua example of a Euclidean pattern generator. It uses integer parameters for 'steps', 'pulses', and 'offset' to control the pattern's behavior. The parameters are defined with ranges and descriptions. ```lua return pattern { parameter = { parameter.integer('steps', 12, {1, 64}, "Steps", "Number of on steps in the pattern"), parameter.integer('pulses', 16, {1, 64}, "Pulses", "Total number of on & off pulses"), parameter.integer('offset', 0, {-16, 16}, "Offset", "Rotates on pattern left (values > 0) or right (values < 0)"), }, unit = "1/1", pulse = function(context) return pulse.euclidean( math.min(context.parameter.steps, context.parameter.pulses), context.parameter.pulses, context.parameter.offset) end, event = "c4" } ``` -------------------------------- ### Drum Pattern Cycle with Configurable Note Parameters in Lua Source: https://github.com/renoise/pattrns/blob/master/docs/src/guide/parameters.md A Lua example for a drum pattern cycle that allows configuration of note values for different drum instruments (kick, snare, hi-hat) using integer parameters. The 'event' function maps pattern elements to specific notes and volumes. ```lua return pattern { unit = "1/1", parameter = { parameter.integer("bd_note", 48, {0, 127}), parameter.integer("sn_note", 70, {0, 127}), parameter.integer("hh_note", 98, {0, 127}) }, event = cycle([[ [*12], [bd1 ~]*2 ~ [~ bd2] ~, [~ sn1]*2, [~ sn2]*8 ]]):map(function(context, value) for _, id in pairs{"bd", "sn", "hh"} do local number = value:match(id.."(%d+)") if number then return note(context.inputs[id.."_note"]):volume( number == "2" and 0.2 or 1.0) end end end) } ``` -------------------------------- ### Create Tidal Cycle Pattern Source: https://github.com/renoise/pattrns/blob/master/docs/src/API/pattern.md This example shows how to create a pattern that emits a tidal cycle every bar. It defines the unit as 'bars' and uses the 'cycle' function to specify the tidal pattern. ```lua return pattern { unit = "bars", event = cycle("[c4 [f5 f4]*2]|[c4 [g5 g4]*3]") } ``` -------------------------------- ### Define Chord Event using sequence() in Lua Source: https://github.com/renoise/pattrns/blob/master/docs/src/guide/event.md Defines a chord event using the `sequence()` helper function for clarity. This example also shows how to specify rests or note-offs within the chord. ```lua return pattern { event = sequence( { "c4", "d#4", "g4" }, { "---", "off", "off" } ) } ``` -------------------------------- ### Seed Random Number Generator for Reproducible Melodies Source: https://github.com/renoise/pattrns/blob/master/docs/src/extras/randomization.md This example shows how to seed the global random number generator using `math.randomseed()` to ensure that the sequence of random notes generated is the same every time the pattern is executed. It uses the `scale` and `pulse.new` functions. ```lua -- create a scale to pick notes from local cmin = scale("c", "minor") -- pick the same random 10 notes from the scale every time math.randomseed(1234) local random_notes = pulse.new(10, function() return cmin.notes[math.random(#cmin.notes)] end) return pattern { event = random_notes } ``` -------------------------------- ### Add wasm32-unknown-emscripten target for Rust Source: https://github.com/renoise/pattrns/blob/master/examples/playground/README.md This command adds the `wasm32-unknown-emscripten` target to your Rust installation, which is necessary for compiling Rust code to WebAssembly using Emscripten. ```bash rustup target add wasm32-unknown-emscripten ``` -------------------------------- ### Create Seeded Random Pentatonic Scale Pattern Source: https://github.com/renoise/pattrns/blob/master/docs/src/API/pattern.md This example demonstrates creating a pattern that triggers random notes from a pentatonic scale using a seeded random number generator. It defines the unit, a conditional pulse, and a random event function. ```lua local cmin = scale("c5", "pentatonic minor").notes return pattern { unit = "1/16", pulse = function(context) return (context.pulse_step % 4 == 1) or (math.random() > 0.8) end, event = function(context) return { key = cmin[math.random(#cmin)], volume = 0.7 } end } ``` -------------------------------- ### Implement Gates for Event Filtering (Lua) Source: https://github.com/renoise/pattrns/blob/master/docs/src/API/pattern.md Provides examples of implementing a 'gate' function to filter events between the pulse and event emitter. It demonstrates a probability gate that uses pulse values as probabilities for passing events, and a threshold gate that passes events only if their pulse value exceeds a certain threshold. ```lua -- probability gate: skips all 0s, passes all 1s. pulse values in range (0, 1) are -- maybe passed, using the pulse value as probability. gate = function(context) return context.pulse_value > math.random() end ``` ```lua -- threshold gate: skips all pulse values below a given threshold value gate = function(context) return context.pulse_value > 0.5 end ``` -------------------------------- ### Serve pattrns Book Locally Source: https://github.com/renoise/pattrns/blob/master/docs/README.md Serves the pattrns book documentation locally on `localhost:3000` using mdBook. This command automatically rebuilds and refreshes the documentation in the browser whenever markdown files are changed, facilitating a live preview during development. ```shell mdbook serve --open ``` -------------------------------- ### Create or Convert Table using table.from() Source: https://github.com/renoise/pattrns/blob/master/docs/src/API/modules/table.md Initializes a new empty table or converts an existing table into an object that uses global 'table.XXX' functions as methods, mirroring string behavior in Lua. This function is part of the tablelib. ```lua t = table.from{1,2,3}; print(t:concat("|")) ``` -------------------------------- ### Cycle with Pulse Control Source: https://github.com/renoise/pattrns/blob/master/docs/src/guide/cycles.md Combines a cycle with a pulse to control when the pattern plays. This example plays only on odd bars. ```lua return pattern { unit = "bars", pulse = {1, 0}, event = cycle("c4 d4 e4 f4") } ``` -------------------------------- ### Build Rust with nightly and build-std for pthread support Source: https://github.com/renoise/pattrns/blob/master/examples/playground/README.md This command uses the nightly Rust toolchain and the `-Z build-std` flag to compile the Rust standard library. This is a workaround often necessary for enabling pthread support in WebAssembly builds. ```bash cargo +nightly -Z build-std ``` -------------------------------- ### Load pattrns library dynamically in C++ (C++) Source: https://github.com/renoise/pattrns/blob/master/bindings/README.md Demonstrates how to load the pattrns shared library dynamically at runtime within a C++ application. This approach is used by Renoise and requires linking against the provided relay.cpp file. ```cpp #include "pattrns.h" int main() { // Assuming pattrns::load_library is available from pattrns.h if (pattrns::load_library("/SOME/PATH/TO/pattrns.so/dylib/dll")) { // Library loaded successfully, proceed with pattrns usage } else { // Handle library loading failure } return 0; } ``` -------------------------------- ### Check if Table Contains Value using table.contains() Source: https://github.com/renoise/pattrns/blob/master/docs/src/API/modules/table.md Tests whether a given table contains a specific value. The search can optionally start from a specified index. Returns a boolean indicating presence. ```lua t = {"a", "b"}; table.contains(t, "a") -- Expected output: true t = {a=1, b=2}; table.contains(t, 2) -- Expected output: true t = {"a", "b"}; table.contains(t, "c") -- Expected output: false ``` -------------------------------- ### Create New Table using table.new() Source: https://github.com/renoise/pattrns/blob/master/docs/src/API/modules/table.md Creates a new, empty table that utilizes global 'table.XXX' functions as methods, similar to how strings behave in Lua. This function is part of the tablelib. ```lua t = table.new(); t:insert("a"); print(t[1]) ``` -------------------------------- ### Create and Initialize Pulse Tables (Lua) Source: https://github.com/renoise/pattrns/blob/master/docs/src/API/pulse.md Demonstrates creating new pulse tables with a specified length and initial value, or by using a function to generate values. This is useful for setting up rhythmic sequences. ```lua pulse.new(8):init(1) --> 1,1,1,1,1,1,1,1 pulse.new(12):init(function() return math.random(0.5, 1.0) end ) pulse.new(16):init(scale("c", "minor").notes_iter()) ``` ```lua pulse.new(4) --> {0,0,0,0} pulse.new(4, 1) --> {1,1,1,1} pulse.new(4, function() return math.random() end) ``` -------------------------------- ### Define Event using Pulse Library in Lua Source: https://github.com/renoise/pattrns/blob/master/docs/src/guide/event.md Defines a complex event pattern by combining multiple pulse generators. This example uses the `pulse` library to create Euclidean rhythms based on scales. ```lua local tritone = scale("c5", "tritone") return pattern { event = pulse.from(tritone:chord(1, 4)):euclidean(6) + pulse.from(tritone:chord(5, 4)):euclidean(6) } ``` -------------------------------- ### Generate Euclidean Rhythms (Lua) Source: https://github.com/renoise/pattrns/blob/master/docs/src/API/pulse.md Illustrates the creation of Euclidean rhythm patterns. This method distributes a specified number of steps evenly across a given length, with optional offsets and empty values. ```lua pulse.euclidean(12, 16) pulse.from{ 1, 0.5, 1, 1 }:euclidean(12) ``` ```lua pulse.euclidean(3, 8) --> {1,0,0,1,0,0,1,0} pulse.from{"x", "x", "x"}:euclidean(8, 0, "-") --> {"x","-","-","x","-","-","x","-"} ``` -------------------------------- ### Get Supported Scale Mode Names (Lua) Source: https://github.com/renoise/pattrns/blob/master/docs/src/API/scale.md Retrieves a list of all supported scale mode names as an array of strings. This function is useful for understanding the available scale types that can be used with the `scale` function. ```lua scale_names() ``` -------------------------------- ### Get Supported Chord Names (Lua) Source: https://github.com/renoise/pattrns/blob/master/docs/src/API/chord.md Retrieves a list of all supported chord names within the Pattrns library. This function is useful for understanding the available chord types for use with the `chord` function or other related functionalities. ```lua -- Available chords. mode: | "major" | "major7" | "major9" | "major11" | "major13" | "minor" | "minor#5" | "minor6" | "minor69" | "minor7b5" | "minor7" | "minor7#5" | "minor7b9" | "minor7#9" | "minor9" | "minor11" | "minor13" | "minorMajor7" | "add9" | "add11" | "add13" | "dom7" | "dom9" | "dom11" | "dom13" | "7b5" | "7#5" | "7b9" | "five" | "six" | "sixNine" | "seven" | "nine" | "eleven" | "thirteen" | "augmented" | "diminished" | "diminished7" | "sus2" | "sus4" | "7sus2" | "7sus4" | "9sus2" | "9sus4" ``` -------------------------------- ### Parameter Creation Functions Source: https://github.com/renoise/pattrns/blob/master/docs/src/API/parameter.md Functions to create different types of parameters. ```APIDOC ## Parameter Creation API ### Description This API provides functions to create different types of parameters, each with specific data types and optional configurations. ### Functions #### `parameter.boolean(id, default, name?, description?)` Creates a parameter with a boolean type. - **id** (`ParameterId`) - Required - Unique ID for the parameter. - **default** (`ParameterBooleanDefault`) - Required - Default boolean value. - **name** (`ParameterName`) - Optional - Display name for the parameter. - **description** (`ParameterDescription`) - Optional - Description of the parameter. #### `parameter.integer(id, default, range?, name?, description?)` Creates a parameter with an integer type. - **id** (`ParameterId`) - Required - Unique ID for the parameter. - **default** (`ParameterIntegerDefault`) - Required - Default integer value. - **range** (`ParameterIntegerRange`) - Optional - Allowed range for the integer value. - **name** (`ParameterName`) - Optional - Display name for the parameter. - **description** (`ParameterDescription`) - Optional - Description of the parameter. #### `parameter.number(id, default, range?, name?, description?)` Creates a parameter with a number type. - **id** (`ParameterId`) - Required - Unique ID for the parameter. - **default** (`ParameterNumberDefault`) - Required - Default number value. - **range** (`ParameterNumberRange`) - Optional - Allowed range for the number value. - **name** (`ParameterName`) - Optional - Display name for the parameter. - **description** (`ParameterDescription`) - Optional - Description of the parameter. #### `parameter.enum(id, default, values, name?, description?)` Creates a parameter with an enum (string) type. - **id** (`ParameterId`) - Required - Unique ID for the parameter. - **default** (`ParameterEnumDefault`) - Required - Default string value. - **values** (`string[]`) - Required - Array of valid string values. - **name** (`ParameterName`) - Optional - Display name for the parameter. - **description** (`ParameterDescription`) - Optional - Description of the parameter. ### Type Aliases - **ParameterId**: `string` - Unique ID for the parameter. - **ParameterBooleanDefault**: `boolean` - Default boolean value. - **ParameterIntegerDefault**: `integer` - Default integer value. - **ParameterIntegerRange**: `{ 1: integer, 2: integer }` - Optional value range for integers. - **ParameterNumberDefault**: `number` - Default number value. - **ParameterNumberRange**: `{ 1: number, 2: number }` - Optional value range for numbers. - **ParameterEnumDefault**: `string` - Default string value for enum parameters. - **ParameterName**: `string` - Optional display name for the parameter. - **ParameterDescription**: `string` - Optional description for the parameter. ``` -------------------------------- ### Create Seeded Random Subdivision Pattern Source: https://github.com/renoise/pattrns/blob/master/docs/src/API/pattern.md This example illustrates creating a pattern with seeded random note triggering based on a subdivision pulse. It uses a seed for reproducibility and a function to determine pulse values. ```lua local seed = 23498 return pattern { unit = "1/8", pulse = { 1, { 0, 1 }, 0, 0.3, 0.2, 1, { 0.5, 0.1, 1 }, 0.5 }, gate = function(init_context) local rand = math.randomstate(seed) return function(context) return context.pulse_value > rand() end end, event = { "c4" } } ``` -------------------------------- ### Lua Event Function Using Context for MIDI Notes Source: https://github.com/renoise/pattrns/blob/master/docs/src/extras/generators.md Rewrites the previous example to use the provided context object to determine the MIDI note. This ensures unique note streams for each pattern instance, even with polyphonic playback. ```lua return pattern { event = function(context) -- NB: pulse_step is an 1 based index, midi notes start with 0 local midi_note = (context.pulse_step - 1) % 128 return note(midi_note) end } ``` -------------------------------- ### Find Key of Table Element using table.find() Source: https://github.com/renoise/pattrns/blob/master/docs/src/API/modules/table.md Locates the key of the first element in a table that matches a given value. The search can be restricted to the array part starting from a specific index. Returns the key or nil if not found. ```lua t = {"a", "b"}; table.find(t, "a") -- Expected output: 1 t = {a=1, b=2}; table.find(t, 2) -- Expected output: "b" t = {"a", "b", "a"}; table.find(t, "a", 2) -- Expected output: 3 t = {"a", "b"}; table.find(t, "c") -- Expected output: nil ``` -------------------------------- ### Create Shallow Copy of Table using table.copy() Source: https://github.com/renoise/pattrns/blob/master/docs/src/API/modules/table.md Generates a new table that is a shallow copy of the original. It copies the metatable and all elements non-recursively, resulting in a clone with shared references to the original elements. ```lua original_table = {1, 2, key = "value"} new_table = table.copy(original_table) print(new_table[1]) print(new_table.key) ``` -------------------------------- ### Custom Parsing and Remapping with Parameters (Lua) Source: https://github.com/renoise/pattrns/blob/master/docs/src/guide/cycles.md Illustrates custom parsing of values and remapping using parameters within a cycle pattern. It defines parameters for sample selection, transposition, and randomization, then uses a map function to apply these to generated notes. ```lua -- prepare an instrument with a set of samples and update this value local number_of_samples = 10 return pattern { parameter = { parameter.integer("sample", 0, {0, number_of_samples - 1}), parameter.number("random_sample", 0, {0, 1}), parameter.integer("transpose", 0, {-36, 36}), parameter.number("random_pitch", 0.1, {0, 1}), parameter.number("random_spread", 0.3, {0, 1}) }, unit = "1/4", event = cycle([=[ s0*<1 1 0 2> s1*4 s2 s1*<1 1 3>, >*4 ]=]):map(function(context, value) -- parse the number after each "s" into an index local sample_index = tonumber(value:sub(2)) or 0 return note("c3") :instrument( (sample_index + context.parameter.sample + context.parameter.random_sample * math.random(0,number_of_samples) ) % number_of_samples) :transpose(context.parameter.transpose + context.parameter.random_pitch * math.random(-36, 36)) :panning(context.parameter.random_spread * (-1 + 2 * math.random())) end) } ``` -------------------------------- ### Sequence Notes with Volume Source: https://github.com/renoise/pattrns/blob/master/docs/src/API/pattern.md This snippet illustrates how to create a sequence of notes and apply a specific volume to all events in the sequence using the ':volume()' method. ```lua -- a sequence of c4, g4 with volume 0.5 event = sequence{"c4", "g4"}:volume(0.5) ``` -------------------------------- ### Create Scale with Key and Mode (Lua) Source: https://github.com/renoise/pattrns/blob/master/docs/src/API/scale.md Creates a new musical scale from a specified key note and mode. The key can be a string or a number, and the mode is specified by its name. This function returns a Scale object containing the scale's notes. ```lua scale("c4", "minor").notes -> {48, 50, 51, 53, 55, 56, 58} ``` -------------------------------- ### Get Note by Scale Degree (Lua) Source: https://github.com/renoise/pattrns/blob/master/docs/src/API/scale.md Retrieves a single note or multiple notes from a scale based on their degree. The degree can be specified using Roman numeral strings or plain numbers. This function is useful for constructing chords or selecting specific intervals. ```Lua local cmin = scale("c4", "minor") cmin:degree(1) --> 48 ("c4") cmin:degree(5) --> 55 cmin:degree("i", "iii", "v") --> 48, 50, 55 ``` -------------------------------- ### Build pattrns with Cargo (Bash) Source: https://github.com/renoise/pattrns/blob/master/bindings/README.md Builds the pattrns library using Cargo, Rust's package manager. This command compiles the project in release mode for optimized performance. Optional feature flags can be specified in Cargo.toml. ```bash cargo build --release ``` -------------------------------- ### Create Note Object - Lua Source: https://github.com/renoise/pattrns/blob/master/docs/src/guide/notes&scales.md Utilizes the `note()` function to create a note object, allowing for method chaining to modify note properties like volume or transpose. This provides a more programmatic approach. ```lua event = note(48):volume(0.1) ``` ```lua event = note({key = "c4"}):volume(0.2) ``` ```lua event = note("c4'min"):transpose({12, 0, 0}) ``` -------------------------------- ### Adding Note Properties on Top of Cycle Output (Lua) Source: https://github.com/renoise/pattrns/blob/master/docs/src/guide/cycles.md Shows how to add dynamic note properties like volume, panning, delay, and instrument to the output of a cycle pattern using `map`. The properties are calculated based on the step and random values. ```lua return cycle([=[ [ ]*4, *2 ]=]) :map(function(context, value) return note(value) :volume(0.3 + math.random() * 0.6) :panning(math.sin((context.step - 1) * .4) * .8) :delay(.2 * math.random()) :instrument(context.step % 3) end) ``` -------------------------------- ### Set Note Attributes in Cycle Patterns (Lua) Source: https://github.com/renoise/pattrns/blob/master/docs/src/guide/cycles.md Demonstrates setting instrument, panning, delay, and volume attributes for notes within a cycle pattern. Supports chained expressions and alternating values. Requires floating-point numbers for volume, panning, and delay. ```lua -- Set instrument (2), panning (-0.5), and delay (0.25) cycle("d4:2:p-0.5:d0.25") -- Set instrument (1) with alternating volumes (0.1, 0.2) cycle("c4:1:") -- Set multiple attributes with randomization cycle("c4:[v0.5:d0.1|v0.8]") ``` -------------------------------- ### Create Musical Patterns with pattrns (Lua) Source: https://context7.com/renoise/pattrns/llms.txt The `pattern` function is the core API for creating musical sequences in pattrns. It accepts a configuration table for timing, rhythm, filtering, and note generation, supporting static arrays, dynamic functions, or TidalCycles mini-notation. ```lua return pattern { unit = "1/16", -- Sixteenth note timing grid resolution = 2/3, -- Triplet feel pulse = pulse.euclidean(12, 16), -- 12 hits over 16 steps event = { "c4", "g4", { "c5 v0.7", "g5 v0.4" }, "a#4" } -- Note sequence with chord } ``` ```lua return pattern { unit = "1/4", parameter = { parameter.boolean("enabled", true), parameter.integer("note", 48, { 0, 127 }) }, event = function(context) if context.parameter.enabled then return note(context.parameter.note) end end } ``` ```lua local seed = 23498 return pattern { unit = "1/8", pulse = { 1, { 0, 1 }, 0, 0.3, 0.2, 1, { 0.5, 0.1, 1 }, 0.5 }, gate = function(init_context) local rand = math.randomstate(seed) return function(context) return context.pulse_value > rand() end end, event = { "c4" } } ```