Skip to content

Commit

Permalink
Add tempo range combo box
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiashienzsch committed Jun 11, 2022
1 parent 5901f7f commit a6e2a81
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/UI/Section/SideBarRight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@ SideBarRight::SideBarRight()
addAndMakeVisible(_placeholder);
addAndMakeVisible(_vinylButton);
addAndMakeVisible(_warpButton);
addAndMakeVisible(_tempoRange);
addAndMakeVisible(_tempo);

_tempo.setRange({-6.0, 6.0}, 0.01);
_tempoRange.setEditableText(false);
_tempoRange.setJustificationType(juce::Justification::centred);
_tempoRange.addItemList({"6%", "10%", "20%", "100%"}, 1);
_tempoRange.setSelectedId(1);
_tempoRange.onChange = [this]() { updateSpeedRange(); };
updateSpeedRange();

_tempo.setValue(0.0, juce::dontSendNotification);
_tempo.onValueChange = [this]()
{
Expand All @@ -31,13 +38,34 @@ auto SideBarRight::resized() -> void
grid.templateRows = fillArray(Track(1_fr), 12);
grid.templateColumns = fillArray(Track(1_fr), 1);
grid.items.addArray({
GridItem(_placeholder).withArea(GridItem::Span(6), {}),
GridItem(_placeholder).withArea(GridItem::Span(5), {}),
GridItem(_vinylButton).withArea(GridItem::Span(1), {}),
GridItem(_warpButton).withArea(GridItem::Span(1), {}),
GridItem(_tempoRange).withArea(GridItem::Span(1), {}),
GridItem(_tempo).withArea(GridItem::Span(4), {}),
});

grid.performLayout(getLocalBounds());
}

auto SideBarRight::updateSpeedRange() -> void
{
auto rangeID = _tempoRange.getSelectedId();
switch (rangeID)
{
case 1: _tempo.setRange({-6.0, 6.0}, 0.01); break;
case 2: _tempo.setRange({-10.0, 10.0}, 0.01); break;
case 3: _tempo.setRange({-20.0, 20.0}, 0.01); break;
case 4: _tempo.setRange({-100.0, 100.0}, 0.01); break;
default: jassertfalse;
}

auto const val = _tempo.getValue();
auto const range = _tempo.getRange();
auto const clipped = range.clipValue(val);

if (onTempoDeltaChanged) { onTempoDeltaChanged(clipped); }
_tempo.setValue(clipped, juce::sendNotification);
}

} // namespace ta
3 changes: 3 additions & 0 deletions src/UI/Section/SideBarRight.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ struct SideBarRight final : juce::Component
std::function<void(double)> onTempoDeltaChanged{};

private:
auto updateSpeedRange() -> void;

Placeholder _placeholder{"", juce::Colours::transparentBlack};
juce::TextButton _vinylButton{"Vinyl"};
juce::TextButton _warpButton{"Warp"};
juce::ComboBox _tempoRange;
juce::Slider _tempo{juce::Slider::LinearVertical, juce::Slider::TextBoxBelow};

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SideBarRight)
Expand Down

0 comments on commit a6e2a81

Please sign in to comment.