# Chopping a sample randomly via midi keyboard

**URL:** <https://in-thread.sonic-pi.net/t/chopping-a-sample-randomly-via-midi-keyboard/6741>\
**Category:** Creations & Ideas\
**Created:** [May 2, 2022, 9:26am UTC](https://in-thread.sonic-pi.net/t/chopping-a-sample-randomly-via-midi-keyboard/6741 "2022-05-02T09:26:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![holz](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/holz/32/1664_2.png) [@holz](https://in-thread.sonic-pi.net/u/holz)\
**Post date:** [May 2, 2022, 9:26am UTC](https://in-thread.sonic-pi.net/t/chopping-a-sample-randomly-via-midi-keyboard/6741/1 "2022-05-02T09:26:13Z")

</div>

Hi there,  
i had the idea to record samples, like just playing the cminor, and let onset decide which note should be played. implemented some reoccuring randomness to get a melody and now when i press c on my keyboard i get 1 of the semi random picked notes from cminor, did the same with bbminor. gonna expand on that since i think thats pretty cool. ill arrange chords and drums like that too i guess.

My only issue is the randomness, i hope there is a better way to do it, cause i want the random note to jump when i pressed once the key. hope u get what i mean 😜

sorry i used samples from my own. ur free to replace them.

```ruby
live_loop :seeeeds do
  use_random_seed 892
  6.times do
    set :randseeed, (ring 541654,64654164,1235216,51531641,6411163,1646532132,1056847645).choose
    
    puts :randseeed
    
    sleep 0.125
    
    cue :simp
  end
end

samps1 = "C:/Users/Gott/Desktop/scales"

live_loop :midi_sfx, sync: :simp do
  use_real_time
  note = sync "/midi:piaggero_0:1/note_on"
  
  use_random_seed get(:randseeed)
  if note[0] == 40 then
    1.times do
      sample samps1, "cmin", onset: choose
      sleep 0.125
    end
  end
  
  if note[0] == 41 then
    1.times do
      sample samps1, "bbmin", onset: choose
      sleep 0.125
    end
  end
end

```

---

<div class="post-metadata">

**Author:** ![holz](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/holz/32/1664_2.png) [@holz](https://in-thread.sonic-pi.net/u/holz)\
**Post date:** [May 2, 2022, 9:59am UTC](https://in-thread.sonic-pi.net/t/chopping-a-sample-randomly-via-midi-keyboard/6741/2 "2022-05-02T09:59:34Z")

</div>

i managed to solve the problem even better than i thought haha here my approach.  
any way to improve on that hhaha?

```ruby

use_random_seed 500456

set :current_state, 0

NOTES = [50, 7896, 45612, 84563, 1237]

RULES = {
  0 => [1,2],
  1 => [3,4],
  2 => [1,3,4],
  3 => [4,0],
  4 => [0,1,2]
}

samps1 = "C:/Users/Gott/Desktop/scales"

live_loop :midi_sfx do
  use_real_time
  note = sync "/midi:piaggero_0:1/note_on"
  s = get[:current_state]
  use_random_seed NOTES[s]
  
  if note[0] == 40 then
    1.times do
      
      sample samps1, "cmin", onset: choose
      sleep 0.125
      set :current_state, RULES[s].choose
      
    end
  end
end

```

---

<div class="post-metadata">

**Author:** ![holz](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/holz/32/1664_2.png) [@holz](https://in-thread.sonic-pi.net/u/holz)\
**Post date:** [May 2, 2022, 10:39am UTC](https://in-thread.sonic-pi.net/t/chopping-a-sample-randomly-via-midi-keyboard/6741/3 "2022-05-02T10:39:13Z")

</div>

well i settled for this, its good enough but not exactly what i wanted

```ruby
samps1 = "C:/Users/Gott/Desktop/scales"

live_loop :midi_sfx do
  
  
  
  use_real_time
  note = sync "/midi:piaggero_0:1/note_on"
  
  use_random_seed (ring 65465,465467,6567,67676,76576,765431,5465,7687,67).tick(:gf)
  
  if note[0] == 60 then
    
    sample samps1, "cmin", onset: choose
    sleep 0.125
 
  end
end

```

---

<div class="post-metadata">

**Author:** ![shemp](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@shemp](https://in-thread.sonic-pi.net/u/shemp)\
**Post date:** [May 2, 2022, 5:21pm UTC](https://in-thread.sonic-pi.net/t/chopping-a-sample-randomly-via-midi-keyboard/6741/4 "2022-05-02T17:21:38Z")

</div>

What is it supposed to do that is exactly what you wanted?

And what is with the collection of random seeds? If you want reproducible results, use a single random seed. If you want a “random” seed, just put in `use_random_seed (Time.now).to_i.freeze` or something similar.
