Dumb formula if midi.note question

61 views
Skip to first unread message

Joe Citizen

unread,
Nov 8, 2018, 4:27:19 AM11/8/18
to Lightjams
Possibly because it's late at night... but how can I write:  if(midi.note 1,1) then use it as a multiplier[note pressure] to 'this expression' - but if no midi.note(1,1) then use 'this expression' by itself?

Driving me nuts - having figured out I can use functions inside other functions, I'm now wanting to use them as conditional statements. Thanks.

Mathieu

unread,
Nov 8, 2018, 7:29:12 AM11/8/18
to Lightjams
Try something like this:

if(midi.note(1,60), midi.note(1,60)/100, 1)*sin(1)

Where midi.note(1,60) is midi note channel 1 and note 60. Replace sin(1) by "this expression".

The thing to understand is that the "if" function returns the 2nd parameter if the condition is true and it returns the 3rd parameter if the condition is false. The condition is the 1st parameter of the if function.

The midi.note function returns a value between 0 and 100, that's why we need to divide it by 100 in the case we want to use it as a multiplier for another function.

Joe Citizen

unread,
Nov 8, 2018, 3:33:21 PM11/8/18
to Lightjams
,Thank you - this mostly makes sense. What does the '1' represent after the /100 here? The 'if not midi.note(1,60)' return a value of '1'?

Joe Citizen

unread,
Nov 8, 2018, 3:34:15 PM11/8/18
to Lightjams
Also.. can I do this just on the Control channel? i.e. not use the not value at all? Thanks.

Mathieu

unread,
Nov 8, 2018, 3:45:13 PM11/8/18
to ligh...@googlegroups.com
The 1 represents the value returned if the condition is false. So if the midi note is on, the pressure of the midi note divided by 100 is returned. Otherwise, 1 is returned. Then this value is multiplied by your expression. 

Maybe you've missed the coma between the /100 and the 1. The coma is the parameter separator.

Mathieu

unread,
Nov 8, 2018, 3:48:29 PM11/8/18
to Lightjams
Sorry, I don't understand. Where is the not value? Do you mean the else parameter of the if function? What is the control channel? The else parameter is mandatory.

Joe Citizen

unread,
Nov 8, 2018, 4:07:24 PM11/8/18
to Lightjams
Sorry - typing too fast, I meant the note value. I'm wondering if I can use  'midi.channel' instead of a 'midi.note'? Thanks.

Mathieu

unread,
Nov 8, 2018, 4:10:00 PM11/8/18
to Lightjams
The functions you can use are described here: https://www.lightjams.com/commandline.html

midi.channel isn't one of them.

Joe Citizen

unread,
Nov 8, 2018, 4:23:23 PM11/8/18
to Lightjams
Yes, sorry - was just wondering about the relationship between the midi.note value and the corresponding velocity changes - can I assume that (for example) if(midi.note(1,1), midi.note(1,1)/100) is a value that = a 'true' value, rather than being sensitive to velocity changes inherent in (1,1)? If the value does relate to velocity changes I was wondering about using the channel as a trigger value, as it doesn't change. Thanks. 

Joe Citizen

unread,
Nov 8, 2018, 4:26:55 PM11/8/18
to Lightjams
What I'm trying to do is:

1. use a midi note as an on/off switch
2. use a midi note to trigger different inputs on an activation grid using the y parameter - and then return to the start of the grid 

Hope that makes sense?

Mathieu

unread,
Nov 8, 2018, 4:36:21 PM11/8/18
to Lightjams
A MIDI note has a value between 0 and 127, which is translated to 0%-100% in Lightjams. When at 0%, the note is off. All other values means the note is pressed and the value represents the velocity.

To use it as a on/off switch, you can just use: midi.note(1,1) > 0

This will give 100% when the midi note value (velocity )is greater than 0%.

You can use the midi note value and link it to a source's y slider if you want. When the note is off, the source automatically goes back to the start of the grid, since 0% is the the y position 0.

Joe Citizen

unread,
Nov 8, 2018, 5:01:18 PM11/8/18
to Lightjams
Fantastic - thank you. I really should've tried to learn math more when I was younger - I understand logic, but operators are weird. 

So to hold the last position I use latchdelta? e.g. [Assuming a grid 10 squares high]:

if (midi.note(1,1) > 0, midi.note (1,1)/100*10,0)+latchdelta(>0,10) ???

I understand that when the note is off the the Y slider will return to the start - but how do I make it loop back to a start position that isn't 0? i.e. Go back to a nominated start position? Introduce another 'If' statement? e.g. for the above example that uses 10 squares high grid, I would write:

if (midi.note(1,1) > 0, midi.note (1,1)/100*10,0)+latchdelta(>0,10) if(100, 10) ???

Thanks for all your help.

Joe Citizen

unread,
Nov 8, 2018, 5:28:07 PM11/8/18
to Lightjams
This is what I'm trying to do...
Tabulated switching grid.jpeg

