Skip to content

Commit

Permalink
actually resize (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreya-Autumn authored Jan 21, 2025
1 parent 99c25a4 commit 7a5afa3
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 120 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
137 changes: 137 additions & 0 deletions src/EveryComponent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
Lattices - A Just-Intonation graphical MTS-ESP Source
Copyright 2023-2024 Andreya Ek Frisk and Paul Walker.
This code is released under the MIT licence, but do note that it depends
on the JUCE library, see licence for more details.
Source available at https://github.com/Andreya-Autumn/lattices
*/

#pragma once

#include <memory>

#include "LatticesProcessor.h"

#include "Components/LatticeComponent.h"
#include "Components/MenuBarComponent.h"
#include "Components/MTSWarningComponent.h"

//==============================================================================
struct EveryComponent : public juce::Component, juce::MultiTimer
{
EveryComponent(LatticesProcessor &p, int w, int h) : processor(p), width(w), height(h)
{
latticeComponent = std::make_unique<LatticeComponent>(p);
addAndMakeVisible(*latticeComponent);
latticeComponent->setBufferedToImage(true);

warningComponent = std::make_unique<MTSWarningComponent>(p);
addAndMakeVisible(*warningComponent);

if (p.registeredMTS)
{
init();
}
else
{
latticeComponent->setEnabled(false);
startTimer(1, 50);
}
}

void resized() override
{
auto b = this->getLocalBounds();
latticeComponent->setBounds(b);

if (inited)
{
auto h = 30;
if (menuComponent->visC->isVisible())
{
h = 330;
}
else if (menuComponent->settingsC->isVisible())
{
h = 240;
}

menuComponent->setBounds(0, 0, b.getWidth(), h);
}
else
{
warningComponent->setBounds((width / 2) - 100, (height / 2) - 100, 200, 200);
}
}

float backgroundWidth() { return this->getLocalBounds().getWidth(); }

private:
LatticesProcessor &processor;
// juce::ComponentBoundsConstrainer constraints;

int width{0}, height{0};

std::unique_ptr<LatticeComponent> latticeComponent;
std::unique_ptr<MTSWarningComponent> warningComponent;
std::unique_ptr<MenuBarComponent> menuComponent;

bool inited{false};
void init()
{
menuComponent = std::make_unique<MenuBarComponent>(processor);
addAndMakeVisible(*menuComponent);
menuComponent->setBounds(this->getLocalBounds());

inited = true;
startTimer(0, 5);
resized();
}

bool menuWasOpen{false};
void timerCallback(int timerID) override
{
if (timerID == 1)
{
if (processor.registeredMTS)
{
warningComponent->setVisible(false);
warningComponent->setEnabled(false);
stopTimer(1);
latticeComponent->setEnabled(true);
init();
}
}

if (timerID == 0)
{
if (processor.loadedState)
{
menuComponent->resetAll();
processor.loadedState = false;
}

bool edvi = menuComponent->visC->isVisible();
menuComponent->visC->setEnabled(edvi);

bool mevi = (edvi || menuComponent->settingsC->isVisible());

if (mevi != menuWasOpen)
{
resized();
menuWasOpen = mevi;
}

if (processor.editingVisitors != edvi)
{
int g = menuComponent->visC->selectedGroup;
processor.editVisitors(edvi, g);
latticeComponent->repaint();
}
latticeComponent->setEnabled(!menuComponent->visC->isVisible());
}
}
};
97 changes: 8 additions & 89 deletions src/LatticesEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,110 +15,29 @@
//==============================================================================
LatticesEditor::LatticesEditor(LatticesProcessor &p) : juce::AudioProcessorEditor(&p), processor(p)
{
latticeComponent = std::make_unique<LatticeComponent>(p);
addAndMakeVisible(*latticeComponent);
latticeComponent->setBufferedToImage(true);

warningComponent = std::make_unique<MTSWarningComponent>(p);
addAndMakeVisible(*warningComponent);

if (p.registeredMTS)
{
init();
}
else
{
latticeComponent->setEnabled(false);
startTimer(1, 50);
}
everyComponent = std::make_unique<EveryComponent>(p, width, height);
everyComponent->setBufferedToImage(true);
everyComponent->setBounds(0, 0, width, height);
addAndMakeVisible(*everyComponent);

setSize(width, height);
getConstrainer()->setFixedAspectRatio(height / width);

setResizable(true, true);
}

LatticesEditor::~LatticesEditor() {}

//==============================================================================

void LatticesEditor::init()
{
menuComponent = std::make_unique<MenuBarComponent>(processor);
addAndMakeVisible(*menuComponent);
menuComponent->setBounds(this->getLocalBounds());

inited = true;
startTimer(0, 5);
resized();
}

void LatticesEditor::paint(juce::Graphics &g) { g.fillAll(backgroundColour); }

void LatticesEditor::idle() {}

void LatticesEditor::resized()
{
auto b = this->getLocalBounds();
latticeComponent->setBounds(b);

if (inited)
{
auto h = 30;
if (menuComponent->visC->isVisible())
{
h = 330;
}
else if (menuComponent->settingsC->isVisible())
{
h = 240;
}

menuComponent->setBounds(0, 0, b.getWidth(), h);
}
else
{
warningComponent->setBounds((width / 2) - 100, (height / 2) - 100, 200, 200);
}
}

void LatticesEditor::timerCallback(int timerID)
{
if (timerID == 1)
{
if (processor.registeredMTS)
{
warningComponent->setVisible(false);
warningComponent->setEnabled(false);
stopTimer(1);
latticeComponent->setEnabled(true);
init();
}
}

if (timerID == 0)
{
if (processor.loadedState)
{
menuComponent->resetAll();
processor.loadedState = false;
}

bool edvi = menuComponent->visC->isVisible();
menuComponent->visC->setEnabled(edvi);

bool mevi = (edvi || menuComponent->settingsC->isVisible());

if (mevi != menuWasOpen)
{
resized();
menuWasOpen = mevi;
}

if (processor.editingVisitors != edvi)
{
int g = menuComponent->visC->selectedGroup;
processor.editVisitors(edvi, g);
latticeComponent->repaint();
}
latticeComponent->setEnabled(!menuComponent->visC->isVisible());
}
float scale = b.getWidth() / everyComponent->backgroundWidth();
everyComponent->setTransform(juce::AffineTransform().scaled(scale));
}
35 changes: 4 additions & 31 deletions src/LatticesEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,14 @@
#include <memory>

#include <juce_audio_processors/juce_audio_processors.h>
// #include "melatonin_inspector/melatonin_inspector.h"
#include "LatticesProcessor.h"
#include "JIMath.h"
#include "LatticeComponent.h"

#include "MenuComponents/MenuBarComponent.h"

#include "MTSWarningComponent.h"
#include "LatticesProcessor.h"
#include "EveryComponent.h"

//==============================================================================
/**
*/
class LatticesEditor : public juce::AudioProcessorEditor, juce::MultiTimer
class LatticesEditor : public juce::AudioProcessorEditor
{
public:
LatticesEditor(LatticesProcessor &);
Expand All @@ -36,40 +31,18 @@ class LatticesEditor : public juce::AudioProcessorEditor, juce::MultiTimer

void paint(juce::Graphics &) override;
void resized() override;

void showVisitorsMenu();
void showTuningMenu();
void showMidiMenu();
void resetMTS();

void timerCallback(int timerID) override;

// std::unique_ptr<juce::Timer> idleTimer;
void idle();
void assignVisitors();

private:
static constexpr int width{1100};
static constexpr int height{580};

// melatonin::Inspector inspector{*this};

juce::Colour backgroundColour = juce::Colour{.475f, 1.f, 0.05f, 1.f};
std::unique_ptr<EveryComponent> everyComponent;

std::unique_ptr<LatticeComponent> latticeComponent;
std::unique_ptr<MTSWarningComponent> warningComponent;
std::unique_ptr<MenuBarComponent> menuComponent;

void init();
bool inited{false};
bool menuWasOpen{false};
// This reference is provided as a quick way for your editor to
// access the processor object that created it.
LatticesProcessor &processor;

bool previouslyActive{false};

int visits[12] = {0};

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(LatticesEditor)
};

0 comments on commit 7a5afa3

Please sign in to comment.