aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2023-07-22 10:08:20 +0200
committerBad Diode <bd@badd10de.dev>2023-07-22 10:08:20 +0200
commit8236e0a7d4f99d1d354b3c7667327e707f1f2f4c (patch)
tree25054bba1dcaf0b6817f1410cd8c69afbea92d2c
parent2c4b3648075cc5faa24b859685426b208ccb3a80 (diff)
downloadstepper-8236e0a7d4f99d1d354b3c7667327e707f1f2f4c.tar.gz
stepper-8236e0a7d4f99d1d354b3c7667327e707f1f2f4c.zip
Add trig probability
-rw-r--r--src/main.c4
-rw-r--r--src/rng.c4
-rw-r--r--src/sequencer.c25
3 files changed, 30 insertions, 3 deletions
diff --git a/src/main.c b/src/main.c
index ffe60e4..a6c2238 100644
--- a/src/main.c
+++ b/src/main.c
@@ -15,9 +15,9 @@ WITH REGARD TO THIS SOFTWARE.
15// + Add new UI for the parameter pages 15// + Add new UI for the parameter pages
16// + Change cursor drawing for new parameter pages 16// + Change cursor drawing for new parameter pages
17// + Change cursor behaviour for new parameter pages 17// + Change cursor behaviour for new parameter pages
18// + Allow prob control (% based or 1:2, etc.)
18// - Display notification when editing a parameter with the highest priority 19// - Display notification when editing a parameter with the highest priority
19// - Add panning support. 20// - Add panning support.
20// - Allow prob control (% based or 1:2, etc.)
21// - Add custom user themes 21// - Add custom user themes
22// - Animations for cursor movement/current step highlight. (A fade out maybe?) 22// - Animations for cursor movement/current step highlight. (A fade out maybe?)
23// 23//
@@ -29,7 +29,7 @@ WITH REGARD TO THIS SOFTWARE.
29// - Undo/Redo. 29// - Undo/Redo.
30// 30//
31// Advanced 31// Advanced
32// - Per trig note probability. 32// + Per trig note probability.
33// - Add tap tempo for BPM. 33// - Add tap tempo for BPM.
34// - Allow "marking" several trigs to be able to copy/paste them and/or adjust 34// - Allow "marking" several trigs to be able to copy/paste them and/or adjust
35// their parameters. 35// their parameters.
diff --git a/src/rng.c b/src/rng.c
index 58a517b..4a93562 100644
--- a/src/rng.c
+++ b/src/rng.c
@@ -7,7 +7,9 @@ u32 hash16(u32 input, u32 key) {
7 7
8u16 rng16() { 8u16 rng16() {
9 rng_state += 0xbadd; 9 rng_state += 0xbadd;
10 return hash16(rng_state, 0x10de); 10 u32 ret = hash16(rng_state, 0x10de);
11 rng_state += ret;
12 return ret;
11} 13}
12 14
13u32 rng32() { 15u32 rng32() {
diff --git a/src/sequencer.c b/src/sequencer.c
index 00baebb..e017700 100644
--- a/src/sequencer.c
+++ b/src/sequencer.c
@@ -17,6 +17,7 @@ bool redraw_params = true;
17bool redraw_bpm = true; 17bool redraw_bpm = true;
18bool redraw_piano_note = true; 18bool redraw_piano_note = true;
19bool update_bpm = false; 19bool update_bpm = false;
20u8 bar_counter = 0;
20 21
21void 22void
22gate_off(void) { 23gate_off(void) {
@@ -73,6 +74,25 @@ find_prev_pattern(void) {
73 74
74bool 75bool
75should_play(u8 prob) { 76should_play(u8 prob) {
77 switch (prob) {
78 case PROB_100: { return true; } break;
79 case PROB_80: { return rng16() < 52427; } break;
80 case PROB_60: { return rng16() < 39320; } break;
81 case PROB_40: { return rng16() < 26213; } break;
82 case PROB_20: { return rng16() < 13106; } break;
83 case PROB_FIRST: { return bar_counter == 0; } break;
84 case PROB_NOT_FIRST: { return bar_counter != 0; } break;
85 case PROB_ONE_TWO: { return bar_counter % 2 == 0; } break;
86 case PROB_TWO_TWO: { return bar_counter % 2 == 1; } break;
87 case PROB_ONE_THREE: { return bar_counter % 3 == 0; } break;
88 case PROB_TWO_THREE: { return bar_counter % 3 == 1; } break;
89 case PROB_THREE_THREE: { return bar_counter % 3 == 2; } break;
90 case PROB_ONE_FOUR: { return bar_counter % 4 == 0; } break;
91 case PROB_TWO_FOUR: { return bar_counter % 4 == 1; } break;
92 case PROB_THREE_FOUR: { return bar_counter % 4 == 2; } break;
93 case PROB_FOUR_FOUR: { return bar_counter % 4 == 3; } break;
94 default: break;
95 }
76 return true; 96 return true;
77} 97}
78 98
@@ -246,6 +266,9 @@ play_step(void) {
246 case SYNC_OUT_LINK_AUDIO_4: { if (step_counter % 4 == 0) { gate_on(); audio_sync_click = true; } } break; 266 case SYNC_OUT_LINK_AUDIO_4: { if (step_counter % 4 == 0) { gate_on(); audio_sync_click = true; } } break;
247 default: break; 267 default: break;
248 } 268 }
269 if (step_counter == 15) {
270 bar_counter++;
271 }
249 step_counter = (step_counter + 1) % 16; 272 step_counter = (step_counter + 1) % 16;
250 redraw_piano_note = true; 273 redraw_piano_note = true;
251} 274}
@@ -389,6 +412,7 @@ stop_playing(void) {
389 chain.current = 15; 412 chain.current = 15;
390 chain.current = find_next_pattern(); 413 chain.current = find_next_pattern();
391 chain.playing = false; 414 chain.playing = false;
415 bar_counter = 0;
392 stop_sound(); 416 stop_sound();
393} 417}
394 418
@@ -399,6 +423,7 @@ toggle_playing(void) {
399 chain.current = 15; 423 chain.current = 15;
400 chain.current = find_next_pattern(); 424 chain.current = find_next_pattern();
401 chain.playing = false; 425 chain.playing = false;
426 bar_counter = 0;
402 if (current_pattern == next_pattern && chain.len > 0) { 427 if (current_pattern == next_pattern && chain.len > 0) {
403 chain.playing = true; 428 chain.playing = true;
404 next_pattern = chain.chain[chain.current]; 429 next_pattern = chain.chain[chain.current];