Deluge Firmware 1.3.0
Build date: 2025.04.16
Loading...
Searching...
No Matches
learned_midi.h
1/*
2 * Copyright © 2016-2023 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 "io/midi/midi_device_manager.h"
21#include "storage/storage_manager.h"
22#include <cstdint>
23
24#define MIDI_MESSAGE_NONE 0
25#define MIDI_MESSAGE_NOTE 1
26#define MIDI_MESSAGE_CC 2
27
28class MIDICable;
29enum class MIDIMatchType { NO_MATCH, CHANNEL, MPE_MEMBER, MPE_MASTER };
30class LearnedMIDI {
31public:
32 LearnedMIDI();
33 void clear();
34
35 constexpr bool equalsCable(MIDICable* newCable) const {
36 return (!MIDIDeviceManager::differentiatingInputsByDevice || !cable || newCable == cable);
37 }
38
39 constexpr bool equalsChannelOrZone(MIDICable* newCable, int32_t newChannelOrZone) const {
40 return (newChannelOrZone == channelOrZone && equalsCable(newCable));
41 }
42
43 constexpr bool equalsNoteOrCC(MIDICable* newCable, int32_t newChannel, int32_t newNoteOrCC) const {
44 return (newNoteOrCC == noteOrCC && equalsChannelOrZone(newCable, newChannel));
45 }
46
47 bool equalsChannelAllowMPE(MIDICable* newCable, int32_t newChannel);
48 bool equalsChannelAllowMPEMasterChannels(MIDICable* newCable, int32_t newChannel);
49
50 // Check that note or CC and channel match, does not check if channel in MPE zone
51 inline bool equalsNoteOrCCAllowMPE(MIDICable* newCable, int32_t newChannel, int32_t newNoteOrCC) {
52 return (newNoteOrCC == noteOrCC && equalsChannelAllowMPE(newCable, newChannel));
53 }
54
55 inline bool equalsNoteOrCCAllowMPEMasterChannels(MIDICable* newCable, int32_t newChannel, int32_t newNoteOrCC) {
56 return (newNoteOrCC == noteOrCC && equalsChannelAllowMPEMasterChannels(newCable, newChannel));
57 }
58 MIDIMatchType checkMatch(MIDICable* fromCable, int32_t channel);
59 inline bool containsSomething() { return (channelOrZone != MIDI_CHANNEL_NONE); }
60
61 // You must have determined that containsSomething() == true before calling this.
62 inline bool isForMPEZone() { return (channelOrZone >= 16); }
63
64 // You must have determined that isForMPEZone() == true before calling this.
65 inline int32_t getMasterChannel() { return (channelOrZone - MIDI_CHANNEL_MPE_LOWER_ZONE) * 15; }
66
67 void writeAttributesToFile(Serializer& writer, int32_t midiMessageType);
68 void writeToFile(Serializer& writer, char const* commandName,
69 int32_t midiMessageType); // Writes the actual tag in addition to the attributes
70 void readFromFile(Deserializer& reader, int32_t midiMessageType);
71
72 inline void writeNoteToFile(Serializer& writer, char const* commandName) {
73 writeToFile(writer, commandName, MIDI_MESSAGE_NOTE);
74 }
75 inline void writeCCToFile(Serializer& writer, char const* commandName) {
76 writeToFile(writer, commandName, MIDI_MESSAGE_CC);
77 }
78 inline void writeChannelToFile(Serializer& writer, char const* commandName) {
79 writeToFile(writer, commandName, MIDI_MESSAGE_NONE);
80 }
81
82 inline void readNoteFromFile(Deserializer& reader) { readFromFile(reader, MIDI_MESSAGE_NOTE); }
83 inline void readCCFromFile(Deserializer& reader) { readFromFile(reader, MIDI_MESSAGE_CC); }
84 inline void readChannelFromFile(Deserializer& reader) { readFromFile(reader, MIDI_MESSAGE_NONE); }
85
86 void readMPEZone(Deserializer& reader);
87
88 MIDICable* cable;
89 // In addition to being set to channel 0 to 15, can also be MIDI_CHANNEL_MPE_LOWER_ZONE or
90 // MIDI_CHANNEL_MPE_UPPER_ZONE. Channels 18-36 signify CCs on channels 1-16+MPE respectively. Check with the
91 // constant IS_A_CC
92 uint8_t channelOrZone;
93 uint8_t noteOrCC;
94};
Definition storage_manager.h:185
A MIDI cable connection. Stores all state specific to a given cable and its contained ports and chann...
Definition midi_device.h:94
Definition storage_manager.h:119