-
Notifications
You must be signed in to change notification settings - Fork 36
feat: replace DocumentManager with RAII MusicXml #435
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
Open
webern
wants to merge
4
commits into
main
Choose a base branch
from
m/mxdev-raii
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a48f262
feat: replace DocumentManager with RAII MusicXml (#95)
webern 24be197
feat: address review of the MusicXml design (#435)
webern 1fbd127
feat: restore getCoreDocument as a public escape hatch (#435)
webern af24e1a
docs: note getCoreDocument's reference lifetime (#435)
webern 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| // MusicXML Class Library | ||
| // Copyright (c) by Matthew James Briggs | ||
| // Distributed under the MIT License | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "mx/api/Result.h" | ||
| #include "mx/api/ScoreData.h" | ||
|
|
||
| #include <iosfwd> | ||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| namespace mx | ||
| { | ||
| namespace core | ||
| { | ||
| class Document; | ||
| } // namespace core | ||
|
|
||
| namespace api | ||
| { | ||
| // A MusicXML document, either parsed or constructed from ScoreData. | ||
| class MusicXml | ||
| { | ||
| public: | ||
| // Parses a MusicXML file. Logical errors and caught exceptions are | ||
| // represented by an error result. | ||
| static Result<MusicXml> fromFile(const std::string &filePath); | ||
|
|
||
| // Parses a MusicXML document from a character stream. Logical errors and | ||
| // caught exceptions are represented by an error result. | ||
| static Result<MusicXml> fromStream(std::istream &stream); | ||
|
|
||
| MusicXml(const MusicXml &other) = delete; | ||
| MusicXml &operator=(const MusicXml &other) = delete; | ||
| MusicXml(MusicXml &&other); | ||
| MusicXml &operator=(MusicXml &&other) noexcept; | ||
| ~MusicXml(); | ||
|
|
||
| // A deep copy of the document. | ||
| MusicXml clone() const; | ||
|
|
||
| // Writes the document to a file. Logical errors and caught exceptions | ||
| // are represented by an error result. | ||
| Result<void> writeToFile(const std::string &filePath) const; | ||
|
|
||
| // Writes the document to a character stream. | ||
| Result<void> writeToStream(std::ostream &stream) const; | ||
|
|
||
| // This is an escape hatch in case mx::api does not do what you need and | ||
| // you want to edit the core DOM directly. You will need to include the | ||
| // private mx::core headers in your header search paths to do so. Not | ||
| // recommended, try opening an issue first! | ||
| // | ||
| // The reference is only good for as long as this MusicXml is alive and | ||
| // you have not moved it away: do not keep it past a std::move of this | ||
| // object into another MusicXml or into intoScore, which destroys the | ||
| // document when it returns. | ||
| core::Document &getCoreDocument(); | ||
| const core::Document &getCoreDocument() const; | ||
|
|
||
| private: | ||
| MusicXml(); | ||
| MusicXml(core::Document document, bool writeMxVersion); | ||
| class Impl; | ||
| std::unique_ptr<Impl> myImpl; | ||
|
|
||
| friend Result<ScoreData> getScore(const MusicXml &document); | ||
| friend Result<MusicXml> fromScore(const ScoreData &score); | ||
| }; | ||
|
|
||
| // Reads the score out of the document. The document stays alive and can be | ||
| // read again or written out. | ||
| Result<ScoreData> getScore(const MusicXml &document); | ||
|
|
||
| // Reads the score out of the document and consumes it: the underlying tree | ||
| // is freed when this function returns rather than when your MusicXml binding | ||
| // goes out of scope. Pass the document with std::move, or hand over the | ||
| // Result's value directly. | ||
| Result<ScoreData> intoScore(MusicXml document); | ||
|
|
||
| // Authors a new document from ScoreData. Fails with an error result when the | ||
| // ScoreData describes something the core model will not represent (e.g. more | ||
| // than 8 beams) rather than silently dropping data. | ||
| Result<MusicXml> fromScore(const ScoreData &score); | ||
|
|
||
| } // namespace api | ||
|
webern marked this conversation as resolved.
|
||
| } // namespace mx | ||
This file contains hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.