sonic-pi icon indicating copy to clipboard operation
sonic-pi copied to clipboard

Midi events: values assigned to two variables (syntax query)

Open jonnyhotchkiss opened this issue 2 years ago • 2 comments

https://github.com/sonic-pi-net/sonic-pi/blob/10de0b5a225ad9f1fcf58ce675b34300a829ff27/etc/doc/tutorial/11.1-MIDI-In.md?plain=1#L37

note, velocity = sync "/midi:nanokey2_keyboard:0:1/note_on"

I've just found this info, and wanted to query the syntax.

Assume the first and second values are accessed via 'index' eg :0 and :1

I kind of expected another semi colon, to indicate in the assignment statement which values are assigned to which var (note and Velocity)

Is this standard ruby, or is someone able to further breakdown what's going on here?

Many thanks!

jonnyhotchkiss avatar Nov 02 '23 09:11 jonnyhotchkiss

it looks like array destructuring (but I don't know what the sync function returns, or much Ruby)

$ irb
irb(main):001:0> a, b = [1, 2]
=> [1, 2]
irb(main):002:0> a
=> 1
irb(main):003:0> 2
=> 2

maybe this article can help: https://dev.to/ridhwana/destructuring-in-ruby-53j0

nicoder avatar Nov 02 '23 17:11 nicoder

Actually I think the 1 is the channel being used, rather than an index.  into the data supplied. If you plug a midi keyboard in a play notes on different channels you’ll see this change. I think the first 0 is because as part of the source device so that if you have two identical devices connected they can be differentiated. Sent from my iPhoneOn 2 Nov 2023, at 09:33, jonnyhotchkiss @.***> wrote: https://github.com/sonic-pi-net/sonic-pi/blob/10de0b5a225ad9f1fcf58ce675b34300a829ff27/etc/doc/tutorial/11.1-MIDI-In.md?plain=1#L37 note, velocity = sync "/midi:nanokey2_keyboard:0:1/note_on" I've just found this info, and wanted to query the syntax. Assume the first and second values are accessed via 'index' eg :0 and :1 I kind of expected another semi colon, to indicate in the assignment statement which values are assigned to which var (note and Velocity) Is this standard ruby, or is someone able to further breakdown what's going on here? Many thanks!

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>

rbnpi avatar Nov 03 '23 00:11 rbnpi