Skip to content
Snippets Groups Projects
  • interpretivechaos's avatar
    3a2ace62
    Loading Parameters and altering Parameter Buttons based on active channels · 3a2ace62
    interpretivechaos authored
    Allows parameters to be set from saved XML and changes the
    parameterEditor buttons (currently for discrete parameters only) to
    reflect which parameters are currently used by selected and
    non-selected channels. This fixes a problem where the buttons would
    always show what the last press was rather than the current values for
    the active channels (e.g. If you changed the parameters on Channel 2,
    and then switched to select only Channel 1, the GUI would incorrectly
    indicate that the settings for Channel 2 were active). Additionally,
    allows the user to see what parameter values are used for channels not
    currently selected.
    3a2ace62
    History
    Loading Parameters and altering Parameter Buttons based on active channels
    interpretivechaos authored
    Allows parameters to be set from saved XML and changes the
    parameterEditor buttons (currently for discrete parameters only) to
    reflect which parameters are currently used by selected and
    non-selected channels. This fixes a problem where the buttons would
    always show what the last press was rather than the current values for
    the active channels (e.g. If you changed the parameters on Channel 2,
    and then switched to select only Channel 1, the GUI would incorrectly
    indicate that the settings for Channel 2 were active). Additionally,
    allows the user to see what parameter values are used for channels not
    currently selected.
Parameter.cpp 4.63 KiB

/*    ------------------------------------------------------------------

    This file is part of the Open Ephys GUI
    Copyright (C) 2013 Open Ephys

    ------------------------------------------------------------------

    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 "Parameter.h"


Parameter::Parameter(const String& name_, bool defaultVal, int ID, bool t)
    : shouldDeactivateDuringAcquisition(t), name(name_), description(""),
      parameterId(ID)
{

    defaultValue = defaultVal;

    possibleValues.add(true);
    possibleValues.add(false);

    isBool = true;
    isCont = false;
    isDisc = 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_, 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;
}


void Parameter::setValue(float val, int chan)
{

    if (isBoolean())
    {
        if (val > 0.0f)
            values.set(chan, true);
        else
            values.set(chan, false);
    }
    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);
        }

    }
    else
    {
        //int index = (int) val;

        //if (index >= 0 && index < possibleValues.size())
        //{
        values.set(chan, val);
        //}

    }

}

// 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];
// }