Syntax error on Rpi 3 but not on Mac OS

Hello,

I have an error which ruins my little project. I can run this code on Sonic Pi 3.2.2 on Mac OS Majove, no error, but on Raspberry Pi 3, Sonic Pi 3.2.2, it doesn’t work.

set :a, [3,5,6,7,8]
a = get :a
b = a[1..]
puts b
# [5,6,7,8]
set :a, b
puts get :a
# [5,6,7,8]

I have syntax error unexcepted ‘]’ on line 3.

It’s annoying because I use to modify Time State var with OSC message like you can see here sonic-pi-music-step-sequencer/FXs.rb at master · coffeecore/sonic-pi-music-step-sequencer · GitHub

On Mac OS, I have Ruby 2.3 and on Rpi is 2.5, but I don’t see anymore diff.

Maybe I can do that by another way.

Thanks you

@athlon64 - is that the full amount of code that you’re trying to run? Given that this particular segment at least looks fine to me, (and runs fine on Windows - I can’t run it on my RPi4 right at the moment, so can’t comment on that) it would be handy to know if there’s any surrounding code that might be causing the issue.

Hello

Code in my initial post doesn’t work on Rpi. Github repo is my full project to show why I use this segment (a[n..]). To run full project, you must use main.rb (change file path in this file). I checked, files are UTF-8 and end line Unix, so I think is good for Linux.

I also commented all include files in main.rb and only let Fxs.rb (I try each files one by one) and always fails on this segment.

Code runs fine on Mac OS and I don’t see another diff than ruby version.
if it runs on Rpi4 will be great news, just to buy one. If not, I will have to remake all :disappointed_relieved:

But, maybe I can do it in a diffrent way, but I don’t know how share var between thread localized in different files.

Thanks you

It’s important to add whilst Sonic Pi is built on top of Ruby, not all Ruby is considered valid Sonic Pi.

There are definitely going to be edge cases where different versions of Ruby don’t quite behave precisely the same. There are also situations where Sonic Pi’s design has deviated away from Ruby’s and there will be incompatibilities and that we simply didn’t consider.

Whilst we don’t (currently) prohibit you from using the general syntactic palette of Ruby, we don’t support anything that’s not explicitly mentioned in our tutorial.

An example of the kind of syntax we don’t currently support is:

b = a[1..]

So, whilst you may use it, you shouldn’t expect it to work consistently on all versions of Sonic Pi. Also, you shouldn’t expect it to continue to work in future versions. We make no guarantees.

1 Like

Hi,

I clean my code to avoid to use lot of Ruby because I read you want do without that, but for my goal, I don’t see how I can manipulate arrays because I try to have variable channels, patterns, steps etc.

I must try to compile Ruby 2.3 on Rpi to reduce environment diff (2 hours to compile so maybe not this evening).

I don’t know if Sonic Pi is the best tool, but I don’t have low-level programming skill and Sonic Pi include all I need concerning audio signal treatment.

Can you make do with switching to using rings? there’s plenty of ring chaining functions that allow you to produce new varieties of rings from existing ones :slight_smile:

I think is the best way to keep working code in future version and on all platforms. I will rewrite all then.

Thanks you.

changing to

set :a, [3,5,6,7,8]
a = get :a
b = a[1..-1]
puts b
# [5,6,7,8]
set :a, b
puts get :a
# [5,6,7,8]

works on a Raspberry Pi wiith the current ruby. 2.5.5p157

1 Like

Another option would be to share what you’re trying to achieve on here and we can all do our best to help you in a way that’s idiomatic with Sonic Pi and will hopefully be future proof :slight_smile:

1 Like

What ? :open_mouth: Why works ? Just the -1 does the job ? I keep your solution if I can’t use ring/map.

@samaaron
I try to code a step sequencer (a little bit like Robin Newman did) with unlimited (depends of platform I suppose) number of channels, patterns and steps (mix between Drumstation and Rubber duck by d-lusion). I want to be able to :

  • add channel (choose synth or sample for this channel)
  • add pattern (represent a bar)
  • add step (musical notes (one or more) or just bool true for sample)
  • change options of synth or sample
  • add FXs on a channel

Code here GitHub - coffeecore/sonic-pi-music-step-sequencer: OSC driven music step sequencer based on Sonic Pi

It’s not really live coding I know :sweat_smile:

I rewrite with ring/map and it runs on Raspberry Pi 3 (See switch_to_ring branch). I must try if @robin.newman suggestion is faster => I don’t think faster.

I remove some loops too (metronome) and (cue)debug log.

Obviously, FXs are the bottleneck, some Timing error : can't keep up... with :slicer FX and sound looks cracking. I have FXs triggered by an eval in a live_loop, si I think the problem is here.

Next step will be to remove/rewrite more simply and keep only what I really need. And try to create FXs around a live_loop