Send pitch bend with lemur scripting (MIDI programming ?)

Discuss Lemur and share techniques.
Post Reply
Traxus
Regular
Posts: 211
Joined: 30 Nov 2012 06:19
Location: Detroit
Contact:

Send pitch bend with lemur scripting (MIDI programming ?)

Post by Traxus »

I would like to send pitch bend signals via scripting. I was able to findthis thread on another forum, which should be everything that I need spare my general ignorance towards the nuts and bolts of general midi programming. (The whole MSB/LSB thing has me confused)...

Basically, I have a pair of faders, Coarse and Fine, that combine to make a value between 0 and 1, and I want to interpolate this value (pitchControlX) into a pitch bend message.
PitchControl.png
PitchControl.png (14.45 KiB) Viewed 4063 times
I would like to cannibalize these settings into the code:
PitchBendSettings.png
PitchBendSettings.png (9.11 KiB) Viewed 4063 times
According to the thread linked above, the target for pitch bend is 224... but what do I do for x and y in this snippiet?:

Code: Select all

midiout(2,{224,x,y});
I know a quick work around would be to map pitchControlX into a third, invisible fader, and then set the pitch bend midi signal with the GUI as per the second photo, but this object is going to be re-used and I would like to be able to set a variable to control the midi channel...

Thanks
Traxus
Regular
Posts: 211
Joined: 30 Nov 2012 06:19
Location: Detroit
Contact:

Re: Send pitch bend with lemur scripting (MIDI programming ?

Post by Traxus »

Well, after a few hours of reading and random plug and chug this is what I ended up with... This maps it from 0-127, which is okay...

From What I understand, it is possible to use values greater than 127 (ie the 16383 in the second image of my first post) which is ideal for something as fine tuned as this. Obviously, having 16000 possible steps allots for far greater fine tuning than 127...

If anyone has further advice, let me know.

Code: Select all

//-----On Expression PitchControl.pitchControlX (any)
decl p = PitchControl.pitchControlX;
decl r = 127;
decl x = floor(range(p, 0, r));
midiout(0,{224,r,x});
Macciza
Regular
Posts: 1315
Joined: 07 Dec 2011 04:57
Location: Sydney, Australia.

Re: Send pitch bend with lemur scripting (MIDI programming ?

Post by Macciza »

Hi
A few comments

Do you want pitch bend both up and down? Maybe use Sliders so you can go bipolar . . .
Also then the range of value is -8192 to +8192 and 0 = MSB-64 LSB 0
MSB is the coarse val and LSB is the Fine val . ..
You may also want to make it that when the MSB changes a value it reset LSB to 0
Or even work it so that when LSB is held at 0 or 127 it makes the MSB move as needed to 'scroll' the value . . .

And then the range thing as well . . .
May just need to think about it a bit more

MM
iMac 2.8G i7 12G 10.6.8/10.7.2, Legacy Dexter/Lemur, Liine Lemur/iPad2, KMI SoftStep, 12Step & QuNeo , B-Controls, Mackie C4 etc
MaxMSP, Live Suite, Native Instrument stuff, etc Modified Virtual Guitar System etc All Projects/Modules © CC-BY-NC-SA[*][/b]
Traxus
Regular
Posts: 211
Joined: 30 Nov 2012 06:19
Location: Detroit
Contact:

Re: Send pitch bend with lemur scripting (MIDI programming ?

Post by Traxus »

15 months later: :roll: 127 * 127 = 16383. Now I get it.

Code: Select all

//-----x = a 0 to 1 value from a fader etc...
//-----d = a 1 to 16 value of the midi channel you wish to transmit on

decl src = range(x, 0, 127);
decl msb = floor(src);
decl lsb = range((src - msb), 0, 127);
decl msg = 224 + (d - 1);
midiout(0, {msg,lsb,msb});

LSB/MSB... makes so much sense now. MSB are the big steps, LSB are the sub steps between each big step.

Remembering that 127 * 127 = 16383,

A MSB of 10, and an LSB of 0 will output a value of 1270 via (10 * 127) + 0
A MSB of 10, and an LSB of 4 will output a value of 1274 via (10 * 127) + 4
Softcore
Regular
Posts: 1613
Joined: 04 Nov 2012 08:34

Re: Send pitch bend with lemur scripting (MIDI programming ?

Post by Softcore »

Traxus wrote:15 months later: :roll: 127 * 127 = 16383. Now I get it.

Code: Select all

//-----x = a 0 to 1 value from a fader etc...
//-----d = a 1 to 16 value of the midi channel you wish to transmit on

decl src = range(x, 0, 127);
decl msb = floor(src);
decl lsb = range((src - msb), 0, 127);
decl msg = 224 + (d - 1);
midiout(0, {msg,lsb,msb});

LSB/MSB... makes so much sense now. MSB are the big steps, LSB are the sub steps between each big step.

Remembering that 127 * 127 = 16383,

A MSB of 10, and an LSB of 0 will output a value of 1270 via (10 * 127) + 0
A MSB of 10, and an LSB of 4 will output a value of 1274 via (10 * 127) + 4
Great info!!!
wul
Regular
Posts: 181
Joined: 10 Apr 2012 13:25

Re: Send pitch bend with lemur scripting (MIDI programming ?

Post by wul »

Have a look in the scaleykeypads demo template it's scripted in there
Macciza
Regular
Posts: 1315
Joined: 07 Dec 2011 04:57
Location: Sydney, Australia.

Re: Send pitch bend with lemur scripting (MIDI programming ?

Post by Macciza »

Remembering that 127 * 127 = 16383,
Um, except 127 * 127 = 16129 . . .???
16384 is however 2^14 ! And because of the whole zero offset/off-by-one stuff you get 16383 . . .
It is also 128 * 128 - The 14 is the important bit here in terms of it be a 14 bit value . . .
Cheers
MM
iMac 2.8G i7 12G 10.6.8/10.7.2, Legacy Dexter/Lemur, Liine Lemur/iPad2, KMI SoftStep, 12Step & QuNeo , B-Controls, Mackie C4 etc
MaxMSP, Live Suite, Native Instrument stuff, etc Modified Virtual Guitar System etc All Projects/Modules © CC-BY-NC-SA[*][/b]
Traxus
Regular
Posts: 211
Joined: 30 Nov 2012 06:19
Location: Detroit
Contact:

Re: Send pitch bend with lemur scripting (MIDI programming ?

Post by Traxus »

Macciza wrote:
Remembering that 127 * 127 = 16383,
Um, except 127 * 127 = 16129 . . .???
16384 is however 2^14 ! And because of the whole zero offset/off-by-one stuff you get 16383 . . .
It is also 128 * 128 - The 14 is the important bit here in terms of it be a 14 bit value . . .
Cheers
MM

Lol yes, 128^2 = 16484, is what i meant (probably why it didn't click for me the first time around)
Post Reply