Verovio
Source code documentation
doc.h
1 // Name: doc.h
3 // Author: Laurent Pugin
4 // Created: 2005
5 // Copyright (c) Authors and others. All rights reserved.
7 
8 #ifndef __VRV_DOC_H__
9 #define __VRV_DOC_H__
10 
11 #include "devicecontextbase.h"
12 #include "expansionmap.h"
13 #include "facsimile.h"
14 #include "options.h"
15 #include "resources.h"
16 #include "scoredef.h"
17 
18 namespace smf {
19 class MidiFile;
20 }
21 
22 namespace vrv {
23 
24 class DocSelection;
25 class PageRange;
26 class FontInfo;
27 class Glyph;
28 class Pages;
29 class Page;
30 class ScoreOrPartElement;
31 
32 enum DocType { Raw = 0, Rendering, FacTranscription };
33 
34 //----------------------------------------------------------------------------
35 // Doc
36 //----------------------------------------------------------------------------
37 
41 class Doc : public Object {
42 
43 public:
49  Doc();
50  virtual ~Doc();
51  std::string GetClassName() const override { return "body"; }
53 
57  bool IsSupportedChild(ClassId classId) override;
58 
62  void Reset() override;
63 
68 
73 
78 
83  Options *GetOptions() { return m_options; }
84  const Options *GetOptions() const { return m_options; }
85  void SetOptions(Options *options) { (*m_options) = *options; }
87 
92  const Resources &GetResources() const { return m_resources; }
93  Resources &GetResourcesForModification() { return m_resources; }
95 
101 
106 
111 
116 
121 
126 
131  DocType GetType() const { return m_type; }
132  void SetType(DocType type);
133  bool IsRaw() const { return (m_type == Raw); }
134  bool IsFacTranscription() const { return (m_type == FacTranscription); }
136 
140  bool HasPage(int pageIdx) const;
141 
149  const Pages *GetPages() const;
151 
155  int GetPageCount() const;
156 
162  const ScoreDef *GetFirstScoreDef() const;
164 
170  std::list<ScoreOrPartElement *> GetVisibleScoresOrParts();
171  ScoreOrPartElement *GetFirstVisibleScoreOrPart();
173 
179  const ScoreOrPartElement *GetCorrespondingScoreOrPart(const Object *object) const;
180  // Generic version that does not necessarily rely on precalculated visible scores
182  const Object *object, const std::list<ScoreOrPartElement *> &scores);
184  const Object *object, const std::list<ScoreOrPartElement *> &scores) const;
186 
190  void CollectReferringObjects(const Object *element, std::set<std::string> &referring, SetOfConstObjects &visited);
191 
195  bool GetMidiExportDone() const;
196 
201  int GetGlyphHeight(char32_t code, int staffSize, bool graceSize, const std::string &fontName = "") const;
202  int GetGlyphWidth(char32_t code, int staffSize, bool graceSize, const std::string &fontName = "") const;
203  int GetGlyphLeft(char32_t code, int staffSize, bool graceSize, const std::string &fontName = "") const;
204  int GetGlyphRight(char32_t code, int staffSize, bool graceSize, const std::string &fontName = "") const;
205  int GetGlyphBottom(char32_t code, int staffSize, bool graceSize, const std::string &fontName = "") const;
206  int GetGlyphTop(char32_t code, int staffSize, bool graceSize, const std::string &fontName = "") const;
207  int GetGlyphAdvX(char32_t code, int staffSize, bool graceSize, const std::string &fontName = "") const;
208  int GetDrawingUnit(int staffSize) const;
209  int GetDrawingDoubleUnit(int staffSize) const;
210  int GetDrawingStaffSize(int staffSize) const;
211  int GetDrawingOctaveSize(int staffSize) const;
212  int GetDrawingBrevisWidth(int staffSize) const;
213  int GetDrawingBarLineWidth(int staffSize) const;
214  int GetDrawingStaffLineWidth(int staffSize) const;
215  int GetDrawingStemWidth(int staffSize) const;
216  int GetDrawingDirHeight(int staffSize, bool withMargin) const;
217  int GetDrawingDynamHeight(int staffSize, bool withMargin) const;
218  int GetDrawingHairpinSize(int staffSize, bool withMargin) const;
219  int GetDrawingBeamWidth(int staffSize, bool graceSize) const;
220  int GetDrawingBeamWhiteWidth(int staffSize, bool graceSize) const;
221  int GetDrawingLedgerLineExtension(int staffSize, bool graceSize) const;
222  int GetDrawingMinimalLedgerLineExtension(int staffSize, bool graceSize) const;
223  int GetCueSize(int value) const;
224  double GetCueScaling() const;
226 
227  Point ConvertFontPoint(const Glyph *glyph, const Point &fontPoint, int staffSize, bool graceSize) const;
228 
234  int GetTextGlyphHeight(char32_t code, const FontInfo *font, bool graceSize) const;
235  int GetTextGlyphWidth(char32_t code, const FontInfo *font, bool graceSize) const;
236  int GetTextGlyphAdvX(char32_t code, const FontInfo *font, bool graceSize) const;
237  int GetTextGlyphDescender(char32_t code, const FontInfo *font, bool graceSize) const;
238  int GetTextLineHeight(const FontInfo *font, bool graceSize) const;
239  int GetTextXHeight(const FontInfo *font, bool graceSize) const;
241 
247  FontInfo *GetDrawingSmuflFont(int staffSize, bool graceSize, const std::string &fontName = "");
248  FontInfo *GetDrawingLyricFont(int staffSize);
249  FontInfo GetDrawingTextFont(int staffSize, const ScoreDefInterface *style, bool lyric = false);
250  FontInfo *GetFingeringFont(int staffSize);
252 
256  void ApplyTypography(FontInfo &font, const AttTypography *typography, int staffSize) const;
257 
263 
269  double GetLeftMargin(const ClassId classId) const;
270  double GetLeftMargin(const Object *object) const;
271  double GetRightMargin(const ClassId classId) const;
272  double GetRightMargin(const Object *object) const;
273  double GetLeftPosition() const;
274  double GetBottomMargin(const ClassId classId) const;
275  double GetTopMargin(const ClassId classId) const;
277 
282  data_MEASUREMENTSIGNED GetStaffDistance(const Object *object, int staffIndex, data_STAFFREL staffPosition) const;
283 
289 
295  bool HasTimemap() const;
296 
303  void ExportMIDI(smf::MidiFile *midiFile, std::string *midiJson = NULL);
304 
309  bool ExportTimemap(std::string &output, bool includeRests, bool includeMeasures, bool useFractions);
310 
314  bool ExportExpansionMap(std::string &output);
315 
319  bool ExportFeatures(std::string &output, const std::string &options);
320 
327  void ScoreDefSetCurrentDoc(bool force = false);
328 
333 
338 
344  void PrepareData();
345 
350  void CastOffDoc();
351 
357 
363 
370  void CastOffDocBase(bool useSb, bool usePb, bool smart = false);
371 
376  void UnCastOffDoc(bool resetCache = true);
377 
383 
390 
396  void ConvertToCastOffMensuralDoc(MensuralCastOffType castOff);
397 
402 
408  void ConvertMarkupDoc(bool permanent = true);
409 
413  void ScoringUpDoc();
414 
415  /*
416  * Convert the doc from mensural to a flattened version with no ligatures and the selected editorial markup.
417  */
418  void ConvertToMensuralViewDoc();
419 
424 
430 
436 
440  void TransposeDoc();
441 
446 
453  Page *SetDrawingPage(int pageIdx, bool withPageRange = false);
454 
459 
466  void ResetDataPage() { m_drawingPage = NULL; }
467 
474  Page *GetDrawingPage() { return m_drawingPage; }
475  const Page *GetDrawingPage() const { return m_drawingPage; }
477 
481  bool CheckPageSize(const Page *page) const;
482 
488 
494 
500  void SetMarkup(int markup) { m_markup |= markup; }
501 
506  void SetMensuralMusicOnly(data_BOOLEAN isMensuralMusicOnly);
507  bool IsMensuralMusicOnly() const { return (m_isMensuralMusicOnly == BOOLEAN_true); }
509 
514  void SetNeumeLines(bool isNeumeLines) { m_isNeumeLines = isNeumeLines; }
515  bool IsNeumeLines() const { return m_isNeumeLines; }
517 
522  void SetFacsimile(Facsimile *facsimile) { m_facsimile = facsimile; }
523  Facsimile *GetFacsimile() { return m_facsimile; }
524  const Facsimile *GetFacsimile() const { return m_facsimile; }
525  bool HasFacsimile() const { return m_facsimile != NULL; }
527 
531  bool IsCastOff() const { return m_isCastOff; }
532 
537  {
538  m_isCastOff = true;
539  m_mensuralCastOff = this->IsMensuralMusicOnly();
540  }
541 
546  void InitSelectionDoc(DocSelection &selection, bool resetCache);
547  void ResetSelectionDoc(bool resetCache);
548  bool HasSelection() const;
555  void ReactivateSelection(bool resetAligners);
557 
562 
566  void SetFocus();
567 
568  //----------//
569  // Functors //
570  //----------//
571 
576  FunctorCode Accept(Functor &functor) override;
577  FunctorCode Accept(ConstFunctor &functor) const override;
578  FunctorCode AcceptEnd(Functor &functor) override;
579  FunctorCode AcceptEnd(ConstFunctor &functor) const override;
581 
582 private:
586  int CalcMusicFontSize();
587 
591  const Glyph *GetMusicGlyph(char32_t code, const std::string &fontName) const;
592 
596  void PrepareMeasureIndices();
597 
601  void CollectVisibleScoresOrParts();
602 
606  void ResetFocus();
607 
608 public:
609  Page *m_selectionPreceding;
610  Page *m_selectionFollowing;
611  std::string m_selectionStart;
612  std::string m_selectionEnd;
613 
618 
622  pugi::xml_document m_header;
623 
627  pugi::xml_document m_front;
628 
632  pugi::xml_document m_back;
633 
637  std::string m_musicDecls;
638 
657 
662  data_NOTATIONTYPE m_notationType;
663 
666 
667 private:
673  DocType m_type;
674 
679  Options *m_options;
680 
684  Resources m_resources;
685 
690  std::list<ScoreOrPartElement *> m_visibleScoresOrParts;
691 
695  bool m_isCastOff;
696 
700  FocusStatusType m_focusStatus;
701 
702  /*
703  * The following values are set in the Doc::SetDrawingPage.
704  * They are all current values to be used when drawing a page in a View and
705  * reset for every page. However, most of them are based on the m_staffDefin values
706  * and will remain the same. This can be optimized.
707  * The pages dimensions and margins are based on the page ones, the document ones or
708  * the default in the following order and if available.
709  */
710 
712  Page *m_drawingPage;
714  int m_drawingBeamWidth;
716  int m_drawingBeamWhiteWidth;
718  int m_drawingBrevisWidth;
719 
721  int m_drawingSmuflFontSize;
723  int m_drawingLyricFontSize;
725  int m_fingeringFontSize;
727  FontInfo m_drawingSmuflFont;
729  FontInfo m_drawingLyricFont;
731  FontInfo m_fingeringFont;
732 
738  bool m_currentScoreDefDone;
739 
744  bool m_dataPreparationDone;
745 
751  double m_timemapTempo;
752 
758  int m_markup;
759 
765  data_BOOLEAN m_isMensuralMusicOnly;
766 
770  bool m_mensuralCastOff;
771 
776  bool m_isNeumeLines;
777 
779  int m_pageWidth;
781  int m_pageHeight;
783  int m_pageMarginBottom;
785  int m_pageMarginLeft;
787  int m_pageMarginRight;
789  int m_pageMarginTop;
790 
792  Facsimile *m_facsimile;
793 };
794 
795 } // namespace vrv
796 
797 #endif
This abstract class is the base class for all const functors.
Definition: functor.h:126
This class is a hold the data and corresponds to the model of a MVC design pattern.
Definition: doc.h:41
void ScoringUpDoc()
Calls the scoringUpFunctor and applies it.
int m_drawingPageMarginTop
The current page top margin.
Definition: doc.h:654
void ResetDataPage()
Reset drawing page to NULL.
Definition: doc.h:466
float m_drawingBeamMaxSlope
the current beam maximal slope
Definition: doc.h:656
Page * SetDrawingPage(int pageIdx, bool withPageRange=false)
Set drawing values (page size, etc) when drawing a page.
void CalculateTimemap()
Prepare the timemap for MIDI and timemap file export.
void ApplyTypography(FontInfo &font, const AttTypography *typography, int staffSize) const
Apply the typography attributes (font family, size, style, weight, and letter spacing) to a font.
void CastOffEncodingDoc()
Cast off of the entire document according to the encoded data (pb and sb).
void ConvertToPageBasedDoc()
Convert the doc from score-based to page-based MEI.
void UpdatePageDrawingSizes()
Update the drawing page sizes when a page is set as drawing page.
bool IsSupportedChild(ClassId classId) override
Add a page to the document.
DocType GetType() const
Getter and setter for the DocType.
Definition: doc.h:131
int GetPageCount() const
Get the total page count.
void ConvertMensuralToCmnDoc()
Convert the doc from mensural to CMN.
void ConvertMarkupDoc(bool permanent=true)
Convert analytical encoding (@fermata, @tie) to correpsonding elements By default,...
int GetAdjustedDrawingPageHeight() const
Return the height adjusted to the content of the current drawing page.
void TransposeDoc()
Transpose the content of the doc.
pugi::xml_document m_header
A copy of the header tree stored as pugi::xml_document.
Definition: doc.h:622
int m_drawingPageMarginLeft
The current page left margin.
Definition: doc.h:650
int m_drawingPageContentWidth
The current page content width (without margins)
Definition: doc.h:646
void ConvertToCmnDoc()
Convert mensural MEI into CMN measure-based MEI.
void CastOffLineDoc()
Casts off the entire document, using the document's line breaks, but adding its own page breaks.
const Resources & GetResources() const
Getter for the resources.
Definition: doc.h:92
void SyncFromFacsimileDoc()
Sync the coordinate provided trought <facsimile> to m_drawingFacsX/Y.
std::list< ScoreOrPartElement * > GetVisibleScoresOrParts()
Get all visible scores or parts / the first visible score or part Lazily updates the visible scores o...
bool IsCastOff() const
Return true if the document has been cast off already.
Definition: doc.h:531
void ResetToLoading()
Reset to the loading state (unset the scoreDef)
void GenerateFooter()
Generate a document pgFoot if none is provided.
int m_drawingPageWidth
The current page width.
Definition: doc.h:642
void ScoreDefOptimizeDoc()
Optimize the scoreDef once the document is cast-off.
void CastOffDocBase(bool useSb, bool usePb, bool smart=false)
Casts off the entire document, with options for obeying breaks.
void GenerateHeader()
Generate a document pgHead from the MEI header if none is provided.
void ExpandExpansions()
Convert encoded <expansion> before rendering.
bool ExportFeatures(std::string &output, const std::string &options)
Extract music features to JSON string.
void ScoreDefSetGrpSymDoc()
Set the GrpSym start / end for each System once ScoreDef is set and (if necessary) optimized.
int GetAdjustedDrawingPageWidth() const
Return the width adjusted to the content of the current drawing page.
ExpansionMap m_expansionMap
An expansion map that contains
Definition: doc.h:665
void UnCastOffDoc(bool resetCache=true)
Undo the cast off of the entire document.
std::string m_musicDecls
The music@decls value.
Definition: doc.h:637
void ClearSelectionPages()
Clear the selection pages.
data_MEASUREMENTSIGNED GetStaffDistance(const Object *object, int staffIndex, data_STAFFREL staffPosition) const
Get the default distance from the staff for the object The distance is given in x * MEI UNIT.
void PrepareData()
Prepare the document data.
int m_drawingPageMarginRight
The current page right margin.
Definition: doc.h:652
void RefreshLayout()
Refresh the layout of all pages in the doc.
PageRange * m_focusRange
A page range (owned object) with focus in the document.
Definition: doc.h:617
void Reset() override
Clear the content of the document.
bool HasPage(int pageIdx) const
Check if the document has a page with the specified value.
void CastOffDoc()
Casts off the entire document.
void CollectReferringObjects(const Object *element, std::set< std::string > &referring, SetOfConstObjects &visited)
Collect the IDs of all objects referring to the element or one of its descendants.
bool ExportTimemap(std::string &output, bool includeRests, bool includeMeasures, bool useFractions)
Extract a timemap from the document to a JSON string.
FunctorCode Accept(Functor &functor) override
Interface for class functor visitation.
bool GenerateMeasureNumbers()
Generate measure numbers from measure attributes.
bool GetMidiExportDone() const
Return true if the MIDI generation is already done.
void ResetToSerialization()
Reset the document for loading a serialization.
void GenerateMEIHeader()
Generate a minimal MEI header.
pugi::xml_document m_back
A copy of the back tree stored as pugi::xml_document.
Definition: doc.h:632
void MarkAsCastOff()
Set the cast off flags (i.e., when loading page-based MEI).
Definition: doc.h:536
int m_drawingPageContentHeight
The current page content height (without margings)
Definition: doc.h:644
Pages * GetPages()
Get the Pages in the visible Mdiv.
ScoreOrPartElement * GetCorrespondingScoreOrPart(const Object *object)
Get the corresponding score for a node.
double GetMusicToLyricFontSizeRatio() const
Get the ratio between the lyric font size and the music font size.
data_NOTATIONTYPE m_notationType
Record notation type for document.
Definition: doc.h:662
int m_drawingPageHeight
The current page height.
Definition: doc.h:640
void ScoreDefSetCurrentDoc(bool force=false)
Set the initial scoreDef of each page.
void SyncToFacsimileDoc()
Sync the coordinate provided in rendering to a <facsimile>.
int m_drawingPageMarginBottom
The current page bottom margin.
Definition: doc.h:648
void ConvertHeaderToMEIBasic()
Convert the header to MEI Basic by preserving only the fileDesc and its titleStmt.
void SetFocus()
Reset the document focus.
bool GenerateDocumentScoreDef()
Generate a document scoreDef when none is provided.
bool HasTimemap() const
Check to see if the timemap has already been calculated.
void DeactiveateSelection()
Temporarily deactivate and reactivate selection.
Page * GetDrawingPage()
Getter to the drawPage.
Definition: doc.h:474
void ExportMIDI(smf::MidiFile *midiFile, std::string *midiJson=NULL)
Export the document to a MIDI file.
ScoreDef * GetFirstScoreDef()
Get the first scoreDef.
bool CheckPageSize(const Page *page) const
Check that the page is the drawing page or that they have no given dimensions.
void SetMarkup(int markup)
Setter for markup flag.
Definition: doc.h:500
void ConvertToCastOffMensuralDoc(MensuralCastOffType castOff)
Convert mensural MEI into cast-off (measure) segments looking at the barLine objects.
Options * GetOptions()
Getter for the options.
Definition: doc.h:83
pugi::xml_document m_front
A copy of the front tree stored as pugi::xml_document.
Definition: doc.h:627
bool ExportExpansionMap(std::string &output)
Extract expansionMap from the document to JSON string.
void CastOffSmartDoc()
Casts off the entire document, only using the document's system breaks if they would be close to the ...
This class stores a document selection.
Definition: docselection.h:24
Definition: expansionmap.h:23
Implements the facsimile element in MEI.
Definition: facsimile.h:31
This class is store font properties.
Definition: devicecontextbase.h:137
This abstract class is the base class for all mutable functors.
Definition: functor.h:101
This class is used for storing a music font glyph.
Definition: glyph.h:32
This class represents a basic object.
Definition: object.h:66
This class contains the document styling parameters.
Definition: options.h:577
This class represents a page in a laid-out score (Doc).
Definition: page.h:31
This class represent a page range not owning child pages.
Definition: pages.h:87
This class represent a <pages> in page-based MEI.
Definition: pages.h:27
Simple class for representing points.
Definition: devicecontextbase.h:203
This class provides resource values.
Definition: resources.h:33
This class represents a MEI scoreDef.
Definition: scoredef.h:136
This class is an interface for elements implementing score attributes, such as <scoreDef>,...
Definition: scoredefinterface.h:44
This class represents a <score> or a <part> in MEI.
Definition: scoreorpartelement.h:33