Skip to content

Commit

Permalink
Changes according to discussion in GrandOrgue#1333
Browse files Browse the repository at this point in the history
  • Loading branch information
larspalo committed Jan 13, 2023
1 parent 0e75cd5 commit 1185b9b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 29 deletions.
8 changes: 4 additions & 4 deletions src/core/temperaments/GOTemperament.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ GOTemperament::GOTemperament(wxString name, wxString group)
m_GroupTitle(wxEmptyString),
m_Name(name),
m_Title(wxEmptyString),
m_respectPitchTuning(true) {}
m_IsTemperamentOriginalBased(true) {}

GOTemperament::GOTemperament(
wxString name, wxString title, wxString group, wxString groupTitle)
: m_Group(group),
m_GroupTitle(groupTitle),
m_Name(name),
m_Title(title),
m_respectPitchTuning(true) {}
m_IsTemperamentOriginalBased(true) {}

GOTemperament::~GOTemperament() {}

Expand All @@ -40,6 +40,6 @@ wxString GOTemperament::GetGroupTitle() const {
return m_GroupTitle.IsEmpty() ? wxGetTranslation(m_Group) : m_GroupTitle;
}

bool GOTemperament::GetRespectPitchTuning() const {
return m_respectPitchTuning;
bool GOTemperament::GetIsTemperamentOriginalBased() const {
return m_IsTemperamentOriginalBased;
}
4 changes: 2 additions & 2 deletions src/core/temperaments/GOTemperament.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GOTemperament {
wxString m_GroupTitle;
wxString m_Name;
wxString m_Title;
bool m_respectPitchTuning;
bool m_IsTemperamentOriginalBased; // To know how tuning should be handled

public:
GOTemperament(wxString name, wxString group = wxEmptyString);
Expand All @@ -29,7 +29,7 @@ class GOTemperament {
wxString GetTitle() const;
wxString GetGroup() const;
wxString GetGroupTitle() const;
bool GetRespectPitchTuning() const;
bool GetIsTemperamentOriginalBased() const;
};

#endif
6 changes: 3 additions & 3 deletions src/core/temperaments/GOTemperamentCent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ GOTemperamentCent::GOTemperamentCent(
m_Tuning[9] = 0;
m_Tuning[10] = 0;
m_Tuning[11] = 0;
m_respectPitchTuning = false;
m_IsTemperamentOriginalBased = false;
}

GOTemperamentCent::GOTemperamentCent(
Expand Down Expand Up @@ -54,7 +54,7 @@ GOTemperamentCent::GOTemperamentCent(
m_Tuning[9] = i10;
m_Tuning[10] = i11;
m_Tuning[11] = i12;
m_respectPitchTuning = false;
m_IsTemperamentOriginalBased = false;
}

GOTemperamentCent::GOTemperamentCent(
Expand Down Expand Up @@ -85,7 +85,7 @@ GOTemperamentCent::GOTemperamentCent(
m_Tuning[9] = i10;
m_Tuning[10] = i11;
m_Tuning[11] = i12;
m_respectPitchTuning = false;
m_IsTemperamentOriginalBased = false;
}

float GOTemperamentCent::GetOffset(unsigned index) const {
Expand Down
41 changes: 22 additions & 19 deletions src/grandorgue/model/GOSoundingPipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ GOSoundingPipe::GOSoundingPipe(
m_MaxVolume(max_volume),
m_SampleMidiKeyNumber(-1),
m_RetunePipe(retune),
m_CurrentTempRespectPT(true),
m_IsTemperamentOriginalBased(true),
m_PipeConfigNode(
&rank->GetPipeConfig(), organController, this, &m_SoundProvider) {}

Expand Down Expand Up @@ -477,25 +477,28 @@ void GOSoundingPipe::UpdateAmplitude() {
}

void GOSoundingPipe::UpdateTuning() {
float adjusted_pitch = 0;
double concert_pitch_correction = 0;
float pitchAdjustment = 0;

if (
!m_PipeConfigNode.GetEffectiveIgnorePitch()
&& m_SoundProvider.GetMidiKeyNumber()) {
concert_pitch_correction
= (100.0 * m_SoundProvider.GetMidiKeyNumber() - 100.0 * m_MidiKeyNumber
+ log(8.0 / m_HarmonicNumber) / log(2) * 1200)
+ m_SoundProvider.GetMidiPitchFract();
if (m_IsTemperamentOriginalBased) {
// For original temperament. Set pitchAdjustment from GetEffectiveTuning
pitchAdjustment = m_PipeConfigNode.GetEffectiveTuning();
} else {
// For any other temperament than original. Calculate pitchAdjustment by
// converting from the original temperament to the equal one before using
// temperament offset. Take PitchCorrection into account
double concert_pitch_correction = 0;

if (
!m_PipeConfigNode.GetEffectiveIgnorePitch()
&& m_SoundProvider.GetMidiKeyNumber()) {
concert_pitch_correction
= (100.0 * m_SoundProvider.GetMidiKeyNumber() - 100.0 * m_MidiKeyNumber
+ log(8.0 / m_HarmonicNumber) / log(2) * 1200)
+ m_SoundProvider.GetMidiPitchFract();
}
pitchAdjustment = m_PitchCorrection - concert_pitch_correction;
}
adjusted_pitch = m_TemperamentOffset - m_PipeConfigNode.GetDefaultTuning()
- concert_pitch_correction + m_PitchCorrection;

if (m_CurrentTempRespectPT) {
m_SoundProvider.SetTuning(
m_PipeConfigNode.GetEffectiveTuning() + adjusted_pitch);
} else
m_SoundProvider.SetTuning(adjusted_pitch);
m_SoundProvider.SetTuning(pitchAdjustment + m_TemperamentOffset);
}

void GOSoundingPipe::UpdateAudioGroup() {
Expand All @@ -504,7 +507,7 @@ void GOSoundingPipe::UpdateAudioGroup() {
}

void GOSoundingPipe::SetTemperament(const GOTemperament &temperament) {
m_CurrentTempRespectPT = temperament.GetRespectPitchTuning();
m_IsTemperamentOriginalBased = temperament.GetIsTemperamentOriginalBased();
if (!m_RetunePipe)
m_TemperamentOffset = 0;
else
Expand Down
2 changes: 1 addition & 1 deletion src/grandorgue/model/GOSoundingPipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class GOSoundingPipe : public GOPipe,
float m_MaxVolume;
int m_SampleMidiKeyNumber;
bool m_RetunePipe;
bool m_CurrentTempRespectPT;
bool m_IsTemperamentOriginalBased;
GOSoundProviderWave m_SoundProvider;
GOPipeConfigNode m_PipeConfigNode;

Expand Down

0 comments on commit 1185b9b

Please sign in to comment.