sonic-pi-net / sonic-pi

Code. Music. Live.
https://sonic-pi.net
Other
10.76k stars 922 forks source link

Midi in events not triggering #2385

Closed sanhuaaan closed 4 years ago

sanhuaaan commented 4 years ago

When using a midi controller, the midi events can be seen on the cue log, but they're not syncing with live_loops. ("play 60" line is never happening)

live_loop :loop_control do
  sync "/midi:launch_control:0:14/note_on"
  play 60
end

Sonic Pi version: 3.2.2 OS: Windows 8.1

server-output.log:

Sonic Pi server booting...
This is version 3.2.0 running on Ruby 2.7.1.
The time is 2020-05-10 12:29:55 +0200
Using primary protocol: udp
Detecting port numbers...
Listen port: 51235
  - OK
Scsynth port: 51237
  - OK
Scsynth send port: 51237
  - OK
OSC cues port: 4560
  - OK
Erlang port: 51240
  - OK
OSC MIDI out port: 51238
  - OK
OSC MIDI in port: 51239
  - OK
Websocket port: 51241
  - OK
Opening UDP Server to listen to GUI on port: 51235
Started [3660] [-] "C:\Program Files\Sonic Pi\app\server\native\scsynth.exe" -u 51237 -m 131072 -a 1024 -D 0 -R 0 -l 1 -i 16 -o 16 -U "C:/Program Files/Sonic Pi/app/server/native/plugins/" -b 4096 -B 127.0.0.1 [-] C:/Users/jsanjuan/AppData/Local/Temp/sonic-pi-pids/3660
Started [2960] [-] "C:/Program Files/Sonic Pi/app/server/native/erlang/bin/erl.exe" -noshell -pz "C:/Program Files/Sonic Pi/app/server/erlang" -s pi_server start 51240 4560 51235 [-] C:/Users/jsanjuan/AppData/Local/Temp/sonic-pi-pids/2960
Started [2640] [-] 'C:/Program Files/Sonic Pi/app/server/native/osmid/o2m.exe' -L -b -i 51238 -O 51239 -m 6 [-] C:/Users/jsanjuan/AppData/Local/Temp/sonic-pi-pids/2640
Started [1164] [-] 'C:/Program Files/Sonic Pi/app/server/native/osmid/m2o.exe' -t /midi:$n:$i:$c/$m -b -o 51239 -m 6 'Sonic Pi' [-] C:/Users/jsanjuan/AppData/Local/Temp/sonic-pi-pids/1164
Starting Server Runtime
Booting server...

Booting Sonic Pi
----------------

Booting on Windows
Boot - Starting the SuperCollider server...
Boot - C:/Program Files/Sonic Pi/app/server/native/scsynth.exe -u 51237 -m 131072 -a 1024 -D 0 -R 0 -l 1 -i 16 -o 16 -U C:/Program Files/Sonic Pi/app/server/native/plugins/ -b 4096 -B 127.0.0.1
Boot - SuperCollider booted successfully.
Boot - Connecting to the SuperCollider server...
Boot - Sending /status to server: 127.0.0.1:51237
Boot - Receiving ack from scsynth
Boot - Server connection established
Studio - Initialised SuperCollider Audio Server v3.11.0
Studio - Resetting server
Studio - Studio - clearing scsynth
Studio - Studio - allocating audio bus
Studio - Studio - Create Base Synth Groups
Studio - Starting mixer
Studio - Starting scope
"C:/Program Files/Sonic Pi/app/server/native/erlang/bin/erl.exe" -noshell -pz "C:/Program Files/Sonic Pi/app/server/erlang" -s pi_server start 51240 4560 51235
Studio - Spawning o2m with:
    'C:/Program Files/Sonic Pi/app/server/native/osmid/o2m.exe' -L -b -i 51238 -O 51239 -m 6
Studio - Spawning m2o with:
    'C:/Program Files/Sonic Pi/app/server/native/osmid/m2o.exe' -t /midi:$n:$i:$c/$m -b -o 51239 -m 6 'Sonic Pi'
Studio - Initialised MIDI subsystems
This is Sonic Pi v3.2.2 running on windows with ruby api 2.7.0.
Sonic Pi Server successfully booted.
mtrifin commented 4 years ago

Hi,

Had the same issue with a Behringer, this didn't work in version 3.2:

sync "/midi:x-touch_mini:0:11/note_on"

Then I try tried using the wildcard described here and manage to receive midi using this sync "/mid*/note_on"

