# MacOS - adjusting velocity curve at note level



## WookieAttitude (Jun 6, 2020)

Hi All,

I am sure this topic has probably been discussed to death. I have an acoustic piano with PianoDisc installed, which I am using as a piano controller for Pianoteq & Garritan CFX.

Trouble is the velocity response is not even across the keyboard with some notes being a lot faster (in velocity response) than others. This is not realistic as these notes really « jump » when playing. Recalibrating the keyboard doesn’t help address the issue, also the sensitivity of the note can be reduced in Pianodisc but that doesn’t help with flattening the response of the note.

I can work around this issue in Pianoteq using the note-by-note volume adjustment. Still it is not perfect as the tone of the uneven notes will be brighter. Also there is no such workaround in Garritan CFX.

I am looking for a MacOS software that would allow me to tweak the velocity curve at note level prior to the midi information being sent to the Pianoteq or Garritan CFX. Does such a software exist? 

From what I have read it may be possible in Logic. However some questions remain, e.g. can Logic be programmed as a processor to other audio programs seamlessly, or is it possible only if the instrument is in Logic itself? Pardon my ignorance, I am not a composer, just a player looking for the most realistic acoustic piano experience  Another thought is Logic is probably overkilled to be used only for that purpose.

Any help much appreciated. Thanks vm


----------



## synthesizerwriter (Jun 28, 2020)

Bome's MIDI Translator Pro might be a possible solution:

 https://www.bome.com/products/miditranslator

I don't have it (yet), so I can't comment on if it can do it. Why not ask Florian at Bome?


----------



## A.G (Jun 29, 2020)

WookieAttitude said:


> Logic is probably the best solution.
> From what I have read it may be possible in Logic. However some questions remain, e.g. can Logic be programmed as a processor to other audio programs seamlessly, or is it possible only if the instrument is in Logic itself?


1. You can cable a Transformer object in the Click & Ports environment layer and set a custom velocity curve in the transformer.

2. You can insert an External Instrument plugin and route the processed MIDI to other Mac applications via IAC for example.
You can also create special MIDI routings in the environment.


----------



## synthesizerwriter (Jun 29, 2020)

Configuring 'per note' custom velocity curves is a lot of work...


----------



## A.G (Jun 30, 2020)

synthesizerwriter said:


> Configuring 'per note' custom velocity curves is a lot of work...


I cannot find a 'per note' custom velocity request in the OP topic here. Normally, the hardware manufactures offer a Velocity global curve across the entire keyboard. It takes a few seconds in Logic if you know how to set Velocity Curves.
For example, the Logic Transformer "Expon" operation is very suitable for that...
Here is a short Video animation.


----------



## Dewdman42 (Jun 30, 2020)

the more complicated part is having a separate curve for every note.

You might want to start with this following site, which has a neat little curve UI, you can drag the velocity curve to what you like and then copy and paste the generated script into Scripter.



Velocity Curve Generator



The only thing about the above is that its a global curve across the entire keyboard, however you could expand it to have a separate curve for every note....but it would definitely be a lot of work to do that...but once you're done then hopefully you wouldn't need to tweak it that much.

Possibly you can just use one curve from the above site for your entire keyboard range and then just scale it differently on a note by note basis...perhaps.. anyway.... there ya go.


----------



## Dewdman42 (Jun 30, 2020)

If you want something that could be used with other programs outside of logic... well.. there are a few options...

check out transmidifier for example, which I think could probably do it but I've never used it. Its free



Be Wary Software - Products - TransMIDIfier



Other options...

BlueCatAudio has their PlugNScript which can run as a standalone, but you will have to learn how to script what you want it to do.

MidiPipe might be able to do that, but not easily.

KushView Element could probably be made to do it, it has standalone or plugin version, also free

PlogueBidule can probably do it, also standalone or plugin, not free.


----------



## Dewdman42 (Jun 30, 2020)

ps - none of those really make it "simple" to do though. I don't know of any general purpose tool that does. VSL Imperial piano includes that ability in a nice way for its own sample playback... not with a definable curve per note, but just a fader for each note which essentially applies a curve to make it happen.

I just quickly tried a test with Transmidifier and it can be done, you would have to set up 127 rules for each pitch and then edit the curve of each rule. But you could get there with it, its just not easy and intuitive. It is free though. 

I think KushView element could be wired up to do this also for free.

Then there is always plogueBidule of course.


----------



## synthesizerwriter (Jul 1, 2020)

A.G said:


> I cannot find a 'per note' custom velocity request in the OP topic here.



The OP text is all about 'per note' velocity. For example, it says 'tweak the velocity curve at note level'. As I said, if you use a utility that allows you to set the velocity curve per note, that is 128 separate velocity curves, and configuring all of those will take a lot of time. It would be rather like tuning up several Yamaha CS-80s at once...


----------



## TGV (Jul 1, 2020)

I think it could be done in Scripter. OP would have to set manually the appropriate parameter for each key, which is a bit of work. But once that's done, it can be saved as a preset and inserted on any channel.


----------



## Dewdman42 (Jul 1, 2020)

it could definitely be done with Scripter, but I later noted that the OP also wanted to be able to do it globally across all music programs, not just LogicPro, ideally. So that's why I'd probably recommend Transmidifier. it can definitely be done with that, though it hasn't been updated in a long time, and it is crashing on me now as we speak on Mojave. I was able to run it yesterday, no idea why today it won't even start without a crash...so... maybe scratch that...

The next choice would be freely available KushView Element. I will try to make some images later of how to do that in there.


----------



## synthesizerwriter (Jul 1, 2020)

The other alternative is to use external hardware, as I proposed...


----------



## Dewdman42 (Jul 1, 2020)

external hardware? I don't understand that suggestion. What did you have in mind?


----------



## synthesizerwriter (Jul 1, 2020)

Cloudflare kicked in and interupted my previous posting as I was about to edit it... Bome's MIDI Translator Pro is software that can process MIDI streams, so can be used outside of Logic et al, but the 'script' that you write to specify the processing can also be run on external hardware. There's a thing called a Bomebox that provides that function. So you could try it in software, and if you run into problems then you can put it in external hardware instead. Given the complexity of per note custom velocity mapping, I would be looking for flexibility in implementation, and being able to run it in software or external hardware might be worth the cost.


----------



## Dewdman42 (Jul 1, 2020)

copy that. Bome's is definitely another good potential solution..I have no idea how to use that one...

I will try to make a Scripter script this afternoon that basically does it... from there I think there are many possible solutions outside of LogicPro, same basic approach, but will take some work to set it up is all.


----------



## synthesizerwriter (Jul 1, 2020)

I used to have an Opcode Studio 5 (and Studio Vision Pro...), and so running MIDI processing outside of the computer is something I think about...


----------



## TGV (Jul 1, 2020)

You can also build your own Arduino-style solution, but that's quite a bit of work if you don't know where to start.


----------



## gsilbers (Jul 1, 2020)

I have the same issue with midi guitars... 

I use Logics (mainstage also works) VELOCITY PROCESSOR plugin. 

se the desired levels and incoming midi will be processed prior to getting to the piano plugin. 

it can work as a compressor. etc


----------



## Dewdman42 (Jul 1, 2020)

the problem here again is that they need a separate processor for each midi pitch, 128 of them. Stay tuned, I'm almost done with a Scripter script that should suffice.


----------



## Dewdman42 (Jul 1, 2020)

Here is a simplistic Scripter script that can do it, it does not use a velocity "curve" it simply uses a percentage scaler, one for each pitch on the keyboard. Configure the array at the top of the script with a percentage value. 100 is no scaling or 100 percent. Any value > 0 is ok to use.

A better version would use a separate velocity "curve" for each pitch, but that gets considerably more complicated. It would also be possible to calculate a known curve based on the percentage, which might be better too, but I leave that for others to figure out...


```
// Configure each note with a simple multiplier.  No "curves" will be
// applied, just a simple multiplier, expressed as a percentage

var PerNoteScale = [
//  C     C#    D     D#    E      F      F#    G     G#   A     A#    B    Octave
  100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,   // -2
  100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,   // -1
  100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,   //  0
  100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,   //  1
  100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,   //  2
  100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,   //  3
  100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,   //  4
  100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,   //  5
  100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,   //  6
  100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,   //  7
  100, 100, 100, 100, 100, 100, 100, 100                                    //  8
];

Event.prototype.scale = function() {
    // nop
};
NoteOn.prototype.scale = function() {
console.log(MIDI.noteName(this.pitch));
    this.velocity = this.velocity * (PerNoteScale[this.pitch]/100);
    if(this.velocity > 127) this.velocity = 127;
};

function HandleMIDI(event) {
    event.scale();
    event.send();
}
```


----------



## synthesizerwriter (Jul 1, 2020)

Looks like a good base to build on!


----------



## TGV (Jul 2, 2020)

It might be a little easier to edit if you place the notes in octaves, thusly:

/* C C# D D# E F F# G G# A A# B */
/* -2 */ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
/* -1 */ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,

(Forum messes up multiple spaces; it should look more like a table). A classic velocity curve shouldn't be hard to add.


----------



## A.G (Jul 2, 2020)

