pattrns

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Pattrns - Generative Music Creation

Pattrns - 生成式音乐创作

Overview

概述

Pattrns is a Lua-based pattern generation engine for Renoise that enables algorithmic, generative music creation. Use this skill when working with Pattrns to create emergent, evolving musical patterns across genres including breakbeat/jungle, IDM, jazz, industrial/trip-hop, and ambient music.
Core Architecture: Pattrns separates rhythm from melody through a Pulse → Gate → Event pipeline:
  • Pulse: Defines when events occur (rhythm)
  • Gate: Optional filter for pulse values (probability, complexity)
  • Event: Generates notes, chords, or sequences (melody/harmony)
This separation enables powerful generative techniques where rhythms and melodies can evolve independently and be recombined in creative ways.
Pattrns是一款基于Lua的Renoise模式生成引擎,可实现算法化的生成式音乐创作。当你使用Pattrns创作跨风格的涌现式、演变型音乐模式时,可运用本技能,涵盖风格包括碎拍/丛林乐、智能舞曲(IDM)、爵士乐、工业/神游舞曲和氛围音乐。
核心架构: Pattrns通过**Pulse(脉冲)→ Gate(闸门)→ Event(事件)**的流程将节奏与旋律分离:
  • Pulse(脉冲):定义事件发生的时机(节奏)
  • Gate(闸门):可选的脉冲值过滤器(控制概率、复杂度)
  • Event(事件):生成音符、和弦或序列(旋律/和声)
这种分离实现了强大的生成技术,让节奏和旋律可以独立演变,并以创意方式重新组合。

When to Use This Skill

适用场景

Invoke this skill when:
  • Creating generative or algorithmic patterns in Renoise
  • Working with euclidean rhythms or polyrhythms
  • Designing evolving, emergent musical structures
  • Generating breakbeats, complex drum patterns, or rhythmic variations
  • Creating generative melodies, harmonies, or chord progressions
  • Building textural, ambient, or atmospheric patterns
  • Using Tidal Cycles mini-notation for pattern creation
  • Developing patterns that resample and resequence for iterative composition
在以下场景中调用本技能:
  • 在Renoise中创作生成式或算法化模式
  • 处理欧几里得节奏或复节奏
  • 设计演变的、涌现式的音乐结构
  • 生成碎拍、复杂鼓点或节奏变体
  • 创作生成式旋律、和声或和弦进行
  • 构建纹理化、氛围化的音色模式
  • 使用Tidal Cycles迷你记谱法创建模式
  • 开发可重采样和重新排序的模式,用于迭代创作

Quick Start

快速入门

Basic Pattern Structure

基础模式结构

Every Pattrns pattern follows this structure:
lua
return pattern {
  unit = "1/16",              -- Time grid (1/16, 1/8, 1/4, bars, etc.)
  resolution = 1,             -- Multiplier (2/3 for triplets)
  offset = 0,                 -- Delay pattern start
  repeats = true,             -- Loop pattern
  pulse = {1, 0, 1, 1},      -- Static rhythm array
  event = {"c4", "e4", "g4"} -- Static note sequence
}
每个Pattrns模式都遵循以下结构:
lua
return pattern {
  unit = "1/16",              -- 时间网格(1/16、1/8、1/4、小节等)
  resolution = 1,             -- 倍数(三连音用2/3)
  offset = 0,                 -- 模式启动延迟
  repeats = true,             -- 循环模式
  pulse = {1, 0, 1, 1},      -- 静态节奏数组
  event = {"c4", "e4", "g4"} -- 静态音符序列
}

Essential Techniques at a Glance

核心技术速览

