SampleEditor rendering fixes

This commit is contained in:
Jack Andersen 2018-07-31 14:49:05 -10:00
parent 6f0a26a86c
commit d062a087c5
5 changed files with 103 additions and 43 deletions

View File

@ -30,17 +30,31 @@ void SampleView::seekToSample(qreal sample)
uint32_t endRem = uint32_t(sample) % 14; uint32_t endRem = uint32_t(sample) % 14;
if (startRem) if (startRem)
{
uint32_t end = 14;
if (startBlock == endBlock)
{
end = endRem;
endRem = 0;
}
DSPDecompressFrameRangedStateOnly(m_sampleData + 8 * startBlock, m_sample->m_ADPCMParms.dsp.m_coefs, DSPDecompressFrameRangedStateOnly(m_sampleData + 8 * startBlock, m_sample->m_ADPCMParms.dsp.m_coefs,
&m_prev1, &m_prev2, startRem, startBlock == endBlock ? endRem : 14); &m_prev1, &m_prev2, startRem, end);
if (end == 14)
++startBlock;
}
for (uint32_t b = startBlock; b < endBlock; ++b) for (uint32_t b = startBlock; b < endBlock; ++b)
{
DSPDecompressFrameStateOnly(m_sampleData + 8 * b, m_sample->m_ADPCMParms.dsp.m_coefs, DSPDecompressFrameStateOnly(m_sampleData + 8 * b, m_sample->m_ADPCMParms.dsp.m_coefs,
&m_prev1, &m_prev2, 14); &m_prev1, &m_prev2, 14);
}
if (endRem) if (endRem)
{
DSPDecompressFrameStateOnly(m_sampleData + 8 * endBlock, m_sample->m_ADPCMParms.dsp.m_coefs, DSPDecompressFrameStateOnly(m_sampleData + 8 * endBlock, m_sample->m_ADPCMParms.dsp.m_coefs,
&m_prev1, &m_prev2, endRem); &m_prev1, &m_prev2, endRem);
} }
}
m_curSamplePos = sample; m_curSamplePos = sample;
} }
@ -72,11 +86,18 @@ std::pair<std::pair<qreal, qreal>, std::pair<qreal, qreal>> SampleView::iterateS
if (startRem) if (startRem)
{ {
uint32_t end = startBlock == endBlock ? endRem : 14; uint32_t end = 14;
if (startBlock == endBlock)
{
end = endRem;
endRem = 0;
}
DSPDecompressFrameRanged(sampleBlock, m_sampleData + 8 * startBlock, m_sample->m_ADPCMParms.dsp.m_coefs, DSPDecompressFrameRanged(sampleBlock, m_sampleData + 8 * startBlock, m_sample->m_ADPCMParms.dsp.m_coefs,
&m_prev1, &m_prev2, startRem, end); &m_prev1, &m_prev2, startRem, end);
for (int s = 0; s < end - startRem; ++s) for (int s = 0; s < end - startRem; ++s)
accumulate(sampleBlock[s]); accumulate(sampleBlock[s]);
if (end == 14)
++startBlock;
} }
for (uint32_t b = startBlock; b < endBlock; ++b) for (uint32_t b = startBlock; b < endBlock; ++b)
@ -129,11 +150,19 @@ void SampleView::paintEvent(QPaintEvent* ev)
constexpr int rulerHeight = 28; constexpr int rulerHeight = 28;
int sampleHeight = height() - rulerHeight; int sampleHeight = height() - rulerHeight;
qreal deviceRatio = devicePixelRatioF();
qreal rectStart = ev->rect().x(); qreal rectStart = ev->rect().x();
qreal deviceWidth = ev->rect().width() * deviceRatio;
qreal increment = 1.0 / deviceRatio;
qreal deviceSamplesPerPx = m_samplesPerPx / deviceRatio;
qreal startSample = rectStart * m_samplesPerPx; qreal startSample = rectStart * m_samplesPerPx;
qreal deviceWidth = ev->rect().width() * devicePixelRatioF(); qreal startSampleRem = std::fmod(startSample, deviceSamplesPerPx);
qreal increment = 1.0 / devicePixelRatioF(); if (startSampleRem > DBL_EPSILON)
qreal deviceSamplesPerPx = m_samplesPerPx / devicePixelRatioF(); {
startSample -= startSampleRem;
deviceWidth += startSampleRem;
rectStart = startSample / m_samplesPerPx;
}
if (m_sample) if (m_sample)
{ {
@ -145,11 +174,15 @@ void SampleView::paintEvent(QPaintEvent* ev)
seekToSample(startSample); seekToSample(startSample);
std::pair<std::pair<qreal, qreal>, std::pair<qreal, qreal>> avgPeak;
for (qreal i = 0.0; i < deviceWidth; i += increment) for (qreal i = 0.0; i < deviceWidth; i += increment)
{ {
if (m_curSamplePos + deviceSamplesPerPx > m_sample->getNumSamples()) if (m_curSamplePos + deviceSamplesPerPx > m_sample->getNumSamples())
break; break;
auto avgPeak = iterateSampleInterval(deviceSamplesPerPx); if (i == 0.0 || std::floor(m_curSamplePos) != std::floor(m_curSamplePos + deviceSamplesPerPx))
avgPeak = iterateSampleInterval(deviceSamplesPerPx);
else
m_curSamplePos += deviceSamplesPerPx;
painter.setPen(peakPen); painter.setPen(peakPen);
painter.drawLine(QPointF(rectStart + i, avgPeak.first.second * scale + trans), painter.drawLine(QPointF(rectStart + i, avgPeak.first.second * scale + trans),
QPointF(rectStart + i, avgPeak.second.second * scale + trans)); QPointF(rectStart + i, avgPeak.second.second * scale + trans));
@ -172,13 +205,14 @@ void SampleView::paintEvent(QPaintEvent* ev)
qreal numSpacing = binaryDiv / m_samplesPerPx; qreal numSpacing = binaryDiv / m_samplesPerPx;
qreal tickSpacing = numSpacing / 5; qreal tickSpacing = numSpacing / 5;
int lastNumDiv = int(ev->rect().x() / numSpacing); int startX = std::max(0, int(ev->rect().x() - numSpacing));
int lastTickDiv = int(ev->rect().x() / tickSpacing); int lastNumDiv = int(startX / numSpacing);
int lastTickDiv = int(startX / tickSpacing);
qreal samplePos = startSample; qreal samplePos = startX * m_samplesPerPx;
painter.setFont(m_rulerFont); painter.setFont(m_rulerFont);
painter.setPen(QPen(QColor(127, 127, 127), increment)); painter.setPen(QPen(QColor(127, 127, 127), increment));
for (int i = ev->rect().x(); i < ev->rect().x() + ev->rect().width(); ++i) for (int i = startX; i < ev->rect().x() + ev->rect().width() + numSpacing; ++i)
{ {
int thisNumDiv = int(i / numSpacing); int thisNumDiv = int(i / numSpacing);
int thisTickDiv = int(i / tickSpacing); int thisTickDiv = int(i / tickSpacing);
@ -327,11 +361,6 @@ void SampleView::wheelEvent(QWheelEvent* ev)
} }
} }
void SampleView::moveEvent(QMoveEvent* ev)
{
update();
}
void SampleView::loadData(ProjectModel::SampleNode* node) void SampleView::loadData(ProjectModel::SampleNode* node)
{ {
m_node = node; m_node = node;
@ -375,11 +404,28 @@ const amuse::SoundMacro* SampleView::soundMacro() const
void SampleView::setSamplePos(int pos) void SampleView::setSamplePos(int pos)
{ {
if (pos != m_displaySamplePos) if (pos != m_displaySamplePos)
{
if (pos >= 0)
{
int lastPos = m_displaySamplePos;
m_displaySamplePos = pos;
updateSampleRange(lastPos, pos);
}
else
{ {
m_displaySamplePos = pos; m_displaySamplePos = pos;
update(); update();
} }
} }
}
void SampleView::updateSampleRange(int oldSamp, int newSamp)
{
qreal lastPos = oldSamp / m_samplesPerPx;
qreal newPos = newSamp / m_samplesPerPx;
update(int(std::min(lastPos, newPos)) - 10, 0,
int(std::fabs(newPos - lastPos)) + 20, height());
}
SampleView::SampleView(QWidget* parent) SampleView::SampleView(QWidget* parent)
: QWidget(parent) : QWidget(parent)
@ -431,9 +477,12 @@ void SampleControls::startValueChanged(int val)
{ {
SampleEditor* editor = qobject_cast<SampleEditor*>(parentWidget()); SampleEditor* editor = qobject_cast<SampleEditor*>(parentWidget());
amuse::SampleEntryData* data = editor->m_sampleView->entryData(); amuse::SampleEntryData* data = editor->m_sampleView->entryData();
int oldPos = data->getLoopStartSample();
data->setLoopStartSample(atUint32(val)); data->setLoopStartSample(atUint32(val));
m_loopEnd->setMinimum(val); m_loopEnd->setMinimum(val);
editor->m_sampleView->update();
editor->m_sampleView->updateSampleRange(oldPos, val);
} }
} }
@ -443,9 +492,12 @@ void SampleControls::endValueChanged(int val)
{ {
SampleEditor* editor = qobject_cast<SampleEditor*>(parentWidget()); SampleEditor* editor = qobject_cast<SampleEditor*>(parentWidget());
amuse::SampleEntryData* data = editor->m_sampleView->entryData(); amuse::SampleEntryData* data = editor->m_sampleView->entryData();
int oldPos = data->getLoopEndSample();
data->setLoopEndSample(atUint32(val)); data->setLoopEndSample(atUint32(val));
m_loopStart->setMaximum(val); m_loopStart->setMaximum(val);
editor->m_sampleView->update();
editor->m_sampleView->updateSampleRange(oldPos, val);
} }
} }

