Skip to content

Commit

Permalink
add update button (#26)
Browse files Browse the repository at this point in the history
* add update button

* remove sendGET
  • Loading branch information
dan-german authored Apr 12, 2024
1 parent b3941a9 commit 1dcc22c
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 32 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ cmake_minimum_required(VERSION 3.15)
# `project()` command. `project()` sets up some helpful variables that describe source/binary
# directories, and the current project version. This is a standard CMake command.

project(blocks VERSION 0.1.2)
project(blocks VERSION 0.1.3)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX20_STANDARD_COMPILE_OPTION "-std:c++latest")
# If you've installed JUCE somehow (via a package manager, or directly using the CMake install
Expand Down
9 changes: 9 additions & 0 deletions Source/MainComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "settings/UserSettings.h"
#include "module_new.h"
#include "vital/common/synth_constants.h"
#include "version_config.h"

MainComponent::MainComponent(juce::MidiKeyboardState& keyboard_state, Delegate* delegate):
delegate(delegate),
Expand Down Expand Up @@ -53,6 +54,14 @@ MainComponent::MainComponent(juce::MidiKeyboardState& keyboard_state, Delegate*
// ui_layer_.setConnections(delegate->getModulations());
// auto osc_block2 = addBlock(0, { 0, 0 });
// spawnBlockComponent(osc_block2);

auto req = [this] {
auto options = juce::URL::InputStreamOptions(juce::URL::ParameterHandling::inAddress);
auto version = juce::URL("https://blocksbucket.s3.us-east-2.amazonaws.com/version").createInputStream(options)->readEntireStreamAsString().toStdString();
juce::MessageManager::callAsync([this, version] { ui_layer_.update_button_.setVisible(version != BLOCKS_VERSION);});
};

juce::Thread::launch(req);
}

