Sample* sample_get_by_filename(const char* abspath) { struct find_sample { Sample* rv; const char* abspath; }; bool filter_sample (GtkTreeModel* model, GtkTreePath* path, GtkTreeIter* iter, gpointer data) { struct find_sample* fs = (struct find_sample*) data; Sample* s = samplecat_list_store_get_sample_by_iter(iter); if (!strcmp(s->full_path, fs->abspath)) { fs->rv=s; return TRUE; } sample_unref(s); return FALSE; } struct find_sample fs; fs.rv = NULL; fs.abspath = abspath; GtkTreeModel* model = GTK_TREE_MODEL(samplecat.store); gtk_tree_model_foreach(model, &filter_sample, &fs); return fs.rv; }
/** return a reference to the existing sample in the tree. * implies sample_ref() * @return needs to be sample_unref(); */ Sample* samplecat_list_store_get_sample_by_path(GtkTreePath* path) { GtkTreeModel* model = GTK_TREE_MODEL(samplecat.store); GtkTreeIter iter; if(!gtk_tree_model_get_iter(model, &iter, path)) return NULL; Sample* sample = samplecat_list_store_get_sample_by_iter(&iter); if (sample && !sample->row_ref) sample->row_ref = gtk_tree_row_reference_new(GTK_TREE_MODEL(samplecat.store), path); return sample; }
void console__init() { #if 0 // for this to work, we would have to not add blank rows before populating them which is not possible. void store_row_inserted(GtkListStore* store, GtkTreePath* path, GtkTreeIter* iter, gpointer user_data) { PF0; Sample* sample = samplecat_list_store_get_sample_by_iter(iter); if(sample){ console__show_result(sample); sample_unref(sample); } }
AGlActor* list_view(WaveformActor* _) { instance_count++; _init(); bool list_paint(AGlActor* actor) { ListView* view = (ListView*)actor; #define row_height 20 #define N_ROWS_VISIBLE(A) (agl_actor__height(((AGlActor*)A)) / row_height) int n_rows = N_ROWS_VISIBLE(actor); int col[] = {0, 150, 260, 360, 420}; GtkTreeIter iter; if(!gtk_tree_model_get_iter_first((GtkTreeModel*)samplecat.store, &iter)){ gerr ("cannot get iter."); return false; } int i = 0; for(;i<view->scroll_offset;i++){ gtk_tree_model_iter_next((GtkTreeModel*)samplecat.store, &iter); } int row_count = 0; do { if(row_count == view->selection - view->scroll_offset){ agl->shaders.plain->uniform.colour = 0x6677ff77; agl_use_program((AGlShader*)agl->shaders.plain); agl_rect_((AGlRect){0, row_count * row_height - 2, agl_actor__width(actor), row_height}); } Sample* sample = samplecat_list_store_get_sample_by_iter(&iter); if(sample){ char* len[32]; format_smpte((char*)len, sample->frames); char* f[32]; samplerate_format((char*)f, sample->sample_rate); char* val[4] = {sample->name, sample->sample_dir, (char*)len, (char*)f}; int c; for(c=0;c<G_N_ELEMENTS(val);c++){ agl_enable_stencil(0, 0, col[c + 1] - 6, actor->region.y2); agl_print(col[c], row_count * row_height, 0, 0xffffffff, val[c]); } sample_unref(sample); } } while (++row_count < n_rows && gtk_tree_model_iter_next((GtkTreeModel*)samplecat.store, &iter)); agl_disable_stencil(); return true; }
void store_content_changed(GtkListStore* store, gpointer data) { PF; GtkTreeIter iter; if(!gtk_tree_model_get_iter_first((GtkTreeModel*)store, &iter)){ gerr ("cannot get iter."); return; } int row_count = 0; do { if(++row_count < 100){ Sample* sample = samplecat_list_store_get_sample_by_iter(&iter); if(sample){ console__show_result(sample); sample_unref(sample); } } } while (gtk_tree_model_iter_next((GtkTreeModel*)store, &iter)); console__show_result_footer(row_count); }
static bool listview_item_set_colour(GtkTreePath* path, unsigned colour_index) { g_return_val_if_fail(path, false); GtkTreeIter iter; gtk_tree_model_get_iter(GTK_TREE_MODEL(samplecat.store), &iter, path); bool ok; Sample* s = samplecat_list_store_get_sample_by_iter(&iter); if((ok = samplecat_model_update_sample (samplecat.model, s, COL_COLOUR, (void*)&colour_index))){ statusbar_print(1, "colour updated"); }else{ statusbar_print(1, "error! colour not updated"); } sample_unref(s); return ok; }