Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intoduced a new class GOMidiObjectContext #2131

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions src/grandorgue/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ loader/cache/GOCacheCleaner.cpp
loader/cache/GOCacheWriter.cpp
midi/dialog-creator/GOMidiDialogCreatorProxy.cpp
midi/objects/GOMidiObject.cpp
midi/objects/GOMidiObjectContext.cpp
midi/objects/GOMidiObjectWithDivision.cpp
midi/objects/GOMidiObjectWithShortcut.cpp
midi/objects/GOMidiReceivingSendingObject.cpp
Expand Down
21 changes: 12 additions & 9 deletions src/grandorgue/control/GOElementCreator.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2006 Milan Digital Audio LLC
* Copyright 2009-2023 GrandOrgue contributors (see AUTHORS)
* Copyright 2009-2025 GrandOrgue contributors (see AUTHORS)
* License GPL-2.0 or later
* (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html).
*/
Expand All @@ -10,14 +10,17 @@
#include "GOCallbackButtonControl.h"

void GOElementCreator::CreateButtons(GOOrganModel &organModel) {
const struct ButtonDefinitionEntry *entries = GetButtonDefinitionList();
for (unsigned i = 0;
entries[i].name != wxEmptyString && entries[i].value >= 0;
i++) {
if (m_buttons.size() <= (unsigned)entries[i].value)
m_buttons.resize(entries[i].value + 1);
m_buttons[entries[i].value] = new GOCallbackButtonControl(
organModel, this, entries[i].is_pushbutton, entries[i].is_piston);
for (const ButtonDefinitionEntry *pEntry = GetButtonDefinitionList();
!pEntry->name.IsEmpty() && pEntry->value >= 0;
pEntry++) {
GOCallbackButtonControl *pButton = new GOCallbackButtonControl(
organModel, this, pEntry->is_pushbutton, pEntry->is_piston);
const unsigned buttonIndex = (unsigned)pEntry->value;

pButton->SetContext(pEntry->p_MidiContext);
if (m_buttons.size() <= buttonIndex)
m_buttons.resize(buttonIndex + 1);
m_buttons[buttonIndex] = pButton;
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/grandorgue/control/GOElementCreator.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2006 Milan Digital Audio LLC
* Copyright 2009-2023 GrandOrgue contributors (see AUTHORS)
* Copyright 2009-2025 GrandOrgue contributors (see AUTHORS)
* License GPL-2.0 or later
* (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html).
*/
Expand All @@ -15,9 +15,10 @@

class GOButtonControl;
class GOConfigReader;
class GOOrganModel;
class GOEnclosure;
class GOLabelControl;
class GOMidiObjectContext;
class GOOrganModel;

class GOElementCreator : private GOButtonCallback {
public:
Expand All @@ -27,6 +28,7 @@ class GOElementCreator : private GOButtonCallback {
bool is_public;
bool is_pushbutton;
bool is_piston;
const GOMidiObjectContext *p_MidiContext = nullptr;
};

protected:
Expand Down
13 changes: 6 additions & 7 deletions src/grandorgue/control/GOLabelControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
const wxString WX_MIDI_TYPE_CODE = wxT("Label");
const wxString WX_MIDI_TYPE_NAME = _("Label");

GOLabelControl::GOLabelControl(GOOrganModel &organModel)
GOLabelControl::GOLabelControl(
GOOrganModel &organModel, const GOMidiObjectContext *pContext)
: GOMidiSendingObject(
organModel, WX_MIDI_TYPE_CODE, WX_MIDI_TYPE_NAME, MIDI_SEND_LABEL) {}

const wxString &GOLabelControl::GetContent() { return m_Content; }
organModel, WX_MIDI_TYPE_CODE, WX_MIDI_TYPE_NAME, MIDI_SEND_LABEL) {
SetContext(pContext);
}

void GOLabelControl::SetContent(wxString name) {
void GOLabelControl::SetContent(const wxString &name) {
m_Content = name;
SendMidiValue(m_Content);
r_OrganModel.SendControlChanged(this);
Expand All @@ -36,8 +37,6 @@ void GOLabelControl::PrepareRecording() {
SendMidiValue(m_Content);
}

wxString GOLabelControl::GetElementStatus() { return m_Content; }

std::vector<wxString> GOLabelControl::GetElementActions() {
std::vector<wxString> actions;
return actions;
Expand Down
10 changes: 6 additions & 4 deletions src/grandorgue/control/GOLabelControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

class GOConfigReader;
class GOConfigWriter;
class GOMidiObjectContext;
class GOOrganModel;

class GOLabelControl : public GOControl, public GOMidiSendingObject {
Expand All @@ -29,11 +30,12 @@ class GOLabelControl : public GOControl, public GOMidiSendingObject {
void PrepareRecording() override;

public:
GOLabelControl(GOOrganModel &organModel);
const wxString &GetContent();
void SetContent(wxString name);
GOLabelControl(
GOOrganModel &organModel, const GOMidiObjectContext *pContext = nullptr);
const wxString &GetContent() const { return m_Content; }
void SetContent(const wxString &name);

wxString GetElementStatus() override;
wxString GetElementStatus() override { return m_Content; }
std::vector<wxString> GetElementActions() override;
void TriggerElementActions(unsigned no) override;
};
Expand Down
9 changes: 8 additions & 1 deletion src/grandorgue/midi/objects/GOMidiObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "midi/GOMidiReceiver.h"
#include "model/GOOrganModel.h"

#include "GOMidiObjectContext.h"

GOMidiObject::GOMidiObject(
GOOrganModel &organModel,
const wxString &midiTypeCode,
Expand All @@ -23,7 +25,8 @@ GOMidiObject::GOMidiObject(
p_MidiSender(nullptr),
p_MidiReceiver(nullptr),
p_ShortcutReceiver(nullptr),
p_DivisionSender(nullptr) {
p_DivisionSender(nullptr),
p_context(nullptr) {
r_OrganModel.RegisterSoundStateHandler(this);
r_OrganModel.RegisterMidiObject(this);
}
Expand All @@ -34,6 +37,10 @@ GOMidiObject::~GOMidiObject() {
r_OrganModel.UnRegisterSoundStateHandler(this);
}

wxString GOMidiObject::GetContextTitle() const {
return GOMidiObjectContext::getFullTitle(p_context);
}

void GOMidiObject::InitMidiObject(
GOConfigReader &cfg, const wxString &group, const wxString &name) {
SetGroup(group);
Expand Down
8 changes: 8 additions & 0 deletions src/grandorgue/midi/objects/GOMidiObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "GOSaveableObject.h"

class GOMidiMap;
class GOMidiObjectContext;
class GOMidiReceiver;
class GOMidiSender;
class GOMidiShortcutReceiver;
Expand All @@ -38,6 +39,8 @@ class GOMidiObject : public GOSoundStateHandler, public GOSaveableObject {
GOMidiShortcutReceiver *p_ShortcutReceiver;
GOMidiSender *p_DivisionSender;

const GOMidiObjectContext *p_context;

protected:
GOMidiObject(
GOOrganModel &organModel,
Expand Down Expand Up @@ -80,6 +83,11 @@ class GOMidiObject : public GOSoundStateHandler, public GOSaveableObject {
const wxString &GetName() const { return m_name; }
void SetName(const wxString &name) { m_name = name; }

const GOMidiObjectContext *GetContext() const { return p_context; }
void SetContext(const GOMidiObjectContext *pContext) { p_context = pContext; }

wxString GetContextTitle() const;

virtual void Init(
GOConfigReader &cfg, const wxString &group, const wxString &name) {
InitMidiObject(cfg, group, name);
Expand Down
28 changes: 28 additions & 0 deletions src/grandorgue/midi/objects/GOMidiObjectContext.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2006 Milan Digital Audio LLC
* Copyright 2009-2025 GrandOrgue contributors (see AUTHORS)
* License GPL-2.0 or later
* (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html).
*/

#include "GOMidiObjectContext.h"

const wxString WX_PATH_SEPARATOR = "/";

GOMidiObjectContext::GOMidiObjectContext(
const wxString &name,
const wxString &title,
const GOMidiObjectContext *pParent)
: m_name(name), m_title(title), p_parent(pParent) {}

wxString GOMidiObjectContext::getFullTitle(
const GOMidiObjectContext *pContext) {
wxString path;

for (; pContext; pContext = pContext->p_parent) {
if (!path.IsEmpty())
path = WX_PATH_SEPARATOR + path;
path = pContext->m_title + path;
}
return path;
}
46 changes: 46 additions & 0 deletions src/grandorgue/midi/objects/GOMidiObjectContext.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2006 Milan Digital Audio LLC
* Copyright 2009-2025 GrandOrgue contributors (see AUTHORS)
* License GPL-2.0 or later
* (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html).
*/

#ifndef GOMIDIOBJECTCONTEXT_H
#define GOMIDIOBJECTCONTEXT_H

#include <wx/string.h>

/**
* This class is used for describing a place where a midi object is used.
* There is a hierarhial tree of contexts. For example, setter, manuals/1/stops,
* manuals/1/divisionals
*/

class GOMidiObjectContext {
private:
// Name. Not translated. Used for exports
wxString m_name;

// Title. Translated. Used in UI
wxString m_title;

// Parent context
const GOMidiObjectContext *p_parent;

public:
GOMidiObjectContext(
const wxString &name,
const wxString &title,
const GOMidiObjectContext *pParent = nullptr);
GOMidiObjectContext()
: GOMidiObjectContext(wxEmptyString, wxEmptyString, nullptr) {}

const wxString &GetName() const { return m_name; }
const wxString &GetTitle() const { return m_title; }
void SetTitle(const wxString title) { m_title = title; }
const GOMidiObjectContext *GetParent() const { return p_parent; }

static wxString getFullTitle(const GOMidiObjectContext *pContext);
};

#endif /* GOMIDIOBJECTCONTEXT_H */