Deluge Firmware 1.3.0
Build date: 2026.07.15
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 <cstdint>
26
27class AudioClip;
28class InstrumentClip;
29class Clip;
30class Kit;
31class Drum;
32class ModelStack;
35enum class MIDIMatchType;
36
38
39class MidiFollow final {
40public:
41 MidiFollow();
44
46 Clip* clip, int32_t soundParamId, int32_t globalParamId,
47 bool displayError = true);
48 void noteMessageReceived(MIDICable& cable, bool on, int32_t channel, int32_t note, int32_t velocity,
49 bool* doingMidiThru, bool shouldRecordNotesNowNow, ModelStack* modelStack);
50 Output* sendNoteToClip(MIDICable& cable, Clip* clip, MIDIMatchType match, bool on, int32_t channel, int32_t note,
51 int32_t velocity, bool* doingMidiThru, bool shouldRecordNotesNowNow, ModelStack* modelStack,
52 bool updateClipForLastNoteReceived = true);
53 void midiCCReceived(MIDICable& cable, uint8_t channel, uint8_t ccNumber, uint8_t ccValue, bool* doingMidiThru,
54 ModelStack* modelStack);
55 void pitchBendReceived(MIDICable& cable, uint8_t channel, uint8_t data1, uint8_t data2, bool* doingMidiThru,
56 ModelStack* modelStack);
57 void aftertouchReceived(MIDICable& cable, int32_t channel, int32_t value, int32_t noteCode, bool* doingMidiThru,
58 ModelStack* modelStack);
59
60 void clearStoredClips();
61 void removeClip(Clip* clip);
62
63 // midi CC mappings
64 int32_t getCCFromParam(deluge::modulation::params::Kind paramKind, int32_t paramID);
66
67 std::array<uint8_t, kMaxMIDIValue + 1> ccToSoundParam;
68 std::array<uint8_t, kMaxMIDIValue + 1> ccToGlobalParam;
69 std::array<uint8_t, params::UNPATCHED_START + params::UNPATCHED_SOUND_MAX_NUM> soundParamToCC;
70 std::array<uint8_t, params::UNPATCHED_GLOBAL_MAX_NUM> globalParamToCC;
71
72 int32_t previousKnobPos[kMaxMIDIValue + 1];
73 uint32_t timeLastCCSent[kMaxMIDIValue + 1];
74 uint32_t timeAutomationFeedbackLastSent;
75
76 // public so it can be called from View::sendMidiFollowFeedback
77 MIDIFollowChannelType getChannelTypeForFeedback();
78 void sendCCWithoutModelStackForMidiFollowFeedback(int32_t channel, bool isAutomation = false);
79 void sendCCForMidiFollowFeedback(int32_t channel, int32_t ccNumber, int32_t knobPos);
80
81 void handleReceivedCC(MIDICable& cable, ModelStackWithTimelineCounter& modelStack, Clip* clip, int32_t ccNumber,
82 int32_t ccValue);
83
84private:
85 // initialize
86 void init();
87 void initState();
88 void clearMappings();
89 void initDefaultMappings();
90
91 // note recieved
92 Output* noteMessageReceivedForSelectedOrActiveClip(MIDICable& cable, bool on, int32_t channel, int32_t note,
93 int32_t velocity, bool* doingMidiThru,
94 bool shouldRecordNotesNowNow, ModelStack* modelStack);
95 void noteMessageReceivedForSpecificTrack(MIDICable& cable, bool on, int32_t channel, int32_t note, int32_t velocity,
96 bool* doingMidiThru, bool shouldRecordNotesNowNow, ModelStack* modelStack,
97 Output* specific_track, int32_t specific_track_index);
98 // cc received
99 Output* midiCCReceivedForSelectedOrActiveClip(MIDICable& cable, uint8_t channel, uint8_t ccNumber, uint8_t ccValue,
100 bool* doingMidiThru, ModelStack* modelStack);
101 void midiCCReceivedForSpecificTrack(MIDICable& cable, uint8_t channel, uint8_t ccNumber, uint8_t ccValue,
102 bool* doingMidiThru, ModelStack* modelStack, Output* specific_track,
103 int32_t specific_track_index);
104
105 // pitch bend received
106 Output* pitchBendReceivedForSelectedOrActiveClip(MIDICable& cable, uint8_t channel, uint8_t data1, uint8_t data2,
107 bool* doingMidiThru, ModelStack* modelStack);
108 void pitchBendReceivedForSpecificTrack(MIDICable& cable, uint8_t channel, uint8_t data1, uint8_t data2,
109 bool* doingMidiThru, ModelStack* modelStack, Output* specific_track,
110 int32_t specific_track_index);
111
112 // after touch received
113 Output* aftertouchReceivedForSelectedOrActiveClip(MIDICable& cable, int32_t channel, int32_t value,
114 int32_t noteCode, bool* doingMidiThru, ModelStack* modelStack);
115 void aftertouchReceivedForSpecificTrack(MIDICable& cable, int32_t channel, int32_t value, int32_t noteCode,
116 bool* doingMidiThru, ModelStack* modelStack, Output* specific_track,
117 int32_t specific_track_index);
118
121 Clip* getActiveClip(ModelStack* modelStack);
122 [[nodiscard]] const size_t getTrackCount() const;
123 Output* getTrackFromIndex(uint32_t trackIndex, uint32_t maxTrack);
124
125 // get model stack with auto param for midi follow cc-param control
126 ModelStackWithAutoParam* getModelStackWithParamForSong(ModelStackWithThreeMainThings* modelStackWithThreeMainThings,
127 int32_t soundParamId, int32_t globalParamId);
128 ModelStackWithAutoParam* getModelStackWithParamForClip(ModelStackWithTimelineCounter* modelStackWithTimelineCounter,
129 Clip* clip, int32_t soundParamId, int32_t globalParamId);
131 getModelStackWithParamForSynthClip(ModelStackWithTimelineCounter* modelStackWithTimelineCounter, Clip* clip,
132 int32_t soundParamId, int32_t globalParamId);
134 getModelStackWithParamForKitClip(ModelStackWithTimelineCounter* modelStackWithTimelineCounter, Clip* clip,
135 int32_t soundParamId, int32_t globalParamId);
137 getModelStackWithParamForAudioClip(ModelStackWithTimelineCounter* modelStackWithTimelineCounter, Clip* clip,
138 int32_t soundParamId, int32_t globalParamId);
139 void displayParamControlError(int32_t soundParamId, int32_t globalParamId);
140
141 MIDIMatchType checkMidiFollowMatch(MIDICable& cable, uint8_t channel);
142 MIDIMatchType checkMidiFollowMatchForSpecificTrack(MIDICable& cable, uint8_t channel, int32_t specific_track_index);
143 bool isFeedbackEnabled();
144
145 // Saving
146
147 // CC Mappings
149
150 // Settings
153 void writeSpecificChannelSettingsToFile(Serializer& writer, MIDIFollowChannelType type);
157
158 // Loading
159 bool successfullyReadDefaultsFromFile;
160
161 // CC Mappings
163
164 // Settings
167 void readSpecificChannelSettingsFromFile(Deserializer& reader, MIDIFollowChannelType type);
171
172 // string tags / values
173 char const* getNameFromChannelType(MIDIFollowChannelType type);
174 MIDIFollowChannelType getChannelTypeFromName(char const* name);
175
176 char const* getNameFromFeedbackAutomationMode(MIDIFollowFeedbackAutomationMode mode);
177 MIDIFollowFeedbackAutomationMode getFeedbackAutomationModeFromName(char const* name);
178
179 char const* getNameFromBool(bool value);
180 bool getBoolFromName(char const* name);
181};
182
183extern MidiFollow midiFollow;
Definition audio_clip.h:35
Definition clip.h:46
Definition storage_manager.h:185
Definition drum.h:44
Definition instrument_clip.h:48
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:39
void writeFeedbackSettingsToFile(Serializer &writer)
Write Feedback settings to XML.
Definition midi_follow.cpp:1635
Clip * getSelectedClip()
Definition midi_follow.cpp:392
void writeDefaultsToFile()
Definition midi_follow.cpp:1480
int32_t getCCFromParam(deluge::modulation::params::Kind paramKind, int32_t paramID)
Definition midi_follow.cpp:643
void writeKitRootNoteSettingToFile(Serializer &writer)
Write Kit Root Note setting to XML.
Definition midi_follow.cpp:1628
const size_t getTrackCount() const
used to forward midi messages to specific tracks
Definition midi_follow.cpp:447
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:776
void writeSpecificChannelSettingsToFile(Serializer &writer, MIDIFollowChannelType type)
Write Specific Channel settings to XML.
Definition midi_follow.cpp:1608
MIDIMatchType checkMidiFollowMatch(MIDICable &cable, uint8_t channel)
Definition midi_follow.cpp:1440
Clip * getSelectedOrActiveClip()
Definition midi_follow.cpp:368
Clip * getActiveClip(ModelStack *modelStack)
Definition midi_follow.cpp:432
void writeChannelSettingsToFile(Serializer &writer)
Write Channel settings to XML.
Definition midi_follow.cpp:1585
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:1411
void writeDefaultMappingsToFile(Serializer &writer)
convert paramID to a paramName to write to XML
Definition midi_follow.cpp:1510
void readDefaultSettingsFromFile(Deserializer &reader)
read default settings (channels, kit root note, feedback, display param) from XML
Definition midi_follow.cpp:1743
void removeClip(Clip *clip)
Definition midi_follow.cpp:698
void readDefaultsFromFile()
read defaults from XML
Definition midi_follow.cpp:1649
Output * pitchBendReceivedForSelectedOrActiveClip(MIDICable &cable, uint8_t channel, uint8_t data1, uint8_t data2, bool *doingMidiThru, ModelStack *modelStack)
Definition midi_follow.cpp:1285
ModelStackWithAutoParam * getModelStackWithParam(ModelStackWithTimelineCounter *modelStackWithTimelineCounter, Clip *clip, int32_t soundParamId, int32_t globalParamId, bool displayError=true)
Definition midi_follow.cpp:481
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:943
void pitchBendReceived(MIDICable &cable, uint8_t channel, uint8_t data1, uint8_t data2, bool *doingMidiThru, ModelStack *modelStack)
Definition midi_follow.cpp:1254
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:1318
Output * midiCCReceivedForSelectedOrActiveClip(MIDICable &cable, uint8_t channel, uint8_t ccNumber, uint8_t ccValue, bool *doingMidiThru, ModelStack *modelStack)
Definition midi_follow.cpp:873
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:740
void handleReceivedCC(MIDICable &cable, ModelStackWithTimelineCounter &modelStack, Clip *clip, int32_t ccNumber, int32_t ccValue)
Definition midi_follow.cpp:1021
void sendCCWithoutModelStackForMidiFollowFeedback(int32_t channel, bool isAutomation=false)
Definition midi_follow.cpp:1161
void midiCCReceived(MIDICable &cable, uint8_t channel, uint8_t ccNumber, uint8_t ccValue, bool *doingMidiThru, ModelStack *modelStack)
Definition midi_follow.cpp:843
char const * getNameFromChannelType(MIDIFollowChannelType type)
enum / string lookup functions
Definition midi_follow.cpp:1862
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:709
void readDefaultMappingsFromFile(Deserializer &reader)
Definition midi_follow.cpp:1701
void readChannelSettingsFromFile(Deserializer &reader)
Read Channel settings from XML.
Definition midi_follow.cpp:1767
void clearStoredClips()
Definition midi_follow.cpp:689
void readKitRootNoteSettingFromFile(Deserializer &reader)
Read Kit Root Note setting from XML.
Definition midi_follow.cpp:1801
void aftertouchReceived(MIDICable &cable, int32_t channel, int32_t value, int32_t noteCode, bool *doingMidiThru, ModelStack *modelStack)
Definition midi_follow.cpp:1347
bool isGlobalEffectableContext()
Definition midi_follow.cpp:664
MIDIMatchType checkMidiFollowMatchForSpecificTrack(MIDICable &cable, uint8_t channel, int32_t specific_track_index)
Definition midi_follow.cpp:1454
Output * getTrackFromIndex(uint32_t trackIndex, uint32_t maxTrack)
used to forward midi messages to specific tracks
Definition midi_follow.cpp:461
void readDisplayParamSettingFromFile(Deserializer &reader)
Read Display Param setting from XML.
Definition midi_follow.cpp:1847
void readSpecificChannelSettingsFromFile(Deserializer &reader, MIDIFollowChannelType type)
Read Specific Channel settings from XML.
Definition midi_follow.cpp:1781
void readFeedbackSettingsFromFile(Deserializer &reader)
Read Feedback settings from XML.
Definition midi_follow.cpp:1817
void sendCCForMidiFollowFeedback(int32_t channel, int32_t ccNumber, int32_t knobPos)
called when updating parameter values using mod (gold) encoders or the select encoder in the soundEdi...
Definition midi_follow.cpp:1234
void writeDisplayParamSettingToFile(Serializer &writer)
Write Display Param setting to XML.
Definition midi_follow.cpp:1644
void writeDefaultSettingsToFile(Serializer &writer)
write default settings (channels, kit root note, feedback, display param) to XML
Definition midi_follow.cpp:1550
Output * aftertouchReceivedForSelectedOrActiveClip(MIDICable &cable, int32_t channel, int32_t value, int32_t noteCode, bool *doingMidiThru, ModelStack *modelStack)
Definition midi_follow.cpp:1378
Definition model_stack.h:269
Definition model_stack.h:231
Definition model_stack.h:129
Definition model_stack.h:123
Definition output.h:81
Definition storage_manager.h:119
Definition param.cpp:28
Kind
Definition param.h:42