Skip to content

Commit

Permalink
Merge pull request #2784 from shoogle/semi-realtime-midi
Browse files Browse the repository at this point in the history
Semi realtime midi - simplify rhythms
  • Loading branch information
lasconic committed Aug 22, 2016
2 parents 964df1a + ba49079 commit 9843867
Show file tree
Hide file tree
Showing 32 changed files with 22,410 additions and 135 deletions.
31 changes: 31 additions & 0 deletions libmscore/chord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3100,6 +3100,37 @@ void Chord::sortNotes()
);
}

//---------------------------------------------------------
// nextTiedChord
// Return next chord if all notes in this chord are tied to it.
// Set backwards=true to return the previous chord instead.
//
// Note: the next chord might have extra notes that are not tied
// back to this one. Set sameSize=true to return 0 in this case.
//---------------------------------------------------------

Chord* Chord::nextTiedChord(bool backwards, bool sameSize)
{
Segment* nextSeg = backwards ? segment()->prev1(Segment::Type::ChordRest) : segment()->next1(Segment::Type::ChordRest);
if (!nextSeg)
return 0;
ChordRest* nextCR = nextSeg->cr(track());
if (!nextCR || !nextCR->isChord())
return 0;
Chord* next = toChord(nextCR);
if (sameSize && notes().size() != next->notes().size())
return 0; // sizes don't match so some notes can't be tied
for (Note* n : _notes) {
Tie* tie = backwards ? n->tieBack() : n->tieFor();
if (!tie)
return 0; // not tied
Note* nn = backwards ? tie->startNote() : tie->endNote();
if (!nn || nn->chord() != next)
return 0; // tied to note in wrong voice, or tied over rest
}
return next; // all notes in this chord are tied to notes in next chord
}

//---------------------------------------------------------
// toGraceAfter
//---------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions libmscore/chord.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ class Chord : public ChordRest {

void sortNotes();

Chord* nextTiedChord(bool backwards = false, bool sameSize = true);

virtual Element* nextElement() override;
virtual Element* prevElement() override;
virtual QString accessibleExtraInfo() const override;
Expand Down
42 changes: 38 additions & 4 deletions libmscore/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ Segment* Score::setNoteRest(Segment* segment, int track, NoteVal nval, Fraction
{
Q_ASSERT(segment->segmentType() == Segment::Type::ChordRest);

bool isRest = nval.pitch == -1;
int tick = segment->tick();
Element* nr = 0;
Tie* tie = 0;
Expand All @@ -572,18 +573,18 @@ Segment* Score::setNoteRest(Segment* segment, int track, NoteVal nval, Fraction
}

measure = segment->measure();
std::vector<TDuration> dl = toDurationList(dd, true);
std::vector<TDuration> dl = toRhythmicDurationList(dd, isRest, segment->rtick(), sigmap()->timesig(tick).nominal(), measure, 1);
int n = dl.size();
for (int i = 0; i < n; ++i) {
const TDuration& d = dl[i];
ChordRest* ncr;
Note* note = 0;
Tie* addTie = 0;
if (nval.pitch == -1) {
if (isRest) {
nr = ncr = new Rest(this);
nr->setTrack(track);
ncr->setDurationType(d);
ncr->setDuration(d.fraction());
ncr->setDuration(d == TDuration::DurationType::V_MEASURE ? measure->len() : d.fraction());
}
else {
nr = note = new Note(this);
Expand Down Expand Up @@ -641,7 +642,7 @@ Segment* Score::setNoteRest(Segment* segment, int track, NoteVal nval, Fraction
//
// Note does not fit on current measure, create Tie to
// next part of note
if (nval.pitch != -1) {
if (!isRest) {
tie = new Tie(this);
tie->setStartNote((Note*)nr);
tie->setTrack(nr->track());
Expand Down Expand Up @@ -1766,6 +1767,37 @@ void Score::cmdResetBeamMode()
}
}

//---------------------------------------------------------
// cmdResetNoteAndRestGroupings
//---------------------------------------------------------

void Score::cmdResetNoteAndRestGroupings()
{
if (selection().isNone())
cmdSelectAll();
else if (!selection().isRange()) {
qDebug("no system or staff selected");
return;
}

// save selection values because selection changes during grouping
int sTick = selection().tickStart();
int eTick = selection().tickEnd();
int sStaff = selection().staffStart();
int eStaff = selection().staffEnd();

startCmd();
for (int staff = sStaff; staff < eStaff; staff++) {
int sTrack = staff * VOICES;
int eTrack = sTrack + VOICES;
for (int track = sTrack; track < eTrack; track++) {
if (selectionFilter().canSelectVoice(track))
regroupNotesAndRests(sTick, eTick, track);
}
}
endCmd();
}

//---------------------------------------------------------
// processMidiInput
//---------------------------------------------------------
Expand Down Expand Up @@ -2487,6 +2519,8 @@ void Score::cmd(const QAction* a)
}
else if (cmd == "reset-beammode")
cmdResetBeamMode();
else if (cmd == "reset-groupings")
cmdResetNoteAndRestGroupings();
else if (cmd == "clef-violin")
cmdInsertClef(ClefType::G);
else if (cmd == "clef-bass")
Expand Down
Loading

0 comments on commit 9843867

Please sign in to comment.