Problem with Arduino MIDI decoder

Hi everyone.
I wondered if anyone can help me with this problem.
I am having difficulty getting the MIDI Decoder by Nick Gammon to work properly.
https://www.gammon.com.au/forum/?id=12746
I am relatively new to programming and so would love some pointers as to what I am doing wrong please.

I have created the circuit and I am sending midi out Via Abelton. I get messages out on the Serial Monitor, however, the data appears to be in the wrong order.
the Note names appear to change even though all I am doing is looping one note.
when I change the velocity, the note name changes. If I change the note, the velocity changes.

On the surface it looks like a simple swapping of the data but I dont know where this change is occurring.
I have attached 3 pictures. one of the loop without change, one where I have changed the velocity but the note data changes and one where I change the Note but the velocity changes.

Any help would be very appreciated.
IDE 1.8.7
Arduino Uno 3

You need to post your code, because that is wrong.

Hi Grumpy_Mike

I am adding the code as an attachment because it exceeds the 9000 character limit if I post it here.
But I copied and pasted it directly from here

Nick Gammon Midi Decoder.txt (14.1 KB)

But I copied and pasted it directly from here

No you didn't, you altered it, and you altered it so as to break it. The textual output you show differs from
what that code can produce.

Post your code, we ask this for very good reason...

MarkT:
No you didn't, you altered it, and you altered it so as to break it. The textual output you show differs from
what that code can produce.

Post your code, we ask this for very good reason...

Hi Mark
I am sorry you believe that altered the code.

I did not at any point use a text editor or any 3rd medium between moving the code from the web-page and the IDE.

The code as I have posted is the code that I uploaded. I understand your comment about being specific about the exact code that was uploaded, however, as far as I am aware I did not alter the code. If the code has been altered, it was done so un-intentionally and done during the copying and pasting of the code. If this is the case I am truly at a loss as to where to begin. I would have thought that I could have missed the end of the code off when copying, but I would have thought that would not compile? I am very new to programming and still trying to understand what is happening.

There would be no benefit to me (or to anyone else) for me to knowingly alter the code and post this problem.

All I could really do is repeat the steps again and see if the problem still exists.

You have me somewhat at a disadvantage, as I do not fully understand the code, however you have read and understood the code to the point where you believe that only altering the code could produce the textual output I have shown.
That is to say that you know the area of the code that would produce such an altered textual output as I have shown and there could be no other possible reason for the anomaly I am seeing (Hardware for example).

It would be very beneficial for me if you could pin point the part of the code that if altered would produce the output I am seeing, and how that code would be altered in order to produce said anomaly. That way I can alter the code to see if I get a change. This would be very appreciated as it would help me understand the code and help me understand what could have happened.

In the IDE, use the Edit/Copy for Forum command and paste the result into a new post. THAT will be the exact code that you are using.

Steve

slipstick:
In the IDE, use the Edit/Copy for Forum command and paste the result into a new post. THAT will be the exact code that you are using.

Steve

Thank you Slipstick.
I will try this when I get home.

DougRocket:
Hi Mark
I am sorry you believe that altered the code.

I did not at any point use a text editor or any 3rd medium between moving the code from the web-page and the IDE.

The code as I have posted is the code that I uploaded.

Well the serial output from your code doesn't match the code at the link you gave, so something's changed it
or you gave the wrong link?

MarkT:
Well the serial output from your code doesn't match the code at the link you gave, so something's changed it
or you gave the wrong link?

Can you pinpoint what you mean.
Thank you

I would but I can't copy/paste text from an image!!

Compare the output produced with the code in the link's print statements. Some letters and
numbers appear from your code that aren't produced by that code. After the ": " and before
the "Note on channel"

Oops, I’m wrong, sorry, getNote() is printing in that code, and returning a single space… My bad.

I expected getNote() to be returning the note…

I think the problem is the order of operations in the C++ stream expression isn’t defined, so that
the call to getNext() happens before getNote().

In general in C or C++ you should assume nothing about order of evaluation without ensuring
a sequence point is present (which is most readably done by using a list of statements, not
an expression).

Presumably your C++ compiler is doing different optimizations so you see a difference in ordering?

Either that or the datastream is corrupt, of course.

MarkT:
I think the problem is the order of operations in the C++ stream expression isn't defined, so that
the call to getNext() happens before getNote().

In general in C or C++ you should assume nothing about order of evaluation without ensuring
a sequence point is present (which is most readably done by using a list of statements, not
an expression).

Presumably your C++ compiler is doing different optimizations so you see a difference in ordering?

Hi Mark
Thank you for this. I need to read up more on sequencing. If I can order the way the data is collected and spat out that may help?

MarkT:
Either that or the datastream is corrupt, of course.

yes this had occurred to me. I have no idea how this would happen, but I need to check that my data represents the data I think I am sending out of Abelton.
Time to get the scope out.

Thank you for your help Mark