Deluge Firmware 1.3.0
Build date: 2025.04.16
Loading...
Searching...
No Matches
message.h
1/*
2 * Copyright © 2024 Synthstrom Audible Limited
3 *
4 * This file is part of The Synthstrom Audible Deluge Firmware.
5 *
6 * The Synthstrom Audible Deluge Firmware is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU General Public License as published by the Free Software Foundation,
8 * either version 3 of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * See the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along with this program.
15 * If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#pragma once
19
20#include <cinttypes>
21#include <cstdlib>
22
24size_t bytesPerStatusMessage(uint8_t status);
25
32 uint8_t statusType;
34 uint8_t channel;
36 uint8_t data1;
38 uint8_t data2;
39
40 [[gnu::always_inline]] [[nodiscard]] bool isSystemMessage() const { return statusType == 0x0f; }
41
44
45 static MIDIMessage noteOff(uint8_t channel, uint8_t note, uint8_t velocity) {
46 return MIDIMessage{.statusType = 0b1000, .channel = channel, .data1 = note, .data2 = velocity};
47 }
48
49 static MIDIMessage noteOn(uint8_t channel, uint8_t note, uint8_t velocity) {
50 return MIDIMessage{.statusType = 0b1001, .channel = channel, .data1 = note, .data2 = velocity};
51 }
52
53 static MIDIMessage polyphonicAftertouch(uint8_t channel, uint8_t note, uint8_t aftertouch) {
54 return MIDIMessage{.statusType = 0b1010, .channel = channel, .data1 = note, .data2 = aftertouch};
55 }
56
57 static MIDIMessage cc(uint8_t channel, uint8_t cc, uint8_t value) {
58 return MIDIMessage{.statusType = 0b1011, .channel = channel, .data1 = cc, .data2 = value};
59 }
60
61 static MIDIMessage programChange(uint8_t channel, uint8_t program) {
62 return MIDIMessage{.statusType = 0b1100, .channel = channel, .data1 = program, .data2 = 0};
63 }
64
65 static MIDIMessage channelAftertouch(uint8_t channel, uint8_t aftertouch) {
66 return MIDIMessage{.statusType = 0b1101, .channel = channel, .data1 = aftertouch, .data2 = 0};
67 }
68
70 static MIDIMessage pitchBend(uint8_t channel, uint16_t bend) {
71 return MIDIMessage{
72 .statusType = 0b1110,
73 .channel = channel,
74 .data1 = static_cast<uint8_t>(bend & 0x7f),
75 .data2 = static_cast<uint8_t>((bend >> 7) & 0x7f),
76 };
77 }
78
79 static MIDIMessage realtimeClock() {
80 return MIDIMessage{.statusType = 0x0F, .channel = 0x08, .data1 = 0, .data2 = 0};
81 }
82
83 static MIDIMessage realtimeStart() {
84 return MIDIMessage{.statusType = 0x0F, .channel = 0x0A, .data1 = 0, .data2 = 0};
85 }
86
87 static MIDIMessage realtimeContinue() {
88 return MIDIMessage{.statusType = 0x0F, .channel = 0x0B, .data1 = 0, .data2 = 0};
89 }
90
91 static MIDIMessage realtimeStop() {
92 return MIDIMessage{.statusType = 0x0F, .channel = 0x0C, .data1 = 0, .data2 = 0};
93 }
94
95 static MIDIMessage systemPositionPointer(uint16_t position) {
96 uint8_t positionPointerLSB = position & (uint32_t)0x7F;
97 uint8_t positionPointerMSB = (position >> 7) & (uint32_t)0x7F;
98 return MIDIMessage{
99 .statusType = 0x0F, .channel = 0x02, .data1 = positionPointerLSB, .data2 = positionPointerMSB};
100 }
101
103};
104
105static_assert(sizeof(MIDIMessage) == 4);
Definition message.h:30
uint8_t channel
Channel, or data field for system function.
Definition message.h:34
uint8_t data1
Optional data byte 1.
Definition message.h:36
uint8_t statusType
Status type. If 0xF, the channel represents the specific system function.
Definition message.h:32
static MIDIMessage pitchBend(uint8_t channel, uint16_t bend)
Bend is 14 bits.
Definition message.h:70
uint8_t data2
Optional data byte 2.
Definition message.h:38