mirror of
https://github.com/LMMS/lmms.git
synced 2025-12-24 07:08:28 -05: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>
375 lines
10 KiB
C++
375 lines
10 KiB
C++
/*
|
|
* Kicker.cpp - drum synthesizer
|
|
*
|
|
* Copyright (c) 2006-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
|
* Copyright (c) 2014 grejppi <grejppi/at/gmail.com>
|
|
*
|
|
* 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.
|
|
*
|
|
*/
|
|
|
|
#include "Kicker.h"
|
|
|
|
#include <QDomElement>
|
|
|
|
#include "AudioEngine.h"
|
|
#include "Engine.h"
|
|
#include "InstrumentTrack.h"
|
|
#include "Knob.h"
|
|
#include "LedCheckBox.h"
|
|
#include "NotePlayHandle.h"
|
|
#include "KickerOsc.h"
|
|
#include "TempoSyncKnob.h"
|
|
|
|
#include "embed.h"
|
|
#include "plugin_export.h"
|
|
|
|
namespace lmms
|
|
{
|
|
|
|
|
|
extern "C"
|
|
{
|
|
|
|
Plugin::Descriptor PLUGIN_EXPORT kicker_plugin_descriptor =
|
|
{
|
|
LMMS_STRINGIFY( PLUGIN_NAME ),
|
|
"Kicker",
|
|
QT_TRANSLATE_NOOP( "PluginBrowser",
|
|
"Versatile drum synthesizer" ),
|
|
"Tobias Doerffel <tobydox/at/users.sf.net>",
|
|
0x0100,
|
|
Plugin::Type::Instrument,
|
|
new PluginPixmapLoader( "logo" ),
|
|
nullptr,
|
|
nullptr,
|
|
} ;
|
|
|
|
}
|
|
|
|
|
|
KickerInstrument::KickerInstrument( InstrumentTrack * _instrument_track ) :
|
|
Instrument(_instrument_track, &kicker_plugin_descriptor, nullptr, Flag::IsNotBendable),
|
|
m_startFreqModel( 150.0f, 5.0f, 1000.0f, 1.0f, this, tr( "Start frequency" ) ),
|
|
m_endFreqModel( 40.0f, 5.0f, 1000.0f, 1.0f, this, tr( "End frequency" ) ),
|
|
m_decayModel( 440.0f, 5.0f, 5000.0f, 1.0f, 5000.0f, this, tr( "Length" ) ),
|
|
m_distModel( 0.8f, 0.0f, 100.0f, 0.1f, this, tr( "Start distortion" ) ),
|
|
m_distEndModel( 0.8f, 0.0f, 100.0f, 0.1f, this, tr( "End distortion" ) ),
|
|
m_gainModel( 1.0f, 0.1f, 5.0f, 0.05f, this, tr( "Gain" ) ),
|
|
m_envModel( 0.163f, 0.01f, 1.0f, 0.001f, this, tr( "Envelope slope" ) ),
|
|
m_noiseModel( 0.0f, 0.0f, 1.0f, 0.01f, this, tr( "Noise" ) ),
|
|
m_clickModel( 0.4f, 0.0f, 1.0f, 0.05f, this, tr( "Click" ) ),
|
|
m_slopeModel( 0.06f, 0.001f, 1.0f, 0.001f, this, tr( "Frequency slope" ) ),
|
|
m_startNoteModel( true, this, tr( "Start from note" ) ),
|
|
m_endNoteModel( false, this, tr( "End to note" ) ),
|
|
m_versionModel( KICKER_PRESET_VERSION, 0, KICKER_PRESET_VERSION, this, "" )
|
|
{
|
|
}
|
|
|
|
|
|
|
|
|
|
void KickerInstrument::saveSettings(QDomDocument& doc, QDomElement& elem)
|
|
{
|
|
m_startFreqModel.saveSettings(doc, elem, "startfreq");
|
|
m_endFreqModel.saveSettings(doc, elem, "endfreq");
|
|
m_decayModel.saveSettings(doc, elem, "decay");
|
|
m_distModel.saveSettings(doc, elem, "dist");
|
|
m_distEndModel.saveSettings(doc, elem, "distend");
|
|
m_gainModel.saveSettings(doc, elem, "gain");
|
|
m_envModel.saveSettings(doc, elem, "env");
|
|
m_noiseModel.saveSettings(doc, elem, "noise");
|
|
m_clickModel.saveSettings(doc, elem, "click");
|
|
m_slopeModel.saveSettings(doc, elem, "slope");
|
|
m_startNoteModel.saveSettings(doc, elem, "startnote");
|
|
m_endNoteModel.saveSettings(doc, elem, "endnote");
|
|
m_versionModel.saveSettings(doc, elem, "version");
|
|
}
|
|
|
|
|
|
|
|
|
|
void KickerInstrument::loadSettings(const QDomElement& elem)
|
|
{
|
|
m_versionModel.loadSettings(elem, "version");
|
|
|
|
m_startFreqModel.loadSettings(elem, "startfreq");
|
|
m_endFreqModel.loadSettings(elem, "endfreq");
|
|
m_decayModel.loadSettings(elem, "decay");
|
|
m_distModel.loadSettings(elem, "dist");
|
|
if (elem.hasAttribute("distend") || !elem.firstChildElement("distend").isNull())
|
|
{
|
|
m_distEndModel.loadSettings(elem, "distend");
|
|
}
|
|
else
|
|
{
|
|
m_distEndModel.setValue(m_distModel.value());
|
|
}
|
|
m_gainModel.loadSettings(elem, "gain");
|
|
m_envModel.loadSettings(elem, "env");
|
|
m_noiseModel.loadSettings(elem, "noise");
|
|
m_clickModel.loadSettings(elem, "click");
|
|
m_slopeModel.loadSettings(elem, "slope");
|
|
m_startNoteModel.loadSettings(elem, "startnote");
|
|
if (m_versionModel.value() < 1)
|
|
{
|
|
m_startNoteModel.setValue(false);
|
|
}
|
|
m_endNoteModel.loadSettings(elem, "endnote");
|
|
|
|
// Try to maintain backwards compatibility
|
|
if (!elem.hasAttribute("version"))
|
|
{
|
|
m_startNoteModel.setValue(false);
|
|
m_decayModel.setValue(m_decayModel.value() * 1.33f);
|
|
m_envModel.setValue(1.0f);
|
|
m_slopeModel.setValue(1.0f);
|
|
m_clickModel.setValue(0.0f);
|
|
}
|
|
m_versionModel.setValue(KICKER_PRESET_VERSION);
|
|
}
|
|
|
|
|
|
|
|
|
|
QString KickerInstrument::nodeName() const
|
|
{
|
|
return kicker_plugin_descriptor.name;
|
|
}
|
|
|
|
using DistFX = DspEffectLibrary::Distortion;
|
|
using SweepOsc = KickerOsc<DspEffectLibrary::MonoToStereoAdaptor<DistFX>>;
|
|
|
|
void KickerInstrument::playNote( NotePlayHandle * _n,
|
|
SampleFrame* _working_buffer )
|
|
{
|
|
const fpp_t frames = _n->framesLeftForCurrentPeriod();
|
|
const f_cnt_t offset = _n->noteOffset();
|
|
const float decfr = m_decayModel.value() * Engine::audioEngine()->outputSampleRate() / 1000.0f;
|
|
const f_cnt_t tfp = _n->totalFramesPlayed();
|
|
|
|
if (!_n->m_pluginData)
|
|
{
|
|
_n->m_pluginData = new SweepOsc(
|
|
DistFX( m_distModel.value(),
|
|
m_gainModel.value() ),
|
|
m_startNoteModel.value() ? _n->frequency() : m_startFreqModel.value(),
|
|
m_endNoteModel.value() ? _n->frequency() : m_endFreqModel.value(),
|
|
m_noiseModel.value() * m_noiseModel.value(),
|
|
m_clickModel.value() * 0.25f,
|
|
m_slopeModel.value(),
|
|
m_envModel.value(),
|
|
m_distModel.value(),
|
|
m_distEndModel.value(),
|
|
decfr );
|
|
}
|
|
else if( tfp > decfr && !_n->isReleased() )
|
|
{
|
|
_n->noteOff();
|
|
}
|
|
|
|
auto so = static_cast<SweepOsc*>(_n->m_pluginData);
|
|
so->update( _working_buffer + offset, frames, Engine::audioEngine()->outputSampleRate() );
|
|
|
|
if( _n->isReleased() )
|
|
{
|
|
// We need this to check if the release has ended
|
|
const float desired = desiredReleaseFrames();
|
|
|
|
// This can be considered the current release frame in the "global" context of the release.
|
|
// We need it with the desired number of release frames to compute the linear decay.
|
|
fpp_t currentReleaseFrame = _n->releaseFramesDone();
|
|
|
|
// Start applying the release at the correct frame
|
|
const float framesBeforeRelease = _n->framesBeforeRelease();
|
|
for (fpp_t f = framesBeforeRelease; f < frames; ++f, ++currentReleaseFrame)
|
|
{
|
|
const bool releaseStillActive = currentReleaseFrame < desired;
|
|
const float attenuation = releaseStillActive ? (1.0f - (currentReleaseFrame / desired)) : 0.f;
|
|
|
|
_working_buffer[f + offset][0] *= attenuation;
|
|
_working_buffer[f + offset][1] *= attenuation;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
void KickerInstrument::deleteNotePluginData( NotePlayHandle * _n )
|
|
{
|
|
delete static_cast<SweepOsc *>( _n->m_pluginData );
|
|
}
|
|
|
|
|
|
|
|
|
|
gui::PluginView * KickerInstrument::instantiateView( QWidget * _parent )
|
|
{
|
|
return new gui::KickerInstrumentView( this, _parent );
|
|
}
|
|
|
|
|
|
namespace gui
|
|
{
|
|
|
|
|
|
class KickerKnob : public Knob
|
|
{
|
|
public:
|
|
KickerKnob( QWidget * _parent ) :
|
|
Knob( KnobType::Styled, _parent )
|
|
{
|
|
setFixedSize( 29, 29 );
|
|
setObjectName( "smallKnob" );
|
|
}
|
|
};
|
|
|
|
|
|
class KickerEnvKnob : public TempoSyncKnob
|
|
{
|
|
public:
|
|
KickerEnvKnob( QWidget * _parent ) :
|
|
TempoSyncKnob( KnobType::Styled, _parent )
|
|
{
|
|
setFixedSize( 29, 29 );
|
|
setObjectName( "smallKnob" );
|
|
}
|
|
};
|
|
|
|
|
|
class KickerLargeKnob : public Knob
|
|
{
|
|
public:
|
|
KickerLargeKnob( QWidget * _parent ) :
|
|
Knob( KnobType::Styled, _parent )
|
|
{
|
|
setFixedSize( 34, 34 );
|
|
setObjectName( "largeKnob" );
|
|
}
|
|
};
|
|
|
|
|
|
|
|
|
|
KickerInstrumentView::KickerInstrumentView( Instrument * _instrument,
|
|
QWidget * _parent ) :
|
|
InstrumentViewFixedSize( _instrument, _parent )
|
|
{
|
|
const int ROW1 = 14;
|
|
const int ROW2 = ROW1 + 56;
|
|
const int ROW3 = ROW2 + 56;
|
|
const int LED_ROW = 63;
|
|
const int COL1 = 14;
|
|
const int COL2 = COL1 + 56;
|
|
const int COL3 = COL2 + 56;
|
|
const int COL4 = COL3 + 41;
|
|
const int COL5 = COL4 + 41;
|
|
const int END_COL = COL1 + 48;
|
|
|
|
m_startFreqKnob = new KickerLargeKnob( this );
|
|
m_startFreqKnob->setHintText( tr( "Start frequency:" ), "Hz" );
|
|
m_startFreqKnob->move( COL1, ROW1 );
|
|
|
|
m_endFreqKnob = new KickerLargeKnob( this );
|
|
m_endFreqKnob->setHintText( tr( "End frequency:" ), "Hz" );
|
|
m_endFreqKnob->move( END_COL, ROW1 );
|
|
|
|
m_slopeKnob = new KickerKnob( this );
|
|
m_slopeKnob->setHintText( tr( "Frequency slope:" ), "" );
|
|
m_slopeKnob->move( COL3, ROW1 );
|
|
|
|
m_gainKnob = new KickerKnob( this );
|
|
m_gainKnob->setHintText( tr( "Gain:" ), "" );
|
|
m_gainKnob->move( COL1, ROW3 );
|
|
|
|
m_decayKnob = new KickerEnvKnob( this );
|
|
m_decayKnob->setHintText( tr( "Envelope length:" ), "ms" );
|
|
m_decayKnob->move( COL2, ROW3 );
|
|
|
|
m_envKnob = new KickerKnob( this );
|
|
m_envKnob->setHintText( tr( "Envelope slope:" ), "" );
|
|
m_envKnob->move( COL3, ROW3 );
|
|
|
|
m_clickKnob = new KickerKnob( this );
|
|
m_clickKnob->setHintText( tr( "Click:" ), "" );
|
|
m_clickKnob->move( COL5, ROW1 );
|
|
|
|
m_noiseKnob = new KickerKnob( this );
|
|
m_noiseKnob->setHintText( tr( "Noise:" ), "" );
|
|
m_noiseKnob->move( COL5, ROW3 );
|
|
|
|
m_distKnob = new KickerKnob( this );
|
|
m_distKnob->setHintText( tr( "Start distortion:" ), "" );
|
|
m_distKnob->move( COL4, ROW2 );
|
|
|
|
m_distEndKnob = new KickerKnob( this );
|
|
m_distEndKnob->setHintText( tr( "End distortion:" ), "" );
|
|
m_distEndKnob->move( COL5, ROW2 );
|
|
|
|
m_startNoteToggle = new LedCheckBox( "", this, "", LedCheckBox::LedColor::Green );
|
|
m_startNoteToggle->move( COL1 + 8, LED_ROW );
|
|
|
|
m_endNoteToggle = new LedCheckBox( "", this, "", LedCheckBox::LedColor::Green );
|
|
m_endNoteToggle->move( END_COL + 8, LED_ROW );
|
|
|
|
setAutoFillBackground( true );
|
|
QPalette pal;
|
|
pal.setBrush( backgroundRole(), PLUGIN_NAME::getIconPixmap( "artwork" ) );
|
|
setPalette( pal );
|
|
}
|
|
|
|
|
|
|
|
|
|
void KickerInstrumentView::modelChanged()
|
|
{
|
|
auto k = castModel<KickerInstrument>();
|
|
m_startFreqKnob->setModel( &k->m_startFreqModel );
|
|
m_endFreqKnob->setModel( &k->m_endFreqModel );
|
|
m_decayKnob->setModel( &k->m_decayModel );
|
|
m_distKnob->setModel( &k->m_distModel );
|
|
m_distEndKnob->setModel( &k->m_distEndModel );
|
|
m_gainKnob->setModel( &k->m_gainModel );
|
|
m_envKnob->setModel( &k->m_envModel );
|
|
m_noiseKnob->setModel( &k->m_noiseModel );
|
|
m_clickKnob->setModel( &k->m_clickModel );
|
|
m_slopeKnob->setModel( &k->m_slopeModel );
|
|
m_startNoteToggle->setModel( &k->m_startNoteModel );
|
|
m_endNoteToggle->setModel( &k->m_endNoteModel );
|
|
}
|
|
|
|
|
|
} // namespace gui
|
|
|
|
|
|
extern "C"
|
|
{
|
|
|
|
// necessary for getting instance out of shared lib
|
|
PLUGIN_EXPORT Plugin * lmms_plugin_main( Model * m, void * )
|
|
{
|
|
return new KickerInstrument( static_cast<InstrumentTrack *>( m ) );
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} // namespace lmms
|