void MainComponent::updateDotPosition(const Point<int> position) {
Expand Down
1 change: 1 addition & 0 deletions Source/MainComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "vital/synthesis/framework/synth_module.h"
#include "gui/column_controls_container.h"
#include "selection_rect.h"
#include "gui/controls/SavePopup.h"

using Modulation = Model::Modulation;
using Block = Model::Block;
Expand Down
7 changes: 7 additions & 0 deletions Source/gui/UILayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ UILayer::UILayer(juce::MidiKeyboardState& keyboard_state, Slider::Listener* list
connections_list_box_model_.slider_listener_ = listener;
setInterceptsMouseClicks(false, true);
setOpaque(false);
update_button_.text.setText("update", dontSendNotification);
addChildComponent(update_button_);
update_button_.on_click_ = [this]() { juce::URL("https://www.soonth.com").launchInDefaultBrowser(); };
}

void UILayer::addSVGButton(std::unique_ptr<SVGButton>& button, const char* rawData, size_t size) {
Expand Down Expand Up @@ -104,6 +107,10 @@ void UILayer::resizeSaveAndNewButtons() {
int newPresetX = preset_button_.getX() - verticalSpacing - buttonSize / 2;
newPresetButton->setBounds(0, 0, buttonSize, buttonSize);
newPresetButton->setCentrePosition(newPresetX, preset_button_.getBounds().getCentreY());

int update_button_width = 50;
update_button_.setBounds(0, 0, update_button_width, 23);
update_button_.setCentrePosition(saveButton->getRight() + verticalSpacing + update_button_width / 2, preset_button_.getBounds().getCentreY());
}

void UILayer::resizeSettingsButton() {
Expand Down
2 changes: 1 addition & 1 deletion Source/gui/UILayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "gui/controls/ButtonGridPopup.h"
#include <juce_gui_basics/juce_gui_basics.h>
#include "gui/controls/SVGButton.h"
#include "gui/controls/SavePopup.h"
#include "connection.h"

using Modulation = Model::Modulation;
Expand All @@ -43,6 +42,7 @@ class UILayer: public juce::Component, ComponentMovementWatcher {
std::unique_ptr<SVGButton> theme_button_;

std::unique_ptr<ModulatorsButton> modulatorsButton;
LabelButton update_button_;

ModulationsListBoxModel connections_list_box_model_;

Expand Down
3 changes: 1 addition & 2 deletions Source/gui/base/BaseButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ class BaseButton: public Component {
std::function<void()> on_click_;

Colour colour;

BaseButton();

virtual void setButtonColour(Colour colour) = 0;
protected:
void mouseEnter(const juce::MouseEvent& event) override;
void mouseExit(const juce::MouseEvent& event) override;
void mouseUp(const juce::MouseEvent& event) override;
virtual void setButtonColour(Colour colour) = 0;

void paint(juce::Graphics&) override;
void resized() override;
Expand Down
10 changes: 0 additions & 10 deletions Source/gui/base/BasePopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,54 +21,44 @@ void BasePopup::setVisible(bool shouldBeVisible) {

void BasePopup::triggerDismissAnimation() {
auto bounds = getBounds();

auto animation = [this, bounds](float value, float progress) {
setBounds(getX(), getY(), bounds.getWidth() * value, bounds.getHeight() * value);

float invertedProgress = 1.0f - progress;
setAlpha(invertedProgress);
};

auto completion = [this]() { juce::Component::setVisible(false); };

EasingAnimator::AnimateInput input = {
.seconds = 0.06f,
.completion = completion,
.animation = animation,
.range = { 1.00f, 0.95f },
.points = { 0.50f, 0.75f, 0.30f, 1.20f },
};

animator.animate(input);
}

void BasePopup::present() {
auto p = getPosition();
setBounds(getX(), getY(), getWidth(), getHeight());
toFront(false);

auto bounds = getBounds();
setAlpha(0.0f);
setVisible(true);

auto animation = [this, bounds](float value, float progress) {
setBounds(getX(), getY(), bounds.getWidth() * value, bounds.getHeight() * value);
setAlpha(progress);
};

auto completion = [this, p, bounds]() {
setBounds(p.getX(), p.getY(), bounds.getWidth(), bounds.getHeight());
setAlpha(1.0f);
this->setInterceptsMouseClicks(true, true);
};

EasingAnimator::AnimateInput input = {
.seconds = 0.06f,
.completion = completion,
.animation = animation,
.range = { 0.95f, 1.00f },
.points = { 0.50f, 0.75f, 0.30f, 1.20f }
};

animator.animate(input);
}
8 changes: 2 additions & 6 deletions Source/gui/controls/LabelButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@ LabelButton::~LabelButton() {
LabelButton::LabelButton() {
hoverBrightness = 8.0f;
orbit = false;

addAndMakeVisible(content);

text.setJustificationType(Justification::centred);
text.setFont(Font(fontSize));
text.setInterceptsMouseClicks(false, false);
text.setColour(Label::ColourIds::textColourId, colour);

content.addAndMakeVisible(text);

content.setInterceptsMouseClicks(false, false);
ThemeManager::shared()->addListener(this);
themeChanged(ThemeManager::shared()->getCurrent());
}
Expand Down Expand Up @@ -53,8 +49,8 @@ void LabelButton::selectedCompletion() {
}

void LabelButton::resized() {
BaseButton::resized();
text.setBounds(getLocalBounds());
content.setBounds(getLocalBounds().reduced(1));
}

void LabelButton::themeChanged(Theme theme) {
Expand Down
3 changes: 1 addition & 2 deletions Source/gui/controls/LabelButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ class LabelButton: public BaseButton, public ThemeListener {
LabelButton();
~LabelButton() override;

DrawablePath content;
Component content;

Label text;
Path p;
float fontSize = 15.0f;
float selectedFontSize = 16.5f;

Expand Down
8 changes: 2 additions & 6 deletions Source/gui/controls/SavePopup.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ class SavePopup: public BasePopup {
LabelButton saveButton;
TextEditor textEditor;

~SavePopup() override { }

SavePopup() {
cornerRadius = 13.0f;

addAndMakeVisible(saveButton);
addAndMakeVisible(textEditor);

saveButton.text.setText("save", dontSendNotification);
}

Expand All @@ -25,19 +25,15 @@ class SavePopup: public BasePopup {
}
}

~SavePopup() override { }

void resized() override {
auto inset = 8.0f;
auto buttonWidth = 37.0f;

textEditor.setBounds(
inset,
inset,
getWidth() - buttonWidth - inset * 3,
getHeight() - inset * 2
);

saveButton.setBounds(
textEditor.getRight(),
textEditor.getY() - 2,
Expand Down
6 changes: 3 additions & 3 deletions Source/util/Analytics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Analytics* Analytics::shared() {
return instance;
}

void Analytics::sendHTTPRequest(const juce::String& urlString, const json& bodyData) {
void Analytics::sendPOST(const juce::String& urlString, const json& bodyData) {
auto options = juce::URL::InputStreamOptions(juce::URL::ParameterHandling::inAddress).withExtraHeaders("Content-Type: application/json");
juce::URL(urlString).withPOSTData(bodyData.dump()).createInputStream(options);
}
Expand Down Expand Up @@ -97,7 +97,7 @@ void Analytics::initProfileIfNeeded() {
json array;
array.push_back(body);

sendHTTPRequest("https://api.mixpanel.com/engage#profile-set-once", array);
sendPOST("https://api.mixpanel.com/engage#profile-set-once", array);
UserSettings::shared()->set("ProfileInitialized", juce::String("true"));
};

Expand All @@ -121,7 +121,7 @@ void Analytics::sendEvent(const String& eventName, std::optional<std::string> cu
json array;
array.push_back(event);

sendHTTPRequest("https://api.mixpanel.com/track", array);
sendPOST("https://api.mixpanel.com/track", array);
};

juce::Thread::launch(req);
Expand Down
2 changes: 1 addition & 1 deletion Source/util/Analytics.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ class Analytics {
void handleQuit();
void handleLaunch(String wrapperType);
void initProfileIfNeeded();
void sendHTTPRequest(const juce::String& urlString, const json& bodyData);
void sendPOST(const juce::String& urlString, const json& bodyData);
};

0 comments on commit 1dcc22c

Please sign in to comment.