View File

@ -44,6 +44,7 @@ public:
amuse::SampleEntryData* entryData() const; amuse::SampleEntryData* entryData() const;
const amuse::SoundMacro* soundMacro() const; const amuse::SoundMacro* soundMacro() const;
void setSamplePos(int pos); void setSamplePos(int pos);
void updateSampleRange(int oldSamp, int newSamp);
void paintEvent(QPaintEvent* ev); void paintEvent(QPaintEvent* ev);
void resetZoom(); void resetZoom();
@ -53,7 +54,6 @@ public:
void mouseReleaseEvent(QMouseEvent* ev); void mouseReleaseEvent(QMouseEvent* ev);
void mouseMoveEvent(QMouseEvent* ev); void mouseMoveEvent(QMouseEvent* ev);
void wheelEvent(QWheelEvent* ev); void wheelEvent(QWheelEvent* ev);
void moveEvent(QMoveEvent* ev);
}; };
class SampleControls : public QFrame class SampleControls : public QFrame

View File

@ -32,11 +32,11 @@
inkscape:current-layer="layer1" inkscape:current-layer="layer1"
showgrid="true" showgrid="true"
units="px" units="px"
inkscape:window-width="1452" inkscape:window-width="3840"
inkscape:window-height="1061" inkscape:window-height="2079"
inkscape:window-x="651" inkscape:window-x="0"
inkscape:window-y="170" inkscape:window-y="40"
inkscape:window-maximized="0" inkscape:window-maximized="1"
gridtolerance="10" gridtolerance="10"
showguides="false"> showguides="false">
<inkscape:grid <inkscape:grid
@ -70,27 +70,27 @@
id="path842" id="path842"
inkscape:connector-curvature="0" /> inkscape:connector-curvature="0" />
<path <path
style="fill:#000006;fill-opacity:1;stroke:none;stroke-width:0.52916664;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:0.49803922" style="fill:#000006;fill-opacity:1;stroke:none;stroke-width:0.79053128;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:0.49803922"
id="path844" id="path844"
sodipodi:type="arc" sodipodi:type="arc"
sodipodi:cx="1.8520833" sodipodi:cx="1.6969496"
sodipodi:cy="293.56039" sodipodi:cy="294.08957"
sodipodi:rx="0.47706053" sodipodi:rx="0.71268904"
sodipodi:ry="0.43746531" sodipodi:ry="0.65353703"
sodipodi:start="0" sodipodi:start="0"
sodipodi:end="5.866374" sodipodi:end="5.866374"
d="m 2.3291439,293.56039 a 0.47706053,0.43746531 0 0 1 -0.4274394,0.4351 0.47706053,0.43746531 0 0 1 -0.5163591,-0.34458 0.47706053,0.43746531 0 0 1 0.3200219,-0.50678 0.47706053,0.43746531 0 0 1 0.5829328,0.23916 l -0.4362168,0.1771 z" /> d="m 2.4096386,294.08957 a 0.71268904,0.65353703 0 0 1 -0.6385591,0.64999 0.71268904,0.65353703 0 0 1 -0.7713978,-0.51477 0.71268904,0.65353703 0 0 1 0.4780863,-0.75708 0.71268904,0.65353703 0 0 1 0.8708534,0.35728 l -0.6516718,0.26458 z" />
<path <path
d="m 3.9161899,293.56039 a 0.47706053,0.43746531 0 0 1 -0.4274394,0.4351 0.47706053,0.43746531 0 0 1 -0.5163591,-0.34458 0.47706053,0.43746531 0 0 1 0.3200219,-0.50678 0.47706053,0.43746531 0 0 1 0.5829328,0.23916 l -0.4362167,0.1771 z" d="m 4.2943505,294.08957 a 0.71268904,0.65353703 0 0 1 -0.6385591,0.64999 0.71268904,0.65353703 0 0 1 -0.7713978,-0.51477 0.71268904,0.65353703 0 0 1 0.4780862,-0.75708 0.71268904,0.65353703 0 0 1 0.8708535,0.35728 l -0.6516718,0.26458 z"
sodipodi:end="5.866374" sodipodi:end="5.866374"
sodipodi:start="0" sodipodi:start="0"
sodipodi:ry="0.43746531" sodipodi:ry="0.65353703"
sodipodi:rx="0.47706053" sodipodi:rx="0.71268904"
sodipodi:cy="293.56039" sodipodi:cy="294.08957"
sodipodi:cx="3.4391294" sodipodi:cx="3.5816615"
sodipodi:type="arc" sodipodi:type="arc"
id="path846" id="path846"
style="fill:#000006;fill-opacity:1;stroke:none;stroke-width:0.52916664;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:0.49803922" /> style="fill:#000006;fill-opacity:1;stroke:none;stroke-width:0.79053128;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:0.49803922" />
<path <path
style="fill:none;stroke:#000000;stroke-width:0.29107958px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" style="fill:none;stroke:#000000;stroke-width:0.29107958px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 2.6458333,295.41249 v 1.28091" d="m 2.6458333,295.41249 v 1.28091"

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

