[SCM] calf/master: + JACK host: implement file open functionality
js at users.alioth.debian.org
js at users.alioth.debian.org
Tue May 7 15:39:55 UTC 2013
The following commit has been merged in the master branch:
commit 5fe5416e1b8f1152350ebb2c8ff2bdbbaec57526
Author: Krzysztof Foltman <wdev at foltman.com>
Date: Fri Jan 1 02:37:46 2010 +0000
+ JACK host: implement file open functionality
diff --git a/src/calf/gui.h b/src/calf/gui.h
index 1d25bab..fc834ca 100644
--- a/src/calf/gui.h
+++ b/src/calf/gui.h
@@ -161,8 +161,8 @@ class main_window_owner_iface
public:
virtual void new_plugin(const char *name) = 0;
virtual void remove_plugin(plugin_ctl_iface *plugin) = 0;
- virtual const char *open_file(const char *name) = 0;
- virtual const char *save_file(const char *name) = 0;
+ virtual char *open_file(const char *name) = 0;
+ virtual char *save_file(const char *name) = 0;
virtual ~main_window_owner_iface() {}
};
diff --git a/src/calf/preset.h b/src/calf/preset.h
index c6a6ec4..c74a8fe 100644
--- a/src/calf/preset.h
+++ b/src/calf/preset.h
@@ -89,6 +89,26 @@ typedef std::vector<plugin_preset> preset_vector;
/// A single list of presets (usually there are two - @see get_builtin_presets(), get_user_presets() )
struct preset_list
{
+ /// Plugin list item
+ struct plugin_snapshot
+ {
+ /// Preset offset
+ int preset_offset;
+ /// Plugin type
+ std::string type;
+ /// Instance name
+ std::string instance_name;
+ /// Index of the first input port
+ int input_index;
+ /// Index of the first output port
+ int output_index;
+ /// Index of the first MIDI port
+ int midi_index;
+
+ /// Reset to initial values
+ void reset();
+ };
+
/// Parser states
enum parser_state
{
@@ -97,24 +117,33 @@ struct preset_list
PRESET, ///< Inside preset definition
VALUE, ///< Inside (empty) param tag
VAR, ///< Inside (non-empty) var tag
+ PLUGIN, ///< Inside plugin element (calfjackhost snapshots only)
+ RACK, ///< Inside rack element (calfjackhost snapshots only)
} state;
/// Contained presets (usually for all plugins)
preset_vector presets;
/// Temporary preset used during parsing process
plugin_preset parser_preset;
+ /// Temporary plugin desc used during parsing process
+ plugin_snapshot parser_plugin;
/// Preset number counters for DSSI (currently broken)
std::map<std::string, int> last_preset_ids;
/// The key used in current <var name="key"> tag (for state == VAR)
std::string current_key;
+ /// The file is loaded in rack mode (and rack/plugin elements are expected)
+ bool rack_mode;
+ /// List of plugin states for rack mode
+ std::vector<plugin_snapshot> plugins;
/// 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 an in-memory XML string
+ void parse(const std::string &data, bool in_rack_mode);
/// Load preset list from XML file
- void load(const char *filename);
+ void load(const char *filename, bool in_rack_mode);
/// 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)
diff --git a/src/jackhost.cpp b/src/jackhost.cpp
index 30f84e8..d529710 100644
--- a/src/jackhost.cpp
+++ b/src/jackhost.cpp
@@ -234,9 +234,9 @@ struct host_session: public main_window_owner_iface, public calf_plugins::progre
void report_progress(float percentage, const std::string &message);
/// Implementation of open file functionality (TODO)
- virtual const char *open_file(const char *name) { return "Not implemented yet"; }
+ virtual char *open_file(const char *name);
/// Implementation of save file functionality
- virtual const char *save_file(const char *name);
+ virtual char *save_file(const char *name);
};
host_session::host_session()
@@ -523,7 +523,39 @@ static string stripfmt(string x)
return x.substr(0, x.length() - 2);
}
-const char *host_session::save_file(const char *name)
+char *host_session::open_file(const char *name)
+{
+ preset_list pl;
+ try {
+ remove_all_plugins();
+ pl.load(name, true);
+ printf("Size %d\n", pl.plugins.size());
+ for (unsigned int i = 0; i < pl.plugins.size(); i++)
+ {
+ preset_list::plugin_snapshot &ps = pl.plugins[i];
+ client.input_nr = ps.input_index;
+ client.output_nr = ps.output_index;
+ client.midi_nr = ps.midi_index;
+ printf("Loading %s\n", ps.type.c_str());
+ if (ps.preset_offset < (int)pl.presets.size())
+ {
+ add_plugin(ps.type, "", ps.instance_name);
+ pl.presets[ps.preset_offset].activate(plugins[i]);
+ main_win->refresh_plugin(plugins[i]);
+ }
+ }
+ }
+ catch(preset_exception &e)
+ {
+ // XXXKF this will leak
+ char *data = strdup(e.what());
+ return data;
+ }
+
+ return NULL;
+}
+
+char *host_session::save_file(const char *name)
{
string i_name = stripfmt(client.input_name);
string o_name = stripfmt(client.output_name);
@@ -555,10 +587,10 @@ const char *host_session::save_file(const char *name)
{
int e = errno;
fclose(f);
- return strerror(e);
+ return strdup(strerror(e));
}
if (fclose(f))
- return strerror(errno);
+ return strdup(strerror(errno));
return NULL;
}
@@ -744,7 +776,7 @@ bool load_data_set_cb(lash_config_handle_t *handle, void *user_data)
if (dict.count("output_name")) sess->client.output_nr = atoi(dict["output_name"].c_str());
if (dict.count("midi_name")) sess->client.midi_nr = atoi(dict["midi_name"].c_str());
preset_list tmp;
- tmp.parse("<presets>"+data+"</presets>");
+ tmp.parse("<presets>"+data+"</presets>", false);
if (tmp.presets.size())
{
printf("Load plugin %s\n", tmp.presets[0].plugin.c_str());
diff --git a/src/main_win.cpp b/src/main_win.cpp
index 3668e01..e420c3c 100644
--- a/src/main_win.cpp
+++ b/src/main_win.cpp
@@ -576,12 +576,13 @@ void main_window::open_file()
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
{
char *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
- const char *error = owner->open_file(filename);
+ char *error = owner->open_file(filename);
if (error)
display_error(error, filename);
else
current_filename = filename;
g_free (filename);
+ free (error);
}
gtk_widget_destroy (dialog);
}
@@ -609,12 +610,13 @@ void main_window::save_file_as()
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
{
char *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
- const char *error = owner->save_file(filename);
+ char *error = owner->save_file(filename);
if (error)
display_error(error, filename);
else
current_filename = filename;
g_free (filename);
+ free(error);
}
gtk_widget_destroy (dialog);
}
diff --git a/src/preset.cpp b/src/preset.cpp
index b8eea01..3573591 100644
--- a/src/preset.cpp
+++ b/src/preset.cpp
@@ -141,19 +141,52 @@ string calf_plugins::preset_list::get_preset_filename(bool builtin)
}
}
+void preset_list::plugin_snapshot::reset()
+{
+ type.clear();
+ instance_name.clear();
+ preset_offset = input_index = output_index = midi_index = 0;
+
+}
+
void preset_list::xml_start_element_handler(void *user_data, const char *name, const char *attrs[])
{
preset_list &self = *(preset_list *)user_data;
+ bool rack_mode = self.rack_mode;
parser_state &state = self.state;
plugin_preset &parser_preset = self.parser_preset;
switch(state)
{
case START:
- if (!strcmp(name, "presets")) {
+ if (!rack_mode && !strcmp(name, "presets")) {
state = LIST;
return;
}
+ if (rack_mode && !strcmp(name, "rack")) {
+ state = RACK;
+ return;
+ }
+ break;
+ case RACK:
+ if (!strcmp(name, "plugin")) {
+ self.parser_plugin.reset();
+ self.parser_plugin.preset_offset = self.presets.size();
+ for(; *attrs; attrs += 2) {
+ if (!strcmp(attrs[0], "type")) self.parser_plugin.type = attrs[1];
+ else
+ if (!strcmp(attrs[0], "instance-name")) self.parser_plugin.instance_name = attrs[1];
+ else
+ if (!strcmp(attrs[0], "input-index")) self.parser_plugin.input_index = atoi(attrs[1]);
+ else
+ if (!strcmp(attrs[0], "output-index")) self.parser_plugin.output_index = atoi(attrs[1]);
+ else
+ if (!strcmp(attrs[0], "midi-index")) self.parser_plugin.midi_index = atoi(attrs[1]);
+ }
+ state = PLUGIN;
+ return;
+ }
break;
+ case PLUGIN:
case LIST:
if (!strcmp(name, "preset")) {
@@ -221,6 +254,7 @@ void preset_list::xml_start_element_handler(void *user_data, const char *name, c
void preset_list::xml_end_element_handler(void *user_data, const char *name)
{
preset_list &self = *(preset_list *)user_data;
+ bool rack_mode = self.rack_mode;
preset_vector &presets = self.presets;
parser_state &state = self.state;
switch(state)
@@ -233,10 +267,23 @@ void preset_list::xml_end_element_handler(void *user_data, const char *name)
return;
}
break;
+ case PLUGIN:
+ if (!strcmp(name, "plugin")) {
+ self.plugins.push_back(self.parser_plugin);
+ state = RACK;
+ return;
+ }
+ break;
+ case RACK:
+ if (!strcmp(name, "rack")) {
+ state = START;
+ return;
+ }
+ break;
case PRESET:
if (!strcmp(name, "preset")) {
presets.push_back(self.parser_preset);
- state = LIST;
+ state = rack_mode ? PLUGIN : LIST;
return;
}
break;
@@ -273,7 +320,7 @@ bool preset_list::load_defaults(bool builtin)
struct stat st;
string name = preset_list::get_preset_filename(builtin);
if (!stat(name.c_str(), &st)) {
- load(name.c_str());
+ load(name.c_str(), false);
if (!presets.empty())
return true;
}
@@ -285,8 +332,9 @@ bool preset_list::load_defaults(bool builtin)
return false;
}
-void preset_list::parse(const std::string &data)
+void preset_list::parse(const std::string &data, bool in_rack_mode)
{
+ rack_mode = in_rack_mode;
state = START;
XML_Parser parser = XML_ParserCreate("UTF-8");
XML_SetUserData(parser, this);
@@ -301,8 +349,9 @@ void preset_list::parse(const std::string &data)
XML_ParserFree(parser);
}
-void preset_list::load(const char *filename)
+void preset_list::load(const char *filename, bool in_rack_mode)
{
+ rack_mode = in_rack_mode;
state = START;
XML_Parser parser = XML_ParserCreate("UTF-8");
XML_SetUserData(parser, this);
diff --git a/src/preset_gui.cpp b/src/preset_gui.cpp
index 3ac8e48..8240480 100644
--- a/src/preset_gui.cpp
+++ b/src/preset_gui.cpp
@@ -74,7 +74,7 @@ void calf_plugins::store_preset(GtkWindow *toplevel, plugin_gui *gui)
sp.get_from(gui->plugin);
preset_list tmp;
try {
- tmp.load(tmp.get_preset_filename(false).c_str());
+ tmp.load(tmp.get_preset_filename(false).c_str(), false);
}
catch(...)
{
--
calf audio plugins packaging
More information about the pkg-multimedia-commits
mailing list