1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
|
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2002-2011 Werner Schweer
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=============================================================================
#include "musescore.h"
#include "scoreview.h"
#include "libmscore/chordrest.h"
#include "libmscore/lyrics.h"
#include "libmscore/score.h"
#include "libmscore/segment.h"
namespace Ms {
//---------------------------------------------------------
// lyricsUpDown
//---------------------------------------------------------
void ScoreView::lyricsUpDown(bool up, bool end)
{
Lyrics* lyrics = static_cast<Lyrics*>(editObject);
int track = lyrics->track();
ChordRest* cr = lyrics->chordRest();
int verse = lyrics->no();
const QList<Lyrics*>* ll = &lyrics->chordRest()->lyricsList();
if (up) {
if (verse == 0)
return;
--verse;
}
else {
++verse;
if (verse >= ll->size())
return;
}
endEdit();
_score->startCmd();
lyrics = ll->value(verse);
if (!lyrics) {
lyrics = new Lyrics(_score);
lyrics->setTrack(track);
lyrics->setParent(cr);
lyrics->setNo(verse);
_score->undoAddElement(lyrics);
}
_score->select(lyrics, SelectType::SINGLE, 0);
startEdit(lyrics, Grip::NO_GRIP);
mscore->changeState(mscoreState());
adjustCanvasPosition(lyrics, false);
if (end) {
((Lyrics*)editObject)->movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
((Lyrics*)editObject)->movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
}
else {
((Lyrics*)editObject)->movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
((Lyrics*)editObject)->movePosition(QTextCursor::Start, QTextCursor::KeepAnchor);
}
_score->setLayoutAll(true);
_score->update();
}
//---------------------------------------------------------
// lyricsTab
//---------------------------------------------------------
void ScoreView::lyricsTab(bool back, bool end, bool moveOnly)
{
Lyrics* lyrics = (Lyrics*)editObject;
int track = lyrics->track();
Segment* segment = lyrics->segment();
int verse = lyrics->no();
Segment* nextSegment = segment;
if (back) {
// search prev chord
while ((nextSegment = nextSegment->prev1(Segment::Type::ChordRest))) {
Element* el = nextSegment->element(track);
if (el && el->type() == Element::Type::CHORD)
break;
}
}
else {
// search next chord
while ((nextSegment = nextSegment->next1(Segment::Type::ChordRest))) {
Element* el = nextSegment->element(track);
if (el && el->type() == Element::Type::CHORD)
break;
}
}
if (nextSegment == 0)
return;
endEdit();
// look for the lyrics we are moving from; may be the current lyrics or a previous one
// if we are skipping several chords with spaces
Lyrics* fromLyrics = 0;
if (!back) {
while (segment) {
const QList<Lyrics*>* nll = segment->lyricsList(track);
if (nll) {
fromLyrics = nll->value(verse);
if (fromLyrics)
break;
}
segment = segment->prev1(Segment::Type::ChordRest);
}
}
const QList<Lyrics*>* ll = nextSegment->lyricsList(track);
if (ll == 0) {
qDebug("no next lyrics list: %s", nextSegment->element(track)->name());
return;
}
Lyrics* toLyrics = ll->value(verse);
bool newLyrics = false;
if (!toLyrics) {
toLyrics = new Lyrics(_score);
toLyrics->setTrack(track);
ChordRest* cr = static_cast<ChordRest*>(nextSegment->element(track));
toLyrics->setParent(cr);
toLyrics->setNo(verse);
toLyrics->setSyllabic(Lyrics::Syllabic::SINGLE);
newLyrics = true;
}
_score->startCmd();
if (fromLyrics && !moveOnly) {
switch(toLyrics->syllabic()) {
// as we arrived at toLyrics by a [Space], it can be the beginning
// of a multi-syllable, but cannot have syllabic dashes before
case Lyrics::Syllabic::SINGLE:
case Lyrics::Syllabic::BEGIN:
break;
case Lyrics::Syllabic::END:
toLyrics->undoChangeProperty(P_ID::SYLLABIC, int(Lyrics::Syllabic::SINGLE));
break;
case Lyrics::Syllabic::MIDDLE:
toLyrics->undoChangeProperty(P_ID::SYLLABIC, int(Lyrics::Syllabic::BEGIN));
break;
}
// as we moved away from fromLyrics by a [Space], it can be
// the end of a multi-syllable, but cannot have syllabic dashes after
switch(fromLyrics->syllabic()) {
case Lyrics::Syllabic::SINGLE:
case Lyrics::Syllabic::END:
break;
case Lyrics::Syllabic::BEGIN:
fromLyrics->undoChangeProperty(P_ID::SYLLABIC, int(Lyrics::Syllabic::SINGLE));
break;
case Lyrics::Syllabic::MIDDLE:
fromLyrics->undoChangeProperty(P_ID::SYLLABIC, int(Lyrics::Syllabic::END));
break;
}
// for the same reason, it cannot have a melisma
fromLyrics->undoChangeProperty(P_ID::LYRIC_TICKS, 0);
}
if (newLyrics)
_score->undoAddElement(toLyrics);
_score->select(toLyrics, SelectType::SINGLE, 0);
startEdit(toLyrics, Grip::NO_GRIP);
mscore->changeState(mscoreState());
adjustCanvasPosition(toLyrics, false);
if (end) {
((Lyrics*)editObject)->movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
((Lyrics*)editObject)->movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
}
else {
((Lyrics*)editObject)->movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
((Lyrics*)editObject)->movePosition(QTextCursor::Start, QTextCursor::KeepAnchor);
}
_score->setLayoutAll(true);
_score->update();
}
//---------------------------------------------------------
// lyricsMinus
//---------------------------------------------------------
void ScoreView::lyricsMinus()
{
Lyrics* lyrics = static_cast<Lyrics*>(editObject);
int track = lyrics->track();
Segment* segment = lyrics->segment();
int verse = lyrics->no();
endEdit();
// search next chord
Segment* nextSegment = segment;
while ((nextSegment = nextSegment->next1(Segment::Type::ChordRest))) {
Element* el = nextSegment->element(track);
if (el && el->type() == Element::Type::CHORD)
break;
}
if (nextSegment == 0)
return;
// look for the lyrics we are moving from; may be the current lyrics or a previous one
// we are extending with several dashes
Lyrics* fromLyrics = 0;
while (segment) {
const QList<Lyrics*>* nll = segment->lyricsList(track);
if (!nll) {
segment = segment->prev1(Segment::Type::ChordRest);
continue;
}
fromLyrics = nll->value(verse);
if (fromLyrics)
break;
segment = segment->prev1(Segment::Type::ChordRest);
}
_score->startCmd();
const QList<Lyrics*>* ll = nextSegment->lyricsList(track);
Lyrics* toLyrics = ll->value(verse);
bool newLyrics = (toLyrics == 0);
if (!toLyrics) {
toLyrics = new Lyrics(_score);
toLyrics->setTrack(track);
toLyrics->setParent(nextSegment->element(track));
toLyrics->setNo(verse);
toLyrics->setSyllabic(Lyrics::Syllabic::END);
}
else {
// as we arrived at toLyrics by a dash, it cannot be initial or isolated
if (toLyrics->syllabic() == Lyrics::Syllabic::BEGIN)
toLyrics->undoChangeProperty(P_ID::SYLLABIC, int(Lyrics::Syllabic::MIDDLE));
else if (toLyrics->syllabic() == Lyrics::Syllabic::SINGLE)
toLyrics->undoChangeProperty(P_ID::SYLLABIC, int(Lyrics::Syllabic::END));
}
if (fromLyrics) {
// as we moved away from fromLyrics by a dash,
// it can have syll. dashes before and after but cannot be isolated or terminal
switch(fromLyrics->syllabic()) {
case Lyrics::Syllabic::BEGIN:
case Lyrics::Syllabic::MIDDLE:
break;
case Lyrics::Syllabic::SINGLE:
fromLyrics->undoChangeProperty(P_ID::SYLLABIC, int(Lyrics::Syllabic::BEGIN));
break;
case Lyrics::Syllabic::END:
fromLyrics->undoChangeProperty(P_ID::SYLLABIC, int(Lyrics::Syllabic::MIDDLE));
break;
}
// for the same reason, it cannot have a melisma
fromLyrics->undoChangeProperty(P_ID::LYRIC_TICKS, 0);
}
if (newLyrics)
_score->undoAddElement(toLyrics);
_score->select(toLyrics, SelectType::SINGLE, 0);
startEdit(toLyrics, Grip::NO_GRIP);
mscore->changeState(mscoreState());
adjustCanvasPosition(toLyrics, false);
((Lyrics*)editObject)->selectAll();
_score->setLayoutAll(true);
_score->update();
}
//---------------------------------------------------------
// lyricsUnderscore
//---------------------------------------------------------
void ScoreView::lyricsUnderscore()
{
Lyrics* lyrics = static_cast<Lyrics*>(editObject);
int track = lyrics->track();
Segment* segment = lyrics->segment();
int verse = lyrics->no();
int endTick = segment->tick(); // a previous melisma cannot extend beyond this point
endEdit();
// search next chord
Segment* nextSegment = segment;
while ((nextSegment = nextSegment->next1(Segment::Type::ChordRest))) {
Element* el = nextSegment->element(track);
if (el && el->type() == Element::Type::CHORD)
break;
}
// look for the lyrics we are moving from; may be the current lyrics or a previous one
// we are extending with several underscores
Lyrics* fromLyrics = 0;
while (segment) {
const QList<Lyrics*>* nll = segment->lyricsList(track);
if (nll) {
fromLyrics = nll->value(verse);
if (fromLyrics)
break;
}
segment = segment->prev1(Segment::Type::ChordRest);
// if the segment has a rest in this track, stop going back
Element* e = segment ? segment->element(track) : 0;
if (e && e->type() != Element::Type::CHORD)
break;
}
_score->startCmd();
// one-chord melisma?
// if still at melisma initial chord and there is a valid next chord (if not,
// there will be no melisma anyway), set a temporary melisma duration
if (fromLyrics == lyrics && nextSegment)
lyrics->undoChangeProperty(P_ID::LYRIC_TICKS, Lyrics::TEMP_MELISMA_TICKS);
if (nextSegment == 0) {
if (fromLyrics) {
switch(fromLyrics->syllabic()) {
case Lyrics::Syllabic::SINGLE:
case Lyrics::Syllabic::END:
break;
default:
fromLyrics->undoChangeProperty(P_ID::SYLLABIC, int(Lyrics::Syllabic::END));
break;
}
if (fromLyrics->segment()->tick() < endTick)
fromLyrics->undoChangeProperty(P_ID::LYRIC_TICKS, endTick - fromLyrics->segment()->tick());
}
// leave edit mode, select something (just for user feedback) and update to show extended melisam
mscore->changeState(STATE_NORMAL);
if (fromLyrics)
_score->select(fromLyrics, SelectType::SINGLE, 0);
//_score->update();
_score->setLayoutAll(true);
_score->endCmd();
return;
}
// if a place for a new lyrics has been found, create a lyrics there
const QList<Lyrics*>* ll = nextSegment->lyricsList(track);
Lyrics* toLyrics = ll->value(verse);
bool newLyrics = (toLyrics == 0);
if (!toLyrics) {
toLyrics = new Lyrics(_score);
toLyrics->setTrack(track);
toLyrics->setParent(nextSegment->element(track));
toLyrics->setNo(verse);
toLyrics->setSyllabic(Lyrics::Syllabic::SINGLE);
}
// as we arrived at toLyrics by an underscore, it cannot have syllabic dashes before
else if (toLyrics->syllabic() == Lyrics::Syllabic::MIDDLE)
toLyrics->undoChangeProperty(P_ID::SYLLABIC, int(Lyrics::Syllabic::BEGIN));
else if (toLyrics->syllabic() == Lyrics::Syllabic::END)
toLyrics->undoChangeProperty(P_ID::SYLLABIC, int(Lyrics::Syllabic::SINGLE));
if (fromLyrics) {
// as we moved away from fromLyrics by an underscore,
// it can be isolated or terminal but cannot have dashes after
switch(fromLyrics->syllabic()) {
case Lyrics::Syllabic::SINGLE:
case Lyrics::Syllabic::END:
break;
default:
fromLyrics->undoChangeProperty(P_ID::SYLLABIC, int(Lyrics::Syllabic::END));
break;
}
// for the same reason, if it has a melisma, this cannot extend beyond toLyrics
if (fromLyrics->segment()->tick() < endTick)
fromLyrics->undoChangeProperty(P_ID::LYRIC_TICKS, endTick - fromLyrics->segment()->tick());
}
if (newLyrics)
_score->undoAddElement(toLyrics);
_score->select(toLyrics, SelectType::SINGLE, 0);
startEdit(toLyrics, Grip::NO_GRIP);
mscore->changeState(mscoreState());
adjustCanvasPosition(toLyrics, false);
((Lyrics*)editObject)->selectAll();
_score->setLayoutAll(true);
//_score->update();
_score->endCmd();
}
//---------------------------------------------------------
// lyricsReturn
//---------------------------------------------------------
void ScoreView::lyricsReturn()
{
Lyrics* lyrics = (Lyrics*)editObject;
Segment* segment = lyrics->segment();
endEdit();
_score->startCmd();
Lyrics* oldLyrics = lyrics;
lyrics = static_cast<Lyrics*>(Element::create(lyrics->type(), _score));
lyrics->setTrack(oldLyrics->track());
lyrics->setParent(segment->element(oldLyrics->track()));
lyrics->setNo(oldLyrics->no() + 1);
_score->undoAddElement(lyrics);
_score->select(lyrics, SelectType::SINGLE, 0);
startEdit(lyrics, Grip::NO_GRIP);
mscore->changeState(mscoreState());
adjustCanvasPosition(lyrics, false);
_score->setLayoutAll(true);
_score->update();
}
//---------------------------------------------------------
// lyricsEndEdit
//---------------------------------------------------------
void ScoreView::lyricsEndEdit()
{
Lyrics* lyrics = static_cast<Lyrics*>(editObject);
// if no text, just remove this lyrics
if (lyrics->isEmpty())
lyrics->parent()->remove(lyrics);
// if not empty, make sure this new lyrics does not fall in the middle
// of an existing melisma from a previous lyrics; in case, shorten it
else {
int verse = lyrics->no();
int track = lyrics->track();
// search previous lyric
Lyrics* prevLyrics = 0;
Segment* prevSegment = lyrics->segment()->prev1(Segment::Type::ChordRest);
Segment* segment = prevSegment;
while (segment) {
const QList<Lyrics*>* nll = segment->lyricsList(track);
if (nll) {
prevLyrics = nll->value(verse);
if (prevLyrics)
break;
}
segment = segment->prev1(Segment::Type::ChordRest);
}
if (prevLyrics && prevLyrics->syllabic() == Lyrics::Syllabic::END) {
int endTick = prevSegment->tick(); // a prev. melisma should not go beyond this segment
if (prevLyrics->endTick() >= endTick)
prevLyrics->undoChangeProperty(P_ID::LYRIC_TICKS, endTick - prevLyrics->segment()->tick());
}
}
}
}
|