Skip to content

Commit

Permalink
Fix #289006: Expose "Select Instrument" in Inspector for Instrument C…
Browse files Browse the repository at this point in the history
…hange text
  • Loading branch information
IsaacWeiss committed Dec 26, 2019
1 parent a3193b3 commit 7a32a58
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 57 deletions.
4 changes: 3 additions & 1 deletion mscore/inspector/inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,11 @@ void Inspector::update(Score* s)
case ElementType::STAFF_TEXT:
case ElementType::SYSTEM_TEXT:
case ElementType::REHEARSAL_MARK:
case ElementType::INSTRUMENT_CHANGE:
ie = new InspectorStaffText(this);
break;
case ElementType::INSTRUMENT_CHANGE:
ie = new InspectorInstrumentChange(this);
break;
case ElementType::MEASURE_NUMBER:
ie = new InspectorMeasureNumber(this);
break;
Expand Down
3 changes: 2 additions & 1 deletion mscore/inspector/inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "ui_inspector_accidental.h"
#include "ui_inspector_tempotext.h"
#include "ui_inspector_lyric.h"
#include "ui_inspector_instrchange.h"
#include "ui_inspector_stafftext.h"
#include "ui_inspector_slur.h"
#include "ui_inspector_empty.h"
Expand Down Expand Up @@ -359,7 +360,7 @@ class InspectorLyric : public InspectorTextBase {
};

//---------------------------------------------------------
// InspectorLyric
// InspectorStaffText
//---------------------------------------------------------

class InspectorStaffText : public InspectorTextBase {
Expand Down
22 changes: 22 additions & 0 deletions mscore/inspector/inspectorInstrchange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
//=============================================================================

#include "inspectorInstrchange.h"
#include "musescore.h"
#include "inspector.h"
#include "libmscore/instrchange.h"
#include "libmscore/score.h"
#include "scoreview.h"

namespace Ms {

Expand All @@ -26,13 +31,30 @@ InspectorInstrumentChange::InspectorInstrumentChange(QWidget* parent)
ic.setupUi(addWidget());

const std::vector<InspectorItem> il = {
{ Pid::SUB_STYLE, 0, ic.style, ic.resetStyle },
{ Pid::PLACEMENT, 0, ic.placement, ic.resetPlacement }
};
const std::vector<InspectorPanel> ppList = {
{ ic.title, ic.panel }
};
populatePlacement(ic.placement);
populateStyle(ic.style);
mapSignals(il, ppList);
connect(ic.selectInstrument, SIGNAL(clicked()), SLOT(selectInstrumentClicked()));
}

//---------------------------------------------------------
// selectInstrumentClicked
//---------------------------------------------------------

void InspectorInstrumentChange::selectInstrumentClicked()
{
InstrumentChange* i = toInstrumentChange(inspector->element());
Score* score = i->score();
score->startCmd();
mscore->currentScoreView()->selectInstrument(i);
score->setLayoutAll();
score->endCmd();
}

} // namespace Ms
Expand Down
3 changes: 3 additions & 0 deletions mscore/inspector/inspectorInstrchange.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class InspectorInstrumentChange : public InspectorTextBase {

Ui::InspectorInstrumentChange ic;

private slots:
void selectInstrumentClicked();

public:
InspectorInstrumentChange(QWidget* parent);
};
Expand Down
81 changes: 61 additions & 20 deletions mscore/inspector/inspector_instrchange.ui
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</rect>
</property>
<property name="accessibleName">
<string>Change Instrument Inspector</string>
<string>Instrument Change Inspector</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
Expand All @@ -30,12 +30,9 @@
<number>0</number>
</property>
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::HLine</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
Expand All @@ -54,12 +51,18 @@
</font>
</property>
<property name="text">
<string>Change Instrument</string>
<string>Instrument Change</string>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="panel" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>3</number>
Expand All @@ -76,20 +79,60 @@
<property name="spacing">
<number>3</number>
</property>
<item row="1" column="2">
<widget class="Ms::ResetButton" name="resetPlacement" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Style:</string>
</property>
<property name="buddy">
<cstring>style</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="style">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="accessibleName">
<string>Style</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="Ms::ResetButton" name="resetStyle" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Placement:</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>placement</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<item row="1" column="1">
<widget class="QComboBox" name="placement">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
Expand All @@ -112,17 +155,14 @@
</item>
</widget>
</item>
<item row="0" column="2">
<widget class="Ms::ResetButton" name="resetPlacement" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item row="2" column="0" colspan="3">
<widget class="QPushButton" name="selectInstrument">
<property name="accessibleName">
<string>Reset 'Placement' value</string>
</property>
<property name="text">
<string>Select Instrument...</string>
</property>
</widget>
</item>
</layout>
Expand All @@ -140,6 +180,7 @@
</customwidgets>
<tabstops>
<tabstop>title</tabstop>
<tabstop>style</tabstop>
<tabstop>placement</tabstop>
</tabstops>
<resources/>
Expand Down
77 changes: 42 additions & 35 deletions mscore/propertymenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ void ScoreView::createElementPropertyMenu(Element* e, QMenu* popup)
}
else if (e->isInstrumentChange()) {
genPropertyMenu1(e, popup);
popup->addAction(tr("Change Instrument…"))->setData("ch-instr");
popup->addAction(tr("Select Instrument…"))->setData("ch-instr");
}
else if (e->isInstrumentName())
popup->addAction(tr("Staff/Part Properties…"))->setData("staff-props");
Expand Down Expand Up @@ -453,7 +453,7 @@ void ScoreView::elementPropertyAction(const QString& cmd, Element* e)
}
}
else if (cmd == "articulation") {
Note* note = static_cast<Note*>(e);
Note* note = toNote(e);
mscore->editInPianoroll(note->staff());
}
else if (cmd == "style") {
Expand All @@ -464,39 +464,8 @@ void ScoreView::elementPropertyAction(const QString& cmd, Element* e)
mscore->styleDlg()->gotoElement(e);
mscore->styleDlg()->exec();
}
else if (cmd == "ch-instr") {
InstrumentChange* ic = static_cast<InstrumentChange*>(e);
SelectInstrument si(ic->instrument(), 0);
if (si.exec()) {
const InstrumentTemplate* it = si.instrTemplate();
if (it) {
Fraction tickStart = ic->segment()->tick();
Part* part = ic->staff()->part();
Interval oldV = part->instrument(tickStart)->transpose();
//Instrument* oi = ic->instrument(); //part->instrument(tickStart);
//Instrument* instrument = new Instrument(Instrument::fromTemplate(it));
// change instrument in all linked scores
for (ScoreElement* se : ic->linkList()) {
InstrumentChange* lic = static_cast<InstrumentChange*>(se);
Instrument* instrument = new Instrument(Instrument::fromTemplate(it));
lic->score()->undo(new ChangeInstrument(lic, instrument));
}
// transpose for current score only
// this automatically propagates to linked scores
if (part->instrument(tickStart)->transpose() != oldV) {
auto i = part->instruments()->upper_bound(tickStart.ticks()); // find(), ++i
Fraction tickEnd;
if (i == part->instruments()->end())
tickEnd = Fraction(-1, 1);
else
tickEnd = Fraction::fromTicks(i->first);
ic->score()->transpositionChanged(part, oldV, tickStart, tickEnd);
}
}
else
qDebug("no template selected?");
}
}
else if (cmd == "ch-instr")
selectInstrument(toInstrumentChange(e));
else if (cmd == "staff-props") {
Fraction tick = {-1,1};
if (e->isChordRest()) {
Expand Down Expand Up @@ -537,5 +506,43 @@ void ScoreView::editTremoloBarProperties(TremoloBar* tb)
score()->undo(new ChangeTremoloBar(static_cast<TremoloBar*>(b), bp.points()));
}
}

