1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
/*
* Copyright (C) 2021 Linux Studio Plugins Project <https://lsp-plug.in/>
* (C) 2021 Vladimir Sadovnikov <sadko4u@gmail.com>
*
* This file is part of lsp-plugins-sampler
* Created on: 11 июл. 2021 г.
*
* lsp-plugins-sampler is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* lsp-plugins-sampler is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with lsp-plugins-sampler. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef PRIVATE_PLUGINS_SAMPLER_H_
#define PRIVATE_PLUGINS_SAMPLER_H_
#include <lsp-plug.in/plug-fw/plug.h>
#include <lsp-plug.in/dsp-units/ctl/Toggle.h>
#include <lsp-plug.in/dsp-units/ctl/Bypass.h>
#include <lsp-plug.in/lltl/parray.h>
#include <lsp-plug.in/ipc/ITask.h>
#include <private/meta/sampler.h>
#include <private/plugins/sampler_kernel.h>
namespace lsp
{
namespace plugins
{
/**
* Sampler plugin
*/
class sampler: public plug::Module
{
protected:
static const size_t BITMASK_MAX = ((meta::sampler_metadata::INSTRUMENTS_MAX + 31) >> 5);
protected:
enum dm_mode_t
{
DM_APPLY_GAIN = 1 << 0,
DM_APPLY_PAN = 1 << 1
};
typedef struct sampler_channel_t
{
float *vDry; // Dry output
float fPan; // Gain
dspu::Bypass sBypass; // Bypass
dspu::Bypass sDryBypass; // Dry channel bypass
plug::IPort *pDry; // Dry port
plug::IPort *pPan; // Gain output
} sampler_channel_t;
typedef struct channel_t
{
float *vIn; // Input
float *vOut; // Output
float *vTmpIn; // Temporary input buffer
float *vTmpOut; // Temporary output buffer
dspu::Bypass sBypass; // Bypass
plug::IPort *pIn; // Input port
plug::IPort *pOut; // Output port
} channel_t;
typedef struct sampler_t
{
sampler_kernel sSampler; // Sampler
float fGain; // Overall gain
size_t nNote; // Trigger note
size_t nChannel; // Channel
size_t nMuteGroup; // Mute group
bool bMuting; // Muting flag
bool bNoteOff; // Handle note-off event
sampler_channel_t vChannels[meta::sampler_metadata::TRACKS_MAX]; // Sampler output channels
plug::IPort *pGain; // Gain output port
plug::IPort *pBypass; // Bypass port
plug::IPort *pDryBypass; // Dry bypass port
plug::IPort *pChannel; // Note port
plug::IPort *pNote; // Note port
plug::IPort *pOctave; // Octave port
plug::IPort *pMuteGroup; // Mute group
plug::IPort *pMuting; // Muting
plug::IPort *pMidiNote; // Output midi note #
plug::IPort *pNoteOff; // Note off switch
} sampler_t;
protected:
size_t nChannels; // Number of channels per output
size_t nSamplers; // Number of samplers
size_t nFiles; // Number of files per sampler
size_t nDOMode; // Mode of direct output
bool bDryPorts; // Dry ports allocated as temporary buffers
sampler_t *vSamplers; // Lisf of samplers
channel_t vChannels[meta::sampler_metadata::TRACKS_MAX]; // Temporary buffers for processing
dspu::Toggle sMute; // Mute request
float *pBuffer; // Buffer data used by vChannels
float fDry; // Dry amount
float fWet; // Wet amount
bool bMuting; // Global muting option
plug::IPort *pMidiIn; // MIDI input port
plug::IPort *pMidiOut; // MIDI output port
plug::IPort *pBypass; // Bypass port
plug::IPort *pMute; // Mute request port
plug::IPort *pMuting; // MIDI muting
plug::IPort *pNoteOff; // Note-off event handling
plug::IPort *pFadeout; // Note-off fadeout
plug::IPort *pDry; // Dry amount port
plug::IPort *pWet; // Wet amount port
plug::IPort *pGain; // Output gain port
plug::IPort *pDOGain; // Direct output gain flag
plug::IPort *pDOPan; // Direct output panning flag
protected:
void process_trigger_events();
void dump_sampler(dspu::IStateDumper *v, const sampler_t *s) const;
void dump_channel(dspu::IStateDumper *v, const channel_t *s) const;
public:
explicit sampler(const meta::plugin_t *metadata, size_t samplers, size_t channels, bool dry_ports);
virtual ~sampler();
public:
virtual void init(plug::IWrapper *wrapper, plug::IPort **ports);
virtual void destroy();
virtual void update_settings();
virtual void update_sample_rate(long sr);
virtual void ui_activated();
virtual void process(size_t samples);
virtual void dump(dspu::IStateDumper *v) const;
};
} /* namespace plugins */
} /* namespace lsp */
#endif /* PRIVATE_PLUGINS_SAMPLER_H_ */
|