yes you re right oli, think i fixed that part now putting in external 'touchfader_tools' file only the type declaration is in there,
the vector itself remains private 'local' to the module so if two modules they *should not interfer now
what i got now is a comma text on input that is parsed to vector elements .name string data , and original id to .id integer data.So when clicking on an element module outputs selected text string and selected integer id, and if using the sort function it will reorder to alphabetical order but it will still be able output the 'original id' that's cool.
now im trying to add similar to usine feature that allows user to specify a value (like A = 10, B=0.1 C =2 ect..on the way
edit:: done (ill show you the code if ya want, basically once line is extracted, do an extra seach for an "=" marker, get the right par sting, remove potential spces, then convert string to float if possibleand assign to element.assignated_value for later recall)
but here is just for alphabetical sorting, while keeping way to reccall 'original id' thing :
in my 'Touch_Fader_Tools.h (an external file i created with useful/frequent called functions, inclueded at top of module main file .h)
Code: Select all
struct Tlist_item //structure for an "element" contening name, id and value
{
std::string name ="";
int id = 0;
float assigned_value = 0;
};
bool sortByName(const Tlist_item &lhs, const Tlist_item &rhs); // sort "rule" function
on same file .cpp this fonction looks like
Code: Select all
bool sortByName(const Tlist_item &lhs, const Tlist_item &rhs)
{
return lhs.name < rhs.name;
};
(wich is something i found on stack overflow), as i get it when later basic sort function is called in main file, it defines
what "rule" is applyed to sort, ie in this case it compares passed element sub .name 'from left hand side' aka lhs to right side rhs
then on my main module Touch_Fader.h created a vector of those 'list elements' stuture wich can handle name, id and float value per vector element as defined by the Tlist_item structure.
Code: Select all
private:
vector<Tlist_item> LIST_ITEMS;
and finally the code trigged on module input comma text changes callback to parse in main .cpp:
onInputCommaTextChange begin:
Code: Select all
istringstream ss(COMMA_IN); //string stream picking the input comma string
string token; // what will be used as string splitted "line element"
LIST_ITEMS.resize(MAX_LIST_ITEMS); //first size to max allowed defined size
int count = 0; // used to iterate, starting at id =0
while (std::getline(ss, token, ',') && count < MAX_LIST_ITEMS) // extract line splitted by comma to token
{
LIST_ITEMS[count].name = token; //store token to same vector pos elmnt.name
LIST_ITEMS[count].id = count; // store original id
count++; // increment loop iteration
}
LIST_ITEMS.resize(count); // resize vector to max found elmts count while looping
TFItem.IListBox.NB_LIST_ITEMS = count; // also passes that list size to local listbox code
sort(LIST_ITEMS.begin(), LIST_ITEMS.end(), sortByName); /// sort function calling a by name sort
// specifing vector start,end, and rule function to apply
sdkRepaintPanel(); /// repaint module t reflect changes
so to sum up it will create a vector with 3 datas: name, id, value.
parse comma text input to splitted elements within commas to vector.name data, keeping 'original' id to .id data.
then sort function sort by alphabetical order of name and so moves all the 'element', meaning the 3 datas in same order.
so when in the code is later asking for an element, it can recall it's name, original id, and assignated value if was set.
maybe there are more efficient ways to do.. but atleast that worked :p