implemented voices exchanging

This commit is contained in:
Roman Pudashkin 2020-11-03 18:54:25 +02:00 committed by pereverzev+v
parent c3230bfc46
commit bad7dbe914
6 changed files with 70 additions and 5 deletions

View file

@ -95,6 +95,7 @@ public:
virtual void setBreaksSpawnInterval(BreaksSpawnIntervalType intervalType, int interval = 0) = 0;
virtual void transpose(const TransposeOptions& options) = 0;
virtual void swapVoices(int voiceIndex1, int voiceIndex2) = 0;
};
using INotationInteractionPtr = std::shared_ptr<INotationInteraction>;

View file

@ -58,6 +58,13 @@ void NotationActionController::init()
dispatcher()->reg(this, "edit-info", this, &NotationActionController::openScoreProperties);
dispatcher()->reg(this, "transpose", this, &NotationActionController::openTransposeDialog);
dispatcher()->reg(this, "parts", this, &NotationActionController::openPartsDialog);
dispatcher()->reg(this, "voice-x12", [this]() { swapVoices(0, 1); });
dispatcher()->reg(this, "voice-x13", [this]() { swapVoices(0, 2); });
dispatcher()->reg(this, "voice-x14", [this]() { swapVoices(0, 3); });
dispatcher()->reg(this, "voice-x23", [this]() { swapVoices(1, 2); });
dispatcher()->reg(this, "voice-x24", [this]() { swapVoices(1, 3); });
dispatcher()->reg(this, "voice-x34", [this]() { swapVoices(2, 3); });
}
bool NotationActionController::canReceiveAction(const actions::ActionName&) const
@ -211,6 +218,16 @@ void NotationActionController::moveText(INotationInteractionPtr interaction, con
interaction->moveText(direction, quickly);
}
void NotationActionController::swapVoices(int voiceIndex1, int voiceIndex2)
{
auto interaction = currentNotationInteraction();
if (!interaction) {
return;
}
interaction->swapVoices(voiceIndex1, voiceIndex2);
}
void NotationActionController::deleteSelection()
{
auto interaction = currentNotationInteraction();

View file

@ -26,8 +26,7 @@
#include "inotation.h"
#include "iinteractive.h"
namespace mu {
namespace notation {
namespace mu::notation {
class NotationActionController : public actions::Actionable
{
INJECT(notation, actions::IActionsDispatcher, dispatcher)
@ -35,11 +34,9 @@ class NotationActionController : public actions::Actionable
INJECT(notation, framework::IInteractive, interactive)
public:
void init();
private:
bool canReceiveAction(const actions::ActionName& action) const override;
INotationPtr currentNotation() const;
@ -52,6 +49,8 @@ private:
void moveAction(const actions::ActionName& action);
void moveText(INotationInteractionPtr interaction, const actions::ActionName& action);
void swapVoices(int voiceIndex1, int voiceIndex2);
void deleteSelection();
void undo();
void redo();
@ -65,6 +64,5 @@ private:
void openPartsDialog();
};
}
}
#endif // MU_NOTATION_NOTATIONACTIONCONTROLLER_H

View file

@ -190,6 +190,30 @@ const std::vector<Action> NotationActions::m_actions = {
Action("redo",
QT_TRANSLATE_NOOP("action", "Redo"),
ShortcutContext::NotationActive
),
Action("voice-x12",
QT_TRANSLATE_NOOP("action", "Exchange Voice 1-2"),
ShortcutContext::NotationActive
),
Action("voice-x13",
QT_TRANSLATE_NOOP("action", "Exchange Voice 1-3"),
ShortcutContext::NotationActive
),
Action("voice-x14",
QT_TRANSLATE_NOOP("action", "Exchange Voice 1-4"),
ShortcutContext::NotationActive
),
Action("voice-x23",
QT_TRANSLATE_NOOP("action", "Exchange Voice 2-3"),
ShortcutContext::NotationActive
),
Action("voice-x24",
QT_TRANSLATE_NOOP("action", "Exchange Voice 2-4"),
ShortcutContext::NotationActive
),
Action("voice-x34",
QT_TRANSLATE_NOOP("action", "Exchange Voice 3-4"),
ShortcutContext::NotationActive
)
};

View file

@ -1939,3 +1939,25 @@ void NotationInteraction::transpose(const TransposeOptions& options)
m_notation->notifyAboutNotationChanged();
}
void NotationInteraction::swapVoices(int voiceIndex1, int voiceIndex2)
{
if (voiceIndex1 == voiceIndex2) {
return;
}
if (!isVoiceIndexValid(voiceIndex1) || !isVoiceIndexValid(voiceIndex2)) {
return;
}
m_undoStack->prepareChanges();
score()->cmdExchangeVoice(voiceIndex1, voiceIndex2);
m_undoStack->commitChanges();
m_notation->notifyAboutNotationChanged();
}
bool NotationInteraction::isVoiceIndexValid(int voiceIndex) const
{
return voiceIndex >= 0 && voiceIndex < VOICES;
}

View file

@ -112,6 +112,7 @@ public:
void setBreaksSpawnInterval(BreaksSpawnIntervalType intervalType, int interval = 0) override;
void transpose(const TransposeOptions& options) override;
void swapVoices(int voiceIndex1, int voiceIndex2) override;
private:
Ms::Score* score() const;
@ -141,6 +142,8 @@ private:
void cmdAddSlur(const Ms::Slur* slurTemplate = nullptr);
void addSlur(Ms::ChordRest* cr1, Ms::ChordRest* cr2, const Ms::Slur* slurTemplate);
bool isVoiceIndexValid(int voiceIndex) const;
struct HitMeasureData
{
int staffIndex = -1;