Skip to content

Commit

Permalink
Merge branch 'master' into cpp20
Browse files Browse the repository at this point in the history
  • Loading branch information
messmerd committed Nov 7, 2024
2 parents 106439a + e36463c commit 48b3de5
Show file tree
Hide file tree
Showing 24 changed files with 170 additions and 380 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ jobs:
arch: [ x86_64, arm64 ]
include:
- arch: x86_64
os: macos-12
xcode: "13.1"
os: macos-13
xcode: "15.2"
- arch: arm64
os: macos-14
xcode: "14.3.1"
xcode: "15.4"
name: macos-${{ matrix.arch }}
runs-on: ${{ matrix.os }}
env:
Expand Down
19 changes: 16 additions & 3 deletions include/AudioEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <memory>
#include <vector>

#include "AudioDevice.h"
#include "lmms_basics.h"
#include "SampleFrame.h"
#include "LocklessList.h"
Expand Down Expand Up @@ -235,9 +236,20 @@ class LMMS_EXPORT AudioEngine : public QObject
}


sample_rate_t baseSampleRate() const;
sample_rate_t outputSampleRate() const;
sample_rate_t inputSampleRate() const;
sample_rate_t baseSampleRate() const { return m_baseSampleRate; }


sample_rate_t outputSampleRate() const
{
return m_audioDev != nullptr ? m_audioDev->sampleRate() : m_baseSampleRate;
}


sample_rate_t inputSampleRate() const
{
return m_audioDev != nullptr ? m_audioDev->sampleRate() : m_baseSampleRate;
}


inline float masterGain() const
{
Expand Down Expand Up @@ -361,6 +373,7 @@ class LMMS_EXPORT AudioEngine : public QObject
SampleFrame* m_inputBuffer[2];
f_cnt_t m_inputBufferFrames[2];
f_cnt_t m_inputBufferSize[2];
sample_rate_t m_baseSampleRate;
int m_inputBufferRead;
int m_inputBufferWrite;

Expand Down
37 changes: 17 additions & 20 deletions include/MixerChannelView.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MixerChannelView.h - the mixer channel view
* MixerChannelView.h
*
* Copyright (c) 2022 saker <sakertooth@gmail.com>
* Copyright (c) 2024 saker
*
* This file is part of LMMS - https://lmms.io
*
Expand All @@ -22,8 +22,8 @@
*
*/

#ifndef MIXER_CHANNEL_VIEW_H
#define MIXER_CHANNEL_VIEW_H
#ifndef LMMS_GUI_MIXER_CHANNEL_VIEW_H
#define LMMS_GUI_MIXER_CHANNEL_VIEW_H

#include <QGraphicsView>
#include <QLabel>
Expand All @@ -46,8 +46,6 @@ class MixerChannel;
namespace lmms::gui {
class PeakIndicator;

constexpr int MIXER_CHANNEL_INNER_BORDER_SIZE = 3;
constexpr int MIXER_CHANNEL_OUTER_BORDER_SIZE = 1;

class MixerChannelView : public QWidget
{
Expand All @@ -65,25 +63,24 @@ class MixerChannelView : public QWidget
void mouseDoubleClickEvent(QMouseEvent*) override;
bool eventFilter(QObject* dist, QEvent* event) override;

int channelIndex() const;
void reset();
int channelIndex() const { return m_channelIndex; }
void setChannelIndex(int index);

QBrush backgroundActive() const;
void setBackgroundActive(const QBrush& c);

QColor strokeOuterActive() const;
void setStrokeOuterActive(const QColor& c);
QBrush backgroundActive() const { return m_backgroundActive; }
void setBackgroundActive(const QBrush& c) { m_backgroundActive = c; }

QColor strokeOuterInactive() const;
void setStrokeOuterInactive(const QColor& c);
QColor strokeOuterActive() const { return m_strokeOuterActive; }
void setStrokeOuterActive(const QColor& c) { m_strokeOuterActive = c; }

QColor strokeInnerActive() const;
void setStrokeInnerActive(const QColor& c);
QColor strokeOuterInactive() const { return m_strokeOuterInactive; }
void setStrokeOuterInactive(const QColor& c) { m_strokeOuterInactive = c; }

QColor strokeInnerInactive() const;
void setStrokeInnerInactive(const QColor& c);
QColor strokeInnerActive() const { return m_strokeInnerActive; }
void setStrokeInnerActive(const QColor& c) { m_strokeInnerActive = c; }

void reset();
QColor strokeInnerInactive() const { return m_strokeInnerInactive; }
void setStrokeInnerInactive(const QColor& c) { m_strokeInnerInactive = c; }

public slots:
void renameChannel();
Expand Down Expand Up @@ -135,4 +132,4 @@ private slots:
};
} // namespace lmms::gui

#endif // MIXER_CHANNEL_VIEW_H
#endif // LMMS_GUI_MIXER_CHANNEL_VIEW_H
3 changes: 1 addition & 2 deletions include/PeakController.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ public slots:
static int m_loadCount;
static bool m_buggedFile;

float m_attackCoeff;
float m_decayCoeff;
float m_coeff;
bool m_coeffNeedsUpdate;
} ;

