Figurate Numbers for Sonic Pi (New Ruby gem for infinite number sequences and patterns)

1. Introduction

Hello everyone!
Do you want to play with infinite sequences of figurative numbers in Sonic Pi?
sonic_pi_threads_figurate_numbers

I have been developing 115 figurate number sequences (planar, spatial, and multidimensional) from the phenomenal book Figurate Numbers (2012) by Elena Deza and Michel Deza for use in Sonic Pi.

2. Installation, source code and instructions

  1. Install Gem via rubygems.org page
  2. Github: Complete list of number sequences implemented and source code

3. How to use this sequences in Sonic Pi?

  1. Locate or download the file in the path lib/figurate_numbers.rb
  2. Drag the file to a buffer in Sonic Pi (this generates the <PATH>)
run_file "<PATH>"

pol_num = FigurateNumbers.polygonal_numbers(8)
80.times do
  play pol_num.next % 12 * 7 # Some mathematical function or transformation
  sleep 0.25
end
7 Likes

Hi there,

figurate_numbers now has 206 infinite sequences with version 1.0.0. All implemented sequences are on github.
You can download it as a gem from:
https://rubygems.org/gems/figurate_numbers

1 Like

Hello Edgar @EdgarDelgadoVega and thanks for your post!..But, I don’t understand very well, how can we “play” concretely with these numbers in the SP interface :thinking:? Thanks for attention :smiley:

1 Like

Thanks for your attention @beryann, I will make a short video tutorial soon!!!

2 Likes

Hello everyone!

This is the video tutorial for using Sonic Pi (click on link or in image)

Video Tutorial Figurate Numbers in Sonic Pi

@Ko-peInefable
@beryann
@halloworld
@mrbombmusic
@Relaxnow
@tuned

3 Likes

Hello Edgar…I have seen your video, thanks for it!. I am going now to explore this on my SPi!I’ll feedback! :grinning:
Warmly

Hi Edgar @EdgarDelgadoVega I have tried your recommendations in the video but on my Windows 11, my terminal doesn’t accept the term “install” (I am not a specialist of the terminal!) …I am going to try it again on my Mac…a priori, is it for the 2 systems? Thanks for attention! :smiley:

Do you have rubygems installed? If not those terminal commands won’t work.

2 Likes

ok Alice @alicesmokesgas I’ll try this! thanks a lot… :+1:

1 Like

No problem, I think there’s a package or something that installs both ruby and rubygems. It’s been a while since I’ve installed though so I can’t remember, just check out rubygems.org

2 Likes

Hi @beryann , gem install figurate_numbers works if you have Ruby installed (not just Sonic Pi): Ruby Programming Language
You can check if you have the package manager installed with the command
which gem.

1 Like

Hi Edgar
Got the gemin installed and working. Using your example in the video plays OK but it seems to clobber Sonic PI sound out…possibly because the latter numbers generate very high frequencies. I need to restart before I can run it again.

I modified the program as below:

run_file "/Users/rbn/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/figurate_numbers-1.0.0/lib/figurate_numbers.rb"
sleep 1 #to allow figurate_numbers to complete load and setup otherwise first run can give error
seq = FigurateNumbers.octahedral_numbers
live_loop :seq_numbers do
  tick
  use_synth :bass_foundation
  n = seq.next
  stop if n > 127
  play n, release: 1
  sleep 1  
end

EDIT I suppose you could use n = (seq.next/)%127 as well which would leave it running

2 Likes

Hi dear @robin.newman,

Indeed, the values ​​must be truncated for all sequences, so that the mapping remains “audible” according to the chosen musical parameter. It’s also great to truncate to % 127 (MIDI values), I used to use it more with % 7 or % 12. On the other hand, I appreciate that you introduced sleep 1 for the first time loading the module.

It’s a matter of exploring other operations that maintain an audible and executable range by SP.
I will soon upload another video with a couple of basic examples developed.

Figurate Numbers in Sonic Pi (Large numbers)

This is the second short tutorial explaining how large sequence values ​​can be included in other parameters. Click the following link:

Deal with large numbers generated by figurate numbers (Example)

1 Like

Hi there! @robin.newman @alicesmokesgas @EdgarDelgadoVega
Everything is fine now (on my windows 11, not on my old mac Big Sur I don’t know why)
I notice this: the different sequences are sometimes very short and sometimes “look” very similar. How to use them in SPi, that’s the question of the day lol but I’ll try to do something with it by trying different types of numbers in different loops to see if it can work. Thanks to the “stop if n > 127” of @robin.newman we effectively avoid nasty clicks at the end of the pattern…Thank you all :raised_hand_with_fingers_splayed: to be continued… :grin:

1 Like

Here’s the rest… I started with Robin’s patch to arrive at this with a few modifications… It’s a simple unpretentious experiment. Try it for yourself, you will probably be able to improve it :wink:

run_file "C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/figurate_numbers-1.0.0/lib/figurate_numbers.rb"

sleep 1
#to allow figurate_numbers to complete load and setup otherwise first run can give error

live_loop :all do
  with_fx :reverb, mix: 0.8 do
    seq1 = FigurateNumbers.six_dimensional_hypercube_numbers
    live_loop :seq_numbers do
      tick
      use_synth :bass_foundation
      n = seq1.next
      stop if n > 127
      play n, release: 1
      sleep 1
    end
    
    seq2 = FigurateNumbers.stella_octangula_numbers
    live_loop :seq_numbers2 do
      use_octave 3
      tick
      use_synth :piano
      n = seq2.next
      stop if n > 127
      play n, release: 1
      sleep 1
    end
    
  end
  sleep 2
end
1 Like

Hi @beryann,
You can do a thousand things with the sequences, it depends on what you imagine. You can put the sequences in any parameter that accepts numbers (remember to do operations so that the values ​​fit).
I share another basic example on the fly that can be done:

run_file "C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/figurate_numbers-1.0.0/lib/figurate_numbers.rb"
sleep 1

seq1 = FigurateNumbers.centered_hyperoctahedral_numbers
seq2 = FigurateNumbers.mgonal_prism_numbers(6)
s = FigurateNumbers.six_dimensional_hypercube_numbers.take(35)[2]

use_random_seed s + seq2.take(7)[4]
live_loop :seq_num do
  tick
  use_synth [:dtri, :chiplead, :subpulse, :fm][seq2.next % 5]
  play seq1.next % 7 * 10 + rand_i(20),
    amp: seq2.next % 5,
    release: 0.125
  sleep 0.125
end

1 Like

Hello Edgar! @EdgarDelgadoVega
Thanks for your patch, I see now and I am going to experiment this.
Can you just tell me what this does?:

play seq1.next % 7 * 10 + rand_i(20)

I understand of course the play and rand_i (for integers) but what does the modulo exactly? Is “next” like a .tick?
Thanks :smiley:

Hi @beryann ,
Thanks for the question. The % symbol means that you are going to take an integer from the sequence and reduce it modulo another integer. The simplest idea is to think of clocks. On a 12 hour clock, 17 hours are equivalent to 5 hours, i.e. 17 % 12 produces 5. In the example you are using a 7 hour clock. If the number in the sequence is 15, then 15 % 7 = 1.
In that sense, % is not an iterator and just reduces the value of the number produced by the sequence.

1 Like

ok I have understood, Thanks a lot Edgar!! @EdgarDelgadoVega

1 Like