Skip to content

Commit

Permalink
Revert the skin data structure changes temporarily (#1581)
Browse files Browse the repository at this point in the history
We're gonna do a quick 1.6.6 release so revert the two data
structure changes from master

Reverts commit 8331375.
Reverts commit ff01bf8.
  • Loading branch information
baconpaul authored Feb 15, 2020
1 parent 9bd282b commit 50f63fd
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 460 deletions.
12 changes: 3 additions & 9 deletions src/common/Parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
#include <sstream>
#include <string>

Parameter::Parameter() : posx( PositionHolder::Axis::X ),
posy( PositionHolder::Axis::Y ),
posy_offset( PositionHolder::Axis::YOFF )
Parameter::Parameter()
{
val.i = 0;
posy_offset = 0;
Expand Down Expand Up @@ -131,13 +129,11 @@ void Parameter::set_name(const char* n)
create_fullname(dispname, fullname, ctrlgroup, ctrlgroup_entry);
}

Parameter* Parameter::assign(ParameterIDCounter::promise_t idp,
Parameter* Parameter::assign(int id,
int pid,
const char* name,
const char* dispname,
int ctrltype,

std::string ui_identifier,
int posx,
int posy,
int scene,
Expand All @@ -146,8 +142,7 @@ Parameter* Parameter::assign(ParameterIDCounter::promise_t idp,
bool modulateable,
int ctrlstyle)
{
this->id_promise = idp.get();
this->id = -1;
this->id = id;
this->param_id_in_scene = pid;
this->ctrlgroup = ctrlgroup;
this->ctrlgroup_entry = ctrlgroup_entry;
Expand All @@ -156,7 +151,6 @@ Parameter* Parameter::assign(ParameterIDCounter::promise_t idp,
this->modulateable = modulateable;
this->scene = scene;
this->ctrlstyle = ctrlstyle;
strncpy(this->ui_identifier, ui_identifier.c_str(), NAMECHARS );

strncpy(this->name, name, NAMECHARS);
set_name(dispname);
Expand Down
99 changes: 2 additions & 97 deletions src/common/Parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#pragma once
#include "globals.h"
#include <string>
#include <memory>

union pdata
{
Expand Down Expand Up @@ -126,104 +125,17 @@ struct CountedSetUserData : public ParamUserData
virtual int getCountedSetSize() = 0; // A constant time answer to the count of the set
};

/*
** It used to be parameters were assigned IDs in SurgePatch using an int which we ++ed along the
** way. If we want to 'add at the end' but 'cluster together' we need a different data strcture
** to allow clusters of parameters, so instead make SurgePatch use a linked list (or multiple lists)
** while constructing params and then resolve them all at the end. This little class lets us
** do that.
*/
struct ParameterIDCounter
{
struct ParameterIDPromise
{
std::shared_ptr<ParameterIDPromise> next;
ParameterIDPromise() : next(nullptr)
{
}
~ParameterIDPromise()
{
}
long value = -1;
};

ParameterIDCounter()
{
head.reset(new ParameterIDPromise());
tail = head;
}
~ParameterIDCounter()
{
head = nullptr;
tail = nullptr;
}

typedef std::shared_ptr<ParameterIDPromise> promise_t;
typedef ParameterIDPromise* promise_ptr_t; // use this for constant size carefully managed weak references

promise_t head, tail;

// This is a post-increment operator
promise_t next()
{
promise_t n(new ParameterIDPromise());
tail->next = n;
auto ret = tail;
tail = n;
return ret;
};

void resolve()
{
auto h = head;
int val = 0;
while (h.get())
{
h->value = val++;
h = h->next;
}
}
};

/*
** Similarly the "position" is part of the parameter and that's a nasty mistake - there should
** be an indirection. Ideally we would remove posx and posy as members altogether but to allow
** an incremental approach make a little class which casts to an int and can redirect (at some
** future point) for position. At this current iteration it is simply a holder for an int.
*/
class PositionHolder
{
public:
typedef enum {
X,
Y,
YOFF
} Axis;

PositionHolder(Axis a) : val(-1), axis(a) { }

operator int() const { return val; }
PositionHolder& operator=(const int v) { val = v; return *this; }

private:
Axis axis;
int val;
};

class Parameter
{
public:
Parameter();
Parameter* assign(ParameterIDCounter::promise_t id,
Parameter* assign(int id,
int pid,
const char* name,
const char* dispname,
int ctrltype,

std::string ui_identifier,
int posx,
int posy,

int scene = 0,
ControlGroup ctrlgroup = cg_GLOBAL,
int ctrlgroup_entry = 0,
Expand Down Expand Up @@ -265,18 +177,12 @@ class Parameter
std::string tempoSyncNotationValue(float f);

pdata val, val_default, val_min, val_max;
// You might be tempted to use a non-fixed-size member here, like a std::string, but
// this class gets pre-c++ memcopied so thats not an option which is why I do this wonky
// pointer thing and strncpy from a string onto ui_identifier
ParameterIDCounter::promise_ptr_t id_promise;
int id;
char name[NAMECHARS], dispname[NAMECHARS], name_storage[NAMECHARS], fullname[NAMECHARS];
char ui_identifier[NAMECHARS];
bool modulateable;
int valtype = 0;
int scene; // 0 = patch, 1 = scene A, 2 = scene B
int ctrltype;
PositionHolder posx, posy, posy_offset;
int ctrltype, posx, posy, posy_offset;
ControlGroup ctrlgroup = cg_GLOBAL;
int ctrlgroup_entry = 0;
int ctrlstyle = cs_off;
Expand All @@ -287,7 +193,6 @@ class Parameter
bool per_voice_processing;
bool temposync, extend_range, absolute, snap;


ParamUserData* user_data; // I know this is a bit gross but we have a runtime type
void set_user_data(ParamUserData* ud); // I take a shallow copy and don't assume ownership and assume i am referencable
};
Loading

0 comments on commit 50f63fd

Please sign in to comment.