1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/// Generate random walk sequence (Brownian motion)
///
/// A random walk is a path consisting of successive random steps. Each value is
/// the previous value plus a random delta. This creates smooth but unpredictable
/// variation - like a drunk person walking or a particle in fluid (Brownian motion).
///
/// Random walks appear throughout nature and music:
/// - Stock market prices
/// - Particle diffusion
/// - Melodic contours in jazz improvisation
/// - Bass line variation
///
/// # Arguments
/// * `start` - Initial value (typically a frequency like 440.0 or musical parameter)
/// * `step_size` - Maximum step size per iteration (controls smoothness)
/// * `steps` - Number of steps to generate
///
/// # Returns
/// Vector of values forming a random walk (unbounded - can go anywhere)
///
/// # Typical Parameters
///
/// **step_size** (relative to start value):
/// - **Small (5-10 Hz)**: Subtle variation, stays close to start (bass lines, pads)
/// - **Medium (20-50 Hz)**: Noticeable wandering (melodic variation)
/// - **Large (100+ Hz)**: Wide exploration (experimental, dramatic changes)
///
/// **For non-frequency parameters:**
/// - Volume: 0.05-0.1 (subtle breathing)
/// - Filter cutoff (0-1): 0.05-0.15 (smooth sweeps)
/// - Pan (-1 to 1): 0.1-0.3 (gentle movement)
///
/// # Recipe: Organic Bass Line
///
/// ```
/// use tunes::prelude::*;
/// use tunes::sequences;
///
/// let mut comp = Composition::new(Tempo::new(120.0));
///
/// // Wandering bass around 110 Hz (A2)
/// let bass_walk = sequences::random_walk::generate(110.0, 8.0, 16);
///
/// comp.instrument("bass", &Instrument::sub_bass())
/// .notes(&bass_walk, 0.5);
/// ```
///
/// # Recipe: Evolving Filter Cutoff
///
/// ```
/// use tunes::sequences;
///
/// // Generate smooth filter automation
/// let start_cutoff = 500.0; // Hz
/// let walk = sequences::random_walk::generate(start_cutoff, 40.0, 64);
///
/// // Clamp to reasonable filter range
/// let filter_curve: Vec<f32> = walk.iter()
/// .map(|&f| f.clamp(200.0, 2000.0))
/// .collect();
/// ```
///
/// # Musical Applications
/// - **Melodic variation**: Organic-sounding pitch movement
/// - **Bass lines**: Smooth but unpredictable bass patterns
/// - **Parameter automation**: Filter cutoff, pan, volume variation
/// - **Generative composition**: Non-repetitive sequences
///
/// # Note
/// This is an unbounded walk - values can grow arbitrarily large or small.
/// Use `bounded_walk()` if you need to constrain the range.
// ========== PRESETS ==========
/// Short random walk - 16 steps, step size 1
/// Classic random walk - 32 steps, step size 1
/// Long random walk - 64 steps, step size 1
/// Large steps - 32 steps, step size 3