-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
File format: store excerpts by a unique and safe name #20210
Merged
DmitryArefiev
merged 5 commits into
musescore:master
from
cbjeukendrup:excerpts_store_by_escaped_name
Dec 11, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1af14c5
File format: store excerpts by unique and safe name
cbjeukendrup dbcabb6
Fix reading/writing excerpt notation view state
cbjeukendrup ba337fb
Fix reading excerpt notation view state if excerpt file name is not "…
cbjeukendrup 873550e
Prevent double writing of excerpt name
cbjeukendrup 8e18026
Update tests
cbjeukendrup File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,15 +127,18 @@ const String& Excerpt::name() const | |
return m_name; | ||
} | ||
|
||
void Excerpt::setName(const String& name) | ||
void Excerpt::setName(const String& name, bool saveAndNotify) | ||
{ | ||
if (m_name == name) { | ||
return; | ||
} | ||
|
||
m_name = name; | ||
writeNameToMetaTags(); | ||
m_nameChanged.notify(); | ||
|
||
if (saveAndNotify) { | ||
writeNameToMetaTags(); | ||
m_nameChanged.notify(); | ||
} | ||
} | ||
|
||
void Excerpt::writeNameToMetaTags() | ||
|
@@ -153,6 +156,59 @@ async::Notification Excerpt::nameChanged() const | |
return m_nameChanged; | ||
} | ||
|
||
const String& Excerpt::fileName() const | ||
{ | ||
IF_ASSERT_FAILED(!m_fileName.empty()) { | ||
const_cast<Excerpt*>(this)->updateFileName(); | ||
} | ||
|
||
return m_fileName; | ||
} | ||
|
||
void Excerpt::setFileName(const String& fileName) | ||
{ | ||
m_fileName = fileName; | ||
} | ||
|
||
static inline bool isValidExcerptFileNameCharacter(char16_t c) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's better to use mu::io::isAllowedFileName / io::path_t mu::io::escapeFileName |
||
{ | ||
return (u'a' <= c && c <= u'z') | ||
|| (u'A' <= c && c <= 'Z') | ||
|| (u'0' <= c && c <= '9') | ||
|| c == u'_' || c == u'-' || c == u' '; | ||
} | ||
|
||
static inline String escapeExcerptFileName(const String& name) | ||
{ | ||
String result; | ||
result.reserve(name.size()); | ||
|
||
for (const char16_t& c : name.toStdU16String()) { | ||
if (isValidExcerptFileNameCharacter(c)) { | ||
result.append(c); | ||
} else { | ||
result.append(u'_'); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
void Excerpt::updateFileName(size_t index) | ||
{ | ||
if (index == mu::nidx && m_masterScore) { | ||
index = mu::indexOf(m_masterScore->excerpts(), this); | ||
} | ||
|
||
const String escapedName = escapeExcerptFileName(m_name); | ||
|
||
if (index == mu::nidx) { | ||
m_fileName = escapedName; | ||
} else { | ||
m_fileName = String(u"%1_%2").arg(String::number(index), escapedName); | ||
} | ||
} | ||
|
||
bool Excerpt::containsPart(const Part* part) const | ||
{ | ||
for (Part* _part : m_parts) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here it aborts when opening a Mu3 score with parts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(in Debug builds only)