Skip to content

Commit 99a8527

Browse files
authored
Fixed crash of reference pipes with the "--gui-only" option #2019 (#2038)
1 parent 1a91922 commit 99a8527

9 files changed

+79
-15
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
- Fixed crash of reference pipes with the "--justgui" option https://github.com/GrandOrgue/grandorgue/issues/2019
12
- Fixed crash on attempt of loading an organ if it's files did not exist https://github.com/GrandOrgue/grandorgue/issues/1990
23
- Fixed the sequencer "Save file" button not lightening after inserting or deleting a combination https://github.com/GrandOrgue/grandorgue/issues/2024
34
- Fixed appearence, sizing and the scrollbar issues with the Stops window https://github.com/GrandOrgue/grandorgue/issues/1961

src/grandorgue/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ model/GOOrganModel.cpp
179179
model/GOPipe.cpp
180180
model/GORank.cpp
181181
model/GOReferencePipe.cpp
182+
model/GOReferencingObject.cpp
182183
model/GOSoundingPipe.cpp
183184
model/GOStop.cpp
184185
model/GOSwitch.cpp

src/grandorgue/model/GOEventHandlerList.h

+13
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class GOControl;
1818
class GOControlChangedHandler;
1919
class GOEventHandler;
2020
class GOMidiConfigurator;
21+
class GOReferencingObject;
2122
class GOSoundStateHandler;
2223
class GOSaveableObject;
2324

@@ -57,6 +58,7 @@ class GOEventHandlerList {
5758
};
5859

