mirror of https://github.com/AxioDL/amuse.git
SampleEditor rendering fixes
This commit is contained in:
parent
6f0a26a86c
commit
d062a087c5
|
@ -30,17 +30,31 @@ void SampleView::seekToSample(qreal sample)
|
|||
uint32_t endRem = uint32_t(sample) % 14;
|
||||
|
||||
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,
|
||||
&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)
|
||||
{
|
||||
DSPDecompressFrameStateOnly(m_sampleData + 8 * b, m_sample->m_ADPCMParms.dsp.m_coefs,
|
||||
&m_prev1, &m_prev2, 14);
|
||||
}
|
||||
|
||||
if (endRem)
|
||||
{
|
||||
DSPDecompressFrameStateOnly(m_sampleData + 8 * endBlock, m_sample->m_ADPCMParms.dsp.m_coefs,
|
||||
&m_prev1, &m_prev2, endRem);
|
||||
}
|
||||
}
|
||||
|
||||
m_curSamplePos = sample;
|
||||
}
|
||||
|
@ -72,11 +86,18 @@ std::pair<std::pair<qreal, qreal>, std::pair<qreal, qreal>> SampleView::iterateS
|
|||
|
||||
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,
|
||||
&m_prev1, &m_prev2, startRem, end);
|
||||
for (int s = 0; s < end - startRem; ++s)
|
||||
accumulate(sampleBlock[s]);
|
||||
if (end == 14)
|
||||
++startBlock;
|
||||
}
|
||||
|
||||
for (uint32_t b = startBlock; b < endBlock; ++b)
|
||||
|
@ -129,11 +150,19 @@ void SampleView::paintEvent(QPaintEvent* ev)
|
|||
constexpr int rulerHeight = 28;
|
||||
int sampleHeight = height() - rulerHeight;
|
||||
|
||||
qreal deviceRatio = devicePixelRatioF();
|
||||
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 deviceWidth = ev->rect().width() * devicePixelRatioF();
|
||||
qreal increment = 1.0 / devicePixelRatioF();
|
||||
qreal deviceSamplesPerPx = m_samplesPerPx / devicePixelRatioF();
|
||||
qreal startSampleRem = std::fmod(startSample, deviceSamplesPerPx);
|
||||
if (startSampleRem > DBL_EPSILON)
|
||||
{
|
||||
startSample -= startSampleRem;
|
||||
deviceWidth += startSampleRem;
|
||||
rectStart = startSample / m_samplesPerPx;
|
||||
}
|
||||
|
||||
if (m_sample)
|
||||
{
|
||||
|
@ -145,11 +174,15 @@ void SampleView::paintEvent(QPaintEvent* ev)
|
|||
|
||||
seekToSample(startSample);
|
||||
|
||||
std::pair<std::pair<qreal, qreal>, std::pair<qreal, qreal>> avgPeak;
|
||||
for (qreal i = 0.0; i < deviceWidth; i += increment)
|
||||
{
|
||||
if (m_curSamplePos + deviceSamplesPerPx > m_sample->getNumSamples())
|
||||
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.drawLine(QPointF(rectStart + i, avgPeak.first.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 tickSpacing = numSpacing / 5;
|
||||
|
||||
int lastNumDiv = int(ev->rect().x() / numSpacing);
|
||||
int lastTickDiv = int(ev->rect().x() / tickSpacing);
|
||||
int startX = std::max(0, int(ev->rect().x() - numSpacing));
|
||||
int lastNumDiv = int(startX / numSpacing);
|
||||
int lastTickDiv = int(startX / tickSpacing);
|
||||
|
||||
qreal samplePos = startSample;
|
||||
qreal samplePos = startX * m_samplesPerPx;
|
||||
painter.setFont(m_rulerFont);
|
||||
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 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)
|
||||
{
|
||||
m_node = node;
|
||||
|
@ -375,10 +404,27 @@ const amuse::SoundMacro* SampleView::soundMacro() const
|
|||
void SampleView::setSamplePos(int pos)
|
||||
{
|
||||
if (pos != m_displaySamplePos)
|
||||
{
|
||||
if (pos >= 0)
|
||||
{
|
||||
int lastPos = m_displaySamplePos;
|
||||
m_displaySamplePos = pos;
|
||||
updateSampleRange(lastPos, pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_displaySamplePos = pos;
|
||||
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)
|
||||
|
@ -431,9 +477,12 @@ void SampleControls::startValueChanged(int val)
|
|||
{
|
||||
SampleEditor* editor = qobject_cast<SampleEditor*>(parentWidget());
|
||||
amuse::SampleEntryData* data = editor->m_sampleView->entryData();
|
||||
|
||||
int oldPos = data->getLoopStartSample();
|
||||
data->setLoopStartSample(atUint32(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());
|
||||
amuse::SampleEntryData* data = editor->m_sampleView->entryData();
|
||||
|
||||
int oldPos = data->getLoopEndSample();
|
||||
data->setLoopEndSample(atUint32(val));
|
||||
m_loopStart->setMaximum(val);
|
||||
editor->m_sampleView->update();
|
||||
|
||||
editor->m_sampleView->updateSampleRange(oldPos, val);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ public:
|
|||
amuse::SampleEntryData* entryData() const;
|
||||
const amuse::SoundMacro* soundMacro() const;
|
||||
void setSamplePos(int pos);
|
||||
void updateSampleRange(int oldSamp, int newSamp);
|
||||
|
||||
void paintEvent(QPaintEvent* ev);
|
||||
void resetZoom();
|
||||
|
@ -53,7 +54,6 @@ public:
|
|||
void mouseReleaseEvent(QMouseEvent* ev);
|
||||
void mouseMoveEvent(QMouseEvent* ev);
|
||||
void wheelEvent(QWheelEvent* ev);
|
||||
void moveEvent(QMoveEvent* ev);
|
||||
};
|
||||
|
||||
class SampleControls : public QFrame
|
||||
|
|
|
@ -32,11 +32,11 @@
|
|||
inkscape:current-layer="layer1"
|
||||
showgrid="true"
|
||||
units="px"
|
||||
inkscape:window-width="1452"
|
||||
inkscape:window-height="1061"
|
||||
inkscape:window-x="651"
|
||||
inkscape:window-y="170"
|
||||
inkscape:window-maximized="0"
|
||||
inkscape:window-width="3840"
|
||||
inkscape:window-height="2079"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="40"
|
||||
inkscape:window-maximized="1"
|
||||
gridtolerance="10"
|
||||
showguides="false">
|
||||
<inkscape:grid
|
||||
|
@ -70,27 +70,27 @@
|
|||
id="path842"
|
||||
inkscape:connector-curvature="0" />
|
||||
<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"
|
||||
sodipodi:type="arc"
|
||||
sodipodi:cx="1.8520833"
|
||||
sodipodi:cy="293.56039"
|
||||
sodipodi:rx="0.47706053"
|
||||
sodipodi:ry="0.43746531"
|
||||
sodipodi:cx="1.6969496"
|
||||
sodipodi:cy="294.08957"
|
||||
sodipodi:rx="0.71268904"
|
||||
sodipodi:ry="0.65353703"
|
||||
sodipodi:start="0"
|
||||
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
|
||||
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:start="0"
|
||||
sodipodi:ry="0.43746531"
|
||||
sodipodi:rx="0.47706053"
|
||||
sodipodi:cy="293.56039"
|
||||
sodipodi:cx="3.4391294"
|
||||
sodipodi:ry="0.65353703"
|
||||
sodipodi:rx="0.71268904"
|
||||
sodipodi:cy="294.08957"
|
||||
sodipodi:cx="3.5816615"
|
||||
sodipodi:type="arc"
|
||||
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
|
||||
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"
|
||||
|
|
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.3 KiB |
|
@ -481,7 +481,12 @@
|
|||
<context>
|
||||
<name>SampleControls</name>
|
||||
<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>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
|
@ -521,11 +526,6 @@
|
|||
<source>Base Pitch</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location line="-115"/>
|
||||
<source>Make WAV Version</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>SoundMacroCatalogue</name>
|
||||
|
|
|
@ -230,10 +230,18 @@ public:
|
|||
m_loopLengthSamples += m_loopStartSample - sample;
|
||||
m_loopStartSample = sample;
|
||||
}
|
||||
atUint32 getLoopStartSample() const
|
||||
{
|
||||
return m_loopStartSample;
|
||||
}
|
||||
void setLoopEndSample(atUint32 sample)
|
||||
{
|
||||
m_loopLengthSamples = sample + 1 - m_loopStartSample;
|
||||
}
|
||||
atUint32 getLoopEndSample() const
|
||||
{
|
||||
return m_loopStartSample + m_loopLengthSamples - 1;
|
||||
}
|
||||
|
||||
EntryData() = default;
|
||||
|
||||
|
|
Loading…
Reference in New Issue