1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2002-2012 Werner Schweer
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2
9 // as published by the Free Software Foundation and appearing in
10 // the file LICENCE.GPL
11 //=============================================================================
12
13 #ifndef __SCORE_H__
14 #define __SCORE_H__
15
16 /**
17 \file
18 Definition of Score class.
19 */
20
21 #include "config.h"
22 #include "input.h"
23 #include "instrument.h"
24 #include "select.h"
25 #include "synthesizerstate.h"
26 #include "mscoreview.h"
27 #include "spannermap.h"
28 #include "layoutbreak.h"
29 #include "property.h"
30 #include "sym.h"
31
32 namespace Ms {
33
34 namespace Avs {
35 class AvsOmr;
36 }
37
38 class Articulation;
39 class Audio;
40 class BarLine;
41 class Beam;
42 class Bracket;
43 class BSymbol;
44 class Chord;
45 class ChordRest;
46 class Clef;
47 class Dynamic;
48 class ElementList;
49 class EventMap;
50 class Excerpt;
51 class FiguredBass;
52 class Fingering;
53 class Hairpin;
54 class Harmony;
55 class Instrument;
56 class KeyList;
57 class KeySig;
58 class KeySigEvent;
59 class LinkedElements;
60 class Lyrics;
61 class MasterSynthesizer;
62 class Measure;
63 class MeasureBase;
64 class MuseScoreView;
65 class Note;
66 class Omr;
67 class Page;
68 class Parameter;
69 class Part;
70 class RepeatList;
71 class Rest;
72 class Revisions;
73 class ScoreFont;
74 class Segment;
75 class Selection;
76 class SigEvent;
77 class Slur;
78 class Spanner;
79 class Staff;
80 class System;
81 class TempoMap;
82 class Text;
83 class TimeSig;
84 class TimeSigMap;
85 class Tuplet;
86 class Undo;
87 class UndoCommand;
88 class UndoStack;
89 class Volta;
90 class XmlWriter;
91 class Channel;
92 class ScoreOrder;
93 struct Interval;
94 struct TEvent;
95 struct LayoutContext;
96
97 enum class Tid;
98 enum class ClefType : signed char;
99 enum class BeatType : char;
100 enum class Key;
101 enum class HairpinType : signed char;
102 enum class SegmentType;
103 enum class OttavaType : char;
104 enum class Voicing : signed char;
105 enum class HDuration : signed char;
106
107 enum class POS : char { CURRENT, LEFT, RIGHT };
108
109 enum class Pad : char {
110 NOTE00,
111 NOTE0,
112 NOTE1,
113 NOTE2,
114 NOTE4,
115 NOTE8,
116 NOTE16,
117 NOTE32,
118 NOTE64,
119 NOTE128,
120 NOTE256,
121 NOTE512,
122 NOTE1024,
123 //--------------------
124 REST,
125 DOT,
126 DOTDOT,
127 DOT3,
128 DOT4
129 };
130
131 //---------------------------------------------------------
132 // LayoutMode
133 // PAGE The normal page view, honors page and line breaks.
134 // LINE The panoramic view, one long system
135 // FLOAT The "reflow" mode, ignore page and line breaks
136 // SYSTEM The "never ending page", page break are turned into line break
137 //---------------------------------------------------------
138
139 enum class LayoutMode : char {
140 PAGE, FLOAT, LINE, SYSTEM
141 };
142
143 //---------------------------------------------------------
144 // MeasureBaseList
145 //---------------------------------------------------------
146
147 class MeasureBaseList {
148 int _size;
149 MeasureBase* _first;
150 MeasureBase* _last;
151
152 void push_back(MeasureBase* e);
153 void push_front(MeasureBase* e);
154
155 public:
156 MeasureBaseList();
first()157 MeasureBase* first() const { return _first; }
last()158 MeasureBase* last() const { return _last; }
clear()159 void clear() { _first = _last = 0; _size = 0; }
160 void add(MeasureBase*);
161 void remove(MeasureBase*);
162 void insert(MeasureBase*, MeasureBase*);
163 void remove(MeasureBase*, MeasureBase*);
164 void change(MeasureBase* o, MeasureBase* n);
size()165 int size() const { return _size; }
166 };
167
168 //---------------------------------------------------------
169 // MidiMapping
170 //---------------------------------------------------------
171
172 class MidiMapping {
173 Part* _part;
174 std::unique_ptr<Channel> _articulation;
175 signed char _port;
176 signed char _channel;
177 Channel* masterChannel;
178 PartChannelSettingsLink link;
179
180 MidiMapping() = default; // should be created only within MasterScore
181 friend class MasterScore;
182
183 public:
part()184 Part* part() { return _part; }
part()185 const Part* part() const { return _part; }
articulation()186 Channel* articulation() { return _articulation.get(); }
articulation()187 const Channel* articulation() const { return _articulation.get(); }
port()188 signed char port() const { return _port; }
channel()189 signed char channel() const { return _channel; }
190 };
191
192 //---------------------------------------------------------
193 // MidiInputEvent
194 //---------------------------------------------------------
195
196 struct MidiInputEvent {
197 int pitch;
198 bool chord;
199 int velocity;
200 };
201
202 //---------------------------------------------------------
203 // Position
204 //---------------------------------------------------------
205
206 struct Position {
207 Segment* segment { 0 };
208 int staffIdx { -1 };
209 int line { 0 };
210 int fret { FRET_NONE };
211 QPointF pos;
212 };
213
214 //---------------------------------------------------------
215 // LayoutFlag bits
216 //---------------------------------------------------------
217
218 enum class LayoutFlag : char {
219 NO_FLAGS = 0,
220 FIX_PITCH_VELO = 1,
221 PLAY_EVENTS = 2,
222 REBUILD_MIDI_MAPPING = 4,
223 };
224
225 typedef QFlags<LayoutFlag> LayoutFlags;
226
227 //---------------------------------------------------------
228 // PlayMode
229 //---------------------------------------------------------
230
231 enum class PlayMode : char {
232 SYNTHESIZER,
233 AUDIO
234 };
235
236 //---------------------------------------------------------
237 // Layer
238 //---------------------------------------------------------
239
240 struct Layer {
241 QString name;
242 uint tags;
243 };
244
245 //---------------------------------------------------------
246 // UpdateMode
247 // There is an implied order from least invasive update
248 // to most invasive update. LayoutAll is fallback and
249 // recreates all.
250 //---------------------------------------------------------
251
252 enum class UpdateMode {
253 DoNothing,
254 Update, // do screen refresh of QRectF "refresh"
255 UpdateAll, // do complete screen refresh
256 Layout, // do partial layout for tick range
257 };
258
259 //---------------------------------------------------------
260 // CmdState
261 //
262 // the following variables are reset on startCmd()
263 // modified during cmd processing and used in endCmd() to
264 // determine what to layout and what to repaint:
265 //---------------------------------------------------------
266
267 class CmdState {
268 UpdateMode _updateMode { UpdateMode::DoNothing };
269 Fraction _startTick {-1, 1}; // start tick for mode LayoutTick
270 Fraction _endTick {-1, 1}; // end tick for mode LayoutTick
271 int _startStaff = -1;
272 int _endStaff = -1;
273 const Element* _el = nullptr;
274 const MeasureBase* _mb = nullptr;
275 bool _oneElement = true;
276 bool _oneMeasureBase = true;
277
278 bool _locked = false;
279
280 void setMeasureBase(const MeasureBase* mb);
281
282 public:
283 LayoutFlags layoutFlags;
284
285 bool _excerptsChanged { false };
286 bool _instrumentsChanged { false };
287
288 void reset();
updateMode()289 UpdateMode updateMode() const { return _updateMode; }
290 void setUpdateMode(UpdateMode m);
291 void _setUpdateMode(UpdateMode m);
layoutRange()292 bool layoutRange() const { return _updateMode == UpdateMode::Layout; }
updateAll()293 bool updateAll() const { return int(_updateMode) >= int(UpdateMode::UpdateAll); }
updateRange()294 bool updateRange() const { return _updateMode == UpdateMode::Update; }
295 void setTick(const Fraction& t);
296 void setStaff(int staff);
297 void setElement(const Element* e);
298 void unsetElement(const Element* e);
startTick()299 Fraction startTick() const { return _startTick; }
endTick()300 Fraction endTick() const { return _endTick; }
startStaff()301 int startStaff() const { return _startStaff; }
endStaff()302 int endStaff() const { return _endStaff; }
303 const Element* element() const;
304
lock()305 void lock() { _locked = true; }
unlock()306 void unlock() { _locked = false; }
307 #ifndef NDEBUG
308 void dump();
309 #endif
310 };
311
312 //---------------------------------------------------------
313 // UpdateState
314 //---------------------------------------------------------
315
316 class UpdateState {
317 public:
318 QRectF refresh; ///< area to update, canvas coordinates
319 bool _playNote { false }; ///< play selected note after command
320 bool _playChord { false }; ///< play whole chord for the selected note
321 bool _selectionChanged { false };
322 QList<ScoreElement*> _deleteList;
323 };
324
325 //---------------------------------------------------------
326 // ScoreContentState
327 //---------------------------------------------------------
328
329 class ScoreContentState {
330 const Score* score;
331 int num;
332 public:
ScoreContentState()333 ScoreContentState() : score(nullptr), num(0) {}
ScoreContentState(const Score * s,int stateNum)334 ScoreContentState(const Score* s, int stateNum) : score(s), num(stateNum) {}
335
336 bool operator==(const ScoreContentState& s2) const { return score == s2.score && num == s2.num; }
337 bool operator!=(const ScoreContentState& s2) const { return !(*this == s2); }
338
isNewerThan(const ScoreContentState & s2)339 bool isNewerThan(const ScoreContentState& s2) const { return score == s2.score && num > s2.num; }
340 };
341
342 class MasterScore;
343
344 //-----------------------------------------------------------------------------
345 // Movements
346 // A movement is a unit of a larger work that may stand
347 // by itself as a complete composition.
348 // A MuseScore score file can contain several movements represented as
349 // MasterScore's. A MasterScore can have several parts represented
350 // as Score. MasterScores are connected in a double linked list.
351 //-----------------------------------------------------------------------------
352
353 class Movements : public std::vector<MasterScore*> {
354 UndoStack* _undo;
355 QList<Page*> _pages; // pages are build from systems
356 MStyle _style;
357
358 public:
359 Movements();
360 ~Movements();
pageIdx(Page * page)361 int pageIdx(Page* page) const { return _pages.indexOf(page); }
npages()362 int npages() const { return _pages.size(); }
pages()363 const QList<Page*>& pages() const { return _pages; }
pages()364 QList<Page*>& pages() { return _pages; }
undo()365 UndoStack* undo() const { return _undo; }
style()366 MStyle& style() { return _style; }
style()367 const MStyle& style() const { return _style; }
368 };
369
370 //---------------------------------------------------------------------------------------
371 // @@ Score
372 // @P composer string composer of the score (read only)
373 // @P duration int duration of score in seconds (read only)
374 // @P excerpts array[Excerpt] the list of the excerpts (linked parts)
375 // @P firstMeasure Measure the first measure of the score (read only)
376 // @P firstMeasureMM Measure the first multi-measure rest measure of the score (read only)
377 // @P harmonyCount int number of harmony items (read only)
378 // @P hasHarmonies bool score has chord symbols (read only)
379 // @P hasLyrics bool score has lyrics (read only)
380 // @P keysig int key signature at the start of the score (read only)
381 // @P lastMeasure Measure the last measure of the score (read only)
382 // @P lastMeasureMM Measure the last multi-measure rest measure of the score (read only)
383 // @P lastSegment Segment the last score segment (read-only)
384 // @P lyricCount int number of lyric items (read only)
385 // @P name string name of the score
386 // @P nmeasures int number of measures (read only)
387 // @P npages int number of pages (read only)
388 // @P nstaves int number of staves (read only)
389 // @P ntracks int number of tracks (staves * 4) (read only)
390 // not to be documented?
391 // @P parts array[Part] the list of parts (read only)
392 //
393 // a Score has always an associated MasterScore
394 //---------------------------------------------------------------------------------------
395
396 class Score : public QObject, public ScoreElement {
397 Q_OBJECT
398
399 public:
400 enum class FileError : char {
401 FILE_NO_ERROR,
402 FILE_ERROR,
403 FILE_NOT_FOUND,
404 FILE_OPEN_ERROR,
405 FILE_BAD_FORMAT,
406 FILE_UNKNOWN_TYPE,
407 FILE_NO_ROOTFILE,
408 FILE_TOO_OLD,
409 FILE_TOO_NEW,
410 FILE_OLD_300_FORMAT,
411 FILE_CORRUPTED,
412 FILE_CRITICALLY_CORRUPTED,
413 FILE_USER_ABORT,
414 FILE_IGNORE_ERROR
415 };
416
417 private:
418 static std::set<Score*> validScores;
419 int _linkId { 0 };
420 MasterScore* _masterScore { 0 };
421 QList<MuseScoreView*> viewer;
422 Excerpt* _excerpt { 0 };
423
424 std::vector<Text*> _headersText;
425 std::vector<Text*> _footersText;
426
427 QString _mscoreVersion;
428 int _mscoreRevision;
429
430 QString _layerTags[32];
431 QString _layerTagComments[32];
432 QList<Layer> _layer;
433 int _currentLayer { 0 };
434
435 ScoreFont* _scoreFont;
436 int _pageNumberOffset { 0 }; ///< Offset for page numbers.
437
438 UpdateState _updateState;
439
440 MeasureBaseList _measures; // here are the notes
441 QList<Part*> _parts;
442 QList<Staff*> _staves;
443
444 SpannerMap _spanner;
445 std::set<Spanner*> _unmanagedSpanner;
446
447 //
448 // objects generated by layout:
449 //
450 QList<Page*> _pages; // pages are build from systems
451 QList<System*> _systems; // measures are accumulated to systems
452
453 InputState _is;
454 MStyle _style;
455
456 bool _created { false }; ///< file is never saved, has generated name
457 bool _startedEmpty { false }; ///< The score was created from an empty template (typically ":/data/My_First_Score.mscx") during this session, so it doesn't need to be saved if it hasn't been modified.
458 QString _tmpName; ///< auto saved with this name if not empty
459 QString _importedFilePath; // file from which the score was imported, or empty
460
461 bool _showInvisible { true };
462 bool _showUnprintable { true };
463 bool _showFrames { true };
464 bool _showPageborders { false };
465 bool _markIrregularMeasures { true };
466 bool _showInstrumentNames { true };
467 bool _showVBox { true };
468 bool _printing { false }; ///< True if we are drawing to a printer
469 bool _autosaveDirty { true };
470 bool _savedCapture { false }; ///< True if we saved an image capture
471 bool _saved { false }; ///< True if project was already saved; only on first
472 ///< save a backup file will be created, subsequent
473 ///< saves will not overwrite the backup file.
474 bool _defaultsRead { false }; ///< defaults were read at MusicXML import, allow export of defaults in convertermode
475 bool _isPalette { false };
476 ScoreOrder* _scoreOrder { nullptr }; ///< used for score ordering
477
478 int _mscVersion { MSCVERSION }; ///< version of current loading *.msc file
479
480 QMap<QString, QString> _metaTags;
481
482 constexpr static double _defaultTempo = 2.0; //default tempo is equal 120 bpm
483
484 Selection _selection;
485 SelectionFilter _selectionFilter;
486 Audio* _audio { 0 };
487 PlayMode _playMode { PlayMode::SYNTHESIZER };
488
489 qreal _noteHeadWidth { 0.0 }; // cached value
490 QString accInfo; ///< information about selected element(s) for use by screen-readers
491 QString accMessage; ///< temporary status message for use by screen-readers
492
493 //------------------
494
495 ChordRest* nextMeasure(ChordRest* element, bool selectBehavior = false, bool mmRest = false);
496 ChordRest* prevMeasure(ChordRest* element, bool mmRest = false);
497 void cmdSetBeamMode(Beam::Mode);
498 void cmdResetAllStyle();
499 void cmdResetTextStyleOverrides();
500 void cmdFlip();
501 Note* getSelectedNote();
502 ChordRest* upStaff(ChordRest* cr);
503 ChordRest* downStaff(ChordRest* cr);
504 ChordRest* nextTrack(ChordRest* cr);
505 ChordRest* prevTrack(ChordRest* cr);
506
507 void padToggle(Pad p, const EditData& ed);
508 void addTempo();
509 void addMetronome();
510
511 void cmdResetBeamMode();
512
513 void cmdInsertClef(ClefType);
514 void cmdAddGrace(NoteType, int);
515 void removeChordRest(ChordRest* cr, bool clearSegment);
516 void cmdMoveRest(Rest*, Direction);
517 void cmdMoveLyrics(Lyrics*, Direction);
518 void cmdIncDecDuration(int nSteps, bool stepDotted = false);
519 void cmdAddBracket();
520 void cmdAddParentheses();
521 void cmdAddBraces();
522 void resetUserStretch();
523
524 void createMMRest(Measure*, Measure*, const Fraction&);
525
526 void beamGraceNotes(Chord*, bool);
527
528 void checkSlurs();
529 void checkScore();
530
531 bool rewriteMeasures(Measure* fm, Measure* lm, const Fraction&, int staffIdx);
532 bool rewriteMeasures(Measure* fm, const Fraction& ns, int staffIdx);
533 void swingAdjustParams(Chord*, int&, int&, int, int);
534 bool isSubdivided(ChordRest*, int);
535 void addAudioTrack();
536 QList<Fraction> splitGapToMeasureBoundaries(ChordRest*, Fraction);
537 void pasteChordRest(ChordRest* cr, const Fraction& tick, const Interval&);
538
539 void selectSingle(Element* e, int staffIdx);
540 void selectAdd(Element* e);
541 void selectRange(Element* e, int staffIdx);
542
543 void cmdAddPitch(const EditData&, int note, bool addFlag, bool insert);
544 void cmdAddFret(int fret);
545 void cmdToggleVisible();
546
547 void putNote(const Position&, bool replace);
548
549 void resetSystems(bool layoutAll, LayoutContext& lc);
550 void collectLinearSystem(LayoutContext& lc);
551 void resetTempo();
552 void resetTempoRange(const Fraction& tick1, const Fraction& tick2);
553
554 void deleteSpannersFromRange(const Fraction& t1, const Fraction& t2, int trackStart, int trackEnd, const SelectionFilter& filter);
555 void deleteAnnotationsFromRange(Segment* segStart, Segment* segEnd, int trackStart, int trackEnd, const SelectionFilter& filter);
556 ChordRest* deleteRange(Segment* segStart, Segment* segEnd, int trackStart, int trackEnd, const SelectionFilter& filter);
557
558 void update(bool resetCmdState);
559
560 protected:
561 int _fileDivision; ///< division of current loading *.msc file
562 LayoutMode _layoutMode { LayoutMode::PAGE };
563 SynthesizerState _synthesizerState;
564
565 void createPlayEvents(Chord*);
566 void createGraceNotesPlayEvents(const Fraction& tick, Chord* chord, int& ontime, int& trailtime);
567 void cmdPitchUp();
568 void cmdPitchDown();
569 void cmdPitchUpOctave();
570 void cmdPitchDownOctave();
571 void cmdPadNoteIncreaseTAB(const EditData& ed);
572 void cmdPadNoteDecreaseTAB(const EditData& ed);
573 void cmdToggleMmrest();
574 void cmdToggleHideEmpty();
575 void cmdSetVisible();
576 void cmdUnsetVisible();
577 inline virtual Movements* movements();
578 inline virtual const Movements* movements() const;
579
580 signals:
581 void posChanged(POS, unsigned);
582 void playlistChanged();
583
584 public:
585 Score();
586 Score(MasterScore*, bool forcePartStyle = true);
587 Score(MasterScore*, const MStyle&);
588 Score(const Score&) = delete;
589 Score& operator=(const Score&) = delete;
590 virtual ~Score();
591 Score* clone();
592
isMaster()593 virtual bool isMaster() const { return false; }
594 virtual bool readOnly() const;
595
596 static void onElementDestruction(Element* se);
597
598 virtual inline QList<Excerpt*>& excerpts();
599 virtual inline const QList<Excerpt*>& excerpts() const;
600
type()601 virtual ElementType type() const override { return ElementType::SCORE; }
602
603 void rebuildBspTree();
noStaves()604 bool noStaves() const { return _staves.empty(); }
605 void insertPart(Part*, int);
606 void removePart(Part*);
607 void insertStaff(Staff*, int);
608 void cmdRemoveStaff(int staffIdx);
609 void removeStaff(Staff*);
610 void addMeasure(MeasureBase*, MeasureBase*);
611 void readStaff(XmlReader&);
612 bool read(XmlReader&);
613 void linkMeasures(Score* score);
614
excerpt()615 Excerpt* excerpt() { return _excerpt; }
setExcerpt(Excerpt * e)616 void setExcerpt(Excerpt* e) { _excerpt = e; }
617
618 System* collectSystem(LayoutContext&);
619 void layoutSystemElements(System* system, LayoutContext& lc);
620 void getNextMeasure(LayoutContext&); // get next measure for layout
621
622 void resetAllPositions();
623
624 void cmdRemovePart(Part*);
625 void cmdAddTie(bool addToChord = false);
626 void cmdToggleTie();
627 static std::vector<Note*> cmdTieNoteList(const Selection& selection, bool noteEntryMode);
628 void cmdAddOttava(OttavaType);
629 void cmdAddStretch(qreal);
630 void cmdResetNoteAndRestGroupings();
631 void cmdResetAllPositions(bool undoable = true);
cmdDoubleDuration()632 void cmdDoubleDuration() { cmdIncDecDuration(-1, false); }
cmdHalfDuration()633 void cmdHalfDuration() { cmdIncDecDuration( 1, false); }
cmdIncDurationDotted()634 void cmdIncDurationDotted() { cmdIncDecDuration(-1, true); }
cmdDecDurationDotted()635 void cmdDecDurationDotted() { cmdIncDecDuration( 1, true); }
636 void cmdToggleLayoutBreak(LayoutBreak::Type);
637
638 void addRemoveBreaks(int interval, bool lock);
639
640 bool transpose(Note* n, Interval, bool useSharpsFlats);
641 void transposeKeys(int staffStart, int staffEnd, const Fraction& tickStart, const Fraction& tickEnd, const Interval&, bool useInstrument = false, bool flip = false);
642 bool transpose(TransposeMode mode, TransposeDirection, Key transposeKey, int transposeInterval,
643 bool trKeys, bool transposeChordNames, bool useDoubleSharpsFlats);
644
645 bool appendMeasuresFromScore(Score* score, const Fraction& startTick, const Fraction& endTick);
646 bool appendScore(Score*, bool addPageBreak = false, bool addSectionBreak = true);
647
648 void write(XmlWriter&, bool onlySelection);
649 void writeMovement(XmlWriter&, bool onlySelection);
650
staves()651 QList<Staff*>& staves() { return _staves; }
staves()652 const QList<Staff*>& staves() const { return _staves; }
nstaves()653 int nstaves() const { return _staves.size(); }
ntracks()654 int ntracks() const { return _staves.size() * VOICES; }
655
656 int staffIdx(const Part*) const;
staff(int n)657 Staff* staff(int n) const { return ((n >= 0) && (n < _staves.size())) ? _staves.at(n) : nullptr; }
658
659 Measure* pos2measure(const QPointF&, int* staffIdx, int* pitch, Segment**, QPointF* offset) const;
660 void dragPosition(const QPointF&, int* staffIdx, Segment**, qreal spacingFactor = 0.5) const;
661
662 void undoAddElement(Element* element);
663 void undoAddCR(ChordRest* element, Measure*, const Fraction& tick);
664 void undoRemoveElement(Element* element);
665 void undoChangeSpannerElements(Spanner* spanner, Element* startElement, Element* endElement);
666 void undoChangeElement(Element* oldElement, Element* newElement);
667 void undoChangePitch(Note* note, int pitch, int tpc1, int tpc2);
668 void undoChangeFretting(Note* note, int pitch, int string, int fret, int tpc1, int tpc2);
669 void spellNotelist(std::vector<Note*>& notes);
670 void undoChangeTpc(Note* note, int tpc);
671 void undoChangeChordRestLen(ChordRest* cr, const TDuration&);
672 void undoTransposeHarmony(Harmony*, int, int);
673 void undoExchangeVoice(Measure* measure, int val1, int val2, int staff1, int staff2);
674 void undoRemovePart(Part* part, int idx);
675 void undoInsertPart(Part* part, int idx);
676 void undoRemoveStaff(Staff* staff);
677 void undoInsertStaff(Staff* staff, int idx, bool createRests=true);
678 void undoChangeInvisible(Element*, bool);
679 void undoChangeTuning(Note*, qreal);
680 void undoChangeUserMirror(Note*, MScore::DirectionH);
681 void undoChangeKeySig(Staff* ostaff, const Fraction& tick, KeySigEvent);
682 void undoChangeClef(Staff* ostaff, Element*, ClefType st, bool forInstrumentChange = false);
683 bool undoPropertyChanged(Element* e, Pid t, const QVariant& st, PropertyFlags ps = PropertyFlags::NOSTYLE);
684 void undoPropertyChanged(ScoreElement*, Pid, const QVariant& v, PropertyFlags ps = PropertyFlags::NOSTYLE);
685 inline virtual UndoStack* undoStack() const;
686 void undo(UndoCommand*, EditData* = 0) const;
687 void undoRemoveMeasures(Measure*, Measure*, bool preserveTies = false);
688 void undoAddBracket(Staff* staff, int level, BracketType type, int span);
689 void undoRemoveBracket(Bracket*);
690 void undoInsertTime(const Fraction& tick, const Fraction& len);
691 void undoChangeStyleVal(Sid idx, const QVariant& v);
692 void undoChangePageNumberOffset(int po);
693
694 void updateInstrumentChangeTranspositions(Ms::KeySigEvent& key, Ms::Staff* staff, const Ms::Fraction& tick);
695
696 Note* setGraceNote(Chord*, int pitch, NoteType type, int len);
697
698 Segment* setNoteRest(Segment*, int track, NoteVal nval, Fraction, Direction stemDirection = Direction::AUTO, bool forceAccidental = false, bool rhythmic = false, InputState* externalInputState = nullptr);
699 Segment* setChord(Segment*, int track, Chord* chord, Fraction, Direction stemDirection = Direction::AUTO);
700 void changeCRlen(ChordRest* cr, const TDuration&);
701 void changeCRlen(ChordRest* cr, const Fraction&, bool fillWithRest=true);
702 void createCRSequence(const Fraction& f, ChordRest* cr, const Fraction& tick);
703
704 Fraction makeGap(Segment*, int track, const Fraction&, Tuplet*, bool keepChord = false);
705 bool makeGap1(const Fraction& baseTick, int staffIdx, const Fraction& len, int voiceOffset[VOICES]);
706 bool makeGapVoice(Segment* seg, int track, Fraction len, const Fraction& tick);
707
708 Rest* addRest(const Fraction& tick, int track, TDuration, Tuplet*);
709 Rest* addRest(Segment* seg, int track, TDuration d, Tuplet*);
710 Chord* addChord(const Fraction& tick, TDuration d, Chord* oc, bool genTie, Tuplet* tuplet);
711
712 ChordRest* addClone(ChordRest* cr, const Fraction& tick, const TDuration& d);
713 Rest* setRest(const Fraction& tick, int track, const Fraction&, bool useDots, Tuplet* tuplet, bool useFullMeasureRest = true);
714
715 void upDown(bool up, UpDownMode);
716 void upDownDelta(int pitchDelta);
717 ChordRest* searchNote(const Fraction& tick, int track) const;
718
719 // undo/redo ops
720 void addArticulation(SymId);
721 bool addArticulation(Element*, Articulation* atr);
722 void toggleAccidental(AccidentalType, const EditData& ed);
723 void changeAccidental(AccidentalType);
724 void changeAccidental(Note* oNote, Ms::AccidentalType);
725
726 void addElement(Element*);
727 void removeElement(Element*);
728
729 Note* addPitch(NoteVal&, bool addFlag, InputState* externalInputState = nullptr);
730 void addPitch(int pitch, bool addFlag, bool insert);
731 Note* addTiedMidiPitch(int pitch, bool addFlag, Chord* prevChord);
732 Note* addMidiPitch(int pitch, bool addFlag);
733 Note* addNote(Chord*, const NoteVal& noteVal, bool forceAccidental = false, InputState* externalInputState = nullptr);
734
735 NoteVal noteValForPosition(Position pos, AccidentalType at, bool &error);
736
737 void deleteItem(Element*);
738 void deleteMeasures(MeasureBase* firstMeasure, MeasureBase* lastMeasure, bool preserveTies = false);
739 void cmdDeleteSelection();
740 void cmdFullMeasureRest();
741
742 void putNote(const QPointF&, bool replace, bool insert);
743 void insertChord(const Position&);
744 void localInsertChord(const Position&);
745 void globalInsertChord(const Position&);
746
747 void cloneVoice(int strack, int dtrack, Segment* sf, const Fraction& lTick, bool link = true, bool spanner = true);
748
749 void repitchNote(const Position& pos, bool replace);
750 void regroupNotesAndRests(const Fraction& startTick, const Fraction& endTick, int track);
751 bool checkTimeDelete(Segment*, Segment*);
752 void timeDelete(Measure*, Segment*, const Fraction&);
753
754 void startCmd(); // start undoable command
755 void endCmd(bool rollback = false); // end undoable command
update()756 void update() { update(true); }
757 void undoRedo(bool undo, EditData*);
758
759 void cmdRemoveTimeSig(TimeSig*);
760 void cmdAddTimeSig(Measure*, int staffIdx, TimeSig*, bool local);
761
762 virtual inline void setUpdateAll();
763 inline void setLayoutAll(int staff = -1, const Element* e = nullptr);
764 inline void setLayout(const Fraction& tick, int staff, const Element* e = nullptr);
765 inline void setLayout(const Fraction& tick1, const Fraction& tick2, int staff1, int staff2, const Element* e = nullptr);
766 virtual inline CmdState& cmdState();
767 virtual inline const CmdState& cmdState() const;
768 virtual inline void addLayoutFlags(LayoutFlags);
769 virtual inline void setInstrumentsChanged(bool);
770 void addRefresh(const QRectF&);
771
772 void cmdRelayout();
773 void cmdToggleAutoplace(bool all);
774
playNote()775 bool playNote() const { return _updateState._playNote; }
setPlayNote(bool v)776 void setPlayNote(bool v) { _updateState._playNote = v; }
playChord()777 bool playChord() const { return _updateState._playChord; }
setPlayChord(bool v)778 void setPlayChord(bool v) { _updateState._playChord = v; }
selectionChanged()779 bool selectionChanged() const { return _updateState._selectionChanged; }
setSelectionChanged(bool val)780 void setSelectionChanged(bool val) { _updateState._selectionChanged = val; }
deleteLater(ScoreElement * e)781 void deleteLater(ScoreElement* e) { _updateState._deleteList.push_back(e); }
782 void deletePostponed();
783
784 void changeVoice(int);
785
786 void colorItem(Element*);
parts()787 QList<Part*>& parts() { return _parts; }
parts()788 const QList<Part*>& parts() const { return _parts; }
789
790 void appendPart(Part* p);
791 void appendPart(const InstrumentTemplate*);
792 void updateStaffIndex();
793 void sortStaves(QList<int>& dst);
794 void mapExcerptTracks(QList<int>& l);
795
showInvisible()796 bool showInvisible() const { return _showInvisible; }
showUnprintable()797 bool showUnprintable() const { return _showUnprintable; }
showFrames()798 bool showFrames() const { return _showFrames; }
showPageborders()799 bool showPageborders() const { return _showPageborders; }
markIrregularMeasures()800 bool markIrregularMeasures() const { return _markIrregularMeasures; }
showInstrumentNames()801 bool showInstrumentNames() const { return _showInstrumentNames; }
showVBox()802 bool showVBox() const { return _showVBox; }
803 void setShowInvisible(bool v);
804 void setShowUnprintable(bool v);
805 void setShowFrames(bool v);
806 void setShowPageborders(bool v);
807 void setMarkIrregularMeasures(bool v);
setShowInstrumentNames(bool v)808 void setShowInstrumentNames(bool v) { _showInstrumentNames = v; }
setShowVBox(bool v)809 void setShowVBox(bool v) { _showVBox = v; }
810
811 bool saveFile(QFileInfo& info);
812 bool saveFile(QIODevice* f, bool msczFormat, bool onlySelection = false);
813 bool saveCompressedFile(QFileInfo&, bool onlySelection, bool createThumbnail = true);
814 bool saveCompressedFile(QIODevice*, const QString& fileName, bool onlySelection, bool createThumbnail = true);
815
816 void print(QPainter* printer, int page);
817 ChordRest* getSelectedChordRest() const;
818 QSet<ChordRest*> getSelectedChordRests() const;
819 void getSelectedChordRest2(ChordRest** cr1, ChordRest** cr2) const;
820
821 void select(Element* obj, SelectType = SelectType::SINGLE, int staff = 0);
822 void selectSimilar(Element* e, bool sameStaff);
823 void selectSimilarInRange(Element* e);
824 static void collectMatch(void* data, Element* e);
825 static void collectNoteMatch(void* data, Element* e);
826 void deselect(Element* obj);
deselectAll()827 void deselectAll() { _selection.deselectAll(); }
updateSelection()828 void updateSelection() { _selection.update(); }
getSelectedElement()829 Element* getSelectedElement() const { return _selection.element(); }
selection()830 const Selection& selection() const { return _selection; }
selection()831 Selection& selection() { return _selection; }
selectionFilter()832 SelectionFilter& selectionFilter() { return _selectionFilter; }
833 void setSelection(const Selection& s);
834
835 Fraction pos();
836 Measure* tick2measure(const Fraction& tick) const;
837 Measure* tick2measureMM(const Fraction& tick) const;
838 MeasureBase* tick2measureBase(const Fraction& tick) const;
839 Segment* tick2segment(const Fraction& tick, bool first, SegmentType st, bool useMMrest = false) const;
840 Segment* tick2segment(const Fraction& tick) const;
841 Segment* tick2segment(const Fraction& tick, bool first) const;
842 Segment* tick2segmentMM(const Fraction& tick, bool first, SegmentType st) const;
843 Segment* tick2segmentMM(const Fraction& tick) const;
844 Segment* tick2segmentMM(const Fraction& tick, bool first) const;
845 Segment* tick2leftSegment(const Fraction& tick, bool useMMrest = false) const;
846 Segment* tick2rightSegment(const Fraction& tick, bool useMMrest = false) const;
tick2leftSegmentMM(const Fraction & tick)847 Segment* tick2leftSegmentMM(const Fraction& tick) { return tick2leftSegment(tick, /* useMMRest */ true); }
848 void fixTicks();
849 void rebuildTempoAndTimeSigMaps(Measure* m);
850 Element* nextElement();
851 Element* prevElement();
852 ChordRest* cmdNextPrevSystem(ChordRest*, bool);
853 Box* cmdNextPrevFrame(MeasureBase*, bool) const;
854 Element* cmdNextPrevSection(Element*, bool) const;
855 MeasureBase* getNextPrevSectionBreak(MeasureBase*, bool) const;
856 Element* getScoreElementOfMeasureBase(MeasureBase*) const;
857
858 void cmd(const QAction*, EditData&);
fileDivision(int t)859 int fileDivision(int t) const { return ((qint64)t * MScore::division + _fileDivision/2) / _fileDivision; }
setFileDivision(int t)860 void setFileDivision(int t) { _fileDivision = t; }
861
importedFilePath()862 QString importedFilePath() const { return _importedFilePath; }
863 void setImportedFilePath(const QString& filePath);
864
865 bool dirty() const;
866 ScoreContentState state() const;
setCreated(bool val)867 void setCreated(bool val) { _created = val; }
created()868 bool created() const { return _created; }
setStartedEmpty(bool val)869 void setStartedEmpty(bool val) { _startedEmpty = val; }
startedEmpty()870 bool startedEmpty() const { return _startedEmpty; }
savedCapture()871 bool savedCapture() const { return _savedCapture; }
saved()872 bool saved() const { return _saved; }
setSaved(bool v)873 void setSaved(bool v) { _saved = v; }
setSavedCapture(bool v)874 void setSavedCapture(bool v) { _savedCapture = v; }
printing()875 bool printing() const { return _printing; }
setPrinting(bool val)876 void setPrinting(bool val) { _printing = val; }
setAutosaveDirty(bool v)877 void setAutosaveDirty(bool v) { _autosaveDirty = v; }
autosaveDirty()878 bool autosaveDirty() const { return _autosaveDirty; }
879 virtual bool playlistDirty() const;
880 virtual void setPlaylistDirty();
881
882 void spell();
883 void spell(int startStaff, int endStaff, Segment* startSegment, Segment* endSegment);
884 void spell(Note*);
885 Fraction nextSeg(const Fraction& tick, int track);
886
style()887 virtual MStyle& style() { return _style; }
style()888 virtual const MStyle& style() const { return _style; }
889
890 void setStyle(const MStyle& s, const bool overlap = false);
891 bool loadStyle(const QString&, bool ign = false, const bool overlap = false);
892 bool saveStyle(const QString&);
893
styleV(Sid idx)894 QVariant styleV(Sid idx) const { return style().value(idx); }
styleS(Sid idx)895 Spatium styleS(Sid idx) const { Q_ASSERT(!strcmp(MStyle::valueType(idx),"Ms::Spatium")); return style().value(idx).value<Spatium>(); }
styleP(Sid idx)896 qreal styleP(Sid idx) const { Q_ASSERT(!strcmp(MStyle::valueType(idx),"Ms::Spatium")); return style().pvalue(idx); }
styleSt(Sid idx)897 QString styleSt(Sid idx) const { Q_ASSERT(!strcmp(MStyle::valueType(idx),"QString")); return style().value(idx).toString(); }
styleB(Sid idx)898 bool styleB(Sid idx) const { Q_ASSERT(!strcmp(MStyle::valueType(idx),"bool")); return style().value(idx).toBool(); }
styleD(Sid idx)899 qreal styleD(Sid idx) const { Q_ASSERT(!strcmp(MStyle::valueType(idx),"double")); return style().value(idx).toDouble(); }
styleI(Sid idx)900 int styleI(Sid idx) const { Q_ASSERT(!strcmp(MStyle::valueType(idx),"int")); return style().value(idx).toInt(); }
901
setStyleValue(Sid sid,QVariant value)902 void setStyleValue(Sid sid, QVariant value) { style().set(sid, value); }
903 QString getTextStyleUserName(Tid tid);
spatium()904 qreal spatium() const { return styleD(Sid::spatium); }
setSpatium(qreal v)905 void setSpatium(qreal v) { setStyleValue(Sid::spatium, v); }
906
genCourtesyTimesig()907 bool genCourtesyTimesig() const { return styleB(Sid::genCourtesyTimesig); }
genCourtesyClef()908 bool genCourtesyClef() const { return styleB(Sid::genCourtesyClef); }
909
910 // These position are in ticks and not uticks
playPos()911 Fraction playPos() const { return pos(POS::CURRENT); }
setPlayPos(const Fraction & tick)912 void setPlayPos(const Fraction& tick) { setPos(POS::CURRENT, tick); }
loopInTick()913 Fraction loopInTick() const { return pos(POS::LEFT); }
loopOutTick()914 Fraction loopOutTick() const { return pos(POS::RIGHT); }
setLoopInTick(const Fraction & tick)915 void setLoopInTick(const Fraction& tick) { setPos(POS::LEFT, tick); }
setLoopOutTick(const Fraction & tick)916 void setLoopOutTick(const Fraction& tick) { setPos(POS::RIGHT, tick); }
917
918 inline Fraction pos(POS pos) const;
919 inline void setPos(POS pos, Fraction tick);
920
noteEntryMode()921 bool noteEntryMode() const { return inputState().noteEntryMode(); }
setNoteEntryMode(bool val)922 void setNoteEntryMode(bool val) { inputState().setNoteEntryMode(val); }
noteEntryMethod()923 NoteEntryMethod noteEntryMethod() const { return inputState().noteEntryMethod(); }
setNoteEntryMethod(NoteEntryMethod m)924 void setNoteEntryMethod(NoteEntryMethod m) { inputState().setNoteEntryMethod(m); }
usingNoteEntryMethod(NoteEntryMethod m)925 bool usingNoteEntryMethod(NoteEntryMethod m) { return inputState().usingNoteEntryMethod(m); }
926 Fraction inputPos() const;
inputTrack()927 int inputTrack() const { return inputState().track(); }
inputState()928 const InputState& inputState() const { return _is; }
inputState()929 InputState& inputState() { return _is; }
setInputState(const InputState & st)930 void setInputState(const InputState& st) { _is = st; }
setInputTrack(int t)931 void setInputTrack(int t) { inputState().setTrack(t); }
932
933 void spatiumChanged(qreal oldValue, qreal newValue);
934 void styleChanged();
935
936 void cmdPaste(const QMimeData* ms, MuseScoreView* view, Fraction scale = Fraction(1, 1));
937 bool pasteStaff(XmlReader&, Segment* dst, int staffIdx, Fraction scale = Fraction(1, 1));
938 void readAddConnector(ConnectorInfoReader* info, bool pasteMode) override;
939 void pasteSymbols(XmlReader& e, ChordRest* dst);
940 void renderMidi(EventMap* events, const SynthesizerState& synthState);
941 void renderMidi(EventMap* events, bool metronome, bool expandRepeats, const SynthesizerState& synthState);
942
943 BeatType tick2beatType(const Fraction& tick);
944
mscVersion()945 int mscVersion() const { return _mscVersion; }
setMscVersion(int v)946 void setMscVersion(int v) { _mscVersion = v; }
947
948 void addLyrics(const Fraction& tick, int staffIdx, const QString&);
949
950 void updateSwing();
951 void createPlayEvents(Measure const * start = nullptr, Measure const * const end = nullptr);
952
953 void updateCapo();
954 void updateVelo();
955 void updateChannel();
956
957 void cmdConcertPitchChanged(bool, bool /*useSharpsFlats*/);
958
959 virtual inline TempoMap* tempomap() const;
960 virtual inline TimeSigMap* sigmap() const;
961
962 void setTempo(Segment*, qreal);
963 void setTempo(const Fraction& tick, qreal bps);
964 void removeTempo(const Fraction& tick);
965 void setPause(const Fraction& tick, qreal seconds);
966 qreal tempo(const Fraction& tick) const;
967
defaultsRead()968 bool defaultsRead() const { return _defaultsRead; }
setDefaultsRead(bool b)969 void setDefaultsRead(bool b) { _defaultsRead = b; }
970 Text* getText(Tid subtype);
971
isPalette()972 bool isPalette() const { return _isPalette; }
setPaletteMode(bool palette)973 void setPaletteMode(bool palette) { _isPalette = palette; }
974
975 bool enableVerticalSpread() const;
976 void setEnableVerticalSpread(bool val);
977 qreal maxSystemDistance() const;
scoreOrder()978 ScoreOrder* scoreOrder() const { return _scoreOrder; }
setScoreOrder(ScoreOrder * order)979 void setScoreOrder(ScoreOrder* order) { _scoreOrder = order; }
980
981 void lassoSelect(const QRectF&);
982 void lassoSelectEnd();
983
984 Page* searchPage(const QPointF&) const;
985 QList<System*> searchSystem(const QPointF& p, const System* preferredSystem = nullptr, qreal spacingFactor = 0.5, qreal preferredSpacingFactor = 1.0) const;
986 Measure* searchMeasure(const QPointF& p, const System* preferredSystem = nullptr, qreal spacingFactor = 0.5, qreal preferredSpacingFactor = 1.0) const;
987
988 bool getPosition(Position* pos, const QPointF&, int voice) const;
989
990 void cmdDeleteTuplet(Tuplet*, bool replaceWithRest);
991
992 // void moveBracket(int staffIdx, int srcCol, int dstCol);
993 Measure* getCreateMeasure(const Fraction& tick);
994
995 void adjustBracketsDel(int sidx, int eidx);
996 void adjustBracketsIns(int sidx, int eidx);
997 void adjustKeySigs(int sidx, int eidx, KeyList km);
998
999 virtual inline const RepeatList& repeatList() const;
1000 virtual inline const RepeatList& repeatList2() const;
1001 qreal utick2utime(int tick) const;
1002 int utime2utick(qreal utime) const;
1003
1004 void nextInputPos(ChordRest* cr, bool);
1005 void cmdMirrorNoteHead();
1006
1007 qreal loWidth() const;
1008 qreal loHeight() const;
1009
npages()1010 virtual int npages() const { return _pages.size(); }
pageIdx(Page * page)1011 virtual int pageIdx(Page* page) const { return _pages.indexOf(page); }
pages()1012 virtual const QList<Page*>& pages() const { return _pages; }
pages()1013 virtual QList<Page*>& pages() { return _pages; }
1014
systems()1015 const QList<System*>& systems() const { return _systems; }
systems()1016 QList<System*>& systems() { return _systems; }
1017
measures()1018 MeasureBaseList* measures() { return &_measures; }
1019 bool checkHasMeasures() const;
1020 MeasureBase* first() const;
1021 MeasureBase* firstMM() const;
1022 MeasureBase* last() const;
1023 Ms::Measure* firstMeasure() const;
1024 Ms::Measure* firstMeasureMM() const;
1025 Ms::Measure* lastMeasure() const;
1026 Ms::Measure* lastMeasureMM() const;
1027 MeasureBase* measure(int idx) const;
1028 Measure* crMeasure(int idx) const;
1029
1030 Fraction endTick() const;
1031
1032 Segment* firstSegment(SegmentType s) const;
1033 Segment* firstSegmentMM(SegmentType s) const;
1034 Segment* lastSegment() const;
1035 Segment* lastSegmentMM() const;
1036
1037 void connectTies(bool silent=false);
1038
point(const Spatium sp)1039 qreal point(const Spatium sp) const { return sp.val() * spatium(); }
1040
1041 void scanElements(void* data, void (*func)(void*, Element*), bool all=true);
1042 void scanElementsInRange(void* data, void (*func)(void*, Element*), bool all = true);
fileDivision()1043 int fileDivision() const { return _fileDivision; } ///< division of current loading *.msc file
1044 void splitStaff(int staffIdx, int splitPoint);
tmpName()1045 QString tmpName() const { return _tmpName; }
setTmpName(const QString & s)1046 void setTmpName(const QString& s) { _tmpName = s; }
1047 bool processMidiInput();
1048 Lyrics* addLyrics();
1049 FiguredBass* addFiguredBass();
1050 void expandVoice(Segment* s, int track);
1051 void expandVoice();
1052
1053 Element* selectMove(const QString& cmd);
1054 Element* move(const QString& cmd);
1055 void cmdEnterRest(const TDuration& d);
1056 void enterRest(const TDuration& d, InputState* externalInputState = nullptr);
1057 void cmdAddInterval(int, const std::vector<Note*>&);
1058 void cmdCreateTuplet(ChordRest*, Tuplet*);
1059 void removeAudio();
1060
1061 void doLayout();
1062 void doLayoutRange(const Fraction&, const Fraction&);
1063 void layoutLinear(bool layoutAll, LayoutContext& lc);
1064
1065 void layoutChords1(Segment* segment, int staffIdx);
1066 qreal layoutChords2(std::vector<Note*>& notes, bool up);
1067 void layoutChords3(std::vector<Note*>&, const Staff*, Segment*);
1068
synthesizerState()1069 SynthesizerState& synthesizerState() { return _synthesizerState; }
1070 void setSynthesizerState(const SynthesizerState& s);
1071
1072 void updateHairpin(Hairpin*); // add/modify hairpin to pitchOffset list
1073
masterScore()1074 MasterScore* masterScore() const { return _masterScore; }
setMasterScore(MasterScore * s)1075 void setMasterScore(MasterScore* s) { _masterScore = s; }
1076 void createRevision();
1077 void writeSegments(XmlWriter& xml, int strack, int etrack, Segment* sseg, Segment* eseg, bool, bool);
1078
metaTags()1079 const QMap<QString, QString>& metaTags() const { return _metaTags; }
metaTags()1080 QMap<QString, QString>& metaTags() { return _metaTags; }
setMetaTags(const QMap<QString,QString> & t)1081 void setMetaTags(const QMap<QString,QString>& t) { _metaTags = t; }
1082
1083 //@ returns as a string the metatag named 'tag'
1084 QString metaTag(const QString& tag) const;
1085 //@ sets the metatag named 'tag' to 'val'
1086 void setMetaTag(const QString& tag, const QString& val);
1087
1088 void cmdSplitMeasure(ChordRest*);
1089 void splitMeasure(Segment*);
1090 void cmdJoinMeasure(Measure*, Measure*);
pageNumberOffset()1091 int pageNumberOffset() const { return _pageNumberOffset; }
setPageNumberOffset(int v)1092 void setPageNumberOffset(int v) { _pageNumberOffset = v; }
1093
mscoreVersion()1094 QString mscoreVersion() const { return _mscoreVersion; }
mscoreRevision()1095 int mscoreRevision() const { return _mscoreRevision; }
setMscoreVersion(const QString & val)1096 void setMscoreVersion(const QString& val) { _mscoreVersion = val; }
setMscoreRevision(int val)1097 void setMscoreRevision(int val) { _mscoreRevision = val; }
1098
currentLayerMask()1099 uint currentLayerMask() const { return _layer[_currentLayer].tags; }
setCurrentLayer(int val)1100 void setCurrentLayer(int val) { _currentLayer = val; }
currentLayer()1101 int currentLayer() const { return _currentLayer; }
layerTags()1102 QString* layerTags() { return _layerTags; }
layerTagComments()1103 QString* layerTagComments() { return _layerTagComments; }
layer()1104 QList<Layer>& layer() { return _layer; }
layer()1105 const QList<Layer>& layer() const { return _layer; }
tagIsValid(uint tag)1106 bool tagIsValid(uint tag) const { return tag & _layer[_currentLayer].tags; }
1107
addViewer(MuseScoreView * v)1108 void addViewer(MuseScoreView* v) { viewer.append(v); }
removeViewer(MuseScoreView * v)1109 void removeViewer(MuseScoreView* v) { viewer.removeAll(v); }
getViewer()1110 const QList<MuseScoreView*>& getViewer() const { return viewer; }
1111
layoutMode()1112 LayoutMode layoutMode() const { return _layoutMode; }
setLayoutMode(LayoutMode lm)1113 void setLayoutMode(LayoutMode lm) { _layoutMode = lm; }
1114
floatMode()1115 bool floatMode() const { return layoutMode() == LayoutMode::FLOAT; }
pageMode()1116 bool pageMode() const { return layoutMode() == LayoutMode::PAGE; }
lineMode()1117 bool lineMode() const { return layoutMode() == LayoutMode::LINE; }
systemMode()1118 bool systemMode() const { return layoutMode() == LayoutMode::SYSTEM; }
1119
1120 Tuplet* searchTuplet(XmlReader& e, int id);
1121 void cmdSelectAll();
1122 void cmdSelectSection();
1123 void respace(std::vector<ChordRest*>* elements);
1124 void transposeSemitone(int semitone);
1125 void transposeDiatonicAlterations(TransposeDirection direction);
1126 void insertMeasure(ElementType type, MeasureBase*, bool createEmptyMeasures = false, bool moveSignaturesClef = true);
audio()1127 Audio* audio() const { return _audio; }
setAudio(Audio * a)1128 void setAudio(Audio* a) { _audio = a; }
playMode()1129 PlayMode playMode() const { return _playMode; }
setPlayMode(PlayMode v)1130 void setPlayMode(PlayMode v) { _playMode = v; }
1131
1132 int linkId();
1133 void linkId(int);
getLinkId()1134 int getLinkId() const { return _linkId; }
1135
1136 QList<Score*> scoreList();
1137 bool switchLayer(const QString& s);
1138 //@ appends to the score a number of measures
1139 void appendMeasures(int);
1140
spanner()1141 const std::multimap<int, Spanner*>& spanner() const { return _spanner.map(); }
spannerMap()1142 SpannerMap& spannerMap() { return _spanner; }
1143 bool isSpannerStartEnd(const Fraction& tick, int track) const;
1144 void removeSpanner(Spanner*);
1145 void addSpanner(Spanner*);
1146 void cmdAddSpanner(Spanner* spanner, const QPointF& pos, bool firstStaffOnly = false);
1147 void cmdAddSpanner(Spanner* spanner, int staffIdx, Segment* startSegment, Segment* endSegment);
1148 void checkSpanner(const Fraction& startTick, const Fraction& lastTick);
unmanagedSpanners()1149 const std::set<Spanner*> unmanagedSpanners() { return _unmanagedSpanner; }
1150 void addUnmanagedSpanner(Spanner*);
1151 void removeUnmanagedSpanner(Spanner*);
1152
1153 Hairpin* addHairpin(HairpinType, const Fraction& tickStart, const Fraction& tickEnd, int track);
1154 Hairpin* addHairpin(HairpinType, ChordRest* cr1, ChordRest* cr2 = nullptr, bool toCr2End = true);
1155
1156 ChordRest* findCR(Fraction tick, int track) const;
1157 ChordRest* findCRinStaff(const Fraction& tick, int staffIdx) const;
1158 void insertTime(const Fraction& tickPos, const Fraction&tickLen);
1159
scoreFont()1160 ScoreFont* scoreFont() const { return _scoreFont; }
setScoreFont(ScoreFont * f)1161 void setScoreFont(ScoreFont* f) { _scoreFont = f; }
1162
noteHeadWidth()1163 qreal noteHeadWidth() const { return _noteHeadWidth; }
setNoteHeadWidth(qreal n)1164 void setNoteHeadWidth( qreal n) { _noteHeadWidth = n; }
1165
1166 QList<int> uniqueStaves() const;
1167 void transpositionChanged(Part*, Interval, Fraction tickStart = { 0, 1 }, Fraction tickEnd = { -1, 1 } );
1168
1169 void moveUp(ChordRest*);
1170 void moveDown(ChordRest*);
1171 Element* upAlt(Element*);
1172 Note* upAltCtrl(Note*) const;
1173 Element* downAlt(Element*);
1174 Note* downAltCtrl(Note*) const;
1175
1176 Element* firstElement(bool frame = true);
1177 Element* lastElement(bool frame = true);
1178
1179 int nmeasures() const;
1180 bool hasLyrics();
1181 bool hasHarmonies();
1182 int lyricCount();
1183 int harmonyCount();
1184 QString extractLyrics();
1185 int keysig();
1186 int duration();
1187 int durationWithoutRepeats();
1188
1189 void cmdInsertClef(Clef* clef, ChordRest* cr);
1190
1191 void cmdExplode();
1192 void cmdImplode();
1193 void cmdSlashFill();
1194 void cmdSlashRhythm();
1195 void cmdResequenceRehearsalMarks();
1196 void cmdExchangeVoice(int, int);
1197 void cmdRemoveEmptyTrailingMeasures();
1198 void cmdRealizeChordSymbols(bool lit = true, Voicing v = Voicing(-1), HDuration durationType = HDuration(-1));
1199
1200 Measure* firstTrailingMeasure(ChordRest** cr = nullptr);
1201 ChordRest* cmdTopStaff(ChordRest* cr = nullptr);
1202
setAccessibleInfo(QString s)1203 void setAccessibleInfo(QString s) { accInfo = s.remove(":").remove(";"); }
accessibleInfo()1204 QString accessibleInfo() const { return accInfo; }
1205
setAccessibleMessage(QString s)1206 void setAccessibleMessage(QString s) { accMessage = s; } // retain ':' and ';'
accessibleMessage()1207 QString accessibleMessage() const { return accMessage; }
1208
1209 QImage createThumbnail();
1210 QString createRehearsalMarkText(RehearsalMark* current) const;
1211 QString nextRehearsalMarkText(RehearsalMark* previous, RehearsalMark* current) const;
1212
1213 //@ ??
1214 // Q_INVOKABLE void cropPage(qreal margins);
1215 bool sanityCheck(const QString& name = QString());
1216
1217 bool checkKeys();
1218 bool checkClefs();
1219
1220 void switchToPageMode();
1221
1222 virtual QVariant getProperty(Pid) const override;
1223 virtual bool setProperty(Pid, const QVariant&) override;
1224 virtual QVariant propertyDefault(Pid) const override;
1225
1226 virtual inline QQueue<MidiInputEvent>* midiInputQueue();
1227 virtual inline std::list<MidiInputEvent>* activeMidiPitches();
1228
1229 virtual QString title() const;
1230
1231 void cmdTimeDelete();
1232 void localTimeDelete();
1233 void globalTimeDelete();
1234
1235 bool isTopScore() const;
1236
headerText(int index)1237 Text* headerText(int index) const { return _headersText[index]; }
footerText(int index)1238 Text* footerText(int index) const { return _footersText[index]; }
setHeaderText(Text * t,int index)1239 void setHeaderText(Text* t, int index) { _headersText.at(index) = t; }
setFooterText(Text * t,int index)1240 void setFooterText(Text* t, int index) { _footersText.at(index) = t; }
1241
1242 void cmdAddPitch(int note, bool addFlag, bool insert);
1243 void forAllLyrics(std::function<void(Lyrics*)> f);
1244
1245 System* getNextSystem(LayoutContext&);
1246 void hideEmptyStaves(System* system, bool isFirstSystem);
1247 void layoutLyrics(System*);
1248 void createBeams(LayoutContext&, Measure*);
1249
defaultTempo()1250 constexpr static double defaultTempo() { return _defaultTempo; }
1251
1252 friend class ChangeSynthesizerState;
1253 friend class Chord;
1254 };
1255
toScore(ScoreElement * e)1256 static inline Score* toScore(ScoreElement* e) {
1257 Q_ASSERT(!e || e->isScore());
1258 return static_cast<Score*>(e);
1259 }
toScore(const ScoreElement * e)1260 static inline const Score* toScore(const ScoreElement* e) {
1261 Q_ASSERT(!e || e->isScore());
1262 return static_cast<const Score*>(e);
1263 }
1264
1265 //---------------------------------------------------------
1266 // MasterScore
1267 //---------------------------------------------------------
1268
1269 class MasterScore : public Score {
1270 Q_OBJECT
1271 TimeSigMap* _sigmap;
1272 TempoMap* _tempomap;
1273 RepeatList* _repeatList;
1274 RepeatList* _repeatList2;
1275 bool _expandRepeats { MScore::playRepeats };
1276 bool _playlistDirty { true };
1277 QList<Excerpt*> _excerpts;
1278 std::vector<PartChannelSettingsLink> _playbackSettingsLinks;
1279 Score* _playbackScore = nullptr;
1280 Revisions* _revisions;
1281 MasterScore* _next { 0 };
1282 MasterScore* _prev { 0 };
1283 Movements* _movements { 0 };
1284
1285 bool _readOnly { false };
1286
1287 CmdState _cmdState; // modified during cmd processing
1288
1289 Omr* _omr { 0 };
1290 bool _showOmr { false };
1291
1292 std::shared_ptr<Avs::AvsOmr> _avsOmr { nullptr };
1293
1294 Fraction _pos[3]; ///< 0 - current, 1 - left loop, 2 - right loop
1295
1296 int _midiPortCount { 0 }; // A count of JACK/ALSA midi out ports
1297 QQueue<MidiInputEvent> _midiInputQueue; // MIDI events that have yet to be processed
1298 std::list<MidiInputEvent> _activeMidiPitches; // MIDI keys currently being held down
1299 std::vector<MidiMapping> _midiMapping;
1300 bool isSimpleMidiMaping; // midi mapping is simple if all ports and channels
1301 // don't decrease and don't have gaps
1302 QSet<int> occupiedMidiChannels; // each entry is port*16+channel, port range: 0-inf, channel: 0-15
1303 unsigned int searchMidiMappingFrom; // makes getting next free MIDI mapping faster
1304
1305 void parseVersion(const QString&);
1306 void reorderMidiMapping();
1307 void rebuildExcerptsMidiMapping();
1308 void removeDeletedMidiMapping();
1309 int updateMidiMapping();
1310
1311 QFileInfo _sessionStartBackupInfo;
1312 QFileInfo info;
1313
1314 bool read(XmlReader&);
setPrev(MasterScore * s)1315 void setPrev(MasterScore* s) { _prev = s; }
setNext(MasterScore * s)1316 void setNext(MasterScore* s) { _next = s; }
1317
1318 public:
1319 MasterScore();
1320 MasterScore(const MStyle&);
1321 virtual ~MasterScore();
1322 MasterScore* clone();
1323
isMaster()1324 virtual bool isMaster() const override { return true; }
readOnly()1325 virtual bool readOnly() const override { return _readOnly; }
setReadOnly(bool ro)1326 void setReadOnly(bool ro) { _readOnly = ro; }
undoStack()1327 virtual UndoStack* undoStack() const override { return _movements->undo(); }
sigmap()1328 virtual TimeSigMap* sigmap() const override { return _sigmap; }
tempomap()1329 virtual TempoMap* tempomap() const override { return _tempomap; }
1330
playlistDirty()1331 virtual bool playlistDirty() const override { return _playlistDirty; }
1332 virtual void setPlaylistDirty() override;
setPlaylistClean()1333 void setPlaylistClean() { _playlistDirty = false; }
1334
1335 void setExpandRepeats(bool expandRepeats);
1336 void updateRepeatListTempo();
1337 virtual const RepeatList& repeatList() const override;
1338 virtual const RepeatList& repeatList2() const override;
1339
excerpts()1340 virtual QList<Excerpt*>& excerpts() override { return _excerpts; }
excerpts()1341 virtual const QList<Excerpt*>& excerpts() const override { return _excerpts; }
midiInputQueue()1342 virtual QQueue<MidiInputEvent>* midiInputQueue() override { return &_midiInputQueue; }
activeMidiPitches()1343 virtual std::list<MidiInputEvent>* activeMidiPitches() override { return &_activeMidiPitches; }
1344
next()1345 MasterScore* next() const { return _next; }
prev()1346 MasterScore* prev() const { return _prev; }
movements()1347 virtual Movements* movements() override { return _movements; }
movements()1348 virtual const Movements* movements() const override { return _movements; }
1349 void setMovements(Movements* m);
1350 void addMovement(MasterScore* score);
1351
1352 virtual void setUpdateAll() override;
1353
1354 void setLayoutAll(int staff = -1, const Element* e = nullptr);
1355 void setLayout(const Fraction& tick, int staff, const Element* e = nullptr);
1356 void setLayout(const Fraction& tick1, const Fraction& tick2, int staff1, int staff2, const Element* e = nullptr);
1357
cmdState()1358 virtual CmdState& cmdState() override { return _cmdState; }
cmdState()1359 const CmdState& cmdState() const override { return _cmdState; }
addLayoutFlags(LayoutFlags val)1360 virtual void addLayoutFlags(LayoutFlags val) override { _cmdState.layoutFlags |= val; }
setInstrumentsChanged(bool val)1361 virtual void setInstrumentsChanged(bool val) override { _cmdState._instrumentsChanged = val; }
1362
setExcerptsChanged(bool val)1363 void setExcerptsChanged(bool val) { _cmdState._excerptsChanged = val; }
excerptsChanged()1364 bool excerptsChanged() const { return _cmdState._excerptsChanged; }
instrumentsChanged()1365 bool instrumentsChanged() const { return _cmdState._instrumentsChanged; }
1366
revisions()1367 Revisions* revisions() { return _revisions; }
1368
1369 bool isSavable() const;
1370 void setTempomap(TempoMap* tm);
1371
1372 bool saveFile(bool generateBackup = true);
1373 FileError read1(XmlReader&, bool ignoreVersionError);
1374 FileError loadCompressedMsc(QIODevice*, bool ignoreVersionError);
1375 FileError loadMsc(QString name, bool ignoreVersionError);
1376 FileError loadMsc(QString name, QIODevice*, bool ignoreVersionError);
1377 FileError read114(XmlReader&);
1378 FileError read206(XmlReader&);
1379 FileError read302(XmlReader&);
1380 QByteArray readToBuffer();
1381 QByteArray readCompressedToBuffer();
1382 int readStyleDefaultsVersion();
1383 int styleDefaultByMscVersion(const int mscVer) const;
1384
omr()1385 Omr* omr() const { return _omr; }
setOmr(Omr * o)1386 void setOmr(Omr* o) { _omr = o; }
1387 void removeOmr();
showOmr()1388 bool showOmr() const { return _showOmr; }
setShowOmr(bool v)1389 void setShowOmr(bool v) { _showOmr = v; }
1390
avsOmr()1391 std::shared_ptr<Avs::AvsOmr> avsOmr() const { return _avsOmr; }
setAvsOmr(std::shared_ptr<Avs::AvsOmr> omr)1392 void setAvsOmr(std::shared_ptr<Avs::AvsOmr> omr) { _avsOmr = omr; }
1393
midiPortCount()1394 int midiPortCount() const { return _midiPortCount; }
setMidiPortCount(int val)1395 void setMidiPortCount(int val) { _midiPortCount = val; }
midiMapping()1396 std::vector<MidiMapping>& midiMapping() { return _midiMapping; }
midiMapping(int channel)1397 MidiMapping* midiMapping(int channel) { return &_midiMapping[channel]; }
1398 void addMidiMapping(Channel* channel, Part* part, int midiPort, int midiChannel);
1399 void updateMidiMapping(Channel* channel, Part* part, int midiPort, int midiChannel);
midiPort(int idx)1400 int midiPort(int idx) const { return _midiMapping[idx].port(); }
midiChannel(int idx)1401 int midiChannel(int idx) const { return _midiMapping[idx].channel(); }
1402 void rebuildMidiMapping();
1403 void checkMidiMapping();
exportMidiMapping()1404 bool exportMidiMapping() { return !isSimpleMidiMaping; }
1405 int getNextFreeMidiMapping(int p = -1, int ch = -1);
1406 int getNextFreeDrumMidiMapping();
enqueueMidiEvent(MidiInputEvent ev)1407 void enqueueMidiEvent(MidiInputEvent ev) { _midiInputQueue.enqueue(ev); }
1408 void rebuildAndUpdateExpressive(Synthesizer* synth);
1409 void updateExpressive(Synthesizer* synth);
1410 void updateExpressive(Synthesizer* synth, bool expressive, bool force = false);
1411 void setSoloMute();
1412
1413 using Score::pos;
pos(POS pos)1414 Fraction pos(POS pos) const { return _pos[int(pos)]; }
1415 void setPos(POS pos, Fraction tick);
1416
1417 void addExcerpt(Excerpt*);
1418 void removeExcerpt(Excerpt*);
1419 void deleteExcerpt(Excerpt*);
1420
1421 void setPlaybackScore(Score*);
playbackScore()1422 Score* playbackScore() { return _playbackScore; }
playbackScore()1423 const Score* playbackScore() const { return _playbackScore; }
playbackChannel(const Channel * c)1424 Channel* playbackChannel(const Channel* c) { return _midiMapping[c->channel()].articulation(); }
playbackChannel(const Channel * c)1425 const Channel* playbackChannel(const Channel* c) const { return _midiMapping[c->channel()].articulation(); }
1426
1427 MasterScore * unrollRepeats();
1428
fileInfo()1429 QFileInfo* fileInfo() { return &info; }
fileInfo()1430 const QFileInfo* fileInfo() const { return &info; }
1431 void setName(const QString&);
1432
sessionStartBackupInfo()1433 const QFileInfo& sessionStartBackupInfo() const { return _sessionStartBackupInfo; }
1434
1435 virtual QString title() const override;
1436
pageIdx(Page * page)1437 virtual int pageIdx(Page* page) const override { return movements()->pageIdx(page); }
pages()1438 virtual const QList<Page*>& pages() const override { return movements()->pages(); }
pages()1439 virtual QList<Page*>& pages() override { return movements()->pages(); }
npages()1440 virtual int npages() const override { return movements()->npages(); }
1441
style()1442 virtual MStyle& style() override { return movements()->style(); }
style()1443 virtual const MStyle& style() const override { return movements()->style(); }
1444 };
1445
1446 //---------------------------------------------------------
1447 // ScoreLoad
1448 //---------------------------------------------------------
1449
1450 class ScoreLoad {
1451 static int _loading;
1452
1453 public:
ScoreLoad()1454 ScoreLoad() { ++_loading; }
~ScoreLoad()1455 ~ScoreLoad() { --_loading; }
loading()1456 static bool loading() { return _loading > 0; }
1457 };
1458
undoStack()1459 inline UndoStack* Score::undoStack() const { return _masterScore->undoStack(); }
repeatList()1460 inline const RepeatList& Score::repeatList() const { return _masterScore->repeatList(); }
repeatList2()1461 inline const RepeatList& Score::repeatList2() const { return _masterScore->repeatList2(); }
tempomap()1462 inline TempoMap* Score::tempomap() const { return _masterScore->tempomap(); }
sigmap()1463 inline TimeSigMap* Score::sigmap() const { return _masterScore->sigmap(); }
excerpts()1464 inline QList<Excerpt*>& Score::excerpts() { return _masterScore->excerpts(); }
excerpts()1465 inline const QList<Excerpt*>& Score::excerpts() const { return _masterScore->excerpts(); }
midiInputQueue()1466 inline QQueue<MidiInputEvent>* Score::midiInputQueue() { return _masterScore->midiInputQueue(); }
activeMidiPitches()1467 inline std::list<MidiInputEvent>* Score::activeMidiPitches() { return _masterScore->activeMidiPitches(); }
1468
setUpdateAll()1469 inline void Score::setUpdateAll() { _masterScore->setUpdateAll(); }
1470
setLayoutAll(int staff,const Element * e)1471 inline void Score::setLayoutAll(int staff, const Element* e) { _masterScore->setLayoutAll(staff, e); }
setLayout(const Fraction & tick,int staff,const Element * e)1472 inline void Score::setLayout(const Fraction& tick, int staff, const Element* e) { _masterScore->setLayout(tick, staff, e); }
setLayout(const Fraction & tick1,const Fraction & tick2,int staff1,int staff2,const Element * e)1473 inline void Score::setLayout(const Fraction& tick1, const Fraction& tick2, int staff1, int staff2, const Element* e) { _masterScore->setLayout(tick1, tick2, staff1, staff2, e); }
1474
cmdState()1475 inline CmdState& Score::cmdState() { return _masterScore->cmdState(); }
cmdState()1476 inline const CmdState& Score::cmdState() const { return _masterScore->cmdState(); }
addLayoutFlags(LayoutFlags f)1477 inline void Score::addLayoutFlags(LayoutFlags f) { _masterScore->addLayoutFlags(f); }
setInstrumentsChanged(bool v)1478 inline void Score::setInstrumentsChanged(bool v) { _masterScore->setInstrumentsChanged(v); }
movements()1479 inline Movements* Score::movements() { return _masterScore->movements(); }
movements()1480 inline const Movements* Score::movements() const { return _masterScore->movements(); }
1481
pos(POS pos)1482 inline Fraction Score::pos(POS pos) const { return _masterScore->pos(pos); }
setPos(POS pos,Fraction tick)1483 inline void Score::setPos(POS pos, Fraction tick) { _masterScore->setPos(pos, tick); }
1484
1485 extern MasterScore* gscore;
1486
1487 extern MStyle* styleDefaults114();
1488 extern MStyle* styleDefaults206();
1489 extern MStyle* styleDefaults301();
1490
1491 Q_DECLARE_OPERATORS_FOR_FLAGS(LayoutFlags);
1492
1493 } // namespace Ms
1494
1495
1496 #endif
1497
1498