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
2 changes: 2 additions & 0 deletions src/engraving/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ target_sources(engraving PRIVATE
editing/edit.cpp
editing/editbrackets.cpp
editing/editbrackets.h
editing/editcapo.cpp
editing/editcapo.h
editing/editchord.cpp
editing/editchord.h
editing/editclef.cpp
Expand Down
113 changes: 60 additions & 53 deletions src/engraving/dom/chord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,28 @@ using namespace mu;
using namespace mu::engraving;

namespace mu::engraving {
NoteParenthesisInfo::NoteParenthesisInfo (Parenthesis* lParen, Parenthesis* rParen, std::vector<Note*> nList)
: m_leftParen(lParen), m_rightParen(rParen), m_notes(nList)
{
std::sort(m_notes.begin(), m_notes.end(), noteIsBefore);
}

NoteParenthesisInfo::~NoteParenthesisInfo()
{
delete m_leftParen;
delete m_rightParen;
}

void NoteParenthesisInfo::insertNote(Note* note)
{
m_notes.insert(std::upper_bound(m_notes.begin(), m_notes.end(), note, noteIsBefore), note);
}

void NoteParenthesisInfo::removeNote(Note* note)
{
muse::remove(m_notes, note);
}

//---------------------------------------------------------
// upNote
//---------------------------------------------------------
Expand Down Expand Up @@ -373,26 +395,26 @@ Chord::Chord(const Chord& c, bool link)
}
}