View File

@ -481,7 +481,12 @@
<context> <context>
<name>SampleControls</name> <name>SampleControls</name>
<message> <message>
<location filename="../SampleEditor.cpp" line="+501"/> <location filename="../SampleEditor.cpp" line="+546"/>
<source>Make WAV Version</source>
<translation type="unfinished"></translation>
</message>
<message>
<location line="+7"/>
<source>Make Compressed Version</source> <source>Make Compressed Version</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
@ -521,11 +526,6 @@
<source>Base Pitch</source> <source>Base Pitch</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<location line="-115"/>
<source>Make WAV Version</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>SoundMacroCatalogue</name> <name>SoundMacroCatalogue</name>

View File

@ -230,10 +230,18 @@ public:
m_loopLengthSamples += m_loopStartSample - sample; m_loopLengthSamples += m_loopStartSample - sample;
m_loopStartSample = sample; m_loopStartSample = sample;
} }
atUint32 getLoopStartSample() const
{
return m_loopStartSample;
}
void setLoopEndSample(atUint32 sample) void setLoopEndSample(atUint32 sample)
{ {
m_loopLengthSamples = sample + 1 - m_loopStartSample; m_loopLengthSamples = sample + 1 - m_loopStartSample;
} }
atUint32 getLoopEndSample() const
{
return m_loopStartSample + m_loopLengthSamples - 1;
}
EntryData() = default; EntryData() = default;