Euclidean Rhythms (most common starting point):
lua
pulse = pulse.euclidean(7, 16)  -- 7 hits distributed in 16 steps
Scale-Based Melodies:
lua
local s = scale("c4", "minor")
event = s.notes  -- Use scale notes as sequence
Random Generation with Control:
lua
event = function(context)
  local notes = scale("c4", "pentatonic minor").notes
  return notes[math.random(#notes)]
end
Tidal Cycles Mini-Notation:
lua
return cycle("kd ~ sn ~, [hh hh]*4"):map({
  kd = "c4 #1",  -- Kick drum
  sn = "c4 #2",  -- Snare
  hh = "c4 #3 v0.5"  -- Hi-hat, quieter
})
欧几里得节奏(最常用的入门方式):
lua
pulse = pulse.euclidean(7, 16)  -- 16个步骤中分布7个触发点
基于调式的旋律
lua
local s = scale("c4", "minor")
event = s.notes  -- 使用调式音符作为序列
可控随机生成
lua
event = function(context)
  local notes = scale("c4", "pentatonic minor").notes
  return notes[math.random(#notes)]
end
Tidal Cycles迷你记谱法
lua
return cycle("kd ~ sn ~, [hh hh]*4"):map({
  kd = "c4 #1",  -- 底鼓
  sn = "c4 #2",  -- 军鼓
  hh = "c4 #3 v0.5"  -- 踩镲,音量更低
})

Core Workflow

核心工作流

1. Choose Musical Goal

1. 确定创作目标

Identify what to create:
  • Rhythmic: Drum pattern, breakbeat, groove
  • Melodic: Bassline, lead, arpeggio
  • Harmonic: Chord progression, pad, texture
  • Textural: Atmosphere, drone, evolving soundscape
明确要创作的内容:
  • 节奏类:鼓点模式、碎拍、律动
  • 旋律类:贝斯线、主音、琶音
  • 和声类:和弦进行、铺垫、纹理
  • 音色类:氛围音、持续音、演变音景

2. Design Rhythm (Pulse)

2. 设计节奏(Pulse)

Start with rhythmic foundation:
Static Arrays:
lua
pulse = {1, 0, 1, 1, 0, 1, 0, 0}  -- Hand-crafted rhythm
Euclidean Distribution:
lua
pulse = pulse.euclidean(5, 8)     -- Algorithmic rhythm
Dynamic/Generative:
lua
pulse = function(context)
  return math.random() > 0.5      -- Probabilistic rhythm
end
Subdivisions (Cramming):
lua
pulse = {1, {1, 1, 1}, 1, 0}      -- Quarter + triplet + quarter + rest
从节奏基础开始:
静态数组:
lua
pulse = {1, 0, 1, 1, 0, 1, 0, 0}  -- 手动制作的节奏
欧几里得分布:
lua
pulse = pulse.euclidean(5, 8)     -- 算法生成节奏
动态/生成式:
lua
pulse = function(context)
  return math.random() > 0.5      -- 概率性节奏
end
细分节奏(密集型):
lua
pulse = {1, {1, 1, 1}, 1, 0}      -- 四分音符 + 三连音 + 四分音符 + 休止

3. Design Note Generation (Event)

3. 设计音符生成(Event)

Create melodic/harmonic content:
Static Sequence:
lua
event = {"c4", "e4", "g4", "b4"}
Scale-Based:
lua
local s = scale("c4", "minor")
event = function(context)
  return s.notes[math.imod(context.step, #s.notes)]
end
Chord Progressions:
lua
local s = scale("c4", "minor")
event = sequence(
  s:chord("i"),   -- Tonic
  s:chord("iv"),  -- Subdominant
  s:chord("v")    -- Dominant
)
Generative/Evolving:
lua
event = function(init_context)
  local state = initial_value
  return function(context)
    -- Update and use state to create evolution
    state = state + delta
    return generate_from(state)
  end
end
创作旋律/和声内容:
静态序列:
lua
event = {"c4", "e4", "g4", "b4"}
基于调式:
lua
local s = scale("c4", "minor")
event = function(context)
  return s.notes[math.imod(context.step, #s.notes)]
end
和弦进行:
lua
local s = scale("c4", "minor")
event = sequence(
  s:chord("i"),   -- 主和弦
  s:chord("iv"),  -- 下属和弦
  s:chord("v")    -- 属和弦
)
生成式/演变型:
lua
event = function(init_context)
  local state = initial_value
  return function(context)
    -- 更新并使用状态来实现演变
    state = state + delta
    return generate_from(state)
  end
end

4. Add Variation (Optional Gate)

4. 添加变化(可选Gate)

Filter or modify pulse triggers:
lua
gate = function(context)
  -- Higher probability on downbeats
  local is_downbeat = (context.pulse_step - 1) % 4 == 0
  local probability = is_downbeat and 0.9 or 0.3
  return math.random() < probability
end
过滤或修改脉冲触发:
lua
gate = function(context)
  -- 重拍触发概率更高
  local is_downbeat = (context.pulse_step - 1) % 4 == 0
  local probability = is_downbeat and 0.9 or 0.3
  return math.random() < probability
end

5. Add Control (Parameters)

5. 添加控制参数

Enable live tweaking without code changes:
lua
parameter = {
  parameter.integer("variation", 1, {1, 4}),
  parameter.number("density", 0.5, {0.0, 1.0}),
}

-- Access in functions
event = function(context)
  local var = context.parameter.variation
  -- Use var to select different patterns
end
无需修改代码即可实时调整:
lua
parameter = {
  parameter.integer("variation", 1, {1, 4}),
  parameter.number("density", 0.5, {0.0, 1.0}),
}

-- 在函数中访问参数
event = function(context)
  local var = context.parameter.variation
  -- 使用var选择不同模式
end

6. Iterate & Evolve

6. 迭代与演变

Workflow for Emergent Music:
  1. Generate pattern → Test in Renoise
  2. Render/bounce to audio
  3. Resample and chop
  4. Create new patterns using resampled material
  5. Layer and arrange into parts
  6. Repeat process for continuous evolution
涌现式音乐工作流:
  1. 生成模式 → 在Renoise中测试
  2. 渲染/导出为音频
  3. 重采样并切片
  4. 使用重采样素材创建新模式
  5. 分层并编排为段落
  6. 重复流程实现持续演变

Common Musical Tasks

常见音乐创作任务

Creating Breakbeats

创作碎拍

Load
references/genre_recipes.md
and search for "Breakbeat" for complete examples.
Quick pattern:
lua
-- Euclidean-based break
local kick = pulse.euclidean(4, 16)
local snare = pulse.euclidean(3, 16, 2)
local hats = pulse.from{1,0,1,0}:repeat_n(4)

-- Use cycle notation to combine
return cycle("[kd*16], [sn*16], [hh*16]"):map({
  kd = function(ctx) return kick[math.imod(ctx.step,16)] and "c4 #1" end,
  sn = function(ctx) return snare[math.imod(ctx.step,16)] and "c4 #2" end,
  hh = function(ctx) return hats[math.imod(ctx.step,16)] and "c4 #3" end
})
加载
references/genre_recipes.md
并搜索"Breakbeat"获取完整示例。
快速模式:
lua
-- 基于欧几里得节奏的碎拍
local kick = pulse.euclidean(4, 16)
local snare = pulse.euclidean(3, 16, 2)
local hats = pulse.from{1,0,1,0}:repeat_n(4)

-- 使用循环记谱法组合
return cycle("[kd*16], [sn*16], [hh*16]"):map({
  kd = function(ctx) return kick[math.imod(ctx.step,16)] and "c4 #1" end,
  sn = function(ctx) return snare[math.imod(ctx.step,16)] and "c4 #2" end,
  hh = function(ctx) return hats[math.imod(ctx.step,16)] and "c4 #3" end
})

Generative Melodies

生成式旋律

Load
references/core_techniques.md
and search for "Constrained Random Walk" or "Scale-Based Generation".
Quick pattern:
lua
return pattern {
  unit = "1/16",
  pulse = pulse.euclidean(7, 16),  -- Rhythmic interest
  event = function(init_context)
    local notes = scale("c4", "pentatonic minor").notes
    local last_idx = 1
    return function(context)
      -- Prefer small intervals (smoother melody)
      local next_idx = last_idx
      while math.abs(next_idx - last_idx) > 2 do
        next_idx = math.random(#notes)
      end
      last_idx = next_idx
      return notes[next_idx]
    end
  end
}
加载
references/core_techniques.md
并搜索"Constrained Random Walk"或"Scale-Based Generation"。
快速模式:
lua
return pattern {
  unit = "1/16",
  pulse = pulse.euclidean(7, 16),  -- 增加节奏趣味
  event = function(init_context)
    local notes = scale("c4", "pentatonic minor").notes
    local last_idx = 1
    return function(context)
      -- 优先选择小音程(旋律更平滑)
      local next_idx = last_idx
      while math.abs(next_idx - last_idx) > 2 do
        next_idx = math.random(#notes)
      end
      last_idx = next_idx
      return notes[next_idx]
    end
  end
}

Chord Progressions

和弦进行

Load
references/core_techniques.md
and search for "Chord Progressions".
Quick pattern:
lua
local s = scale("c4", "minor")
return pattern {
  unit = "1/4",  -- Whole notes
  pulse = {1, 1, 1, 1},
  event = sequence(
    s:chord("i", 3),   -- i minor
    s:chord("iv", 3),  -- iv minor
    s:chord("v", 3),   -- v minor
    s:chord("i", 3)    -- i minor
  )
}
加载
references/core_techniques.md
并搜索"Chord Progressions"。
快速模式:
lua
local s = scale("c4", "minor")
return pattern {
  unit = "1/4",  -- 全音符
  pulse = {1, 1, 1, 1},
  event = sequence(
    s:chord("i", 3),   -- i小调
    s:chord("iv", 3),  -- iv小调
    s:chord("v", 3),   -- v小调
    s:chord("i", 3)    -- i小调
  )
}

Evolving Textures

演变型音色纹理

Load
references/genre_recipes.md
and search for "Ambient" or "Textural".
Quick pattern:
lua
return pattern {
  unit = "1/16",
  pulse = function(context)
    return math.random() > 0.85  -- Sparse
  end,
  event = function(context)
    local notes = scale("c4", "phrygian").notes
    return note(notes[math.random(#notes)])
      :volume(0.2 + math.random() * 0.3)
      :delay(math.random() * 0.5)
      :panning(math.random() * 2 - 1)
  end
}
加载
references/genre_recipes.md
并搜索"Ambient"或"Textural"。
快速模式:
lua
return pattern {
  unit = "1/16",
  pulse = function(context)
    return math.random() > 0.85  -- 稀疏触发
  end,
  event = function(context)
    local notes = scale("c4", "phrygian").notes
    return note(notes[math.random(#notes)])
      :volume(0.2 + math.random() * 0.3)
      :delay(math.random() * 0.5)
      :panning(math.random() * 2 - 1)
  end
}

Polyrhythms

复节奏

Load
references/core_techniques.md
and search for "Polyrhythms".
Quick pattern:
lua
-- 3:4:5 polyrhythm
cycle("[c4*3]/4, [e4*4]/4, [g4*5]/4")
加载
references/core_techniques.md
并搜索"Polyrhythms"。
快速模式:
lua
-- 3:4:5复节奏
cycle("[c4*3]/4, [e4*4]/4, [g4*5]/4")

Key Techniques Reference

核心技术参考

For detailed explanations and complete code examples, load these reference files:
如需详细说明和完整代码示例,请加载以下参考文件:

Core Techniques (
references/core_techniques.md
)

核心技术(
references/core_techniques.md

Load when working with:
  • Euclidean rhythms and pulse operations
  • Randomization and controlled chaos
  • Scale-based generation
  • Pattern evolution and stateful generators
  • Polyrhythms and unusual time signatures
  • Note transformations
  • Tidal Cycles mini-notation
  • Texture generation
Search patterns:
  • grep -i "euclidean" references/core_techniques.md
  • grep -i "random" references/core_techniques.md
  • grep -i "scale" references/core_techniques.md
处理以下内容时加载:
  • 欧几里得节奏和脉冲操作
  • 随机化与可控混沌
  • 基于调式的生成
  • 模式演变和有状态生成器
  • 复节奏和非常规拍号
  • 音符变换
  • Tidal Cycles迷你记谱法
  • 音色纹理生成
搜索示例:
  • grep -i "euclidean" references/core_techniques.md
  • grep -i "random" references/core_techniques.md
  • grep -i "scale" references/core_techniques.md

Genre-Specific Recipes (
references/genre_recipes.md
)

风格化配方(
references/genre_recipes.md

Load when creating:
  • Breakbeat/Jungle/DnB: Complex breaks, swing, reese bass
  • IDM/Experimental: Glitchy effects, algorithmic complexity
  • Jazz: Swing, walking bass, chord substitutions
  • Industrial/Trip-Hop: Heavy grooves, dark textures
  • Ambient: Slow evolution, drones, sparse atmospheres
Search patterns:
  • grep -i "breakbeat\|jungle\|dnb" references/genre_recipes.md
  • grep -i "idm\|experimental\|glitch" references/genre_recipes.md
  • grep -i "jazz\|swing\|walking" references/genre_recipes.md
创作以下风格时加载:
  • 碎拍/丛林乐/鼓打贝斯:复杂碎拍、摇摆感、 Reese贝斯
  • 智能舞曲/实验音乐: glitch效果、算法复杂度
  • 爵士乐:摇摆感、行走贝斯、和弦替换
  • 工业/神游舞曲:厚重律动、暗黑纹理
  • 氛围音乐:缓慢演变、持续音、稀疏氛围
搜索示例:
  • grep -i "breakbeat\|jungle\|dnb" references/genre_recipes.md
  • grep -i "idm\|experimental\|glitch" references/genre_recipes.md
  • grep -i "jazz\|swing\|walking" references/genre_recipes.md

API Quick Reference (
references/api_quick_reference.md
)

API速查(
references/api_quick_reference.md

Load when needing:
  • Function signatures and parameters
  • Available scale modes
  • Context object properties
  • Utility functions
  • Common code patterns
  • Workflow tips and gotchas
需要以下信息时加载:
  • 函数签名和参数
  • 可用调式
  • 上下文对象属性
  • 工具函数
  • 常见代码模式
  • 工作流技巧和注意事项

Pattern Templates

模式模板

The
assets/
directory contains starter templates for common patterns:
  • euclidean_drum.lua
    : Euclidean-based drum pattern
  • generative_melody.lua
    : Scale-based melody with constraints
  • evolving_chord.lua
    : Slowly evolving chord progression
  • texture_cloud.lua
    : Sparse atmospheric texture
Copy and modify these as starting points.
assets/
目录包含常见模式的起始模板:
  • euclidean_drum.lua
    :基于欧几里得节奏的鼓点模式
  • generative_melody.lua
    :带约束的调式旋律
  • evolving_chord.lua
    :缓慢演变的和弦进行
  • texture_cloud.lua
    :稀疏的氛围音色纹理
可复制并修改这些模板作为创作起点。

Best Practices

最佳实践

Start Simple, Add Complexity

从简到繁,逐步添加复杂度

  1. Begin with static pulse and static event
  2. Make one dynamic (usually event first)
  3. Add gate for probability/filtering
  4. Add parameters for control
  5. Layer multiple patterns
  1. 从静态脉冲和静态事件开始
  2. 先让一个部分动态化(通常是事件)
  3. 添加闸门实现概率/过滤
  4. 添加控制参数
  5. 分层多个模式

Controlled Randomness

可控随机性

Use seeded random for reproducibility:
lua
event = function(init_context)
  local rand = math.randomstate(12345)  -- Consistent seed
  return function(context)
    return generate_with(rand)
  end
end
使用种子随机保证可复现性:
lua
event = function(init_context)
  local rand = math.randomstate(12345)  -- 固定种子
  return function(context)
    return generate_with(rand)
  end
end

State Management

状态管理

  • Global state: Shared across all triggers (use sparingly)
  • Local state (in generators): Per-trigger isolation (preferred)
  • Use init function + inner function pattern for local state
  • 全局状态:所有触发共享(谨慎使用)
  • 局部状态(生成器内):每个触发独立(推荐)
  • 使用初始化函数+内部函数的模式实现局部状态

Performance Optimization

性能优化

  • Cache expensive calculations in init functions
  • Use local variables
  • Avoid creating tables in inner loops
  • Return
    nil
    for rests, not 0 or false
  • 在初始化函数中缓存昂贵计算
  • 使用局部变量
  • 避免在内部循环中创建表
  • 休止时返回
    nil
    ,而非0或false

Tracker Context for Programmers

面向程序员的Tracker提示

  • Lua uses 1-based indexing:
    array[1]
    is first element
  • Use
    math.imod(step, #array)
    for array wrapping
  • Patterns run in musical time (beats/bars), not CPU time
  • BPM and time signature from Renoise project settings
  • Lua使用1-based索引:
    array[1]
    是第一个元素
  • 使用
    math.imod(step, #array)
    实现数组循环
  • 模式按音乐时间(节拍/小节)运行,而非CPU时间
  • BPM和拍号取自Renoise项目设置

Troubleshooting

故障排除

Pattern not triggering:
  • Check
    unit
    is appropriate for tempo
  • Verify
    pulse
    returns non-zero values
  • Check
    gate
    (if present) isn't filtering all events
Notes out of key:
  • Use
    scale()
    to constrain note generation
  • Check root note and mode are correct
Pattern too predictable:
  • Add randomization with
    math.random()
  • Use euclidean rhythms with different parameters
  • Implement constrained random walk for melodies
Pattern too chaotic:
  • Use seeded random for consistency
  • Add constraints to random generation
  • Use scale-based generation for harmonic coherence
  • Lower probability in gates
Lua errors:
  • Check 1-based indexing
  • Verify init function returns inner function for generators
  • Use
    math.imod
    for array wrapping, not
    %
模式未触发:
  • 检查
    unit
    是否与速度匹配
  • 验证
    pulse
    返回非零值
  • 检查
    gate
    (如果存在)是否过滤了所有事件
音符跑调:
  • 使用
    scale()
    约束音符生成
  • 检查根音和调式是否正确
模式过于可预测:
  • 使用
    math.random()
    添加随机化
  • 使用不同参数的欧几里得节奏
  • 为旋律实现约束随机游走
模式过于混乱:
  • 使用种子随机保证一致性
  • 为随机生成添加约束
  • 使用基于调式的生成保证和声连贯性
  • 降低闸门的触发概率
Lua错误:
  • 检查1-based索引
  • 验证初始化函数是否返回内部生成函数
  • 使用
    math.imod
    实现数组循环,而非
    %

Generative Workflow Summary

生成式工作流总结

The power of Pattrns for emergent music:
IDEA → ALGORITHM → PATTERN → EVENTS → AUDIO → RESAMPLE → NEW PATTERN
  1. Generate: Create algorithmic patterns with controlled randomness
  2. Evolve: Use stateful generators to create evolving material
  3. Render: Bounce patterns to audio in Renoise
  4. Resample: Chop and manipulate rendered audio
  5. Resequence: Create new patterns using resampled material
  6. Iterate: Repeat for continuous evolution and emergence
This workflow enables creating "parts" that can be assembled into songs in Renoise or exported to traditional DAWs, with each iteration adding new layers of complexity and emergence.
Pattrns用于涌现式音乐创作的核心流程:
想法 → 算法 → 模式 → 事件 → 音频 → 重采样 → 新模式
  1. 生成:用可控随机性创建算法模式
  2. 演变:使用有状态生成器创建演变素材
  3. 渲染:在Renoise中将模式导出为音频
  4. 重采样:切片并处理渲染后的音频
  5. 重新排序:使用重采样素材创建新模式
  6. 迭代:重复流程实现持续演变和涌现
该工作流可创作出可在Renoise中组装成歌曲,或导出到传统DAW的「段落」,每次迭代都会增加新的复杂度和涌现性。

Resources

资源

references/

references/

Detailed technical documentation and genre-specific recipes. Load as needed:
  • core_techniques.md
    : In-depth technique explanations and code patterns
  • genre_recipes.md
    : Complete examples for different musical styles
  • api_quick_reference.md
    : Function signatures and API reference
详细技术文档和风格化配方。按需加载:
  • core_techniques.md
    :深入的技术说明和代码模式
  • genre_recipes.md
    :不同音乐风格的完整示例
  • api_quick_reference.md
    :函数签名和API参考

assets/

assets/

Pattern templates ready to copy and modify:
  • Starter templates for common musical tasks
  • Genre-specific boilerplate patterns
可直接复制修改的模式模板:
  • 常见音乐任务的起始模板
  • 风格化的基础模式