Skip to content
Merged
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
11 changes: 4 additions & 7 deletions framework/audio/engine/internal/fx/reverb/circularsamplebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef MUSE_AUDIO_CIRCULARSAMPLEBUFFER_H
#define MUSE_AUDIO_CIRCULARSAMPLEBUFFER_H
#pragma once

#include <cstring>
#include <algorithm>
Expand Down Expand Up @@ -127,21 +126,21 @@ class CircularSampleBuffer
public:
void writeBlock(int startOffset, int n, const SampleT* sourceBlock)
{
splitBlockOffsetFunction(startOffset, n, [=](int bufferOff, int sampleOff, int n) {
splitBlockOffsetFunction(startOffset, n, [this, sourceBlock](int bufferOff, int sampleOff, int n) {
vo::copy(&sourceBlock[sampleOff], &m_buffer[bufferOff], n);
});
}

void readBlockWithGain(int startOffset, int n, SampleT* targetBlock, float gainFactor) const
{
splitBlockOffsetFunction(startOffset, n, [=](int bufferOff, int sampleOff, int n) {
splitBlockOffsetFunction(startOffset, n, [this, targetBlock, gainFactor](int bufferOff, int sampleOff, int n) {
vo::constantMultiply(&m_buffer[bufferOff], gainFactor, &targetBlock[sampleOff], n);
});
}

void readAddBlockWithGain(int startOffset, int n, SampleT* targetBlock, float gainFactor) const
{
splitBlockOffsetFunction(startOffset, n, [=](int bufferOff, int sampleOff, int n) {
splitBlockOffsetFunction(startOffset, n, [this, targetBlock, gainFactor](int bufferOff, int sampleOff, int n) {
vo::constantMultiplyAndAdd(&m_buffer[bufferOff], gainFactor, &targetBlock[sampleOff], n);
});
}
Expand All @@ -154,5 +153,3 @@ class CircularSampleBuffer
int m_bufferSizeMask = 0; // 2^n-1 buffer mask
};
} // namespace muse::audio::fx

#endif // MUSE_AUDIO_CIRCULARSAMPLEBUFFER_H
6 changes: 3 additions & 3 deletions framework/draw/bufferedpaintprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,12 @@ void BufferedPaintProvider::drawPolygon(const PointF* points, size_t pointCount,

void BufferedPaintProvider::drawText(const PointF& point, const String& text)
{
editableData().texts.push_back(DrawText { DrawText::Point, RectF(point, SizeF()), 0, text });
editableData().texts.push_back(DrawText { DrawText::Point, RectF(point, SizeF()), {}, {}, text });
}

void BufferedPaintProvider::drawText(const RectF& rect, int flags, const String& text)
void BufferedPaintProvider::drawText(const RectF& rect, Alignment alignment, TextFlags textFlags, const String& text)
{
editableData().texts.push_back(DrawText { DrawText::Rect, rect, flags, text });
editableData().texts.push_back(DrawText { DrawText::Rect, rect, alignment, textFlags, text });
}

void BufferedPaintProvider::drawSymbol(const PointF& point, char32_t ucs4Code)
Expand Down
8 changes: 3 additions & 5 deletions framework/draw/bufferedpaintprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef MUSE_DRAW_BUFFEREDPAINTPROVIDER_H
#define MUSE_DRAW_BUFFEREDPAINTPROVIDER_H

#pragma once

#include "ipaintprovider.h"
#include "types/drawdata.h"
Expand Down Expand Up @@ -71,7 +71,7 @@ class BufferedPaintProvider : public IPaintProvider
void drawPolygon(const PointF* points, size_t pointCount, PolygonMode mode) override;

void drawText(const PointF& point, const String& text) override;
void drawText(const RectF& rect, int flags, const String& text) override;
void drawText(const RectF& rect, Alignment alignment, TextFlags textFlags, const String& text) override;

void drawSymbol(const PointF& point, char32_t ucs4Code) override;

Expand Down Expand Up @@ -115,5 +115,3 @@ class BufferedPaintProvider : public IPaintProvider
DrawObjectsLogger* m_drawObjectsLogger = nullptr;
};
}

#endif // MUSE_DRAW_BUFFEREDPAINTPROVIDER_H
5 changes: 3 additions & 2 deletions framework/draw/internal/qpainterprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,10 @@ void QPainterProvider::drawText(const PointF& point, const String& text)
m_painter->drawText(p, t);
}

void QPainterProvider::drawText(const RectF& rect, int flags, const String& text)
void QPainterProvider::drawText(const RectF& rect, Alignment alignment, TextFlags textFlags, const String& text)
{
m_painter->drawText(rect.toQRectF(), flags, text);
int flags = static_cast<int>(alignment) | static_cast<int>(textFlags);
m_painter->drawText(rect.toQRectF(), flags, text.toQString());
}

void QPainterProvider::drawSymbol(const PointF& point, char32_t ucs4Code)
Expand Down
2 changes: 1 addition & 1 deletion framework/draw/internal/qpainterprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class QPainterProvider : public IPaintProvider
void drawPolygon(const PointF* points, size_t pointCount, PolygonMode mode) override;

void drawText(const PointF& point, const String& text) override;
void drawText(const RectF& rect, int flags, const String& text) override;
void drawText(const RectF& rect, Alignment alignment, TextFlags textFlags, const String& text) override;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to add a new method here...
and then delete the old one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... but I got the corresponding MSS PR already ready: musescore/MuseScore#33504

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can try to merge them quickly!

But it's better to go with compatibility, especially in simple cases like these. Add something new, mark something old as deprecated, and remove it after syncing.


void drawSymbol(const PointF& point, char32_t ucs4Code) override;

Expand Down
8 changes: 3 additions & 5 deletions framework/draw/ipaintprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef MUSE_DRAW_IPAINTPROVIDER_H
#define MUSE_DRAW_IPAINTPROVIDER_H

#pragma once

#include <memory>

Expand Down Expand Up @@ -75,7 +75,7 @@ class IPaintProvider
virtual void drawPolygon(const PointF* points, size_t pointCount, PolygonMode mode) = 0;

virtual void drawText(const PointF& point, const String& text) = 0;
virtual void drawText(const RectF& rect, int flags, const String& text) = 0;
virtual void drawText(const RectF& rect, Alignment alignment, TextFlags textFlags, const String& text) = 0;

virtual void drawSymbol(const PointF& point, char32_t ucs4Code) = 0;

Expand All @@ -96,5 +96,3 @@ class IPaintProvider

using IPaintProviderPtr = std::shared_ptr<IPaintProvider>;
}

#endif // MUSE_DRAW_IPAINTPROVIDER_H
6 changes: 3 additions & 3 deletions framework/draw/painter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,13 +444,13 @@ void Painter::drawText(const PointF& point, const String& text)
}
}

