Pot touch - how to send a MIDI message

New to Lua programming, I’m maximising what can be achieved with the E1 :wink:

How to use:

events.subscribe(POTS)
events.setPort(PORT_1)

function events.onPotTouch(potId, controlId, touched)

and send a Control Change or
MIDI Note On on Pot Touched
MIDI Note Off on Pot release

Thanks!

I think what you’re looking for is covered here: Preset Lua extension | Electra One Documentation

For sending a MIDI Note On on key 0 on channel 1 with a velocity of 127 on pot touch and sending a MIDI Note Off on key 0 on channel 1 with a velocity of 0 on pot release, do something like the following:

events.subscribe(POTS)

function events.onPotTouch(potId, controlId, touched)
  if touched == true then
    midi.sendNoteOn (PORT_1, 1, 0, 127)
  else
    midi.sendNoteOff (PORT_1, 1, 0, 0)
  end
end
1 Like

Closer… @Mint-Gecko

But how to give
midi.sendNoteOn (PORT_1, 1, 0, 127)
to a specific Pot? example Pot1 = C-2, Pot2 = C#-2 etc…

In this specific case, I’d use a list:

PotsToKeys =
{
  -- Send note 64 when touching pot 1
  64,
  -- Send note 32 when touching pot 2
  32,
  -- You get the idea, fill the remaining 10 pots
}

function events.onPotTouch(potId, controlId, touched)
  if touched == true then
    -- we use potId+1 because Lua lists start at 1 but potIds start at 0
    midi.sendNoteOn (PORT_1, 1, PotsToKeys[potId+1], 127)
  else
    midi.sendNoteOff (PORT_1, 1, PotsToKeys[potId+1], 0)
  end
end

2 Likes

Yuhhuh!! we can have fun!!
Thanks @Mint-Gecko ! :beer: or :chocolate_bar: or both :wink:

1 Like

We always want more :wink:

Now, as it is, all pages have the Pots sending the same Notes (disregarded of what control is on screen:

  • How to combine Pots with say, ControlId?
  • different pages > different octaves?
  • this could give us control over Velocity (controlled by a fader )

Maybe you could split the pots across MIDI channels. That would give you 36 keys per pot/channel. Should look like this:

local controlset = pages.getActiveControlSet ()
local page = pages.getActive():getId()
midi.sendNoteOn (port, potId+1, controlset*page, 127)

Thanks once more !

OK I think this I can understand,

… you lost me here…

Ah yeah, it’s actually not quite true what I wrote. The idea is this:

Touching knob 1-12 on the first page with control set 1 will give you MIDI key 1 on channels 1-12.

Touching knob 1-12 on the first page with control set 2 will give you MIDI key 2 on channels 1-12.

Touching knob 1-12 on the first page with control set 3 will give you MIDI key 3 on channels 1-12.

Touching knob 1-12 on the second page with control set 1 will give you MIDI key 4 on channels 1-12.

You get the idea… should look like this:

local controlset = pages.getActiveControlSet ()
local page = pages.getActive():getId() - 1
midi.sendNoteOn (port, potId+1, controlset + (page*3), 127)
1 Like

Thanks for following up @Mint-Gecko, but I can’t “cook” this ingredients up;
I get the strangest errors, or nothing at all ;-(

Combine the list

PotsToKeys =
-- then 
`function events.onPotTouch(potId, controlId, touched)`

with your last post?

I don’t think the list is going to be useful in that scenario. Why would you want to use it?

Maybe you didn’t set the port to the one you want to use or you forgot to subscribe to the POTS event. The entire script should look like this:

events.subscribe(POTS)

function events.onPotTouch(potId, controlId, touched)
  local controlset = pages.getActiveControlSet () - 1
  local page = pages.getActive():getId() - 1
  
  if touched == true then
    -- we use potId+1 because Pots start at 0 while MIDI channel starts at 1
    midi.sendNoteOn (PORT_1, potId+1, controlset + (page*3), 127)
  else
    midi.sendNoteOff (PORT_1, potId+1, controlset + (page*3), 0)
  end
end

EDIT: Here’s a working preset with the code from above: Electra One App

I’m learning !! thanks for the examples :wink:

Notes now start at C-2, is there a way to change this? the list was cool in a way you choose the notes to your desire ;-), it could be arbitrary, now its in order.

I see that changing (page*3) say to (page*1) its chromatic across pages, the same way (page*12) goes in octaves - thats nice !

Its a shame you can’t change pages while pot is touched…

I still would like Pot touched only on Page 2 notes (C2-G3-E1-F5-C3-A4) top row, and no notes on bottom row…

P.S. ohhh and what about Screen Faders affect notes touched, say CC74 ?

If you still want to control the actual note with a list, you can do something like this:

events.subscribe(POTS)

PotsToKeys =
{
  -- Send note 64 when touching a pot on control set 1 on page 1
  64,
  -- Send note 32 when touching a pot on control set 2 on page 1
  32,
  -- Send note 16 when touching a pot on control set 3 on page 1
  16,
  -- Send note 15 when touching a pot on control set 1 on page 2
  15,
  -- you'll need 12 pages x 3 control sets = 36 entries in this list
}

function events.onPotTouch(potId, controlId, touched)
  local controlset = pages.getActiveControlSet () - 1
  local page = pages.getActive():getId() - 1
  
  if touched == true then
    -- we use potId+1 because Pots start at 0 while MIDI channel starts at 1
    midi.sendNoteOn (PORT_1, potId+1, PotsToKeys[controlset + (page*3)], 127)
  else
    midi.sendNoteOff (PORT_1, potId+1, PotsToKeys[controlset + (page*3)], 0)
  end
end

I still would like Pot touched only on Page 2 notes (C2-G3-E1-F5-C3-A4) top row, and no notes on bottom row…

You can easily add another if statement if you only want this to happen on on page 2 top row only:

if controlset == 1 and page == 1 then
  -- the "if touched == true then" block from the code example above goes here
end

P.S. on and what about Screen Faders affect notes touched, say CC74 ?

Not sure what that means.

2 Likes

Pot touch generates a note and knob rotate generates MIDI CC74 (relative to that note)

Will go check your new stuff :wink: thanks!!

@Mint-Gecko
got this error sorry,

error running function 'onPotTouch': ctrlv2/p045.lua:57: bad argument #-2 to 'sendNoteOff' (number expected, got nil)

Does it work if you remove the - 1 part from the controlset variable definition?

yes, but only on page 1.
All other I get that same error…

@Mint-Gecko
now this is working!!!:

events.subscribe(POTS)

PotsToKeys =
{
  -- Send note 64 when touching a pot on control set 1 on page 1
  64,
  -- Send note 32 when touching a pot on control set 2 on page 1
  32,
  -- Send note 16 when touching a pot on control set 3 on page 1
  16,
  -- Send note 15 when touching a pot on control set 1 on page 2
  15,
  -- you'll need 12 pages x 3 control sets = 36 entries in this list
  40,
  41,
  42,
  43,
  44,
  45,
  46,
  47,
  48,
}

function events.onPotTouch(potId, controlId, touched)
  local controlset = pages.getActiveControlSet ()
  local page = pages.getActive():getId()
  
  if touched == true then
    -- we use potId+1 because Pots start at 0 while MIDI channel starts at 1
    midi.sendNoteOn (PORT_1, potId+1, PotsToKeys[controlset + (page*1)], 127)
  else
    midi.sendNoteOff (PORT_1, potId+1, PotsToKeys[controlset + (page*1)], 0)
  end
end
1 Like