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
/// Generate arithmetic sequence (linear progression)
///
/// An arithmetic sequence is formed by adding a constant value (the "step" or "common difference")
/// to each term: a, a+d, a+2d, a+3d, a+4d, ...
///
/// This is the simplest type of progression - just counting up (or down) by a fixed amount.
/// Examples:
/// - 1, 2, 3, 4, 5, 6... (step = 1)
/// - 2, 4, 6, 8, 10... (step = 2, even numbers)
/// - 5, 10, 15, 20, 25... (step = 5, multiples of 5)
/// - 100, 90, 80, 70... (step = -10, counting down - use with caution for u32)
///
/// # Arguments
/// * `start` - The first value in the sequence
/// * `step` - Amount to add to each subsequent term (common difference)
/// * `n` - Number of terms to generate
///
/// # Returns
/// Vector containing [start, start+step, start+2*step, ...]
///
/// # Examples
/// ```
/// use tunes::sequences;
///
/// // Simple counting sequence
/// let count = sequences::arithmetic::generate(1, 1, 10);
/// assert_eq!(count, vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
///
/// // Even numbers
/// let evens = sequences::arithmetic::generate(2, 2, 8);
/// assert_eq!(evens, vec![2, 4, 6, 8, 10, 12, 14, 16]);
///
/// // Use for ascending scale pattern
/// # use tunes::prelude::*;
/// # let mut comp = Composition::new(Tempo::new(120.0));
/// # use tunes::consts::scales::C4_MAJOR_SCALE;
/// let scale_indices = sequences::arithmetic::generate(0, 1, 8); // [0, 1, 2, 3, 4, 5, 6, 7]
/// comp.track("ascending")
/// .sequence_from(&scale_indices, &C4_MAJOR_SCALE, 0.25);
///
/// // Use for regular rhythm (every 4 beats)
/// let beat_positions = sequences::arithmetic::generate(0, 4, 16);
/// let times = sequences::normalize(&beat_positions, 0.0, 16.0);
/// ```
///
/// # Musical Applications
/// - **Scales**: Ascending/descending through scale degrees (0, 1, 2, 3...)
/// - **Regular rhythms**: Evenly spaced beats (every 2, 3, or 4 steps)
/// - **Velocity ramps**: Linear increase/decrease in volume
/// - **Filter sweeps**: Linear cutoff frequency changes
/// - **Time markers**: Evenly spaced section boundaries
/// - **Melodic steps**: Stepwise motion up or down
///
/// # Why Use Arithmetic Sequences
/// They're predictable and regular - perfect for:
/// - Creating steady, mechanical patterns
/// - Building foundations for more complex variations
/// - Establishing a baseline before applying transformations
/// - Simulating linear motion or growth
// ========== PRESETS ==========
/// Ascending sequence (1,2,3,4,5...) - 12 terms
/// Even numbers (2,4,6,8...) - 12 terms
/// Odd numbers (1,3,5,7...) - 12 terms
/// Multiples of 5 (5,10,15,20...) - 12 terms
/// Whole tone steps (0,2,4,6,8,10...) - 8 terms, good for whole tone scale
/// Chromatic steps (0,1,2,3,4...) - 13 terms, full octave