Skip to content

Commit d4a5a28

Browse files
committed
Restyle the tuning panel.
1 parent 3eb0ef2 commit d4a5a28

File tree

13 files changed

+149
-14
lines changed

13 files changed

+149
-14
lines changed

Aeolus.jucer

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@
109109
file="Source/PluginProcessor.h"/>
110110
</GROUP>
111111
<GROUP id="{9E90580A-EE5A-EE88-9338-83E8FEECB687}" name="Resources">
112+
<GROUP id="{818AC889-AD97-87EC-B3B9-6F634DCD9936}" name="images">
113+
<FILE id="wvRCwD" name="tuning-fork-hover.svg" compile="0" resource="1"
114+
file="Resources/images/tuning-fork-hover.svg"/>
115+
<FILE id="MIIEWv" name="tuning-fork.svg" compile="0" resource="1" file="Resources/images/tuning-fork.svg"/>
116+
</GROUP>
112117
<GROUP id="{D8B82854-C2FA-AA1F-D5C8-36DAC5781517}" name="icons">
113118
<FILE id="LO441C" name="icon64.png" compile="0" resource="1" file="Resources/icons/icon64.png"/>
114119
<FILE id="WQXHsa" name="icon256.png" compile="0" resource="1" file="Resources/icons/icon256.png"/>
Lines changed: 20 additions & 0 deletions
Loading

Resources/images/tuning-fork.svg

Lines changed: 8 additions & 0 deletions
Loading

Source/PluginEditor.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ AeolusAudioProcessorEditor::AeolusAudioProcessorEditor (AeolusAudioProcessor& p)
4848
, _volumeSlider{*p.getParametersContainer().volume, juce::Slider::LinearHorizontal}
4949
, _volumeLevelL{p.getEngine().getVolumeLevel().left, ui::LevelIndicator::Orientation::Horizontal}
5050
, _volumeLevelR{p.getEngine().getVolumeLevel().right, ui::LevelIndicator::Orientation::Horizontal}
51-
, _tuningButton{"Tune"}
51+
, _tuningButton{"tuningButton", DrawableButton::ImageFitted}
5252
, _panicButton{"PANIC"}
5353
, _cancelButton{"Cancel"}
5454
, _midiControlChannelLabel{{}, {"Control channel"}}
@@ -109,6 +109,19 @@ AeolusAudioProcessorEditor::AeolusAudioProcessorEditor (AeolusAudioProcessor& p)
109109
_volumeSlider.setLookAndFeel(&ui::CustomLookAndFeel::getInstance());
110110

111111
addAndMakeVisible(_tuningButton);
112+
113+
auto loadSVG = [](const char* data, size_t size) -> std::unique_ptr<Drawable> {
114+
if (auto xml = parseXML(String::fromUTF8(data, (int)size))) {
115+
return Drawable::createFromSVG(*xml);
116+
}
117+
return nullptr;
118+
};
119+
120+
auto normalIcon = loadSVG(BinaryData::tuningfork_svg, BinaryData::tuningfork_svgSize);
121+
auto hoverIcon = loadSVG(BinaryData::tuningforkhover_svg, BinaryData::tuningforkhover_svgSize);
122+
_tuningButton.setImages(normalIcon.get(), hoverIcon.get());
123+
_tuningButton.setMouseCursor(MouseCursor::PointingHandCursor);
124+
112125
_tuningButton.onClick = [this] {
113126
auto content = std::make_unique<ui::GlobalTuningComponent>();
114127
content->setSize(240, 140);
@@ -127,6 +140,7 @@ AeolusAudioProcessorEditor::AeolusAudioProcessorEditor (AeolusAudioProcessor& p)
127140
g->setTuningFrequency(freq);
128141
g->setScaleType(scaleType);
129142
g->rebuildRankwaves();
143+
g->saveSettings();
130144
}
131145

132146
box.dismiss();
@@ -229,7 +243,7 @@ void AeolusAudioProcessorEditor::resized()
229243
_volumeLevelL.setBounds(_volumeSlider.getX() + 5, _volumeSlider.getY() + 2, _volumeSlider.getWidth() - 10, 2);
230244
_volumeLevelR.setBounds(_volumeSlider.getX() + 5, _volumeSlider.getY() + _volumeSlider.getHeight() - 4, _volumeSlider.getWidth() - 10, 2);
231245

232-
_tuningButton.setBounds(_volumeSlider.getRight() + 40, margin, 60, 20);
246+
_tuningButton.setBounds(_volumeSlider.getRight() + 40, margin - 2, 60, 24);
233247

234248
_panicButton.setBounds(getWidth() - 90, margin, 50, 20);
235249

Source/PluginEditor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class AeolusAudioProcessorEditor : public juce::AudioProcessorEditor,
8989
ui::LevelIndicator _volumeLevelL;
9090
ui::LevelIndicator _volumeLevelR;
9191

92-
juce::TextButton _tuningButton;
92+
juce::DrawableButton _tuningButton;
9393

9494
/// Kill all active voices button
9595
juce::TextButton _panicButton;

Source/aeolus/division.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,16 @@ void Division::noteOn(int note, int midiChannel)
335335
if (zone.isForKey(note)) {
336336
for (auto* rw : zone.rankwaves) {
337337
auto state = rw->trigger(note);
338-
state.gain = stop.getGain();
339-
state.chiffGain = stop.getChiffGain();
340338

341-
if (auto* voice = _engine.getVoicePool().trigger(state))
342-
_activeVoices.append(voice);
339+
// Rankwave may be in the middle of construction, in this case
340+
// we don't trigger a voice.
341+
if (state.isTriggered()) {
342+
state.gain = stop.getGain();
343+
state.chiffGain = stop.getChiffGain();
344+
345+
if (auto* voice = _engine.getVoicePool().trigger(state))
346+
_activeVoices.append(voice);
347+
}
343348
}
344349
}
345350
}

