Skip to content

Commit

Permalink
Elevation Mode is now an automatable parameter (issue #190)
Browse files Browse the repository at this point in the history
  • Loading branch information
OKGougou committed Nov 1, 2022
1 parent 35de6c1 commit b185d25
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 15 deletions.
18 changes: 16 additions & 2 deletions Source/cg_ControlGrisAudioProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@ juce::AudioProcessorValueTreeState::ParameterLayout createParameterLayout()
juce::String("Elevation Span"),
juce::NormalisableRange<float>(0.0f, 1.0f),
0.0f,
Attributes()));
Attributes()),
std::make_unique<Parameter>(
juce::ParameterID{ Automation::Ids::ELEVATION_MODE, 1 },
juce::String("Elevation Mode"),
juce::NormalisableRange<float>(0.0f, static_cast<float>(ELEVATION_MODE_TYPES.size() - 1), 1.0f),
0.0f,
Attributes().withDiscrete(true).withAutomatable(true)));

return layout;
}
Expand Down Expand Up @@ -120,7 +126,6 @@ ControlGrisAudioProcessor::ControlGrisAudioProcessor()
mAudioProcessorValueTreeState.state.setProperty("firstSourceId", 1, nullptr);
mAudioProcessorValueTreeState.state.setProperty("oscOutputPluginId", 1, nullptr);

mAudioProcessorValueTreeState.state.setProperty("elevationMode", static_cast<int>(ElevationMode::normal), nullptr);

// Trajectory box persitent settings.
mAudioProcessorValueTreeState.state.setProperty("trajectoryType",
Expand Down Expand Up @@ -182,6 +187,7 @@ ControlGrisAudioProcessor::ControlGrisAudioProcessor()
mAudioProcessorValueTreeState.addParameterListener(Automation::Ids::POSITION_PRESET, this);
mAudioProcessorValueTreeState.addParameterListener(Automation::Ids::AZIMUTH_SPAN, this);
mAudioProcessorValueTreeState.addParameterListener(Automation::Ids::ELEVATION_SPAN, this);
mAudioProcessorValueTreeState.addParameterListener(Automation::Ids::ELEVATION_MODE, this);

// The timer's callback send OSC messages periodically.
//-----------------------------------------------------
Expand Down Expand Up @@ -237,6 +243,14 @@ void ControlGrisAudioProcessor::parameterChanged(juce::String const & parameterI
source.setElevationSpan(normalized);
}
}

if (parameterId.compare(Automation::Ids::ELEVATION_MODE) == 0) {
auto const val{ static_cast<ElevationMode>(newValue) };
auto * editor{ dynamic_cast<ControlGrisAudioProcessorEditor *>(getActiveEditor()) };
if (editor != nullptr) {
editor->updateElevationMode(val);
}
}
}

//==============================================================================
Expand Down
46 changes: 35 additions & 11 deletions Source/cg_ControlGrisAudioProcessorEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,22 @@ ControlGrisAudioProcessorEditor::ControlGrisAudioProcessorEditor(
addAndMakeVisible(&mElevationModeLabel);

mElevationModeCombobox.setLookAndFeel(&mGrisLookAndFeel);
mElevationModeCombobox.addItem("Normal", static_cast<int>(ElevationMode::normal));
mElevationModeCombobox.addItem("Extended Top", static_cast<int>(ElevationMode::extendedTop));
mElevationModeCombobox.addItem("Extended Top And Bottom", static_cast<int>(ElevationMode::extendedTopAndBottom));
mElevationModeCombobox.addItemList(ELEVATION_MODE_TYPES, 1);
mElevationModeCombobox.onChange = [this] {
mElevationField.setElevationMode(static_cast<ElevationMode>(mElevationModeCombobox.getSelectedId()));
mAudioProcessorValueTreeState.state.setProperty("elevationMode",
mElevationModeCombobox.getSelectedId(),
nullptr);
mElevationField.repaint();
elevationModeChangedStartedCallback();
auto const howMany{ static_cast<float>(ELEVATION_MODE_TYPES.size() - 1) };
auto const value{ (static_cast<float>(mElevationModeCombobox.getSelectedId()) - 1.0f) / howMany };
auto * parameter{ mAudioProcessorValueTreeState.getParameter(Automation::Ids::ELEVATION_MODE) };
auto const gestureLock{ mProcessor.getChangeGestureManager().getScopedLock(
Automation::Ids::ELEVATION_MODE) };
parameter->setValueNotifyingHost(value);
elevationModeChangedEndedCallback();
};
auto const elevModeValue{ mAudioProcessorValueTreeState.getParameterAsValue(Automation::Ids::ELEVATION_MODE) };
auto const elevMode{ static_cast<ElevationMode>(static_cast<int>(elevModeValue.getValue())) };
updateElevationMode(elevMode);
addAndMakeVisible(&mElevationModeCombobox);

auto const width{ getWidth() - 50 }; // Remove position preset space.
auto const fieldSize{ std::max(width / 2, MIN_FIELD_WIDTH) };
// only setting positions in resized() is not sufficient
Expand Down Expand Up @@ -225,8 +230,6 @@ void ControlGrisAudioProcessorEditor::reloadUiState()
Degrees{ mAudioProcessorValueTreeState.state.getProperty("deviationPerCycle", 0) });
mSectionTrajectory.setCycleDuration(mAudioProcessorValueTreeState.state.getProperty("cycleDuration", 5.0));
mSectionTrajectory.setDurationUnit(mAudioProcessorValueTreeState.state.getProperty("durationUnit", 1));
mElevationModeCombobox.setSelectedId(
mAudioProcessorValueTreeState.state.getProperty("elevationMode", static_cast<int>(ElevationMode::normal)));