It is nice to see various solutions such as Scripter, 3rd party tools etc.
To my opinion the Scripter prototype cannot be set "musically" in real time and it looks that the code math results a scale rather than curves (I'm sorry if I did not get it correctly). I know that a curve math can be added in the Scripter.

*AG Velocity Transformer 1.0*

I decided to invest my time in making a Logic environment pre-sequencer plugin which allows you to set the velocity curves (per Note #, or for the entire Keyboard range).
The benefit is that you can assign the curves in real time just by playing a Note and tweaking the Mod Wheel (to change the curve). This method is very quick and you can audition the result.
The other benefit is that the recorded MIDI regions print the AG plugin output. This is useful if you decide to use the MIDI regions with another DAW.
Note: It is possible to tweak the "Curve Level" plugin parameter to set the Curve shape in case that your digital piano or keyboard does not have Mod Wheel or any CC fader.

The "Curve Type" menu offers up to 11 preset slots.
The 0. Per Note# preset (mode) is designed for curves per Note.
The slots 1-10 are designed for global keyboard velocity curve presets.

Here is a demo animation (click the image to watch in full screen).
Get the AG Velocity Transformer (Logic template) from the attachment.


----------



## Dewdman42 (Jul 2, 2020)

TGV said:


> It might be a little easier to edit if you place the notes in octaves, thusly:
> 
> /* C C# D D# E F F# G G# A A# B */
> /* -2 */ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
> ...



Good idea!

_HINT, in order to add code to your post, look on the toolbar...There is a code related toolbar item you can use._


----------



## Dewdman42 (Jul 2, 2020)

TGV said:


> A classic velocity curve shouldn't be hard to add.



I agree, I leave that to others to take it from here. 

In truth, the OP probably doesn't need a different curve for each key..probably the same curve always applied (which might be linear or not) and then just scaling it a bit for certain keys which are not evenly responsive on his Disklavier.

So anyway, all it would take is modifying the following lines to slightly different math to match the desired curve.


```
this.velocity = this.velocity * (PerNoteScale[this.pitch]/100);
    if(this.velocity > 127) this.velocity = 127;
```

..or better yet, use the approach from the website I quoted before, you can drag the curve line around and generate a velocities array to copy and paste into the script. Then you'd have to use a slightly modified version of his script code which applies some scaling and min/max logic to it on per note basis, honestly based a single percentage value would probably be fine at that point. But honestly...I think in reality he will be happy with just scaling the default linear velocity a little bit up or down

you could also leave the script exactly as it is, and use a second plugin to handle the overall velocity curve in a global way. You could use Scripter again in that second plugin slot and use the website I mentioned.. That actually would be the easiest way I think.


----------



## Dewdman42 (Jul 2, 2020)

Ivan's environment solution also looks very interesting, hopefully its not a locked macro I'd really like to see how you did it Ivan.


----------



## Dewdman42 (Jul 2, 2020)

another thing that could be added to Scripter solution would be a GUI. The point of the GUI would be to have 128 faders to control the scale. However, a Scripter GUI with 128 faders would not be very manageable honestly speaking, so I didn't want to bother with it. It would certainly be easier to tweak and fine tune the settings with faders, rather then having to edit code and hit "Run Script" every time to test it. But once the script is dialed in you could just save it and reuse it in projects with hard coded values that make sense.


----------



## synthesizerwriter (Jul 2, 2020)

It took me ages to get my head around producing the sort of curves that are shown in A.G.s' animations in this topic. To pass it on, here's what I learned (and I'm going to try to be as implementation independent as I can be here):

1. Convert the range of the input into 0.0->1.0 (for bipolar inputs then there's a different strategy).
2. Use a 'power' function, with an exponent from, say, 0.5 to 2.0. (That's 'x to the power 1 half', through to 'x squared'. When the exponent is 1.0, then you get a linear translation over the 0->1 range.
3. Convert the range back to the original (0-127 for MIDI, as in this topic).

This may be obvious to some, but I struggled with some horribly complicated, mind-bending functions before I realised that it was much easier to 'normalise' the range to 0.0->1.0 and do all the processing there...


----------



## Dewdman42 (Jul 2, 2020)

well in terms of a Scripter script, its usually better to pre-calculate the curve ahead of time and store 128 values in an array for that recalculated curve... See that website I posted earlier, that is the approach they used.. They are using some of the math you are talking about.



Velocity Curve Generator



So what I am suggesting is...

Use two instances of Scripter on the LogicPro channel







In one scripter instance put the script I provided here


In the other scripter instance use the website I just linked to for the overall velocity curve.
That should get you 99% close enough for government work.... as my programmer peer used to say. Truthfully the algorithm in my script could be slightly better to generate a linear correction that fits within a range of 0-127. Right now it just multiplies it and caps it off at 127, which honestly its probably good enough. Anyway, I defer the rest to others from here....have at it..I just wanted to provide a starter. Not a peep from the OP at this point...so...we're starting to wax philosophical.


----------



## synthesizerwriter (Jul 2, 2020)

'Normalising' to 0->1 can be used live (I've done it in Max, for example) or used to pre-calculate tables. Your implementation may vary, as they say.


----------



## Dewdman42 (Jul 2, 2020)

its simply a matter of making it easier to figure out that math, play with a visual curve while you figure it out...and avoiding math during the runtime thread of Scripter. The website advantage is it calculates the math on the website, the Scripter implementation is lightening fast and avoids math operations during plugin processing. But if you have some specific math ideas, let's hear it!


----------



## rotho (Jul 2, 2020)

I made a Pure data patch which I run taking the input from my midi controller and processing it in various ways before I pass it on to the DAW.

I do things like MIDI curve / compression as well as slightly adjusting the sensitivity of some keys which have a erroneous response.

I also do some algorithmic, generative and machine learning behaviours on the incoming MIDI stream, a bit like some of the Stratus stuff Halldór Eldjárn built with Olafur Arnalds.


----------



## synthesizerwriter (Jul 2, 2020)

@rotho I've been doing algorithmic and generative stuff (published a new version of MIDIdelA3 on M4L.com today, as it happens) for a while... My past history with ML is checkered...


----------



## rotho (Jul 3, 2020)

synthesizerwriter said:


> @rotho I've been doing algorithmic and generative stuff (published a new version of MIDIdelA3 on M4L.com today, as it happens) for a while... My past history with ML is checkered...


ML history is checkered in general imho


----------



## Scottyb (Jul 10, 2021)

Bringing this one back. The Velocity Processor plugin in Logic is a lifesaver for anyone experiencing this issue on their Mac! Too Bad Studio One doesn't have something like this - I wish it did. It can literally take a Midi controller with Velocity issues (for instance reaching full 127 like on some Yamahas) and clear them right up! Just had to bring this back for anyone going through the same thing. Someone earlier in the thread mentioned it as well.


----------

