Sync, get and lost midi notes

Hello!

First, let me say thank you for sonic pi: It sweetened my last month, and I have a hard time to put it aside. Even at office, where I should do other stuff.

Ok, my problem is this:
I got two identical midi controllers, one at the office (win10), and one at home (osx). They both use the same live_loop to get the midi_notes. It seemed to work fine at home, but when I tried the today program at office, the behaviour was … unexpected.

ok, this is the setting:

I got a button on my midi-controller, that sends out two notes. One for the selected mode, and one for the actual button push.

It looks like this on the controller - in case you wonder -:
[] CUE (led/midi65)
[
] LOOP (led/midi66)
[x] SAMPLE (led/midi67)
[button midi9]

with x being a lit led. So note 65,66 and 67 tell me what the selected item is.

Looks like this in cues-log:

/midi/dj_tech_dj_for_all/3/1/note_on [9, 127]
/midi/dj_tech_dj_for_all/3/1/note_on [67, 127]
/midi/dj_tech_dj_for_all/3/1/note_on [9, 0]
/midi/dj_tech_dj_for_all/3/1/note_on [9, 127]
/midi/dj_tech_dj_for_all/3/1/note_on [65, 127]
/midi/dj_tech_dj_for_all/3/1/note_on [9, 0]
/midi/dj_tech_dj_for_all/3/1/note_on [9, 127]
/midi/dj_tech_dj_for_all/3/1/note_on [66, 127]
/midi/dj_tech_dj_for_all/3/1/note_on [9, 0]
/midi/dj_tech_dj_for_all/3/1/note_on [9, 127]
/midi/dj_tech_dj_for_all/3/1/note_on [67, 127]
/midi/dj_tech_dj_for_all/3/1/note_on [9, 0]

I get two notes with v127 for every button-down of button 9, and one v0 for the button9-up.


This is the code:

DJ Tech Dj for all test

midi_connection_note = “/midi/dj_tech_dj_for_all///note_on”

live_loop :INGOInput do
  #use_real_time
  n,v = sync midi_connection_note
  
  
  puts n
  if v == 127 then
    case n
    
    # wemnn sequenz läuft, dann laut spielsheibe ton abspielen
    # wirklich sichern erst bei loslassen
    
    when 65 # SAMPLE, im Edit-mode
      puts "SET SAMPLE MODE"
      set :mode,  :mode_sample
    when 67 # CUE, im Edit-mode
      puts "SET TON MODE"
      set :mode, :mode_TON
    when 66 # LOOP, im Edit-mode
      puts "SET LOOP MODE"
      set :mode, :mode_LOOP
    end
  end
  # sleep 0.01
end

This code does very nice switching between the modes on my home-pc. Never looked back, because it just worked.

But at office, it does not work.
When I push the button, it puts out 9s with every button press, but it rarely goes into the case. Just in about 1 out of 10 times.

I dont understand why.

when to use n,v= get midi, and when to use n,v = sync midi?

I really dont understand why my code does not work …

2 Likes

seems to work with

use_real_time
n,v = get midi_connection_note
sleep 0.1

… still, both solutions make me unhappy.

I dont understand why sonicPi reacts differently on different OSses.

I dont understand when to use get or sync
Please help me undersand wheen to use them.

Hi there, have you read the built-in documentation and examples for sync and get? Also, the tutorial pages might be helpful: http://sonic-pi.net/tutorial.html#section-10

In essense, get is to look up the last value and sync is to wait for the next value. It’s important to note that get may ‘miss’ events as multiple events might have been received since the last event and you only see the latest one). However, sync should never miss an event.

Additionally, get should be used alongside sleep whereas sync is a special kind of sleep, so should rarely be used in the same live_loop as a call to sleep. This is because get never waits for the next event and sync “sleeps” until the next event. If multiple events are received in the same logical timestamp, then sync will return the next one in order determined by sorting them in a deterministically.

It’s very strange to me that you’re observing different behaviours across different operating systems. This is the first I’ve heard of this. Could you reduce your code to the smallest possible fragment that has this behaviour so I could examine it? Remember, any live loops with a sync should not include a sleep for the reasons stated above and in the documentation :slight_smile:

Thanks!
I heard that, and I am sure I read it … sorry for asking again, cause you had to use up valuable time you could instead use for more happy stuff ! :frowning: :slight_smile:

Yes, it was very surprising to find out that my program does not work as expected when I started it today at office. Was working yesterday at home, and I just copied it. I invested some minutes to understand why (sometimes) nothing is happening (when the button is pressed).

I make sure to deliver a proof that the same program works different on different OSes… :slight_smile:
How can I? Cues-log + protokoll + source snippet enough?

Thanks for far, and thanks for helping me out! :smiley:

yes -… sync misses nearly all notes on the win pc. Can proof behaviour.

there, I fixed it. Not sure if insane or necessary hack…

(just kidding. Its a hack. But that makes the whole program work on windows, I just found out. No complains so far.)

This definitely looks like a bug :frowning:

Can you confirm that it’s still badly behaved if you take the * matchers out?

Also, can you confirm that the sleep line really is a comment?

It was a comment. Restarted sonicPi, started the loop new. Will Test the same program on OSX later.

In the screenshot you see the rare case of a number other than 9 hitting sync. It happens every 10 to 100 button presses. Sometimes.

Definitely a bug. Sorry about this.

don’t sell yourself short. Its still the best videogame out there. Thanks so much for it. :slight_smile:

1 Like

just to confirm the behaviour on my mac:

So that looks just fine on macOS.