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 Score;
31 
32 enum DocType { Raw = 0, Rendering, Transcription, Facs };
33 
34 //----------------------------------------------------------------------------
35 // Doc
36 //----------------------------------------------------------------------------
37 
41 class Doc : public Object {
42 
43 public:
49  Doc();
50  virtual ~Doc();
52 
56  bool IsSupportedChild(ClassId classId) override;
57 
61  void Reset() override;
62 
66  void ResetToLoading();
67 
72 
77  Options *GetOptions() { return m_options; }
78  const Options *GetOptions() const { return m_options; }
79  void SetOptions(Options *options) { (*m_options) = *options; }
81 
86  const Resources &GetResources() const { return m_resources; }
87  Resources &GetResourcesForModification() { return m_resources; }
89 
95 
100 
105 
110 
115 
120 
125  DocType GetType() const { return m_type; }
126  void SetType(DocType type);
127  bool IsFacs() const { return (m_type == Facs); }
128  bool IsRaw() const { return (m_type == Raw); }
129  bool IsRendering() const { return (m_type == Rendering); }
130  bool IsTranscription() const { return (m_type == Transcription); }
132 
136  bool HasPage(int pageIdx) const;
137 
145  const Pages *GetPages() const;
147 
151  int GetPageCount() const;
152 
158  const ScoreDef *GetFirstScoreDef() const;
160 
166  std::list<Score *> GetVisibleScores();
167  Score *GetFirstVisibleScore();
169 
175  const Score *GetCorrespondingScore(const Object *object) const;
176  // Generic version that does not necessarily rely on precalculated visible scores
177  Score *GetCorrespondingScore(const Object *object, const std::list<Score *> &scores);
178  const Score *GetCorrespondingScore(const Object *object, const std::list<Score *> &scores) const;
180 
184  bool GetMidiExportDone() const;
185 
190  int GetGlyphHeight(char32_t code, int staffSize, bool graceSize) const;
191  int GetGlyphWidth(char32_t code, int staffSize, bool graceSize) const;
192  int GetGlyphLeft(char32_t code, int staffSize, bool graceSize) const;
193  int GetGlyphRight(char32_t code, int staffSize, bool graceSize) const;
194  int GetGlyphBottom(char32_t code, int staffSize, bool graceSize) const;
195  int GetGlyphTop(char32_t code, int staffSize, bool graceSize) const;
196  int GetGlyphAdvX(char32_t code, int staffSize, bool graceSize) const;
197  int GetDrawingUnit(int staffSize) const;
198  int GetDrawingDoubleUnit(int staffSize) const;
199  int GetDrawingStaffSize(int staffSize) const;
200  int GetDrawingOctaveSize(int staffSize) const;
201  int GetDrawingBrevisWidth(int staffSize) const;
202  int GetDrawingBarLineWidth(int staffSize) const;
203  int GetDrawingStaffLineWidth(int staffSize) const;
204  int GetDrawingStemWidth(int staffSize) const;
205  int GetDrawingDirHeight(int staffSize, bool withMargin) const;
206  int GetDrawingDynamHeight(int staffSize, bool withMargin) const;
207  int GetDrawingHairpinSize(int staffSize, bool withMargin) const;
208  int GetDrawingBeamWidth(int staffSize, bool graceSize) const;
209  int GetDrawingBeamWhiteWidth(int staffSize, bool graceSize) const;
210  int GetDrawingLedgerLineExtension(int staffSize, bool graceSize) const;
211  int GetDrawingMinimalLedgerLineExtension(int staffSize, bool graceSize) const;
212  int GetCueSize(int value) const;
213  double GetCueScaling() const;
215 
216  Point ConvertFontPoint(const Glyph *glyph, const Point &fontPoint, int staffSize, bool graceSize) const;
217 
223  int GetTextGlyphHeight(char32_t code, const FontInfo *font, bool graceSize) const;
224  int GetTextGlyphWidth(char32_t code, const FontInfo *font, bool graceSize) const;
225  int GetTextGlyphAdvX(char32_t code, const FontInfo *font, bool graceSize) const;
226  int GetTextGlyphDescender(char32_t code, const FontInfo *font, bool graceSize) const;
227  int GetTextLineHeight(const FontInfo *font, bool graceSize) const;
228  int GetTextXHeight(const FontInfo *font, bool graceSize) const;
230 
236  FontInfo *GetDrawingSmuflFont(int staffSize, bool graceSize);
237  FontInfo *GetDrawingLyricFont(int staffSize);
238  FontInfo *GetFingeringFont(int staffSize);
240 
246 
252  double GetLeftMargin(const ClassId classId) const;
253  double GetLeftMargin(const Object *object) const;
254  double GetRightMargin(const ClassId classId) const;
255  double GetRightMargin(const Object *object) const;
256  double GetLeftPosition() const;
257  double GetBottomMargin(const ClassId classId) const;
258  double GetTopMargin(const ClassId classId) const;
260 
265  data_MEASUREMENTSIGNED GetStaffDistance(const Object *object, int staffIndex, data_STAFFREL staffPosition) const;
266 
272 
278  bool HasTimemap() const;
279 
284  void ExportMIDI(smf::MidiFile *midiFile);
285 
290  bool ExportTimemap(std::string &output, bool includeRests, bool includeMeasures, bool useFractions);
291 
295  bool ExportExpansionMap(std::string &output);
296 
300  bool ExportFeatures(std::string &output, const std::string &options);
301 
308  void ScoreDefSetCurrentDoc(bool force = false);
309 
314 
319 
325  void PrepareData();
326 
331  void CastOffDoc();
332 
338 
344 
351  void CastOffDocBase(bool useSb, bool usePb, bool smart = false);
352 
357  void UnCastOffDoc(bool resetCache = true);
358 
364 
371 
377  void ConvertToCastOffMensuralDoc(bool castOff);
378 
383 
389  void ConvertMarkupDoc(bool permanent = true);
390 
394  void ScoringUpDoc();
395 
396  /*
397  * Convert the doc from mensural to a flattened version with no ligatures and the selected editorial markup.
398  */
399  void ConvertToMensuralViewDoc();
400 
405 
411 
417 
421  void TransposeDoc();
422 
427 
434  Page *SetDrawingPage(int pageIdx, bool withPageRange = false);
435 
440 
447  void ResetDataPage() { m_drawingPage = NULL; }
448 
455  Page *GetDrawingPage() { return m_drawingPage; }
456  const Page *GetDrawingPage() const { return m_drawingPage; }
458 
462  bool CheckPageSize(const Page *page) const;
463 
469 
475 
481  void SetMarkup(int markup) { m_markup |= markup; }
482 
487  void SetMensuralMusicOnly(data_BOOLEAN isMensuralMusicOnly);
488  bool IsMensuralMusicOnly() const { return (m_isMensuralMusicOnly == BOOLEAN_true); }
490 
495  void SetNeumeLines(bool isNeumeLines) { m_isNeumeLines = isNeumeLines; }
496  bool IsNeumeLines() const { return m_isNeumeLines; }
498 
503  void SetFacsimile(Facsimile *facsimile) { m_facsimile = facsimile; }
504  Facsimile *GetFacsimile() { return m_facsimile; }
505  const Facsimile *GetFacsimile() const { return m_facsimile; }
506  bool HasFacsimile() const { return m_facsimile != NULL; }
508 
512  bool IsCastOff() const { return m_isCastOff; }
513 
518  void InitSelectionDoc(DocSelection &selection, bool resetCache);
519  void ResetSelectionDoc(bool resetCache);
520  bool HasSelection() const;
527  void ReactivateSelection(bool resetAligners);
529 
534 
538  void SetFocus();
539 
540  //----------//
541  // Functors //
542  //----------//
543 
548  FunctorCode Accept(Functor &functor) override;
549  FunctorCode Accept(ConstFunctor &functor) const override;
550  FunctorCode AcceptEnd(Functor &functor) override;
551  FunctorCode AcceptEnd(ConstFunctor &functor) const override;
553 
554 private:
558  int CalcMusicFontSize();
559 
563  void PrepareMeasureIndices();
564 
568  void CollectVisibleScores();
569 
573  void ResetFocus();
574 
575 public:
576  Page *m_selectionPreceding;
577  Page *m_selectionFollowing;
578  std::string m_selectionStart;
579  std::string m_selectionEnd;
580 
585 
589  pugi::xml_document m_header;
590 
594  pugi::xml_document m_front;
595 
599  pugi::xml_document m_back;
600 
604  std::string m_musicDecls;
605 
624 
629  data_NOTATIONTYPE m_notationType;
630 
633 
634 private:
640  DocType m_type;
641 
646  Options *m_options;
647 
651  Resources m_resources;
652 
657  std::list<Score *> m_visibleScores;
658 
662  bool m_isCastOff;
663 
667  FocusStatusType m_focusStatus;
668 
669  /*
670  * The following values are set in the Doc::SetDrawingPage.
671  * They are all current values to be used when drawing a page in a View and
672  * reset for every page. However, most of them are based on the m_staffDefin values
673  * and will remain the same. This can be optimized.
674  * The pages dimensions and margins are based on the page ones, the document ones or
675  * the default in the following order and if available.
676  */
677 
679  Page *m_drawingPage;
681  int m_drawingBeamWidth;
683  int m_drawingBeamWhiteWidth;
685  int m_drawingBrevisWidth;
686 
688  int m_drawingSmuflFontSize;
690  int m_drawingLyricFontSize;
692  int m_fingeringFontSize;
694  FontInfo m_drawingSmuflFont;
696  FontInfo m_drawingLyricFont;
698  FontInfo m_fingeringFont;
699 
705  bool m_currentScoreDefDone;
706 
711  bool m_dataPreparationDone;
712 
718  double m_timemapTempo;
719 
725  int m_markup;
726 
731  data_BOOLEAN m_isMensuralMusicOnly;
732 
737  bool m_isNeumeLines;
738 
740  int m_pageWidth;
742  int m_pageHeight;
744  int m_pageMarginBottom;
746  int m_pageMarginLeft;
748  int m_pageMarginRight;
750  int m_pageMarginTop;
751 
753  Facsimile *m_facsimile;
754 };
755 
756 } // namespace vrv
757 
758 #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:621
void ResetDataPage()
Reset drawing page to NULL.
Definition: doc.h:447
float m_drawingBeamMaxSlope
the current beam maximal slope
Definition: doc.h:623
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 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:125
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:589
int m_drawingPageMarginLeft
The current page left margin.
Definition: doc.h:617
Score * GetCorrespondingScore(const Object *object)
Get the corresponding score for a node.
int m_drawingPageContentWidth
The current page content width (without margins)
Definition: doc.h:613
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:86
void SyncFromFacsimileDoc()
Sync the coordinate provided trought <facsimile> to m_drawingFacsX/Y.
void ExportMIDI(smf::MidiFile *midiFile)
Export the document to a MIDI file.
void ConvertToCastOffMensuralDoc(bool castOff)
Convert mensural MEI into cast-off (measure) segments looking at the barLine objects.
bool IsCastOff() const
Return true if the document has been cast off already.
Definition: doc.h:512
void GenerateFooter()
Generate a document pgFoot if none is provided.
int m_drawingPageWidth
The current page width.
Definition: doc.h:609
std::list< Score * > GetVisibleScores()
Get all visible scores / the first visible score Lazily updates the visible scores,...
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:632
void UnCastOffDoc(bool resetCache=true)
Undo the cast off of the entire document.
std::string m_musicDecls
The music@decls value.
Definition: doc.h:604
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:619
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:584
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.
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 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:599
int m_drawingPageContentHeight
The current page content height (without margings)
Definition: doc.h:611
Pages * GetPages()
Get the Pages in the visible Mdiv.
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:629
int m_drawingPageHeight
The current page height.
Definition: doc.h:607
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:615
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:455
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:481
Options * GetOptions()
Getter for the options.
Definition: doc.h:77
pugi::xml_document m_front
A copy of the front tree stored as pugi::xml_document.
Definition: doc.h:594
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:19
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:31
This class represents a basic object.
Definition: object.h:61
This class contains the document styling parameters.
Definition: options.h:576
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:30
This class represents a MEI scoreDef.
Definition: scoredef.h:135
This class represent a <score> in MEI.
Definition: score.h:30