Skip to content
Snippets Groups Projects
Commit c49c3a85 authored by Septen's avatar Septen
Browse files

Parameter class refactoring and stylystic fixes.

parent f9c41c4c
No related branches found
No related tags found
No related merge requests found
/* ------------------------------------------------------------------
This file is part of the Open Ephys GUI
Copyright (C) 2014 Open Ephys
Copyright (C) 2016 Open Ephys
------------------------------------------------------------------
......@@ -24,252 +23,91 @@
#include "Parameter.h"
Parameter::Parameter(const String& name_, bool defaultVal, int ID, bool t)
: shouldDeactivateDuringAcquisition(t), name(name_), description(""),
parameterId(ID)
Parameter::Parameter (const String& name, bool defaultValue, int ID, bool deactivateDuringAcquisition)
: shouldDeactivateDuringAcquisition (deactivateDuringAcquisition)
, m_name (name)
, m_description ("")
, m_parameterId (ID)
, m_parameterType (PARAMETER_TYPE_BOOLEAN)
, m_defaultValue (defaultValue)
{
defaultValue = defaultVal;
possibleValues.add(true);
possibleValues.add(false);
isBool = true;
isCont = false;
isDisc = false;
m_possibleValues.add (true);
m_possibleValues.add (false);
}
Parameter::Parameter(const String& name_, float low, float high,
float defaultVal, int ID, bool t)
: shouldDeactivateDuringAcquisition(t), name(name_), description(""),
parameterId(ID)
{
defaultValue = defaultVal;
possibleValues.add(low);
possibleValues.add(high);
isCont = true;
isBool = false;
isDisc = false;
Parameter::Parameter (const String& name,
float minPossibleValue, float maxPossibleValue, float defaultValue,
int ID,
bool deactivateDuringAcquisition)
: shouldDeactivateDuringAcquisition (deactivateDuringAcquisition)
, m_name (name)
, m_description ("")
, m_parameterId (ID)
, m_parameterType (PARAMETER_TYPE_CONTINUOUS)
, m_defaultValue (defaultValue)
{
m_possibleValues.add (minPossibleValue);
m_possibleValues.add (maxPossibleValue);
// Initialize default value
values.set (0, defaultValue);
m_values.set (0, m_defaultValue);
}
Parameter::Parameter(const String& name_, Array<var> a, int defaultVal,
int ID, bool t)
: shouldDeactivateDuringAcquisition(t), name(name_), description(""),
parameterId(ID)
{
possibleValues = a;
defaultValue = defaultVal; //possibleValues[defaultVal];
isCont = false;
isDisc = true;
isBool = false;
Parameter::Parameter (const String& name,
Array<var> a,
int defaultValue, int ID,
bool deactivateDuringAcquisition)
: shouldDeactivateDuringAcquisition (deactivateDuringAcquisition)
, m_name (name)
, m_description ("")
, m_parameterId (ID)
, m_parameterType (PARAMETER_TYPE_DISCRETE)
, m_defaultValue (defaultValue)
{
m_possibleValues = a;
}
Parameter::~Parameter() {}
const String& Parameter::getName()
{
return name;
}
const String& Parameter::getDescription()
{
return description;
}
const String& Parameter::getName() const noexcept { return m_name; }
const String& Parameter::getDescription() const noexcept { return m_description; }
void Parameter::addDescription(const String& desc)
{
description = desc;
}
int Parameter::getID() const noexcept { return m_parameterId; }
var Parameter::getDefaultValue()
{
return defaultValue;
}
var Parameter::getDefaultValue() const noexcept { return m_defaultValue; }
Array<var> Parameter::getPossibleValues() const noexcept { return m_possibleValues; }
var Parameter::getValue (int channel) const { return m_values[channel]; }
var Parameter::operator[] (int channel) const { return m_values[channel]; }
bool Parameter::isBoolean() const noexcept { return m_parameterType == PARAMETER_TYPE_BOOLEAN; }
bool Parameter::isContinuous() const noexcept { return m_parameterType == PARAMETER_TYPE_CONTINUOUS; }
bool Parameter::isDiscrete() const noexcept { return m_parameterType == PARAMETER_TYPE_DISCRETE; }
int Parameter::getID()
{
return parameterId;
}
Array<var> Parameter::getPossibleValues()
void Parameter::setDescription (const String& description)
{
return possibleValues;
m_description = description;
}
void Parameter::setValue(float val, int chan)
void Parameter::setValue (float value, int channel)
{
if (isBoolean())
{
if (val > 0.0f)
values.set(chan, true);
else
values.set(chan, false);
const bool newValue = (value > 0.0f) ? true : false;
m_values.set (channel, newValue);
}
else if (isContinuous())
{
if (val < (float) possibleValues[0])
{
values.set(chan, possibleValues[0]);
}
else if (val > (float) possibleValues[1])
{
values.set(chan, possibleValues[1]);
}
else
{
values.set(chan, val);
}
const float newValue = jlimit (float (m_possibleValues[0]), float (m_possibleValues[1]), value);
m_values.set (channel, newValue);
}
else
{
//int index = (int) val;
//if (index >= 0 && index < possibleValues.size())
//{
values.set(chan, val);
//}
m_values.set (channel, value);
}
}
var Parameter::operator[](int chan)
{
return values[chan];
}
var Parameter::getValue(int chan)
{
return values[chan];
}
bool Parameter::isBoolean()
{
return isBool;
}
bool Parameter::isContinuous()
{
return isCont;
}
bool Parameter::isDiscrete()
{
return isDisc;
}
// void BooleanParameter::setValue(float val, int chan)
// {
// var b = true;
// bool c = b;
// if (val > 0)
// values.set(chan, true);
// else
// values.set(chan, false);
// }
// void ContinuousParameter::setValue(float val, int chan)
// {
// if (val < low)
// {
// values.set(chan, low);
// } else if (val > high) {
// values.set(chan, high);
// } else {
// values.set(chan, val);
// }
// }
// void DiscreteParameter::setValue(float val, int chan)
// {
// int index = (int) val;
// if (index >= 0 && index < possibleValues.size())
// {
// values.set(chan, possibleValues[index]);
// }
// }
// Array<var> BooleanParameter::getPossibleValues()
// {
// Array<var> a;
// a.add(true);
// a.add(false);
// return a;
// }
// Array<var> ContinuousParameter::getPossibleValues()
// {
// Array<var> a;
// a.add(low);
// a.add(high);
// return a;
// }
// Array<var> DiscreteParameter::getPossibleValues()
// {
// return possibleValues;
// }
// void* BooleanParameter::operator[](int chan)
// {
// return (void*) values[chan];
// }
// void* ContinuousParameter::operator[](int chan)
// {
// return (void*) values[chan];
// }
// void* DiscreteParameter::operator[](int chan)
// {
// return (void*) values[chan];
// }
// BooleanParameter::BooleanParameter(const String name_, bool defaultVal) : Parameter(name_)
// {
// defaultValue = defaultVal;
// }
// ContinuousParameter::ContinuousParameter(const String name_,
// float low_, float high_, float defaultVal)
// : Parameter(name_)
// {
// low = low_;
// high = high_;
// defaultValue = defaultVal;
// }
// DiscreteParameter::DiscreteParameter(const String name_,
// Array<var> a, int defaultVal)
// : Parameter(name_)
// {
// possibleValues = a;
// defaultValue = possibleValues[defaultVal];
// }
......@@ -2,7 +2,7 @@
------------------------------------------------------------------
This file is part of the Open Ephys GUI
Copyright (C) 2014 Open Ephys
Copyright (C) 2016 Open Ephys
------------------------------------------------------------------
......@@ -26,179 +26,105 @@
#include "../../../JuceLibraryCode/JuceHeader.h"
#include "../PluginManager/OpenEphysPlugin.h"
// #include "Editors/GenericEditor.h"
// #include "GenericProcessor.h"
// #include "../AccessClass.h"
#include <stdio.h>
/**
Class for holding user-definable processor parameters.
Parameters can either hold boolean, categorical, or continuous (float) values.
/**
Class for holding user-definable processor parameters.
Using the Parameter class makes it easier to create a graphical interface for editing
parameters, because each Parameter has a ParameterEditor that is created automatically.
Parameters can either hold boolean, categorical, or continuous (float) values.
@see GenericProcessor, GenericEditor
Using the Parameter class makes it easier to create a graphical interface for editing
parameters, because each Parameter has a ParameterEditor that is created automatically.
@see GenericProcessor, GenericEditor
*/
class PLUGIN_API Parameter
{
public:
/** Constructor for boolean parameters.*/
Parameter(const String& name_, bool defaultVal, int ID, bool t = false);
Parameter (const String& name,
bool defaultValue,
int ID,
bool deactivateDuringAcquisition = false);
/** Constructor for continuous (float) parameters.*/
Parameter(const String& name_, float low, float high, float defaultVal, int ID, bool t = false);
Parameter (const String& name,
float low, float high, float defaultValue,
int ID,
bool deactivateDuringAcquisition = false);
/** Constructor for categorical parameters.*/
Parameter(const String& name_, Array<var> a, int defaultVal, int ID, bool t = false);
Parameter (const String& name,
Array<var> a,
int defaultValue, int ID,
bool deactivateDuringAcquisition = false);
/** Destructor.*/
~Parameter();
~Parameter();
/** Returns the name of the parameter.*/
const String& getName();
const String& getName() const noexcept;
/** Returns a description of the parameter.*/
const String& getDescription();
/** Sets the description of the parameter.*/
void addDescription(const String& desc);
/** Returns the default value of a parameter (can be boolean, int, or float).*/
var getDefaultValue();
const String& getDescription() const noexcept;
/** Returns the unique integer ID of a parameter.*/
int getID();
int getID() const noexcept;
/** Returns all the possible values that a parameter can take.*/
Array<var> getPossibleValues();
/** Sets the value of a parameter for a given channel.*/
void setValue(float val, int chan);
/** Returns the default value of a parameter (can be boolean, int, or float).*/
var getDefaultValue() const noexcept;
/** Returns the value of a parameter for a given channel.*/
var operator[](int chan);
var getValue (int chan) const;
/** Returns the value of a parameter for a given channel.*/
var getValue(int chan);
var operator[](int chan) const;
/** Copies a parameter.*/
Parameter& operator=(const Parameter& other);
/** Returns all the possible values that a parameter can take for Boolean and Discrete parameters;
Returns the minimum and maximum value that a parameter can take for Continuous parameters.*/
Array<var> getPossibleValues() const noexcept;
/** Returns true if a parameter is boolean, false otherwise.*/
bool isBoolean();
bool isBoolean() const noexcept;
/** Returns true if a parameter is continuous, false otherwise.*/
bool isContinuous();
bool isContinuous() const noexcept;
/** Returns true if a parameter is discrete, false otherwise.*/
bool isDiscrete();
bool isDiscrete() const noexcept;
/** Certain parameters should not be changed while data acquisition is active.
/** Sets the description of the parameter.*/
void setDescription (const String& desc);
/** Sets the value of a parameter for a given channel.*/
void setValue (float val, int chan);
/** Certain parameters should not be changed while data acquisition is active.
This variable indicates whether or not these parameters can be edited.*/
bool shouldDeactivateDuringAcquisition;
private:
const String name;
String description;
private:
enum ParameterType
{
PARAMETER_TYPE_BOOLEAN = 0
, PARAMETER_TYPE_CONTINUOUS
, PARAMETER_TYPE_DISCRETE
};
int parameterId;
const String m_name;
String m_description;
bool isBool, isCont, isDisc;
int m_parameterId;
var defaultValue;
Array<var> values;
Array<var> possibleValues;
ParameterType m_parameterType;
var m_defaultValue;
Array<var> m_values;
Array<var> m_possibleValues;
};
// class BooleanParameter : public Parameter
// {
// public:
// BooleanParameter(const String name_, bool defaultVal);
// ~BooleanParameter() {}
// Array<var> getPossibleValues();
// void setValue(float val, int chan);
// void* operator[](int chan);
// bool isBoolean() {return true;}
// bool defaultValue;
// Array<bool> values;
// };
// class ContinuousParameter : public Parameter
// {
// public:
// ContinuousParameter(const String name_, float low, float high, float defaultVal);
// ~ContinuousParameter() {}
// Array<var> getPossibleValues();
// void setValue(float val, int chan);
// void* operator[](int chan);
// bool isContinuous() {return true;}
// float low, high, defaultValue;
// Array<float> values;
// };
// class DiscreteParameter : public Parameter
// {
// public:
// DiscreteParameter(const String name_, Array<var> a, int defaultVal);
// ~DiscreteParameter() {}
// Array<var> getPossibleValues();
// void setValue(float val, int chan);
// void* operator[](int chan);
// bool isDiscrete() {return true;}
// Array<var> possibleValues;
// Array<var> values;
// int defaultValue;
// };
// template <class Type>
// class Parameter
// {
// public:
// Parameter(const String& name_,
// Type defaultVal,
// Array<var> possibleVals = Array<var>()) :
// name(name_), defaultValue(defaultVal), possibleValues(possibleVals)
// {
// }
// Type operator[](int chan) {return values[chan];}
// private:
// const String name;
// Type defaultValue;
// Array<Type> values;
// Array<var> possibleValues;
// };
#endif // __PARAMETER_H_62922AE5__
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment