preenfm Forum

PreenFM => preenfm2 and preenfm3 => Topic started by: lokki on December 24, 2020, 11:34:45 AM

Title: [fixed in v0.102] Hanging notes...pfm3
Post by: lokki on December 24, 2020, 11:34:45 AM
Xavier, I have quite a lot of hanging notes on my preenfm3 with my midi bass controller. I know it sends a lot of midi data (down the usb port, it acts as a host) but it works reliably with a waldorf pulse 2, a blofeld, a moog Minitaur and all axoloti stuffi built. Would you consider looking at the midi code in axoloti for example? It is open source built on a "similar" hardware and as I said rock solid.
Title: Re: Hanging notes...pfm3
Post by: Xavier on December 24, 2020, 01:33:28 PM
Out of curiosity, what is your midi bass control that acts as a USB host ?

Do you also have hanging notes if you do the same thing through Din5 ?
Would be great if you can save to a midi file the reproduces the problem. (Or an pure data patch ;) ?)

Title: Re: Hanging notes...pfm3
Post by: Xavier on December 24, 2020, 06:56:23 PM
Hanging Notes to my experience are more often a voice allocation problem in the sound engine than a midi driver problem.
And they are always complicated to catch.

But i just found and fix one hanging note problem thanks to this  PureData patch that floods midi with notes and control change :)
I used the one you sent me as a template  :)
(I will share it soon).

But i cannot say your problem is the same.
Title: Re: Hanging notes...pfm3
Post by: lokki on December 24, 2020, 09:47:02 PM
Will try asap. This brings me to the next question, what are the steps to compile  the firmware on Linux? So I can test stuff quicker, once it's up on GitHub :)

I think I once sent you a PD test patch for hanging notes on the pfm2
Title: Re: Hanging notes...pfm3
Post by: lokki on December 24, 2020, 09:53:48 PM
One thing I observed:

On every other synth I use, if I ever get a hanging note, hitting it again will unstuck it, since the note off will reset that note, no matter how many ons came in before. On pfm3 this does not work. I think most synths use an array of bools [128] in size and every midi note gets a 1 or 0 depending if there was a note on or off at that pitch... Don't know if that makes sense in the pfm3 case, will look a the code later :)
Title: Re: Hanging notes...pfm3
Post by: lokki on December 25, 2020, 01:40:29 AM
Out of curiosity, what is your midi bass control that acts as a USB host ?

Do you also have hanging notes if you do the same thing through Din5 ?
Would be great if you can save to a midi file the reproduces the problem. (Or an pure data patch ;) ?)

it is a bass midi controller made from a teensy 3.6 board that acts as a usb-host. it has a 8-port hub connected as a floor unit where i can connect synths to it.

will try with din5 and report back.
Title: Re: Hanging notes...pfm3
Post by: Xavier on December 25, 2020, 09:49:32 PM
On every other synth I use, if I ever get a hanging note, hitting it again will unstuck it

That's exactly what it should do with the preenfm.
I just fixed a bug because of which a midi note that is in some situation stored as 255. So when new note are played [0:127] it does not see it's the same note, and the note is not terminated.

It was occuring only with super short notes. So not sure how often it can occur in real situation. But my PureData patch triggered this bug. The pfm2 has the same bug BTW :/

Can you try this firmware 0.101z ?
https://drive.google.com/file/d/1G8al0cANieZdNVr_cxoeevwUjQX-x3Ny/view?usp=sharing

Let me know,
Thanks a lot,

Title: Re: Hanging notes...pfm3
Post by: lokki on December 26, 2020, 12:40:00 AM
well well...

this fixes my hanging notes! and it makes sense, since when i slide on my "bass" a lot of short notes get sent after each other (which i slur with a little glide on overlapping notes)

there is a slight problem now when i play in mono or unison mode.

if i play fast lines with rather short notes some don't get played.

Title: Re: Hanging notes...pfm3
Post by: lokki on December 26, 2020, 10:36:14 AM
Do you have a sort of buffer for the last played notes in mono and unison mode?

I have to check again later, but maybe that is the issue in mono playing.

What i mean:

If I press more then one note in mono mode, the latest (or highest, some synths have an option for that) will sound. If I release one key, the pitch should jump back to the one key that is still held, even if there is no new note on command...
Title: Re: Hanging notes...pfm3
Post by: Xavier on December 26, 2020, 11:12:58 AM
Do you have a sort of buffer for the last played notes in mono and unison mode?

I have to check again later, but maybe that is the issue in mono playing.

What i mean:

If I press more then one note in mono mode, the latest (or highest, some synths have an option for that) will sound. If I release one key, the pitch should jump back to the one key that is still held, even if there is no new note on command...

In Mono and Unison you have some options in the second Engine page.

So the answer depends on the "Glide" parameter.
If glide is "Overlap" or "Always", while at least one note is pressed, the sound glides. The base note is the still the same until it's released, then the base note become the latest pressed key (the one it was gliding to). So, no, it doesn't have a buffer of ALL pressed keys, only the base note and the note it glides to.
If glide is "Off", no buffer. It just plays the new note it receives.

So if the sound does not come back to the note that is still pressed, i assume you have "glide" to "Off". no ?
Title: Re: Hanging notes...pfm3
Post by: lokki on December 26, 2020, 11:34:08 AM
Could well be! I just browsed assume presets, while trying to make hanging notes :) will check again. Interesting approach, with the glide enabling held and released keys. Does it also prevent the adsr from firing on every new note? So just fire the adsr on non overlapping notes?

Will report back.
Title: Re: Hanging notes...pfm3
Post by: Xavier on December 26, 2020, 11:36:51 AM
Could well be! I just browsed assume presets, while trying to make hanging notes :) will check again. Interesting approach, with the glide enabling held and released keys. Does it also prevent the adsr from firing on every new note? So just fire the adsr on non overlapping notes?

While it's gliding, it does not re-trigger the env on new note, it's a smooth frequency glide :).
All Envs stay in the "Sustain" (ADSR) state.
Title: Re: Hanging notes...pfm3
Post by: lokki on December 26, 2020, 11:49:15 AM
Out of curiosity, what happens if I held down more then two keys in mono mode?
Title: Re: Hanging notes...pfm3
Post by: Xavier on December 26, 2020, 12:24:29 PM
Out of curiosity, what happens if I held down more then two keys in mono mode?

Keep in mind that only 2 notes are in memory. The Base note, and the last note it was gliding to.

So here is how it works :

1 . The first key your press is the based note (A)
2 . Then you press and hold other notes (B, C, D). It will glide to B, then C then D. The base note will remain A untill it's released.

From this point A,B,C,D are hold down but B and C are not in memory anymore, so B and C don't have any impact on future actions:

3.1.    If you release D,  it will glide back to A .
3.2.    If you release A, the base note will become D. So D will become the return note of future notes until it's releaed.
3.3.    If you release A and D the sound stop (although B & D are still pressed).

3.3 is not ideal, but it's a corner case to my opinion.
Title: Re: Hanging notes...pfm3
Post by: lokki on December 26, 2020, 04:20:18 PM
Thanks for the clear explanation.
I played a little with the synth, I never got a hanging note!
This is a great improvement, thanks!

As for the mono handling of multiple notes, is there a reason it depends on glide?

You could turn on all of this simply if a patch is set to mono independently of glide, no?

I still get some missing notes and I guess it happens, when more then two notes are on. Would you consider a buffer for mono handling? It could contain maybe the last 5 notes...
Title: Re: Hanging notes...pfm3
Post by: Xavier on December 26, 2020, 07:21:23 PM
Thanks for the clear explanation.
I played a little with the synth, I never got a hanging note!
This is a great improvement, thanks!

Cool  ! :)
Thanks for the report and the test !

As for the mono handling of multiple notes, is there a reason it depends on glide?
You could turn on all of this simply if a patch is set to mono independently of glide, no?

So you would want glide="Overlap" by default for mono patch. It wouldn't add any feature, just a different approach.
Maybe it's a bit confusing, but it's always difficult to change that kind of thing without breaking compatibility with previous patches.


I still get some missing notes and I guess it happens, when more then two notes are on. Would you consider a buffer for mono handling? It could contain maybe the last 5 notes...

I don't consider changing the behaviour for the moment.
I'll definitely take a look if you have missing notes. But for the moment i don't understand from your description when it occurs and what is the problem.
Title: Re: Hanging notes...pfm3
Post by: lokki on December 26, 2020, 09:14:55 PM
No I would leave glide off by default. But I would enable the bounce back to a previously held key and the non retriggering of the adsr in mono.

I get the feeling that for you glide, adsr triggering etc. are somehow related to each other, but they are really separate.

You might want a mono sound with no glide, but still no retriggering adsr on over lapping notes and most definitely it should bounce back to the pitch of the least recently used key when you release one.

So the golden solution would be settings for mono mode:

Glide off/on/overlap
Adsr retrigger: on/off
Note priority: last/highest/lowest (but for this you need a buffer)

This gives the most freedom, but I get that pfm3 is not a mono synth primarily.

As for the missing notes:

I will try to find a pattern, and a way for you to reproduce it.

I think it happens when I have more then two keys held down, but I will investigate further...
Title: Re: Hanging notes...pfm3
Post by: lokki on January 02, 2021, 12:26:48 AM
ok, i just sent you a PD patch to show one of the problems i am having with lost notes. as it only happens with rather short notes, i guess it comes from your fix to disregard notes that do not yet sound...

here is some code from axoloti (from the object that handles monophonic incoming midi, with the held down keys saved in an array, and simply ordered by a counter (p++) once a key is released, the code scans the whole array and finds the least recently used key (the one with the highest number stored and plays that. i don't want to "lecture" you or something, but i really would like a proper mono handling on preenfm3, since in this state it does not work correctly for me. and since i know for a fact that many synths do it like on axoloti (or very similar) i thought i post it as an example...



Code: [Select]
if ((status == MIDI_NOTE_ON + attr_midichannel) && (data2)) {
  if ((data1 >= attr_startNote)&&(data1 <= attr_endNote)) {
    _velo = data2;
    _note = data1-64;
    _gate = 1<<27;
    _gate2 = 0;
    np[data1-attr_startNote]=p++;
  }
} else if (((status == MIDI_NOTE_ON + attr_midichannel) && (!data2))||
          (status == MIDI_NOTE_OFF + attr_midichannel)) {
if ((data1 >= attr_startNote)&&(data1 <= attr_endNote)) {
   _rvelo = data2;
np[data1-attr_startNote]=0;
int j;
int np2 = 0;
int n2 = 0;
for(j=0;j<attr_endNote-attr_startNote+1;j++){
   if (np[j]>np2) {
      np2=np[j];
      n2 = j;
   }
}
if (n2>0) {
  int nn = n2+attr_startNote-64;
  if (nn != _note) {
    _gate2 = 0;
    _note = nn;
  }
}
else _gate = 0;
}
} else if ((status == attr_midichannel + MIDI_CONTROL_CHANGE)&&(data1 == MIDI_C_ALL_NOTES_OFF)) {
  _gate = 0;
}

those attr_* "variables" are actually constants that you can choose before you compile a program.
_gate is only triggered on non legato playing, _gate2 is always triggered when a new note is played.
_note contains the pitch obviously
np[] is the array that contains the notes played if non zero and also the order in which they were depressed.


is there a "simple" way to implement something like this within the preenfm3 eco-system? if you point me to the right direction i can also have a look myself. will try to install the cube stuff to compile the firmware.

thanks for considering.

Title: Re: Hanging notes...pfm3
Post by: Xavier on January 02, 2021, 09:23:00 AM
Hi,

So when you release the key that triggered the playing note, it loops and compare through the 127 (most of the time) np values to retrieve which one was the latest pressed key before this one.
The preenfm3 can have 5 other instruments playing many notes, a high note on/of activity on the other instruments,  and a high CPU usage, so i'm not a big fan of this loop.
It should be possible to have an array of struct that simulate a linked list for better performance and limiting the number of notes in the buffer to 10 (we have 10 fingers ;) )
This mono change would also likely require to modify the "glide" algo to work with this new behavior.

Importing the project in STM32CubeIde should be very easy, you'll have 3 projects (firmware, bootloader, lib).
You'll find some debug config to upload the firmware and debug.
It works very well with any STLink board.
The one i used the most is a part of a nucleo board that i cut and make a nice small STLink 2.1.
4 wires to the SWD pins on the pfm mother board, and that's it.
Upload is very fast, and debugging (breakpoint and watching variables) is very easy.

You can also, create the bin (look in "scripts" folder) and upload through DFU but it's much much longer.
Title: Re: Hanging notes...pfm3
Post by: lokki on January 02, 2021, 09:38:02 AM
Yes, I thought about those 6x problem as well. A buffer of 10 notes would already be great!

For the moment I don't have a stlink board. Can I still compile and upload via DFU?
Title: Re: Hanging notes...pfm3
Post by: Xavier on January 02, 2021, 09:42:52 AM
For the moment I don't have a stlink board. Can I still compile and upload via DFU?

Yes, but it's slow to upload, and your only debugging tool will be to display values on the display.
Go in "/scripts/" folder and run create_object_debug.sh, you should get your firmware bin file.
Title: Re: Hanging notes...pfm3
Post by: Xavier on January 02, 2021, 09:56:22 AM
.. and what you want to look at is in Timbre.cpp : preenNoteOn and preenNoteOff.
Title: Re: [fixed in v0.102?] Hanging notes...pfm3
Post by: lokki on January 05, 2021, 11:38:02 AM
Just tried v. 0.102.

it is again better, there are only a few missing notes still. they all happen, when there are notes overlapping, never when only one note is held down. I will again try to find a way to reproduce this on PD or similar. Never got a hanging note! Great work...

I will try to make some sense of timbre.cpp to see if I can implement something.

Your solution with a buffer of 10 notes (a 2d array with not pitch and timestamp?) Sounds very reasonable...
Title: Re: [fixed in v0.102?] Hanging notes...pfm3
Post by: lokki on January 09, 2021, 11:46:22 PM
ok, for now i could not wrap my head around it. maybe it will be easier just to add a small buffer (10 notes as you suggest) to the glide part of the code?