Subsetting scales, rings and arrays

v3.2.2 on macos 10.15.2

I’m having trouble subsetting scales it doesn’t seem to be working as I understand it from section 8 in the tutorial or from the examples given here:

Trying take on a scale doesn’t return the first n notes of the scale as I would expect:

myscale = (scale :b2, :major, num_octaves: 2)
puts myscale
puts myscale.take(3)

 ├─ (ring <SonicPi::Scale :B :major [47, 49, 51, 52, 54, 56, 58, 59, 61, 63, 64, 66, 68, 70, 71])
 ├─ (ring <SonicPi::Scale :C : )

myring = [1,2,3,4,5].ring
puts myring
puts myring.take(3)

 ├─ (ring 1, 2, 3, 4, 5)
 └─ (ring 1, 2, 3)

But it does start giving valuest when I use negative numbers or numbers longer than the length of the ring. What am I doing wrong?

1 Like

What do you expect ?
Looks right to me …

I see the same problem in Sonic Pi 3.2.2:

s = (scale :b2, :major).take(3)
puts s
6.times do |i|
  puts s[i]

But it looks like it’s just a bug in the way the ring is printed, accessing the values still produces the correct results.

Thanks for bringing this to our attention @Andrew and @emlyn!
I can confirm this is a recent bug with how the result is printed. It should be fixed soon (hopefully I can get something ready for Sam to review within the next day or two and then merged into the main GitHub repository, ready for the next Beta or release version).

Fix submitted, hopefully reviewed and merged soon :slight_smile:


hello, @hitsware

Seems to be a problem depends on sonic pi version.
Which version do you use ?
In general it would be cool to give this information each issue met. It helps a lot. :slight_smile:

1 Like

so it’s not “très grave”

@Andrew it was really your question ? an printed issue or a question about the use of take ?

Indeed :slight_smile:

let’s play music

s = (scale :b2, :major).take(3)

s.length.times do
  play s.tick
  sleep 0.5

so it works :slight_smile: just the printed result a little broken but repaired now by @ethancrawford but needs to be merged and will be included into next version

1 Like

Thanks everyone.

@nlb to be fair I didn’t think to try playing the notes - I was thrown by the printed output when trying out subsetting for making patterns

1 Like

Well, I tried :joy:
We’re going to aim for an alternative solution that entirely removes the section of code I was editing. Still thinking it’ll probably make it into the next beta version, or next release at the latest - and even if not, at least it’s not technically breaking much :slight_smile:

1 Like

Duuuh …
Would someone(s) carefully explain the problem
to an (evident) idiot ?

If it ain’t broke, dont fix it. :slight_smile:

Classic techie, Ethan, you win todays Internets.


so it works :slight_smile: just the printed result

when we use puts