Deluge Firmware 1.3.0
Build date: 2025.04.16
Loading...
Searching...
No Matches
audio_output.h
1/*
2 * Copyright © 2019-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 "definitions_cxx.hpp"
21#include "gui/ui/ui.h"
22#include "model/global_effectable/global_effectable_for_clip.h"
23#include "model/output.h"
24#include "modulation/envelope.h"
25#include "util/container/enum_to_string_map.hpp"
26
28
32enum class AudioOutputMode : uint8_t { player, sampler, looper };
33constexpr int kNumAudioOutputModes = 3;
34AudioOutputMode stringToAOMode(char const* string);
35char const* aoModeToString(AudioOutputMode mode);
36
37class AudioOutput final : public Output, public GlobalEffectableForClip {
38public:
39 AudioOutput();
40 ~AudioOutput() override;
41 void cloneFrom(ModControllableAudio* other) override;
42
43 void renderOutput(ModelStack* modelStack, std::span<StereoSample> buffer, int32_t* reverbBuffer,
44 int32_t reverbAmountAdjust, int32_t sideChainHitPending, bool shouldLimitDelayFeedback,
45 bool isClipActive) override;
46
47 bool renderGlobalEffectableForClip(ModelStackWithTimelineCounter* modelStack,
48 std::span<StereoSample> globalEffectableBuffer, int32_t* bufferToTransferTo,
49 int32_t* reverbBuffer, int32_t reverbAmountAdjust, int32_t sideChainHitPending,
50 bool shouldLimitDelayFeedback, bool isClipActive, int32_t pitchAdjust,
51 int32_t amplitudeAtStart, int32_t amplitudeAtEnd) override;
52
53 void resetEnvelope();
54 bool matchesPreset(OutputType otherType, int32_t channel, int32_t channelSuffix, char const* otherName,
55 char const* dirPath) override {
56 return false;
57 };
58
59 ModControllable* toModControllable() override { return this; }
60 uint8_t* getModKnobMode() override { return &modKnobMode; }
61
62 void cutAllSound() override;
63 void getThingWithMostReverb(Sound** soundWithMostReverb, ParamManagerForTimeline** paramManagerWithMostReverb,
64 Kit** kitWithMostReverb, int32_t* highestReverbAmountFound);
65
66 Error readFromFile(Deserializer& reader, Song* song, Clip* clip, int32_t readAutomationUpToPos) override;
67 bool writeDataToFile(Serializer& writer, Clip* clipForSavingOutputOnly, Song* song) override;
68 void deleteBackedUpParamManagers(Song* song) override;
69 bool setActiveClip(ModelStackWithTimelineCounter* modelStack,
70 PgmChangeSend maySendMIDIPGMs = PgmChangeSend::ONCE) override;
71 bool isSkippingRendering() override;
72 Output* toOutput() override { return this; }
73 void getThingWithMostReverb(Sound** soundWithMostReverb, ParamManager** paramManagerWithMostReverb,
74 GlobalEffectableForClip** globalEffectableWithMostReverb,
75 int32_t* highestReverbAmountFound) override;
76
77 // A TimelineCounter is required
78 void offerReceivedCCToLearnedParams(MIDICable& cable, uint8_t channel, uint8_t ccNumber, uint8_t value,
79 ModelStackWithTimelineCounter* modelStack) override {
80 ModControllableAudio::offerReceivedCCToLearnedParamsForClip(cable, channel, ccNumber, value, modelStack);
81 }
82 bool offerReceivedPitchBendToLearnedParams(MIDICable& cable, uint8_t channel, uint8_t data1, uint8_t data2,
83 ModelStackWithTimelineCounter* modelStack) override {
84 return ModControllableAudio::offerReceivedPitchBendToLearnedParams(cable, channel, data1, data2, modelStack);
85 }
86
87 char const* getXMLTag() override { return "audioTrack"; }
88
89 Envelope envelope;
90
91 int32_t amplitudeLastTime;
92
93 int32_t overrideAmplitudeEnvelopeReleaseRate;
94
96 AudioInputChannel inputChannel{AudioInputChannel::UNSET};
97
102 int16_t outputRecordingFromIndex{-1}; // int16 so it fits with the bool and mode
103
104 AudioOutputMode mode{AudioOutputMode::player};
105
106 Output* getOutputRecordingFrom() { return outputRecordingFrom; }
107 void clearRecordingFrom() override { setOutputRecordingFrom(nullptr); }
108 void setOutputRecordingFrom(Output* toRecordfrom) {
109 if (toRecordfrom == this) {
110 // can happen from bad save files
111 return;
112 }
114 outputRecordingFrom->setRenderingToAudioOutput(false, nullptr);
115 }
116 outputRecordingFrom = toRecordfrom;
118 // If we are a SAMPLER or a LOOPER then we're monitoring the audio, so tell the other output that we're in
119 // charge of rendering
120 outputRecordingFrom->setRenderingToAudioOutput(mode != AudioOutputMode::player, this);
121 }
122 }
123
124 ModelStackWithAutoParam* getModelStackWithParam(ModelStackWithTimelineCounter* modelStack, Clip* clip,
125 int32_t paramID, deluge::modulation::params::Kind paramKind,
126 bool affectEntire, bool useMenuStack) override;
127 void scrollAudioOutputMode(int offset) {
128 auto modeInt = util::to_underlying(mode);
129 modeInt = (modeInt + offset) % kNumAudioOutputModes;
130
131 mode = static_cast<AudioOutputMode>(std::clamp<int>(modeInt, 0, kNumAudioOutputModes - 1));
133 // update the output we're recording from on whether we're monitoring
134 outputRecordingFrom->setRenderingToAudioOutput(mode != AudioOutputMode::player, this);
135 }
136 renderUIsForOled(); // oled shows the type on the clip screen (including while holding a clip in song view)
137 if (display->have7SEG()) {
138 const char* type;
139 switch (mode) {
140 case AudioOutputMode::player:
141 type = "PLAY";
142 break;
143 case AudioOutputMode::sampler:
144 type = "SAMP";
145 break;
146 case AudioOutputMode::looper:
147 type = "LOOP";
148 }
149 display->displayPopup(type);
150 }
151 }
152
153protected:
154 Clip* createNewClipForArrangementRecording(ModelStack* modelStack) override;
155 bool wantsToBeginArrangementRecording() override;
156 bool willRenderAsOneChannelOnlyWhichWillNeedCopying() override;
157
159 Output* outputRecordingFrom{nullptr};
160};
AudioInputChannel inputChannel
Audio channel used for recording and monitoring.
Definition audio_output.h:96
bool offerReceivedPitchBendToLearnedParams(MIDICable &cable, uint8_t channel, uint8_t data1, uint8_t data2, ModelStackWithTimelineCounter *modelStack) override
Pitch bend is available in the mod matrix as X and shouldn't be learned to params anymore (post 4....
Definition audio_output.h:82
Output * outputRecordingFrom
Which output to record from. Only valid when inputChannel is AudioInputChannel::SPECIFIC_OUTPUT.
Definition audio_output.h:159
int16_t outputRecordingFromIndex
Definition audio_output.h:102
Definition clip.h:46
Definition storage_manager.h:185
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 mod_controllable.h:40
Definition model_stack.h:129
Definition model_stack.h:123
Definition param_manager.h:174
Definition param_manager.h:45
Definition storage_manager.h:119
Definition song.h:104
Definition sound.h:71
Kind
Definition param.h:42