// Update the position preset box.
//--------------------------------
Expand Down Expand Up @@ -289,6 +292,27 @@ void ControlGrisAudioProcessorEditor::updatePositionPreset(int const presetNumbe
mPositionPresetComponent.setPreset(presetNumber, true);
}

//==============================================================================
void ControlGrisAudioProcessorEditor::updateElevationMode(ElevationMode mode)
{
juce::MessageManager::callAsync([=] {
mElevationModeCombobox.setSelectedId(static_cast<int>(mode) + 1, juce::dontSendNotification);
mElevationField.setElevationMode(mode);
});
}

//==============================================================================
void ControlGrisAudioProcessorEditor::elevationModeChangedStartedCallback()
{
mProcessor.getChangeGestureManager().beginGesture(Automation::Ids::ELEVATION_MODE);
}

//==============================================================================
void ControlGrisAudioProcessorEditor::elevationModeChangedEndedCallback()
{
mProcessor.getChangeGestureManager().endGesture(Automation::Ids::ELEVATION_MODE);
}

//==============================================================================
// Value::Listener callback. Called when the stored window size changes.
void ControlGrisAudioProcessorEditor::valueChanged(juce::Value &)
Expand Down Expand Up @@ -837,7 +861,7 @@ void ControlGrisAudioProcessorEditor::setSpatMode(SpatMode spatMode)
//==============================================================================
ElevationMode ControlGrisAudioProcessorEditor::getElevationMode() const
{
return static_cast<ElevationMode>(mElevationModeCombobox.getSelectedId());
return static_cast<ElevationMode>(mElevationModeCombobox.getSelectedId() - 1);
}

} // namespace gris
4 changes: 4 additions & 0 deletions Source/cg_ControlGrisAudioProcessorEditor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ class ControlGrisAudioProcessorEditor final
void updateSourceLinkCombo(PositionSourceLink value);
void updateElevationSourceLinkCombo(ElevationSourceLink value);
void updatePositionPreset(int presetNumber);
void updateElevationMode(ElevationMode mode);

void elevationModeChangedStartedCallback();
void elevationModeChangedEndedCallback();

void refresh();

Expand Down
1 change: 1 addition & 0 deletions Source/cg_FieldComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,7 @@ Radians ElevationFieldComponent::componentPositionToSourceElevation(juce::Point<
void ElevationFieldComponent::setElevationMode(ElevationMode const & elevationMode)
{
mElevationMode = elevationMode;
repaint();
}

//==============================================================================
Expand Down
8 changes: 8 additions & 0 deletions Source/cg_constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ juce::String const Automation::Ids::ELEVATION_SOURCE_LINK{ "sourceLinkAlt" };
juce::String const Automation::Ids::AZIMUTH_SPAN{ "azimuthSpan" };
juce::String const Automation::Ids::ELEVATION_SPAN{ "elevationSpan" };
juce::String const Automation::Ids::POSITION_PRESET{ "positionPreset" };
juce::String const Automation::Ids::ELEVATION_MODE{ "elevationMode" };

Automation::Enum Automation::idToEnum(const juce::String & name)
{
Expand Down Expand Up @@ -57,6 +58,9 @@ Automation::Enum Automation::idToEnum(const juce::String & name)
if (name.compare(Ids::POSITION_PRESET) == 0) {
return Enum::positionPreset;
}
if (name.compare(Ids::ELEVATION_MODE) == 0) {
return Enum::elevationMode;
}

jassertfalse;
return {};
Expand Down Expand Up @@ -104,6 +108,10 @@ juce::StringArray const ELEVATION_TRAJECTORY_TYPE_TYPES{ juce::String("Realtime"
juce::String("Up Down"),
juce::String("Down Up") };

juce::StringArray const ELEVATION_MODE_TYPES{ juce::String("Normal"),
juce::String("Extended Top"),
juce::String("Extended Top and Bottom") };

juce::StringArray const FIXED_POSITION_DATA_HEADERS{
// TODO: is this useful?
juce::String("ID"), juce::String("S1_X"), juce::String("S1_Y"), juce::String("S1_Z"), juce::String("S2_X"),
Expand Down
16 changes: 14 additions & 2 deletions Source/cg_constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ enum class SpatMode { dome, cube };

//==============================================================================
// Elevation modes.
enum class ElevationMode { normal = 1, extendedTop, extendedTopAndBottom };
enum class ElevationMode { normal, extendedTop, extendedTopAndBottom };
extern juce::StringArray const ELEVATION_MODE_TYPES;

extern juce::String const SOURCE_SELECTION_WARNING;

Expand Down Expand Up @@ -124,9 +125,20 @@ juce::String extern const ELEVATION_SOURCE_LINK;
juce::String extern const AZIMUTH_SPAN;
juce::String extern const ELEVATION_SPAN;
juce::String extern const POSITION_PRESET;
juce::String extern const ELEVATION_MODE;
} // namespace Ids

enum class Enum { x, y, z, positionSourceLink, elevationSourceLink, azimuthSpan, elevationSpan, positionPreset };
enum class Enum {
x,
y,
z,
positionSourceLink,
elevationSourceLink,
azimuthSpan,
elevationSpan,
positionPreset,
elevationMode
};

Enum idToEnum(juce::String const & name);

Expand Down

0 comments on commit b185d25

Please sign in to comment.