Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-Studio-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2021 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 : #pragma once
23 :
24 : #include "containers.h"
25 :
26 : #include "engraving/dom/select.h"
27 : #include "engraving/dom/score.h"
28 :
29 : namespace mu::engraving::write {
30 : struct WriteRange {
31 : MeasureBase* startMeasure = nullptr;
32 : MeasureBase* endMeasure = nullptr;
33 : staff_idx_t startStaffIdx = muse::nidx;
34 : staff_idx_t endStaffIdx = muse::nidx;
35 :
36 : bool operator==(const WriteRange& r) const
37 : {
38 : return startMeasure == r.startMeasure
39 : && endMeasure == r.endMeasure
40 : && startStaffIdx == r.startStaffIdx
41 : && endStaffIdx == r.endStaffIdx;
42 : }
43 : };
44 :
45 : class WriteContext
46 : {
47 : public:
48 :
49 2039 : WriteContext(const Score* s, bool clipboardMode = false)
50 2039 : : m_score(s), _clipboardmode(clipboardMode) {}
51 :
52 : std::shared_ptr<IEngravingConfiguration> configuration() const;
53 :
54 312414 : Fraction curTick() const { return _curTick; }
55 52901 : void setCurTick(const Fraction& v) { _curTick = v; }
56 32899 : void incCurTick(const Fraction& v) { _curTick += v; }
57 :
58 : Fraction tickDiff() const { return _tickDiff; }
59 1969 : void setTickDiff(const Fraction& v) { _tickDiff = v; }
60 :
61 94756 : track_idx_t curTrack() const { return _curTrack; }
62 41173 : void setCurTrack(track_idx_t v) { _curTrack = v; }
63 3044 : int trackDiff() const { return _trackDiff; }
64 1388 : void setTrackDiff(int v) { _trackDiff = v; }
65 :
66 36460 : bool clipboardmode() const { return _clipboardmode; }
67 :
68 599 : const std::optional<Fraction>& firstClipboardTick() const { return _firstClipboardTick; }
69 81 : void setFirstClipboardTick(const Fraction& v) { _firstClipboardTick = v; }
70 :
71 81 : void setFilter(const SelectionFilter& f) { _filter = f; }
72 : bool canWrite(const EngravingItem*) const;
73 : bool canWriteNoteIdx(size_t noteIdx, size_t totalNotesInChord) const;
74 : bool canWriteVoice(track_idx_t track) const;
75 :
76 23719 : bool shouldWriteRange() const { return _range.has_value(); }
77 0 : const std::optional<WriteRange>& range() const { return _range; }
78 0 : void setRange(const WriteRange& v) { _range = v; }
79 :
80 : inline bool operator==(const WriteContext& c) const
81 : {
82 : return _curTick == c._curTick
83 : && _tickDiff == c._tickDiff
84 : && _curTrack == c._curTrack
85 : && _trackDiff == c._trackDiff
86 : && _clipboardmode == c._clipboardmode
87 : && _filter == c._filter
88 : && _range == c._range
89 : && _firstClipboardTick == c._firstClipboardTick;
90 : }
91 :
92 : inline bool operator!=(const WriteContext& c) const { return !this->operator==(c); }
93 :
94 : private:
95 :
96 : const Score* m_score = nullptr;
97 :
98 : Fraction _curTick { 0, 1 }; // used to optimize output
99 : Fraction _tickDiff { 0, 1 };
100 : track_idx_t _curTrack = muse::nidx;
101 : int _trackDiff { 0 }; // saved track is curTrack-trackDiff
102 :
103 : bool _clipboardmode { false }; // used to modify write() behaviour
104 :
105 : std::optional<WriteRange> _range;
106 : std::optional<SelectionFilter> _filter;
107 : std::optional<Fraction> _firstClipboardTick;
108 : };
109 : }
|