(Help required) Fixing sonic-pi-tool (both versions)

Hi!

Technical specs: MacBook Air (10.14 Mojave), everything is updated (brew packages updated too).

I’ve never took the time to fix my sonic-pi-tool but it is now more necessary than ever. The program works nice except for the most useful command: start-server. Here is a copy of the error log for both versions:

Lpil version:

Failed to load the fast_osc c-extension, falling back to pure Ruby version
Overriding fast_osc c-extension FastOsc::decode_single_message, falling back to pure Ruby version
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- ffi_c (LoadError)
	from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /Applications/Sonic Pi.app/app/server/ruby/vendor/ffi-1.9.17/lib/ffi.rb:6:in `rescue in <top (required)>'
	from /Applications/Sonic Pi.app/app/server/ruby/vendor/ffi-1.9.17/lib/ffi.rb:3:in `<top (required)>'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /Applications/Sonic Pi.app/app/server/ruby/vendor/ruby-aubio-prerelease/lib/aubio/api.rb:1:in `<top (required)>'
	from /Applications/Sonic Pi.app/app/server/ruby/vendor/ruby-aubio-prerelease/lib/aubio.rb:2:in `require_relative'
	from /Applications/Sonic Pi.app/app/server/ruby/vendor/ruby-aubio-prerelease/lib/aubio.rb:2:in `<top (required)>'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /Applications/Sonic Pi.app/app/server/ruby/lib/sonicpi/samplebuffer.rb:17:in `<top (required)>'
	from /Applications/Sonic Pi.app/app/server/ruby/lib/sonicpi/studio.rb:16:in `require_relative'
	from /Applications/Sonic Pi.app/app/server/ruby/lib/sonicpi/studio.rb:16:in `<top (required)>'
	from /Applications/Sonic Pi.app/server/ruby/bin/sonic-pi-server.rb:20:in `require_relative'
	from /Applications/Sonic Pi.app/server/ruby/bin/sonic-pi-server.rb:20:in `<main>'

Emlyn Python version:

Found installation at: /Applications/Sonic Pi.app
Running: /Applications/Sonic Pi.app/server/native/ruby/bin/ruby /Applications/Sonic Pi.app/server/ruby/bin/sonic-pi-server.rb
Traceback (most recent call last):
  File "/usr/local/bin/sonic-pi-tool.py", line 291, in <module>
    cli(obj=None)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/bin/sonic-pi-tool.py", line 256, in start_server
    subprocess.run([inst.ruby_path(), inst.server_path()]).check_returncode()
AttributeError: 'module' object has no attribute 'run'

It might be easy to fix but everything I tried so far was unsuccessful. I’m basically trying to run Sonic-Pi and edit code from the terminal using Vim or any other application. So far, I was just opening the app and letting it run in the background but I want to go one step further.

1 Like

To be honest, this sounds like something Sonic Pi should support natively.

What functionality do you need?

My idea was to start the Sonic-Pi server from the command-line, with the ability to print the log back in the terminal too. By doing so, I might be able to indifferently use different code editors such as Visual Studio Code, Atom, Vim, etc… to play. I’m used to editing text and code using Vim keybindings + it’s easier to manage snippets. I can already do that with the existing packages but I don’t have any visual feedback.

Using sonic-pi-tool, I could launch the process from the Atom or VSCode terminal and keep an eye on it.

Sounds good, although would you only want the log or also the cue log?

Only the logs. I can’t use the english version of Sonic-Pi because my computer is configured in french, so to be perfectly clear, I call “log” the following :

{run: 1, time: 36.25, thread: :live_loop_b}
 └─ synth :fm, {note: 65.0, release: 0.5, amp: 0.125, amp_step: 0.5, pitch_slide: 0.25, pitch: 0.0, note_slide: 0.5, divisor: 0.5, sleep: 0.25, degree: 4, pan: 0}

and “cue log” the following:

/live_loop/metro  []
 /live_loop/metro  []
 /live_loop/b      []

I don’t know if having both is possible but I would definitely prefer the logs only.

EDIT: maybe I should tag @lpil and @emlyn. I definitely think that my configuration must be wrong somehow.

Hi all!

sonic-pi-tool isn’t very clever about starting the server, it just searches for server/bin/sonic-pi-server.rb and executes it. https://github.com/lpil/sonic-pi-tool/blob/35e355dd85693ee0dc63ac8e00aa13311b24e1fd/src/lib.rs#L88-L116

It’s been a while since I looked at how Sonic Pi works but I seem to recall it including a specific version of the Ruby runtime as well as some dependencies. We should probably explicitly use these.

1 Like

The error in the Python version seems to be a Python2/3 incompatibility. I’ve just pushed a change that hopefully should make it compatible with both versions, let me know if it helps.

Sorry, I wasn’t able to test until now. The new change you just pushed works, but the terminal is flooded with an error as I play:

Exception!
Connection refused - send(2)
["/Applications/Sonic Pi.app/app/server/ruby/lib/sonicpi/osc/udp_client.rb:30:in `send'", "/Applic
ations/Sonic Pi.app/app/server/ruby/lib/sonicpi/osc/udp_client.rb:30:in `send'", "/Applications/So
nic Pi.app/server/ruby/bin/sonic-pi-server.rb:456:in `block in <main>'"

When I try to open another terminal to get the logs, I encounter the following error too:

**{run: 1, time: 15.75}**
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/t
hreading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/t
hreading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)

  File "/usr/local/lib/python2.7/site-packages/oscpy/server.py", line 359, in _listen
    cb(*values)
  File "/usr/local/bin/sonic-pi-tool.py", line 150, in handle_multi_message
    Server.printc(prefix, 'multi', line, typ)
  File "/usr/local/bin/sonic-pi-tool.py", line 130, in printc
    r += click.style(txt, **style)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 6: ordinal not in range(128)

It looks like my computer is trying desperately to run Python 2.7 even if I have the last version of Python 3. When I try to to run the following command: python3 sonic-pi-tool.py logs, the following error is printed back:

Traceback (most recent call last):
  File "sonic-pi-tool.py", line 6, in <module>
    import click

ModuleNotFoundError: No module named 'click'

The module click is installed both in my Python 2 and Python 3 package folder via pip.

I’ve been able to do what I intended to do by using both your version and the @lpil version:
— starting the server from your new version. Despite the error messages, it works pretty well.
— opening a new terminal and printing the logs using lpil version.

It looks like it’s still not completely Python 2 compatible… when I get a bit of time I’ll try to look into it some more.
Are you sure you have click properly installed in Python 3? what happens if you run pip3 install click?

Already installed: Requirement already satisfied: click in /usr/local/lib/python3.7/site-packages (6.7).

That’s strange, it looks to me like there must be something up with your Python installation.
I think I might change sonic-pi-tool.py to use argparse instead of click, as that seems to be more standard, so might be less likely to have similar issues.