5960
UPVector<GOCacheObject> m_CacheObjects;
61+
UPVector<GOReferencingObject> m_ReferencingObjects;
6062
UPVector<GOCombinationButtonSet> m_CombinationButtonSets;
6163
UPVector<GOControlChangedHandler> m_ControlChangedHandlers;
6264
UPVector<GOMidiConfigurator> m_MidiConfigurators;
@@ -68,6 +70,9 @@ class GOEventHandlerList {
6870
const std::vector<GOCacheObject *> &GetCacheObjects() const {
6971
return m_CacheObjects.AsVector();
7072
}
73+
const std::vector<GOReferencingObject *> &GetReferencingObjects() const {
74+
return m_ReferencingObjects.AsVector();
75+
}
7176
const std::vector<GOCombinationButtonSet *> &GetCombinationButtonSets()
7277
const {
7378
return m_CombinationButtonSets.AsVector();
@@ -87,6 +92,14 @@ class GOEventHandlerList {
8792

8893
void RegisterCacheObject(GOCacheObject *obj) { m_CacheObjects.Add(obj); }
8994

95+
void RegisterReferencingObject(GOReferencingObject *pObj) {
96+
m_ReferencingObjects.Add(pObj);
97+
}
98+
99+
void UnRegisterReferencingObject(GOReferencingObject *pObj) {
100+
m_ReferencingObjects.Remove(pObj);
101+
}
102+
90103
void RegisterCombinationButtonSet(GOCombinationButtonSet *obj) {
91104
m_CombinationButtonSets.Add(obj);
92105
}

src/grandorgue/model/GOOrganModel.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "GOEnclosure.h"
1818
#include "GOManual.h"
1919
#include "GORank.h"
20+
#include "GOReferencingObject.h"
2021
#include "GOSwitch.h"
2122
#include "GOTremulant.h"
2223
#include "GOWindchest.h"
@@ -169,6 +170,9 @@ void GOOrganModel::Load(GOConfigReader &cfg) {
169170
for (unsigned i = 0; i < m_tremulants.size(); i++)
170171
m_tremulants[i]->SetElementID(
171172
GetRecorderElementID(wxString::Format(wxT("T%d"), i)));
173+
174+
for (GOReferencingObject *pObj : GetReferencingObjects())
175+
pObj->ResolveReferences();
172176
}
173177

174178
void GOOrganModel::LoadCmbButtons(GOConfigReader &cfg) {

src/grandorgue/model/GOReferencePipe.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#include <wx/intl.h>
1111
#include <wx/tokenzr.h>
1212

13-
#include "config/GOConfigReader.h"
14-
1513
#include "GOManual.h"
1614
#include "GOOrganModel.h"
1715
#include "GORank.h"
@@ -20,21 +18,20 @@
2018
GOReferencePipe::GOReferencePipe(
2119
GOOrganModel *model, GORank *rank, unsigned midi_key_number)
2220
: GOPipe(model, rank, midi_key_number),
21+
GOReferencingObject(*model),
2322
m_model(model),
2423
m_Reference(NULL),
2524
m_ReferenceID(0),
2625
m_Filename() {}
2726

2827
void GOReferencePipe::Load(
2928
GOConfigReader &cfg, const wxString &group, const wxString &prefix) {
30-
SetGroupAndPrefix(group, prefix);
31-
m_model->RegisterCacheObject(this);
3229
m_Filename = cfg.ReadStringTrim(ODFSetting, group, prefix);
3330
if (!m_Filename.StartsWith(wxT("REF:")))
3431
throw(wxString) _("ReferencePipe without Reference");
3532
}
3633

37-
void GOReferencePipe::Initialize() {
34+
void GOReferencePipe::OnResolvingReferences() {
3835
if (!m_Filename.StartsWith(wxT("REF:")))
3936
throw(wxString) _("ReferencePipe without Reference");
4037

src/grandorgue/model/GOReferencePipe.h

+3-7
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,18 @@
1010

1111
#include "GOCacheObject.h"
1212
#include "GOPipe.h"
13+
#include "GOReferencingObject.h"
1314

1415
class GOOrganModel;
1516

16-
class GOReferencePipe : public GOPipe, private GOCacheObject {
17+
class GOReferencePipe : public GOPipe, public GOReferencingObject {
1718
private:
1819
GOOrganModel *m_model;
1920
GOPipe *m_Reference;
2021
unsigned m_ReferenceID;
2122
wxString m_Filename;
2223

23-
void Initialize() override;
24-
void LoadData(const GOFileStore &fileStore, GOMemoryPool &pool) override {}
25-
bool LoadCache(GOMemoryPool &pool, GOCache &cache) override { return true; }
26-
bool SaveCache(GOCacheWriter &cache) const override { return true; }
27-
void UpdateHash(GOHash &hash) const override {}
28-
const wxString &GetLoadTitle() const override { return m_Filename; }
24+
void OnResolvingReferences() override;
2925

3026
void VelocityChanged(unsigned velocity, unsigned old_velocity) override;
3127

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2006 Milan Digital Audio LLC
3+
* Copyright 2009-2024 GrandOrgue contributors (see AUTHORS)
4+
* License GPL-2.0 or later
5+
* (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html).
6+
*/
7+
8+
#include "GOReferencingObject.h"
9+
10+
#include "GOEventHandlerList.h"
11+
12+
GOReferencingObject::GOReferencingObject(GOEventHandlerList &handlerList)
13+
: r_HandlerList(handlerList) {
14+
r_HandlerList.RegisterReferencingObject(this);
15+
}
16+
17+
GOReferencingObject::~GOReferencingObject() {
18+
r_HandlerList.UnRegisterReferencingObject(this);
19+
}
20+
21+
void GOReferencingObject::ResolveReferences() {
22+
if (!m_HasBeenResolved) {
23+
OnResolvingReferences();
24+
m_HasBeenResolved = true;
25+
}
26+
}
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2006 Milan Digital Audio LLC
3+
* Copyright 2009-2024 GrandOrgue contributors (see AUTHORS)
4+
* License GPL-2.0 or later
5+
* (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html).
6+
*/
7+
8+
#ifndef GOREFERENCINGOBJECT_H
9+
#define GOREFERENCINGOBJECT_H
10+
11+
class GOEventHandlerList;
12+
13+
class GOReferencingObject {
14+
private:
15+
GOEventHandlerList &r_HandlerList;
16+
bool m_HasBeenResolved = false;
17+
18+
protected:
19+
virtual void OnResolvingReferences() {}
20+
21+
public:
22+
GOReferencingObject(GOEventHandlerList &handlerList);
23+
virtual ~GOReferencingObject();
24+
25+
void ResolveReferences();
26+
};
27+
28+
#endif /* GOREFERENCINGOBJECT_H */

src/grandorgue/model/GOTremulant.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ void GOTremulant::OnDrawstopStateChanged(bool on) {
100100
m_PlaybackHandle = pSoundEngine ? pSoundEngine->StartTremulantSample(
101101
m_TremProvider, m_TremulantN, m_LastStop)
102102
: nullptr;
103-
on = (m_PlaybackHandle != nullptr);
104-
} else {
105-
assert(m_PlaybackHandle);
103+
} else if (m_PlaybackHandle) {
106104
m_LastStop = pSoundEngine
107105
? pSoundEngine->StopSample(m_TremProvider, m_PlaybackHandle)
108106
: 0;

0 commit comments

Comments
 (0)