From 3c050000c6918b77a353583999e6e810aa675fda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?llu=C3=ADs=20g=C3=B3mez=20i=20bigord=C3=A0?= Date: Wed, 24 Oct 2007 20:37:21 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r8875, which included commits to RCS files with non-trunk default branches. svn path=/trunk/externals/pdvjtools/; revision=8876 --- pdp_frei0r/CHANGES.LOG | 2 + pdp_frei0r/INSTALL | 20 ++ pdp_frei0r/Makefile | 14 + pdp_frei0r/Makefile.config | 22 ++ pdp_frei0r/frei0r.h | 567 +++++++++++++++++++++++++++++++++++++ pdp_frei0r/help_pdp_frei0r.pd | 328 ++++++++++++++++++++++ pdp_frei0r/pdp_frei0r.c | 637 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 1590 insertions(+) create mode 100755 pdp_frei0r/CHANGES.LOG create mode 100644 pdp_frei0r/INSTALL create mode 100644 pdp_frei0r/Makefile create mode 100644 pdp_frei0r/Makefile.config create mode 100644 pdp_frei0r/frei0r.h create mode 100644 pdp_frei0r/help_pdp_frei0r.pd create mode 100644 pdp_frei0r/pdp_frei0r.c (limited to 'pdp_frei0r') diff --git a/pdp_frei0r/CHANGES.LOG b/pdp_frei0r/CHANGES.LOG new file mode 100755 index 0000000..a273448 --- /dev/null +++ b/pdp_frei0r/CHANGES.LOG @@ -0,0 +1,2 @@ +0.1 + initial release diff --git a/pdp_frei0r/INSTALL b/pdp_frei0r/INSTALL new file mode 100644 index 0000000..551090b --- /dev/null +++ b/pdp_frei0r/INSTALL @@ -0,0 +1,20 @@ +1. Download Frei0r specs and plugins, here: http://www.piksel.org/frei0r + + darcs get http://darcs.gephex.org/frei0r/frei0r--main--1.1 + cd to the frei0r-plugins-x.y.z directory + compile the plugins:: + cd to plugins and type 'scons' + install the plugins:: + type 'scons install' + +2. Download pdp_frei0r-0.1.tar.gz from http://www.artefacte.org/pd/pdp_frei0r-0.1.tar.gz + + untar the pdp_frei0r-0.1.tar.gz file + cd in to the pdp_frei0r-0.1 directory + + edit the Makefile.config file and change the path to the pd (m_pd.h), pdp (pdp.h) sources + and frei0r plugin directory (.so) if needed. + + type 'make' + + to load the pdp_frei0r help file type 'pd -nrt -lib pdp:pdp_frei0r help_pdp_frei0r.pd' diff --git a/pdp_frei0r/Makefile b/pdp_frei0r/Makefile new file mode 100644 index 0000000..30b81e0 --- /dev/null +++ b/pdp_frei0r/Makefile @@ -0,0 +1,14 @@ +current: all + +include Makefile.config + +PDP_MOD = pdp_frei0r.o + +all: $(PDP_MOD) + $(CC) -export_dynamic -shared -o pdp_frei0r.pd_linux *.o $(PDP_LIBS) + +clean: + rm -f *~ + rm -f *.o + rm -f *.pd_linux + diff --git a/pdp_frei0r/Makefile.config b/pdp_frei0r/Makefile.config new file mode 100644 index 0000000..cf89221 --- /dev/null +++ b/pdp_frei0r/Makefile.config @@ -0,0 +1,22 @@ +# if configure can't find the m_pd.h header +# specify pd's include path here and ignore the warning +# +FR_PLUGIN_DIR=/usr/local/lib/frei0r-1/ +PD_CPPFLAGS=-I/usr/local/pd/src +PDP_CFLAGS=-I/usr/local/pd/pdp/include -DPD -Wall -W -Wstrict-prototypes -Wno-unused -Wno-parentheses -Wno-switch -O2 -funroll-loops -fomit-frame-pointer -ffast-math -freg-struct-return -DLINUX + +prefix=/usr/local +PDPF_VERSION = 0.1 +PDPF_TARGET = linux +PDPF_LIBRARY_NAME = pdp_frei0r.pd_linux + +PDP_CPPFLAGS = -I. -I/usr/X11R6/include -I../include -I../../include $(PD_CPPFLAGS) + +PDP_CFLAGS += -DPDPF_VERSION=\"$(PDPF_VERSION)\" -DFR_PLUGIN_DIR=\"$(FR_PLUGIN_DIR)\" + +CC = gcc + +# build rules + +.c.o: + $(CC) $(PDP_CFLAGS) $(PDP_CPPFLAGS) -o $*.o -c $*.c diff --git a/pdp_frei0r/frei0r.h b/pdp_frei0r/frei0r.h new file mode 100644 index 0000000..2e09113 --- /dev/null +++ b/pdp_frei0r/frei0r.h @@ -0,0 +1,567 @@ +/** @mainpage frei0r - a minimalistic plugin API for video effects + * + * @section sec_intro Introduction + * + * This is frei0r - a minimalistic plugin API for video effects. + * + * The main emphasis is on simplicity - there are many different applications + * that use video effects, and they all have different requirements regarding + * their internal plugin API. And that's why frei0r does not try to be a + * one-in-all general video plugin API, but instead an API for the most + * common video effects: simple filters, sources and mixers that can be + * controlled by parameters. + * + * It's our hope that this way these simple effects can be shared between + * many applications, avoiding their reimplementation by different + * projects. + * + * On the other hand, this is not meant as a competing standard to + * more ambitious efforts that try to satisfy the needs of many different + * applications and more complex effects. + * + * + * @section sec_overview Overview + * + * If you are new to frei0r, the best thing is probably to have + * a look at the frei0r header, + * which is quite simple. + * + * After that, you might want to look at the + * frei0r functions in more detail. + * + * When developing a new frei0r effect, you have to choose + * - which effect type to use (\ref PLUGIN_TYPE), + * - which color model to use (\ref COLOR_MODEL), and + * - which parameter types (\ref PARAM_TYPE) your effect will support. + * + * To round things up, you should decide whether your effect should have + * an associated icon (\ref icons), and where it will be installed + * (\ref pluglocations). + * + * @section sec_changes Changes + * + * @subsection sec_changes_1_0_1_1 From frei0r 1.0 to frei0r 1.1 + * + * - added specifications for plugin locations + * - added specifications for frei0r icons + * - added RGBA8888 color model + * - added packed32 color model + * - added better specification of color models + * - added string type + * - added bounds to resolution (8 <= width, height <= 2048) + * - width and height must be an integer multiple of 8 + * - frame data must be 16 byte aligned + * - improved update specification (must not change parameters, + * must restore fpu state) + * - added note for applications to ignore effects with unknown fields + * - added new plugin types mixer2 and mixer3 + * - added section about \ref concurrency + */ + + +/** + * \addtogroup pluglocations Plugin Locations + * @section sec_pluglocations Plugin Locations + * + * For Unix platforms there are rules for the location of frei0r plugins. + * + * frei0r 1.x plugin files should be located in + * + * - (1) /usr/lib/frei0r-1/\ + * - (2) /usr/local/lib/frei0r-1/\ + * - (3) $HOME/.frei0r-1/lib/\ + * + * Examples: + * + * - /usr/lib/frei0r-1/mob/flippo.so + * - /usr/lib/frei0r-1/drone/flippo.so + * - /usr/local/lib/frei0r-1/gephex/coma/invert0r.so + * - /home/martin/.frei0r-1/lib/martin/test.so + * + * Like in these examples plugins should be placed in "vendor" subdirs + * to reduce name clashes. + * + * @subsection sec_order Plugin Loading Order + * + * The application shall load plugins in the following order: 3, 2, 1. + * If a name clash occurs (two or more frei0r plugins with identical + * effect name), the plugins in directory 3 have precedence over plugins + * in directory 2, and those in directory 2 have precedence over plugins + * in directory 1. + * + * This makes it possible for users to "override" effects that are + * installed in system wide directories by placing plugins in their + * home directory. + * + * The order of loading plugins inside each of the directories + * 1, 2, and 3 is not defined. + */ + +/** + *\addtogroup icons Icons for frei0r effects + * @section sec_icons Icons for frei0r effects + * + * Each frei0r effect can have an associated icon. + * + * @subsection sec_icon_format Icon Format + * + * The format of frei0r icons must be png. + * Recommended resolution is 64x64. + * The icon filename of an effect with effect name "frei0r" + * must be "frei0r.png". + * + * @subsection sec_icon_location Icon location + * + * The exact location where the application should look for the + * plugin is platform dependant. + * + * For Windows platforms, the icon should be at the same place as + * the plugin containing the effect. + * + * For Unix platforms, the following mapping from plugin location + * to icon location must be used: + * + * Let \/\ be a frei0r plugin with name \. + * Then the corresponding icon (if any) shall be located in + * \/\.png. + * \ can be obtained in the following way: + * + * @verbatim + | + ---------------------------------------------------------------------------- + $HOME/.frei0r-1/lib/ | $HOME/.frei0r-1/icons/ + /usr/local/lib/frei0r-1/ | /usr/local/share/frei0r-1/icons/ + /usr/lib/frei0r-1/ | /usr/share/frei0r-1/icons/ + * | + @endverbatim + * + * (The wildcard '*' stands for any other plugin_path) + * + * For other platforms, no location is defined. We recommend to use the + * plugin path where possible. + */ + +/** + * \addtogroup concurrency Concurrency + * @section sec_concurrency Concurrency + * + * - \ref f0r_init + * - \ref f0r_deinit + * + * These methods must not be called more than once. It is obvious that no + * concurrent calls are allowed. + * + * + * - \ref f0r_get_plugin_info + * - \ref f0r_get_param_info + * - \ref f0r_construct + * - \ref f0r_destruct + * + * Concurrent calls of these functions are allowed. + * + * + * - \ref f0r_set_param_value + * - \ref f0r_get_param_value + * - \ref f0r_update + * - \ref f0r_update2 + * + * If a thread is in one of these methods its allowed for another thread to + * enter one of theses methods for a different effect instance. But for one + * effect instance only one thread is allowed to execute any of these methods. + */ + + + +/** \file + * \brief This file defines the frei0r api, version 1.1. + * + * A conforming plugin must implement and export all functions declared in + * this header. + * + * A conforming application must accept only those plugins which use + * allowed values for the described fields. + */ + +#ifndef INCLUDED_FREI0R_H +#define INCLUDED_FREI0R_H + +#include + +/** + * The frei0r API major version + */ +#define FREI0R_MAJOR_VERSION 1 + +/** + * The frei0r API minor version + */ +#define FREI0R_MINOR_VERSION 1 + +//--------------------------------------------------------------------------- + +/** + * f0r_init() is called once when the plugin is loaded by the application. + * \see f0r_deinit + */ +int f0r_init(void); + +/** + * f0r_deinit is called once when the plugin is unloaded by the application. + * \see f0r_init + */ +void f0r_deinit(void); + +//--------------------------------------------------------------------------- + +/** \addtogroup PLUGIN_TYPE Type of the Plugin + * These defines determine whether the plugin is a + * source, a filter or one of the two mixer types + * @{ + */ + +/** one input and one output */ +#define F0R_PLUGIN_TYPE_FILTER 0 +/** just one output */ +#define F0R_PLUGIN_TYPE_SOURCE 1 +/** two inputs and one output */ +#define F0R_PLUGIN_TYPE_MIXER2 2 +/** three inputs and one output */ +#define F0R_PLUGIN_TYPE_MIXER3 3 + +/** @} */ + +//--------------------------------------------------------------------------- + +/** \addtogroup COLOR_MODEL Color Models + * List of supported color models. + * + * Note: the color models are endian independent, because the + * color components are defined by their positon in memory, not + * by their significance in an uint32_t value. + * + * For effects that work on the color components, + * RGBA8888 is the recommended color model for frei0r-1.1 effects. + * For effects that only work on pixels, PACKED32 is the recommended + * color model since it helps the application to avoid unnecessary + * color conversions. + * + * Effects can choose an appropriate color model, applications must support + * all color models and do conversions if necessary. Source effects + * must not use the PACKED32 color model because the application must know + * in which color model the created framebuffers are represented. + * + * For each color model, a frame consists of width*height pixels which + * are stored row-wise and consecutively in memory. The size of a pixel is + * 4 bytes. There is no extra pitch parameter + * (i.e. the pitch is simply width*4). + * + * The following additional constraints must be honored: + * - The top-most line of a frame is stored first in memory. + * - A frame must be aligned to a 16 byte border in memory. + * - The width and height of a frame must be positive + * - The width and height of a frame must be integer multiples of 8 + * + * These constraints make sure that each line is stored at an address aligned + * to 16 byte. + */ +/*@{*/ +/** + * In BGRA8888, each pixel is represented by 4 consecutive + * unsigned bytes, where the first byte value represents + * the blue, the second the green, and the third the red color + * component of the pixel. The last value represents the + * alpha value. + */ +#define F0R_COLOR_MODEL_BGRA8888 0 + +/** + * In RGBA8888, each pixel is represented by 4 consecutive + * unsigned bytes, where the first byte value represents + * the red, the second the green, and the third the blue color + * component of the pixel. The last value represents the + * alpha value. + */ +#define F0R_COLOR_MODEL_RGBA8888 1 + +/** + * In PACKED32, each pixel is represented by 4 consecutive + * bytes, but it is not defined how the color componets are + * stored. The true color format could be RGBA8888, + * BGRA8888, a packed 32 bit YUV format, or any other + * color format that stores pixels in 32 bit. + * + * This is useful for effects that don't work on color but + * only on pixels (for example a mirror effect). + * + * Note that source effects must not use this color model. + */ +#define F0R_COLOR_MODEL_PACKED32 2 +/*@}*/ + +/** + * The f0r_plugin_info_t structure is filled in by the plugin + * to tell the application about its name, type, number of parameters, + * and version. + * + * An application should ignore (i.e. not use) frei0r effects that + * have unknown values in the plugin_type or color_model field. + * It should also ignore effects with a too high frei0r_version. + * + * This is necessary to be able to extend the frei0r spec (e.g. + * by adding new color models or plugin types) in a way that does not + * result in crashes when loading effects that make use of these + * extensions into an older application. + * + * All strings are unicode, 0-terminated, and the encoding is utf-8. + */ +typedef struct f0r_plugin_info +{ + const char* name; /**< The (short) name of the plugin */ + const char* author; /**< The plugin author */ + /** The plugin type + * \see PLUGIN_TYPE + */ + int plugin_type; + int color_model; /**< The color model used */ + int frei0r_version; /**< The frei0r major version this plugin is built for*/ + int major_version; /**< The major version of the plugin */ + int minor_version; /**< The minor version of the plugin */ + int num_params; /**< The number of parameters of the plugin */ + const char* explanation; /**< An optional explanation string */ +} f0r_plugin_info_t; + + +/** + * Is called once after init. The plugin has to fill in the values in info. + * + * \param info Pointer to an info struct allocated by the application. + */ +void f0r_get_plugin_info(f0r_plugin_info_t* info); + +//--------------------------------------------------------------------------- + +/** \addtogroup PARAM_TYPE Parameter Types + * + * @{ + */ + + +/** + * Parameter type for boolean values + * \see f0r_param_bool + */ +#define F0R_PARAM_BOOL 0 + +/** + * Parameter type for doubles + * \see f0r_param_double + */ +#define F0R_PARAM_DOUBLE 1 + +/** + * Parameter type for color + * \see f0r_param_color + */ +#define F0R_PARAM_COLOR 2 +/** + * Parameter type for position + * \see f0r_param_position + */ +#define F0R_PARAM_POSITION 3 + +/** + * Parameter type for string + * \see f0r_param_string + */ +#define F0R_PARAM_STRING 4 + +/** + * The boolean type. The allowed range of values is [0, 1]. + * [0, 0.5[ is mapped to false and [0.5, 1] is mapped to true. + */ +typedef double f0r_param_bool; + +/** + * The double type. The allowed range of values is [0, 1]. + */ +typedef double f0r_param_double; + +/** + * The color type. All three color components are in the range [0, 1]. + */ +typedef struct f0r_param_color +{ + float r; /**< red color component */ + float g; /**< green color component */ + float b; /**< blue color component */ +} f0r_param_color_t; + +/** + * The position type. Both position coordinates are in the range [0, 1]. + */ +typedef struct f0r_param_position +{ + double x; /**< x coordinate */ + double y; /**< y coordinate */ +} f0r_param_position_t; + + +/** + * The string type. + * Zero terminated array of 8-bit values in utf-8 encoding + */ +typedef char f0r_param_string; + +/** @} */ + + +/** + * Similar to f0r_plugin_info_t, this structure is filled by the plugin + * for every parameter. + * + * All strings are unicode, 0-terminated, and the encoding is utf-8. + */ +typedef struct f0r_param_info +{ + const char* name; /**; +#X obj 46 376 pdp_frei0r 16; +#X text 499 562 you can get the index from the list of loaded plugins +; +#X text 498 575 at startup ( check pd window ); +#X text 13 290 WARNING : sizes of inputs; +#X text 12 302 _must_ be the same; +#X connect 0 0 75 3; +#X connect 1 0 0 0; +#X connect 2 0 5 0; +#X connect 3 0 6 0; +#X connect 4 0 7 0; +#X connect 5 0 75 0; +#X connect 6 0 75 0; +#X connect 7 0 75 0; +#X connect 12 0 28 1; +#X connect 16 0 22 0; +#X connect 17 0 23 0; +#X connect 18 0 24 0; +#X connect 19 0 25 0; +#X connect 20 0 26 0; +#X connect 21 0 27 0; +#X connect 22 0 75 0; +#X connect 23 0 75 0; +#X connect 24 0 75 0; +#X connect 25 0 75 0; +#X connect 26 0 75 0; +#X connect 27 0 75 0; +#X connect 44 0 48 0; +#X connect 45 0 49 0; +#X connect 48 0 75 0; +#X connect 49 0 75 0; +#X connect 51 0 66 0; +#X connect 54 0 51 1; +#X connect 55 0 51 0; +#X connect 58 0 60 1; +#X connect 59 0 60 0; +#X connect 60 0 67 0; +#X connect 63 0 65 1; +#X connect 64 0 65 0; +#X connect 65 0 68 0; +#X connect 66 0 75 0; +#X connect 67 0 75 1; +#X connect 68 0 75 2; +#X connect 69 0 71 0; +#X connect 70 0 73 0; +#X connect 71 0 70 0; +#X connect 73 0 72 0; +#X connect 75 0 50 0; +#X connect 75 1 10 0; +#X connect 75 2 12 0; +#X connect 75 3 28 0; +#X connect 75 4 42 0; diff --git a/pdp_frei0r/pdp_frei0r.c b/pdp_frei0r/pdp_frei0r.c new file mode 100644 index 0000000..3a66147 --- /dev/null +++ b/pdp_frei0r/pdp_frei0r.c @@ -0,0 +1,637 @@ +/* + * Pure Data Packet module. + * Copyright (c) by Tom Schouten + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#include +#include +#include +#include +#include +#include + +#include "pdp.h" +#include "frei0r.h" + +#define FREI0R_PNAME_LENGTH 128 + +typedef struct +{ + char name[FREI0R_PNAME_LENGTH+1]; + unsigned numparameters; + int plugin_type; + f0r_instance_t instance; + f0r_plugin_info_t plugin_info; + int (*f0r_init)(void); + void (*f0r_get_plugin_info)(f0r_plugin_info_t* pluginInfo); + void (*f0r_get_param_info)(f0r_param_info_t* info, int param_index); + f0r_instance_t (*f0r_construct)(unsigned int width, unsigned int height); + void (*f0r_destruct)(f0r_instance_t instance); + void (*f0r_set_param_value)(f0r_instance_t instance, f0r_param_t param, int param_index); + void (*f0r_get_param_value)(f0r_instance_t instance, f0r_param_t param, int param_index); + void (*f0r_update)(f0r_instance_t instance, double time, const uint32_t* inframe, uint32_t* outframe); + void (*f0r_update2)(f0r_instance_t instance, double time, + const uint32_t* inframe1, const uint32_t* inframe2, const uint32_t* inframe3, uint32_t* outframe); + int (*f0r_deinit)(void); +} PLUGIN; + +typedef struct pdp_frei0r_struct +{ + t_object x_obj; + t_float x_f; + + t_outlet *x_outlet0; + t_outlet *x_pname; + t_outlet *x_nparams; + t_outlet *x_parname; + t_outlet *x_partype; + int x_packet0; + int x_packet1; + int x_packet2; + int x_packet3; + + // middle input packets + int x_packetm0; + int x_packetm1; + + // right input packets + int x_packetr0; + int x_packetr1; + + int x_dropped; + int x_queue_id; + + int x_width; + int x_height; + int x_size; + + int x_plugin_count; + struct dirent **x_filename_list; + int x_filename_count; + + int x_plugin; + int x_infosok; + + PLUGIN *plugins; + +} t_pdp_frei0r; + +void panic(const char *panicstr, ...) +{ + post("pdp_frei0r :: PANIC!! %s\n", panicstr); + exit(1); +} + +static int selector(const struct dirent *dp) +{ + return (strstr(dp->d_name, ".so") != NULL); +} + +static void scan_plugins(t_pdp_frei0r *x, char *plugindir) +{ + x->x_filename_count = scandir(plugindir, &x->x_filename_list, selector, alphasort); + if (x->x_filename_count < 0) + { + x->x_filename_count = 0; + } +} + +void fr_loadplugins(t_pdp_frei0r *x, char *plugindir) +{ + char libname[PATH_MAX]; + unsigned instance, numparameters; + int i; + char *pluginname; + void *plugin_handle; + + scan_plugins(x, plugindir); + + x->x_plugin_count = 0; + x->plugins = (PLUGIN *)getbytes(x->x_filename_count*sizeof(PLUGIN)); + if (x->plugins == NULL) + { + panic("no memory for loading plugins\n"); + } + else + { + post( "allocated plugins : %x", x->plugins ); + } + + for (i=0; ix_filename_count; i++) + { + pluginname = x->x_filename_list[i]->d_name; + + snprintf(libname, PATH_MAX, "%s/%s", plugindir, pluginname); + + post( "pdp_frei0r : opening : %s", pluginname ); + + plugin_handle = dlopen(libname, RTLD_NOW); + dlerror(); + + // get functions pointers + *(void**) (&x->plugins[x->x_plugin_count].f0r_init) = dlsym(plugin_handle, "f0r_init"); + *(void**) (&x->plugins[x->x_plugin_count].f0r_get_plugin_info) = dlsym(plugin_handle, "f0r_get_plugin_info"); + *(void**) (&x->plugins[x->x_plugin_count].f0r_get_param_info) = dlsym(plugin_handle, "f0r_get_param_info"); + *(void**) (&x->plugins[x->x_plugin_count].f0r_construct) = dlsym(plugin_handle, "f0r_construct"); + *(void**) (&x->plugins[x->x_plugin_count].f0r_destruct) = dlsym(plugin_handle, "f0r_destruct"); + *(void**) (&x->plugins[x->x_plugin_count].f0r_set_param_value) = dlsym(plugin_handle, "f0r_set_param_value"); + *(void**) (&x->plugins[x->x_plugin_count].f0r_get_param_value) = dlsym(plugin_handle, "f0r_get_param_value"); + *(void**) (&x->plugins[x->x_plugin_count].f0r_update) = dlsym(plugin_handle, "f0r_update"); + dlerror(); + + // check for special function update2 + *(void**) (&x->plugins[x->x_plugin_count].f0r_update2) = dlsym(plugin_handle, "f0r_update2"); + if (!dlerror()) + { + // continue; + } + + // init plugin + (*x->plugins[x->x_plugin_count].f0r_init)(); + + // instantiate + x->plugins[x->x_plugin_count].instance = (*x->plugins[x->x_plugin_count].f0r_construct)(x->x_width, x->x_height); + + // get plugin infos + (*x->plugins[x->x_plugin_count].f0r_get_plugin_info)(&x->plugins[x->x_plugin_count].plugin_info); + strcpy( x->plugins[x->x_plugin_count].name, x->plugins[x->x_plugin_count].plugin_info.name ); + x->plugins[x->x_plugin_count].numparameters=x->plugins[x->x_plugin_count].plugin_info.num_params; + x->plugins[x->x_plugin_count].plugin_type=x->plugins[x->x_plugin_count].plugin_info.plugin_type; + + if ( ( x->plugins[x->x_plugin_count].plugin_info.color_model != F0R_COLOR_MODEL_RGBA8888 ) && + ( x->plugins[x->x_plugin_count].plugin_info.color_model != F0R_COLOR_MODEL_BGRA8888 ) && + ( x->plugins[x->x_plugin_count].plugin_info.color_model != F0R_COLOR_MODEL_PACKED32 ) ) + { + post( "pdp_frei0r : warning : plugin : %s use unsupported color model (%d) : ignored ...", + pluginname, x->plugins[x->x_plugin_count].plugin_info.color_model ); + continue; + } + + x->x_plugin_count++; + } +} + +void fr_processframe(t_pdp_frei0r *x, int plugin, void *ibuffer, void *imbuffer, void *irbuffer, void *obuffer) +{ + double time = 0.0; + + if ( x->x_plugin_count <= 0 ) + { + return; + } + + if ( ( x->plugins[x->x_plugin].plugin_type == F0R_PLUGIN_TYPE_FILTER ) || + ( x->plugins[x->x_plugin].plugin_type == F0R_PLUGIN_TYPE_SOURCE ) ) + { + // process frame + (*x->plugins[x->x_plugin].f0r_update)(x->plugins[x->x_plugin].instance, time, ibuffer, obuffer); + } + if ( x->plugins[x->x_plugin].plugin_type == F0R_PLUGIN_TYPE_MIXER2 ) + { + if ( ( x->x_packet1 != -1 ) && ( x->x_packet2 != -1 ) && ( x->x_packetm1 != -1 ) ) + { + // process frame + (*x->plugins[x->x_plugin].f0r_update2)(x->plugins[x->x_plugin].instance, time, ibuffer, imbuffer, irbuffer, obuffer); + } + } + if ( x->plugins[x->x_plugin].plugin_type == F0R_PLUGIN_TYPE_MIXER3 ) + { + if ( ( x->x_packet1 != -1 ) && ( x->x_packet2 != -1 ) && ( x->x_packetm1 != -1 ) && ( x->x_packetr1 != -1 ) ) + { + // process frame + (*x->plugins[x->x_plugin].f0r_update2)(x->plugins[x->x_plugin].instance, time, ibuffer, imbuffer, irbuffer, obuffer); + } + } +} + +void fr_freeplugins(t_pdp_frei0r *x) +{ + t_int i; + + for (i=0; ix_plugin_count; i++) + { + // destroy plugin + (*x->plugins[i].f0r_destruct)(x->plugins[i].instance); + } + post("freeing plugin resources : %x", x->plugins); + freebytes( x->plugins, x->x_filename_count*sizeof(PLUGIN) ); + x->plugins = NULL; +} + +static void pdp_frei0r_process_rgba(t_pdp_frei0r *x) +{ + t_pdp *newheader = pdp_packet_header(x->x_packet2); + char *newdata = (char *)pdp_packet_data(x->x_packet2); + t_pdp *lheader = pdp_packet_header(x->x_packet1); + char *ldata = (char *)pdp_packet_data(x->x_packet1); + t_pdp *mheader = pdp_packet_header(x->x_packetm1); + char *mdata = (char *)pdp_packet_data(x->x_packetm1); + t_pdp *rheader = pdp_packet_header(x->x_packetr1); + char *rdata = (char *)pdp_packet_data(x->x_packetr1); + + if ((x->x_width != (t_int)lheader->info.image.width) || + (x->x_height != (t_int)lheader->info.image.height)) + { + + post("pdp_frei0r :: resizing plugins"); + + fr_freeplugins(x); + + x->x_width = lheader->info.image.width; + x->x_height = lheader->info.image.height; + x->x_size = x->x_width*x->x_height; + + //load the plugins + fr_loadplugins(x, FR_PLUGIN_DIR); + } + + newheader->info.image.encoding = lheader->info.image.encoding; + newheader->info.image.width = x->x_width; + newheader->info.image.height = x->x_height; + + memcpy( newdata, ldata, x->x_size*sizeof(uint32_t) ); + + fr_processframe(x, x->x_plugin, ldata, mdata, rdata, newdata); + + +} + +static void pdp_frei0r_param(t_pdp_frei0r *x, t_symbol *s, int argc, t_atom *argv) +{ + int pnumber; + f0r_param_info_t param_infos; + + if ( x->x_plugin_count <= 0 ) + { + post( "frei0r : set parameter : no plugins loaded, check your plugin directory setup" ); + return; + } + + if ( argc < 2 ) + { + post("pdp_frei0r : set parameter : insufficient parameters (%d)", argc ); + return; + } + + if ( argv[0].a_type != A_FLOAT ) + { + post("pdp_frei0r : set parameter : wrong parameter number" ); + return; + } + pnumber = (int)argv[0].a_w.w_float; + // post("pdp_frei0r : setting parameter : %d", pnumber ); + + if ( (pnumber<0) || (pnumber>=(int)x->plugins[x->x_plugin].numparameters) ) + { + post("pdp_frei0r : set parameter : wrong parameter number : %d : max : %d", pnumber, x->plugins[x->x_plugin].numparameters ); + return; + } + + (*x->plugins[x->x_plugin].f0r_get_param_info)(¶m_infos, pnumber); + + // set parameter + switch (param_infos.type) + { + case F0R_PARAM_BOOL: + { + f0r_param_bool fvalue; + + if ( argc != 2 ) + { + post("pdp_frei0r : wrong parameter arguments (%d) for boolean", argc ); + return; + } + if ( argv[1].a_type != A_FLOAT ) + { + post("pdp_frei0r : wrong parameter value" ); + return; + } + if ( argv[1].a_w.w_float != 0. && argv[1].a_w.w_float != 1. ) + { + // post("pdp_frei0r : wrong parameter value for boolean" ); + return; + } + fvalue=argv[1].a_w.w_float; + (*x->plugins[x->x_plugin].f0r_set_param_value)(x->plugins[x->x_plugin].instance, &fvalue, pnumber); + } + break; + case F0R_PARAM_DOUBLE: + { + f0r_param_double fvalue; + + if ( argc != 2 ) + { + post("pdp_frei0r : wrong parameter arguments (%d) for double", argc ); + return; + } + if ( argv[1].a_type != A_FLOAT ) + { + post("pdp_frei0r : wrong parameter value" ); + return; + } + fvalue=argv[1].a_w.w_float; + (*x->plugins[x->x_plugin].f0r_set_param_value)(x->plugins[x->x_plugin].instance, &fvalue, pnumber); + } + break; + case F0R_PARAM_COLOR: + { + struct f0r_param_color color; + + if ( argc != 4 ) + { + post("pdp_frei0r : wrong parameter arguments (%d) for color", argc ); + return; + } + if ( argv[1].a_type != A_FLOAT || + argv[2].a_type != A_FLOAT || + argv[3].a_type != A_FLOAT ) + { + post("pdp_frei0r : wrong parameter value" ); + return; + } + color.r = argv[1].a_w.w_float; + color.g = argv[2].a_w.w_float; + color.b = argv[3].a_w.w_float; + (*x->plugins[x->x_plugin].f0r_set_param_value)(x->plugins[x->x_plugin].instance, &color, pnumber); + } + break; + case F0R_PARAM_POSITION: + { + struct f0r_param_position position; + + if ( argc != 3 ) + { + post("pdp_frei0r : wrong parameter arguments (%d) for position", argc ); + return; + } + if ( argv[1].a_type != A_FLOAT || + argv[2].a_type != A_FLOAT ) + { + post("pdp_frei0r : wrong parameter value" ); + return; + } + position.x = argv[1].a_w.w_float; + position.y = argv[2].a_w.w_float; + (*x->plugins[x->x_plugin].f0r_set_param_value)(x->plugins[x->x_plugin].instance, &position, pnumber); + } + break; + default: + post("pdp_frei0r : unsupported parameter type (%d)", param_infos.type ); + return; + } +} + +static void pdp_frei0r_plugin(t_pdp_frei0r *x, t_floatarg f) +{ + unsigned pi; + char *parname; + int partype; + t_atom plist[2]; + t_atom tlist[2]; + t_atom vlist[2]; + f0r_param_info_t param_infos; + + if ( x->x_plugin_count <= 0 ) + { + post( "frei0r : no plugins loaded, check your plugin directory setup" ); + return; + } + if((fx_plugin_count)&&(f>-1)) + { + x->x_plugin = f; + } + else + { + post( "frei0r : plugin out of range : %d", (t_int)f ); + return; + } + post ("pdp_freeframe :: %s selected, %d parameters", x->plugins[x->x_plugin].name, x->plugins[x->x_plugin].numparameters); + outlet_symbol(x->x_pname, gensym( x->plugins[x->x_plugin].name ) ); + outlet_float(x->x_nparams, (float)x->plugins[x->x_plugin].numparameters); + for ( pi=0; piplugins[x->x_plugin].numparameters; pi++ ) + { + (*x->plugins[x->x_plugin].f0r_get_param_info)(¶m_infos, pi); + SETFLOAT(&plist[0], pi); + SETSYMBOL(&plist[1], gensym(param_infos.name) ); + outlet_list( x->x_parname, &s_list, 2, &plist[0] ); + SETFLOAT(&tlist[0], pi); + SETFLOAT(&tlist[1], param_infos.type ); + outlet_list( x->x_partype, &s_list, 2, &tlist[0] ); + } +} + +static void pdp_frei0r_sendpacket(t_pdp_frei0r *x) +{ + /* release the incoming packets */ + pdp_packet_mark_unused(x->x_packet0); + x->x_packet0 = -1; + pdp_packet_mark_unused(x->x_packet1); + x->x_packet1 = -1; + pdp_packet_mark_unused(x->x_packetr0); + x->x_packetr0 = -1; + pdp_packet_mark_unused(x->x_packetr1); + x->x_packetr1 = -1; + pdp_packet_mark_unused(x->x_packetm0); + x->x_packetm0 = -1; + pdp_packet_mark_unused(x->x_packetm1); + x->x_packetm1 = -1; + + x->x_packet3=-1; + x->x_dropped = pdp_packet_convert_ro_or_drop(&x->x_packet3, x->x_packet2, pdp_gensym("bitmap/rgb/*") ); + pdp_packet_mark_unused(x->x_packet2); + x->x_packet2 = -1; + + /* unregister and propagate if valid dest packet */ + pdp_packet_pass_if_valid(x->x_outlet0, &x->x_packet3); +} + +static void pdp_frei0r_process(t_pdp_frei0r *x) +{ + int encoding; + t_pdp *header = 0; + char *parname; + unsigned pi; + int partype; + t_atom plist[2]; + t_atom tlist[2]; + t_atom vlist[2]; + f0r_param_info_t param_infos; + + /* check if image data packets are compatible */ + if ( (header = pdp_packet_header(x->x_packet1)) + && (PDP_BITMAP == header->type)){ + + /* pdp_frei0r_process inputs and write into active inlet */ + switch(pdp_packet_header(x->x_packet1)->info.image.encoding){ + + case PDP_BITMAP_RGBA: + x->x_packet2 = pdp_packet_clone_rw(x->x_packet1); + pdp_queue_add(x, pdp_frei0r_process_rgba, pdp_frei0r_sendpacket, &x->x_queue_id); + break; + + default: + /* don't know the type, so dont pdp_frei0r_process */ + break; + + } + } + + // hack to display infos of first loaded plugin + if ( ( x->x_plugin_count>0 ) && ( !x->x_infosok ) ) + { + outlet_symbol(x->x_pname, gensym( x->plugins[x->x_plugin].name ) ); + outlet_float(x->x_nparams, (float)x->plugins[x->x_plugin].numparameters); + for ( pi=0; piplugins[x->x_plugin].numparameters; pi++ ) + { + (*x->plugins[x->x_plugin].f0r_get_param_info)(¶m_infos, pi); + SETFLOAT(&plist[0], pi); + SETSYMBOL(&plist[1], gensym(param_infos.name) ); + outlet_list( x->x_parname, &s_list, 2, &plist[0] ); + SETFLOAT(&tlist[0], pi); + SETFLOAT(&tlist[1], param_infos.type ); + outlet_list( x->x_partype, &s_list, 2, &tlist[0] ); + } + x->x_infosok = 1; + } +} + +static void pdp_frei0r_input_0(t_pdp_frei0r *x, t_symbol *s, t_floatarg f) +{ + if (s == gensym("register_rw")) + { + x->x_packet0=-1; + x->x_dropped = pdp_packet_convert_ro_or_drop(&x->x_packet0, (int)f, pdp_gensym("bitmap/rgb/*") ); + // post("pdp_freiOr : drop 1 : %d", x->x_dropped ); + x->x_packet1=-1; + x->x_dropped = pdp_packet_convert_ro_or_drop(&x->x_packet1, x->x_packet0, pdp_gensym("bitmap/rgba/*") ); + // post("pdp_freiOr : drop 2 : %d", x->x_dropped ); + } + + if ((s == gensym("process")) && (-1 != x->x_packet1) && (!x->x_dropped)) + { + /* add the process method and callback to the process queue */ + pdp_frei0r_process(x); + } +} + +static void pdp_frei0r_input_1(t_pdp_frei0r *x, t_symbol *s, t_floatarg f) +{ + char *ddata; + char *sdata; + + if ( x->x_packetm0 != -1 ) + { + return; + } + x->x_dropped = pdp_packet_convert_rw_or_drop(&x->x_packetm0, (int)f, pdp_gensym("bitmap/rgb/*") ); + // post("pdp_freiOr : middle drop 1 : %d", x->x_dropped ); + x->x_dropped = pdp_packet_convert_rw_or_drop(&x->x_packetm1, x->x_packetm0, pdp_gensym("bitmap/rgba/*") ); + // post("pdp_freiOr : middle drop 2 : %d", x->x_dropped ); +} + +static void pdp_frei0r_input_2(t_pdp_frei0r *x, t_symbol *s, t_floatarg f) +{ + char *ddata; + char *sdata; + + if ( x->x_packetr0 != -1 ) + { + return; + } + x->x_dropped = pdp_packet_convert_rw_or_drop(&x->x_packetr0, (int)f, pdp_gensym("bitmap/rgb/*") ); + // post("pdp_freiOr : right drop 1 : %d", x->x_dropped ); + x->x_dropped = pdp_packet_convert_rw_or_drop(&x->x_packetr1, x->x_packetr0, pdp_gensym("bitmap/rgba/*") ); + // post("pdp_freiOr : right drop 2 : %d", x->x_dropped ); +} + +static void pdp_frei0r_free(t_pdp_frei0r *x) +{ + int i; + + pdp_queue_finish(x->x_queue_id); + pdp_packet_mark_unused(x->x_packet0); + fr_freeplugins(x); +} + +t_class *pdp_frei0r_class; + +void *pdp_frei0r_new(t_floatarg f) +{ + int i; + + t_pdp_frei0r *x = (t_pdp_frei0r *)pd_new(pdp_frei0r_class); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("pdp"), gensym("pdp1") ); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("pdp"), gensym("pdp2") ); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("plugin")); + + x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); + x->x_pname = outlet_new(&x->x_obj, &s_anything); + x->x_nparams = outlet_new(&x->x_obj, &s_anything); + x->x_parname = outlet_new(&x->x_obj, &s_anything); + x->x_partype = outlet_new(&x->x_obj, &s_anything); + + x->x_packet0 = -1; + x->x_packet1 = -1; + x->x_packet2 = -1; + x->x_packet3 = -1; + x->x_packetm0 = -1; + x->x_packetm1 = -1; + x->x_packetr0 = -1; + x->x_packetr1 = -1; + x->x_queue_id = -1; + + x->x_width = 320; + x->x_height = 240; + x->x_size = x->x_width * x->x_height; + + //load the plugins + x->x_plugin_count = 0; + x->x_infosok = 0; + fr_loadplugins(x, FR_PLUGIN_DIR); + + //select plugin + pdp_frei0r_plugin(x, f); + + return (void *)x; +} + + +#ifdef __cplusplus +extern "C" +{ +#endif + + +void pdp_frei0r_setup(void) +{ + + post( "pdp_frei0r :: frei0r host for Pure Data Packet version 0.1\n by Lluis Gomez i Bigorda (lluis@artefacte.org) \n & Yves Degoyon (ydegoyon@free.fr)\n using frei0r specification 1.1 by Georg Seidel,\n Phillip Promesberger and Martin Bayer\n made at piksel yearly gathering : http://www.piksel.no" ); + pdp_frei0r_class = class_new(gensym("pdp_frei0r"), (t_newmethod)pdp_frei0r_new, + (t_method)pdp_frei0r_free, sizeof(t_pdp_frei0r), 0, A_DEFFLOAT, A_NULL); + + class_addmethod(pdp_frei0r_class, (t_method)pdp_frei0r_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); + class_addmethod(pdp_frei0r_class, (t_method)pdp_frei0r_input_1, gensym("pdp1"), A_SYMBOL, A_DEFFLOAT, A_NULL); + class_addmethod(pdp_frei0r_class, (t_method)pdp_frei0r_input_2, gensym("pdp2"), A_SYMBOL, A_DEFFLOAT, A_NULL); + class_addmethod(pdp_frei0r_class, (t_method)pdp_frei0r_plugin, gensym("plugin"), A_FLOAT, A_NULL); + class_addmethod(pdp_frei0r_class, (t_method)pdp_frei0r_param, gensym("param"), A_GIMME, A_NULL); + +} + +#ifdef __cplusplus +} +#endif -- cgit v1.2.1