Deluge Firmware 1.3.0
Build date: 2025.04.16
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();
43
45 Clip* clip, int32_t soundParamId, int32_t globalParamId,
46 bool displayError = true);
47 void noteMessageReceived(MIDICable& cable, bool on, int32_t channel, int32_t note, int32_t velocity,
48 bool* doingMidiThru, bool shouldRecordNotesNowNow, ModelStack* modelStack);
49 void sendNoteToClip(MIDICable& cable, Clip* clip, MIDIMatchType match, bool on, int32_t channel, int32_t note,
50 int32_t velocity, bool* doingMidiThru, bool shouldRecordNotesNowNow, ModelStack* modelStack);
51 void midiCCReceived(MIDICable& cable, uint8_t channel, uint8_t ccNumber, uint8_t ccValue, bool* doingMidiThru,
52 ModelStack* modelStack);
53 void pitchBendReceived(MIDICable& cable, uint8_t channel, uint8_t data1, uint8_t data2, bool* doingMidiThru,
54 ModelStack* modelStack);
55 void aftertouchReceived(MIDICable& cable, int32_t channel, int32_t value, int32_t noteCode, bool* doingMidiThru,
56 ModelStack* modelStack);
57
58 void clearStoredClips();
59 void removeClip(Clip* clip);
60
61 // midi CC mappings
62 int32_t getCCFromParam(deluge::modulation::params::Kind paramKind, int32_t paramID);
63 bool isGlobalEffectableContext();
64
65 std::array<uint8_t, kMaxMIDIValue + 1> ccToSoundParam;
66 std::array<uint8_t, kMaxMIDIValue + 1> ccToGlobalParam;
67 std::array<uint8_t, params::UNPATCHED_START + params::UNPATCHED_SOUND_MAX_NUM> soundParamToCC;
68 std::array<uint8_t, params::UNPATCHED_GLOBAL_MAX_NUM> globalParamToCC;
69
70 int32_t previousKnobPos[kMaxMIDIValue + 1];
71 uint32_t timeLastCCSent[kMaxMIDIValue + 1];
72 uint32_t timeAutomationFeedbackLastSent;
73
74 // public so it can be called from View::sendMidiFollowFeedback
75 void sendCCWithoutModelStackForMidiFollowFeedback(int32_t channel, bool isAutomation = false);
76 void sendCCForMidiFollowFeedback(int32_t channel, int32_t ccNumber, int32_t knobPos);
77
78 void handleReceivedCC(ModelStackWithTimelineCounter& modelStack, Clip* clip, int32_t ccNumber, int32_t ccValue);
79
80private:
81 // initialize
82 void init();
83 void initState();
84 void clearMappings();
85 void initDefaultMappings();
86
89 Clip* getActiveClip(ModelStack* modelStack);
90
91 // get model stack with auto param for midi follow cc-param control
92 ModelStackWithAutoParam* getModelStackWithParamForSong(ModelStackWithThreeMainThings* modelStackWithThreeMainThings,
93 int32_t soundParamId, int32_t globalParamId);
94 ModelStackWithAutoParam* getModelStackWithParamForClip(ModelStackWithTimelineCounter* modelStackWithTimelineCounter,
95 Clip* clip, int32_t soundParamId, int32_t globalParamId);
97 getModelStackWithParamForSynthClip(ModelStackWithTimelineCounter* modelStackWithTimelineCounter, Clip* clip,
98 int32_t soundParamId, int32_t globalParamId);
100 getModelStackWithParamForKitClip(ModelStackWithTimelineCounter* modelStackWithTimelineCounter, Clip* clip,
101 int32_t soundParamId, int32_t globalParamId);
103 getModelStackWithParamForAudioClip(ModelStackWithTimelineCounter* modelStackWithTimelineCounter, Clip* clip,
104 int32_t soundParamId, int32_t globalParamId);
105 void displayParamControlError(int32_t soundParamId, int32_t globalParamId);
106
107 MIDIMatchType checkMidiFollowMatch(MIDICable& cable, uint8_t channel);
108 bool isFeedbackEnabled();
109
110 // saving
111 void writeDefaultsToFile();
113
114 // loading
115 bool successfullyReadDefaultsFromFile;
117};
118
119extern 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:94
Definition midi_follow.h:39
Clip * getSelectedClip()
Definition midi_follow.cpp:343
void writeDefaultsToFile()
Definition midi_follow.cpp:1032
int32_t getCCFromParam(deluge::modulation::params::Kind paramKind, int32_t paramID)
Definition midi_follow.cpp:562
MIDIMatchType checkMidiFollowMatch(MIDICable &cable, uint8_t channel)
Definition midi_follow.cpp:1007
Clip * getSelectedOrActiveClip()
Definition midi_follow.cpp:319
void removeClip(Clip *clip)
Definition midi_follow.cpp:617
void readDefaultsFromFile()
read defaults from XML
Definition midi_follow.cpp:1095
void handleReceivedCC(ModelStackWithTimelineCounter &modelStack, Clip *clip, int32_t ccNumber, int32_t ccValue)
Definition midi_follow.cpp:762
ModelStackWithAutoParam * getModelStackWithParam(ModelStackWithTimelineCounter *modelStackWithTimelineCounter, Clip *clip, int32_t soundParamId, int32_t globalParamId, bool displayError=true)
Definition midi_follow.cpp:400
void pitchBendReceived(MIDICable &cable, uint8_t channel, uint8_t data1, uint8_t data2, bool *doingMidiThru, ModelStack *modelStack)
Definition midi_follow.cpp:952
void sendCCWithoutModelStackForMidiFollowFeedback(int32_t channel, bool isAutomation=false)
Definition midi_follow.cpp:859
void midiCCReceived(MIDICable &cable, uint8_t channel, uint8_t ccNumber, uint8_t ccValue, bool *doingMidiThru, ModelStack *modelStack)
Definition midi_follow.cpp:695
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:628
void readDefaultMappingsFromFile(Deserializer &reader)
Definition midi_follow.cpp:1152
void clearStoredClips()
Definition midi_follow.cpp:608
void aftertouchReceived(MIDICable &cable, int32_t channel, int32_t value, int32_t noteCode, bool *doingMidiThru, ModelStack *modelStack)
Definition midi_follow.cpp:980
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:932
void writeDefaultMappingsToFile()
convert paramID to a paramName to write to XML
Definition midi_follow.cpp:1057
Definition model_stack.h:269
Definition model_stack.h:231
Definition model_stack.h:129
Definition model_stack.h:123
Definition param.cpp:27
Kind
Definition param.h:42