Deluge Firmware 1.3.0
Build date: 2026.11.28
Loading...
Searching...
No Matches
midi_follow.h
1/*
2 * Copyright (c) 2024 Sean Ditny
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 "definitions_cxx.hpp"
21#include "model/global_effectable/global_effectable.h"
22#include "modulation/params/param.h"
23#include "storage/storage_manager.h"
24#include "util/containers.h"
25#include <array>
26#include <cstdint>
27
28class AudioClip;
29class InstrumentClip;
30class Clip;
31class Kit;
32class Drum;
33class ModelStack;
36enum class MIDIMatchType;
37
39
40class MidiFollow final {
41public:
42 MidiFollow();
43 void factoryReset(bool showPopup = true);
47
49 Clip* clip, int32_t soundParamId, int32_t globalParamId,
50 bool displayError = true);
51 void noteMessageReceived(MIDICable& cable, bool on, int32_t channel, int32_t note, int32_t velocity,
52 bool* doingMidiThru, bool shouldRecordNotesNowNow, ModelStack* modelStack);
53 Output* sendNoteToClip(MIDICable& cable, Clip* clip, MIDIMatchType match, bool on, int32_t channel, int32_t note,
54 int32_t velocity, bool* doingMidiThru, bool shouldRecordNotesNowNow, ModelStack* modelStack,
55 bool updateClipForLastNoteReceived = true);
56 void midiCCReceived(MIDICable& cable, uint8_t channel, uint8_t ccNumber, uint8_t ccValue, bool* doingMidiThru,
57 ModelStack* modelStack);
58 void pitchBendReceived(MIDICable& cable, uint8_t channel, uint8_t data1, uint8_t data2, bool* doingMidiThru,
59 ModelStack* modelStack);
60 void aftertouchReceived(MIDICable& cable, int32_t channel, int32_t value, int32_t noteCode, bool* doingMidiThru,
61 ModelStack* modelStack);
62
63 void clearStoredClips();
64 void removeClip(Clip* clip);
65
66 // midi CC mappings
67 int32_t getCCFromParam(deluge::modulation::params::Kind paramKind, int32_t paramID);
69
70 std::array<uint8_t, kMaxMIDIValue + 1> ccToSoundParam;
71 std::array<uint8_t, kMaxMIDIValue + 1> ccToGlobalParam;
72 std::array<uint8_t, params::UNPATCHED_START + params::UNPATCHED_SOUND_MAX_NUM> soundParamToCC;
73 std::array<uint8_t, params::UNPATCHED_GLOBAL_MAX_NUM> globalParamToCC;
74
75 int32_t previousKnobPos[kMaxMIDIValue + 1];
76 uint32_t timeLastCCSent[kMaxMIDIValue + 1];
77 uint32_t timeAutomationFeedbackLastSent;
78
79 // public so it can be called from View::sendMidiFollowFeedback
80 bool isFeedbackEnabled();
81 void sendCCWithoutModelStackForMidiFollowFeedback(bool isAutomation = false);
83 void sendCCForMidiFollowFeedback(int32_t ccNumber, int32_t knobPos);
84
85 void handleReceivedCC(MIDICable& cable, ModelStackWithTimelineCounter& modelStack, Clip* clip, int32_t ccNumber,
86 int32_t ccValue);
87
88private:
89 // initialize
90 void init();
91 void initState();
92 void clearMappings();
93 void initDefaultMappings();
94
95 // note recieved
96 Output* noteMessageReceivedForSelectedOrActiveClip(MIDICable& cable, bool on, int32_t channel, int32_t note,
97 int32_t velocity, bool* doingMidiThru,
98 bool shouldRecordNotesNowNow, ModelStack* modelStack);
99 void noteMessageReceivedForSpecificTrack(MIDICable& cable, bool on, int32_t channel, int32_t note, int32_t velocity,
100 bool* doingMidiThru, bool shouldRecordNotesNowNow, ModelStack* modelStack,
101 Output* specific_track, int32_t specific_track_index);
102 // cc received
103 Output* midiCCReceivedForSelectedOrActiveClip(MIDICable& cable, uint8_t channel, uint8_t ccNumber, uint8_t ccValue,
104 bool* doingMidiThru, ModelStack* modelStack);
105 void midiCCReceivedForSpecificTrack(MIDICable& cable, uint8_t channel, uint8_t ccNumber, uint8_t ccValue,
106 bool* doingMidiThru, ModelStack* modelStack, Output* specific_track,
107 int32_t specific_track_index);
108
109 // pitch bend received
110 Output* pitchBendReceivedForSelectedOrActiveClip(MIDICable& cable, uint8_t channel, uint8_t data1, uint8_t data2,
111 bool* doingMidiThru, ModelStack* modelStack);
112 void pitchBendReceivedForSpecificTrack(MIDICable& cable, uint8_t channel, uint8_t data1, uint8_t data2,
113 bool* doingMidiThru, ModelStack* modelStack, Output* specific_track,
114 int32_t specific_track_index);
115
116 // after touch received
117 Output* aftertouchReceivedForSelectedOrActiveClip(MIDICable& cable, int32_t channel, int32_t value,
118 int32_t noteCode, bool* doingMidiThru, ModelStack* modelStack);
119 void aftertouchReceivedForSpecificTrack(MIDICable& cable, int32_t channel, int32_t value, int32_t noteCode,
120 bool* doingMidiThru, ModelStack* modelStack, Output* specific_track,
121 int32_t specific_track_index);
122
125 Clip* getActiveClip(ModelStack* modelStack);
126 [[nodiscard]] const size_t getTrackCount() const;
127 Output* getTrackFromIndex(uint32_t trackIndex, uint32_t maxTrack);
128
129 // get model stack with auto param for midi follow cc-param control
130 ModelStackWithAutoParam* getModelStackWithParamForSong(ModelStackWithThreeMainThings* modelStackWithThreeMainThings,
131 int32_t soundParamId, int32_t globalParamId);
132 ModelStackWithAutoParam* getModelStackWithParamForClip(ModelStackWithTimelineCounter* modelStackWithTimelineCounter,
133 Clip* clip, int32_t soundParamId, int32_t globalParamId);
135 getModelStackWithParamForSynthClip(ModelStackWithTimelineCounter* modelStackWithTimelineCounter, Clip* clip,
136 int32_t soundParamId, int32_t globalParamId);
138 getModelStackWithParamForKitClip(ModelStackWithTimelineCounter* modelStackWithTimelineCounter, Clip* clip,
139 int32_t soundParamId, int32_t globalParamId);
141 getModelStackWithParamForAudioClip(ModelStackWithTimelineCounter* modelStackWithTimelineCounter, Clip* clip,
142 int32_t soundParamId, int32_t globalParamId);
143 void displayParamControlError(int32_t soundParamId, int32_t globalParamId);
144
145 MIDIMatchType checkMidiFollowMatch(MIDICable& cable, uint8_t channel);
146 MIDIMatchType checkMidiFollowMatchForSpecificTrack(MIDICable& cable, uint8_t channel, int32_t specific_track_index);
147
148 static constexpr size_t kMaxMIDIFollowFeedbackTargets = 2;
149 using FeedbackChannelTypes = std::array<MIDIFollowChannelType, kMaxMIDIFollowFeedbackTargets>;
150 size_t getChannelTypesForFeedback(FeedbackChannelTypes& feedbackChannelTypes);
151 MIDIFollowChannelType getChannelTypeForTrackFeedback();
152 bool addChannelTypeForFeedback(FeedbackChannelTypes& feedbackChannelTypes, size_t& numChannelTypes,
153 MIDIFollowChannelType feedbackChannelType);
155 void sendCCForMidiFollowFeedback(FeedbackChannelTypes const& feedbackChannelTypes, size_t numChannelTypes,
156 int32_t ccNumber, int32_t knobPos);
158 void sendCCForMidiFollowFeedback(MIDIFollowChannelType feedbackChannelType, int32_t ccNumber, int32_t knobPos);
159
160 // Saving
161
162 // CC Mappings
164
165 // Settings
168 void writeSpecificChannelSettingsToFile(Serializer& writer, MIDIFollowChannelType type);
172
173 // Loading
174 bool successfullyReadDefaultsFromFile;
175
176 void completeLegacyFlashMigration(bool defaultsWereWritten);
177
178 // CC Mappings
180
181 // Settings
184 void readSpecificChannelSettingsFromFile(Deserializer& reader, MIDIFollowChannelType type);
188
189 // string tags / values
190 char const* getNameFromChannelType(MIDIFollowChannelType type);
191 MIDIFollowChannelType getChannelTypeFromName(char const* name);
192
193 char const* getNameFromFeedbackChannelType(MIDIFollowFeedbackChannelType type);
194 MIDIFollowFeedbackChannelType getFeedbackChannelTypeFromName(char const* name);
195
196 char const* getNameFromFeedbackAutomationMode(MIDIFollowFeedbackAutomationMode mode);
197 MIDIFollowFeedbackAutomationMode getFeedbackAutomationModeFromName(char const* name);
198
199 char const* getNameFromBool(bool value);
200 bool getBoolFromName(char const* name);
201};
202
203extern MidiFollow midiFollow;
Definition audio_clip.h:35
Definition clip.h:46
Definition storage_manager.h:190
Definition drum.h:44
Definition instrument_clip.h:52
Definition kit.h:34
A MIDI cable connection. Stores all state specific to a given cable and its contained ports and chann...
Definition midi_device.h:96
Definition midi_follow.h:40
void writeFeedbackSettingsToFile(Serializer &writer)
Write Feedback settings to XML.
Definition midi_follow.cpp:1816
Clip * getSelectedClip()
Definition midi_follow.cpp:419
void completeLegacyFlashMigration(bool defaultsWereWritten)
Definition midi_follow.cpp:1836
size_t getChannelTypesForFeedback(FeedbackChannelTypes &feedbackChannelTypes)
Definition midi_follow.cpp:1245
bool addChannelTypeForFeedback(FeedbackChannelTypes &feedbackChannelTypes, size_t &numChannelTypes, MIDIFollowChannelType feedbackChannelType)
Definition midi_follow.cpp:1206
int32_t getCCFromParam(deluge::modulation::params::Kind paramKind, int32_t paramID)
Definition midi_follow.cpp:675
void writeKitRootNoteSettingToFile(Serializer &writer)
Write Kit Root Note setting to XML.
Definition midi_follow.cpp:1809
const size_t getTrackCount() const
used to forward midi messages to specific tracks
Definition midi_follow.cpp:479
void noteMessageReceivedForSpecificTrack(MIDICable &cable, bool on, int32_t channel, int32_t note, int32_t velocity, bool *doingMidiThru, bool shouldRecordNotesNowNow, ModelStack *modelStack, Output *specific_track, int32_t specific_track_index)
Definition midi_follow.cpp:808
void writeSpecificChannelSettingsToFile(Serializer &writer, MIDIFollowChannelType type)
Write Specific Channel settings to XML.
Definition midi_follow.cpp:1789
MIDIMatchType checkMidiFollowMatch(MIDICable &cable, uint8_t channel)
Definition midi_follow.cpp:1627
Clip * getSelectedOrActiveClip()
Definition midi_follow.cpp:395
Clip * getActiveClip(ModelStack *modelStack)
Definition midi_follow.cpp:459
void writeChannelSettingsToFile(Serializer &writer)
Write Channel settings to XML.
Definition midi_follow.cpp:1766
void aftertouchReceivedForSpecificTrack(MIDICable &cable, int32_t channel, int32_t value, int32_t noteCode, bool *doingMidiThru, ModelStack *modelStack, Output *specific_track, int32_t specific_track_index)
Definition midi_follow.cpp:1598
void writeDefaultMappingsToFile(Serializer &writer)
convert paramID to a paramName to write to XML
Definition midi_follow.cpp:1691
void readDefaultSettingsFromFile(Deserializer &reader)
read default settings (channels, kit root note, feedback, display param) from XML
Definition midi_follow.cpp:1949
void removeClip(Clip *clip)
Definition midi_follow.cpp:730
void readDefaultsFromFile()
read defaults from XML
Definition midi_follow.cpp:1845
Output * pitchBendReceivedForSelectedOrActiveClip(MIDICable &cable, uint8_t channel, uint8_t data1, uint8_t data2, bool *doingMidiThru, ModelStack *modelStack)
Definition midi_follow.cpp:1460
ModelStackWithAutoParam * getModelStackWithParam(ModelStackWithTimelineCounter *modelStackWithTimelineCounter, Clip *clip, int32_t soundParamId, int32_t globalParamId, bool displayError=true)
Definition midi_follow.cpp:513
void midiCCReceivedForSpecificTrack(MIDICable &cable, uint8_t channel, uint8_t ccNumber, uint8_t ccValue, bool *doingMidiThru, ModelStack *modelStack, Output *specific_track, int32_t specific_track_index)
Definition midi_follow.cpp:981
void pitchBendReceived(MIDICable &cable, uint8_t channel, uint8_t data1, uint8_t data2, bool *doingMidiThru, ModelStack *modelStack)
Definition midi_follow.cpp:1429
void pitchBendReceivedForSpecificTrack(MIDICable &cable, uint8_t channel, uint8_t data1, uint8_t data2, bool *doingMidiThru, ModelStack *modelStack, Output *specific_track, int32_t specific_track_index)
Definition midi_follow.cpp:1499
bool writeDefaultsToFile()
Definition midi_follow.cpp:1661
Output * midiCCReceivedForSelectedOrActiveClip(MIDICable &cable, uint8_t channel, uint8_t ccNumber, uint8_t ccValue, bool *doingMidiThru, ModelStack *modelStack)
Definition midi_follow.cpp:910
Output * noteMessageReceivedForSelectedOrActiveClip(MIDICable &cable, bool on, int32_t channel, int32_t note, int32_t velocity, bool *doingMidiThru, bool shouldRecordNotesNowNow, ModelStack *modelStack)
Definition midi_follow.cpp:772
void handleReceivedCC(MIDICable &cable, ModelStackWithTimelineCounter &modelStack, Clip *clip, int32_t ccNumber, int32_t ccValue)
Definition midi_follow.cpp:1059
void midiCCReceived(MIDICable &cable, uint8_t channel, uint8_t ccNumber, uint8_t ccValue, bool *doingMidiThru, ModelStack *modelStack)
Definition midi_follow.cpp:880
char const * getNameFromChannelType(MIDIFollowChannelType type)
enum / string lookup functions
Definition midi_follow.cpp:2069
void noteMessageReceived(MIDICable &cable, bool on, int32_t channel, int32_t note, int32_t velocity, bool *doingMidiThru, bool shouldRecordNotesNowNow, ModelStack *modelStack)
Definition midi_follow.cpp:741
void readDefaultMappingsFromFile(Deserializer &reader)
Definition midi_follow.cpp:1907
void readChannelSettingsFromFile(Deserializer &reader)
Read Channel settings from XML.
Definition midi_follow.cpp:1973
void clearStoredClips()
Definition midi_follow.cpp:721
void readKitRootNoteSettingFromFile(Deserializer &reader)
Read Kit Root Note setting from XML.
Definition midi_follow.cpp:2008
void aftertouchReceived(MIDICable &cable, int32_t channel, int32_t value, int32_t noteCode, bool *doingMidiThru, ModelStack *modelStack)
Definition midi_follow.cpp:1528
bool isGlobalEffectableContext()
Definition midi_follow.cpp:696
MIDIMatchType checkMidiFollowMatchForSpecificTrack(MIDICable &cable, uint8_t channel, int32_t specific_track_index)
Definition midi_follow.cpp:1641
Output * getTrackFromIndex(uint32_t trackIndex, uint32_t maxTrack)
used to forward midi messages to specific tracks
Definition midi_follow.cpp:493
void readDisplayParamSettingFromFile(Deserializer &reader)
Read Display Param setting from XML.
Definition midi_follow.cpp:2054
void readSpecificChannelSettingsFromFile(Deserializer &reader, MIDIFollowChannelType type)
Read Specific Channel settings from XML.
Definition midi_follow.cpp:1987
void readFeedbackSettingsFromFile(Deserializer &reader)
Read Feedback settings from XML.
Definition midi_follow.cpp:2024
void writeDisplayParamSettingToFile(Serializer &writer)
Write Display Param setting to XML.
Definition midi_follow.cpp:1825
void sendCCWithoutModelStackForMidiFollowFeedback(bool isAutomation=false)
Definition midi_follow.cpp:1306
void writeDefaultSettingsToFile(Serializer &writer)
write default settings (channels, kit root note, feedback, display param) to XML
Definition midi_follow.cpp:1731
void sendCCForMidiFollowFeedback(int32_t ccNumber, int32_t knobPos)
Resolve the configured MIDI Follow feedback targets and send a learned CC value to each one.
Definition midi_follow.cpp:1393
Output * aftertouchReceivedForSelectedOrActiveClip(MIDICable &cable, int32_t channel, int32_t value, int32_t noteCode, bool *doingMidiThru, ModelStack *modelStack)
Definition midi_follow.cpp:1559
Definition model_stack.h:264
Definition model_stack.h:227
Definition model_stack.h:129
Definition model_stack.h:123
Definition output.h:81
Definition storage_manager.h:124
Definition param.cpp:30
Kind
Definition param.h:42