# Using a Midi Keyboard to create coloured shapes

**URL:** <https://discourse.processing.org/t/using-a-midi-keyboard-to-create-coloured-shapes/9685>\
**Category:** Libraries\
**Created:** [March 27, 2019, 4:41pm UTC](https://discourse.processing.org/t/using-a-midi-keyboard-to-create-coloured-shapes/9685 "2019-03-27T16:41:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![djspoonzay](https://avatars.discourse-cdn.com/v4/letter/d/839c29/32.png) [@djspoonzay](https://discourse.processing.org/u/djspoonzay)\
**Post date:** [March 27, 2019, 4:41pm UTC](https://discourse.processing.org/t/using-a-midi-keyboard-to-create-coloured-shapes/9685/1 "2019-03-27T16:41:09Z")

</div>

Hello,  
I am trying to use a MIDI keyboard to create a red ellipse to start with. I keep getting the same response of cannot convert void to boolean. Any help would be appreciated.

```auto
import themidibus.*;
MidiBus myBus;
int x;

void noteOn(int channel, int pitch, int velocity) {
}

void setup () {
  size (400, 400);
  background (0);

  MidiBus.list();
  myBus = new MidiBus(this, 0, 3);
 
}

void draw () {
   while (noteOn (0, 60, x));{
    fill (255, 0, 0);
    ellipse (200, 200, 200, 200);
  }
}

```

---

<div class="post-metadata">

**Author:** ![cansik](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/cansik/32/8815_2.png) [@cansik](https://discourse.processing.org/u/cansik)\
**Post date:** [March 27, 2019, 6:12pm UTC](https://discourse.processing.org/t/using-a-midi-keyboard-to-create-coloured-shapes/9685/2 "2019-03-27T18:12:43Z")

</div>

`noteOn()` is a method which is called when a **Note On** midi signal reaches your sketch. So you are able to write code in that function to do something. The parameters are then set to the specific channel and pitch. To just log which note was pressed, you can add a simple `println()`.

```java
void noteOn(int channel, int pitch, int velocity) {
    println("C: " + channel + " P: " + pitch + " V: " + velocity);
}

```

Now to use this information later in the draw method, you need to store the information you get in noteOn. You could just use a simple `boolean` to indicate if the note was pressed or not.

```java
boolean noteWasPressed = false;

void noteOn(int channel, int pitch, int velocity) {
    if(channel == 0 && pitch == 60) {
        noteWasPressed = true;
    }  
}

```

Now you can check in draw if the condition is true, and of course reset it again after you’ve drawn the ellipse.

```java
void draw() {
    if(noteWasPressed) {
        // draw your ellipse

         // reset the flag
        noteWasPressed = false;
    }
}

```

---

<div class="post-metadata">

**Author:** ![Adilic0](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@Adilic0](https://discourse.processing.org/u/Adilic0)\
**Post date:** [August 1, 2021, 11:10am UTC](https://discourse.processing.org/t/using-a-midi-keyboard-to-create-coloured-shapes/9685/3 "2021-08-01T11:10:20Z")

</div>

this really help me too, its really helpfull for beginners ,and I will be stuck in this question for two days until I see your answer.

wish you have a good day