Expand Down
4 changes: 2 additions & 2 deletions include/RemotePluginBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,15 +398,15 @@ class LMMS_EXPORT RemotePluginBase
message & addInt( int _i )
{
char buf[32];
sprintf( buf, "%d", _i );
std::snprintf(buf, 32, "%d", _i);
data.emplace_back( buf );
return *this;
}

message & addFloat( float _f )
{
char buf[32];
sprintf( buf, "%f", _f );
std::snprintf(buf, 32, "%f", _f);
data.emplace_back( buf );
return *this;
}
Expand Down
2 changes: 1 addition & 1 deletion include/RemotePluginClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ bool RemotePluginClient::processMessage( const message & _m )
default:
{
char buf[64];
sprintf( buf, "undefined message: %d\n", (int) _m.id );
std::snprintf(buf, 64, "undefined message: %d\n", _m.id);
debugMessage( buf );
break;
}
Expand Down
84 changes: 58 additions & 26 deletions include/TimePos.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#ifndef LMMS_TIME_POS_H
#define LMMS_TIME_POS_H

#include <algorithm>
#include <cassert>
#include "lmms_export.h"
#include "lmms_basics.h"

Expand All @@ -51,8 +53,8 @@ class LMMS_EXPORT TimeSig
public:
TimeSig( int num, int denom );
TimeSig( const MeterModel &model );
int numerator() const;
int denominator() const;
int numerator() const { return m_num; }
int denominator() const { return m_denom; }
private:
int m_num;
int m_denom;
Expand All @@ -69,42 +71,72 @@ class LMMS_EXPORT TimePos
TimePos( const tick_t ticks = 0 );

TimePos quantize(float) const;
TimePos toAbsoluteBar() const;
TimePos toAbsoluteBar() const { return getBar() * s_ticksPerBar; }

TimePos& operator+=( const TimePos& time );
TimePos& operator-=( const TimePos& time );
TimePos& operator+=(const TimePos& time)
{
m_ticks += time.m_ticks;
return *this;
}

TimePos& operator-=(const TimePos& time)
{
m_ticks -= time.m_ticks;
return *this;
}

// return the bar, rounded down and 0-based
bar_t getBar() const;
bar_t getBar() const { return m_ticks / s_ticksPerBar; }

// return the bar, rounded up and 0-based
bar_t nextFullBar() const;
bar_t nextFullBar() const { return (m_ticks + (s_ticksPerBar - 1)) / s_ticksPerBar; }

void setTicks(tick_t ticks) { m_ticks = ticks; }
tick_t getTicks() const { return m_ticks; }

void setTicks( tick_t ticks );
tick_t getTicks() const;
operator int() const { return m_ticks; }

operator int() const;
tick_t ticksPerBeat(const TimeSig& sig) const { return ticksPerBar(sig) / sig.numerator(); }

tick_t ticksPerBeat( const TimeSig &sig ) const;
// Remainder ticks after bar is removed
tick_t getTickWithinBar( const TimeSig &sig ) const;
tick_t getTickWithinBar(const TimeSig& sig) const { return m_ticks % ticksPerBar(sig); }

// Returns the beat position inside the bar, 0-based
tick_t getBeatWithinBar( const TimeSig &sig ) const;
tick_t getBeatWithinBar(const TimeSig& sig) const { return getTickWithinBar(sig) / ticksPerBeat(sig); }

// Remainder ticks after bar and beat are removed
tick_t getTickWithinBeat( const TimeSig &sig ) const;
tick_t getTickWithinBeat(const TimeSig& sig) const { return getTickWithinBar(sig) % ticksPerBeat(sig); }

// calculate number of frame that are needed this time
f_cnt_t frames( const float framesPerTick ) const;

double getTimeInMilliseconds( bpm_t beatsPerMinute ) const;

static TimePos fromFrames( const f_cnt_t frames, const float framesPerTick );
static tick_t ticksPerBar();
static tick_t ticksPerBar( const TimeSig &sig );
static int stepsPerBar();
static void setTicksPerBar( tick_t tpt );
static TimePos stepPosition( int step );
static double ticksToMilliseconds( tick_t ticks, bpm_t beatsPerMinute );
static double ticksToMilliseconds( double ticks, bpm_t beatsPerMinute );
f_cnt_t frames(const float framesPerTick) const
{
// Before, step notes used to have negative length. This
// assert is a safeguard against negative length being
// introduced again (now using Note Types instead #5902)
assert(m_ticks >= 0);
return static_cast<f_cnt_t>(m_ticks * framesPerTick);
}

double getTimeInMilliseconds(bpm_t beatsPerMinute) const { return ticksToMilliseconds(getTicks(), beatsPerMinute); }

static TimePos fromFrames(const f_cnt_t frames, const float framesPerTick)
{
return TimePos(static_cast<int>(frames / framesPerTick));
}

