sorting signal names for the list view

This commit is contained in:
Edward Arthur Bingham 2022-09-24 17:54:11 -04:00
parent 53ea178541
commit 24aaa7c1f2
2 changed files with 45 additions and 1 deletions

View File

@ -242,6 +242,50 @@ wavetable_foreach_wavevar(WaveTable *wt, GFunc func, gpointer *p)
}
}
typedef struct {
char *name;
int index;
} keyval;
int keyval_compare(const void *k1, const void *k2) {
return strcmp(((keyval*)k1)->name, ((keyval*)k2)->name);
}
/*
* Iterate over all WaveVars in all sweeps/segments in the WaveFile,
* calling the function for each one.
*/
void
wavetable_foreach_wavevar_sorted(WaveTable *wt, GFunc func, gpointer *p)
{
keyval k;
WaveVar *var;
WDataSet *wds;
int i, j;
for ( i = 0; i < wt->ntables; i++) {
wds = g_ptr_array_index(wt->tables, i);
if (wds->nrows > 0 ){
keyval names[wds->numVars-1];
for (j = 1; j < wds->numVars; j++) {
var = (WaveVar *) dataset_get_wavevar(wds, j);
k.index = j;
k.name = wavevar_get_name(var);
names[j-1] = k;
}
qsort(names, wds->numVars-1, sizeof(keyval), &keyval_compare);
for (j = 0 ; j < wds->numVars-1; j++) {
msg_dbg("%d %s %d\n", j, names[j].name, names[j].index);
var = (WaveVar *) dataset_get_wavevar(wds, names[j].index);
(func)(var, p);
}
}
}
}
/*
* find a cooresponding name in new dataset after file reload
* with corresponding table num

View File

@ -233,7 +233,7 @@ void datafile_list_win_empty(DataFile *wdata)
void datafile_list_win_fill(DataFile *wdata)
{
if (wdata->wlist_win) {
wavetable_foreach_wavevar(wdata->wt, datafile_add_list_button,
wavetable_foreach_wavevar_sorted(wdata->wt, datafile_add_list_button,
(gpointer) wdata);
}
}