Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send playback position in samples to VST plug-ins #26663

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
<li>Multiple improvements to the Plugin API</li>
<li>Implement changing palette and palette cell properties on fly</li>
<li>Current workspace is automatically saved on each action that changes the workspace</li>
<li>Palettes and workspaces can be reset to the default state defined by the workspace you started customisations from</li>
<li>Palettes and workspaces can be reset to the default state defined by the workspace you started customizations from</li>
<li>Improve algorithm for determining start point for note input</li>
<li>Move the viewport to show actual changes in the score if they are outside of the current view</li>
</ul>
Expand Down
2,283 changes: 1,159 additions & 1,124 deletions share/locale/musescore_en.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/engraving/dom/engravingitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ staff_idx_t EngravingItem::effectiveStaffIdx() const
}

const System* system = toSystem(findAncestor(ElementType::SYSTEM));
if (!system) {
if (!system || system->vbox()) {
return vStaffIdx();
}

Expand Down
5 changes: 3 additions & 2 deletions src/engraving/dom/select.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,8 +813,9 @@ void Selection::updateSelectedElements()
if ((sp->tick() >= stick && sp->tick() < etick) || (sp->tick2() >= stick && sp->tick2() <= etick)) {
EngravingItem* startCR = sp->startCR();
EngravingItem* endCR = sp->endCR();
const bool canSelectStart = (sp->startElement()->isTimeTickAnchor() || canSelect(startCR));
const bool canSelectEnd = (sp->endElement()->isTimeTickAnchor() || canSelect(endCR));
const bool canSelectStart
= (sp->startElement()->isTimeTickAnchor() || sp->startElement()->isSegment() || canSelect(startCR));
const bool canSelectEnd = (sp->endElement()->isTimeTickAnchor() || sp->endElement()->isSegment() || canSelect(endCR));
if (canSelectStart && canSelectEnd) {
for (auto seg : sp->spannerSegments()) {
appendFiltered(seg); // spanner with start or end in range selection
Expand Down
1 change: 1 addition & 0 deletions src/engraving/engravingmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

#include "engraving/style/defaultstyle.h"

#include "engraving/dom/stafftype.h"
#include "engraving/dom/mscore.h"
#include "engraving/dom/masterscore.h"
#include "engraving/dom/drumset.h"
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/rendering/score/masklayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void MaskLayout::maskBarlineForText(BarLine* barline, const std::vector<TextBase

for (TextBase* text : allSystemText) {
const double fontSizeScaleFactor = text->size() / 10.0;
const double collisionPadding = 0.25 * spatium * fontSizeScaleFactor;
const double collisionPadding = 0.2 * spatium * fontSizeScaleFactor;
const bool hasFrame = text->frameType() != FrameType::NO_FRAME;
const bool useHighResShape = !text->isDynamic() && !text->hasFrame();
const double maskPadding = hasFrame ? 0.0 : std::clamp(0.5 * spatium * fontSizeScaleFactor, 0.1 * spatium, spatium);
Expand Down
5 changes: 3 additions & 2 deletions src/engraving/rendering/score/measurelayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1252,8 +1252,9 @@ MeasureLayout::MeasureStartEndPos MeasureLayout::getMeasureStartEndPos(const Mea
break;
}

if (!modernMMRest && (s2->isClefRepeatAnnounceType() || s2->isTimeSigRepeatAnnounceType() || s2->isKeySigRepeatAnnounceType()
|| s2->isEndBarLineType()) && s2->element(staffIdx * VOICES)) {
if (!modernMMRest
&& (s2->isClefRepeatAnnounceType() || (s2->isTimeSigRepeatAnnounceType() && !s2->hasTimeSigAboveStaves())
|| s2->isKeySigRepeatAnnounceType() || s2->isEndBarLineType()) && s2->element(staffIdx * VOICES)) {
break;
}
}
Expand Down
15 changes: 7 additions & 8 deletions src/engraving/rendering/score/slurtielayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1852,31 +1852,30 @@ void SlurTieLayout::setPartialTieEndPos(PartialTie* item, SlurTiePos& sPos)
const Segment* seg = chord->segment();
const Measure* measure = seg->measure();
const System* system = measure->system();
double width = item->style().styleS(Sid::minHangingTieLength).val() * item->spatium();

if (seg->measure()->isFirstInSystem() && !outgoing) {
sPos.p1 = PointF((system ? system->firstNoteRestSegmentX(true) : 0), sPos.p2.y());
return;
}

const Segment* adjSeg = outgoing ? seg->next() : seg->prev();
const Segment* adjSeg = outgoing ? seg->next1() : seg->prev1();
while (adjSeg && (!adjSeg->isActive() || !adjSeg->enabled())) {
adjSeg = outgoing ? seg->next() : seg->prev();
adjSeg = outgoing ? seg->next1() : seg->prev1();
}

double widthToSegment = 0.0;
if (adjSeg) {
EngravingItem* element = adjSeg->element(staff2track(item->vStaffIdx()));
const double elementWidth = element ? element->width() : 0.0;
double widthToSegment = outgoing ? adjSeg->xPosInSystemCoords() - sPos.p1.x() : sPos.p2.x()
- (adjSeg->xPosInSystemCoords() + elementWidth);
widthToSegment = outgoing ? adjSeg->xPosInSystemCoords() - sPos.p1.x() : sPos.p2.x()
- (adjSeg->xPosInSystemCoords() + elementWidth);
widthToSegment -= 0.25 * item->spatium();
width = std::max(widthToSegment, width);
}

if (outgoing) {
sPos.p2 = PointF(sPos.p1.x() + width, sPos.p1.y());
sPos.p2 = PointF(sPos.p1.x() + widthToSegment, sPos.p1.y());
} else {
sPos.p1 = PointF(sPos.p2.x() - width, sPos.p2.y());
sPos.p1 = PointF(sPos.p2.x() - widthToSegment, sPos.p2.y());
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/framework/audio/internal/worker/eventaudiosource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ void EventAudioSource::setIsActive(const bool active)
return;
}

if (m_synth->isActive() == active) {
return;
}

m_synth->setIsActive(active);
m_synth->flushSound();
}
Expand Down
67 changes: 34 additions & 33 deletions src/framework/audio/internal/worker/mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ RetVal<MixerChannelPtr> Mixer::addChannel(const TrackId trackId, ITrackAudioInpu
return;
}

ITrackAudioInputPtr source = std::static_pointer_cast<ITrackAudioInput>(channel->source());

if (channel->muted()) {
if (source) {
source->setIsActive(false);
}
if (m_nonMutedTrackCount != 0) {
m_nonMutedTrackCount--;
}
Expand All @@ -92,8 +97,8 @@ RetVal<MixerChannelPtr> Mixer::addChannel(const TrackId trackId, ITrackAudioInpu

m_nonMutedTrackCount++;

ITrackAudioInputPtr source = std::static_pointer_cast<ITrackAudioInput>(channel->source());
if (source) {
source->setIsActive(isActive());
source->seek(currentTime());
}
});
Expand Down Expand Up @@ -206,26 +211,25 @@ samples_t Mixer::process(float* outBuffer, samples_t samplesPerChannel)

prepareAuxBuffers(outBufferSize);

samples_t masterChannelSampleCount = 0;

for (auto& pair : tracksData) {
const std::vector<float>& trackBuffer = pair.second;

bool outBufferIsSilent = false;
mixOutputFromChannel(outBuffer, trackBuffer.data(), samplesPerChannel, outBufferIsSilent);
masterChannelSampleCount = std::max(samplesPerChannel, masterChannelSampleCount);
auto channelIt = m_trackChannels.find(pair.first);
if (channelIt == m_trackChannels.cend()) {
continue;
}

if (!outBufferIsSilent) {
const MixerChannelPtr channel = channelIt->second;
if (!channel->isSilent()) {
m_isSilence = false;
} else if (m_isSilence) {
continue;
}

const AuxSendsParams& auxSends = m_trackChannels.at(pair.first)->outputParams().auxSends;
writeTrackToAuxBuffers(trackBuffer.data(), auxSends, samplesPerChannel);
const std::vector<float>& trackBuffer = pair.second;
mixOutputFromChannel(outBuffer, trackBuffer.data(), samplesPerChannel);
writeTrackToAuxBuffers(trackBuffer.data(), channel->outputParams().auxSends, samplesPerChannel);
}

if (m_masterParams.muted || masterChannelSampleCount == 0 || m_isSilence) {
if (m_masterParams.muted || samplesPerChannel == 0 || m_isSilence) {
notifyNoAudioSignal();
return 0;
}
Expand All @@ -239,7 +243,7 @@ samples_t Mixer::process(float* outBuffer, samples_t samplesPerChannel)
}
}

return masterChannelSampleCount;
return samplesPerChannel;
}

void Mixer::processTrackChannels(size_t outBufferSize, size_t samplesPerChannel, TracksData& outTracksData)
Expand Down Expand Up @@ -272,7 +276,7 @@ void Mixer::processTrackChannels(size_t outBufferSize, size_t samplesPerChannel,
continue;
}

if (pair.second->muted()) {
if (pair.second->muted() && pair.second->isSilent()) {
pair.second->notifyNoAudioSignal();
continue;
}
Expand All @@ -290,7 +294,7 @@ void Mixer::processTrackChannels(size_t outBufferSize, size_t samplesPerChannel,
continue;
}

if (pair.second->muted()) {
if (pair.second->muted() && pair.second->isSilent()) {
pair.second->notifyNoAudioSignal();
continue;
}
Expand Down Expand Up @@ -321,8 +325,16 @@ void Mixer::setIsActive(bool arg)

AbstractAudioSource::setIsActive(arg);

for (const auto& channel : m_trackChannels) {
channel.second->setIsActive(arg);
for (auto& channel : m_trackChannels) {
if (!channel.second->muted()) {
channel.second->setIsActive(arg);
}
}

for (auto& aux : m_auxChannelInfoList) {
if (!aux.channel->muted()) {
aux.channel->setIsActive(arg);
}
}
}

Expand Down Expand Up @@ -429,14 +441,12 @@ void Mixer::setTracksToProcessWhenIdle(std::unordered_set<TrackId>&& trackIds)
m_tracksToProcessWhenIdle = std::move(trackIds);
}

void Mixer::mixOutputFromChannel(float* outBuffer, const float* inBuffer, unsigned int samplesCount, bool& outBufferIsSilent)
void Mixer::mixOutputFromChannel(float* outBuffer, const float* inBuffer, unsigned int samplesCount) const
{
IF_ASSERT_FAILED(outBuffer && inBuffer) {
return;
}

outBufferIsSilent = true;

if (m_masterParams.muted) {
return;
}
Expand All @@ -448,10 +458,6 @@ void Mixer::mixOutputFromChannel(float* outBuffer, const float* inBuffer, unsign
size_t idx = samplePos + audioChNum;
float sample = inBuffer[idx];
outBuffer[idx] += sample;

if (outBufferIsSilent && !RealIsNull(sample)) {
outBufferIsSilent = false;
}
}
}
}
Expand Down Expand Up @@ -516,8 +522,9 @@ void Mixer::processAuxChannels(float* buffer, samples_t samplesPerChannel)
float* auxBuffer = aux.buffer.data();
aux.channel->process(auxBuffer, samplesPerChannel);

static bool isSilent = false;
mixOutputFromChannel(buffer, auxBuffer, samplesPerChannel, isSilent);
if (!aux.channel->isSilent()) {
mixOutputFromChannel(buffer, auxBuffer, samplesPerChannel);
}
}
}

Expand All @@ -527,14 +534,11 @@ void Mixer::completeOutput(float* buffer, samples_t samplesPerChannel)
return;
}

m_isSilence = true;

float totalSquaredSum = 0.f;
float volume = muse::db_to_linear(m_masterParams.volume);

for (audioch_t audioChNum = 0; audioChNum < m_audioChannelsCount; ++audioChNum) {
float singleChannelSquaredSum = 0.f;

gain_t totalGain = dsp::balanceGain(m_masterParams.balance, audioChNum) * volume;

for (samples_t s = 0; s < samplesPerChannel; ++s) {
Expand All @@ -543,10 +547,6 @@ void Mixer::completeOutput(float* buffer, samples_t samplesPerChannel)
float resultSample = buffer[idx] * totalGain;
buffer[idx] = resultSample;

if (m_isSilence && !RealIsNull(resultSample)) {
m_isSilence = false;
}

float squaredSample = resultSample * resultSample;
totalSquaredSum += squaredSample;
singleChannelSquaredSum += squaredSample;
Expand All @@ -556,6 +556,7 @@ void Mixer::completeOutput(float* buffer, samples_t samplesPerChannel)
m_audioSignalNotifier.updateSignalValues(audioChNum, rms);
}

m_isSilence = RealIsNull(totalSquaredSum);
m_audioSignalNotifier.notifyAboutChanges();

if (!m_limiter->isActive()) {
Expand Down
2 changes: 1 addition & 1 deletion src/framework/audio/internal/worker/mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Mixer : public AbstractAudioSource, public Injectable, public async::Async
using TracksData = std::map<TrackId, std::vector<float> >;

void processTrackChannels(size_t outBufferSize, size_t samplesPerChannel, TracksData& outTracksData);
void mixOutputFromChannel(float* outBuffer, const float* inBuffer, unsigned int samplesCount, bool& outBufferIsSilent);
void mixOutputFromChannel(float* outBuffer, const float* inBuffer, unsigned int samplesCount) const;
void prepareAuxBuffers(size_t outBufferSize);
void writeTrackToAuxBuffers(const float* trackBuffer, const AuxSendsParams& auxSends, samples_t samplesPerChannel);
void processAuxChannels(float* buffer, samples_t samplesPerChannel);
Expand Down
16 changes: 12 additions & 4 deletions src/framework/audio/internal/worker/mixerchannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,13 @@ samples_t MixerChannel::process(float* buffer, samples_t samplesPerChannel)

samples_t processedSamplesCount = samplesPerChannel;

if (m_audioSource && !m_params.muted) {
processedSamplesCount = m_audioSource->process(buffer, samplesPerChannel);
if (m_audioSource) {
if (!m_params.muted || !m_isSilent) {
processedSamplesCount = m_audioSource->process(buffer, samplesPerChannel);
}
}

if (processedSamplesCount == 0 || m_params.muted) {
if (processedSamplesCount == 0 || (m_params.muted && m_isSilent)) {
std::fill(buffer, buffer + samplesPerChannel * audioChannelsCount(), 0.f);
notifyNoAudioSignal();

Expand All @@ -215,7 +217,7 @@ samples_t MixerChannel::process(float* buffer, samples_t samplesPerChannel)
return processedSamplesCount;
}

void MixerChannel::completeOutput(float* buffer, unsigned int samplesCount) const
void MixerChannel::completeOutput(float* buffer, unsigned int samplesCount)
{
unsigned int channelsCount = audioChannelsCount();
float volume = muse::db_to_linear(m_params.volume);
Expand All @@ -241,6 +243,7 @@ void MixerChannel::completeOutput(float* buffer, unsigned int samplesCount) cons
m_audioSignalNotifier.updateSignalValues(audioChNum, rms);
}

m_isSilent = RealIsNull(totalSquaredSum);
m_audioSignalNotifier.notifyAboutChanges();

if (!m_compressor->isActive()) {
Expand All @@ -251,6 +254,11 @@ void MixerChannel::completeOutput(float* buffer, unsigned int samplesCount) cons
m_compressor->process(totalRms, buffer, channelsCount, samplesCount);
}

bool MixerChannel::isSilent() const
{
return m_isSilent;
}

void MixerChannel::notifyNoAudioSignal()
{
unsigned int channelsCount = audioChannelsCount();
Expand Down
6 changes: 5 additions & 1 deletion src/framework/audio/internal/worker/mixerchannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class MixerChannel : public ITrackAudioOutput, public Injectable, public async::
bool muted() const;
async::Notification mutedChanged() const;

bool isSilent() const;

void notifyNoAudioSignal();

const AudioOutputParams& outputParams() const override;
Expand All @@ -65,7 +67,7 @@ class MixerChannel : public ITrackAudioOutput, public Injectable, public async::
samples_t process(float* buffer, samples_t samplesPerChannel) override;

private:
void completeOutput(float* buffer, unsigned int samplesCount) const;
void completeOutput(float* buffer, unsigned int samplesCount);

TrackId m_trackId = -1;

Expand All @@ -78,6 +80,8 @@ class MixerChannel : public ITrackAudioOutput, public Injectable, public async::

dsp::CompressorPtr m_compressor = nullptr;

bool m_isSilent = true;

async::Notification m_mutedChanged;
mutable async::Channel<AudioOutputParams> m_paramsChanges;
mutable AudioSignalsNotifier m_audioSignalNotifier;
Expand Down
Loading
Loading