1 //=============================================================================
2 // MuseScore
3 // Linux Music Score Editor
4 //
5 // Copyright (C) 2002-2011 Werner Schweer and others
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 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //=============================================================================
19
20 #include "scoreview.h"
21 #include "libmscore/note.h"
22 #include "libmscore/sym.h"
23 #include "libmscore/note.h"
24 #include "libmscore/score.h"
25 #include "libmscore/rest.h"
26 #include "libmscore/chord.h"
27 #include "libmscore/select.h"
28 #include "libmscore/input.h"
29 #include "libmscore/key.h"
30 #include "libmscore/measure.h"
31 #include "musescore.h"
32 #include "libmscore/slur.h"
33 #include "libmscore/tuplet.h"
34 #include "libmscore/text.h"
35 #include "libmscore/staff.h"
36 #include "libmscore/part.h"
37 #include "drumtools.h"
38 #include "preferences.h"
39 #include "libmscore/segment.h"
40 #include "libmscore/mscore.h"
41 #include "libmscore/stafftype.h"
42 #include "texttools.h"
43
44 namespace Ms {
45
46 //---------------------------------------------------------
47 // Canvas::editCmd
48 //---------------------------------------------------------
49
editCmd(const QString & cmd)50 void ScoreView::editCmd(const QString& cmd)
51 {
52 if (!editData.element)
53 return;
54
55 if (editData.element->isLyrics()) {
56 if (cmd == "next-lyric")
57 lyricsTab(false, true, false);
58 else if (cmd == "prev-lyric")
59 lyricsTab(true, true, false);
60 }
61 }
62
63 //---------------------------------------------------------
64 // updateInputState
65 //---------------------------------------------------------
66
updateInputState(Score * score)67 void MuseScore::updateInputState(Score* score)
68 {
69 InputState& is = score->inputState();
70 if (is.noteEntryMode()) {
71 if (is.usingNoteEntryMethod(NoteEntryMethod::REPITCH)) {
72 TDuration d = is.cr() ? is.cr()->durationType() : TDuration::DurationType::V_QUARTER;
73 if (!d.isValid() || d.isZero() || d.isMeasure())
74 d = TDuration::DurationType::V_QUARTER;
75 is.setDuration(d);
76 }
77 Staff* staff = score->staff(is.track() / VOICES);
78
79 //if not tab, note entry depends on instrument (override StaffGroup)
80 StaffGroup staffGroup = staff->staffType(is.tick())->group();
81 if (staffGroup != StaffGroup::TAB)
82 staffGroup = staff->part()->instrument(is.tick())->useDrumset() ? StaffGroup::PERCUSSION : StaffGroup::STANDARD;
83
84 switch (staffGroup) {
85 case StaffGroup::STANDARD:
86 changeState(STATE_NOTE_ENTRY_STAFF_PITCHED);
87 break;
88 case StaffGroup::TAB:
89 changeState(STATE_NOTE_ENTRY_STAFF_TAB);
90 break;
91 case StaffGroup::PERCUSSION:
92 changeState(STATE_NOTE_ENTRY_STAFF_DRUM);
93 break;
94 }
95 }
96 else
97 is.update(score->selection());
98
99 getAction("pad-rest")->setChecked(is.rest());
100 getAction("pad-dot")->setChecked(is.duration().dots() == 1);
101 getAction("pad-dotdot")->setChecked(is.duration().dots() == 2);
102 getAction("pad-dot3")->setChecked(is.duration().dots() == 3);
103 getAction("pad-dot4")->setChecked(is.duration().dots() == 4);
104 if ((mscore->state() & STATE_NORMAL) | (mscore->state() & STATE_NOTE_ENTRY)) {
105 getAction("pad-dot")->setEnabled(true);
106 getAction("pad-dotdot")->setEnabled(true);
107 getAction("pad-dot3")->setEnabled(true);
108 getAction("pad-dot4")->setEnabled(true);
109 }
110 switch (is.duration().type()) {
111 case TDuration::DurationType::V_1024TH:
112 getAction("pad-dot")->setChecked(false);
113 getAction("pad-dot")->setEnabled(false);
114 // fall through
115 case TDuration::DurationType::V_512TH:
116 getAction("pad-dotdot")->setChecked(false);
117 getAction("pad-dotdot")->setEnabled(false);
118 // fall through
119 case TDuration::DurationType::V_256TH:
120 getAction("pad-dot3")->setChecked(false);
121 getAction("pad-dot3")->setEnabled(false);
122 // fall through
123 case TDuration::DurationType::V_128TH:
124 getAction("pad-dot4")->setChecked(false);
125 getAction("pad-dot4")->setEnabled(false);
126 default:
127 break;
128 }
129
130 getAction("note-longa")->setChecked(is.duration() == TDuration::DurationType::V_LONG);
131 getAction("note-breve")->setChecked(is.duration() == TDuration::DurationType::V_BREVE);
132 getAction("pad-note-1")->setChecked(is.duration() == TDuration::DurationType::V_WHOLE);
133 getAction("pad-note-2")->setChecked(is.duration() == TDuration::DurationType::V_HALF);
134 getAction("pad-note-4")->setChecked(is.duration() == TDuration::DurationType::V_QUARTER);
135 getAction("pad-note-8")->setChecked(is.duration() == TDuration::DurationType::V_EIGHTH);
136 getAction("pad-note-16")->setChecked(is.duration() == TDuration::DurationType::V_16TH);
137 getAction("pad-note-32")->setChecked(is.duration() == TDuration::DurationType::V_32ND);
138 getAction("pad-note-64")->setChecked(is.duration() == TDuration::DurationType::V_64TH);
139 getAction("pad-note-128")->setChecked(is.duration() == TDuration::DurationType::V_128TH);
140 getAction("pad-note-256")->setChecked(is.duration() == TDuration::DurationType::V_256TH);
141 getAction("pad-note-512")->setChecked(is.duration() == TDuration::DurationType::V_512TH);
142 getAction("pad-note-1024")->setChecked(is.duration() == TDuration::DurationType::V_1024TH);
143
144 getAction("sharp2")->setChecked(is.accidentalType() == AccidentalType::SHARP2);
145 getAction("sharp")->setChecked(is.accidentalType() == AccidentalType::SHARP);
146 getAction("nat")->setChecked(is.accidentalType() == AccidentalType::NATURAL);
147 getAction("flat")->setChecked(is.accidentalType() == AccidentalType::FLAT);
148 getAction("flat2")->setChecked(is.accidentalType() == AccidentalType::FLAT2);
149
150 // uncheck all voices if multi-selection
151 int voice = score->selection().isSingle() ? is.voice() : -1;
152 getAction("voice-1")->setChecked(voice == 0);
153 getAction("voice-2")->setChecked(voice == 1);
154 getAction("voice-3")->setChecked(voice == 2);
155 getAction("voice-4")->setChecked(voice == 3);
156
157 QAction* tieAction = getAction("tie");
158 if (is.noteEntryMode())
159 tieAction->setChecked(false);
160 else {
161 const std::vector<Note*> cmdTieNotes = Score::cmdTieNoteList(score->selection(), false);
162 bool onlyTiedNotes = !cmdTieNotes.empty();
163 for (Note* n : cmdTieNotes) {
164 if (!n->tieFor()) {
165 onlyTiedNotes = false;
166 break;
167 }
168 }
169 tieAction->setChecked(onlyTiedNotes);
170 }
171
172 getAction("acciaccatura")->setChecked(is.noteType() == NoteType::ACCIACCATURA);
173 getAction("appoggiatura")->setChecked(is.noteType() == NoteType::APPOGGIATURA);
174 getAction("grace4")->setChecked(is.noteType() == NoteType::GRACE4);
175 getAction("grace16")->setChecked(is.noteType() == NoteType::GRACE16);
176 getAction("grace32")->setChecked(is.noteType() == NoteType::GRACE32);
177 getAction("grace8after")->setChecked(is.noteType() == NoteType::GRACE8_AFTER);
178 getAction("grace16after")->setChecked(is.noteType() == NoteType::GRACE16_AFTER);
179 getAction("grace32after")->setChecked(is.noteType() == NoteType::GRACE32_AFTER);
180 getAction("beam-start")->setChecked(is.beamMode() == Beam::Mode::BEGIN);
181 getAction("beam-mid")->setChecked(is.beamMode() == Beam::Mode::MID);
182 getAction("no-beam")->setChecked(is.beamMode() == Beam::Mode::NONE);
183 getAction("beam32")->setChecked(is.beamMode() == Beam::Mode::BEGIN32);
184 getAction("beam64")->setChecked(is.beamMode() == Beam::Mode::BEGIN64);
185 getAction("auto-beam")->setChecked(is.beamMode() == Beam::Mode::AUTO);
186
187 if(is.noteEntryMode() && !is.rest())
188 updateShadowNote();
189 }
190 }
191
192