Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion include/BasePedalComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @brief Base class for pedal components.
* This class provides a common interface and functionality for all pedal components.
*/
class BasePedalComponent : public EffectComponent
class BasePedalComponent : public EffectComponent, public DragAndDropTarget
{
public:
/**
Expand All @@ -32,6 +32,25 @@ class BasePedalComponent : public EffectComponent
*/
void resized() override;

/**
* @brief Handles mouse down events.
* @param event The mouse event that occurred.
*/
void mouseDown(const juce::MouseEvent& event) override;

/**
*
* @param dragSourceDetails The details of the drag source.
* @return A boolean indicating whether the component is interested in the drag source.
*/
bool isInterestedInDragSource(const SourceDetails& dragSourceDetails) override;

/**
* @brief Handles the drop of a component onto this pedal component.
* @param dragSourceDetails The details of the drag source.
*/
void itemDropped(const SourceDetails& dragSourceDetails) override;

protected:
/**
* @brief The default width of the component.
Expand Down
20 changes: 20 additions & 0 deletions include/ChromaticTuner.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include <JuceHeader.h>

class ChromaticTuner
{
public:
ChromaticTuner(int fftOrder, double sampleRate);
~ChromaticTuner();
std::optional<float> getMainFrequencyFromAudioBlock(const dsp::AudioBlock<float>& block);
int getFFTSize() const;

private:
juce::dsp::FFT fft;
int fftSize;
double sampleRate;

juce::HeapBlock<float> fftBuffer;
juce::dsp::WindowingFunction<float> window;
};
40 changes: 40 additions & 0 deletions include/ChromaticTunerComponent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once

#include <JuceHeader.h>

#include "ChromaticTuner.h"

struct ChromaticTuningResult
{
std::string noteName;
float frequency;
float deviation;
bool isInTune;
};

class ChromaticTunerComponent : public juce::Component
{
public:
explicit ChromaticTunerComponent(int sampleRate = 44100, int fftOrder = 10);
~ChromaticTunerComponent() override;

void paint(juce::Graphics &g) override;
void resized() override;
void prepareToPlay(int samplesPerBlockExpected, double sampleRate);
void tune(const AudioSourceChannelInfo &bufferToFill);
bool isTuning();
private:
ChromaticTuner* tuner;
bool isTunerActive = false;
const std::vector<std::string> notesNames;
float baseFrequency;
std::string currentNote;
float currentTuneCents;
bool isInTune;
float smoothedFrequency = 0.0f;
float smoothingCoeff = 0.2f; // Ajustez selon la réactivité voulue

ChromaticTuningResult detectTuning(float frequency);
std::string getNoteName(int midiNote);
void updateTuningDisplay(const ChromaticTuningResult& result);
};
9 changes: 1 addition & 8 deletions include/DistortionEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,7 @@ class DistortionEffect : public AbstractEffect {
}
}

bool operator==(const AbstractEffect* other)
{
return dynamic_cast<const DistortionEffect*>(other) &&
level == static_cast<const DistortionEffect*>(other)->level &&
tone == static_cast<const DistortionEffect*>(other)->tone &&
dist == static_cast<const DistortionEffect*>(other)->dist &&
turbo == static_cast<const DistortionEffect*>(other)->turbo;
}
bool operator==(const AbstractEffect* other);

private:
float level = 1.0f;
Expand Down
9 changes: 8 additions & 1 deletion include/MainComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@
* It is responsible for the layout of the components and the audio processing.
* It contains the pedalboard, the top menu bar, the bottom menu bar and the connection component.
*/
class MainComponent final : public AudioAppComponent {
class MainComponent final : public AudioAppComponent, public DragAndDropContainer {
public:
explicit MainComponent(const Manager &manager);

/**
* Destructor of the MainComponent.
*/
~MainComponent() override;

/**
* Determines how the component is displayed.
*/
Expand Down Expand Up @@ -100,5 +105,7 @@ class MainComponent final : public AudioAppComponent {
*/
bool isSoundMuted = false;

std::function<void(const juce::AudioSourceChannelInfo&)> tuningFunction;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MainComponent)
};
3 changes: 2 additions & 1 deletion include/ModalOverlayComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class ModalOverlayComponent : public juce::Component
{
public:
ModalOverlayComponent(std::string viewName, juce::Component* modalContent);
ModalOverlayComponent(std::string viewName, juce::Component* modalContent, std::function<void()> onCloseCallback);
~ModalOverlayComponent() override = default;
void resized() override;
void paint(Graphics& g) override;
Expand All @@ -13,6 +13,7 @@ class ModalOverlayComponent : public juce::Component
juce::Label viewNameLabel;
juce::ImageButton closeOverlayButton;
juce::Component* modalComponent = nullptr;
std::function<void()> onCloseCallback;

void onCloseOverlayButtonClicked();
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ModalOverlayComponent)
Expand Down
5 changes: 0 additions & 5 deletions include/Pedal.h

This file was deleted.

2 changes: 1 addition & 1 deletion include/Pedalboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Pedalboard : public AbstractEffect {
* @brief Gets the collection of effects contained in the pedalboard.
* @return The collection of effects contained in the pedalboard.
*/
std::vector<AbstractEffect *> getEffects();
std::vector<AbstractEffect *>& getEffects();

/**
* @brief Gets the type name of the effect for serialization purposes.
Expand Down
27 changes: 26 additions & 1 deletion include/PedalboardComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* @brief Represents a graphical component that contains and displays a pedalboard.
*/
class PedalboardComponent : public EffectComponent {
class PedalboardComponent : public EffectComponent, public DragAndDropContainer {
public:
/**
* @brief Initializes a new instance of the PedalboardComponent class.
Expand Down Expand Up @@ -48,6 +48,21 @@ class PedalboardComponent : public EffectComponent {
* @return The required height for the pedalboard.
*/
int getRequiredHeight(const int boardWidth) const;

/**
* @brief Handles the drag and drop of a Component onto the pedalboard.
* @param target The target Component where the dragged component is dropped.
* @param dragged The Component that is being dragged.
*/
void onPedalDropped(Component* target, Component* dragged);

/**
* @brief Handles the drag and drop of an EffectComponent onto the pedalboard.
* @param target The target EffectComponent where the dragged component is dropped.
* @param dragged The EffectComponent that is being dragged.
*/
void onPedalDropped(EffectComponent* target, EffectComponent* dragged);

private:

/**
Expand All @@ -64,4 +79,14 @@ class PedalboardComponent : public EffectComponent {
* @brief The flexbox that arranges layout for the effect components in the pedalboard.
*/
juce::FlexBox flexBox;

/**
* @brief Indicates whether something is being dragged over the pedalboard.
*/
bool somethingIsBeingDraggedOver;

/**
* @brief Refreshes the flexbox layout of the pedalboard.
*/
void refreshFlexBox();
};
11 changes: 9 additions & 2 deletions include/TopMenuBarComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "ModalOverlayComponent.h"
#include "SettingsComponent.h"
#include "AccountComponent.h"
#include "ChromaticTunerComponent.h"

/**
* @brief Represents a graphical component that contains and displays the top menu bar.
Expand All @@ -15,7 +16,7 @@ class TopMenuBarComponent : public juce::Component {
/**
* @brief Initializes a new instance of the TopMenuBarComponent class.
*/
explicit TopMenuBarComponent(juce::AudioDeviceManager& deviceManager, bool* isMuted = nullptr);
explicit TopMenuBarComponent(juce::AudioDeviceManager& deviceManager, bool* isMuted = nullptr, std::function<void(const juce::AudioSourceChannelInfo&)>* tuningFunction = nullptr);

/**
* @brief Destroys the instance of the TopMenuBarComponent class.
Expand All @@ -39,7 +40,7 @@ class TopMenuBarComponent : public juce::Component {
*/
juce::FlexBox flexBox;

ModalOverlayComponent* modalOverlay;
std::unique_ptr<ModalOverlayComponent> modalOverlay;

/**
* @brief The image button to open settings.
Expand All @@ -50,12 +51,18 @@ class TopMenuBarComponent : public juce::Component {
juce::ImageButton accountButton;
AccountComponent* accountComponent;

juce::ImageButton tunerButton;
ChromaticTunerComponent* tunerComponent;
std::function<void(const juce::AudioSourceChannelInfo&)>* tuningFunction;

bool* isSoundMuted = nullptr;
juce::ImageButton muteButton;

void openSettingsPopup(juce::AudioDeviceManager& deviceManager);
void openAccountPopup();
void openTunerPopup();
void toggleMute();
void closePopup();

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(TopMenuBarComponent)
};
Binary file added resources/icons/close.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/tuner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 10 additions & 4 deletions src/MainComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
#include "SettingsComponent.h"
#include "ResourceManager.h"




MainComponent::MainComponent(const Manager &manager): pedalboardComponent(manager.getPedalboard()),
topMenuBarComponent(this->deviceManager, &isSoundMuted), manager(manager)
topMenuBarComponent(this->deviceManager, &isSoundMuted, &tuningFunction), manager(manager)
{
setAudioChannels(2, 2);

Expand All @@ -28,6 +25,11 @@ MainComponent::MainComponent(const Manager &manager): pedalboardComponent(manage
addAndMakeVisible(connectionComponent);
}

MainComponent::~MainComponent()
{
releaseResources();
}

//==============================================================================
void MainComponent::paint (juce::Graphics& g)
{
Expand Down Expand Up @@ -76,9 +78,13 @@ void MainComponent::getNextAudioBlock(const AudioSourceChannelInfo &bufferToFill
{
bufferToFill.clearActiveBufferRegion();
}
if (tuningFunction != nullptr) {
tuningFunction(bufferToFill);
}
}

void MainComponent::releaseResources() {
shutdownAudio();
}


8 changes: 6 additions & 2 deletions src/Pedalboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

Pedalboard::Pedalboard() { };

Pedalboard::~Pedalboard() = default;
Pedalboard::~Pedalboard() {
for (AbstractEffect* effect : effects) {
delete effect;
}
};

void Pedalboard::apply(const AudioSourceChannelInfo &bufferToFill) {
for (AbstractEffect* effect : effects) {
Expand All @@ -33,7 +37,7 @@ void Pedalboard::remove(const AbstractEffect* effect) {
effects.erase(std::remove(effects.begin(), effects.end(), effect), effects.end());
}

std::vector<AbstractEffect*> Pedalboard::getEffects() {
std::vector<AbstractEffect*>& Pedalboard::getEffects() {
return effects;
}

Expand Down
Loading