static tick_t ticksPerBar() { return s_ticksPerBar; }
static tick_t ticksPerBar(const TimeSig& sig) { return DefaultTicksPerBar * sig.numerator() / sig.denominator(); }

static int stepsPerBar() { return std::max(1, ticksPerBar() / DefaultBeatsPerBar); }
static void setTicksPerBar(tick_t ticks) { s_ticksPerBar = ticks; }
static TimePos stepPosition(int step) { return step * ticksPerBar() / stepsPerBar(); }

static double ticksToMilliseconds(tick_t ticks, bpm_t beatsPerMinute)
{
return ticksToMilliseconds(static_cast<double>(ticks), beatsPerMinute);
}

static double ticksToMilliseconds(double ticks, bpm_t beatsPerMinute) { return (ticks * 1250) / beatsPerMinute; }

private:
tick_t m_ticks;
Expand Down
2 changes: 1 addition & 1 deletion plugins/HydrogenImport/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
INCLUDE(BuildPlugin)

BUILD_PLUGIN(hydrogenimport HydrogenImport.cpp HydrogenImport.h local_file_mgr.cpp LocalFileMng.h)
BUILD_PLUGIN(hydrogenimport HydrogenImport.cpp HydrogenImport.h LocalFileMng.cpp LocalFileMng.h)

3 changes: 2 additions & 1 deletion plugins/HydrogenImport/HydrogenImport.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "HydrogenImport.h"

#include <QDomDocument>

#include "LocalFileMng.h"
#include "HydrogenImport.h"
#include "Song.h"
#include "Engine.h"
#include "Instrument.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#include <sys/stat.h>
#include "LocalFileMng.h"

#include <cctype>

#include <QDomDocument>
#include <QFile>
#include <QLocale>
#include <QTextCodec>

#include "LocalFileMng.h"

namespace lmms
{
Expand Down Expand Up @@ -197,10 +196,7 @@ QDomDocument LocalFileMng::openXmlDocument( const QString& filename )
return QDomDocument();

if( TinyXMLCompat ) {
QString enc = QTextCodec::codecForLocale()->name();
if( enc == QString("System") ) {
enc = "UTF-8";
}
const QString enc = "UTF-8"; // unknown encoding, so assume utf-8 and call it a day
QByteArray line;
QByteArray buf = QString("<?xml version='1.0' encoding='%1' ?>\n")
.arg( enc )
Expand Down
7 changes: 0 additions & 7 deletions plugins/HydrogenImport/LocalFileMng.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,13 @@ namespace lmms
class LocalFileMng
{
public:
LocalFileMng();
~LocalFileMng();
std::vector<QString> getallPatternList(){
return m_allPatternList;
}

static QString readXmlString( QDomNode , const QString& nodeName, const QString& defaultValue, bool bCanBeEmpty = false, bool bShouldExists = true , bool tinyXmlCompatMode = false);
static float readXmlFloat( QDomNode , const QString& nodeName, float defaultValue, bool bCanBeEmpty = false, bool bShouldExists = true , bool tinyXmlCompatMode = false);
static int readXmlInt( QDomNode , const QString& nodeName, int defaultValue, bool bCanBeEmpty = false, bool bShouldExists = true , bool tinyXmlCompatMode = false);
static bool readXmlBool( QDomNode , const QString& nodeName, bool defaultValue, bool bShouldExists = true , bool tinyXmlCompatMode = false );
static void convertFromTinyXMLString( QByteArray* str );
static bool checkTinyXMLCompatMode( const QString& filename );
static QDomDocument openXmlDocument( const QString& filename );
std::vector<QString> m_allPatternList;
};


Expand Down
12 changes: 11 additions & 1 deletion plugins/PeakControllerEffect/PeakControllerEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,18 @@ Effect::ProcessStatus PeakControllerEffect::processImpl(SampleFrame* buf, const
float curRMS = sqrt_neg(sum / frames);
const float tres = c.m_tresholdModel.value();
const float amount = c.m_amountModel.value() * c.m_amountMultModel.value();
const float attack = 1.0f - c.m_attackModel.value();
const float decay = 1.0f - c.m_decayModel.value();

curRMS = qAbs( curRMS ) < tres ? 0.0f : curRMS;
m_lastSample = qBound( 0.0f, c.m_baseModel.value() + amount * curRMS, 1.0f );
float target = c.m_baseModel.value() + amount * curRMS;
// Use decay when the volume is decreasing, attack otherwise.
// Since direction can change as often as every sampleBuffer, it's difficult
// to witness attack/decay working in isolation unless using large buffer sizes.
const float t = target < m_lastSample ? decay : attack;
// Set m_lastSample to the interpolation between itself and target.
// When t is 1.0, m_lastSample snaps to target. When t is 0.0, m_lastSample shouldn't change.
m_lastSample = std::clamp(m_lastSample + t * (target - m_lastSample), 0.0f, 1.0f);

return ProcessStatus::Continue;
}
Expand Down
Loading

0 comments on commit 48b3de5

Please sign in to comment.