# Microtonal musical systems

**URL:** <https://in-thread.sonic-pi.net/t/microtonal-musical-systems/5498>\
**Category:** Creations & Ideas\
**Created:** [May 5, 2021, 4:02pm UTC](https://in-thread.sonic-pi.net/t/microtonal-musical-systems/5498 "2021-05-05T16:02:26Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregeporter](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/gregeporter/32/1277_2.png) [@gregeporter](https://in-thread.sonic-pi.net/u/gregeporter)\
**Post date:** [May 5, 2021, 4:02pm UTC](https://in-thread.sonic-pi.net/t/microtonal-musical-systems/5498/1 "2021-05-05T16:02:26Z")

</div>

When playing a note with `play` you can provide the notes in a couple ways:  
`play C #the note name`  
or  
`play 60 #the key on the keyboard that corresponds to that note`

I was looking through the wiki page for [Svara](https://en.wikipedia.org/wiki/Svara) and it has note names like M’a which corresponds to F#.

Would it be possible to add the names of notes for other musical systems like in Indian Classical Music?

---

<div class="post-metadata">

**Author:** ![hitsware](https://avatars.discourse-cdn.com/v4/letter/h/a9adbd/32.png) [@hitsware](https://in-thread.sonic-pi.net/u/hitsware)\
**Post date:** [May 9, 2021, 2:09am UTC](https://in-thread.sonic-pi.net/t/microtonal-musical-systems/5498/2 "2021-05-09T02:09:27Z")

</div>

```ruby
doh = 60 ### any names you want
re = 70 ### also allows for
mi = 80 ### Indian microtuning
skale = [doh,re,mi]
for i in 0..2
  play skale[i]
  sleep 1
end
```

---

<div class="post-metadata">

**Author:** ![gregeporter](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/gregeporter/32/1277_2.png) [@gregeporter](https://in-thread.sonic-pi.net/u/gregeporter)\
**Post date:** [May 9, 2021, 4:34am UTC](https://in-thread.sonic-pi.net/t/microtonal-musical-systems/5498/3 "2021-05-09T04:34:48Z")

</div>

That would totally work for a session or a song but I was thinking making a more permanent change to the code base to allow for those additional names.

I can’t seem to find where it would be though, thought my search felt a little superficial

Update: Ok, I checked out the code and it looks like it might be in `app/server/ruby/lib/sonicpi/note.rb` further investigation commencing 😛

---

<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:** [May 9, 2021, 9:15am UTC](https://in-thread.sonic-pi.net/t/microtonal-musical-systems/5498/4 "2021-05-09T09:15:09Z")

</div>

> [@gregeporter](#):
>
> That would totally work for a session or a song but I was thinking making a more permanent change to the code base to allow for those additional names.

Happy to consider proposals for changes.

However, it’s important to note that the solfège method of education for music uses the terms `doh`, `re`, `mi`, etc to refer to the intervals on a scale - so definitely shouldn’t be hard-coded to specific MIDI numbers.

Having said that, I do think there’s huge value in taking the same approach as the live coding system Ixi Lang took which is to allow people to work directly with scale intervals as that has been shown to make things simple and musical for beginners.

So something like the following might make sense:

```ruby
play :doh #=> plays the first note of the current scale (perhaps the default is C Major)

```

```ruby
use_scale :d, :minor
play :doh #=> now plays :d

```

```ruby
use_scale :f, :major
use_scale_intervals #=> let people use integers to refer to scale intervals
play 1 #=> plays :f

```

---

<div class="post-metadata">

**Author:** ![gregeporter](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/gregeporter/32/1277_2.png) [@gregeporter](https://in-thread.sonic-pi.net/u/gregeporter)\
**Post date:** [May 9, 2021, 1:10pm UTC](https://in-thread.sonic-pi.net/t/microtonal-musical-systems/5498/5 "2021-05-09T13:10:19Z")

</div>

I see what you mean about how the intervals  
are translated in `notes.rb`:

```ruby
NOTES_TO_INTERVALS =
      {cf: -1, CF: -1, Cf: -1, cF: -1,
       cb: -1, CB: -1, Cb: -1, cB: -1,
       c: 0, C: 0,
       cs: 1, CS: 1, cS: 1, Cs: 1,
       df: 1, DF: 1, Df: 1, dF: 1,
       db: 1, DB: 1, Db: 1, dB: 1,
       d: 2, D: 2,
       eb: 3, EB: 3, Eb: 3, eB: 3,
       ef: 3, EF: 3, Ef: 3, eF: 3,
       ds: 3, DS: 3, Ds: 3, dS: 3,
       e: 4, E: 4,
       fb: 4, FB: 4, Fb: 4, fB: 4,
       ff: 4, FF: 4, Ff: 4, fF: 4,
       f: 5, F: 5,
       es: 5, ES: 5, Es: 5, eS: 5,
       fs: 6, FS: 6, Fs: 6, fS: 6,
       gb: 6, GB: 6, Gb: 6, gB: 6,
       gf: 6, GF: 6, Gf: 6, gF: 6,
       g: 7, G: 7,
       gs: 8, GS: 8, Gs: 8, gS: 8,
       ab: 8, AB: 8, Ab: 8, aB: 8,
       af: 8, AF: 8, Af: 8, aF: 8,
       a: 9, A: 9,
       bb: 10, BB: 10, Bb: 10, bB: 10,
       bf: 10, BF: 10, Bf: 10, bF: 10,
       as: 10, AS: 10, As: 10, aS: 10,
       b: 11, B: 11,
       bs: 12, BS: 12, Bs: 12, bS: 12}

    INTERVALS_TO_NOTES = {
      0 => :C,
      1 => :Cs,
      2 => :D,
      3 => :Eb,
      4 => :E,
      5 => :F,
      6 => :Fs,
      7 => :G,
      8 => :Ab,
      9 => :A,
      10 => :Bb,
      11 => :B}

    DEFAULT_OCTAVE = 4

    MIDI_NOTE_RE = /\A:?(([a-gA-G])([sSbBfF]?))([-]?[0-9]*)\Z/

```

With that method, it seems like that is used for the purposes of Western music but maybe by allowing to play with the intervals then other systems could be used.

The time between posting this and now, I did some reading and it seems like my perception of something like Indian classical music wasn’t right; there are still 12 intervals but I guess the starting point is different? I’ll do some more research 🙂

Thanks, you two!

---

<div class="post-metadata">

**Author:** ![gregeporter](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/gregeporter/32/1277_2.png) [@gregeporter](https://in-thread.sonic-pi.net/u/gregeporter)\
**Post date:** [May 9, 2021, 1:15pm UTC](https://in-thread.sonic-pi.net/t/microtonal-musical-systems/5498/6 "2021-05-09T13:15:04Z")

</div>

Oh, and just to make sure I didn’t cause confusion. In terms of a permanent solution. I didn’t mean for something like Doh Re Me to be hardcoded, but something like one of the tables from that wiki page:

 ![notes](https://europe1.discourse-cdn.com/flex017/uploads/sonic_pi/original/2X/7/7c10648850f428161df32a9a9240dd71950a54ed.png)

Where  
`Play Sa === Play C === Play 60`

Cause I don’t think that’ll change any time soon.

---

<div class="post-metadata">

**Author:** ![hitsware](https://avatars.discourse-cdn.com/v4/letter/h/a9adbd/32.png) [@hitsware](https://in-thread.sonic-pi.net/u/hitsware)\
**Post date:** [May 9, 2021, 8:39pm UTC](https://in-thread.sonic-pi.net/t/microtonal-musical-systems/5498/7 "2021-05-09T20:39:14Z")

</div>

I ’ d be tempted to use numbers instead of note names …

> **[Indian Tuning - Just Intonation](https://sitars-ragas-icm.blogspot.com/2010/09/indian-tuning-just-intonation.html)**
>
> When it comes to sitars you really don't want to be using a guitar tuner. Sitars, and a lot of Indian instruments, use something called Just...

---

<div class="post-metadata">

**Author:** ![gregeporter](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/gregeporter/32/1277_2.png) [@gregeporter](https://in-thread.sonic-pi.net/u/gregeporter)\
**Post date:** [May 9, 2021, 9:18pm UTC](https://in-thread.sonic-pi.net/t/microtonal-musical-systems/5498/8 "2021-05-09T21:18:24Z")

</div>

I probably would too

---

<div class="post-metadata">

**Author:** ![hitsware](https://avatars.discourse-cdn.com/v4/letter/h/a9adbd/32.png) [@hitsware](https://in-thread.sonic-pi.net/u/hitsware)\
**Post date:** [May 10, 2021, 1:44am UTC](https://in-thread.sonic-pi.net/t/microtonal-musical-systems/5498/9 "2021-05-10T01:44:57Z")

</div>

Would you dare the ratios for a scale ?  
I’ve looked before and could never find  
the numbers …

---

<div class="post-metadata">

**Author:** ![gregeporter](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/gregeporter/32/1277_2.png) [@gregeporter](https://in-thread.sonic-pi.net/u/gregeporter)\
**Post date:** [May 10, 2021, 2:17am UTC](https://in-thread.sonic-pi.net/t/microtonal-musical-systems/5498/10 "2021-05-10T02:17:12Z")

</div>

Hmm, I think the best I find at the moment would be in that wiki page under the section “Swaras in Carnatic music“

In that chart, it seems to say, given a base note, or Shadja, then the scale is built upon some number of semi tones.

So, if I’m reading it correctly, maybe if we assume C is the Shadja, then we can build up the subsequent notes?

---

<div class="post-metadata">

**Author:** ![gregeporter](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/gregeporter/32/1277_2.png) [@gregeporter](https://in-thread.sonic-pi.net/u/gregeporter)\
**Post date:** [May 10, 2021, 2:18am UTC](https://in-thread.sonic-pi.net/t/microtonal-musical-systems/5498/11 "2021-05-10T02:18:49Z")

</div>

I think tonight, I’ll try building out a temporary variable list like you mentioned and then I’ll see how it sounds.

I let you know what I find out and maybe I’ll share some code here and we can determine if it sounds right. 🙂

---

<div class="post-metadata">

**Author:** ![gregeporter](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/gregeporter/32/1277_2.png) [@gregeporter](https://in-thread.sonic-pi.net/u/gregeporter)\
**Post date:** [May 10, 2021, 2:37pm UTC](https://in-thread.sonic-pi.net/t/microtonal-musical-systems/5498/12 "2021-05-10T14:37:27Z")

</div>

Ok, what do you think of this?

```
sa = 60 #0
ra = 61 #1
ri = 62 #2
ru = 63 #3
gi = 63 #3
gu = 64 #4
ma = 65 #5
mi = 66 #6
pa = 67 #7
dha = 68 #8
dhi = 69 #9
na = 69 #9
dhu = 70 #10
ni = 70 #10
nu = 71 #11

live_loop :amen do
  sample :loop_tabla, amp: 2
  sleep sample_duration(:loop_tabla)
end

use_synth :pluck

15.times do
  play (ring mi, gi, ru, gi).tick
  sleep 0.1
end

5.times do
  play (ring na+2, ni+2, nu+2, ni+2, na+2).tick
  sleep 0.25
end

5.times do
  play (ring pa, dha, nu, dha, pa).tick
  sleep 0.25
end

sleep 1

13.times do
  play ma
  sleep 0.3
end

2.times do
  play ru
  
  sleep 0.3
  
  play ma
  
  sleep 0.3
  
  play mi
  
  sleep 0.3
  
  play ma
  
  sleep 0.3
  
  play ma
  
  sleep 0.3
  
  play ma
  
  sleep 0.3
  play ma
  
  sleep 0.3
  
  play ru
  
  sleep 0.3
  play ma
  
  sleep 0.3
  play mi
  
  sleep 0.3
  
  play ma
  
  sleep 1
end

```

I tried to pseudo-recreate the beginning of this song:  
https://www.youtube.com/embed/8nd5NLbUu44?feature=oembed&wmode=opaque&list=PLCDA27B24BA28C8C9

But, to be honest, I used intervals to get it all in line 🤣 so, take that for what you will.

---

<div class="post-metadata">

**Author:** ![hitsware](https://avatars.discourse-cdn.com/v4/letter/h/a9adbd/32.png) [@hitsware](https://in-thread.sonic-pi.net/u/hitsware)\
**Post date:** [May 10, 2021, 11:20pm UTC](https://in-thread.sonic-pi.net/t/microtonal-musical-systems/5498/13 "2021-05-10T23:20:31Z")

</div>

> > Ok, what do you think of this?

Sounds good ! … O.K. for Bollywood ,  
but Ravi might be more like …???

```ruby
skale = ["sa ","ra ","ri ","ru/gi ",
         "gu ","ma ","mi ", "pa ",
         "dha ","dhi/na","dhu/ni","nu ",
         "SA "]
numerator = [1,16,9,6,5,4,45,3,8,27,9,15,2]
denominator = [1,15,8,5,4,3,32,2,5,16,5,8,1]

# For sa = 440 Hz

for i in 0..12
  f=(numerator[i]*440)/denominator[i]
puts skale[i],f,"Hz midi #",hz_to_midi(f)
end
```

![2021-05-10-153305_488x444_scrot](https://europe1.discourse-cdn.com/flex017/uploads/sonic_pi/original/2X/8/887bd1356da6a00e0fd981d26b07a3f6c77c5892.png)

---

<div class="post-metadata">

**Author:** ![gregeporter](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/gregeporter/32/1277_2.png) [@gregeporter](https://in-thread.sonic-pi.net/u/gregeporter)\
**Post date:** [May 11, 2021, 12:38pm UTC](https://in-thread.sonic-pi.net/t/microtonal-musical-systems/5498/14 "2021-05-11T12:38:48Z")

</div>

That is some really impressive code, @hitsware; amazing job finding that chart and translating it. Where did you find it?

I do like the sound of it more now too

I feel like your code could be something that could be included in Note.rb to maintain a reference to those ratios.

Heck, I’m definitely saving this thread for the purposes of keeping it 🙂

---

<div class="post-metadata">

**Author:** ![hitsware](https://avatars.discourse-cdn.com/v4/letter/h/a9adbd/32.png) [@hitsware](https://in-thread.sonic-pi.net/u/hitsware)\
**Post date:** [May 11, 2021, 3:04pm UTC](https://in-thread.sonic-pi.net/t/microtonal-musical-systems/5498/15 "2021-05-11T15:04:30Z")

</div>

Thank You !

> > Where did you find it?

By the grace of Google 🙂

> > I do like the sound of it more now too

Music is all in Your Mind … But that is where it counts !
