/* ============================================================================== Copyright 2022 Nicolas Chambert This program is free software : you can redistribute itand /or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program.If not, see < http://www.gnu.org/licenses/>. ============================================================================== */ /* ============================================================================== Gestion du nombre de temps par mesure. ============================================================================== */ #include "TempoPanel.h" #include "Metronome.h" TempoPanel::TempoPanel(juce::Colour c) : backgroundColour(c) { // initialisation de l'interface addComponent(decrement); addComponent(tempo); addComponent(increment); tempo.setText("4", juce::dontSendNotification); // On met une valeur mais elle va être RaZ dans le init() tempo.getFont().setBold(true); tempo.setColour(juce::Label::textColourId, juce::Colours::black); tempo.setJustificationType(juce::Justification::centred); tempo.setFont(30); } void TempoPanel::addComponent(juce::Component& c) { addAndMakeVisible(c); c.setColour(juce::TextButton::buttonColourId, backgroundColour); c.setColour(juce::TextButton::textColourOffId, juce::Colours::black); } void TempoPanel::paint(juce::Graphics& g) { g.fillAll(backgroundColour); } void TempoPanel::resized() { // On gêre le layout à la main auto area = getLocalBounds(); int butHeigth = 20; int butWidth = 48; int labeSize = 3 * butHeigth; int totalWidth = 2 * butWidth + labeSize; int marginH = (area.getWidth() - totalWidth) / 2; int marginV = (area.getHeight() - labeSize) / 2; decrement.setBounds(area.getX() + marginH, area.getY() + marginV + butHeigth, butWidth, butHeigth); tempo.setBounds(area.getX() + marginH + butWidth, area.getY() + marginV, labeSize, labeSize); increment.setBounds(area.getX() + marginH + butWidth + labeSize, area.getY() + marginV + butHeigth, butWidth, butHeigth); } void TempoPanel::init(Metronome& metro) { // On établi les liaisons entre le Metronome et les composants graphique tempo.setText(juce::String(metro.getMeasures()), juce::dontSendNotification); increment.onClick = [&, this]() { inc(metro); }; decrement.onClick = [&, this]() { dec(metro); }; } void TempoPanel::inc(Metronome& metro) { // incrémente le tempo metro.setMeasures(metro.getMeasures() + 1); tempo.setText(juce::String(metro.getMeasures()), juce::dontSendNotification); // MàJ du label } void TempoPanel::dec(Metronome& metro) { // decremente le tempo metro.setMeasures(metro.getMeasures() - 1); tempo.setText(juce::String(metro.getMeasures()), juce::dontSendNotification); // MàJ du label }