if (!c.noteParens().empty()) {
for (const NoteParenthesisInfo& info : c.noteParens()) {
Parenthesis* newLeftParen = toParenthesis(info.leftParen->clone());
if (!c.noteParentheses().empty()) {
for (const NoteParenthesisInfo* info : c.noteParentheses()) {
Parenthesis* newLeftParen = toParenthesis(info->leftParen()->clone());
newLeftParen->setParent(this);
Parenthesis* newRightParen = toParenthesis(info.rightParen->clone());
Parenthesis* newRightParen = toParenthesis(info->rightParen()->clone());
newRightParen->setParent(this);

if (link && !info.leftParen->generated()) {
score()->undo(new Link(newLeftParen, info.leftParen));
if (link && !info->leftParen()->generated()) {
score()->undo(new Link(newLeftParen, info->leftParen()));
}
if (link && !info.rightParen->generated()) {
score()->undo(new Link(newRightParen, info.rightParen));
if (link && !info->rightParen()->generated()) {
score()->undo(new Link(newRightParen, info->rightParen()));
}

std::vector<Note*> newNotes;
for (Note* note : info.notes) {
for (Note* note : info->notes()) {
newNotes.push_back(findNote(note->pitch()));
}

m_noteParens.push_back(NoteParenthesisInfo(newLeftParen, newRightParen, newNotes));
m_noteParens.push_back(new NoteParenthesisInfo(newLeftParen, newRightParen, newNotes));
}
}
}
Expand Down Expand Up @@ -453,6 +475,7 @@ Chord::~Chord()
muse::DeleteAll(m_ledgerLines);
muse::DeleteAll(m_graceNotes);
muse::DeleteAll(m_notes);
muse::DeleteAll(m_noteParens);
}

#ifndef ENGRAVING_NO_ACCESSIBILITY
Expand Down Expand Up @@ -1294,97 +1317,81 @@ void Chord::scanElements(std::function<void(EngravingItem*)> func)
}

for (auto& p : m_noteParens) {
p.leftParen->scanElements(func);
p.rightParen->scanElements(func);
p->leftParen()->scanElements(func);
p->rightParen()->scanElements(func);
}
ChordRest::scanElements(func);
}

const NoteParenthesisInfo* Chord::findNoteParenInfo(const Parenthesis* paren) const
NoteParenthesisInfo* Chord::findNoteParenthesisInfo(const Parenthesis* paren)
{
for (NoteParenthesisInfoList::const_iterator it = m_noteParens.begin(); it != m_noteParens.end(); ++it) {
const NoteParenthesisInfo& noteParenInfo = *it;
if (paren == noteParenInfo.leftParen || paren == noteParenInfo.rightParen) {
return &noteParenInfo;
for (NoteParenthesisInfo* infoPtr : m_noteParens) {
if (paren == infoPtr->leftParen() || paren == infoPtr->rightParen()) {
return infoPtr;
}
}

return nullptr;
}

NoteParenthesisInfo* Chord::findNoteParenInfo(const Parenthesis* paren)
const NoteParenthesisInfo* Chord::findNoteParenthesisInfo(const Note* note) const
{
for (NoteParenthesisInfoList::iterator it = m_noteParens.begin(); it != m_noteParens.end(); ++it) {
NoteParenthesisInfo& noteParenInfo = *it;
if (paren == noteParenInfo.leftParen || paren == noteParenInfo.rightParen) {
return &noteParenInfo;
}
}

return nullptr;
}

const NoteParenthesisInfo* Chord::findNoteParenInfo(const Note* note) const
{
for (NoteParenthesisInfoList::const_iterator it = m_noteParens.begin(); it != m_noteParens.end(); ++it) {
const NoteParenthesisInfo& noteParenInfo = *it;
for (const Note* parenNote : noteParenInfo.notes) {
for (const NoteParenthesisInfo* infoPtr : m_noteParens) {
for (const Note* parenNote : infoPtr->notes()) {
if (parenNote == note) {
return &noteParenInfo;
return infoPtr;
}
}
}

DO_ASSERT(u"Parentheses are not in chord");

return nullptr;
}

void Chord::addNoteParenInfo(Parenthesis* leftParen, Parenthesis* rightParen, std::vector<Note*> notes)
void Chord::addNoteParenthesisInfo(NoteParenthesisInfo* noteParenInfo)
{
m_noteParens.emplace_back(NoteParenthesisInfo(leftParen, rightParen, notes));
m_noteParens.push_back(noteParenInfo);
}

void Chord::removeNoteParenInfo(const NoteParenthesisInfo* noteParenInfo)
void Chord::removeNoteParenthesisInfo(const NoteParenthesisInfo* noteParenInfo)
{
if (m_noteParens.empty()) {
return;
}

Parenthesis* paren = noteParenInfo->leftParen;
if (!noteParenInfo) {
return;
}

NoteParenthesisInfoList::iterator itToRemove = m_noteParens.end();
auto it = std::find_if(m_noteParens.begin(), m_noteParens.end(), [noteParenInfo](const NoteParenthesisInfo* ptr) {
return ptr == noteParenInfo;
});

for (NoteParenthesisInfoList::iterator it = m_noteParens.begin(); it != m_noteParens.end(); ++it) {
NoteParenthesisInfo& info = *it;
if (paren == info.leftParen) {
itToRemove = it;
}
if (it != m_noteParens.end()) {
m_noteParens.erase(it);
}

m_noteParens.erase(itToRemove);
}

void Chord::addNoteToParenInfo(Note* note, const Parenthesis* paren)
void Chord::addNoteToParenthesisInfo(Note* note, const Parenthesis* paren)
{
NoteParenthesisInfo* noteParenInfo = findNoteParenInfo(paren);
NoteParenthesisInfo* noteParenInfo = findNoteParenthesisInfo(paren);

if (!noteParenInfo) {
return;
}

noteParenInfo->notes.push_back(note);
noteParenInfo->insertNote(note);
}

void Chord::removeNoteFromParenInfo(Note* note, const Parenthesis* paren)
void Chord::removeNoteFromParenthesisInfo(Note* note, const Parenthesis* paren)
{
NoteParenthesisInfo* noteParenInfo = findNoteParenInfo(paren);
NoteParenthesisInfo* noteParenInfo = findNoteParenthesisInfo(paren);

if (!noteParenInfo) {
return;
}

muse::remove(noteParenInfo->notes, note);
noteParenInfo->removeNote(note);
}

//---------------------------------------------------------
Expand Down
36 changes: 21 additions & 15 deletions src/engraving/dom/chord.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,22 @@ class GraceNotesGroup final : public std::vector<Chord*>, public EngravingItem
//---------------------------------------------------------

struct NoteParenthesisInfo {
NoteParenthesisInfo (Parenthesis* lParen, Parenthesis* rParen, std::vector<Note*> nList)
: leftParen(lParen), rightParen(rParen), notes(nList) {}
NoteParenthesisInfo() {}
Parenthesis* leftParen = nullptr;
Parenthesis* rightParen = nullptr;
std::vector<Note*> notes;
NoteParenthesisInfo (Parenthesis* lParen, Parenthesis* rParen, std::vector<Note*> nList);
~NoteParenthesisInfo();
Parenthesis* leftParen() const { return m_leftParen; }
Parenthesis* rightParen() const { return m_rightParen; }
const std::vector<Note*>& notes() const { return m_notes; }

void insertNote(Note* note);
void removeNote(Note* note);

private:
Parenthesis* m_leftParen = nullptr;
Parenthesis* m_rightParen = nullptr;
std::vector<Note*> m_notes;
};

using NoteParenthesisInfoList = std::vector<NoteParenthesisInfo>;
using NoteParenthesisInfoList = std::vector<NoteParenthesisInfo*>;

class Chord final : public ChordRest
{
Expand Down Expand Up @@ -170,14 +177,13 @@ class Chord final : public ChordRest
std::vector<Note*>& notes() { return m_notes; }
const std::vector<Note*>& notes() const { return m_notes; }

const NoteParenthesisInfoList& noteParens() const { return m_noteParens; }
const NoteParenthesisInfo* findNoteParenInfo(const Note* note) const;
const NoteParenthesisInfo* findNoteParenInfo(const Parenthesis* paren) const;
NoteParenthesisInfo* findNoteParenInfo(const Parenthesis* paren);
void addNoteParenInfo(Parenthesis* leftParen, Parenthesis* rightParen, std::vector<Note*> notes);
void removeNoteParenInfo(const NoteParenthesisInfo* noteParenInfo);
void addNoteToParenInfo(Note* note, const Parenthesis* paren);
void removeNoteFromParenInfo(Note* note, const Parenthesis* paren);
const NoteParenthesisInfoList& noteParentheses() const { return m_noteParens; }
const NoteParenthesisInfo* findNoteParenthesisInfo(const Note* note) const;
NoteParenthesisInfo* findNoteParenthesisInfo(const Parenthesis* paren);
void addNoteParenthesisInfo(NoteParenthesisInfo* noteParenInfo);
void removeNoteParenthesisInfo(const NoteParenthesisInfo* noteParenInfo);
void addNoteToParenthesisInfo(Note* note, const Parenthesis* paren);
void removeNoteFromParenthesisInfo(Note* note, const Parenthesis* paren);

bool isChordPlayable() const;
void setIsChordPlayable(const bool isPlayable);
Expand Down
2 changes: 0 additions & 2 deletions src/engraving/dom/dom.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ set(DOM_SRC
${CMAKE_CURRENT_LIST_DIR}/dynamichairpingroup.h
${CMAKE_CURRENT_LIST_DIR}/easeInOut.cpp
${CMAKE_CURRENT_LIST_DIR}/easeInOut.h
${CMAKE_CURRENT_LIST_DIR}/editcapo.cpp
${CMAKE_CURRENT_LIST_DIR}/editcapo.h
${CMAKE_CURRENT_LIST_DIR}/elementgroup.cpp
${CMAKE_CURRENT_LIST_DIR}/elementgroup.h
${CMAKE_CURRENT_LIST_DIR}/elementmap.cpp
Expand Down
22 changes: 11 additions & 11 deletions src/engraving/dom/note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1497,17 +1497,17 @@ bool Note::shouldForceShowFret() const
void Note::setVisible(bool v)
{
EngravingItem::setVisible(v);
if (!chord() || chord()->noteParens().empty()) {
if (!chord() || chord()->noteParentheses().empty()) {
return;
}

const NoteParenthesisInfo* noteParenInfo = chord()->findNoteParenInfo(this);
const NoteParenthesisInfo* noteParenInfo = chord()->findNoteParenthesisInfo(this);

if (!noteParenInfo) {
return;
}

const std::vector<Note*>& notes = noteParenInfo->notes;
const std::vector<Note*>& notes = noteParenInfo->notes();
bool visible = false;
for (const Note* note : notes) {
if (note->visible()) {
Expand All @@ -1516,11 +1516,11 @@ void Note::setVisible(bool v)
}
}

if (noteParenInfo->leftParen) {
noteParenInfo->leftParen->setVisible(visible);
if (noteParenInfo->leftParen()) {
noteParenInfo->leftParen()->setVisible(visible);
}
if (noteParenInfo->rightParen) {
noteParenInfo->rightParen->setVisible(visible);
if (noteParenInfo->rightParen()) {
noteParenInfo->rightParen()->setVisible(visible);
}
}

Expand Down Expand Up @@ -3949,9 +3949,9 @@ void Note::setParenthesesMode(const ParenthesesMode& v, bool addToLinked, bool g
return;
}

const NoteParenthesisInfo* noteParenInfo = parenInfo();
const NoteParenthesisInfo* noteParenInfo = parenthesisInfo();

Parenthesis* leftParen = noteParenInfo ? noteParenInfo->leftParen : nullptr;
Parenthesis* leftParen = noteParenInfo ? noteParenInfo->leftParen() : nullptr;

const bool hasGeneratedParen = leftParen && leftParen->generated();
const bool hasUserParen = leftParen && !leftParen->generated();
Expand All @@ -3975,9 +3975,9 @@ void Note::setParenthesesMode(const ParenthesesMode& v, bool addToLinked, bool g
}
}

const NoteParenthesisInfo* Note::parenInfo() const
const NoteParenthesisInfo* Note::parenthesisInfo() const
{
return chord() ? chord()->findNoteParenInfo(this) : nullptr;
return chord() ? chord()->findNoteParenthesisInfo(this) : nullptr;
}

bool Note::isGrace() const
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/dom/note.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ class Note final : public EngravingItem

void setParenthesesMode(const ParenthesesMode& v, bool addToLinked = true, bool generated = false) override;

const NoteParenthesisInfo* parenInfo() const;
const NoteParenthesisInfo* parenthesisInfo() const;

void setHarmonic(bool val) { m_harmonic = val; }
bool harmonic() const { return m_harmonic; }
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/dom/staff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#include "editing/transpose.h"
#include "utils.h"
#include "capo.h"
#include "editcapo.h"
#include "editing/editcapo.h"

// #define DEBUG_CLEFS

Expand Down
5 changes: 5 additions & 0 deletions src/engraving/dom/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1417,6 +1417,11 @@ std::unordered_set<EngravingItem*> collectElementsAnchoredToNote(const Note* not
elems.emplace(sp);
}
}
const NoteParenthesisInfo* noteParenInfo = note->parenthesisInfo();
if (noteParenInfo && noteParenInfo->notes().size()) {
elems.emplace(noteParenInfo->leftParen());
elems.emplace(noteParenInfo->rightParen());
}
return elems;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
*/

#include "editcapo.h"
#include "staff.h"
#include "note.h"
#include "stringdata.h"
#include "score.h"
#include "part.h"
#include "dom/staff.h"
#include "dom/note.h"
#include "dom/stringdata.h"
#include "dom/score.h"
#include "dom/part.h"

namespace mu::engraving {
// static
Expand Down Expand Up @@ -113,6 +113,10 @@ void EditCapo::updateNotationForCapoChange(const CapoParams& oldParams, const Ca
// ctx.stringData = nullptr;
// ctx.possibleFretConflict = false;

Score* score = staff->score();
Fraction layoutEndTick = endTick != -1 ? Fraction::fromTicks(endTick) : Fraction::max();
score->setLayout(layoutEndTick, staff->idx());

const bool modeChanged = oldParams.transposeMode != newParams.transposeMode;
const bool fretChanged = oldParams.fretPosition != newParams.fretPosition;
const bool stringsChanged = oldParams.ignoredStrings != newParams.ignoredStrings;
Expand Down
File renamed without changes.
Loading
Loading