Deluge Firmware 1.3.0
Build date: 2026.07.29
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() override { 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 = toRecordfrom;
116 }
117
122 if (outputRecordingFrom && outputRecordingFrom->getOutputRecordingThis() == this) {
123 outputRecordingFrom->setRenderingToAudioOutput(false, nullptr);
124 }
125 }
126
130 if (outputRecordingFrom && mode != AudioOutputMode::player) {
131 outputRecordingFrom->setRenderingToAudioOutput(true, this);
132 }
133 else {
135 }
136 }
137
138 ModelStackWithAutoParam* getModelStackWithParam(ModelStackWithTimelineCounter* modelStack, Clip* clip,
139 int32_t paramID, deluge::modulation::params::Kind paramKind,
140 bool affectEntire, bool useMenuStack) override;
141 void scrollAudioOutputMode(int offset) {
142 auto modeInt = util::to_underlying(mode);
143 modeInt = (modeInt + offset) % kNumAudioOutputModes;
144
145 mode = static_cast<AudioOutputMode>(std::clamp<int>(modeInt, 0, kNumAudioOutputModes - 1));
146 // update the output we're recording from on whether we're monitoring
148 renderUIsForOled(); // oled shows the type on the clip screen (including while holding a clip in song view)
149 if (display->have7SEG()) {
150 const char* type;
151 switch (mode) {
152 case AudioOutputMode::player:
153 type = "PLAY";
154 break;
155 case AudioOutputMode::sampler:
156 type = "SAMP";
157 break;
158 case AudioOutputMode::looper:
159 type = "LOOP";
160 }
161 display->displayPopup(type);
162 }
163 }
164
165protected:
166 Clip* createNewClipForArrangementRecording(ModelStack* modelStack) override;
167 bool wantsToBeginArrangementRecording() override;
168 bool willRenderAsOneChannelOnlyWhichWillNeedCopying() override;
169
171 bool modeAllowsMonitoring() const;
173 Output* outputRecordingFrom{nullptr};
174};
AudioInputChannel inputChannel
Audio channel used for recording and monitoring.
Definition audio_output.h:96
Output * getOutputRecordingFrom() override
Which output this one records from, or nullptr. Only audio outputs ever record from another output.
Definition audio_output.h:106
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:173
void updateMonitoringClaim()
Definition audio_output.h:129
bool modeAllowsMonitoring() const
returns true for loopers and samplers without a file
Definition audio_output.cpp:117
int16_t outputRecordingFromIndex
Definition audio_output.h:102
void releaseMonitoringClaim()
Definition audio_output.h:121
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:96
Definition mod_controllable.h:40
Definition model_stack.h:269
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:103
Definition sound.h:71
Kind
Definition param.h:42