void Painter::drawText(const RectF& rect, int flags, const String& text)
void Painter::drawText(const RectF& rect, Alignment alignment, TextFlags textFlags, const String& text)
{
applyFontSizeScaling();

m_provider->drawText(rect, flags, text);
m_provider->drawText(rect, alignment, textFlags, text);
if (extended) {
extended->drawText(rect, flags, text);
extended->drawText(rect, alignment, textFlags, text);
}
}

Expand Down
3 changes: 2 additions & 1 deletion framework/draw/painter.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#pragma once

#include <stack>
Expand Down Expand Up @@ -131,7 +132,7 @@ class Painter
void drawText(const PointF& point, const String& text);
inline void drawText(double x, double y, const String& text);

void drawText(const RectF& rect, int flags, const String& text);
void drawText(const RectF& rect, Alignment alignment, TextFlags textFlags, const String& text);

void drawSymbol(const PointF& point, char32_t ucs4Code);

Expand Down
10 changes: 5 additions & 5 deletions framework/draw/types/drawdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef MUSE_DRAW_BUFFEREDDRAWTYPES_H
#define MUSE_DRAW_BUFFEREDDRAWTYPES_H

#pragma once

#include <memory>

Expand Down Expand Up @@ -81,11 +81,12 @@ struct DrawText {

Mode mode = Mode::Undefined;
RectF rect; // If mode is Point when use topLeft point
int flags = 0;
Alignment alignment = {};
TextFlags textFlags = {};
String text;
bool operator==(const DrawText& o) const
{
return mode == o.mode && flags == o.flags && rect == o.rect && text == o.text;
return mode == o.mode && alignment == o.alignment && textFlags == o.textFlags && rect == o.rect && text == o.text;
}

bool operator!=(const DrawText& o) const { return !this->operator==(o); }
Expand Down Expand Up @@ -175,4 +176,3 @@ struct Diff {
}
};
}
#endif // MUSE_DRAW_BUFFEREDDRAWTYPES_H
11 changes: 7 additions & 4 deletions framework/draw/types/drawtypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef MUSE_DRAW_DRAWTYPES_H
#define MUSE_DRAW_DRAWTYPES_H

#pragma once

#include "global/types/flags.h"

Expand Down Expand Up @@ -86,6 +86,7 @@ enum class FillRule {
WindingFill
};

