|
| 1 | +/* |
| 2 | + * AudioBusHandle.h - ThreadableJob between PlayHandle and MixerChannel |
| 3 | + * |
| 4 | + * Copyright (c) 2005-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net> |
| 5 | + * Copyright (c) 2025 Johannes Lorenz <jlsf2013$users.sourceforge.net, $=@> |
| 6 | + * |
| 7 | + * This file is part of LMMS - https://lmms.io |
| 8 | + * |
| 9 | + * This program is free software; you can redistribute it and/or |
| 10 | + * modify it under the terms of the GNU General Public |
| 11 | + * License as published by the Free Software Foundation; either |
| 12 | + * version 2 of the License, or (at your option) any later version. |
| 13 | + * |
| 14 | + * This program is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | + * General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU General Public |
| 20 | + * License along with this program (see COPYING); if not, write to the |
| 21 | + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 22 | + * Boston, MA 02110-1301 USA. |
| 23 | + * |
| 24 | + */ |
| 25 | + |
| 26 | +#ifndef LMMS_AUDIO_BUS_HANDLE_H |
| 27 | +#define LMMS_AUDIO_BUS_HANDLE_H |
| 28 | + |
| 29 | +#include <memory> |
| 30 | +#include <QString> |
| 31 | +#include <QMutex> |
| 32 | + |
| 33 | +#include "PlayHandle.h" |
| 34 | + |
| 35 | +namespace lmms |
| 36 | +{ |
| 37 | + |
| 38 | +class EffectChain; |
| 39 | +class FloatModel; |
| 40 | +class BoolModel; |
| 41 | + |
| 42 | +/** |
| 43 | + @brief Job between @ref PlayHandle and @ref MixerChannel |
| 44 | +
|
| 45 | + A @ref ThreadableJob class located at the exit point of each @ref PlayHandle into a @ref MixerChannel |
| 46 | + (or into an audio device, in case of @ref AudioJack, but this is not supported in AudioBusHandle yet). |
| 47 | + It contains an optional @ref EffectChain which is e.g. visualized in the |
| 48 | + @ref InstrumentTrackWindow or @ref SampleTrackWindow. |
| 49 | + For processing, it adds all input play handles into an internal buffer, |
| 50 | + processes the @ref EffectChain (if existing) on that buffer |
| 51 | + and finally merges the buffer into its @ref MixerChannel. |
| 52 | +*/ |
| 53 | +class AudioBusHandle : public ThreadableJob |
| 54 | +{ |
| 55 | +public: |
| 56 | + AudioBusHandle(const QString& name, bool hasEffectChain = true, |
| 57 | + FloatModel* volumeModel = nullptr, FloatModel* panningModel = nullptr, |
| 58 | + BoolModel* mutedModel = nullptr); |
| 59 | + virtual ~AudioBusHandle(); |
| 60 | + |
| 61 | + SampleFrame* buffer() { return m_buffer; } |
| 62 | + |
| 63 | + // indicate whether JACK & Co should provide output-buffer at ext. port |
| 64 | + bool extOutputEnabled() const { return m_extOutputEnabled; } |
| 65 | + void setExtOutputEnabled(bool enabled); |
| 66 | + |
| 67 | + // next mixer-channel after this audio-bus-handle |
| 68 | + // (-1 = none 0 = master) |
| 69 | + mix_ch_t nextMixerChannel() const { return m_nextMixerChannel; } |
| 70 | + void setNextMixerChannel(const mix_ch_t chnl) { m_nextMixerChannel = chnl; } |
| 71 | + |
| 72 | + const QString& name() const { return m_name; } |
| 73 | + void setName(const QString& newName); |
| 74 | + |
| 75 | + EffectChain* effects() { return m_effects.get(); } |
| 76 | + bool processEffects(); |
| 77 | + |
| 78 | + // ThreadableJob stuff |
| 79 | + void doProcessing() override; |
| 80 | + bool requiresProcessing() const override { return true; } |
| 81 | + |
| 82 | + void addPlayHandle(PlayHandle* handle); |
| 83 | + void removePlayHandle(PlayHandle* handle); |
| 84 | + |
| 85 | +private: |
| 86 | + volatile bool m_bufferUsage; |
| 87 | + |
| 88 | + SampleFrame* const m_buffer; |
| 89 | + |
| 90 | + bool m_extOutputEnabled; |
| 91 | + mix_ch_t m_nextMixerChannel; |
| 92 | + |
| 93 | + QString m_name; |
| 94 | + |
| 95 | + std::unique_ptr<EffectChain> m_effects; |
| 96 | + |
| 97 | + PlayHandleList m_playHandles; |
| 98 | + QMutex m_playHandleLock; |
| 99 | + |
| 100 | + FloatModel* m_volumeModel; |
| 101 | + FloatModel* m_panningModel; |
| 102 | + BoolModel* m_mutedModel; |
| 103 | + |
| 104 | + friend class AudioEngine; |
| 105 | + friend class AudioEngineWorkerThread; |
| 106 | +}; |
| 107 | + |
| 108 | +} // namespace lmms |
| 109 | + |
| 110 | +#endif // LMMS_AUDIO_BUS_HANDLE_H |
0 commit comments