Skip to content

Commit

Permalink
implementation of next/prev track
Browse files Browse the repository at this point in the history
move up and down by track, stopping only at tracks that have content at
or before the cursor position within the current measure
  • Loading branch information
MarcSabatella committed Aug 2, 2013
1 parent 1ae7471 commit d9d6472
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 5 deletions.
20 changes: 15 additions & 5 deletions libmscore/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1795,13 +1795,23 @@ Element* Score::move(const QString& cmd)
moveInputPos(crc->segment());
}
}
else if (cmd == "next-track")
el = downStaff(cr);
else if (cmd == "prev-track")
el = upStaff(cr);
else if (cmd == "next-track") {
el = nextTrack(cr);
if (noteEntryMode() && el && (el->type() == Element::CHORD || el->type() == Element::REST)){
ChordRest* crc = static_cast<ChordRest*>(el);
moveInputPos(crc->segment());
}
}
else if (cmd == "prev-track") {
el = prevTrack(cr);
if (noteEntryMode() && el && (el->type() == Element::CHORD || el->type() == Element::REST)){
ChordRest* crc = static_cast<ChordRest*>(el);
moveInputPos(crc->segment());
}
}
if (el) {
if (el->type() == Element::CHORD)
el = static_cast<Chord*>(el)->downNote();
el = static_cast<Chord*>(el)->upNote(); // originally downNote
_playNote = true;
select(el, SELECT_SINGLE, 0);
}
Expand Down
71 changes: 71 additions & 0 deletions libmscore/navigate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,77 @@ ChordRest* Score::downStaff(ChordRest* cr)
return 0;
}

//---------------------------------------------------------
// nextTrack
// returns note at or just previous to current (cr) position
// in next non-empty track for this measure
// that contains such an element
//---------------------------------------------------------

ChordRest* Score::nextTrack(ChordRest* cr)
{
if (!cr)
return 0;

Element* el = 0;
Measure* measure = cr->measure();
int track = cr->track();
int tracks = nstaves() * VOICES;

while (!el) {
// find next non-empty track
while (++track < tracks){
if (measure->hasVoice(track))
break;
}
// no more tracks, return original element
if (track == tracks)
return cr;
// find element at same or previous segment within this track
for (Segment* segment = cr->segment(); segment != 0; segment = segment->prev(Segment::SegChordRest)) {
el = segment->element(track);
if (el)
break;
}
}
return static_cast<ChordRest*>(el);
}

//---------------------------------------------------------
// prevTrack
// returns ChordRest at or just previous to current (cr) position
// in previous non-empty track for this measure
// that contains such an element
//---------------------------------------------------------

ChordRest* Score::prevTrack(ChordRest* cr)
{
if (!cr)
return 0;

Element* el = 0;
Measure* measure = cr->measure();
int track = cr->track();

while (!el) {
// find next non-empty track
while (--track >= 0){
if (measure->hasVoice(track))
break;
}
// no more tracks, return original element
if (track < 0)
return cr;
// find element at same or previous segment within this track
for (Segment* segment = cr->segment(); segment != 0; segment = segment->prev(Segment::SegChordRest)) {
el = segment->element(track);
if (el)
break;
}
}
return static_cast<ChordRest*>(el);
}

//---------------------------------------------------------
// nextMeasure
//---------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions libmscore/score.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ class Score : public QObject {
Note* downAltCtrl(Note*) const;
ChordRest* upStaff(ChordRest* cr);
ChordRest* downStaff(ChordRest* cr);
ChordRest* nextTrack(ChordRest* cr);
ChordRest* prevTrack(ChordRest* cr);
void moveUp(Chord*);
void moveDown(Chord*);

Expand Down

0 comments on commit d9d6472

Please sign in to comment.