Ive got a random commatext on input im splitting to elements and putting to an array of string
what i dlike to achieve is sorting the list by alphabetical order, but keep trace of where the original positions/id went once sorted to be able to recall them if clicing on a sorted element
ex:
INPUT OUTPUT
pos string id become pos string id
1 Zozo 1 ------> 1 aahhh 5
2 wouoou 2 ------> 2 doodle 4
3 xanax 3 ------> 3 xanax 3
4 doodle 4 ------> 4 wouoou 2
5 aaahh 5 -----> 5 Zozo 1
any idea best/simple way to do that?
alphabetical sorting / reordering
Ok sorry nevermind, found solution.
in case interested the idea was to build a structure with a .name and .id data, make a vector of those custom type element, sort this vector by name using sort function, then get the id when needed accessing vector wanted pos id.
I couldn't get this work and fail to understand why i finally got it working only if the declaration of this type was made out of my module private declaration.. anyway works now
in case interested the idea was to build a structure with a .name and .id data, make a vector of those custom type element, sort this vector by name using sort function, then get the id when needed accessing vector wanted pos id.
I couldn't get this work and fail to understand why i finally got it working only if the declaration of this type was made out of my module private declaration.. anyway works now
good news !
Olivier Sens
www.brainmodular.com
www.brainmodular.com
I think that if the declaration is public you could have trouble if using more than one module in your workspace.
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
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
http://oli-lab.org
Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces
follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social
Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces
follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social
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)
on same file .cpp this fonction looks like
(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.
and finally the code trigged on module input comma text changes callback to parse in main .cpp:
onInputCommaTextChange begin:
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
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" functionCode: Select all
bool 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.
Code: Select all
private:
vector<Tlist_item> LIST_ITEMS;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 changesparse 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
Who is online
Users browsing this forum: No registered users and 25 guests