//---------------------------------------------------------
// selectInstrument
//---------------------------------------------------------

void Ms::ScoreView::selectInstrument(InstrumentChange* ic)
{
SelectInstrument si(ic->instrument(), 0);
if (si.exec()) {
const InstrumentTemplate* it = si.instrTemplate();
if (it) {
Fraction tickStart = ic->segment()->tick();
Part* part = ic->staff()->part();
Interval oldV = part->instrument(tickStart)->transpose();
//Instrument* oi = ic->instrument(); //part->instrument(tickStart);
//Instrument* instrument = new Instrument(Instrument::fromTemplate(it));
// change instrument in all linked scores
for (ScoreElement* se : ic->linkList()) {
InstrumentChange* lic = toInstrumentChange(se);
Instrument* instrument = new Instrument(Instrument::fromTemplate(it));
lic->score()->undo(new ChangeInstrument(lic, instrument));
}
// transpose for current score only
// this automatically propagates to linked scores
if (part->instrument(tickStart)->transpose() != oldV) {
auto i = part->instruments()->upper_bound(tickStart.ticks()); // find(), ++i
Fraction tickEnd;
if (i == part->instruments()->end())
tickEnd = Fraction(-1, 1);
else
tickEnd = Fraction::fromTicks(i->first);
ic->score()->transpositionChanged(part, oldV, tickStart, tickEnd);
}
}
else
qDebug("no template selected?");
}
}
}

1 change: 1 addition & 0 deletions mscore/scoreview.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ class ScoreView : public QWidget, public MuseScoreView {
virtual Element* elementNear(QPointF);
QList<Element*> elementsNear(QPointF);
void editTremoloBarProperties(TremoloBar*);
void selectInstrument(InstrumentChange*);
EditData& getEditData() { return editData; }
void changeState(ViewState);

Expand Down

0 comments on commit 7a32a58

Please sign in to comment.