static gboolean get_selected (void * user, gint row) { g_return_val_if_fail (row >= 0 && row < index_count (user), FALSE); return ((Column *) index_get (user, row))->selected; }
static void set_selected (void * user, gint row, gboolean selected) { g_return_if_fail (row >= 0 && row < index_count (user)); ((Column *) index_get (user, row))->selected = selected; }
static GtkWidget * equalizerwin_create_list_window (Index * preset_list, const gchar *title, GtkWidget **window, GtkSelectionMode sel_mode, GtkWidget **entry, const gchar *action_name, GCallback action_func, GCallback select_row_func) { GtkWidget *vbox, *scrolled_window, *bbox, *view; GtkWidget *button_cancel, *button_action; GtkListStore *store; GtkTreeIter iter; GtkTreeModel *model; GtkCellRenderer *renderer; GtkTreeSelection *selection; GtkTreeSortable *sortable; *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(*window), title); gtk_window_set_type_hint(GTK_WINDOW(*window), GDK_WINDOW_TYPE_HINT_DIALOG); gtk_window_set_default_size(GTK_WINDOW(*window), 350, 300); gtk_window_set_position(GTK_WINDOW(*window), GTK_WIN_POS_CENTER); gtk_container_set_border_width(GTK_CONTAINER(*window), 10); gtk_window_set_transient_for(GTK_WINDOW(*window), GTK_WINDOW(equalizerwin)); g_signal_connect(*window, "destroy", G_CALLBACK(gtk_widget_destroyed), window); vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10); gtk_container_add(GTK_CONTAINER(*window), vbox); scrolled_window = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); /* fill the store with the names of all available presets */ store = gtk_list_store_new(1, G_TYPE_STRING); for (int p = 0; p < index_count (preset_list); p ++) { EqualizerPreset * preset = index_get (preset_list, p); gtk_list_store_append(store, &iter); gtk_list_store_set (store, & iter, 0, preset->name, -1); } model = GTK_TREE_MODEL(store); sortable = GTK_TREE_SORTABLE(store); gtk_tree_sortable_set_sort_column_id(sortable, 0, GTK_SORT_ASCENDING); view = gtk_tree_view_new(); renderer = gtk_cell_renderer_text_new(); gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), -1, _("Presets"), renderer, "text", 0, NULL); gtk_tree_view_set_model(GTK_TREE_VIEW(view), model); g_object_unref(model); selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); gtk_tree_selection_set_mode(selection, sel_mode); gtk_container_add(GTK_CONTAINER(scrolled_window), view); gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0); if (entry) { *entry = gtk_entry_new(); g_signal_connect(*entry, "activate", action_func, NULL); gtk_box_pack_start(GTK_BOX(vbox), *entry, FALSE, FALSE, 0); } bbox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL); gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); gtk_box_set_spacing(GTK_BOX(bbox), 5); gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); button_cancel = gtk_button_new_from_stock(GTK_STOCK_CANCEL); g_signal_connect_swapped (button_cancel, "clicked", (GCallback) gtk_widget_destroy, * window); gtk_box_pack_start(GTK_BOX(bbox), button_cancel, TRUE, TRUE, 0); button_action = gtk_button_new_from_stock(action_name); g_signal_connect(button_action, "clicked", G_CALLBACK(action_func), view); gtk_widget_set_can_default (button_action, TRUE); if (select_row_func) g_signal_connect(view, "row-activated", G_CALLBACK(select_row_func), NULL); gtk_box_pack_start(GTK_BOX(bbox), button_action, TRUE, TRUE, 0); gtk_widget_grab_default(button_action); gtk_widget_show_all(*window); return *window; }
static void get_value (void * user, gint row, gint column, GValue * value) { g_return_if_fail (row >= 0 && row < index_count (user)); Column * c = index_get (user, row); g_value_set_string (value, _(pw_col_names[c->column])); }
static void select_all (void * user, bool_t selected) { int rows = index_count (user); for (int row = 0; row < rows; row ++) ((Column *) index_get (user, row))->selected = selected; }
// Select void bwindow_pick(BWindow self){ static GLuint selectionBuffer[256]; GLuint *ptr, *selection, num_obj, z1,z2,z; GLint hits; int num, i,j; raster_hit =0; current_window = self; draw_status = SELECT; self->event.pos.y = self->height - self->event.pos.y; self->event.dpos.y *=-1; pick_dx = self->event.pos.x - pick_x; pick_dy = self->event.pos.y - pick_y; pick_x = self->event.pos.x; pick_y = self->event.pos.y; // initialize selection buffer glSelectBuffer(256,selectionBuffer); //-------------------------------------------------------------------------------------------- glViewport(0,0,self->width,self->height); current_viewport[0] = 0; current_viewport[1] = 0; current_viewport[2] = self->width; current_viewport[3] = self->height; //-------------------------------------------------------------------------------------------- /* * Hit stack looks like this: * * num_obj (GLuint)- number of objects on stack * z1 (GLuint) - value of closest point in hit * z2 (GLuint) - value of farthest point in hit * first object in hit - this is the id (or in this case pointer) of the first object in hit * . * . * n object in hit - this is the id (or in this case pointer) of the n object in hit */ ptr = selectionBuffer; num_obj = z1 = z2 = z=0; selection=NULL; glRenderMode(GL_SELECT); glInitNames(); // iterate window's items and draw them im_draw( self->items); hits = glRenderMode(GL_RENDER); //number of hit stacks if (hits){ // initialize values for first hit num_obj = num = *ptr++; // number of objects in stack z = z1 = *ptr++; // min depth of hit z2 = *ptr++; // max depth of hit selection = ptr; // selection remembers closest hit // if there is more than one hit selection will be the one with the nearest point for (i = 1; i<hits ; i++){ ptr+=num; // increment ahead to next hit num = *ptr++; z1 = *ptr++; z2 = *ptr++; if (z1 < z){ selection = ptr; z = z1; num_obj=num; } } // num is the number of hits in this stack // j = 0 is the view Layer lay = NULL; Link child = NULL; Binding binding = NULL; view_transform(current_view); for (j = 0 ; j< num_obj ; j++){ child=(Link) index_get(bound_layers, *selection++); lay = child->value.vptr; layer_transform(child->value.vptr); binding = lay->bindings; while(binding){ if( ((binding->event.state & current_window->event.state) == binding->event.state) && (binding->event.key == current_window->event.key)) { callback(child,binding->callback); } binding = binding->next; } } } if (self->update) bwindow_paint(self); }
static void _traverse_paths (GList **pvlist, const char *path) { GList *children, *iter; char *value = NULL; size_t vsize; /* Look for a value - db first */ if (!db_get (path, (unsigned char**)&value, &vsize)) { /* Provide next */ value = provide_get (path); } if (value) { Apteryx__PathValue *pv = NULL; /* Allocate a new pv */ pv = g_malloc0 (sizeof (Apteryx__PathValue)); pv->path = g_strdup (path); pv->value = value; /* Add to the list */ *pvlist = g_list_prepend (*pvlist, pv); } /* Check for children - index first */ char *path_s = g_strdup_printf ("%s/", path); if (!index_get (path_s, &children)) { /* Search database next */ children = db_search (path_s); /* Append any provided paths */ GList *providers = NULL; providers = cb_match (&provide_list, path_s, CB_MATCH_PART); for (iter = providers; iter; iter = g_list_next (iter)) { cb_info_t *provider = iter->data; char *ptr, *ppath; int len = strlen (path_s); if (strcmp (provider->path, path_s) == 0) continue; ppath = g_strdup (provider->path); if ((ptr = strchr (&ppath[len+1], '/')) != 0) *ptr = '\0'; if (!g_list_find_custom (children, ppath, (GCompareFunc) strcmp)) children = g_list_prepend (children, ppath); else g_free (ppath); } g_list_free_full (providers, (GDestroyNotify) cb_release); } for (iter = children; iter; iter = g_list_next (iter)) { _traverse_paths (pvlist, (const char *) iter->data); } g_list_free_full (children, g_free); g_free (path_s); }
static gboolean xspf_playlist_save (const gchar * filename, VFSFile * file, const gchar * title, Index * filenames, Index * tuples) { gint entries = index_count (filenames); xmlDocPtr doc; xmlNodePtr rootnode, tracklist; gint count; doc = xmlNewDoc((xmlChar *)"1.0"); doc->charset = XML_CHAR_ENCODING_UTF8; doc->encoding = xmlStrdup((xmlChar *)"UTF-8"); rootnode = xmlNewNode(NULL, (xmlChar *)XSPF_ROOT_NODE_NAME); xmlSetProp(rootnode, (xmlChar *)"version", (xmlChar *)"1"); xmlSetProp(rootnode, (xmlChar *)"xmlns", (xmlChar *)XSPF_XMLNS); /* common */ xmlDocSetRootElement(doc, rootnode); if (title) xspf_add_node (rootnode, TUPLE_STRING, FALSE, "title", title, 0); tracklist = xmlNewNode(NULL, (xmlChar *)"trackList"); xmlAddChild(rootnode, tracklist); for (count = 0; count < entries; count ++) { const gchar * filename = index_get (filenames, count); const Tuple * tuple = index_get (tuples, count); xmlNodePtr track, location; gchar *scratch = NULL; gint scratchi = 0; track = xmlNewNode(NULL, (xmlChar *)"track"); location = xmlNewNode(NULL, (xmlChar *)"location"); xmlAddChild(location, xmlNewText((xmlChar *)filename)); xmlAddChild(track, location); xmlAddChild(tracklist, track); if (tuple != NULL) { gint i; for (i = 0; i < xspf_nentries; i++) { const xspf_entry_t *xs = &xspf_entries[i]; gboolean isOK = (tuple_get_value_type (tuple, xs->tupleField, NULL) == xs->type); switch (xs->type) { case TUPLE_STRING: scratch = tuple_get_str (tuple, xs->tupleField, NULL); if (! scratch) isOK = FALSE; str_unref(scratch); break; case TUPLE_INT: scratchi = tuple_get_int (tuple, xs->tupleField, NULL); break; default: break; } if (isOK) xspf_add_node(track, xs->type, xs->isMeta, xs->xspfName, scratch, scratchi); } } } xmlSaveCtxt * save = xmlSaveToIO (write_cb, close_cb, file, NULL, XML_SAVE_FORMAT); if (! save) goto ERR; if (xmlSaveDoc (save, doc) < 0 || xmlSaveClose (save) < 0) goto ERR; xmlFreeDoc(doc); return TRUE; ERR: xmlFreeDoc (doc); return FALSE; }
static void start_plugin (LoadedPlugin * loaded) { if (loaded->active) return; loaded->active = 1; PluginData * plugin = loaded->plugin; const LADSPA_Descriptor * desc = plugin->desc; int ports = plugin->in_ports->len; if (ports == 0 || ports != plugin->out_ports->len) { fprintf (stderr, "Plugin has unusable port configuration: %s\n", desc->Name); return; } if (ladspa_channels % ports != 0) { fprintf (stderr, "Plugin cannot be used with %d channels: %s\n", ladspa_channels, desc->Name); return; } int instances = ladspa_channels / ports; loaded->instances = index_new (); loaded->in_bufs = g_malloc (sizeof (float *) * ladspa_channels); loaded->out_bufs = g_malloc (sizeof (float *) * ladspa_channels); for (int i = 0; i < instances; i ++) { LADSPA_Handle handle = desc->instantiate (desc, ladspa_rate); index_append (loaded->instances, handle); int controls = index_count (plugin->controls); for (int c = 0; c < controls; c ++) { ControlData * control = index_get (plugin->controls, c); desc->connect_port (handle, control->port, & loaded->values[c]); } for (int p = 0; p < ports; p ++) { int channel = ports * i + p; float * in = g_malloc (sizeof (float) * LADSPA_BUFLEN); loaded->in_bufs[channel] = in; int in_port = g_array_index (plugin->in_ports, int, p); desc->connect_port (handle, in_port, in); float * out = g_malloc (sizeof (float) * LADSPA_BUFLEN); loaded->out_bufs[channel] = out; int out_port = g_array_index (plugin->out_ports, int, p); desc->connect_port (handle, out_port, out); } if (desc->activate) desc->activate (handle); } }