// Keep in sync with Qt::AlignmentFlag (https://doc.qt.io/qt-6/qt.html#AlignmentFlag-enum)
enum AlignmentFlag {
AlignLeft = 0x0001,
AlignLeading = AlignLeft,
Expand All @@ -112,6 +113,7 @@ enum AlignmentFlag {
DECLARE_FLAGS(Alignment, AlignmentFlag)
DECLARE_OPERATORS_FOR_FLAGS(Alignment)

// Keep in sync with Qt::TextFlag (https://doc.qt.io/qt-6/qt.html#TextFlag-enum)
enum TextFlag {
TextSingleLine = 0x0100,
TextDontClip = 0x0200,
Expand All @@ -129,6 +131,7 @@ enum TextFlag {
// size of a multi-variant string.
TextLongestVariant = 0x80000
};
}

#endif // MUSE_DRAW_DRAWTYPES_H
DECLARE_FLAGS(TextFlags, TextFlag)
DECLARE_OPERATORS_FOR_FLAGS(TextFlags)
}
6 changes: 5 additions & 1 deletion framework/draw/utils/drawdatacomp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,11 @@ static bool isEqual(const DrawText& v1, const DrawText& v2, DrawDataComp::Tolera
return false;
}

if (v1.flags != v2.flags) {
if (v1.alignment != v2.alignment) {
return false;
}

if (v1.textFlags != v2.textFlags) {
return false;
}

Expand Down
6 changes: 4 additions & 2 deletions framework/draw/utils/drawdatajson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ static JsonObject toObj(const DrawText& text)
} else {
o["rect"] = toArr(text.rect);
}
o["flags"] = text.flags;
o["alignment"] = static_cast<int>(text.alignment);
o["textFlags"] = static_cast<int>(text.textFlags);
o["text"] = text.text;
return o;
}
Expand All @@ -334,7 +335,8 @@ static void fromObj(const JsonObject& obj, DrawText& text)
fromArr(obj["rect"].toArray(), text.rect);
text.mode = DrawText::Rect;
}
text.flags = obj["flags"].toInt();
text.alignment = static_cast<Alignment>(obj["alignment"].toInt());
text.textFlags = static_cast<TextFlags>(obj["textFlags"].toInt());
Comment on lines +338 to +339
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Add legacy flags fallback in DrawText deserialization.

Line 338-339 only reads alignment and textFlags; older JSON containing only flags will silently deserialize with zeroed layout flags.

💡 Proposed compatibility fix
-    text.alignment = static_cast<Alignment>(obj["alignment"].toInt());
-    text.textFlags = static_cast<TextFlags>(obj["textFlags"].toInt());
+    const int legacyFlags = obj.value("flags").toInt();
+    text.alignment = obj.contains("alignment")
+            ? static_cast<Alignment>(obj.value("alignment").toInt())
+            : static_cast<Alignment>(legacyFlags);
+    text.textFlags = obj.contains("textFlags")
+            ? static_cast<TextFlags>(obj.value("textFlags").toInt())
+            : static_cast<TextFlags>(legacyFlags);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
text.alignment = static_cast<Alignment>(obj["alignment"].toInt());
text.textFlags = static_cast<TextFlags>(obj["textFlags"].toInt());
const int legacyFlags = obj.value("flags").toInt();
text.alignment = obj.contains("alignment")
? static_cast<Alignment>(obj.value("alignment").toInt())
: static_cast<Alignment>(legacyFlags);
text.textFlags = obj.contains("textFlags")
? static_cast<TextFlags>(obj.value("textFlags").toInt())
: static_cast<TextFlags>(legacyFlags);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@framework/draw/utils/drawdatajson.cpp` around lines 338 - 339, The
deserializer currently assigns text.alignment and text.textFlags only from
obj["alignment"] and obj["textFlags"], losing legacy values stored under a
single "flags" field; update the DrawText deserialization to detect a legacy
obj.contains("flags") and, when present and alignment/textFlags keys are
missing, read int flags = obj["flags"].toInt() and decompose that value into the
appropriate Alignment and TextFlags bits before assigning text.alignment and
text.textFlags (use the same bit masks/enum mapping used elsewhere for these
enums to ensure compatibility).

text.text = obj["text"].toString();
}

Expand Down
2 changes: 1 addition & 1 deletion framework/draw/utils/drawdatapaint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static void drawItem(IPaintProviderPtr& provider, const DrawData::Item& item, co
if (t.mode == DrawText::Point) {
provider->drawText(t.rect.topLeft(), t.text);
} else {
provider->drawText(t.rect, t.flags, t.text);
provider->drawText(t.rect, t.alignment, t.textFlags, t.text);
}
}

Expand Down
4 changes: 1 addition & 3 deletions framework/testflow/internal/draw/abpaintprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
static const QColor REMOVED_COLOR("#cc0000");
static const QColor ADDED_COLOR("#009900");

static const std::string NOTATION_DEFAULT_OBJ("notationview_default");

using namespace muse::testflow;

const std::shared_ptr<AbPaintProvider>& AbPaintProvider::instance()
Expand Down Expand Up @@ -99,7 +97,7 @@ void AbPaintProvider::paintData(muse::draw::IPaintProviderPtr provider, const mu
if (t.mode == DrawText::Point) {
provider->drawText(t.rect.topLeft(), t.text);
} else {
provider->drawText(t.rect, t.flags, t.text);
provider->drawText(t.rect, t.alignment, t.textFlags, t.text);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void AbstractTableViewModel::insertRow(int row, const QVector<TableViewCell*>& c

endResetModel();

QTimer::singleShot(100, [=](){
QTimer::singleShot(100, [this, row](){
m_selectionModel->select(index(row, 0));
});
}
Expand All @@ -154,7 +154,7 @@ void AbstractTableViewModel::removeRow(int row)
emit m_selectionModel->selectionChanged(selectionItem, selectionItem);

if (isRowValid(row)) {
QTimer::singleShot(100, [=](){
QTimer::singleShot(100, [this, row](){
m_selectionModel->select(index(row, 0));
});
}
Expand Down