[SCM] calf/master: + LASH: redo LASH support to also support plugins created on the fly (using menu)
js at users.alioth.debian.org
js at users.alioth.debian.org
Tue May 7 15:37:08 UTC 2013
The following commit has been merged in the master branch:
commit 5c5b8a9cc27dba949fe4394bb4281053b110ec35
Author: kfoltman <kfoltman at 78b06b96-2940-0410-b7fc-879d825d01d8>
Date: Thu Apr 10 21:18:27 2008 +0000
+ LASH: redo LASH support to also support plugins created on the fly (using menu)
git-svn-id: https://calf.svn.sourceforge.net/svnroot/calf/trunk@153 78b06b96-2940-0410-b7fc-879d825d01d8
diff --git a/src/Makefile.am b/src/Makefile.am
index 5999aca..0bc479d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -44,7 +44,7 @@ calfdssigui_SOURCES = dssigui.cpp
calfdssigui_LDADD = -lglib-2.0 libcalfstatic.la libcalfgui.la $(GUI_DEPS_LIBS)
endif
-calf_la_SOURCES = modules.cpp giface.cpp monosynth.cpp organ.cpp preset.cpp synth.cpp
+calf_la_SOURCES = modules.cpp giface.cpp monosynth.cpp organ.cpp osctl.cpp preset.cpp synth.cpp utils.cpp
calf_la_LDFLAGS = -rpath $(ladspadir) -avoid-version -module -lexpat -export-symbols-regex "(ladspa_|lv2_|dssi_)descriptor"
if USE_LV2_GUI
@@ -52,7 +52,7 @@ calflv2gui_la_SOURCES = gui.cpp custom_ctl.cpp modules.cpp giface.cpp monosynth.
calflv2gui_la_LDFLAGS = -rpath $(lv2dir) -avoid-version -module -lexpat -export-symbols-regex "lv2_gui_descriptor" $(GUI_DEPS_LIBS)
endif
-libcalfstatic_la_SOURCES = modules.cpp giface.cpp monosynth.cpp organ.cpp preset.cpp synth.cpp
+libcalfstatic_la_SOURCES = modules.cpp giface.cpp monosynth.cpp organ.cpp osctl.cpp preset.cpp synth.cpp utils.cpp
libcalfstatic_la_LDFLAGS = -static -lexpat
if USE_GUI
diff --git a/src/calf/jackhost.h b/src/calf/jackhost.h
index 8094432..7bd765c 100644
--- a/src/calf/jackhost.h
+++ b/src/calf/jackhost.h
@@ -34,7 +34,7 @@ class jack_host_base;
class jack_client {
protected:
std::vector<jack_host_base *> plugins;
- ptmutex mutex;
+ calf_utils::ptmutex mutex;
public:
jack_client_t *client;
int input_nr, output_nr, midi_nr;
@@ -53,13 +53,13 @@ public:
void add(jack_host_base *plugin)
{
- ptlock lock(mutex);
+ calf_utils::ptlock lock(mutex);
plugins.push_back(plugin);
}
void del(int item)
{
- ptlock lock(mutex);
+ calf_utils::ptlock lock(mutex);
plugins.erase(plugins.begin()+item);
}
diff --git a/src/calf/utils.h b/src/calf/utils.h
index 3f52e82..ae2d663 100644
--- a/src/calf/utils.h
+++ b/src/calf/utils.h
@@ -22,6 +22,10 @@
#define __CALF_UTILS_H
#include <pthread.h>
+#include <map>
+
+namespace calf_utils
+{
class ptmutex
{
@@ -84,4 +88,11 @@ public:
}
};
+typedef std::map<std::string, std::string> dictionary;
+
+extern std::string encodeMap(const dictionary &data);
+extern void decodeMap(dictionary &data, const std::string &src);
+
+};
+
#endif
diff --git a/src/jackhost.cpp b/src/jackhost.cpp
index 77f98ae..49ee598 100644
--- a/src/jackhost.cpp
+++ b/src/jackhost.cpp
@@ -35,9 +35,11 @@
#include <calf/preset.h>
#include <calf/preset_gui.h>
#include <calf/main_win.h>
+#include <calf/utils.h>
using namespace synth;
using namespace std;
+using namespace calf_utils;
// I don't need anyone to tell me this is stupid. I already know that :)
plugin_gui_window *gui_win;
@@ -146,6 +148,8 @@ struct host_session: public main_window_owner_iface
host_session();
void open();
+ void add_plugin(string name, string preset);
+ void create_plugins_from_list();
void connect();
void close();
static gboolean update_lash(void *self) { ((host_session *)self)->update_lash(); return TRUE; }
@@ -180,6 +184,31 @@ host_session::host_session()
main_win->set_owner(this);
}
+void host_session::add_plugin(string name, string preset)
+{
+ jack_host_base *jh = create_jack_host(name.c_str());
+ if (!jh) {
+#ifdef ENABLE_EXPERIMENTAL
+#else
+#endif
+ throw audio_exception("Unknown plugin name; allowed are: reverb, flanger, filter, vintagedelay, monosynth, organ, rotaryspeaker, phaser\n");
+ }
+ jh->open(&client);
+
+ plugins.push_back(jh);
+ client.add(jh);
+ main_win->add_plugin(jh);
+ if (!preset.empty())
+ activate_preset(plugins.size() - 1, preset);
+}
+
+void host_session::create_plugins_from_list()
+{
+ for (unsigned int i = 0; i < plugin_names.size(); i++) {
+ add_plugin(plugin_names[i], presets.count(i) ? presets[i] : string());
+ }
+}
+
void host_session::open()
{
if (!input_name.empty()) client.input_name = input_name;
@@ -189,24 +218,8 @@ void host_session::open()
main_win->prefix = client_name + " - ";
main_win->conditions.insert("jackhost");
main_win->conditions.insert("directlink");
- for (unsigned int i = 0; i < plugin_names.size(); i++) {
- // if (presets.count(i))
- // printf("%s : %s\n", names[i].c_str(), presets[i].c_str());
- jack_host_base *jh = create_jack_host(plugin_names[i].c_str());
- if (!jh) {
-#ifdef ENABLE_EXPERIMENTAL
-#else
-#endif
- throw audio_exception("Unknown plugin name; allowed are: reverb, flanger, filter, vintagedelay, monosynth, organ, rotaryspeaker, phaser\n");
- }
- jh->open(&client);
-
- plugins.push_back(jh);
- client.add(jh);
- main_win->add_plugin(jh);
- if (presets.count(i))
- activate_preset(i, presets[i]);
- }
+ if (!restoring_session)
+ create_plugins_from_list();
main_win->create();
gtk_signal_connect(GTK_OBJECT(main_win->toplevel), "destroy", G_CALLBACK(destroy), NULL);
}
@@ -329,6 +342,16 @@ void host_session::close()
}
#if USE_LASH
+
+static string stripfmt(string x)
+{
+ if (x.length() < 2)
+ return x;
+ if (x.substr(x.length() - 2) != "%d")
+ return x;
+ return x.substr(0, x.length() - 2);
+}
+
void host_session::update_lash()
{
do {
@@ -341,13 +364,36 @@ void host_session::update_lash()
switch(lash_event_get_type(event)) {
case LASH_Save_Data_Set:
{
+ lash_config_t *cfg = lash_config_new_with_key("global");
+ dictionary tmp;
+ string pstr;
+ string i_name = stripfmt(client.input_name);
+ string o_name = stripfmt(client.output_name);
+ string m_name = stripfmt(client.midi_name);
+ tmp["input_prefix"] = i_name;
+ tmp["output_prefix"] = stripfmt(client.output_name);
+ tmp["midi_prefix"] = stripfmt(client.midi_name);
+ pstr = encodeMap(tmp);
+ lash_config_set_value(cfg, pstr.c_str(), pstr.length());
+ lash_send_config(lash_client, cfg);
+
for (unsigned int i = 0; i < plugins.size(); i++) {
+ jack_host_base *p = plugins[i];
char ss[32];
plugin_preset preset;
- preset.plugin = plugins[i]->get_id();
- preset.get_from(plugins[i]);
- sprintf(ss, "plugin%d", i);
- string pstr = preset.to_xml();
+ preset.plugin = p->get_id();
+ preset.get_from(p);
+ sprintf(ss, "Plugin%d", i);
+ pstr = preset.to_xml();
+ tmp.clear();
+ if (p->get_input_count())
+ tmp["input_name"] = p->get_inputs()[0].name.substr(i_name.length());
+ if (p->get_output_count())
+ tmp["output_name"] = p->get_outputs()[0].name.substr(o_name.length());
+ if (p->get_midi_port())
+ tmp["midi_name"] = p->get_midi_port()->name.substr(m_name.length());
+ tmp["preset"] = pstr;
+ pstr = encodeMap(tmp);
lash_config_t *cfg = lash_config_new_with_key(ss);
lash_config_set_value(cfg, pstr.c_str(), pstr.length());
lash_send_config(lash_client, cfg);
@@ -363,18 +409,31 @@ void host_session::update_lash()
const char *key = lash_config_get_key(cfg);
// printf("key = %s\n", lash_config_get_key(cfg));
string data = string((const char *)lash_config_get_value(cfg), lash_config_get_value_size(cfg));
- if (!strncmp(key, "plugin", 6))
+ if (!strcmp(key, "global"))
+ {
+ dictionary dict;
+ decodeMap(dict, data);
+ if (dict.count("input_prefix")) client.input_name = dict["input_prefix"]+"%d";
+ if (dict.count("output_prefix")) client.output_name = dict["output_prefix"]+"%d";
+ if (dict.count("midi_prefix")) client.midi_name = dict["midi_prefix"]+"%d";
+ }
+ if (!strncmp(key, "Plugin", 6))
{
unsigned int nplugin = atoi(key + 6);
- if (nplugin < plugins.size())
+ dictionary dict;
+ decodeMap(dict, data);
+ data = dict["preset"];
+ if (dict.count("input_name")) client.input_nr = atoi(dict["input_name"].c_str());
+ if (dict.count("output_name")) client.output_nr = atoi(dict["output_name"].c_str());
+ if (dict.count("midi_name")) client.midi_nr = atoi(dict["midi_name"].c_str());
+ preset_list tmp;
+ tmp.parse("<presets>"+data+"</presets>");
+ if (tmp.presets.size())
{
- preset_list tmp;
- tmp.parse("<presets>"+data+"</presets>");
- if (tmp.presets.size())
- {
- tmp.presets[0].activate(plugins[nplugin]);
- main_win->refresh_plugin(plugins[nplugin]);
- }
+ printf("Load plugin %s\n", tmp.presets[0].plugin.c_str());
+ add_plugin(tmp.presets[0].plugin, "");
+ tmp.presets[0].activate(plugins[nplugin]);
+ main_win->refresh_plugin(plugins[nplugin]);
}
}
lash_config_destroy(cfg);
diff --git a/src/main_win.cpp b/src/main_win.cpp
index a7318d0..56c30ce 100644
--- a/src/main_win.cpp
+++ b/src/main_win.cpp
@@ -347,7 +347,8 @@ void main_window::create()
void main_window::refresh_plugin(plugin_ctl_iface *plugin)
{
- plugins[plugin]->gui_win->gui->refresh();
+ if (plugins[plugin]->gui_win)
+ plugins[plugin]->gui_win->gui->refresh();
}
void main_window::close_guis()
diff --git a/src/utils.cpp b/src/utils.cpp
new file mode 100644
index 0000000..ce15501
--- /dev/null
+++ b/src/utils.cpp
@@ -0,0 +1,56 @@
+/* Calf DSP Library
+ * Various utility functions.
+ * 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * 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.
+ */
+
+#include <assert.h>
+#include <config.h>
+#include <calf/osctl.h>
+#include <calf/utils.h>
+
+using namespace calf_utils;
+using namespace std;
+using namespace osctl;
+
+string calf_utils::encodeMap(const dictionary &data)
+{
+ osc_stream str;
+ str.write((int32_t)data.size());
+ for(dictionary::const_iterator i = data.begin(); i != data.end(); i++)
+ {
+ str.write(osc_data(i->first));
+ str.write(osc_data(i->second));
+ }
+ return str.buffer;
+}
+
+void calf_utils::decodeMap(dictionary &data, const string &src)
+{
+ osc_stream str(src);
+ osc_data tmp, tmp2;
+ int32_t count = 0;
+ str.read(osc_i32, tmp);
+ count = tmp.i32val;
+ data.clear();
+ for (int i = 0; i < count; i++)
+ {
+ str.read(osc_string, tmp);
+ str.read(osc_string, tmp2);
+ data[tmp.strval] = tmp2.strval;
+ }
+}
--
calf audio plugins packaging
More information about the pkg-multimedia-commits
mailing list