ArrayArrayArrayArrayArray
CODE: CODE: CODE: CODE: Statistics: Posted by 23fx23 — 09 Oct 2016, 19:45 Statistics: Posted by oli_lab — 09 Oct 2016, 19:12
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)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" functionbool sortByName(const Tlist_item &lhs, const Tlist_item &rhs){return lhs.name < rhs.name;};
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.private:vector<Tlist_item> LIST_ITEMS;
onInputCommaTextChange begin: istringstream ss(COMMA_IN); //string stream picking the input comma stringstring 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 =0while (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.nameLIST_ITEMS[count].id = count; // store original idcount++; // increment loop iteration}LIST_ITEMS.resize(count); // resize vector to max found elmts count while loopingTFItem.IListBox.NB_LIST_ITEMS = count; // also passes that list size to local listbox codesort(LIST_ITEMS.begin(), LIST_ITEMS.end(), sortByName); /// sort function calling a by name sort // specifing vector start,end, and rule function to applysdkRepaintPanel(); /// repaint module t reflect changes
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
]]>
for the sorting thing, you can have a module with comma text on input and ID on output
the output should be an array of numbers : index 0 value 5 etc...
how did you managed the alphabetical sorting ?
thanx for sharing
Olivar
]]>
Statistics: Posted by 23fx23 — 09 Oct 2016, 17:47
Statistics: Posted by 23fx23 — 09 Oct 2016, 15:12
CODE:
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" functionCODE:
bool sortByName(const Tlist_item &lhs, const Tlist_item &rhs){return lhs.name < rhs.name;};CODE:
private:vector<Tlist_item> LIST_ITEMS;CODE:
istringstream ss(COMMA_IN); //string stream picking the input comma stringstring 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 =0while (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.nameLIST_ITEMS[count].id = count; // store original idcount++; // increment loop iteration}LIST_ITEMS.resize(count); // resize vector to max found elmts count while loopingTFItem.IListBox.NB_LIST_ITEMS = count; // also passes that list size to local listbox codesort(LIST_ITEMS.begin(), LIST_ITEMS.end(), sortByName); /// sort function calling a by name sort // specifing vector start,end, and rule function to applysdkRepaintPanel(); /// repaint module t reflect changesStatistics: Posted by 23fx23 — 09 Oct 2016, 19:45
Statistics: Posted by oli_lab — 09 Oct 2016, 19:12
Statistics: Posted by 23fx23 — 09 Oct 2016, 17:47
Statistics: Posted by 23fx23 — 09 Oct 2016, 15:12