# Algorithic music on alternative tuning

**URL:** <https://in-thread.sonic-pi.net/t/algorithic-music-on-alternative-tuning/1469>\
**Category:** Creations & Ideas\
**Created:** [September 9, 2018, 9:08pm UTC](https://in-thread.sonic-pi.net/t/algorithic-music-on-alternative-tuning/1469 "2018-09-09T21:08:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raul](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/raul/32/265_2.png) [@Raul](https://in-thread.sonic-pi.net/u/Raul)\
**Post date:** [September 9, 2018, 9:08pm UTC](https://in-thread.sonic-pi.net/t/algorithic-music-on-alternative-tuning/1469/1 "2018-09-09T21:08:21Z")

</div>

The code

```
nota = 260
raiz = 1.1040895136738123
nt = []

for i in 0..14 do
    nt[i]= nota
    nota = nota*raiz
    puts nt[i]
  end
  with_fx :reverb do
   
    live_loop :acordes do
      d = (ring 1,2).choose
      use_synth :piano
      play hz_to_midi(nt[0]/d),pan: (ring -0.7,-0.3,0.7,0.3).choose
    sleep 0.5
    play hz_to_midi(nt[2]/d),pan: (ring -0.7,-0.3,0.7,0.3).choose
      sleep 0.5
      
      play hz_to_midi(nt[4]/d),pan: (ring -0.7,-0.3,0.7,0.3).choose
    sleep 0.5
    play hz_to_midi(nt[0]/d),pan: (ring -0.7,-0.3,0.7,0.3).choose
      sleep 0.5
      
      play hz_to_midi(nt[2]/d),pan: (ring -0.7,-0.3,0.7,0.3).choose
    sleep 0.5
    play hz_to_midi(nt[5]/d),pan: (ring -0.7,-0.3,0.7,0.3).choose
      sleep 0.5
      play hz_to_midi(nt[0]/d),pan: (ring -0.7,-0.3,0.7,0.3).choose
    sleep 0.5
    play hz_to_midi(nt[3]/d),pan: (ring -0.7,-0.3,0.7,0.3).choose
      sleep 0.5
      
      play hz_to_midi(nt[5]/d),pan: (ring -0.7,-0.3,0.7,0.3).choose
    sleep 0.5
    play hz_to_midi(nt[1]/d),pan: (ring -0.7,-0.3,0.7,0.3).choose
      sleep 0.5
      play hz_to_midi(nt[4]/d),pan: (ring -0.7,-0.3,0.7,0.3).choose
    sleep 0.5
    play hz_to_midi(nt[6]/d),pan: (ring -0.7,-0.3,0.7,0.3).choose
      sleep 0.5
    end
    
    sleep 12
    live_loop :mus do
      use_synth :piano
      azar = rrand_i(0,5000)
      veces = rrand_i(5,8)
      d = (ring 0.5,1,2).choose
      with_fx :echo, phase: (ring 0.25,0.50).choose do
        2.times do
          use_random_seed azar
          veces.times do
            i = rrand_i(0,7)
            n = rrand_i(2,4)
            play hz_to_midi(nt[i]/d), pan: rrand(-0.5,0.5)
            play hz_to_midi(nt[i+n]/d), pan: rrand(-0.5,0.5)
            sleep (ring 0.75,0.25,0.50).choose
          end
        end
      end
      with_fx :echo, phase: (ring 0.25,0.50).choose do
        2.times do
          use_random_seed azar
          veces.times do
            i = rrand_i(0,7)
            n = rrand_i(2,4)
            play hz_to_midi(nt[i]/d), pan: rrand(-0.5,0.5)
            sleep 0.25
            play hz_to_midi(nt[i+n]/d), pan: rrand(-0.5,0.5)
            sleep (ring 0.75,0.25,0.50).choose
          end
        end
      end
    end

```

[https://www.youtube.com/watch?v=iQ2sPHg59o4](https://www.youtube.com/watch?v=iQ2sPHg59o4)

---

<div class="post-metadata">

**Author:** ![samaaron](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/samaaron/32/7_2.png) [@samaaron](https://in-thread.sonic-pi.net/u/samaaron)\
**Post date:** [September 10, 2018, 9:09am UTC](https://in-thread.sonic-pi.net/t/algorithic-music-on-alternative-tuning/1469/2 "2018-09-10T09:09:46Z")

</div>

Nice stuff, although please be aware that the `:piano` synth only plays whole tones, and so the following will result in exactly the same pitch:

```ruby
synth :piano, note: 60
synth :piano, note: 60.4

```

However, all other synths will honour fractional notes.

Also, for experimenting with different tuning systems, you might be interested in playing with `use_tuning` 🙂

---

<div class="post-metadata">

**Author:** ![emlyn](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/emlyn/32/1460_2.png) [@emlyn](https://in-thread.sonic-pi.net/u/emlyn)\
**Post date:** [March 19, 2019, 11:04pm UTC](https://in-thread.sonic-pi.net/t/algorithic-music-on-alternative-tuning/1469/3 "2019-03-19T23:04:36Z")

</div>

@samaaron what’s the reason the piano synth won’t do fractional notes?  
It would be nice if it was possible to use it with different tunings (or just out of tune).

---

<div class="post-metadata">

**Author:** ![samaaron](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/samaaron/32/7_2.png) [@samaaron](https://in-thread.sonic-pi.net/u/samaaron)\
**Post date:** [March 20, 2019, 9:40am UTC](https://in-thread.sonic-pi.net/t/algorithic-music-on-alternative-tuning/1469/4 "2019-03-20T09:40:42Z")

</div>

@emlyn The limitation is down to the specific way in which the piano synth was coded at the SuperCollider level. It uses a lot of hard-coded magic numbers for each piano note.

---

<div class="post-metadata">

**Author:** ![emlyn](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/emlyn/32/1460_2.png) [@emlyn](https://in-thread.sonic-pi.net/u/emlyn)\
**Post date:** [March 20, 2019, 3:35pm UTC](https://in-thread.sonic-pi.net/t/algorithic-music-on-alternative-tuning/1469/5 "2019-03-20T15:35:08Z")

</div>

Thanks @samaaron. I had a look through the source code, and while it does quantise the input note to the nearest midi number, it doesn’t _look_ like it’s inherently limited to whole numbers, since the ugen has a `tune` input that looks like it’s for the fractional part of the note ([here](https://github.com/supercollider/sc3-plugins/blob/42a1bc6d160783b21129ddc7fbcfc63623935ba3/source/MdaUGens/MdaUGens.cpp#L87)).  
When I get a bit of time I may try compiling a synthdef with the fractional part of the note wired up to the `tune` input and see if I can get it to play non-integer notes.

---

<div class="post-metadata">

**Author:** ![samaaron](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/samaaron/32/7_2.png) [@samaaron](https://in-thread.sonic-pi.net/u/samaaron)\
**Post date:** [March 20, 2019, 6:07pm UTC](https://in-thread.sonic-pi.net/t/algorithic-music-on-alternative-tuning/1469/6 "2019-03-20T18:07:56Z")

</div>

Oh nice! If you can figure out a way of using that to essentially interpolate between well tempered pitches, that would be nice. What would be ideal is if the synthdef just accepted a float MIDI value and handled this `tune` parameter internally.

---

<div class="post-metadata">

**Author:** ![emlyn](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/emlyn/32/1460_2.png) [@emlyn](https://in-thread.sonic-pi.net/u/emlyn)\
**Post date:** [March 20, 2019, 10:24pm UTC](https://in-thread.sonic-pi.net/t/algorithic-music-on-alternative-tuning/1469/7 "2019-03-20T22:24:11Z")

</div>

@samaaron I’ve made a new topic over [here](http://in-thread.sonic-pi.net/t/modifying-and-compiling-synthdefs/2143) to avoid hijacking this thread further. I had an initial go at modifying the synthdef but am a bit stuck - any pointers you have would be great.