Mathieu

unread,
Nov 8, 2018, 5:45:17 PM11/8/18
to Lightjams
>> how do I make it loop back to a start position that isn't 0

You add a value. Try adding 10 and you'll see. Then you'll understand what yToPercent does. In your case, if you want to start at the cell 2, you add yToPercent(2).

if (midi.note(1,1) > 0, midi.note (1,1)/100*10,0)+latchdelta(>0,10) ?

Sorry, this doesn't work that way. Please go over the examples to better understand how it works: https://www.lightjams.com/commandline.html

And remember that all sliders want a percent value, event for x and y sliders. For the y slider, 0% means at the bottom and 100% means at the top. It doesn't matter whether your grid height is 10 or 1000.

Joe Citizen

unread,
Nov 8, 2018, 6:24:32 PM11/8/18
to Lightjams
Thank you. I think this is starting to make sense. Just so I understand, what you're telling me is: 

if(midi.note(1,1)>0, midi.note(1,1)/100*10,0)+ytopercent(1) 

Then this is the same as saying: when midi note 1 is activated (goes above zero), divide this by 100 (to give the percentile) and multiply by 10, otherwise return zero, then whatever that result is, add the y value as a percentile... ... but does this mean that the activated midi note is turned into a percentile and multiplied by 10, then 1 is added (returning the percentile multiplied by 10 plus 10%)? And when the y value becomes 100% (at the top) and I want it to return to the zero position  (loop), the '110%' loops back to the zero position?

Hope this makes sense? I'm trying to step through activations as part of a grid using the y parameter triggered by a midi.note, and when it reaches 100% (the top), it returns to the zero (bottom) position.

Thanks again for all your help.

Mathieu

unread,
Nov 8, 2018, 7:07:03 PM11/8/18
to Lightjams
A few notes:

this 

if(midi.note(1,1)>0, midi.note(1,1)/100*10,0)

is equivalent to

midi.note(1,1)/100*10

In other words, you don't seem to need to use the if function since when the midi note is 0, you want 0.

midi.note(1,1)/100*10 is equivalent to midi.note(1,1)/10 since /100*10 (divide by 100 and multiply by 10) can be simplified to /10 (divide by 10).

But then I'm not sure why you want to take the midi note ranging from 0-100 and make it to go from 0 to 10 ?

Assuming that's what you want, then you add the value equivalent to 1 cell vertically with the yToPercent(1). Then you want it to wrap and go back to 0 when going over 100. 

Are you sure you're not looking for a way to move one cell up each time you press a MIDI note and then wrap around when reaching the top?

Joe Citizen

unread,
Nov 8, 2018, 8:04:40 PM11/8/18
to Lightjams
That's exactly what I'm trying to do! Yes, I want it to move one cell up and then wrap around when it gets to the top - sounds like I'm trying to be too complicated about it.

I'm moving up by 10% each time as that gives me 10% of a grid with 10 cells - trying to move one cell up at a time over a percentage range from bottom to top.

Thanks for the info about not needing to use 'if' (I'm realising this is almost entirely math, not really programming).

So your saying that [in a grid that is 10 cells high] midi.note(1,1)/10+yToPercent(1) will move one cell up each time a MIDI note is pressed and then wrap around when reaching the top? 

Using the 'if' statement (here) becomes useful only when I'm determining a threshold value based on velocity. (?)

Nearly there..



0
 
0

Mathieu

unread,
Nov 8, 2018, 8:39:48 PM11/8/18
to Lightjams
Then you're looking for something like:

ytopercent(counter(0,grid.lasty, onbeat(midi.note(1,1))))

The key is the counter function. Each time the midi note is pressed, the counter is incremented. The counter function automatically restarts when reaching the end.

Joe Citizen

unread,
Nov 8, 2018, 8:49:45 PM11/8/18
to Lightjams
Aha!! Thank you! Simple way to do what I've been trying to do in a complicated manner! I will study this further - thank you Mathieu.

Joe Citizen

unread,
Nov 8, 2018, 9:05:29 PM11/8/18
to Lightjams
Last quick question - 

if(midi.note(1,1)>0,100,0) is the same as saying: if midi note is greater than zero, make it 100, otherwise return 0? This is the same as using the midi note as a simple 'on' or 'off'?

Mathieu

unread,
Nov 8, 2018, 9:29:58 PM11/8/18
to ligh...@googlegroups.com
Yes. And it's also the same as simply:

midi.note(1,1)>0

For a simple on/off, you don't need the "if".

Joe Citizen

unread,
Nov 8, 2018, 9:51:02 PM11/8/18
to Lightjams
Thanks very much. It's one thing to learn how to fix the immediate problem, but I really appreciate how you try to give the knowledge of principles that can be applied elsewhere. Very cool.
Reply all
Reply to author
Forward
0 new messages