Skip to content

Commit

Permalink
[Docs] mention note number convention (#972)
Browse files Browse the repository at this point in the history
  • Loading branch information
tttapa committed Nov 5, 2023
1 parent ba8812f commit 39d1ab5
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
* note C4.
* - When the button on pin 5 is released, a MIDI Note Off message is sent for
* note C4.
*
* Note numbers use the [Scientific Pitch Notation system](https://en.wikipedia.org/wiki/Scientific_pitch_notation),
* where <b>A<sub>4</sub></b> is 440 Hz, and <b>C<sub>-1</sub></b> is 8.1758 Hz.
* See @ref MIDI_Notes for a table of MIDI note numbers.
*
* Mapping
* -------
Expand Down
4 changes: 4 additions & 0 deletions examples/examples.dox
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@
* note C4.
* - When the button on pin 5 is released, a MIDI Note Off message is sent for
* note C4.
*
* Note numbers use the [Scientific Pitch Notation system](https://en.wikipedia.org/wiki/Scientific_pitch_notation),
* where <b>A<sub>4</sub></b> is 440 Hz, and <b>C<sub>-1</sub></b> is 8.1758 Hz.
* See @ref MIDI_Notes for a table of MIDI note numbers.
*
* Mapping
* -------
Expand Down
15 changes: 15 additions & 0 deletions src/MIDI_Constants/Notes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ BEGIN_CS_NAMESPACE
/// @{

/// MIDI note names.
/// Uses the [Scientific Pitch Notation system](https://en.wikipedia.org/wiki/Scientific_pitch_notation),
/// where <b>A<sub>4</sub></b> is 440 Hz, and <b>C<sub>-1</sub></b> is 8.1758 Hz.
///
/// |Octave| C |C♯/D♭| D |D♯/E♭| E | F |F♯/G♭| G |G♯/A♭| A |A♯/B♭| B |
/// |:-----|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|
/// |-1 | 0| 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| 11|
/// |0 | 12| 13| 14| 15| 16| 17| 18| 19| 20| 21| 22| 23|
/// |1 | 24| 25| 26| 27| 28| 29| 30| 31| 32| 33| 34| 35|
/// |2 | 36| 37| 38| 39| 40| 41| 42| 43| 44| 45| 46| 47|
/// |3 | 48| 49| 50| 51| 52| 53| 54| 55| 56| 57| 58| 59|
/// |4 | 60| 61| 62| 63| 64| 65| 66| 67| 68| 69| 70| 71|
/// |5 | 72| 73| 74| 75| 76| 77| 78| 79| 80| 81| 82| 83|
/// |6 | 84| 85| 86| 87| 88| 89| 90| 91| 92| 93| 94| 95|
/// |7 | 96| 97| 98| 99| 100| 101| 102| 103| 104| 105| 106| 107|
/// |8 | 108| 109| 110| 111| 112| 113| 114| 115| 116| 117| 118| 119|
namespace MIDI_Notes {

class Note {
Expand Down
6 changes: 6 additions & 0 deletions src/MIDI_Constants/Notes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
notes = ["C", "C♯/D♭", "D", "D♯/E♭", "E", "F", "F♯/G♭", "G", "G♯/A♭", "A", "A♯/B♭", "B"]
print("|Octave| C |C♯/D♭| D |D♯/E♭| E | F |F♯/G♭| G |G♯/A♭| A |A♯/B♭| B |")
print(f"|:-----|{'---:|' * 12}")
for octave in range(-1, 9):
notes = [f"{base + 12 * (octave + 1):4}" for base in range(12)]
print(f"|{octave:<6}|{'|'.join(notes)}|")
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ add_executable(tests
"MIDI_Senders/test-RelativeCCSender.cpp"
"MIDI_Parsers/tests-MIDI_Parsers.cpp"
"MIDI_Constants/test-MCU.cpp"
"MIDI_Constants/test-Notes.cpp"
"MIDI_Outputs/test-PBPotentiometer.cpp"
"MIDI_Outputs/test-NoteButtonMatrix.cpp"
"MIDI_Outputs/test-NoteButtonLatching.cpp"
Expand Down
11 changes: 11 additions & 0 deletions test/MIDI_Constants/test-Notes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <MIDI_Constants/Notes.hpp>
#include <gtest/gtest.h>

TEST(Notes, noteNumbers) {
// See https://en.wikipedia.org/wiki/Scientific_pitch_notation
// and page 48 of MIDI 1.0 Detailed Specification 4.2
EXPECT_EQ(cs::MIDI_Notes::C(-1), 0x00);
EXPECT_EQ(cs::MIDI_Notes::C(0), 0x0C);
EXPECT_EQ(cs::MIDI_Notes::C(4), 0x3C);
EXPECT_EQ(cs::MIDI_Notes::A(4), 0x45); // 440 Hz
}

0 comments on commit 39d1ab5

Please sign in to comment.