Source/aeolus/engine.cpp

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,38 @@ class PrepareRankwaveJob : ThreadPoolJob
5151

5252
//==============================================================================
5353

54+
namespace settings {
55+
const static char* tuningFrequency = "tuningFrequency";
56+
const static char* tuningTemperament = "tuningTemperament";
57+
}
58+
5459
EngineGlobal::EngineGlobal()
5560
: _rankwaves{}
5661
, _scale(Scale::EqualTemp)
57-
, _tuningFrequency(440.0f)
62+
, _tuningFrequency(TUNING_FREQUENCY_DEFAULT)
63+
, _globalProperties{}
5864
{
65+
PropertiesFile::Options options{};
66+
67+
options.applicationName = ProjectInfo::projectName;
68+
options.filenameSuffix = ".settings";
69+
options.osxLibrarySubFolder = "~/Library/Application Support";
70+
options.storageFormat = PropertiesFile::storeAsXML;
71+
72+
_globalProperties.setStorageParameters(options);
73+
74+
loadSettings();
75+
5976
loadRankwaves();
6077
loadIRs();
6178
}
6279

80+
EngineGlobal::~EngineGlobal()
81+
{
82+
saveSettings();
83+
clearSingletonInstance();
84+
}
85+
6386
void EngineGlobal::registerProcessorProxy(ProcessorProxy* proxy)
6487
{
6588
jassert(proxy != nullptr);
@@ -72,6 +95,26 @@ void EngineGlobal::unregisterProcessorProxy(ProcessorProxy* proxy)
7295
_processors.removeAllInstancesOf(proxy);
7396
}
7497

98+
void EngineGlobal::loadSettings()
99+
{
100+
if (auto* propertiesFile = _globalProperties.getUserSettings()) {
101+
_tuningFrequency = (float) propertiesFile->getDoubleValue(settings::tuningFrequency, TUNING_FREQUENCY_DEFAULT);
102+
int scaleType = propertiesFile->getIntValue(settings::tuningTemperament, (int)Scale::EqualTemp);
103+
if (scaleType >= (int)Scale::First && scaleType < (int)Scale::Total) {
104+
_scale.setType(static_cast<Scale::Type>(scaleType));
105+
}
106+
}
107+
}
108+
109+
void EngineGlobal::saveSettings()
110+
{
111+
if (auto* propertiesFile = _globalProperties.getUserSettings()) {
112+
propertiesFile->setValue(settings::tuningFrequency, _tuningFrequency);
113+
propertiesFile->setValue(settings::tuningTemperament, (int)_scale.getType());
114+
}
115+
116+
_globalProperties.saveIfNeeded();
117+
}
75118

76119
StringArray EngineGlobal::getAllStopNames() const
77120
{
@@ -132,12 +175,13 @@ void EngineGlobal::rebuildRankwaves()
132175
numActiveVoices += processor->getNumberOfActiveVoices();
133176
}
134177

135-
Thread::sleep(10);
178+
Thread::sleep(100);
136179

137-
// Wait for the voices to stop
180+
// Wait for the voices to release
138181
while (numActiveVoices > 0) {
139182
numActiveVoices = 0;
140183
for (auto* processor : _processors) {
184+
processor->killAllVoices();
141185
numActiveVoices += processor->getNumberOfActiveVoices();
142186
Thread::sleep(100);
143187
}

Source/aeolus/engine.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ class EngineGlobal : public juce::DeletedAtShutdown
7474
juce::AudioBuffer<float> waveform;
7575
};
7676

77+
void loadSettings();
78+
void saveSettings();
79+
7780
int getStopsCount() const noexcept { return _rankwaves.size(); }
7881
Rankwave* getStop(int i) { return _rankwaves[i]; }
7982

@@ -97,7 +100,7 @@ class EngineGlobal : public juce::DeletedAtShutdown
97100

98101
private:
99102
EngineGlobal();
100-
~EngineGlobal() override { clearSingletonInstance(); }
103+
~EngineGlobal() override;
101104

102105
void loadRankwaves();
103106
void loadIRs();
@@ -113,6 +116,8 @@ class EngineGlobal : public juce::DeletedAtShutdown
113116
float _sampleRate;
114117
Scale _scale;
115118
float _tuningFrequency;
119+
120+
juce::ApplicationProperties _globalProperties;
116121
};
117122

118123
//==============================================================================

Source/aeolus/rankwave.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,12 @@ Pipewave::State Rankwave::trigger(int note)
447447
if (note < _noteMin || note > _noteMax)
448448
return {};
449449

450-
int index = note - _noteMin;
451-
jassert(index >= 0 && index < (int)_pipes.size());
450+
const int index = note - _noteMin;
451+
452+
if (!isPositiveAndBelow(index, _pipes.size())) {
453+
jassertfalse;
454+
return {};
455+
}
452456

453457
Pipewave* pipe = _pipes[note - _noteMin];
454458
return pipe->trigger();

Source/aeolus/rankwave.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class Pipewave
6464
float chiffGain = 0.0f;
6565

6666
void release() { if (pipewave != nullptr) pipewave->release(*this); }
67+
bool isTriggered() const noexcept { return pipewave != nullptr && env == Attack; }
6768
bool isIdle() const noexcept { return env == Idle; }
6869
bool isOver() const noexcept { return env == Over; }
6970
void reset() { pipewave = nullptr; env = Idle;}

0 commit comments

Comments
 (0)