Skip to content
Merged
Changes from 1 commit
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
101 changes: 69 additions & 32 deletions source/app/powertabeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2076,9 +2076,12 @@ bool PowerTabEditor::eventFilter(QObject *object, QEvent *event)
if (scorearea && event->type() == QEvent::KeyPress)
{
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if (keyEvent->key() >= Qt::Key_0 && keyEvent->key() <= Qt::Key_9)
// x for a muted note
const bool isMutedKey = (keyEvent->key() == Qt::Key_X);
if (keyEvent->key() >= Qt::Key_0 && keyEvent->key() <= Qt::Key_9 ||
Comment thread
sbonaime marked this conversation as resolved.
Outdated
isMutedKey)
{
const int number = keyEvent->key() - Qt::Key_0;
const int number = isMutedKey ? 0 : (keyEvent->key() - Qt::Key_0);
ScoreLocation &location = getLocation();

// Add a space if the user is attempting to add a note at the end of
Expand All @@ -2093,42 +2096,76 @@ bool PowerTabEditor::eventFilter(QObject *object, QEvent *event)
// unless it's the first position of the system.
if (!location.getBarline() || location.getPositionIndex() == 0)
{
// Update the existing note if possible.
if (location.getNote())
{
myUndoManager->push(new EditTabNumber(location, number),
location.getSystemIndex());
}
else
if (isMutedKey && !location.getNote())
{
// Directly insert a new muted note without requiring a
// number to be entered first.
Note mutedNote(location.getString(), 0);
mutedNote.setProperty(Note::Muted);
myUndoManager->push(
new AddNote(location,
Note(location.getString(), number),
myActiveDurationType),
location.getSystemIndex());
new AddNote(location, mutedNote, myActiveDurationType),
location.getSystemIndex());
return true;
}

if (mySettingsManager->getReadHandle()->get(
Settings::PlayNotesWhileEditing))
if (!isMutedKey)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only comment here is that the logic is a bit tricker to follow now:

  • if isMutedKey is true and there is already a note, it's not very clear that the intent is to fall through and not handle the key here. An early return might make that more clear?

{
const ScoreLocation &location = getLocation();
// Generate the midi data and then transfer it to the midi
// thread.
MidiFile midi_data = MidiPlayer::generateSingleNote(
location, *mySettingsManager);
MidiPlaybackSettings initial_settings(100,
location.getScore());

QMetaObject::invokeMethod(
myMidiPlayer,
[=, this, midi_data = std::move(midi_data)]() mutable {
myMidiPlayer->playSingleNote(midi_data, location,
initial_settings);
},
Qt::QueuedConnection);
}
// Update the existing note if possible.
if (location.getNote())
{
const Note *note = location.getNote();
if (note->hasProperty(Note::Muted))
{
// Remove the muted property and set the fret number
// as a single undoable action.
myUndoManager->beginMacro(tr("Edit Tab Number"));
myUndoManager->push(
new RemoveNoteProperty(location, Note::Muted,
Comment thread
sbonaime marked this conversation as resolved.
tr("Muted")),
location.getSystemIndex());
myUndoManager->push(
new EditTabNumber(location, number),
location.getSystemIndex());
myUndoManager->endMacro();
}
else
{
myUndoManager->push(
new EditTabNumber(location, number),
location.getSystemIndex());
}
}
else
{
myUndoManager->push(
new AddNote(location,
Note(location.getString(), number),
myActiveDurationType),
location.getSystemIndex());
}

return true;
if (mySettingsManager->getReadHandle()->get(
Settings::PlayNotesWhileEditing))
{
const ScoreLocation &location = getLocation();
Comment thread
sbonaime marked this conversation as resolved.
Outdated
// Generate the midi data and then transfer it to the midi
// thread.
MidiFile midi_data = MidiPlayer::generateSingleNote(
location, *mySettingsManager);
MidiPlaybackSettings initial_settings(100,
location.getScore());

QMetaObject::invokeMethod(
myMidiPlayer,
[=, this, midi_data = std::move(midi_data)]() mutable {
myMidiPlayer->playSingleNote(midi_data, location,
initial_settings);
},
Qt::QueuedConnection);
}

return true;
}
}
}
}
Expand Down
Loading