Logo Search packages:      
Sourcecode: calf version File versions  Download package


/* Calf DSP Library
 * Preset management
 * Copyright (C) 2007 Krzysztof Foltman
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General
 * Public License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
#ifndef __CALF_PRESET_H
#define __CALF_PRESET_H

#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <ostream>
#include <string.h>
#include "utils.h"

namespace calf_plugins {

class plugin_ctl_iface;
/// Contents of single preset
00037 struct plugin_preset
    /// Bank the preset belongs to (not used yet)
00040     int bank;
    /// Program number of the preset (not used yet)
00042     int program;
    /// Name of the preset
00044     std::string name;
    /// Name of the plugin the preset is for
00046     std::string plugin;
    /// Names of parameters in values array (for each item in param_names there should be a counterpart in values)
00048     std::vector<std::string> param_names;
    /// Values of parameters
00050     std::vector<float> values;
    /// DSSI configure-style variables
00052     std::map<std::string, std::string> variables;

    plugin_preset() : bank(0), program(0) {}
    /// Export preset as XML
    std::string to_xml();   
    /// "Upload" preset content to the plugin
    void activate(plugin_ctl_iface *plugin);
    /// "Download" preset content from the plugin
    void get_from(plugin_ctl_iface *plugin);

/// Exception thrown by preset system
00064 struct preset_exception
    std::string message, param, fulltext;
    int error;
    preset_exception(const std::string &_message, const std::string &_param, int _error)
    : message(_message), param(_param), error(_error)
    const char *what() {
        if (error)
            fulltext = message + " " + param + " (" + strerror(error) + ")";
            fulltext = message + " " + param;
        return fulltext.c_str();

/// A vector of presets
typedef std::vector<plugin_preset> preset_vector;

/// A single list of presets (usually there are two - @see get_builtin_presets(), get_user_presets() )
00088 struct preset_list
    /// Parser states
00091     enum parser_state
00093         START, ///< Beginning of parsing process (before root element)
00094         LIST, ///< Inside root element
00095         PRESET, ///< Inside preset definition
00096         VALUE, ///< Inside (empty) param tag
00097         VAR, ///< Inside (non-empty) var tag
    } state;

    /// Contained presets (usually for all plugins)
00101     preset_vector presets;
    /// Temporary preset used during parsing process
00103     plugin_preset parser_preset;
    /// Preset number counters for DSSI (currently broken)
00105     std::map<std::string, int> last_preset_ids;
    /// The key used in current <var name="key"> tag (for state == VAR)
00107     std::string current_key;

    /// Return the name of the built-in or user-defined preset file
    static std::string get_preset_filename(bool builtin);
    /// Load default preset list (built-in or user-defined)
    bool load_defaults(bool builtin);
    void parse(const std::string &data);
    /// Load preset list from XML file
    void load(const char *filename);
    /// Save preset list as XML file
    void save(const char *filename);
    /// Append or replace a preset (replaces a preset with the same plugin and preset name)
    void add(const plugin_preset &sp);
    /// Get a sublist of presets for a given plugin (those with plugin_preset::plugin == plugin)
    void get_for_plugin(preset_vector &vec, const char *plugin);
    /// Internal function: start element handler for expat
    static void xml_start_element_handler(void *user_data, const char *name, const char *attrs[]);
    /// Internal function: end element handler for expat
    static void xml_end_element_handler(void *user_data, const char *name);
    /// Internal function: character data (tag text content) handler for expat
    static void xml_character_data_handler(void *user_data, const char *data, int len);

/// Return the current list of built-in (factory) presets (these are loaded from system-wide file)
extern preset_list &get_builtin_presets();

/// Return the current list of user-defined presets (these are loaded from ~/.calfpresets)
extern preset_list &get_user_presets();



Generated by  Doxygen 1.6.0   Back to index