Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin API: alter Cursor API for better usage in interactive plugins #5657

Merged
merged 6 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 36 additions & 34 deletions libmscore/noteentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,62 +121,64 @@ NoteVal Score::noteValForPosition(Position pos, AccidentalType at, bool &error)
// addPitch
//---------------------------------------------------------

Note* Score::addPitch(NoteVal& nval, bool addFlag)
Note* Score::addPitch(NoteVal& nval, bool addFlag, InputState* externalInputState)
{
InputState& is = externalInputState ? (*externalInputState) : _is;

if (addFlag) {
Chord* c = toChord(_is.lastSegment()->element(_is.track()));
Chord* c = toChord(is.lastSegment()->element(is.track()));

if (c == 0 || !c->isChord()) {
qDebug("Score::addPitch: cr %s", c ? c->name() : "zero");
return 0;
}
Note* note = addNote(c, nval);
if (_is.lastSegment() == _is.segment()) {
NoteEntryMethod entryMethod = _is.noteEntryMethod();
if (is.lastSegment() == is.segment()) {
NoteEntryMethod entryMethod = is.noteEntryMethod();
if (entryMethod != NoteEntryMethod::REALTIME_AUTO && entryMethod != NoteEntryMethod::REALTIME_MANUAL)
_is.moveToNextInputPos();
is.moveToNextInputPos();
}
return note;
}
expandVoice();

// insert note
Direction stemDirection = Direction::AUTO;
int track = _is.track();
if (_is.drumNote() != -1) {
nval.pitch = _is.drumNote();
const Drumset* ds = _is.drumset();
int track = is.track();
if (is.drumNote() != -1) {
nval.pitch = is.drumNote();
const Drumset* ds = is.drumset();
nval.headGroup = ds->noteHead(nval.pitch);
stemDirection = ds->stemDirection(nval.pitch);
track = ds->voice(nval.pitch) + (_is.track() / VOICES) * VOICES;
_is.setTrack(track);
track = ds->voice(nval.pitch) + (is.track() / VOICES) * VOICES;
is.setTrack(track);
expandVoice();
}
if (!_is.cr())
if (!is.cr())
return 0;
Fraction duration;
if (_is.usingNoteEntryMethod(NoteEntryMethod::REPITCH)) {
duration = _is.cr()->ticks();
if (is.usingNoteEntryMethod(NoteEntryMethod::REPITCH)) {
duration = is.cr()->ticks();
}
else if (_is.usingNoteEntryMethod(NoteEntryMethod::REALTIME_AUTO) || _is.usingNoteEntryMethod(NoteEntryMethod::REALTIME_MANUAL)) {
else if (is.usingNoteEntryMethod(NoteEntryMethod::REALTIME_AUTO) || is.usingNoteEntryMethod(NoteEntryMethod::REALTIME_MANUAL)) {
// FIXME: truncate duration at barline in real-time modes.
// The user might try to enter a duration that is too long to fit in the remaining space in the measure.
// We could split the duration at the barline and continue into the next bar, but this would create extra
// notes, extra ties, and extra pain. Instead, we simply truncate the duration at the barline.
Fraction ticks2measureEnd = _is.segment()->measure()->ticks() - _is.segment()->rtick();
duration = _is.duration() > ticks2measureEnd ? ticks2measureEnd : _is.duration().fraction();
Fraction ticks2measureEnd = is.segment()->measure()->ticks() - is.segment()->rtick();
duration = is.duration() > ticks2measureEnd ? ticks2measureEnd : is.duration().fraction();
}
else {
duration = _is.duration().fraction();
duration = is.duration().fraction();
}
Note* note = 0;
Note* firstTiedNote = 0;
Note* lastTiedNote = 0;
if (_is.usingNoteEntryMethod(NoteEntryMethod::REPITCH) && _is.cr()->isChord()) {
if (is.usingNoteEntryMethod(NoteEntryMethod::REPITCH) && is.cr()->isChord()) {
// repitch mode for MIDI input (where we are given a pitch) is handled here
// for keyboard input (where we are given a staff position), there is a separate function Score::repitchNote()
// the code is similar enough that it could possibly be refactored
Chord* chord = toChord(_is.cr());
Chord* chord = toChord(is.cr());
note = new Note(this);
note->setParent(chord);
note->setTrack(chord->track());
Expand Down Expand Up @@ -232,49 +234,49 @@ Note* Score::addPitch(NoteVal& nval, bool addFlag)
}
select(lastTiedNote);
}
else if (!_is.usingNoteEntryMethod(NoteEntryMethod::REPITCH)) {
Segment* seg = setNoteRest(_is.segment(), track, nval, duration, stemDirection);
else if (!is.usingNoteEntryMethod(NoteEntryMethod::REPITCH)) {
Segment* seg = setNoteRest(is.segment(), track, nval, duration, stemDirection);
if (seg) {
note = toChord(seg->element(track))->upNote();
}
}

if (_is.slur()) {
if (is.slur()) {
//
// extend slur
//
ChordRest* e = searchNote(_is.tick(), _is.track());
ChordRest* e = searchNote(is.tick(), is.track());
if (e) {
Fraction stick = Fraction(0, 1);
Element* ee = _is.slur()->startElement();
Element* ee = is.slur()->startElement();
if (ee->isChordRest())
stick = toChordRest(ee)->tick();
else if (ee->isNote())
stick = toNote(ee)->chord()->tick();
if (stick == e->tick()) {
_is.slur()->setTick(stick);
_is.slur()->setStartElement(e);
is.slur()->setTick(stick);
is.slur()->setStartElement(e);
}
else {
_is.slur()->setTick2(e->tick());
_is.slur()->setEndElement(e);
is.slur()->setTick2(e->tick());
is.slur()->setEndElement(e);
}
}
else
qDebug("addPitch: cannot find slur note");
}
if (_is.usingNoteEntryMethod(NoteEntryMethod::REPITCH)) {
if (is.usingNoteEntryMethod(NoteEntryMethod::REPITCH)) {
// move cursor to next note, but skip tied notes (they were already repitched above)
ChordRest* next = lastTiedNote ? nextChordRest(lastTiedNote->chord()) : nextChordRest(_is.cr());
ChordRest* next = lastTiedNote ? nextChordRest(lastTiedNote->chord()) : nextChordRest(is.cr());
while (next && !next->isChord())
next = nextChordRest(next);
if (next)
_is.moveInputPos(next->segment());
is.moveInputPos(next->segment());
}
else {
NoteEntryMethod entryMethod = _is.noteEntryMethod();
NoteEntryMethod entryMethod = is.noteEntryMethod();
if (entryMethod != NoteEntryMethod::REALTIME_AUTO && entryMethod != NoteEntryMethod::REALTIME_MANUAL)
_is.moveToNextInputPos();
is.moveToNextInputPos();
}
return note;
}
Expand Down
2 changes: 1 addition & 1 deletion libmscore/score.h
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ class Score : public QObject, public ScoreElement {
void addElement(Element*);
void removeElement(Element*);

Note* addPitch(NoteVal&, bool addFlag);
Note* addPitch(NoteVal&, bool addFlag, InputState* externalInputState = nullptr);
void addPitch(int pitch, bool addFlag, bool insert);
Note* addTiedMidiPitch(int pitch, bool addFlag, Chord* prevChord);
Note* addMidiPitch(int pitch, bool addFlag);
Expand Down
2 changes: 1 addition & 1 deletion mscore/musescore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5914,7 +5914,7 @@ void MuseScore::cmd(QAction* a)
cmd(a, cmdn);
if (lastShortcut->isCmd())
cs->endCmd();
else
else if (!lastShortcut->isUndoRedo()) // undoRedo() calls endCmd() itself
endCmd();
TourHandler::startTour(cmdn);
}
Expand Down
Loading