noteoff-noteon with Custom MIDI noteout

Discuss problems and solutions.
Post Reply
AkaMed
Newbie
Posts: 37
Joined: 31 Mar 2014 00:26

noteoff-noteon with Custom MIDI noteout

Post by AkaMed »

Hello,

I´ve been a time without programming Lemur and now I am back, trying to create a custom MIDI noteout PAD.
The problem is that I am not being able to hold pressed one pad for triggering an arpeggiator in Ableton Live. It just sends 'noteon' and automatically sends 'noteoff', even if I didn´t release my finger. It doesn´t hold the notes.
I´ve been trying a lot of combinations and I know it is a basic aproach, but I am not able to achieve this.

My last test is the project that I attach here...
I need to use that custom midi because the code will be part of one bigger project where I can choose the MIDI target, cannel, etc. from my template´s screen.

Any ideas?

Thanks!
Attachments
PADs custom MIDI3.jzml
(4.41 KiB) Downloaded 67 times
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: noteoff-noteon with Custom MIDI noteout

Post by oldgearguy »

your code is looping through all 12 pads and every time it sees one or more on, sends a MIDI ON note event... to the first one (firstof(x)) that is on.

Let's walk through the loop manually.

Say you press and hold the first pad down (internal number is 0).
The loop starts - m=0, m < 12.
So, x[m] == 1 is true and a note ON is sent to pad_notes[firstof(x)] which is the 0th position in the array.

This all works.

Now m = 1.

x[m] == 1 fails, so the else code is invoked and it sends a note OFF to pad_notes[firstof(x)] which is the 0th position in the array...

This is why it fails.

If you don't care about sending extra note off's, you can simplify the code immensely:

velocity = 127;
for (m=0; m<12; m++)
noteout(MIDI_target, pads_notes[m], (velocity*Pads.x[m]),MIDI_channel_drums);


So if the pad is pressed (it's x value is 1) velocity * 1 = velocity. If the pad is not pressed (x=0) it's velocity is velocity * 0 = 0 which is a note off.

If you want to thin the data even more, you can capture the current on/off state of all the pads and then when the script is called, only send messages for the changed ones and then save off the new current state
AkaMed
Newbie
Posts: 37
Joined: 31 Mar 2014 00:26

Re: noteoff-noteon with Custom MIDI noteout

Post by AkaMed »

Thanks oldgearguy,
it works perfectly. I was actually trying to get that without any loop, but I tried it with a loop in my last test and that was what I attached.
I didn´t think about it...I was blocked trying different things.
Thank you very much for your great help!!!
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: noteoff-noteon with Custom MIDI noteout

Post by oldgearguy »

Glad it worked out for you. Even though I've written a lot of code in my life, I still find it helpful to manually walk through sections like that to verify it's really doing what I think I'm asking it to do.

The beauty of Lemur is that it's very quick to write something and test it out to see how it works. I usually start with 3 or 4 Monitor objects along the top or bottom of the screen watching various values as I develop a script. It's not quite as good as a full debugging environment, but it does help (me anyway).

Here's the followup on saving off the current state:

if (under the Pads object) you create a variable called savedP and set the initial value to 0, then modified the conditional in a() to something like this:

for (m=0; m<12; m++)
if (Pads.x[m] != savedP[m])
noteout(MIDI_target, pads_notes[firstof(x)], (velocity*Pads.x[m]),MIDI_channel_drums);

savedP = Pads.x;

you could only send out MIDI messages for the changed pad(s).

Put a Monitor object in the container (I used width 330, height 40, 12pt font, 0 precision) and add this line above the 'for' statement to see what is happening:

Monitor.value = {'saved: ', savedP, ' x: ', x};
AkaMed
Newbie
Posts: 37
Joined: 31 Mar 2014 00:26

Re: noteoff-noteon with Custom MIDI noteout

Post by AkaMed »

I will try that oldgearguy, I looks like it is even better for my goals.
Thanks for your tips and ideas!
AkaMed
Newbie
Posts: 37
Joined: 31 Mar 2014 00:26

Re: noteoff-noteon with Custom MIDI noteout

Post by AkaMed »

Yes it works, but I had to modify it (pads_notes[m] instead of pad_notes[firstof.x]:

decl velocity, note, m;
velocity = pow(Velocity.x,2)*127;
//velocity=(Velocity.x)*127;
for (m=0; m<12; m++)
if (Pads.x[m] != savedP[m])
noteout(MIDI_target, pads_notes[m], (velocity*Pads.x[m]),MIDI_channel_drums);
savedP=Pads.x;

I attach the module for if anybody wants to work with it. It has an exponential fader (I prefer it) for the velocity of the pads.
Attachments
PADs custom MIDI3.jzml
(4.31 KiB) Downloaded 89 times
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: noteoff-noteon with Custom MIDI noteout

Post by oldgearguy »

That's what I get for not looking at which file I was cutting and pasting from. Glad you got it sorted out.
AkaMed
Newbie
Posts: 37
Joined: 31 Mar 2014 00:26

Re: noteoff-noteon with Custom MIDI noteout

Post by AkaMed »

That's what I get for not looking at which file I was cutting and pasting from. Glad you got it sorted out.
Usually happens :)
Thank you!
:D
Post Reply