Пример #1
0
static void save_enabled_to_config (void)
{
    int count = index_count (loadeds);
    aud_set_int ("ladspa", "plugin_count", count);

    for (int i = 0; i < count; i ++)
    {
        LoadedPlugin * loaded = index_get (loadeds, 0);
        char key[32];

        snprintf (key, sizeof key, "plugin%d_path", i);
        aud_set_string ("ladspa", key, loaded->plugin->path);

        snprintf (key, sizeof key, "plugin%d_label", i);
        aud_set_string ("ladspa", key, loaded->plugin->desc->Label);

        int ccount = index_count (loaded->plugin->controls);
        for (int ci = 0; ci < ccount; ci ++)
        {
            snprintf (key, sizeof key, "plugin%d_control%d", i, ci);
            aud_set_double ("ladspa", key, loaded->values[ci]);
        }

        disable_plugin_locked (0);
    }
}
Пример #2
0
static void search_cb (void * key, void * _item, void * _state)
{
    Item * item = _item;
    SearchState * state = _state;

    if (index_count (state->items[item->field]) > MAX_RESULTS)
        return;

    int oldmask = state->mask;
    int count = index_count (search_terms);

    for (int t = 0, bit = 1; t < count; t ++, bit <<= 1)
    {
        if (! (state->mask & bit))
            continue; /* skip term if it is already found */

        if (strstr (item->folded, index_get (search_terms, t)))
            state->mask &= ~bit; /* we found it */
        else if (! item->children)
            break; /* quit early if there are no children to search */
    }

    if (! state->mask)
        index_insert (state->items[item->field], -1, item);

    if (item->children)
        g_hash_table_foreach (item->children, search_cb, state);

    state->mask = oldmask;
}
Пример #3
0
static void close_modules (void)
{
    int count = index_count (plugins);
    for (int i = 0; i < count; i ++)
        close_plugin (index_get (plugins, i));

    index_delete (plugins, 0, count);

    count = index_count (modules);
    for (int i = 0; i < count; i ++)
        g_module_close (index_get (modules, i));

    index_delete (modules, 0, count);
}
Пример #4
0
void pw_col_init (void)
{
    pw_num_cols = 0;

    char * columns = aud_get_str ("gtkui", "playlist_columns");
    Index * index = str_list_to_index (columns, " ");

    int count = index_count (index);
    if (count > PW_COLS)
        count = PW_COLS;

    for (int c = 0; c < count; c ++)
    {
        char * column = index_get (index, c);

        int i = 0;
        while (i < PW_COLS && strcmp (column, pw_col_keys[i]))
            i ++;

        if (i == PW_COLS)
            break;

        pw_cols[pw_num_cols ++] = i;
    }

    index_free_full (index, (IndexFreeFunc) str_unref);
    str_unref (columns);
}
Пример #5
0
static void free_presets (Index * presets)
{
    for (int p = 0; p < index_count (presets); p ++)
        equalizer_preset_free (index_get (presets, p));

    index_free (presets);
}
Пример #6
0
static bool_t search_cb (GtkTreeModel * model, int column, const char * key,
 GtkTreeIter * iter, void * user)
{
    GtkTreePath * path = gtk_tree_model_get_path (model, iter);
    g_return_val_if_fail (path, TRUE);
    int row = gtk_tree_path_get_indices (path)[0];
    gtk_tree_path_free (path);

    char * title = aud_playlist_get_title (row);
    g_return_val_if_fail (title, TRUE);

    Index * keys = str_list_to_index (key, " ");
    int count = index_count (keys);

    bool_t match = FALSE;

    for (int i = 0; i < count; i ++)
    {
        if (strstr_nocase_utf8 (title, index_get (keys, i)))
            match = TRUE;
        else
        {
            match = FALSE;
            break;
        }
    }

    index_free_full (keys, (IndexFreeFunc) str_unref);
    str_unref (title);

    return ! match; /* TRUE == not matched, FALSE == matched */
}
Пример #7
0
void shutdown_plugin_locked (LoadedPlugin * loaded)
{
    loaded->active = 0;

    if (! loaded->instances)
        return;

    PluginData * plugin = loaded->plugin;
    const LADSPA_Descriptor * desc = plugin->desc;

    int instances = index_count (loaded->instances);
    for (int i = 0; i < instances; i ++)
    {
        LADSPA_Handle * handle = index_get (loaded->instances, i);

        if (desc->deactivate)
            desc->deactivate (handle);

        desc->cleanup (handle);
    }

    for (int channel = 0; channel < ladspa_channels; channel ++)
    {
        g_free (loaded->in_bufs[channel]);
        g_free (loaded->out_bufs[channel]);
    }

    index_free (loaded->instances);
    loaded->instances = NULL;
    g_free (loaded->in_bufs);
    loaded->in_bufs = NULL;
    g_free (loaded->out_bufs);
    loaded->out_bufs = NULL;
}
Пример #8
0
static void list_get_value (void * user, int row, int column, GValue * value)
{
    g_return_if_fail (items && row >= 0 && row < index_count (items));

    Item * item = index_get (items, row);
    char * string = NULL;

    switch (item->field)
    {
        int albums;
        char scratch[128];

    case TITLE:
        string = g_strdup_printf (_("%s\n on %s by %s"), item->name,
         item->parent->name, item->parent->parent->name);
        break;

    case ARTIST:
        albums = g_hash_table_size (item->children);
        snprintf (scratch, sizeof scratch, dngettext (PACKAGE, "%d album",
         "%d albums", albums), albums);
        string = g_strdup_printf (dngettext (PACKAGE, "%s\n %s, %d song",
         "%s\n %s, %d songs", item->matches->len), item->name, scratch,
         item->matches->len);
        break;

    case ALBUM:
        string = g_strdup_printf (dngettext (PACKAGE, "%s\n %d song by %s",
         "%s\n %d songs by %s", item->matches->len), item->name,
         item->matches->len, item->parent->name);
        break;
    }

    g_value_take_string (value, string);
}
Пример #9
0
static void do_add (bool_t play, char * * title)
{
    int list = aud_playlist_by_unique_id (playlist_id);
    int n_items = index_count (items);
    int n_selected = 0;

    Index * filenames = index_new ();
    Index * tuples = index_new ();

    for (int i = 0; i < n_items; i ++)
    {
        if (! selection->data[i])
            continue;

        Item * item = index_get (items, i);

        for (int m = 0; m < item->matches->len; m ++)
        {
            int entry = g_array_index (item->matches, int, m);
            index_insert (filenames, -1, aud_playlist_entry_get_filename (list, entry));
            index_insert (tuples, -1, aud_playlist_entry_get_tuple (list, entry, TRUE));
        }

        n_selected ++;
        if (title && n_selected == 1)
            * title = item->name;
    }

    if (title && n_selected != 1)
        * title = NULL;

    aud_playlist_entry_insert_batch (aud_playlist_get_active (), -1, filenames,
     tuples, play);
}
Пример #10
0
static int get_selected (void * user, int row)
{
    g_return_val_if_fail (row >= 0 && row < index_count (plugins), 0);

    PluginData * plugin = index_get (plugins, row);
    return plugin->selected;
}
Пример #11
0
LoadedPlugin * enable_plugin_locked (PluginData * plugin)
{
    LoadedPlugin * loaded = g_slice_new (LoadedPlugin);
    loaded->plugin = plugin;
    loaded->selected = 0;

    int count = index_count (plugin->controls);
    loaded->values = g_malloc (sizeof (float) * count);

    for (int i = 0; i < count; i ++)
    {
        ControlData * control = index_get (plugin->controls, i);
        loaded->values[i] = control->def;
    }

    loaded->active = 0;
    loaded->instances = NULL;
    loaded->in_bufs = NULL;
    loaded->out_bufs = NULL;

    loaded->settings_win = NULL;

    index_append (loadeds, loaded);
    return loaded;
}
Пример #12
0
GtkWidget * create_plugin_list (void)
{
    GtkWidget * list = mlpgui_list_new (& callbacks, NULL, index_count (plugins));
    mlpgui_list_add_column (list, NULL, 0, G_TYPE_STRING, -1);
    gtk_tree_view_set_headers_visible ((GtkTreeView *) list, 0);
    return list;
}
Пример #13
0
static void load_enabled_from_config (void)
{
    int count = aud_get_int ("ladspa", "plugin_count");

    for (int i = 0; i < count; i ++)
    {
        char key[32];

        snprintf (key, sizeof key, "plugin%d_path", i);
        char * path = aud_get_string ("ladspa", key);

        snprintf (key, sizeof key, "plugin%d_label", i);
        char * label = aud_get_string ("ladspa", key);

        PluginData * plugin = find_plugin (path, label);
        if (plugin)
        {
            LoadedPlugin * loaded = enable_plugin_locked (plugin);

            int ccount = index_count (loaded->plugin->controls);
            for (int ci = 0; ci < ccount; ci ++)
            {
                snprintf (key, sizeof key, "plugin%d_control%d", i, ci);
                loaded->values[ci] = aud_get_double ("ladspa", key);
            }
        }

        g_free (path);
        g_free (label);
    }
}
Пример #14
0
static void
equalizerwin_read_winamp_eqf(VFSFile * file)
{
    Index * presets = aud_import_winamp_presets (file);

    if (! presets)
    {
        SPRINTF (error, _("Error importing Winamp EQF file '%s'"), vfs_get_filename (file));
        aud_interface_show_error (error);
        return;
    }

    if (! index_count (presets))
        goto DONE;

    /* just get the first preset --asphyx */
    EqualizerPreset * preset = index_get (presets, 0);
    equalizerwin_set_preamp(preset->preamp);

    for (int i = 0; i < AUD_EQUALIZER_NBANDS; i ++)
        equalizerwin_set_band(i, preset->bands[i]);

    equalizerwin_eq_changed();

DONE:
    index_free_full (presets, (IndexFreeFunc) aud_equalizer_preset_free);
}
Пример #15
0
static void set_selected (void * user, int row, int selected)
{
    g_return_if_fail (row >= 0 && row < index_count (plugins));

    PluginData * plugin = index_get (plugins, row);
    plugin->selected = selected;
}
Пример #16
0
static bool_t audpl_save (const char * path, VFSFile * file,
 const char * title, Index * filenames, Index * tuples)
{
    if (! write_key (file, "title", title))
        return FALSE;

    int count = index_count (filenames);

    for (int i = 0; i < count; i ++)
    {
        if (! write_key (file, "uri", index_get (filenames, i)))
            return FALSE;

        const Tuple * tuple = tuples ? index_get (tuples, i) : NULL;

        if (tuple)
        {
            int keys = 0;

            for (int f = 0; f < TUPLE_FIELDS; f ++)
            {
                if (f == FIELD_FILE_PATH || f == FIELD_FILE_NAME || f == FIELD_FILE_EXT)
                    continue;

                TupleValueType type = tuple_get_value_type (tuple, f, NULL);

                if (type == TUPLE_STRING)
                {
                    char * str = tuple_get_str (tuple, f, NULL);

                    if (! write_key (file, tuple_field_get_name (f), str))
                    {
                        str_unref (str);
                        return FALSE;
                    }

                    str_unref (str);
                    keys ++;
                }
                else if (type == TUPLE_INT)
                {
                    char buf[32];
                    snprintf (buf, sizeof buf, "%d", tuple_get_int (tuple, f, NULL));

                    if (! write_key (file, tuple_field_get_name (f), buf))
                        return FALSE;

                    keys ++;
                }
            }

            /* distinguish between an empty tuple and no tuple at all */
            if (! keys && ! write_key (file, "empty", "1"))
                return FALSE;
        }
    }

    return TRUE;
}
Пример #17
0
static void save_enabled_to_config (void)
{
    int count = index_count (loadeds);
    int old_count = aud_get_int ("ladspa", "plugin_count");
    aud_set_int ("ladspa", "plugin_count", count);

    for (int i = 0; i < count; i ++)
    {
        LoadedPlugin * loaded = index_get (loadeds, 0);
        char key[32];

        snprintf (key, sizeof key, "plugin%d_path", i);
        aud_set_str ("ladspa", key, loaded->plugin->path);

        snprintf (key, sizeof key, "plugin%d_label", i);
        aud_set_str ("ladspa", key, loaded->plugin->desc->Label);

        snprintf (key, sizeof key, "plugin%d_controls", i);

        int ccount = index_count (loaded->plugin->controls);
        double temp[ccount];

        for (int ci = 0; ci < ccount; ci ++)
            temp[ci] = loaded->values[ci];

        char * controls = double_array_to_str (temp, ccount);
        aud_set_str ("ladspa", key, controls);
        str_unref (controls);

        disable_plugin_locked (0);
    }

    for (int i = count; i < old_count; i ++)
    {
        char key[32];

        snprintf (key, sizeof key, "plugin%d_path", i);
        aud_set_str ("ladspa", key, "");

        snprintf (key, sizeof key, "plugin%d_label", i);
        aud_set_str ("ladspa", key, "");

        snprintf (key, sizeof key, "plugin%d_controls", i);
        aud_set_str ("ladspa", key, "");
    }
}
Пример #18
0
static void get_value (void * user, int row, int column, GValue * value)
{
    g_return_if_fail (row >= 0 && row < index_count (plugins));
    g_return_if_fail (column == 0);

    PluginData * plugin = index_get (plugins, row);
    g_value_set_string (value, plugin->desc->Name);
}
Пример #19
0
static void destroy_cb (void)
{
    window = NULL;
    chosen_list = NULL;
    avail_list = NULL;

    gint rows = index_count (chosen);
    for (gint row = 0; row < rows; row ++)
        g_slice_free (Column, index_get (chosen, row));
    index_free (chosen);
    chosen = NULL;

    rows = index_count (avail);
    for (gint row = 0; row < rows; row ++)
        g_slice_free (Column, index_get (avail, row));
    index_free (avail);
    avail = NULL;
}
Пример #20
0
static void select_all (void * user, int selected)
{
    int count = index_count (plugins);
    for (int i = 0; i < count; i ++)
    {
        PluginData * plugin = index_get (plugins, i);
        plugin->selected = selected;
    }
}
Пример #21
0
static bool_t playlist_save_m3u (const char * path, VFSFile * file,
 const char * title, Index * filenames, Index * tuples)
{
    int count = index_count (filenames);

    for (int i = 0; i < count; i ++)
        vfs_fprintf (file, "%s\n", (const char *) index_get (filenames, i));

    return TRUE;
}
Пример #22
0
static void configure_plugin (LoadedPlugin * loaded)
{
    if (loaded->settings_win)
    {
        gtk_window_present ((GtkWindow *) loaded->settings_win);
        return;
    }

    PluginData * plugin = loaded->plugin;
    char buf[200];

    snprintf (buf, sizeof buf, _("%s Settings"), plugin->desc->Name);
    loaded->settings_win = gtk_dialog_new_with_buttons (buf, (GtkWindow *)
     config_win, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CLOSE,
     GTK_RESPONSE_CLOSE, NULL);
    gtk_window_set_resizable ((GtkWindow *) loaded->settings_win, 0);

    GtkWidget * vbox = gtk_dialog_get_content_area ((GtkDialog *) loaded->settings_win);

    int count = index_count (plugin->controls);
    for (int i = 0; i < count; i ++)
    {
        ControlData * control = index_get (plugin->controls, i);

        GtkWidget * hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
        gtk_box_pack_start ((GtkBox *) vbox, hbox, 0, 0, 0);

        if (control->is_toggle)
        {
            GtkWidget * toggle = gtk_check_button_new_with_label (control->name);
            gtk_toggle_button_set_active ((GtkToggleButton *) toggle, (loaded->values[i] > 0) ? 1 : 0);
            gtk_box_pack_start ((GtkBox *) hbox, toggle, 0, 0, 0);

            g_signal_connect (toggle, "toggled", (GCallback) control_toggled, & loaded->values[i]);
        }
        else
        {
            snprintf (buf, sizeof buf, "%s:", control->name);
            GtkWidget * label = gtk_label_new (buf);
            gtk_box_pack_start ((GtkBox *) hbox, label, 0, 0, 0);

            GtkWidget * spin = gtk_spin_button_new_with_range (control->min, control->max, 0.01);
            gtk_spin_button_set_value ((GtkSpinButton *) spin, loaded->values[i]);
            gtk_box_pack_start ((GtkBox *) hbox, spin, 0, 0, 0);

            g_signal_connect (spin, "value-changed", (GCallback) control_changed, & loaded->values[i]);
        }
    }

    g_signal_connect (loaded->settings_win, "response", (GCallback) gtk_widget_destroy, NULL);
    g_signal_connect (loaded->settings_win, "destroy", (GCallback)
     gtk_widget_destroyed, & loaded->settings_win);

    gtk_widget_show_all (loaded->settings_win);
}
Пример #23
0
static void run_plugin (LoadedPlugin * loaded, float * data, int samples)
{
    if (! loaded->instances)
        return;

    PluginData * plugin = loaded->plugin;
    const LADSPA_Descriptor * desc = plugin->desc;

    int ports = plugin->in_ports->len;
    int instances = index_count (loaded->instances);
    assert (ports * instances == ladspa_channels);

    while (samples / ladspa_channels > 0)
    {
        int frames = MIN (samples / ladspa_channels, LADSPA_BUFLEN);

        for (int i = 0; i < instances; i ++)
        {
            LADSPA_Handle * handle = index_get (loaded->instances, i);

            for (int p = 0; p < ports; p ++)
            {
                int channel = ports * i + p;
                float * get = data + channel;
                float * in = loaded->in_bufs[channel];
                float * in_end = in + frames;

                while (in < in_end)
                {
                    * in ++ = * get;
                    get += ladspa_channels;
                }
            }

            desc->run (handle, frames);

            for (int p = 0; p < ports; p ++)
            {
                int channel = ports * i + p;
                float * set = data + channel;
                float * out = loaded->out_bufs[channel];
                float * out_end = out + frames;

                while (out < out_end)
                {
                    * set = * out ++;
                    set += ladspa_channels;
                }
            }
        }

        data += ladspa_channels * frames;
        samples -= ladspa_channels * frames;
    }
}
Пример #24
0
bool_t playlist_load (const char * filename, char * * title,
 Index * * filenames_p, Index * * tuples_p)
{
    AUDDBG ("Loading playlist %s.\n", filename);

    PluginHandle * plugin = get_plugin (filename, FALSE);
    if (! plugin)
        return FALSE;

    PlaylistPlugin * pp = plugin_get_header (plugin);
    g_return_val_if_fail (pp && PLUGIN_HAS_FUNC (pp, load), FALSE);

    VFSFile * file = vfs_fopen (filename, "r");
    if (! file)
        return FALSE;

    Index * filenames = index_new ();
    Index * tuples = index_new ();
    bool_t success = pp->load (filename, file, title, filenames, tuples);

    vfs_fclose (file);

    if (! success)
    {
        index_free (filenames);
        index_free (tuples);
        return FALSE;
    }

    if (index_count (tuples))
        g_return_val_if_fail (index_count (tuples) == index_count (filenames),
         FALSE);
    else
    {
        index_free (tuples);
        tuples = NULL;
    }

    * filenames_p = filenames;
    * tuples_p = tuples;
    return TRUE;
}
Пример #25
0
static void destroy_database (void)
{
    if (items)
        index_delete (items, 0, index_count (items));

    if (database)
    {
        g_hash_table_destroy (database);
        database = NULL;
    }
}
Пример #26
0
bool index_read_all(std::vector<index_data> *data, int idxfd, int logfd) {
	const auto size = index_count(idxfd);
	data->resize(size);

	for ( auto it = data->begin(); it != data->end(); ++it ) {
		if ( !index_read_data(&(*it), std::distance(data->begin(), it), idxfd, logfd) )
			return false;
	}

	return true;
}
Пример #27
0
static int equalizerwin_find_preset (Index * list, const char * name)
{
    for (int p = 0; p < index_count (list); p ++)
    {
        EqualizerPreset * preset = index_get (list, p);
        if (!g_ascii_strcasecmp(preset->name, name))
            return p;
    }

    return -1;
}
Пример #28
0
static void shift_rows (void * user, gint row, gint before)
{
    gint rows = index_count (user);
    g_return_if_fail (row >= 0 && row < rows);
    g_return_if_fail (before >= 0 && before <= rows);

    if (before == row)
        return;

    Index * move = index_new ();
    Index * others = index_new ();

    gint begin, end;
    if (before < row)
    {
        begin = before;
        end = row + 1;
        while (end < rows && ((Column *) index_get (user, end))->selected)
            end ++;
    }
    else
    {
        begin = row;
        while (begin > 0 && ((Column *) index_get (user, begin - 1))->selected)
            begin --;
        end = before;
    }

    for (gint i = begin; i < end; i ++)
    {
        Column * c = index_get (user, i);
        index_append (c->selected ? move : others, c);
    }

    if (before < row)
    {
        index_merge_append (move, others);
        index_free (others);
    }
    else
    {
        index_merge_append (others, move);
        index_free (move);
        move = others;
    }

    index_copy_set (move, 0, user, begin, end - begin);
    index_free (move);

    GtkWidget * list = (user == chosen) ? chosen_list : avail_list;
    audgui_list_update_rows (list, begin, end - begin);
    audgui_list_update_selection (list, begin, end - begin);
}
Пример #29
0
static PluginData * find_plugin (const char * path, const char * label)
{
    int count = index_count (plugins);
    for (int i = 0; i < count; i ++)
    {
        PluginData * plugin = index_get (plugins, i);
        if (! strcmp (plugin->path, path) && ! strcmp (plugin->desc->Label, label))
            return plugin;
    }

    return NULL;
}
Пример #30
0
static void do_search (void)
{
    index_delete (items, 0, index_count (items));

    if (! database)
        return;

    SearchState state;

    for (int f = 0; f < FIELDS; f ++)
        state.items[f] = index_new ();

    /* effectively limits number of search terms to 32 */
    state.mask = (1 << index_count (search_terms)) - 1;

    g_hash_table_foreach (database, search_cb, & state);

    int total = 0;

    for (int f = 0; f < FIELDS; f ++)
    {
        int count = index_count (state.items[f]);
        if (count > MAX_RESULTS - total)
            count = MAX_RESULTS - total;

        if (count)
        {
            index_sort (state.items[f], item_compare);
            index_copy_insert (state.items[f], 0, items, -1, count);
            total += count;
        }

        index_free (state.items[f]);
    }

    g_array_set_size (selection, total);
    memset (selection->data, 0, selection->len);
    if (selection->len > 0)
        selection->data[0] = 1;
}