MIDI controller (serial to MIDI) with Potentiometers and Buttons

Hello everyone!
I've recently started a project with an Arduino Uno, I'm making a midi controller.
The idea is to send serial data and use a software (Hairless MIDI to Serial Bridge) to convert serial to midi, then map it with Ableton/Traktor or any other software.

I started with this tutorial, which works great for me, I managed to make a controller with potentiometers, but I'm struggling with buttons now.

No matter what I do, the button status stays the same and I get a repeated command, which makes a constant stuttering button.

Here's the full code:

int val0;
int lastVal0;

int buttonState0;
int lastButtonState0;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  //Potentiometer on А0
  val0 = analogRead(0) / 8;
  if (val0 != lastVal0)
  {
    MIDImessage(176, 1, val0);
  }
  lastVal0 = val0;



/////////////////////////////////////////////////////////////////
  //Button on D8
  buttonState0 = digitalRead(8);
  if (buttonState0 != lastButtonState0)
  {
    MIDImessage(144, 69, buttonState0);  //144 - Note On, 69 - A4 note, 127 - a pressed button
  }
  lastButtonState0 = buttonState0;
/////////////////////////////////////////////////////////////////

  delay(10);
}

void MIDImessage(byte message, byte control, byte value)
{
  Serial.write(message);
  Serial.write(control);
  Serial.write(value);
}

The problem is the code for button between the slashes.

What I want is a simple button that sends a A4 note on a press, then wait for another time I press it.
I'm also not using any libraries, I figured there must be an easy way to avoid it since the potentiometers work fine.

What am I missing here? Any help will be appreciated, thanks in advance!

It looks like you forgot to enable the built-in pull-up resistor.

Pieter

Thank you! The hint was clear enough, I needed the pinMode set up correctly:

void setup()
{
  pinMode(8, INPUT_PULLUP);
  Serial.begin(9600);
}

After that the button code itself needed a little work, I managed to make it a switch so it would hold the status until it's pressed again:

  //Button on D8
  buttonState0 = digitalRead(8);
  if (buttonState0 == HIGH && previous == LOW && millis() - time > debounce) {
    if (state == HIGH) {
    state = LOW;
    MIDImessage(144, 69, 127);
    } else {
    state = HIGH;
    MIDImessage(144, 69, 127);
    time = millis();
    }
  }
  previous = buttonState0;

Thank you for help!