diff --git a/au4/src/au3wrap/iau3wavepainter.h b/au4/src/au3wrap/iau3wavepainter.h index fe98e7d8954c2ac9d6156cc566ef18554cbbd4f1..019ebfebf1e0173969ad1b80254308b394f6569c 100644 --- a/au4/src/au3wrap/iau3wavepainter.h +++ b/au4/src/au3wrap/iau3wavepainter.h @@ -23,9 +23,9 @@ public: }; struct Geometry { - double height = 0.0; // wave view height - double width = 0.0; // wave view width - double left = 0.0; // on track line + double clipHeight = 0.0; // clip view height + double clipWidth = 0.0; // clip view width + double relClipLeft = 0.0; // relatively to frameLeft double frameLeft = 0.0; // track line shift double frameWidth = 0.0; // track line visible width }; diff --git a/au4/src/au3wrap/internal/au3wavepainter.cpp b/au4/src/au3wrap/internal/au3wavepainter.cpp index 64956bdb9d15deddbf1cd8c35fad923d44e99386..a6578574b434e9139da332c0873dfcc8ac9828ec 100644 --- a/au4/src/au3wrap/internal/au3wavepainter.cpp +++ b/au4/src/au3wrap/internal/au3wavepainter.cpp @@ -123,6 +123,7 @@ public: double top = 0.0; double left = 0.0; double height = 0.0; + double width = 0.0; // not used for draw, just info }; void Draw(int channelIndex, @@ -148,14 +149,6 @@ public: int left = geometry.left; int height = geometry.height; - LOGDA() << " top: " << geometry.top - << " left: " << geometry.left - << " height: " << geometry.height - << " zoom: " << zoom - << " from: " << from - << " to: " << to - ; - for (auto it = range.begin(); it != range.end(); ++it) { const auto elementLeftOffset = it.GetLeftOffset(); const auto elementRightOffset = it.GetRightOffset(); @@ -368,12 +361,12 @@ int GetWaveYPos(float value, float min, float max, return (int)(value * (height - 1) + 0.5); } -struct ClipGeometry +struct WaveGeometry { - double top = 0.0; // wave channel view top - double height = 0.0; // wave view height - double width = 0.0; // wave view width - double left = 0.0; // on track line + double waveTop = 0.0; // wave channel view top + double waveHeight = 0.0; // wave channel view height + double clipWidth = 0.0; // clip view width + double relClipLeft = 0.0; // relatively to frameLeft double frameLeft = 0.0; // track line shift double frameWidth = 0.0; // track line visible width }; @@ -381,25 +374,44 @@ struct ClipGeometry struct ClipParameters { // Do a bunch of calculations common to waveform and spectrum drawing. - ClipParameters(const ClipGeometry& geometry, double zoom); + ClipParameters(const WaveGeometry& geometry, double zoom); + + const WaveGeometry geometry; - ClipGeometry geometry; + WaveformPainter::Geometry drawGeometry; // Lower and upper visible time boundaries (relative to clip). If completely // off-screen, `t0 == t1`. double t0 = 0.0; double t1 = 0.0; - - QRect mid; }; -ClipParameters::ClipParameters(const ClipGeometry& geomet, double zoom) +ClipParameters::ClipParameters(const WaveGeometry& geomet, double zoom) : geometry(geomet) { - geometry.left = 0.0; + double drawWidth = std::min(geometry.relClipLeft + geometry.clipWidth, geometry.frameWidth) - geometry.relClipLeft; + double drawLeft = 0.0; + if (geometry.relClipLeft < 0) { + drawLeft = -geometry.relClipLeft; + } - t0 = 0;//geomet.left / zoom; - t1 = t0 + (geomet.width / zoom); + drawGeometry.top = geometry.waveTop; + drawGeometry.left = drawLeft; + drawGeometry.height = geometry.waveHeight; + drawGeometry.width = drawWidth; + + t0 = drawLeft / zoom; + t1 = drawWidth / zoom; + + LOGDA() << " relClipLeft: " << geometry.relClipLeft + << " clipWidth: " << geometry.clipWidth + << " frameLeft: " << geometry.frameLeft + << " frameWidth: " << geometry.frameWidth + << " draw width: " << drawWidth + << " draw left: " << drawLeft + << " t0: " << t0 + << " t1: " << t1 + ; } void DrawIndividualSamples(int channelIndex, QPainter& painter, const QRect& rect, @@ -536,17 +548,12 @@ void DrawMinMaxRMS(int channelIndex, QPainter& painter, { auto& waveformPainter = WaveformPainter::Get(clip); - WaveformPainter::Geometry g; - g.top = params.geometry.top; - g.left = params.geometry.left; - g.height = params.geometry.height; - WavePaintParameters paintParameters; paintParameters .SetDisplayParameters( //TODO: uncomment and fix - g.height, zoomMin, zoomMax, false /*artist->mShowClipping*/) + params.drawGeometry.height, zoomMin, zoomMax, false /*artist->mShowClipping*/) .SetDBParameters(dbRange, dB) .SetBlankColor(ColorFromQColor(style.blankBrush)) .SetSampleColors( @@ -565,7 +572,7 @@ void DrawMinMaxRMS(int channelIndex, QPainter& painter, const auto trimLeft = clip.GetTrimLeft(); - waveformPainter.Draw(channelIndex, painter, paintParameters, g, zoom, params.t0 + trimLeft, params.t1 + trimLeft); + waveformPainter.Draw(channelIndex, painter, paintParameters, params.drawGeometry, zoom, params.t0 + trimLeft, params.t1 + trimLeft); } static bool showIndividualSamples(const WaveClip& clip, bool zoom) @@ -584,14 +591,14 @@ static void DrawWaveform(int channelIndex, QPainter& painter, WaveTrack& track, const WaveClip& clip, - const ClipGeometry& geometry, + const WaveGeometry& geometry, double zoom, const Style& style, bool dB) { //If clip is "too small" draw a placeholder instead of //attempting to fit the contents into a few pixels - if (geometry.width < CLIPVIEW_WIDTH_MIN) { + if (geometry.clipWidth < CLIPVIEW_WIDTH_MIN) { //TODO: uncomment and fix me /* auto clipRect = ClipParameters::GetClipRect(clip, zoomInfo, rect); @@ -601,9 +608,9 @@ static void DrawWaveform(int channelIndex, } const ClipParameters params(geometry, zoom); - // if (params.mid.width() <= 0) { - // return; - // } + if (params.drawGeometry.width < 0.1) { + return; + } auto& settings = WaveformSettings::Get(track); const float dBRange = settings.dBRange; @@ -650,7 +657,12 @@ AudacityProject& Au3WavePainter::projectRef() const void Au3WavePainter::paint(QPainter& painter, const processing::ClipKey& clipKey, const Params& params) { - LOGD() << "trackId: " << clipKey.trackId << ", clip: " << clipKey.index; + //! NOTE Please don't remove, need for debug + // if (!(clipKey.trackId == 2 && clipKey.index == 0)) { + // return; + // } + // LOGD() << "trackId: " << clipKey.trackId << ", clip: " << clipKey.index; + WaveTrack* track = DomAccessor::findWaveTrack(projectRef(), TrackId(clipKey.trackId)); IF_ASSERT_FAILED(track) { return; @@ -672,20 +684,20 @@ void Au3WavePainter::doPaint(QPainter& painter, const WaveTrack* _track, const W const bool dB = !WaveformSettings::Get(*track).isLinear(); - const auto channelHeight = (params.geometry.height) / static_cast<int>(clip->NChannels()); + const auto channelHeight = (params.geometry.clipHeight) / static_cast<int>(clip->NChannels()); const Geometry& g = params.geometry; - ClipGeometry cg; - cg.height = channelHeight; - cg.width = g.width; - cg.left = g.left; + WaveGeometry cg; + cg.waveHeight = channelHeight; + cg.clipWidth = g.clipWidth; + cg.relClipLeft = g.relClipLeft; cg.frameLeft = g.frameLeft; cg.frameWidth = g.frameWidth; - cg.top = 0.0; + cg.waveTop = 0.0; for (unsigned i = 0; i < clip->NChannels(); ++i) { DrawWaveform(i, painter, *track, *clip, cg, params.zoom, params.style, dB); - cg.top += channelHeight; + cg.waveTop += channelHeight; } } diff --git a/au4/src/projectscene/qml/Audacity/ProjectScene/clipsview/Timeline.qml b/au4/src/projectscene/qml/Audacity/ProjectScene/clipsview/Timeline.qml index c5ccdb265961fb0fde2ef1e804be15683b5e9083..b7d0d0561d7d9704126b82b1f25fde77862bbce6 100644 --- a/au4/src/projectscene/qml/Audacity/ProjectScene/clipsview/Timeline.qml +++ b/au4/src/projectscene/qml/Audacity/ProjectScene/clipsview/Timeline.qml @@ -48,6 +48,7 @@ Rectangle { text: "zoom: " + timelineContext.zoom + ", frame start time: " + timelineContext.frameStartTime + ", end time: " + timelineContext.frameEndTime + + ", root.width: " + root.width } SeparatorLine { anchors.bottom: parent.bottom } diff --git a/au4/src/projectscene/qml/Audacity/ProjectScene/clipsview/TracksClipsView.qml b/au4/src/projectscene/qml/Audacity/ProjectScene/clipsview/TracksClipsView.qml index 721fff76947130d9c8d8c571a887d97832f42c7c..9928bc4fc791137bf23373bd36190c07e9a8d2cf 100644 --- a/au4/src/projectscene/qml/Audacity/ProjectScene/clipsview/TracksClipsView.qml +++ b/au4/src/projectscene/qml/Audacity/ProjectScene/clipsview/TracksClipsView.qml @@ -10,8 +10,7 @@ Rectangle { clip: true - //color: ui.theme.backgroundPrimaryColor - color: "#ffffff" + color: ui.theme.backgroundPrimaryColor TracksListClipsModel { id: tracksModel @@ -21,42 +20,35 @@ Rectangle { tracksModel.load() } - Rectangle { - anchors.fill: parent - anchors.leftMargin: 150 - anchors.rightMargin: 150 - color: ui.theme.backgroundPrimaryColor - - Timeline { - id: timeline + Timeline { + id: timeline - anchors.top: parent.top - anchors.left: parent.left - anchors.right: parent.right - } + anchors.top: parent.top + anchors.left: parent.left + anchors.right: parent.right + } - MouseArea { - anchors.fill: parent - onWheel: function(wheel) { - timeline.onWheel(wheel.angleDelta.y) - } + MouseArea { + anchors.fill: parent + onWheel: function(wheel) { + timeline.onWheel(wheel.angleDelta.y) } + } - Column { - anchors.top: timeline.bottom - anchors.left: parent.left - anchors.right: parent.right - anchors.bottom: parent.bottom - - Repeater { - model: tracksModel - delegate: TrackClipsItem { - anchors.left: parent.left - anchors.right: parent.right - height: 144 - context: timeline.context - trackId: trackIdData - } + Column { + anchors.top: timeline.bottom + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: parent.bottom + + Repeater { + model: tracksModel + delegate: TrackClipsItem { + anchors.left: parent.left + anchors.right: parent.right + height: 144 + context: timeline.context + trackId: trackIdData } } } diff --git a/au4/src/projectscene/view/clipsview/timelinecontext.cpp b/au4/src/projectscene/view/clipsview/timelinecontext.cpp index 6f6e6e9ddacdf26e6cd27ab87f7e23a63cdefaac..c3e4676f1551190639ddb58d92eaa9d4c9980c23 100644 --- a/au4/src/projectscene/view/clipsview/timelinecontext.cpp +++ b/au4/src/projectscene/view/clipsview/timelinecontext.cpp @@ -37,17 +37,12 @@ void TimelineContext::onWheel(double y) void TimelineContext::changeZoom(int direction) { - double step = std::round(std::max(zoom() / 2.0, ZOOM_MIN) * 10) / 10; + double step = (muse::is_equal(m_zoom, 1.0) && direction < 0) ? 0.1 : 1.0; - double _zoom = zoom() + (step * direction); - _zoom = std::floor(_zoom * 10.0) / 10.0; - if (_zoom > 4) { - _zoom = std::floor(_zoom); - } - - _zoom = std::max(_zoom, ZOOM_MIN); + double zoom = m_zoom + (step * direction); + zoom = std::max(zoom, ZOOM_MIN); - setZoom(_zoom); + setZoom(zoom); } void TimelineContext::onResizeFrameWidth(double frameWidth) @@ -69,7 +64,7 @@ void TimelineContext::shiftFrameTime(int direction) void TimelineContext::updateFrameTime() { - setFrameEndTime(m_frameStartTime + positionToTime(m_frameWidth)); + setFrameEndTime(positionToTime(m_frameWidth)); emit frameTimeChanged(); } diff --git a/au4/src/projectscene/view/clipsview/waveview.cpp b/au4/src/projectscene/view/clipsview/waveview.cpp index c2ef066e9f27ba9a9f48719740f87d637daddf36..19e6130920d3e8221e070cb839003aca4590cade 100644 --- a/au4/src/projectscene/view/clipsview/waveview.cpp +++ b/au4/src/projectscene/view/clipsview/waveview.cpp @@ -29,9 +29,9 @@ void WaveView::setClipKey(const ClipKey& newClipKey) void WaveView::paint(QPainter* painter) { au3::IAu3WavePainter::Params params; - params.geometry.height = height(); - params.geometry.width = width(); - params.geometry.left = m_clipLeft; + params.geometry.clipHeight = height(); + params.geometry.clipWidth = width(); + params.geometry.relClipLeft = m_clipLeft; params.geometry.frameLeft = m_context->frameStartTime() * m_context->zoom(); params.geometry.frameWidth = (m_context->frameEndTime() - m_context->frameStartTime()) * m_context->zoom();