Hello everyone!
Do you want to play with infinite sequences of figurative numbers in Sonic Pi?
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.
Locate or download the file in the path lib/figurate_numbers.rb
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
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
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 ? Thanks for attention
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!
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
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.
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
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.
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 to be continued…
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
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
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
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.