Skip to content

Commit

Permalink
Merge branch 'LMMS:master' into arashpartow/update_exprtk_0.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ArashPartow authored Nov 15, 2024
2 parents 4233808 + ada836c commit 6ccc786
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 72 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
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
12 changes: 6 additions & 6 deletions plugins/Vestige/Vestige.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ void VestigeInstrument::loadSettings( const QDomElement & _this )
QStringList s_dumpValues;
for( int i = 0; i < paramCount; i++ )
{
sprintf(paramStr.data(), "param%d", i);
std::snprintf(paramStr.data(), paramStr.size(), "param%d", i);
s_dumpValues = dump[paramStr.data()].split(":");

knobFModel[i] = new FloatModel( 0.0f, 0.0f, 1.0f, 0.01f, this, QString::number(i) );
Expand Down Expand Up @@ -290,7 +290,7 @@ void VestigeInstrument::saveSettings( QDomDocument & _doc, QDomElement & _this )
for( int i = 0; i < paramCount; i++ )
{
if (knobFModel[i]->isAutomated() || knobFModel[i]->controllerConnection()) {
sprintf(paramStr.data(), "param%d", i);
std::snprintf(paramStr.data(), paramStr.size(), "param%d", i);
knobFModel[i]->saveSettings(_doc, _this, paramStr.data());
}

Expand Down Expand Up @@ -987,7 +987,7 @@ ManageVestigeInstrumentView::ManageVestigeInstrumentView( Instrument * _instrume

for( int i = 0; i < m_vi->paramCount; i++ )
{
sprintf(paramStr.data(), "param%d", i);
std::snprintf(paramStr.data(), paramStr.size(), "param%d", i);
s_dumpValues = dump[paramStr.data()].split(":");

vstKnobs[ i ] = new CustomTextKnob( KnobType::Bright26, this, s_dumpValues.at( 1 ) );
Expand All @@ -996,7 +996,7 @@ ManageVestigeInstrumentView::ManageVestigeInstrumentView( Instrument * _instrume

if( !hasKnobModel )
{
sprintf(paramStr.data(), "%d", i);
std::snprintf(paramStr.data(), paramStr.size(), "%d", i);
m_vi->knobFModel[i] = new FloatModel(LocaleHelper::toFloat(s_dumpValues.at(2)),
0.0f, 1.0f, 0.01f, castModel<VestigeInstrument>(), paramStr.data());
}
Expand Down Expand Up @@ -1059,8 +1059,8 @@ void ManageVestigeInstrumentView::syncPlugin( void )
// those auto-setted values are not jurnaled, tracked for undo / redo
if( !( m_vi->knobFModel[ i ]->isAutomated() || m_vi->knobFModel[ i ]->controllerConnection() ) )
{
sprintf(paramStr.data(), "param%d", i);
s_dumpValues = dump[paramStr.data()].split(":");
std::snprintf(paramStr.data(), paramStr.size(), "param%d", i);
s_dumpValues = dump[paramStr.data()].split(":");
float f_value = LocaleHelper::toFloat(s_dumpValues.at(2));
m_vi->knobFModel[ i ]->setAutomatedValue( f_value );
m_vi->knobFModel[ i ]->setInitValue( f_value );
Expand Down
10 changes: 5 additions & 5 deletions plugins/VstEffect/VstEffectControls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void VstEffectControls::loadSettings( const QDomElement & _this )
QStringList s_dumpValues;
for( int i = 0; i < paramCount; i++ )
{
sprintf(paramStr.data(), "param%d", i);
std::snprintf(paramStr.data(), paramStr.size(), "param%d", i);
s_dumpValues = dump[paramStr.data()].split(":");

knobFModel[i] = new FloatModel( 0.0f, 0.0f, 1.0f, 0.01f, this, QString::number(i) );
Expand Down Expand Up @@ -137,7 +137,7 @@ void VstEffectControls::saveSettings( QDomDocument & _doc, QDomElement & _this )
for( int i = 0; i < paramCount; i++ )
{
if (knobFModel[i]->isAutomated() || knobFModel[i]->controllerConnection()) {
sprintf(paramStr.data(), "param%d", i);
std::snprintf(paramStr.data(), paramStr.size(), "param%d", i);
knobFModel[i]->saveSettings(_doc, _this, paramStr.data());
}
}
Expand Down Expand Up @@ -386,7 +386,7 @@ ManageVSTEffectView::ManageVSTEffectView( VstEffect * _eff, VstEffectControls *

for( int i = 0; i < m_vi->paramCount; i++ )
{
sprintf(paramStr.data(), "param%d", i);
std::snprintf(paramStr.data(), paramStr.size(), "param%d", i);
s_dumpValues = dump[paramStr.data()].split(":");

vstKnobs[ i ] = new CustomTextKnob( KnobType::Bright26, widget, s_dumpValues.at( 1 ) );
Expand All @@ -395,7 +395,7 @@ ManageVSTEffectView::ManageVSTEffectView( VstEffect * _eff, VstEffectControls *

if( !hasKnobModel )
{
sprintf(paramStr.data(), "%d", i);
std::snprintf(paramStr.data(), paramStr.size(), "%d", i);
m_vi->knobFModel[i] = new FloatModel(LocaleHelper::toFloat(s_dumpValues.at(2)),
0.0f, 1.0f, 0.01f, _eff, paramStr.data());
}
Expand Down Expand Up @@ -460,7 +460,7 @@ void ManageVSTEffectView::syncPlugin()
if( !( m_vi2->knobFModel[ i ]->isAutomated() ||
m_vi2->knobFModel[ i ]->controllerConnection() ) )
{
sprintf(paramStr.data(), "param%d", i);
std::snprintf(paramStr.data(), paramStr.size(), "param%d", i);
s_dumpValues = dump[paramStr.data()].split(":");
float f_value = LocaleHelper::toFloat(s_dumpValues.at(2));
m_vi2->knobFModel[ i ]->setAutomatedValue( f_value );
Expand Down
43 changes: 29 additions & 14 deletions plugins/Xpressive/ExprSynth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ struct IntegrateFunction : public exprtk::ifunction<T>

IntegrateFunction(const unsigned int* frame, unsigned int sample_rate,unsigned int max_counters) :
exprtk::ifunction<T>(1),
m_firstValue(0),
m_frame(frame),
m_sample_rate(sample_rate),
m_max_counters(max_counters),
m_sampleRate(sample_rate),
m_maxCounters(max_counters),
m_nCounters(0),
m_nCountersCalls(0),
m_cc(0)
Expand All @@ -96,15 +97,26 @@ struct IntegrateFunction : public exprtk::ifunction<T>

inline T operator()(const T& x) override
{
if (*m_frame == 0)
if (m_frame)
{
++m_nCountersCalls;
if (m_nCountersCalls > m_max_counters)
if (m_nCountersCalls == 0)
{
m_firstValue = *m_frame;
}
if (m_firstValue == *m_frame)
{
return 0;
++m_nCountersCalls;
if (m_nCountersCalls > m_maxCounters)
{
return 0;
}
m_cc = m_nCounters;
++m_nCounters;
}
else // we moved to the next frame
{
m_frame = 0; // this will indicate that we are no longer in init phase.
}
m_cc = m_nCounters;
++m_nCounters;
}

T res = 0;
Expand All @@ -114,13 +126,16 @@ struct IntegrateFunction : public exprtk::ifunction<T>
m_counters[m_cc] += x;
}
m_cc = (m_cc + 1) % m_nCountersCalls;
return res / m_sample_rate;
}

const unsigned int* const m_frame;
const unsigned int m_sample_rate;
const unsigned int m_max_counters;
return res / m_sampleRate;
}
unsigned int m_firstValue;
const unsigned int* m_frame;
const unsigned int m_sampleRate;
// number of counters allocated
const unsigned int m_maxCounters;
// number of integrate instances that has counters allocated
unsigned int m_nCounters;
// real number of integrate instances
unsigned int m_nCountersCalls;
unsigned int m_cc;
double *m_counters;
Expand Down
20 changes: 12 additions & 8 deletions plugins/Xpressive/Xpressive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ void XpressiveView::expressionChanged() {
ExprFront expr(text.constData(),sample_rate);
float t=0;
const float f=10,key=5,v=0.5;
unsigned int i;
unsigned int frame_counter = 0;
expr.add_variable("t", t);

if (m_output_expr)
Expand All @@ -572,20 +572,24 @@ void XpressiveView::expressionChanged() {
expr.add_cyclic_vector("W2",e->graphW2().samples(),e->graphW2().length());
expr.add_cyclic_vector("W3",e->graphW3().samples(),e->graphW3().length());
}
expr.setIntegrate(&i,sample_rate);
expr.setIntegrate(&frame_counter,sample_rate);
expr.add_constant("srate",sample_rate);

const bool parse_ok=expr.compile();

if (parse_ok) {
e->exprValid().setValue(0);
const auto length = static_cast<std::size_t>(m_raw_graph->length());
const unsigned int length = static_cast<unsigned int>(m_raw_graph->length());
auto const samples = new float[length];
for (auto i = std::size_t{0}; i < length; i++) {
t = i / (float) length;
samples[i] = expr.evaluate();
if (std::isinf(samples[i]) != 0 || std::isnan(samples[i]) != 0)
samples[i] = 0;
// frame_counter's reference is used in the integrate function.
for (frame_counter = 0; frame_counter < length; ++frame_counter)
{
t = frame_counter / (float) length;
samples[frame_counter] = expr.evaluate();
if (std::isinf(samples[frame_counter]) != 0 || std::isnan(samples[frame_counter]) != 0)
{
samples[frame_counter] = 0;
}
}
m_raw_graph->setSamples(samples);
delete[] samples;
Expand Down
11 changes: 4 additions & 7 deletions src/core/ComboBoxModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,17 @@
namespace lmms
{

using std::unique_ptr;
using std::move;

void ComboBoxModel::addItem( QString item, unique_ptr<PixmapLoader> loader )
void ComboBoxModel::addItem(QString item, std::unique_ptr<PixmapLoader> loader)
{
m_items.emplace_back( move(item), move(loader) );
m_items.emplace_back(std::move(item), std::move(loader));
setRange( 0, m_items.size() - 1 );
}


void ComboBoxModel::replaceItem(std::size_t index, QString item, unique_ptr<PixmapLoader> loader)
void ComboBoxModel::replaceItem(std::size_t index, QString item, std::unique_ptr<PixmapLoader> loader)
{
assert(index < m_items.size());
m_items[index] = Item(move(item), move(loader));
m_items[index] = Item(std::move(item), std::move(loader));
emit propertiesChanged();
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/Keymap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void Keymap::loadSettings(const QDomElement &element)
QDomNode node = element.firstChild();
m_map.clear();

for (int i = 0; !node.isNull(); i++)
while (!node.isNull())
{
m_map.push_back(node.toElement().attribute("value").toInt());
node = node.nextSibling();
Expand Down
6 changes: 3 additions & 3 deletions src/core/ProjectRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ void ProjectRenderer::abortProcessing()

void ProjectRenderer::updateConsoleProgress()
{
const int cols = 50;
constexpr int cols = 50;
static int rot = 0;
auto buf = std::array<char, 80>{};
auto prog = std::array<char, cols + 1>{};
Expand All @@ -221,9 +221,9 @@ void ProjectRenderer::updateConsoleProgress()
}
prog[cols] = 0;

const auto activity = (const char*)"|/-\\";
const auto activity = "|/-\\";
std::fill(buf.begin(), buf.end(), 0);
sprintf(buf.data(), "\r|%s| %3d%% %c ", prog.data(), m_progress,
std::snprintf(buf.data(), buf.size(), "\r|%s| %3d%% %c ", prog.data(), m_progress,
activity[rot] );
rot = ( rot+1 ) % 4;

Expand Down
2 changes: 1 addition & 1 deletion src/core/Scale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void Scale::loadSettings(const QDomElement &element)
QDomNode node = element.firstChild();
m_intervals.clear();

for (int i = 0; !node.isNull(); i++)
while (!node.isNull())
{
Interval temp;
temp.restoreState(node.toElement());
Expand Down
6 changes: 3 additions & 3 deletions src/core/midi/MidiApple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void MidiApple::removePort( MidiPort* port )

QString MidiApple::sourcePortName( const MidiEvent& event ) const
{
qDebug("sourcePortName return '%s'?\n", event.sourcePort());
qDebug("sourcePortName");
/*
if( event.sourcePort() )
{
Expand Down Expand Up @@ -501,7 +501,7 @@ void MidiApple::openDevices()
void MidiApple::openMidiReference( MIDIEndpointRef reference, QString refName, bool isIn )
{
char * registeredName = (char*) malloc(refName.length()+1);
sprintf(registeredName, "%s",refName.toLatin1().constData());
std::snprintf(registeredName, refName.length() + 1, "%s",refName.toLatin1().constData());
qDebug("openMidiReference refName '%s'",refName.toLatin1().constData());

MIDIClientRef mClient = getMidiClientRef();
Expand Down Expand Up @@ -623,7 +623,7 @@ char * MidiApple::getFullName(MIDIEndpointRef &endpoint_ref)
size_t deviceNameLen = deviceName == nullptr ? 0 : strlen(deviceName);
size_t endPointNameLen = endPointName == nullptr ? 0 : strlen(endPointName);
char * fullName = (char *)malloc(deviceNameLen + endPointNameLen + 2);
sprintf(fullName, "%s:%s", deviceName,endPointName);
std::snprintf(fullName, deviceNameLen + endPointNameLen + 2, "%s:%s", deviceName,endPointName);
if (deviceName != nullptr) { free(deviceName); }
if (endPointName != nullptr) { free(endPointName); }
return fullName;
Expand Down
33 changes: 15 additions & 18 deletions src/gui/widgets/Fader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,20 +282,17 @@ void Fader::paintEvent(QPaintEvent* ev)

void Fader::paintLevels(QPaintEvent* ev, QPainter& painter, bool linear)
{
std::function<float(float value)> mapper = [this](float value) { return ampToDbfs(qMax(0.0001f, value)); };

if (linear)
{
mapper = [this](float value) { return value; };
}

const float mappedMinPeak(mapper(m_fMinPeak));
const float mappedMaxPeak(mapper(m_fMaxPeak));
const float mappedPeakL(mapper(m_fPeakValue_L));
const float mappedPeakR(mapper(m_fPeakValue_R));
const float mappedPersistentPeakL(mapper(m_persistentPeak_L));
const float mappedPersistentPeakR(mapper(m_persistentPeak_R));
const float mappedUnity(mapper(1.f));
const auto mapper = linear
? +[](float value) -> float { return value; }
: +[](float value) -> float { return ampToDbfs(qMax(0.0001f, value)); };

const float mappedMinPeak = mapper(m_fMinPeak);
const float mappedMaxPeak = mapper(m_fMaxPeak);
const float mappedPeakL = mapper(m_fPeakValue_L);
const float mappedPeakR = mapper(m_fPeakValue_R);
const float mappedPersistentPeakL = mapper(m_persistentPeak_L);
const float mappedPersistentPeakR = mapper(m_persistentPeak_R);
const float mappedUnity = mapper(1.f);

painter.save();

Expand Down Expand Up @@ -375,10 +372,10 @@ void Fader::paintLevels(QPaintEvent* ev, QPainter& painter, bool linear)
// Please ensure that "clip starts" is the maximum value and that "ok ends"
// is the minimum value and that all other values lie inbetween. Otherwise
// there will be warnings when the gradient is defined.
const float mappedClipStarts(mapper(dbfsToAmp(0.f)));
const float mappedWarnEnd(mapper(dbfsToAmp(-0.01f)));
const float mappedWarnStart(mapper(dbfsToAmp(-6.f)));
const float mappedOkEnd(mapper(dbfsToAmp(-12.f)));
const float mappedClipStarts = mapper(dbfsToAmp(0.f));
const float mappedWarnEnd = mapper(dbfsToAmp(-0.01f));
const float mappedWarnStart = mapper(dbfsToAmp(-6.f));
const float mappedOkEnd = mapper(dbfsToAmp(-12.f));

// Prepare the gradient for the meters
//
Expand Down

0 comments on commit 6ccc786

Please sign in to comment.