So I continued until reaching this: sync "/midi:x-touch_mini:0:*11/note_on"

So I guess there are some characters missing but couldn't find which one

Hope this helps

samaaron commented 4 years ago

In both cases, what do you see in the cue log?

mtrifin commented 4 years ago

In clue log I see this: "/midi:x-touch_mini:0:11/note_on"

ninjudd commented 4 years ago

I am having a similar issue with events like this: /midi:ddj-1000:0:10/note_on

Adding a * to my pattern fixes it, but I don't understand why. For example:

sync "/midi:ddj-1000:*:10/note_on" # works
sync "/midi:ddj-1000:0:10/note_on" # does not work
samaaron commented 4 years ago

I think it’s likely to be the hyphen which is interpreted as a regex like range symbol. It probably should be converted to an underscore along with other special chars.

I’ll look into it later tonight :-)

samaaron commented 4 years ago

I'm pretty sure the issue is that osmid, the c++ process which converts MIDI to OSC isn't replacing the - with _ when it converts messages to "safe OSC strings". Here's the specific part of the code where this happens:

https://github.com/llloret/osmid/blob/master/src/utils.cpp#L57

If you're feeling brave, you can add another line here to do the replace and then rebuild osmid (a simple cmake build process), drop the new m2o binary into app/server/native/osmid and run again.

I'll also do some more tests later to see if I can replicate the error and determine whether this fixes things.

llloret commented 4 years ago

I'll have a look later today and fix it.

On Sat, 6 Jun 2020, 19:36 Sam Aaron, notifications@github.com wrote:

I'm pretty sure the issue is that osmid, the c++ process which converts MIDI to OSC isn't replacing the - with _ when it converts messages to "safe OSC strings". Here's the specific part of the code where this happens:

https://github.com/llloret/osmid/blob/master/src/utils.cpp#L57

If you're feeling brave, you can add another line here to do the replace and then rebuild osmid (a simple cmake build process), drop the new m2o binary into app/server/native/osmid and run again.

I'll also do some more tests later to see if I can replicate the error and determine whether this fixes things.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/samaaron/sonic-pi/issues/2385#issuecomment-640101127, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJOL45R5N6U4NW7KLKUWILRVKEC5ANCNFSM4M5F7T5A .

samaaron commented 4 years ago

@llloret thanks! I'm super happy to send a PR if this is indeed the issue.

To be specific, this isn't really a problem with osmid per se, it's more that it's likely an issue with how the generated MIDI names interact with Sonic Pi's time-state OSC-like pattern matching system.

llloret commented 4 years ago

I would happily accept a pr :), of course

On Sat, 6 Jun 2020, 19:41 Sam Aaron, notifications@github.com wrote:

@llloret https://github.com/llloret thanks! I'm super happy to send a PR if this is indeed the issue.

To be specific, this isn't really a problem with osmid per se, it's more that it's likely an issue with how the generated MIDI names interact with Sonic Pi's time-state OSC-like pattern matching system.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/samaaron/sonic-pi/issues/2385#issuecomment-640101691, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJOL42OKQHTJWRAAU5P6YTRVKET7ANCNFSM4M5F7T5A .

samaaron commented 4 years ago

OK, I think I have found the issue.

I believe that osmid not converting - to _ is actually ok, as the - is only activated within [ ] pairs which are already sanitised. So a stand-alone - outside of [ ] should be harmless.

However, I did have some very old code lying around which was me playing with an attempt to emulate Clojure-like namespace symbols. It was super hacky at the time and I have no idea how it managed to stay in the codebase unused for so long.

It essentially modified the raw code as a text string with no regard for syntax and converted :foo: to a special namespaces symbol - even if it was embedded within a Ruby string.

I've now removed this code, so won't be part of any future release.

To test that this fixes things for you in the meantime, you can manually edit your code. Head to this file:

app/server/ruby/lib/sonicpi/preparser.rb

and remove this line (should be on line 27):

rb.gsub!(/:([a-zA-Z0-9\!\?=_]+(:[a-zA-Z0-9\!\?=_]+[a-zA-Z0-9\!\?=_])+)/){|s| "::SonicPi::SPSym.new('#{$1.split(':').join(' : ')}')"}        

Then restart Sonic Pi and let me know if that fixes things for you :-)

mtrifin commented 4 years ago

Removing that line works for me

Thanks

samaaron commented 4 years ago

Closing this - Fixed in 8cfc2f6545da2547d7358210f81e83ea354dfe2d