mirror of
https://github.com/LMMS/lmms.git
synced 2026-04-01 21:04:18 -04:00
* Remove the struct StereoSample Remove the struct `StereoSample`. Let `AudioEngine::getPeakValues` return a `sampleFrame` instead. Adjust the calls in `Mixer` and `Oscilloscope`. * Simplify AudioEngine::getPeakValues * Remove surroundSampleFrame Some code assumes that `surroundSampleFrame` is interchangeable with `sampleFrame`. Thus, if the line `#define LMMS_DISABLE_SURROUND` is commented out in `lmms_basics.h` then the code does not compile anymore because `surroundSampleFrame` now is defined to be an array with four values instead of two. There also does not seem to be any support for surround sound (four channels instead of two) in the application. The faders and mixers do not seem to support more that two channels and the instruments and effects all expect a `sampleFrame`, i.e. stereo channels. It therefore makes sense to remove the "feature" because it also hinders the improvement of `sampleFrame`, e.g. by making it a class with some convenience methods that act on `sampleFrame` instances. All occurrences of `surroundSampleFrame` are replaced with `sampleFrame`. The version of `BufferManager::clear` that takes a `surroundSampleFrame` is removed completely. The define `SURROUND_CHANNELS` is removed. All its occurrences are replaced with `DEFAULT_CHANNELS`. Most of the audio devices classes, i.e. classes that inherit from `AudioDevice`, now clamp the configuration parameter between two values of `DEFAULT_CHANNELS`. This can be improved/streamlined later. `BYTES_PER_SURROUND_FRAME` has been removed as it was not used anywhere anyway. * Make sampleFrame a class Make `sampleFrame` a class with several convenience methods. As a first step and demonstration adjust the follow methods to make use of the new functionality: * `AudioEngine::getPeakValues`: Much more concise now. * `lmms::MixHelpers::sanitize`: Better structure, better readable, less dereferencing and juggling with indices. * `AddOp`, `AddMultipliedOp`, `multiply`: Make use of operators. Might become superfluous in the future. * More operators and methods for sampleFrame Add some more operators and methods to `sampleFrame`: * Constructor which initializes both channels from a single sample value * Assignment operator from a single sample value * Addition/multiplication operators * Scalar product Adjust some more plugins to the new functionality of `sampleFrame`. * Adjust DelayEffect to methods in sampleFrame * Use composition instead of inheritance Using inheritance was the quickest way to enable adding methods to `sampleFrame` without having to reimpement much of `std::array`s interface. This is changed with this commit. The array is now a member of `sampleFrame` and the interface is extended with the necessary methods `data` and the index operator. An `average` method was added so that no iterators need to be implemented (see changes in `SampleWaveform.cpp`). * Apply suggestions from code review Apply Veratil's suggestions from the code review Co-authored-by: Kevin Zander <veratil@gmail.com> * Fix warnings: zeroing non-trivial type Fix several warnings of the following form: Warnung: »void* memset(void*, int, size_t)« Säubern eines Objekts von nichttrivialem Typ »class lmms::sampleFrame«; use assignment or value-initialization instead [-Wclass-memaccess] * Remove unnecessary reinterpret_casts Remove some unnecessary reinterpret_casts with regards to `sampleFrame` buffers. `PlayHandle::m_playHandleBuffer` already is a `sampleFrame*` and does not need a reinterpret_cast anymore. In `LadspaEffect::processAudioBuffer` the `QVarLengthArray` is now directly initialized as an array of `sampleFrame` instances. I guess in both places the `sampleFrame` previously was a `surroundSampleFrame` which has been removed. * Clean up zeroSampleFrames code * Fix warnings in RemotePlugin Fix some warnings related to calls to `memcpy` in conjunction with`sampleFrame` which is now a class. Add the helper functions `copyToSampleFrames` and `copyFromSampleFrames` and use them. The first function copies data from a `float` buffer into a `sampleFrame` buffer and the second copies vice versa. * Rename "sampleFrame" to "SampleFrame" Uppercase the name of `sampleFrame` so that it uses UpperCamelCase convention. * Move SampleFrame into its own file Move the class `SampleFrame` into its own class and remove it from `lmms_basics.h`. Add forward includes to all headers where possible or include the `SampleFrame` header if it's not just referenced but used. Add include to all cpp files where necessary. It's a bit surprising that the `SampleFrame` header does not need to be included much more often in the implementation/cpp files. This is an indicator that it seems to be included via an include chain that at one point includes one of the headers where an include instead of a forward declaration had to be added in this commit. * Return reference for += and *= Return a reference for the compound assignment operators `+=` and `-=`. * Explicit float constructor Make the constructor that takes a `float` explicit. Remove the assignment operator that takes a `float`. Clients must use the explicit `float` constructor and assign the result. Adjust the code in "BitInvader" accordingly. * Use std::fill in zeroSampleFrames * Use zeroSampleFrames in sanitize * Replace max with absMax Replace `SampleFrame::max` with `SampleFrame::absMax`. Use `absMax` in `DelayEffect::processAudioBuffer`. This should also fix a buggy implementation of the peak computation. Add the function `getAbsPeakValues`. It computes the absolute peak values for a buffer. Remove `AudioEngine::getPeakValues`. It's not really the business of the audio engine. Let `Mixer` and `Oscilloscope` use `getAbsPeakValues`. * Replace scalarProduct Replace the rather mathematical method `scalarProduct` with `sumOfSquaredAmplitudes`. It was always called on itself anyway. * Remove comment/TODO * Simplify sanitize Simplify the `sanitize` function by getting rid of the `bool found` and by zeroing the buffer as soon as a problem is found. * Put pointer symbols next to type * Code review adjustments * Remove "#pragme once" * Adjust name of include guard * Remove superfluous includes (leftovers from previous code changes) --------- Co-authored-by: Kevin Zander <veratil@gmail.com>
277 lines
6.6 KiB
C++
277 lines
6.6 KiB
C++
/*
|
|
* Lv2Ports.h - Lv2 port classes definitions
|
|
*
|
|
* Copyright (c) 2019-2020 Johannes Lorenz <jlsf2013$users.sourceforge.net, $=@>
|
|
*
|
|
* This file is part of LMMS - https://lmms.io
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2 of the License, or (at your option) any later version.
|
|
*
|
|
* This program 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
|
|
* General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public
|
|
* License along with this program (see COPYING); if not, write to the
|
|
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
* Boston, MA 02110-1301 USA.
|
|
*
|
|
*/
|
|
|
|
#ifndef LMMS_LV2PORTS_H
|
|
#define LMMS_LV2PORTS_H
|
|
|
|
#include "lmmsconfig.h"
|
|
|
|
#ifdef LMMS_HAVE_LV2
|
|
|
|
#include <lilv/lilv.h>
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
#include "Flags.h"
|
|
#include "lmms_basics.h"
|
|
#include "PluginIssue.h"
|
|
|
|
|
|
namespace lmms
|
|
{
|
|
|
|
class SampleFrame;
|
|
|
|
struct ConnectPortVisitor;
|
|
using LV2_Evbuf = struct LV2_Evbuf_Impl;
|
|
|
|
namespace Lv2Ports {
|
|
|
|
/*
|
|
port structs
|
|
*/
|
|
enum class Flow {
|
|
Unknown,
|
|
Input,
|
|
Output
|
|
};
|
|
|
|
enum class Type {
|
|
Unknown,
|
|
Control,
|
|
Audio,
|
|
AtomSeq,
|
|
Cv //!< TODO: unused, describe
|
|
};
|
|
|
|
//! Port visualization
|
|
//! @note All Lv2 audio ports are float, this is only the visualisation
|
|
enum class Vis {
|
|
Generic, //!< nothing specific, a generic knob or slider shall be used
|
|
Integer, //!< counter
|
|
Enumeration, //!< selection from enumerated values
|
|
Toggled //!< boolean widget
|
|
};
|
|
|
|
const char* toStr(Lv2Ports::Flow pf);
|
|
const char* toStr(Lv2Ports::Type pt);
|
|
const char* toStr(Lv2Ports::Vis pv);
|
|
|
|
struct ControlPortBase;
|
|
struct Control;
|
|
struct Audio;
|
|
struct Cv;
|
|
struct AtomSeq;
|
|
struct Unknown;
|
|
|
|
struct ConstVisitor
|
|
{
|
|
virtual void visit(const Lv2Ports::ControlPortBase& ) {}
|
|
virtual void visit(const Lv2Ports::Control& ) {}
|
|
virtual void visit(const Lv2Ports::Audio& ) {}
|
|
virtual void visit(const Lv2Ports::Cv& ) {}
|
|
virtual void visit(const Lv2Ports::AtomSeq& ) {}
|
|
virtual void visit(const Lv2Ports::Unknown& ) {}
|
|
|
|
virtual ~ConstVisitor() = default;
|
|
};
|
|
|
|
struct Visitor
|
|
{
|
|
virtual void visit(Lv2Ports::ControlPortBase& ) {}
|
|
virtual void visit(Lv2Ports::Control& ) {}
|
|
virtual void visit(Lv2Ports::Audio& ) {}
|
|
virtual void visit(Lv2Ports::Cv& ) {}
|
|
virtual void visit(Lv2Ports::AtomSeq& ) {}
|
|
virtual void visit(Lv2Ports::Unknown& ) {}
|
|
|
|
virtual ~Visitor() = default;
|
|
};
|
|
|
|
struct Meta
|
|
{
|
|
Type m_type = Type::Unknown;
|
|
Flow m_flow = Flow::Unknown;
|
|
Vis m_vis = Vis::Generic;
|
|
|
|
bool m_logarithmic = false;
|
|
|
|
bool m_optional = false;
|
|
bool m_used = true;
|
|
|
|
std::vector<PluginIssue> get(const LilvPlugin* plugin, std::size_t portNum);
|
|
|
|
float def() const { return m_def; }
|
|
float min(sample_rate_t sr) const { return m_sampleRate ? sr * m_min : m_min; }
|
|
float max(sample_rate_t sr) const { return m_sampleRate ? sr * m_max : m_max; }
|
|
private:
|
|
float m_def = .0f, m_min = .0f, m_max = .0f;
|
|
bool m_sampleRate = false;
|
|
};
|
|
|
|
struct PortBase : public Meta
|
|
{
|
|
const LilvPort* m_port = nullptr;
|
|
const LilvPlugin* m_plugin = nullptr;
|
|
|
|
virtual void accept(Visitor& v) = 0;
|
|
virtual void accept(ConstVisitor& v) const = 0;
|
|
|
|
QString name() const;
|
|
QString uri() const;
|
|
|
|
virtual ~PortBase() = default;
|
|
};
|
|
|
|
template<typename Derived, typename Base>
|
|
struct VisitablePort : public Base
|
|
{
|
|
void accept(Visitor& v) override { v.visit(static_cast<Derived&>(*this)); }
|
|
void accept(ConstVisitor& v) const override { v.visit(static_cast<const Derived&>(*this)); }
|
|
};
|
|
|
|
struct ControlPortBase : public VisitablePort<ControlPortBase, PortBase>
|
|
{
|
|
//! LMMS models
|
|
//! Always up-to-date, except during runs
|
|
std::unique_ptr<class AutomatableModel> m_connectedModel;
|
|
|
|
//! Enumerate float values
|
|
//! lv2 defines scale points as
|
|
//! "single float Points (for control inputs)"
|
|
std::vector<float> m_scalePointMap;
|
|
};
|
|
|
|
struct Control : public VisitablePort<Control, ControlPortBase>
|
|
{
|
|
//! Data location which Lv2 plugins see
|
|
//! Model values are being copied here every run
|
|
//! Between runs, this data is not up-to-date
|
|
float m_val;
|
|
};
|
|
|
|
struct Cv : public VisitablePort<Cv, ControlPortBase>
|
|
{
|
|
//! Data location which Lv2 plugins see
|
|
//! Model values are being copied here every run
|
|
//! Between runs, this data is not up-to-date
|
|
std::vector<float> m_buffer;
|
|
};
|
|
|
|
struct Audio : public VisitablePort<Audio, PortBase>
|
|
{
|
|
Audio(std::size_t bufferSize, bool isSidechain);
|
|
|
|
//! Copy buffer passed by LMMS into our ports
|
|
//! @param channel channel index into each sample frame
|
|
void copyBuffersFromCore(const SampleFrame* lmmsBuf,
|
|
unsigned channel, fpp_t frames);
|
|
//! Add buffer passed by LMMS into our ports, and halve the result
|
|
//! @param channel channel index into each sample frame
|
|
void averageWithBuffersFromCore(const SampleFrame* lmmsBuf,
|
|
unsigned channel, fpp_t frames);
|
|
//! Copy our ports into buffers passed by LMMS
|
|
//! @param channel channel index into each sample frame
|
|
void copyBuffersToCore(SampleFrame* lmmsBuf,
|
|
unsigned channel, fpp_t frames) const;
|
|
|
|
bool isSideChain() const { return m_sidechain; }
|
|
bool isOptional() const { return m_optional; }
|
|
bool mustBeUsed() const { return !isSideChain() && !isOptional(); }
|
|
std::size_t bufferSize() const { return m_buffer.size(); }
|
|
|
|
private:
|
|
//! the buffer where Lv2 reads/writes the data from/to
|
|
std::vector<float> m_buffer;
|
|
bool m_sidechain;
|
|
|
|
// the only case when data of m_buffer may be referenced:
|
|
friend struct lmms::ConnectPortVisitor;
|
|
};
|
|
|
|
struct AtomSeq : public VisitablePort<AtomSeq, PortBase>
|
|
{
|
|
enum class FlagType
|
|
{
|
|
None = 0,
|
|
Midi = 1
|
|
};
|
|
Flags<FlagType> flags = FlagType::None;
|
|
|
|
struct Lv2EvbufDeleter
|
|
{
|
|
void operator()(LV2_Evbuf* n);
|
|
};
|
|
using AutoLv2Evbuf = std::unique_ptr<LV2_Evbuf, Lv2EvbufDeleter>;
|
|
AutoLv2Evbuf m_buf;
|
|
};
|
|
|
|
struct Unknown : public VisitablePort<Unknown, PortBase>
|
|
{
|
|
};
|
|
|
|
/*
|
|
port casts
|
|
*/
|
|
template<class Target>
|
|
struct DCastVisitor : public Visitor
|
|
{
|
|
Target* m_result = nullptr;
|
|
void visit(Target& tar) { m_result = &tar; }
|
|
};
|
|
|
|
template<class Target>
|
|
struct ConstDCastVisitor : public ConstVisitor
|
|
{
|
|
const Target* m_result = nullptr;
|
|
void visit(const Target& tar) { m_result = &tar; }
|
|
};
|
|
|
|
//! If you don't want to use a whole visitor, you can use dcast
|
|
template<class Target>
|
|
Target* dcast(PortBase* base)
|
|
{
|
|
DCastVisitor<Target> vis;
|
|
base->accept(vis);
|
|
return vis.m_result;
|
|
}
|
|
|
|
//! const overload
|
|
template<class Target>
|
|
const Target* dcast(const PortBase* base)
|
|
{
|
|
ConstDCastVisitor<Target> vis;
|
|
base->accept(vis);
|
|
return vis.m_result;
|
|
}
|
|
|
|
} // namespace Lv2Ports
|
|
|
|
|
|
} // namespace lmms
|
|
|
|
#endif // LMMS_HAVE_LV2
|
|
|
|
#endif // LMMS_LV2PORTS_H
|