Skip to content

Commit

Permalink
Beautified code
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg68 committed Jan 8, 2024
1 parent 1488ab2 commit 37d2d2e
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 152 deletions.
176 changes: 93 additions & 83 deletions src/grandorgue/model/GOSoundingPipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ GOSoundingPipe::GOSoundingPipe(
m_LastStop(0),
m_Instances(0),
m_Tremulant(false),
m_AttackInfo(),
m_ReleaseInfo(),
m_AttackFileInfos(),
m_ReleaseFileInfos(),
m_Filename(),
m_SamplerGroupID(sampler_group_id),
m_AudioGroupID(0),
Expand All @@ -62,16 +62,48 @@ GOSoundingPipe::GOSoundingPipe(
m_PipeConfigNode(
&rank->GetPipeConfig(), pOrganModel, this, &m_SoundProvider) {}

void GOSoundingPipe::LoadAttack(
GOConfigReader &cfg, wxString group, wxString prefix) {
void GOSoundingPipe::Init(
GOConfigReader &cfg,
const wxString &group,
const wxString &prefix,
const wxString &filename) {
SetGroupAndPrefix(group, prefix);
p_OrganModel->RegisterCacheObject(this);
m_Filename = filename;
m_PipeConfigNode.Init(cfg, group, prefix);
m_OdfMidiKeyNumber = -1;
m_OdfMidiPitchFraction = -1.0;
UpdateAmplitude();
p_OrganModel->GetWindchest(m_SamplerGroupID - 1)->AddPipe(this);

GOSoundProviderWave::AttackFileInfo ainfo;

ainfo.filename.AssignResource(m_Filename);
ainfo.sample_group = -1;
ainfo.load_release = !m_Percussive;
ainfo.percussive = m_Percussive;
ainfo.max_playback_time = -1;
ainfo.cue_point = -1;
ainfo.min_attack_velocity = 0;
ainfo.max_released_time = -1;
ainfo.attack_start = 0;
ainfo.release_end = -1;
m_AttackFileInfos.push_back(ainfo);

m_SoundProvider.SetVelocityParameter(m_MinVolume, m_MaxVolume);
m_PipeConfigNode.SetName(
wxString::Format(_("%d: %s"), m_MidiKeyNumber, m_Filename.c_str()));
}

void GOSoundingPipe::LoadAttackFileInfo(
GOConfigReader &cfg, const wxString &group, const wxString &prefix) {
GOSoundProviderWave::AttackFileInfo ainfo;

ainfo.filename.Assign(cfg.ReadFileName(ODFSetting, group, prefix));
ainfo.sample_group = cfg.ReadInteger(
ODFSetting, group, prefix + wxT("IsTremulant"), -1, 1, false, -1);
ainfo.load_release = cfg.ReadBoolean(
ODFSetting, group, prefix + wxT("LoadRelease"), false, !m_Percussive);
;
ainfo.percussive = m_Percussive;
ainfo.max_playback_time = cfg.ReadInteger(
ODFSetting, group, prefix + wxT("MaxKeyPressTime"), -1, 100000, false, -1);
Expand Down Expand Up @@ -133,39 +165,35 @@ void GOSoundingPipe::LoadAttack(
ainfo.loops.push_back(linfo);
}

m_AttackInfo.push_back(ainfo);
m_AttackFileInfos.push_back(ainfo);
}

void GOSoundingPipe::Init(
GOConfigReader &cfg, wxString group, wxString prefix, wxString filename) {
SetGroupAndPrefix(group, prefix);
p_OrganModel->RegisterCacheObject(this);
m_Filename = filename;
m_PipeConfigNode.Init(cfg, group, prefix);
m_OdfMidiKeyNumber = -1;
m_OdfMidiPitchFraction = -1.0;
m_LoopCrossfadeLength = 0;
m_ReleaseCrossfadeLength = 0;
UpdateAmplitude();
p_OrganModel->GetWindchest(m_SamplerGroupID - 1)->AddPipe(this);

GOSoundProviderWave::AttackFileInfo ainfo;
void GOSoundingPipe::LoadReleaseFileInfo(
GOConfigReader &cfg, const wxString &group, const wxString &prefix) {
GOSoundProviderWave::ReleaseFileInfo rinfo;

ainfo.filename.AssignResource(m_Filename);
ainfo.sample_group = -1;
ainfo.load_release = !m_Percussive;
ainfo.percussive = m_Percussive;
ainfo.max_playback_time = -1;
ainfo.cue_point = -1;
ainfo.min_attack_velocity = 0;
ainfo.max_released_time = -1;
ainfo.attack_start = 0;
ainfo.release_end = -1;
m_AttackInfo.push_back(ainfo);

m_SoundProvider.SetVelocityParameter(m_MinVolume, m_MaxVolume);
m_PipeConfigNode.SetName(
wxString::Format(_("%d: %s"), m_MidiKeyNumber, m_Filename.c_str()));
rinfo.filename.Assign(cfg.ReadFileName(ODFSetting, group, prefix));
rinfo.sample_group = cfg.ReadInteger(
ODFSetting, group, prefix + wxT("IsTremulant"), -1, 1, false, -1);
rinfo.max_playback_time = cfg.ReadInteger(
ODFSetting, group, prefix + wxT("MaxKeyPressTime"), -1, 100000, false, -1);
rinfo.cue_point = cfg.ReadInteger(
ODFSetting,
group,
prefix + wxT("CuePoint"),
-1,
MAX_SAMPLE_LENGTH,
false,
-1);
rinfo.release_end = cfg.ReadInteger(
ODFSetting,
group,
prefix + wxT("ReleaseEnd"),
-1,
MAX_SAMPLE_LENGTH,
false,
-1);
m_ReleaseFileInfos.push_back(rinfo);
}

void GOSoundingPipe::Load(
Expand Down Expand Up @@ -217,37 +245,19 @@ void GOSoundingPipe::Load(
UpdateAmplitude();
p_OrganModel->GetWindchest(m_SamplerGroupID - 1)->AddPipe(this);

LoadAttack(cfg, group, prefix);
LoadAttackFileInfo(cfg, group, prefix);

unsigned attack_count = cfg.ReadInteger(
ODFSetting, group, prefix + wxT("AttackCount"), 0, 100, false, 0);
for (unsigned i = 0; i < attack_count; i++)
LoadAttack(cfg, group, prefix + wxString::Format(wxT("Attack%03d"), i + 1));
for (unsigned i = 1; i <= attack_count; i++)
LoadAttackFileInfo(
cfg, group, wxString::Format(wxT("%sAttack%03d"), prefix, i));

unsigned release_count = cfg.ReadInteger(
ODFSetting, group, prefix + wxT("ReleaseCount"), 0, 100, false, 0);
for (unsigned i = 0; i < release_count; i++) {
GOSoundProviderWave::ReleaseFileInfo rinfo;
wxString p = prefix + wxString::Format(wxT("Release%03d"), i + 1);

rinfo.filename.Assign(cfg.ReadFileName(ODFSetting, group, p));
rinfo.sample_group = cfg.ReadInteger(
ODFSetting, group, p + wxT("IsTremulant"), -1, 1, false, -1);
rinfo.max_playback_time = cfg.ReadInteger(
ODFSetting, group, p + wxT("MaxKeyPressTime"), -1, 100000, false, -1);
rinfo.cue_point = cfg.ReadInteger(
ODFSetting, group, p + wxT("CuePoint"), -1, MAX_SAMPLE_LENGTH, false, -1);
rinfo.release_end = cfg.ReadInteger(
ODFSetting,
group,
p + wxT("ReleaseEnd"),
-1,
MAX_SAMPLE_LENGTH,
false,
-1);

m_ReleaseInfo.push_back(rinfo);
}
for (unsigned i = 1; i <= release_count; i++)
LoadReleaseFileInfo(
cfg, group, wxString::Format(wxT("%sRelease%03d"), prefix, i));

m_MinVolume = cfg.ReadFloat(
ODFSetting, group, wxT("MinVelocityVolume"), 0, 1000, false, m_MinVolume);
Expand All @@ -264,8 +274,8 @@ void GOSoundingPipe::LoadData(
m_SoundProvider.LoadFromMultipleFiles(
fileStore,
pool,
m_AttackInfo,
m_ReleaseInfo,
m_AttackFileInfos,
m_ReleaseFileInfos,
m_PipeConfigNode.GetEffectiveBitsPerSample(),
m_PipeConfigNode.GetEffectiveChannels(),
m_PipeConfigNode.GetEffectiveCompress(),
Expand Down Expand Up @@ -316,30 +326,30 @@ void GOSoundingPipe::UpdateHash(GOHash &hash) const {
hash.Update(m_LoopCrossfadeLength);
hash.Update(m_ReleaseCrossfadeLength);

hash.Update(m_AttackInfo.size());
for (unsigned i = 0; i < m_AttackInfo.size(); i++) {
m_AttackInfo[i].filename.Hash(hash);
hash.Update(m_AttackInfo[i].sample_group);
hash.Update(m_AttackInfo[i].max_playback_time);
hash.Update(m_AttackInfo[i].load_release);
hash.Update(m_AttackInfo[i].percussive);
hash.Update(m_AttackInfo[i].cue_point);
hash.Update(m_AttackInfo[i].loops.size());
hash.Update(m_AttackInfo[i].attack_start);
hash.Update(m_AttackInfo[i].release_end);
for (unsigned j = 0; j < m_AttackInfo[i].loops.size(); j++) {
hash.Update(m_AttackInfo[i].loops[j].m_StartPosition);
hash.Update(m_AttackInfo[i].loops[j].m_EndPosition);
hash.Update(m_AttackFileInfos.size());
for (const auto &a : m_AttackFileInfos) {
a.filename.Hash(hash);
hash.Update(a.sample_group);
hash.Update(a.max_playback_time);
hash.Update(a.load_release);
hash.Update(a.percussive);
hash.Update(a.cue_point);
hash.Update(a.loops.size());
hash.Update(a.attack_start);
hash.Update(a.release_end);
for (unsigned j = 0; j < a.loops.size(); j++) {
hash.Update(a.loops[j].m_StartPosition);
hash.Update(a.loops[j].m_EndPosition);
}
}

hash.Update(m_ReleaseInfo.size());
for (unsigned i = 0; i < m_ReleaseInfo.size(); i++) {
m_ReleaseInfo[i].filename.Hash(hash);
hash.Update(m_ReleaseInfo[i].sample_group);
hash.Update(m_ReleaseInfo[i].max_playback_time);
hash.Update(m_ReleaseInfo[i].cue_point);
hash.Update(m_ReleaseInfo[i].release_end);
hash.Update(m_ReleaseFileInfos.size());
for (const auto &r : m_ReleaseFileInfos) {
r.filename.Hash(hash);
hash.Update(r.sample_group);
hash.Update(r.max_playback_time);
hash.Update(r.cue_point);
hash.Update(r.release_end);
}
}

Expand Down
22 changes: 17 additions & 5 deletions src/grandorgue/model/GOSoundingPipe.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-2024 GrandOrgue contributors (see AUTHORS)
* License GPL-2.0 or later
* (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html).
*/
Expand Down Expand Up @@ -29,8 +29,8 @@ class GOSoundingPipe : public GOPipe,
uint64_t m_LastStop;
int m_Instances;
bool m_Tremulant;
std::vector<GOSoundProviderWave::AttackFileInfo> m_AttackInfo;
std::vector<GOSoundProviderWave::ReleaseFileInfo> m_ReleaseInfo;
std::vector<GOSoundProviderWave::AttackFileInfo> m_AttackFileInfos;
std::vector<GOSoundProviderWave::ReleaseFileInfo> m_ReleaseFileInfos;
wxString m_Filename;

/* states which windchest this pipe belongs to, see
Expand All @@ -54,7 +54,16 @@ class GOSoundingPipe : public GOPipe,
GOPipeConfigNode m_PipeConfigNode;

// internal functions
void LoadAttack(GOConfigReader &cfg, wxString group, wxString prefix);
/* Read one attack file info from the odf keys with the prefix specified and
* add it to m_AttackFileInfos
*/
void LoadAttackFileInfo(
GOConfigReader &cfg, const wxString &group, const wxString &prefix);
/* Read one release file info from the odf keys with the prefix specified and
* add it to m_AttackFileInfos
*/
void LoadReleaseFileInfo(
GOConfigReader &cfg, const wxString &group, const wxString &prefix);
/**
* Calculate a pitch offset for manual tuning
* @return pitch offset in cents
Expand Down Expand Up @@ -113,7 +122,10 @@ class GOSoundingPipe : public GOPipe,
bool retune);

void Init(
GOConfigReader &cfg, wxString group, wxString prefix, wxString filename);
GOConfigReader &cfg,
const wxString &group,
const wxString &prefix,
const wxString &filename);
void Load(GOConfigReader &cfg, wxString group, wxString prefix);
};

Expand Down
28 changes: 13 additions & 15 deletions src/grandorgue/model/pipe-config/GOPipeConfigNode.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-2024 GrandOrgue contributors (see AUTHORS)
* License GPL-2.0 or later
* (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html).
*/
Expand Down Expand Up @@ -155,22 +155,20 @@ unsigned GOPipeConfigNode::GetEffectiveLoopLoad() const {
return m_config.LoopLoad();
}

unsigned GOPipeConfigNode::GetEffectiveAttackLoad() const {
if (m_PipeConfig.GetAttackLoad() != -1)
return m_PipeConfig.GetAttackLoad();
if (m_parent)
return m_parent->GetEffectiveAttackLoad();
else
return m_config.AttackLoad();
bool GOPipeConfigNode::GetEffectiveAttackLoad() const {
const int thisConfigValue = m_PipeConfig.GetAttackLoad();

return thisConfigValue != -1 ? (bool)thisConfigValue
: m_parent ? m_parent->GetEffectiveAttackLoad()
: m_config.AttackLoad();
}

unsigned GOPipeConfigNode::GetEffectiveReleaseLoad() const {
if (m_PipeConfig.GetReleaseLoad() != -1)
return m_PipeConfig.GetReleaseLoad();
if (m_parent)
return m_parent->GetEffectiveReleaseLoad();
else
return m_config.ReleaseLoad();
bool GOPipeConfigNode::GetEffectiveReleaseLoad() const {
const int thisConfigValue = m_PipeConfig.GetReleaseLoad();

return thisConfigValue != -1 ? (bool)thisConfigValue
: m_parent ? m_parent->GetEffectiveReleaseLoad()
: m_config.ReleaseLoad();
}

unsigned GOPipeConfigNode::GetEffectiveChannels() const {
Expand Down
6 changes: 3 additions & 3 deletions src/grandorgue/model/pipe-config/GOPipeConfigNode.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-2024 GrandOrgue contributors (see AUTHORS)
* License GPL-2.0 or later
* (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html).
*/
Expand Down Expand Up @@ -61,8 +61,8 @@ class GOPipeConfigNode : private GOSaveableObject {
unsigned GetEffectiveBitsPerSample() const;
bool GetEffectiveCompress() const;
unsigned GetEffectiveLoopLoad() const;
unsigned GetEffectiveAttackLoad() const;
unsigned GetEffectiveReleaseLoad() const;
bool GetEffectiveAttackLoad() const;
bool GetEffectiveReleaseLoad() const;
unsigned GetEffectiveChannels() const;
bool GetEffectiveIgnorePitch() const;
unsigned GetEffectiveReleaseTail() const;
Expand Down
1 change: 1 addition & 0 deletions src/grandorgue/sound/GOSoundAudioSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ void GOAudioSection::Setup(
assert(pcm_data_nb_samples > 0);

const unsigned bytes_per_sample = wave_bytes_per_sample(pcm_data_format);

m_BytesPerSample = bytes_per_sample * pcm_data_channels;

unsigned total_alloc_samples = pcm_data_nb_samples;
Expand Down
1 change: 1 addition & 0 deletions src/grandorgue/sound/GOSoundAudioSection.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ class GOAudioSection {
unsigned GetChannels() const;
unsigned GetBytesPerSample() const;
unsigned GetLength() const;

bool LoadCache(GOCache &cache);
bool SaveCache(GOCacheWriter &cache) const;

Expand Down
Loading

0 comments on commit 37d2d2e

Please sign in to comment.