Norns - How do I listen for incoming MIDI start/stop messages?

I’m working on a norns sequencer that sends MIDI, but I’d also like to have it respond to external gear se ding start/stop commands.

In the “clocks” doc on line I see the functions for

clock.transport.stop()
clock.transport.start()

… but I’m not sure how to implement them.

What is a basic way that I can manage this?

I think you should be able to handle the raw MIDI event with midi.event:


You have to parse through the byte array, but it’s not too bad. The start and stop events don’t have a channel and it looks like they’re 1 byte each:

Start = 11111010 a.k.a 250
Stop = 11111100 a.k.a 252
So just check data[1] for those I think.
2 Likes

No - you don’t need to do that now.

m = midi.connect()
-- too send start/stop you can use these
m:stop()
m:start()

-- to receive you can use this
m.event = function(data)
  local d = midi.to_msg(data)
  -- print something for various data types
  -- ignore clock for the moment but look at other types
  if d.type = "start" then
  -- do stuff
  end
  if d.type = "stop" then
  -- do stuff
  end

otherwise use the clocks module like:

function midi_event(data)
  msg = midi.to_msg(data)
  if msg.type == "start" then
      clock.transport.reset()
      clock.transport.start()
  elseif msg.type == "continue" then
    if running then 
      clock.transport.stop()
    else 
      clock.transport.start()
    end
  end 
  if msg.type == "stop" then
    clock.transport.stop()
  end 
-- etc...

see my MIDI Monitor script for more of that example

4 Likes

Nice! That midi.to_msg looks a lot cleaner than bit-juggling. Just to make sure I’m following, it’s just abstracting these:

  • data[1] == 250
  • data[1] == 252

so you can instead use these (which are more descriptive and nicer):

  • d.type == "start"
  • d.type == "stop"

Is that right?

yeah, pretty much (it’s looking at the hex values instead of decimal) - see midi.lua for full details

1 Like

Perfect! I’ll give that a shot and see how it goes.

Edit:

Works perfectly! Thank you.