Skip to content

Commit

Permalink
Implemented duplication of a panel by right-click in the organ tree. …
Browse files Browse the repository at this point in the history
…Don't write sharp key width if not necessary. Also check tremulants for switch usage/references.
  • Loading branch information
larspalo committed Jul 27, 2024
1 parent cae4bce commit 806155b
Show file tree
Hide file tree
Showing 32 changed files with 157 additions and 3 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Option to create new panel from selection on existing panel display. (TODO)
- Option to duplicate an existing panel. (TODO)

## [0.15.0] - 2024-07-27

### Added

- Option to duplicate an existing panel by right-clicking on it in the organ tree.
- Setter element CrescendoOverride.

### Fixed
Expand All @@ -24,6 +29,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Issue/Bug on the msw port in the PipeDialog that would cause forcing selection of IsPercussive=Y when navigating with "Next" button to the last pipe
- Direct right-click on a pipe in rank pipe tree that previously didn't create a true selection of a pipe in the msw port.
- Restore focus to main window after opening an .organ file on the msw port (make sure it's raised).
- Not writing Key999Width for sharps when not necessary (could potentially mess up the layout of keys).
- Take tremulants into accound when checking if a switch is referenced anywhere.

## [0.14.0] - 2024-07-02

Expand Down
50 changes: 50 additions & 0 deletions src/GOODFFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,56 @@ void GOODFFrame::OnOrganTreeRightClicked(wxTreeEvent& event) {
event.Skip();
return;
}

if (parentId == tree_panels) {
// A panel was right clicked, should it be duplicated?
if (m_organ->getNumberOfPanels() < 1000) {
wxMessageDialog dlg(this, wxT("Do you want to duplicate the right-clicked panel?"), wxT("Duplicate panel?"), wxYES_NO|wxCENTRE);
if (dlg.ShowModal() == wxID_YES) {
int selectedPanelIndex = 0;
int numPanels = m_organTreeCtrl->GetChildrenCount(tree_panels, false);
wxTreeItemIdValue cookie;
for (int i = 0; i < numPanels; i++) {
wxTreeItemId currentId;
if (i == 0)
currentId = m_organTreeCtrl->GetFirstChild(tree_panels, cookie);
else
currentId = m_organTreeCtrl->GetNextChild(tree_panels, cookie);
if (clickedId == currentId)
selectedPanelIndex = i;
}

GoPanel p = *(m_organ->getOrganPanelAt(selectedPanelIndex));
m_organ->addPanel(p);
wxTreeItemId thisPanel = m_organTreeCtrl->AppendItem(tree_panels, p.getName());
// create the subitems for Displaymetrics, Images and GUIElements
m_organTreeCtrl->AppendItem(thisPanel, wxT("Displaymetrics"));
wxTreeItemId panelImages = m_organTreeCtrl->AppendItem(thisPanel, wxT("Images"));
for (unsigned i = 0; i < p.getNumberOfImages(); i++) {
wxString displayName = p.getImageAt(i)->getImageNameOnly();
if (displayName == wxEmptyString)
displayName = wxT("New Image");
m_organTreeCtrl->AppendItem(panelImages, displayName);
}
wxTreeItemId panelGuiElements = m_organTreeCtrl->AppendItem(thisPanel, wxT("GUI Elements"));
for (int i = 0; i < p.getNumberOfGuiElements(); i++) {
m_organTreeCtrl->AppendItem(panelGuiElements, p.getGuiElementAt(i)->getDisplayName());
}
m_organ->setModified(true);
m_organTreeCtrl->SelectItem(thisPanel);

} else {
event.Skip();
return;
}
} else {
wxMessageDialog msg(this, wxT("Organ cannot have more than 1000 panels!"), wxT("Too many panels"), wxOK|wxCENTRE|wxICON_EXCLAMATION);
msg.ShowModal();
event.Skip();
return;
}
}

wxTreeItemId grandParentId = m_organTreeCtrl->GetItemParent(parentId);
if (grandParentId != tree_organ && m_organTreeCtrl->GetItemParent(grandParentId) == tree_panels) {
int selectedIndex = 0;
Expand Down
5 changes: 5 additions & 0 deletions src/GUIButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@ void GUIButton::read(wxFileConfig *cfg, bool isPiston, Organ *readOrgan) {
setTextBreakWidth(0);
}


GUIButton* GUIButton::clone() {
return new GUIButton(*this);
}

void GUIButton::updateDisplayName() {

}
Expand Down
1 change: 1 addition & 0 deletions src/GUIButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class GUIButton : public GUIElement {
virtual void write(wxTextFile *outFile);
virtual void read(wxFileConfig *cfg, bool isPiston, Organ *readOrgan);

virtual GUIButton* clone();
virtual void updateDisplayName();
virtual wxBitmap getBitmap();
virtual wxString getElementName();
Expand Down
4 changes: 4 additions & 0 deletions src/GUICoupler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ void GUICoupler::write(wxTextFile *outFile) {
GUIButton::write(outFile);
}

GUICoupler* GUICoupler::clone() {
return new GUICoupler(*this);
}

bool GUICoupler::isReferencing(Coupler *cplr) {
return m_coupler == cplr ? true : false;
}
Expand Down
1 change: 1 addition & 0 deletions src/GUICoupler.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class GUICoupler : public GUIButton {
~GUICoupler();

void write(wxTextFile *outFile);
virtual GUICoupler* clone();
bool isReferencing(Coupler *cplr);
void updateDisplayName();
wxString getElementName();
Expand Down
4 changes: 4 additions & 0 deletions src/GUIDivisional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ void GUIDivisional::write(wxTextFile *outFile) {
GUIButton::write(outFile);
}

GUIDivisional* GUIDivisional::clone() {
return new GUIDivisional(*this);
}

bool GUIDivisional::isReferencing(Divisional *divisional) {
return m_divisional == divisional ? true : false;
}
Expand Down
1 change: 1 addition & 0 deletions src/GUIDivisional.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class GUIDivisional : public GUIButton {
~GUIDivisional();

void write(wxTextFile *outFile);
virtual GUIDivisional* clone();
bool isReferencing(Divisional *divisional);
void updateDisplayName();
wxString getElementName();
Expand Down
4 changes: 4 additions & 0 deletions src/GUIDivisionalCoupler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ void GUIDivisionalCoupler::write(wxTextFile *outFile) {
GUIButton::write(outFile);
}

GUIDivisionalCoupler* GUIDivisionalCoupler::clone() {
return new GUIDivisionalCoupler(*this);
}

bool GUIDivisionalCoupler::isReferencing(DivisionalCoupler *divCplr) {
return m_divCoupler == divCplr ? true : false;
}
Expand Down
1 change: 1 addition & 0 deletions src/GUIDivisionalCoupler.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class GUIDivisionalCoupler : public GUIButton {
~GUIDivisionalCoupler();

void write(wxTextFile *outFile);
virtual GUIDivisionalCoupler* clone();
bool isReferencing(DivisionalCoupler *divisional);
void updateDisplayName();
wxString getElementName();
Expand Down
4 changes: 4 additions & 0 deletions src/GUIElements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ void GUIElement::read(wxFileConfig *cfg) {
m_type = cfg->Read("Type", wxEmptyString);
}

GUIElement* GUIElement::clone() {
return nullptr;
}

void GUIElement::updateDisplayName() {

}
Expand Down
1 change: 1 addition & 0 deletions src/GUIElements.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class GUIElement {
virtual void write(wxTextFile *outFile);
virtual void read(wxFileConfig *cfg);

virtual GUIElement* clone();
virtual void updateDisplayName();
virtual void setDefaultFont(wxFont&);
virtual wxBitmap getBitmap();
Expand Down
4 changes: 4 additions & 0 deletions src/GUIEnclosure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ void GUIEnclosure::read(wxFileConfig *cfg, Organ *readOrgan) {
setTextBreakWidth(0);
}

GUIEnclosure* GUIEnclosure::clone() {
return new GUIEnclosure(*this);
}

bool GUIEnclosure::isReferencing(Enclosure *enclosure) {
return m_enclosure == enclosure ? true : false;
}
Expand Down
1 change: 1 addition & 0 deletions src/GUIEnclosure.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class GUIEnclosure : public GUIElement {
void write(wxTextFile *outFile);
void read(wxFileConfig *cfg, Organ *readOrgan);

virtual GUIEnclosure* clone();
bool isReferencing(Enclosure *enclosure);
void updateDisplayName();
virtual wxBitmap getBitmap();
Expand Down
4 changes: 4 additions & 0 deletions src/GUIGeneral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ void GUIGeneral::write(wxTextFile *outFile) {
GUIButton::write(outFile);
}

GUIGeneral* GUIGeneral::clone() {
return new GUIGeneral(*this);
}

bool GUIGeneral::isReferencing(General *general) {
return m_general == general ? true : false;
}
Expand Down
1 change: 1 addition & 0 deletions src/GUIGeneral.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class GUIGeneral : public GUIButton {
~GUIGeneral();

void write(wxTextFile *outFile);
virtual GUIGeneral* clone();
bool isReferencing(General *general);
void updateDisplayName();
wxString getElementName();
Expand Down
4 changes: 4 additions & 0 deletions src/GUILabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ void GUILabel::read(wxFileConfig *cfg, Organ *readOrgan) {
}
}

GUILabel* GUILabel::clone() {
return new GUILabel(*this);
}

void GUILabel::updateDisplayName() {
if (m_type.IsSameAs(wxT("Label"))) {
if (m_name != wxEmptyString) {
Expand Down
1 change: 1 addition & 0 deletions src/GUILabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class GUILabel : public GUIElement {

void write(wxTextFile *outFile);
void read(wxFileConfig *cfg, Organ *readOrgan);
virtual GUILabel* clone();

void updateDisplayName();

Expand Down
6 changes: 5 additions & 1 deletion src/GUIManual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ void GUIManual::read(wxFileConfig *cfg, Organ *readOrgan) {
updateKeyInfo();
}

GUIManual* GUIManual::clone() {
return new GUIManual(*this);
}

bool GUIManual::isReferencing(Manual *man) {
return m_manual == man ? true : false;
}
Expand Down Expand Up @@ -668,7 +672,7 @@ int GUIManual::baseKeyTypeExistAtIndex(wxString keyNbrType) {

bool GUIManual::keyNbrOverrideBaseKeyWidth(KEYTYPE *key) {
int possibleOverride = baseKeyTypeExistAtIndex(key->KeytypeIdentifier);
if (possibleOverride > -1 && possibleOverride < (int) m_keytypes.size()) {
if (possibleOverride > -1 && possibleOverride < (int) m_keytypes.size() && !key->IsSharp) {
if (key->Width != getKeytypeAt((unsigned) possibleOverride)->Width)
return true;
else
Expand Down
1 change: 1 addition & 0 deletions src/GUIManual.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class GUIManual : public GUIElement {
void write(wxTextFile *outFile);
void read(wxFileConfig *cfg, Organ *readOrgan);

virtual GUIManual* clone();
bool isReferencing(Manual *man);
void updateDisplayName();

Expand Down
4 changes: 4 additions & 0 deletions src/GUIReversiblePiston.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ void GUIReversiblePiston::write(wxTextFile *outFile) {
GUIButton::write(outFile);
}

GUIReversiblePiston* GUIReversiblePiston::clone() {
return new GUIReversiblePiston(*this);
}

bool GUIReversiblePiston::isReferencing(ReversiblePiston *reversiblePiston) {
return m_reversiblePiston == reversiblePiston ? true : false;
}
Expand Down
1 change: 1 addition & 0 deletions src/GUIReversiblePiston.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class GUIReversiblePiston : public GUIButton {
~GUIReversiblePiston();

void write(wxTextFile *outFile);
virtual GUIReversiblePiston* clone();
bool isReferencing(ReversiblePiston *reversiblePiston);
void updateDisplayName();
wxString getElementName();
Expand Down
4 changes: 4 additions & 0 deletions src/GUIStop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ void GUIStop::write(wxTextFile *outFile) {
GUIButton::write(outFile);
}

GUIStop* GUIStop::clone() {
return new GUIStop(*this);
}

bool GUIStop::isReferencing(Stop *stop) {
return m_stop == stop ? true : false;
}
Expand Down
1 change: 1 addition & 0 deletions src/GUIStop.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class GUIStop : public GUIButton {
virtual ~GUIStop();

void write(wxTextFile *outFile);
virtual GUIStop* clone();
bool isReferencing(Stop *stop);
void updateDisplayName();
wxString getElementName();
Expand Down
4 changes: 4 additions & 0 deletions src/GUISwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ void GUISwitch::read(wxFileConfig *cfg, Organ *readOrgan) {
GUIButton::read(cfg, false, readOrgan);
}

GUISwitch* GUISwitch::clone() {
return new GUISwitch(*this);
}

bool GUISwitch::isReferencing(GoSwitch *sw) {
return m_switch == sw ? true : false;
}
Expand Down
1 change: 1 addition & 0 deletions src/GUISwitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class GUISwitch : public GUIButton {
void write(wxTextFile *outFile);
void read(wxFileConfig *cfg, Organ *readOrgan);

virtual GUISwitch* clone();
bool isReferencing(GoSwitch *sw);
void updateDisplayName();
wxString getElementName();
Expand Down
4 changes: 4 additions & 0 deletions src/GUITremulant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ void GUITremulant::read(wxFileConfig *cfg, Organ *readOrgan) {
GUIButton::read(cfg, false, readOrgan);
}

GUITremulant* GUITremulant::clone() {
return new GUITremulant(*this);
}

bool GUITremulant::isReferencing(Tremulant *tremulant) {
return m_tremulant == tremulant ? true : false;
}
Expand Down
1 change: 1 addition & 0 deletions src/GUITremulant.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class GUITremulant : public GUIButton {
void write(wxTextFile *outFile);
void read(wxFileConfig *cfg, Organ *readOrgan);

virtual GUITremulant* clone();
bool isReferencing(Tremulant *tremulant);
void updateDisplayName();
wxString getElementName();
Expand Down
19 changes: 19 additions & 0 deletions src/GoPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@ GoPanel::GoPanel() {
m_isGuiElementFirstRemoval = true;
}

GoPanel::GoPanel(const GoPanel& p) {
m_name = p.m_name;
m_group = p.m_group;
m_hasPedals = p.m_hasPedals;
m_isGuiElementFirstRemoval = true;
m_displayMetrics = p.m_displayMetrics;

for (GoImage img : p.m_images) {
addImage(img);
}

for (GUIElement *e : p.m_guiElements) {
addGuiElement(e->clone());
}

updateGuiManuals();
updateGuiEnclosures();
}

GoPanel::~GoPanel() {
m_guiElements.remove_if([](GUIElement *element){delete element; return true;});
}
Expand Down
1 change: 1 addition & 0 deletions src/GoPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Organ;
class GoPanel {
public:
GoPanel();
GoPanel(const GoPanel& p);
~GoPanel();

void write(wxTextFile *outFile, unsigned panelNbr);
Expand Down
11 changes: 11 additions & 0 deletions src/Organ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2016,6 +2016,17 @@ bool Organ::isElementReferenced(GoSwitch *sw) {
}
}

if (!isReferenced) {
for (Tremulant &trem : m_Tremulants) {
if (!trem.getFunction().IsSameAs(wxT("Input"))) {
if (trem.hasSwitchReference(sw)) {
isReferenced = true;
break;
}
}
}
}

if (!isReferenced) {
for (Coupler &c : m_Couplers) {
if (c.hasSwitchReference(sw)) {
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.14.0
0.15.0

0 comments on commit 806155b

Please sign in to comment.