Skip to content

Commit

Permalink
factor out ControlElement base class without UI dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
drlight-code committed Feb 28, 2020
1 parent 9e09c46 commit ae8c279
Show file tree
Hide file tree
Showing 15 changed files with 233 additions and 129 deletions.
4 changes: 2 additions & 2 deletions Source/ControlContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/

#include "LayoutHints.h"
#include "ControlElement.h"
#include "ControlElementUI.h"

#include "ControlContainer.h"

Expand All @@ -36,7 +36,7 @@ resized()
}
}

std::list<ControlElementUniq> &
std::list<ControlElementUIUniq> &
ControlContainer::
getElementList()
{
Expand Down
9 changes: 4 additions & 5 deletions Source/ControlContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,21 @@

#include <JuceHeader.h>

class ControlElement;
using ControlElementUniq = std::unique_ptr<ControlElement>;
class ControlElementUI;
using ControlElementUIUniq = std::unique_ptr<ControlElementUI>;

class ControlContainer :
public Component
{
public:
void resized() override;

std::list<ControlElementUniq> & getElementList();
std::list<ControlElementUIUniq> & getElementList();

OSCSender & getOSCSender();

private:
std::list<ControlElementUniq> listControlElements;
std::list<ControlElementUIUniq> listControlElements;
OSCSender oscSender;
};

using ControlContainerUniq = std::unique_ptr<ControlContainer>;
74 changes: 0 additions & 74 deletions Source/ControlElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
*/

#include "LayoutHints.h"

#include "ControlElement.h"

ControlElement::
Expand All @@ -29,76 +27,4 @@ ControlElement
oscSender(oscSender),
createInfo(createInfo)
{
message = createInfo.message;
messageMute = createInfo.messageMute;

buttonMute.reset (new TextButton ("buttonMute"));
buttonMute->setButtonText("m");
buttonMute->setColour(TextButton::buttonOnColourId,
Colours::crimson);
buttonMute->setClickingTogglesState(true);
buttonMute->setPaintingIsUnclipped(true);
buttonMute->getToggleStateValue().addListener(this);
addAndMakeVisible(buttonMute.get());

sendValue.addListener(this);
}

void
ControlElement::
resized()
{
auto area = getLocalBounds();

auto gap = LayoutHints::sizeGap;
auto buttonSize = LayoutHints::heightRow - 2*gap;

area.removeFromRight(gap);
area.removeFromTop(gap);
area.setHeight(buttonSize);

buttonMute->setBounds(area.removeFromRight(buttonSize));
}

void
ControlElement::
registerSendValue()
{
sendValue.removeListener(this);
sendValue.referTo
(getSpecificSendValue());
sendValue.addListener(this);
}

void
ControlElement::
valueChanged
(Value & value)
{
if(value == buttonMute->getToggleStateValue()) {
auto toggleState = buttonMute->getToggleState();
if(messageMute != "") {
auto oscMessage = OSCMessage(String(messageMute),
int(toggleState));
oscSender.send(oscMessage);
}

if(!toggleState) {
send();
}
}
else if(value.refersToSameSourceAs(sendValue)) {
send();
}
}

void
ControlElement::
send()
{
if (!buttonMute->getToggleState()) {
auto value = sendValue.getValue();
auto oscMessage = OSCMessage(String(message), float(value));
oscSender.send(oscMessage);
}
}
22 changes: 2 additions & 20 deletions Source/ControlElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@

#include <JuceHeader.h>

class ControlElement :
public Component,
public Value::Listener
class ControlElement
{
public:
struct CreateInfo {
Expand All @@ -44,25 +42,9 @@ class ControlElement :
(const CreateInfo & info,
OSCSender & oscSender);

virtual int getNumberOfRows() const = 0;
void resized() override;

void registerSendValue();

void valueChanged(Value & value) override;

void send();
virtual void send() = 0;

protected:
virtual Value & getSpecificSendValue() = 0;
OSCSender & oscSender;

private:
CreateInfo createInfo;
std::unique_ptr<TextButton> buttonMute;

String message;
String messageMute;

Value sendValue;
};
7 changes: 4 additions & 3 deletions Source/ControlElementFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "PluginProcessor.h"

#include "ControlElementUI.h"
#include "ControlElementKnob.h"
#include "ControlElementFactory.h"

Expand All @@ -34,9 +35,9 @@ ControlElementFactory
{
}

std::unique_ptr<ControlElement>
std::unique_ptr<ControlElementUI>
ControlElementFactory::
createControlElement
createControlElementUI
(YAML::Node configElement, YAML::Node configInterface)
{
ControlElement::CreateInfo info;
Expand All @@ -50,7 +51,7 @@ createControlElement
showNames.IsScalar() ? showNames.as<bool>() : false;
}

std::unique_ptr<ControlElement> product;
std::unique_ptr<ControlElementUI> product;
if(type == "knob") {

auto range = configElement["range"];
Expand Down
4 changes: 2 additions & 2 deletions Source/ControlElementFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class ControlElementFactory {
(OSCSender & oscSender,
OscsendvstAudioProcessor & processor);

std::unique_ptr<ControlElement>
createControlElement
std::unique_ptr<ControlElementUI>
createControlElementUI
(YAML::Node configElement,
YAML::Node configInterface);

Expand Down
4 changes: 2 additions & 2 deletions Source/ControlElementKnob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ControlElementKnob::
ControlElementKnob
(const CreateInfo & createInfo,
OSCSender & oscSender) :
ControlElement(createInfo, oscSender)
ControlElementUI(createInfo, oscSender)
{
knob.reset (new Slider("knob"));
knob->setSliderStyle (Slider::RotaryVerticalDrag);
Expand Down Expand Up @@ -72,7 +72,7 @@ void
ControlElementKnob::
resized()
{
ControlElement::resized();
ControlElementUI::resized();

auto area = getLocalBounds();
auto areaKnob = area.removeFromLeft(LayoutHints::heightRow);
Expand Down
4 changes: 2 additions & 2 deletions Source/ControlElementKnob.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@

#include <utility>

#include "ControlElement.h"
#include "ControlElementUI.h"
#include "ControlElementKnob.h"

class ControlElementKnob :
public ControlElement
public ControlElementUI
{
public:
ControlElementKnob
Expand Down
101 changes: 101 additions & 0 deletions Source/ControlElementUI.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
oscsend-vst - An audio plugin that speaks OSC.
Copyright (C) 2020 Patric Schmitz
This program is free software: you can redistribute it and/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/>.
*/

#include "LayoutHints.h"

#include "ControlElementUI.h"

ControlElementUI::
ControlElementUI
(const CreateInfo & info,
OSCSender & oscSender) :
ControlElement(info, oscSender)
{
buttonMute.reset (new TextButton ("buttonMute"));
buttonMute->setButtonText("m");
buttonMute->setColour(TextButton::buttonOnColourId,
Colours::crimson);
buttonMute->setClickingTogglesState(true);
buttonMute->setPaintingIsUnclipped(true);
buttonMute->getToggleStateValue().addListener(this);
addAndMakeVisible(buttonMute.get());

sendValue.addListener(this);
}

void
ControlElementUI::
resized()
{
auto area = getLocalBounds();

auto gap = LayoutHints::sizeGap;
auto buttonSize = LayoutHints::heightRow - 2*gap;

area.removeFromRight(gap);
area.removeFromTop(gap);
area.setHeight(buttonSize);

buttonMute->setBounds(area.removeFromRight(buttonSize));
}

void
ControlElementUI::
registerSendValue()
{
sendValue.removeListener(this);
sendValue.referTo
(getSpecificSendValue());
sendValue.addListener(this);
}

void
ControlElementUI::
valueChanged
(Value & value)
{
if(value == buttonMute->getToggleStateValue()) {
auto toggleState = buttonMute->getToggleState();
if(createInfo.messageMute != "") {
auto oscMessage =
OSCMessage(String(createInfo.messageMute), int(toggleState));
oscSender.send(oscMessage);
}

if(!toggleState) {
send();
}
}
else if(value.refersToSameSourceAs(sendValue)) {
send();
}
}

void
ControlElementUI::
send()
{
if (!buttonMute->getToggleState()) {
auto value = sendValue.getValue();
auto oscMessage =
OSCMessage(String(createInfo.message), float(value));
oscSender.send(oscMessage);
}
}
53 changes: 53 additions & 0 deletions Source/ControlElementUI.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
oscsend-vst - An audio plugin that speaks OSC.
Copyright (C) 2020 Patric Schmitz
This program is free software: you can redistribute it and/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/>.
*/

#pragma once

#include "ControlElement.h"

class ControlElementUI :
public ControlElement,
public Component,
public Value::Listener
{
public:
ControlElementUI
(const CreateInfo & info,
OSCSender & oscSender);

virtual int getNumberOfRows() const = 0;
void resized() override;

void registerSendValue();

void valueChanged(Value & value) override;

void send() override;

protected:

virtual Value & getSpecificSendValue() = 0;

private:

std::unique_ptr<TextButton> buttonMute;
Value sendValue;
};
using ControlElementUIUniq = std::unique_ptr<ControlElementUI>;
Loading

0 comments on commit ae8c279

Please sign in to comment.