Skip to content

Commit

Permalink
fix #276217 Support-MIDI-IN-while-playback-engaged
Browse files Browse the repository at this point in the history
Can now play in any part while playback is engaged.  PianoTools
reflects both the note the user is pressing and the playback notes
at the same time.  Loop range is no longer automatically set when
Play is pressed.

Turning off auto loop range selection on pressing play is now a
configurable option.

Restoring commented out debug line.
  • Loading branch information
blackears committed Nov 13, 2018
1 parent cf24e6c commit dbf4c10
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 13 deletions.
11 changes: 6 additions & 5 deletions mscore/pianotools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ QSize HPiano::sizeHint() const
// pressKeys
//---------------------------------------------------------

void HPiano::setPressedPitches(QSet<int> pitches)
void HPiano::setPressedPlaybackPitches(QSet<int> pitches)
{
_pressedPitches = pitches;
_pressedPlaybackPitches = pitches;
updateAllKeys();
}

Expand Down Expand Up @@ -218,7 +218,8 @@ void HPiano::clearSelection()
void HPiano::updateAllKeys()
{
for (PianoKeyItem* key : keys) {
key->setPressed(_pressedPitches.contains(key->pitch()));
key->setPressed(_pressedPitches.contains(key->pitch())
|| _pressedPlaybackPitches.contains(key->pitch()));
key->update();
}
}
Expand Down Expand Up @@ -443,13 +444,13 @@ void PianoTools::retranslate()
// heartBeat
//---------------------------------------------------------

void PianoTools::heartBeat(QList<const Ms::Note *> notes)
void PianoTools::setPlaybackNotes(QList<const Ms::Note *> notes)
{
QSet<int> pitches;
for (const Note* note : notes) {
pitches.insert(note->ppitch());
}
_piano->setPressedPitches(pitches);
_piano->setPressedPlaybackPitches(pitches);
}

//---------------------------------------------------------
Expand Down
7 changes: 5 additions & 2 deletions mscore/pianotools.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class HPiano : public QGraphicsView {
Q_OBJECT
int _firstKey;
int _lastKey;
//Pitches pressed due to playback
QSet<int> _pressedPlaybackPitches;
//Pitches pressed due to user interaction
QSet<int> _pressedPitches;
QList<PianoKeyItem*> keys;
qreal scaleVal;
Expand All @@ -75,7 +78,7 @@ class HPiano : public QGraphicsView {
public:
HPiano(QWidget* parent = 0);
friend class PianoKeyItem;
void setPressedPitches(QSet<int> pitches);
void setPressedPlaybackPitches(QSet<int> pitches);
void pressPitch(int pitch);
void releasePitch(int pitch);
void clearSelection();
Expand Down Expand Up @@ -108,7 +111,7 @@ class PianoTools : public QDockWidget {
PianoTools(QWidget* parent = 0);
void pressPitch(int pitch) { _piano->pressPitch(pitch); }
void releasePitch(int pitch) { _piano->releasePitch(pitch); }
void heartBeat(QList<const Note*> notes);
void setPlaybackNotes(QList<const Note*> notes);
void clearSelection();
void changeSelection(Selection selection);
};
Expand Down
1 change: 1 addition & 0 deletions mscore/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ void Preferences::init(bool storeInMemoryOnly)
{PREF_APP_PLAYBACK_FOLLOWSONG, new BoolPreference(true)},
{PREF_APP_PLAYBACK_PANPLAYBACK, new BoolPreference(true)},
{PREF_APP_PLAYBACK_PLAYREPEATS, new BoolPreference(true)},
{PREF_APP_PLAYBACK_LOOPTOSELECTIONONPLAY, new BoolPreference(true)},
{PREF_APP_USESINGLEPALETTE, new BoolPreference(false)},
{PREF_APP_STARTUP_FIRSTSTART, new BoolPreference(true)},
{PREF_APP_STARTUP_SESSIONSTART, new EnumPreference(QVariant::fromValue(SessionStart::SCORE), false)},
Expand Down
1 change: 1 addition & 0 deletions mscore/preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ enum class MusicxmlExportBreaks : char {
#define PREF_APP_PLAYBACK_FOLLOWSONG "application/playback/followSong"
#define PREF_APP_PLAYBACK_PANPLAYBACK "application/playback/panPlayback"
#define PREF_APP_PLAYBACK_PLAYREPEATS "application/playback/playRepeats"
#define PREF_APP_PLAYBACK_LOOPTOSELECTIONONPLAY "application/playback/setLoopToSelectionOnPlay"
#define PREF_APP_USESINGLEPALETTE "application/useSinglePalette"
#define PREF_APP_STARTUP_FIRSTSTART "application/startup/firstStart"
#define PREF_APP_STARTUP_SESSIONSTART "application/startup/sessionStart"
Expand Down
2 changes: 1 addition & 1 deletion mscore/scoreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3550,7 +3550,7 @@ void ScoreView::cmdTuplet(int n)

void ScoreView::midiNoteReceived(int pitch, bool chord, int velocity)
{
qDebug("midiNoteReceived %d chord %d", pitch, chord);
qDebug("midiNoteReceived: pitch %d, chord %d, velocity %d", pitch, chord, velocity);

MidiInputEvent ev;
ev.pitch = pitch;
Expand Down
12 changes: 7 additions & 5 deletions mscore/seq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,10 @@ void Seq::start()
}
}
if ((mscore->loop())) {
if (cs->selection().isRange())
setLoopSelection();
if (preferences.getBool(PREF_APP_PLAYBACK_LOOPTOSELECTIONONPLAY)) {
if (cs->selection().isRange())
setLoopSelection();
}
if (!preferences.getBool(PREF_IO_JACK_USEJACKTRANSPORT) || (preferences.getBool(PREF_IO_JACK_USEJACKTRANSPORT) && state == Transport::STOP))
seek(cs->repeatList()->tick2utick(cs->loopInTick()));
}
Expand Down Expand Up @@ -417,7 +419,7 @@ void Seq::unmarkNotes()
markedNotes.clear();
PianoTools* piano = mscore->pianoTools();
if (piano && piano->isVisible())
piano->heartBeat(markedNotes);
piano->setPlaybackNotes(markedNotes);
}

//---------------------------------------------------------
Expand Down Expand Up @@ -1133,7 +1135,7 @@ void Seq::seekRT(int utick)

void Seq::startNote(int channel, int pitch, int velo, double nt)
{
if (state != Transport::STOP)
if (state != Transport::STOP && state != Transport::PLAY)
return;
NPlayEvent ev(ME_NOTEON, channel, pitch, velo);
ev.setTuning(nt);
Expand Down Expand Up @@ -1518,7 +1520,7 @@ void Seq::heartBeatTimeout()

PianoTools* piano = mscore->pianoTools();
if (piano && piano->isVisible())
piano->heartBeat(markedNotes);
piano->setPlaybackNotes(markedNotes);

cv->update(cv->toPhysical(r));
}
Expand Down

0 comments on commit dbf4c10

Please sign in to comment.