I'm trying to find the simplest sketch for the most basic midi keyboard possible - push a button and it sends the note out via din plug midi. If i have 10 buttons then i have 10 different notes. That's it
I don't want to make LED's light up in response, i'm not interested in measuring the intensity of the key press, i don't want to matrix the buttons (it's quite important that its a direct 1 input per note), i don't want potentiometers to pitch bend and change volume, i don't want USB/bluetooth/wireless controls - it's literally going to be the simplest midi piano ever that just spits out the note codes via old school 5 pin midi.
I've spent 3 hours searching now and i can't seem to come up with the right combination of words to find what i assume is the most basic midi sketch possible. I've found 6 different ways to make a keyboard that uses fruit as keys and plenty of sketches that output the midi over usb but nothing simple and basic that I can fiddle with.
That is indeed simple. So simple that it's possible no-one else has made anything quite that simple and written it up.
All you really need are NoteOn and NoteOff and the examples that come with MIDI.h should have enough information to allow you to make a start on those. E.g. take Basic_IO and replace the midi.read() with if (button is pressed). Then you'll need to look at the basic example StateChangeDetection because you want to know when a specific button BECOMES pressed (then send a NoteOn) and when it BECOMES released (to send the NoteOff).
Give it a try and if you have problems post again with the code that you've tried and what problems you're having.
That's gorgeously simple and after a quick upload seems to be exactly what i need.
Is there a document anywhere that explains the definitions / code / numbers for notes so i can mess around and assign different notes / octaves without having to keep coming back and asking?
tommoore:
That's gorgeously simple and after a quick upload seems to be exactly what i need.
Is there a document anywhere that explains the definitions / code / numbers for notes so i can mess around and assign different notes / octaves without having to keep coming back and asking?
The note function returns the given note in the given octave. Middle C is note(C, 4) is note Nº 0x3C is note Nº 60. The lowest note is note(C, -1) and the highest note is note(G, 9).
MarkT:
You don't even need noteOff messages, noteOn with a velocity value of 0 are equivalent to noteOff.
So that does highlight that when the button is pressed i just get a single note and it doesn't stay "playing" until released. I understand the concept of noteOn noteOff commands but i'm not finding guidance on how to impliment those commands. Presumably i have to adjust the array data to something like
{3, note(Db, 4), noteOffcommand},
Where can i find some documents that take me through how to implement that?
PieterP:
The note function returns the given note in the given octave. Middle C is note(C, 4) is note Nº 0x3C is note Nº 60. The lowest note is note(C, -1) and the highest note is note(G, 9).
These note numbers are not specific to the library, they are the standard MIDI note numbers.
I'm just going to put it out there - i LOVE how practical your library is; i've spent too many evenings trying to learn obscure commands to make other librarys work and here you are creating something that /just works/ and that uses stand terms. THANKYOU!
tommoore:
So that does highlight that when the button is pressed i just get a single note and it doesn't stay "playing" until released. I understand the concept of noteOn noteOff commands but i'm not finding guidance on how to impliment those commands. Presumably i have to adjust the array data to something like
{3, note(Db, 4), noteOffcommand},
Where can i find some documents that take me through how to implement that?
The default NoteButton class sends a noteOn command when pressed and noteOff when released.
The third argument of the NoteButton class (where you wrote "noteOffcommand) is the velocity that's used for both the noteOn and noteOff events.
You can find the documentation here:
Create a new NoteButton object with the given pin, note number and channel.
Parameters:
- **pin**: The digital input pin to read from. The internal pull-up resistor will be enabled.
- **address**: The MIDI address containing the note number [0, 127], channel [CHANNEL_1, CHANNEL_16], and optional cable number [CABLE_1, CABLE_16].
- **velocity**: The velocity of the MIDI Note events.
The velocity has a default value, so that's why my example code in reply #1 works without specifying it explicitly.
If you want finer control over what happens when you press the button, e.g. to use a noteOn with velocity zero instead of a noteOff, or to use a different velocity for the noteOn and noteOff messages, you might want to look into adding your own MIDI Output Elements.
It's demonstrated in this example: Custom-MIDI-Output-Element.ino.
tommoore:
I'm just going to put it out there - i LOVE how practical your library is; i've spent too many evenings trying to learn obscure commands to make other librarys work and here you are creating something that /just works/ and that uses stand terms. THANKYOU!
// A Serial MIDI interface for 5-pin DIN MIDI
HardwareSerialMIDI_Interface midi = Serial;
and modify to something like
MyNoteButton button = {
5, // Push button on pin 5
{note(C, 4), CHANNEL_1}, // Note C4 on MIDI channel 1
0x7F, // Maximum velocity
};
{
6, // Push button on pin 6
{note(D, 4), CHANNEL_1}, // Note D4 on MIDI channel 1
0x7F, // Maximum velocity
};
{
7, // Push button on pin 6
{note(E, 4), CHANNEL_1}, // Note E4 on MIDI channel 1
0x7F, // Maximum velocity
};
Is that right, I don't need the velocity as such; i just need to note to keep playing whilst the button is pressed; I don't know enough about Midi protocols and requirements to pass an educated judgement as to whether that's correct way to achieve it.
(and forgive me, i'm not a musician, just a propmaker who's fiddled with arduino a bit and been asked to make some instruments for a special needs situation so am really out of my comfort zone)
The MyNoteButton class in the Custom-MIDI-Output-Element.ino example does effectively the same thing as the NoteButton class that comes with the library (the one I used in my first example in reply #1), so if you want buttons that send note events, you can just use the NoteButton class.
If you need more control, then yes, the Custom-MIDI-Output-Element.ino is the way to go.
If you want multiple buttons, you have to be careful with the array syntax:
// ┌────── You want an array here
MyNoteButton buttons[] = { // ── Opening brace for the array
{ // ── Opening brace for the first element
5, // Push button on pin 5
{note(C, 4), CHANNEL_1}, // Note C4 on MIDI channel 1
0x7F, // Maximum velocity
}, // ── Closing brace for the first element
{ // ── Opening brace for the second element
6, // Push button on pin 6
{note(D, 4), CHANNEL_1}, // Note D4 on MIDI channel 1
0x7F, // Maximum velocity
}, // ── Closing brace for the second element
{ // ── Opening brace for the third element
7, // Push button on pin 6
{note(E, 4), CHANNEL_1}, // Note E4 on MIDI channel 1
0x7F, // Maximum velocity
}, // ── Closing brace for the third element
}; // ── Closing brace for the array