aboutsummaryrefslogtreecommitdiff
path: root/pdp_freeframe
diff options
context:
space:
mode:
Diffstat (limited to 'pdp_freeframe')
-rwxr-xr-xpdp_freeframe/CHANGES.LOG6
-rw-r--r--pdp_freeframe/FreeFrame.h233
-rw-r--r--pdp_freeframe/INSTALL21
-rw-r--r--pdp_freeframe/Makefile16
-rw-r--r--pdp_freeframe/Makefile.config25
-rw-r--r--pdp_freeframe/help_pdp_freeframe.pd206
-rw-r--r--pdp_freeframe/pdp_freeframe.c461
7 files changed, 968 insertions, 0 deletions
diff --git a/pdp_freeframe/CHANGES.LOG b/pdp_freeframe/CHANGES.LOG
new file mode 100755
index 0000000..46f7ad7
--- /dev/null
+++ b/pdp_freeframe/CHANGES.LOG
@@ -0,0 +1,6 @@
+0.3
+ added parameters details
+0.2
+ simplified RGB conversions
+0.1
+ initial release
diff --git a/pdp_freeframe/FreeFrame.h b/pdp_freeframe/FreeFrame.h
new file mode 100644
index 0000000..7ca7f75
--- /dev/null
+++ b/pdp_freeframe/FreeFrame.h
@@ -0,0 +1,233 @@
+#ifndef __FREEFRAME_H__
+#define __FREEFRAME_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * FreeFrame.h
+ *
+ * FreeFrame Open Video Plugin Prototype
+ * C Version
+ *
+ * www.freeframe.org
+ * marcus@freeframe.org
+ *
+ *
+ *
+ * Copyright (c) 2002, Marcus Clements www.freeframe.org
+ * All rights reserved.
+ *
+ * FreeFrame 1.0 upgrade by Pete Warden
+ * www.petewarden.com
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of FreeFrame nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * includes
+ */
+
+#ifdef WIN32
+
+#if _MSC_VER > 1000
+#pragma once
+#endif /* _MSC_VER > 1000 */
+
+#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
+#include <windows.h>
+
+#elif defined LINUX
+
+typedef unsigned int DWORD;
+typedef void *LPVOID;
+typedef unsigned char BYTE;
+
+#elif defined MACOS
+
+typedef unsigned int DWORD;
+typedef unsigned char BYTE;
+
+#endif
+
+
+/*
+ * #defines
+ */
+
+#define FF_EFFECT 0
+#define FF_SOURCE 1
+
+#define FF_FAIL 0xFFFFFFFF
+#define FF_SUCCESS 0
+#define FF_TRUE 1
+#define FF_FALSE 0
+#define FF_SUPPORTED 1
+#define FF_UNSUPPORTED 0
+
+#define FF_GETINFO 0
+#define FF_INITIALISE 1
+#define FF_DEINITIALISE 2
+#define FF_PROCESSFRAME 3
+#define FF_GETNUMPARAMETERS 4
+#define FF_GETPARAMETERNAME 5
+#define FF_GETPARAMETERDEFAULT 6
+#define FF_GETPARAMETERDISPLAY 7
+#define FF_SETPARAMETER 8
+#define FF_GETPARAMETER 9
+#define FF_GETPLUGINCAPS 10
+#define FF_INSTANTIATE 11
+#define FF_DEINSTANTIATE 12
+#define FF_GETEXTENDEDINFO 13
+#define FF_PROCESSFRAMECOPY 14
+#define FF_GETPARAMETERTYPE 15
+
+#define FF_CAP_16BITVIDEO 0
+#define FF_CAP_24BITVIDEO 1
+#define FF_CAP_32BITVIDEO 2
+#define FF_CAP_PROCESSFRAMECOPY 3
+#define FF_CAP_MINIMUMINPUTFRAMES 10
+#define FF_CAP_MAXIMUMINPUTFRAMES 11
+#define FF_CAP_COPYORINPLACE 15
+
+#define FF_CAP_PREFER_NONE 0
+#define FF_CAP_PREFER_INPLACE 1
+#define FF_CAP_PREFER_COPY 2
+#define FF_CAP_PREFER_BOTH 3
+
+#define FF_TYPE_BOOLEAN 0
+#define FF_TYPE_EVENT 1
+#define FF_TYPE_RED 2
+#define FF_TYPE_GREEN 3
+#define FF_TYPE_BLUE 4
+#define FF_TYPE_XPOS 5
+#define FF_TYPE_YPOS 6
+#define FF_TYPE_STANDARD 10
+#define FF_TYPE_TEXT 100
+
+/*
+ * FreeFrame types
+ */
+
+typedef struct PlugInfoStructTag {
+ DWORD APIMajorVersion;
+ DWORD APIMinorVersion;
+ BYTE uniqueID[4]; /* 4 chars uniqueID - not null terminated */
+ BYTE pluginName[16]; /* 16 chars plugin friendly name - not null terminated */
+ DWORD pluginType; /* Effect or source */
+} PlugInfoStruct;
+
+typedef struct PlugExtendedInfoStructTag {
+ DWORD PluginMajorVersion;
+ DWORD PluginMinorVersion;
+ char* Description;
+ char* About;
+ DWORD FreeFrameExtendedDataSize;
+ void* FreeFrameExtendedDataBlock;
+} PlugExtendedInfoStruct;
+
+typedef struct VideoInfoStructTag {
+ DWORD frameWidth; /* width of frame in pixels */
+ DWORD frameHeight; /* height of frame in pixels */
+ DWORD bitDepth; /* enumerated indicator of bit depth of video */
+ /* 0 = 16 bit 5-6-5 1 = 24bit packed 2 = 32bit */
+ DWORD orientation; /* video frame orientation meaningful values:
+ 1 = origin at top left 2 = origin at bottom left */
+
+} VideoInfoStruct;
+
+typedef struct ProcessFrameCopyStructTag {
+ DWORD numInputFrames;
+ void** InputFrames;
+ void* OutputFrame;
+} ProcessFrameCopyStruct;
+
+typedef struct SetParameterStructTag {
+ DWORD index;
+ float value;
+} SetParameterStruct;
+
+typedef union {
+ DWORD ivalue;
+ float fvalue;
+ char *svalue;
+} ParameterValue;
+
+typedef union plugMainUnionTag {
+ DWORD ivalue;
+ float fvalue;
+ VideoInfoStruct *VISvalue;
+ PlugInfoStruct *PISvalue;
+ char *svalue;
+} plugMainUnion;
+
+typedef plugMainUnion plugMainType(DWORD, LPVOID, DWORD);
+
+/*
+ * Function prototypes
+ */
+
+/*
+ * plugMain - The one and only exposed function
+ * parameters:
+ * functionCode - tells the plugin which function is being called
+ * pParam - 32-bit parameter or 32-bit pointer to parameter structure
+ *
+ * PLUGIN DEVELOPERS: you shouldn't need to change this function
+ *
+ * All parameters are cast as 32-bit untyped pointers and cast to appropriate
+ * types here
+ *
+ * All return values are cast to 32-bit untyped pointers here before return to
+ * the host
+ *
+ *
+ */
+
+#ifdef WIN32
+
+BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, DWORD lpReserved );
+
+__declspec(dllexport) LPVOID __stdcall plugMain(DWORD functionCode, LPVOID pParam, DWORD reserved);
+
+typedef __declspec(dllimport) LPVOID (__stdcall *FF_Main_FuncPtr)(DWORD, LPVOID, DWORD);
+
+#elif LINUX
+
+plugMainUnion plugMain(DWORD functionCode, LPVOID pParam, DWORD reserved);
+
+
+#elif MACOS
+
+typedef LPVOID (*FF_Main_FuncPtr)(DWORD, LPVOID, DWORD);
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/pdp_freeframe/INSTALL b/pdp_freeframe/INSTALL
new file mode 100644
index 0000000..74dc31e
--- /dev/null
+++ b/pdp_freeframe/INSTALL
@@ -0,0 +1,21 @@
+1. Download FreeFrame1.0-05.tar.gz from http://sourceforge.net/projects/freeframe/
+
+ untar and cd to the FreeFrame1.0-05 directory
+ you have the binary plugins in the plugins_bin directory but you will need to compile the plugins to be sure that work.
+ compile the plugins::
+ cd to plugins_src/PetesPluginsLinux/ and type 'make'
+
+2. Download pdp_freeframe.tar.gz from http://www.artefacte.org/pd/pdp_freeframe.tar.gz
+
+ untar the pdp_freeframe.tar.gz file
+ cd in to the pdp_freeframe directory
+
+ edit the Makefile.config file and change the path to the pd and pdp sources i
+ and to the Free Frame plugins (*.so files)
+
+ type 'make'
+
+ to load the pdp_freeframe help file type 'pd -nrt -lib pdp:pdp_freeframe help_pdp_freeframe.pd'
+
+
+
diff --git a/pdp_freeframe/Makefile b/pdp_freeframe/Makefile
new file mode 100644
index 0000000..60c358b
--- /dev/null
+++ b/pdp_freeframe/Makefile
@@ -0,0 +1,16 @@
+current: all
+
+include Makefile.config
+
+PDP_MOD = pdp_freeframe.o
+
+
+# build basic image processing modules (derived from base class)
+all: $(PDP_MOD)
+ $(CC) -export_dynamic -shared -o pdp_freeframe.pd_linux *.o $(PDP_LIBS)
+
+clean:
+ rm -f *~
+ rm -f *.o
+ rm -f *.pd_linux
+
diff --git a/pdp_freeframe/Makefile.config b/pdp_freeframe/Makefile.config
new file mode 100644
index 0000000..2d0444b
--- /dev/null
+++ b/pdp_freeframe/Makefile.config
@@ -0,0 +1,25 @@
+# if configure can't find the m_pd.h header
+# specify pd's include path here and ignore the warning
+#
+FF_PLUGIN_DIR=/usr/lib/FreeFrame
+PD_CPPFLAGS=-I/usr/src/pd-0.40-2/src
+PDP_CFLAGS=-I/usr/src/pdp-0.12.5-test-7/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
+PDP_VERSION = 0.0.1
+PDP_TARGET = linux
+PDP_LIBRARY_NAME = pdp_freeframe.pd_linux
+
+PDP_CPPFLAGS = -I. -I/usr/X11R6/include -I../include -I../../include $(PD_CPPFLAGS)
+#--gstabs
+
+PDP_CFLAGS += -DPDP_VERSION=\"$(PDP_VERSION)\" -DFF_PLUGIN_DIR=\"$(FF_PLUGIN_DIR)\"
+
+CC = gcc
+
+# build rules
+
+.c.o:
+ $(CC) $(PDP_CFLAGS) $(PDP_CPPFLAGS) -o $*.o -c $*.c
+.s.o:
+ $(AS) -o $*.o $*.s $(PDP_AFLAGS)
diff --git a/pdp_freeframe/help_pdp_freeframe.pd b/pdp_freeframe/help_pdp_freeframe.pd
new file mode 100644
index 0000000..5eb6555
--- /dev/null
+++ b/pdp_freeframe/help_pdp_freeframe.pd
@@ -0,0 +1,206 @@
+#N canvas 0 0 996 665 10;
+#X obj 43 335 pdp_freeframe;
+#X floatatom 149 338 5 0 0 0 - - -;
+#X obj 46 115 pdp_qt;
+#X obj 46 45 metro 40;
+#X msg 46 -17 bang;
+#X msg 107 45 loop 1;
+#X obj 41 507 pdp_xv;
+#X obj 46 247 pdp_scale 320 240;
+#X obj 194 336 hradio 15 1 0 44 empty empty empty 0 -6 0 8 -262144
+-1 -1 0;
+#X obj 261 171 hsl 128 15 0 1 0 0 empty vparam3 empty -2 -6 0 8 -262144
+-1 -1 0 1;
+#X obj 401 171 hsl 128 15 0 1 0 0 empty vparam4 empty -2 -6 0 8 -262144
+-1 -1 0 1;
+#X obj 541 171 hsl 128 15 0 1 0 0 empty vparam5 empty -2 -6 0 8 -262144
+-1 -1 0 1;
+#X msg 258 191 param 3 \$1;
+#X msg 398 190 param 4 \$1;
+#X msg 539 190 param 5 \$1;
+#X text 195 317 Select the plugin;
+#X text 258 72 Adjust plugin parameters.;
+#X msg 164 45 open \$1;
+#X obj 164 23 openpanel;
+#X text 95 -17 Load a mov file;
+#X symbolatom 96 488 20 0 0 0 - - -;
+#X text 249 488 <-- plugin name;
+#X floatatom 115 466 5 0 0 0 - - -;
+#X text 163 464 <-- number of parameters;
+#X obj 46 176 pdp_spigot;
+#X obj 119 148 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
+1;
+#X obj 89 215 pdp_scale 192 168;
+#X obj 241 47 pdp_v4l;
+#X obj 241 20 metro 40;
+#X msg 241 -8 bang;
+#X text 214 438 <-- parameter name;
+#X text 241 410 <-- parameter type;
+#X text 257 381 <-- parameter default;
+#X obj 263 112 hsl 128 15 0 1 0 0 empty vparam0 empty -2 -6 0 8 -262144
+-1 -1 0 1;
+#X obj 401 112 hsl 128 15 0 1 0 0 empty vparam1 empty -2 -6 0 8 -262144
+-1 -1 2391 1;
+#X obj 542 112 hsl 128 15 0 1 0 0 empty vparam2 empty -2 -6 0 8 -262144
+-1 -1 0 1;
+#X obj 261 234 hsl 128 15 0 1 0 0 empty vparam6 empty -2 -6 0 8 -262144
+-1 -1 0 1;
+#X obj 402 234 hsl 128 15 0 1 0 0 empty vparam7 empty -2 -6 0 8 -262144
+-1 -1 0 1;
+#X obj 544 234 hsl 128 15 0 1 0 0 empty vparam8 empty -2 -6 0 8 -262144
+-1 -1 0 1;
+#X msg 260 131 param 0 \$1;
+#X msg 398 131 param 1 \$1;
+#X msg 539 131 param 2 \$1;
+#X msg 260 254 param 6 \$1;
+#X msg 399 253 param 7 \$1;
+#X msg 541 253 param 8 \$1;
+#N canvas 0 0 996 665 pname 0;
+#X obj 51 119 l2s;
+#X obj 80 119 l2s;
+#X obj 111 119 l2s;
+#X obj 143 119 l2s;
+#X obj 207 120 l2s;
+#X obj 236 120 l2s;
+#X obj 267 120 l2s;
+#X obj 298 119 l2s;
+#X obj 97 86 route 0 1 2 3 4 5 6 7 8;
+#X obj 327 119 l2s;
+#X obj 97 51 inlet;
+#X obj 51 154 s ffparam0;
+#X obj 79 178 s ffparam1;
+#X obj 118 205 s ffparam2;
+#X obj 148 227 s ffparam3;
+#X obj 185 157 s ffparam4;
+#X obj 213 181 s ffparam5;
+#X obj 255 206 s ffparam6;
+#X obj 283 230 s ffparam7;
+#X obj 305 155 s ffparam8;
+#X obj 391 53 inlet;
+#X msg 390 79 symbol;
+#X connect 0 0 11 0;
+#X connect 1 0 12 0;
+#X connect 2 0 13 0;
+#X connect 3 0 14 0;
+#X connect 4 0 15 0;
+#X connect 5 0 16 0;
+#X connect 6 0 17 0;
+#X connect 7 0 18 0;
+#X connect 8 0 0 0;
+#X connect 8 1 1 0;
+#X connect 8 2 2 0;
+#X connect 8 3 3 0;
+#X connect 8 4 4 0;
+#X connect 8 5 5 0;
+#X connect 8 6 6 0;
+#X connect 8 7 7 0;
+#X connect 8 8 9 0;
+#X connect 9 0 19 0;
+#X connect 10 0 8 0;
+#X connect 20 0 21 0;
+#X connect 21 0 11 0;
+#X connect 21 0 12 0;
+#X connect 21 0 13 0;
+#X connect 21 0 14 0;
+#X connect 21 0 15 0;
+#X connect 21 0 16 0;
+#X connect 21 0 17 0;
+#X connect 21 0 18 0;
+#X connect 21 0 19 0;
+#X restore 146 438 pd pname;
+#X symbolatom 260 93 18 0 0 0 - ffparam0 -;
+#X symbolatom 399 92 18 0 0 0 - ffparam1 -;
+#X symbolatom 538 92 18 0 0 0 - ffparam2 -;
+#X symbolatom 261 154 18 0 0 0 - ffparam3 -;
+#X symbolatom 400 153 18 0 0 0 - ffparam4 -;
+#X symbolatom 539 153 18 0 0 0 - ffparam5 -;
+#X symbolatom 261 214 18 0 0 0 - ffparam6 -;
+#X symbolatom 400 213 18 0 0 0 - ffparam7 -;
+#X symbolatom 539 213 18 0 0 0 - ffparam8 -;
+#N canvas 0 0 996 665 default 0;
+#X obj 97 86 route 0 1 2 3 4 5 6 7 8;
+#X obj 97 51 inlet;
+#X obj 391 53 inlet;
+#X obj 51 154 s vparam0;
+#X obj 393 114 float 0;
+#X msg 392 88 bang;
+#X obj 79 178 s vparam1;
+#X obj 118 205 s vparam2;
+#X obj 148 227 s vparam3;
+#X obj 184 159 s vparam4;
+#X obj 213 181 s vparam5;
+#X obj 255 206 s vparam6;
+#X obj 283 230 s vparam7;
+#X obj 304 155 s vparam8;
+#X connect 0 0 3 0;
+#X connect 0 1 6 0;
+#X connect 0 2 7 0;
+#X connect 0 3 8 0;
+#X connect 0 4 9 0;
+#X connect 0 5 10 0;
+#X connect 0 6 11 0;
+#X connect 0 7 12 0;
+#X connect 0 8 13 0;
+#X connect 1 0 0 0;
+#X connect 2 0 5 0;
+#X connect 4 0 3 0;
+#X connect 4 0 6 0;
+#X connect 4 0 7 0;
+#X connect 4 0 8 0;
+#X connect 4 0 9 0;
+#X connect 4 0 10 0;
+#X connect 4 0 11 0;
+#X connect 4 0 12 0;
+#X connect 4 0 13 0;
+#X connect 5 0 4 0;
+#X restore 180 380 pd default;
+#X text 487 440 FreeFrame host for Pure Data Packet version 0.3;
+#X text 489 455 by Lluis Gomez i Bigorda (lluis@artefacte.org);
+#X text 508 468 & Yves Degoyon (ydegoyon@free.fr);
+#X text 489 483 using GPL code from http://freeframe.sf.net;
+#X text 489 498 and Pete Warden http://petewarden.com;
+#X obj 164 410 print type;
+#X connect 0 0 6 0;
+#X connect 0 1 20 0;
+#X connect 0 2 22 0;
+#X connect 0 3 45 0;
+#X connect 0 4 61 0;
+#X connect 0 5 55 0;
+#X connect 1 0 0 1;
+#X connect 2 0 24 0;
+#X connect 3 0 2 0;
+#X connect 4 0 3 0;
+#X connect 4 0 5 0;
+#X connect 4 0 18 0;
+#X connect 5 0 2 0;
+#X connect 7 0 0 0;
+#X connect 8 0 1 0;
+#X connect 9 0 12 0;
+#X connect 10 0 13 0;
+#X connect 11 0 14 0;
+#X connect 12 0 0 0;
+#X connect 13 0 0 0;
+#X connect 14 0 0 0;
+#X connect 17 0 2 0;
+#X connect 18 0 17 0;
+#X connect 22 0 45 1;
+#X connect 22 0 55 1;
+#X connect 24 0 7 0;
+#X connect 24 1 26 0;
+#X connect 25 0 24 1;
+#X connect 26 0 0 0;
+#X connect 27 0 24 0;
+#X connect 28 0 27 0;
+#X connect 29 0 28 0;
+#X connect 33 0 39 0;
+#X connect 34 0 40 0;
+#X connect 35 0 41 0;
+#X connect 36 0 42 0;
+#X connect 37 0 43 0;
+#X connect 38 0 44 0;
+#X connect 39 0 0 0;
+#X connect 40 0 0 0;
+#X connect 41 0 0 0;
+#X connect 42 0 0 0;
+#X connect 43 0 0 0;
+#X connect 44 0 0 0;
diff --git a/pdp_freeframe/pdp_freeframe.c b/pdp_freeframe/pdp_freeframe.c
new file mode 100644
index 0000000..7eaf1cc
--- /dev/null
+++ b/pdp_freeframe/pdp_freeframe.c
@@ -0,0 +1,461 @@
+/*
+ * Pure Data Packet module.
+ * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org>
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <dirent.h>
+#include <limits.h>
+#include <dlfcn.h>
+
+#include "pdp.h"
+#include "FreeFrame.h"
+
+#define PLUGINDIR "plugins"
+#define FREEFRAME_PNAME_LENGTH 16
+#define FREEFRAME_ID_LENGTH 4
+#define FREEFRAME_PARAM_DETAILS_LENGTH 128
+
+#define FF_CAP_V_BITS_VIDEO FF_CAP_24BITVIDEO
+
+typedef struct
+{
+ char name[FREEFRAME_PNAME_LENGTH+1];
+ plugMainType *plugmain;
+ unsigned instance;
+ unsigned numparameters;
+} PLUGIN;
+
+typedef struct pdp_freeframe_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;
+ t_outlet *x_pardefault;
+ int x_packet0;
+ int x_packet1;
+ 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;
+ char x_pdetails[FREEFRAME_PARAM_DETAILS_LENGTH];
+
+ PLUGIN *plugins;
+
+} t_pdp_freeframe;
+
+
+void panic(const char *panicstr, ...)
+{
+ post("pdp_freeframe :: 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_freeframe *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 ff_loadplugins(t_pdp_freeframe *x, char *plugindir)
+{
+ char libname[PATH_MAX];
+ plugMainType *plugmain;
+ 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; i<x->x_filename_count; i++)
+ {
+ pluginname = x->x_filename_list[i]->d_name;
+
+ snprintf(libname, PATH_MAX, "%s/%s", plugindir, pluginname);
+
+ plugin_handle = dlopen(libname, RTLD_NOW);
+ dlerror();
+ plugmain = (plugMainType *)(unsigned)dlsym(plugin_handle, "plugMain");
+ if (plugmain == NULL)
+ panic("plugin %s: %s", x->x_filename_list[i]->d_name, dlerror());
+
+ PlugInfoStruct *pis = (plugmain(FF_GETINFO, NULL, 0)).PISvalue;
+
+ if ((plugmain(FF_GETPLUGINCAPS, (LPVOID)FF_CAP_V_BITS_VIDEO, 0)).ivalue != FF_TRUE)
+ panic("plugin %s: no 24 bit support", pluginname);
+
+ if (pis->APIMajorVersion < 1)
+ panic("plugin %s: old api version", pluginname);
+
+ if ((plugmain(FF_INITIALISE, NULL, 0)).ivalue == FF_FAIL)
+ panic("plugin %s: init failed", pluginname);
+
+ VideoInfoStruct vidinfo;
+ vidinfo.frameWidth = x->x_width;
+ vidinfo.frameHeight = x->x_height;
+ vidinfo.orientation = 1;
+ vidinfo.bitDepth = FF_CAP_V_BITS_VIDEO;
+
+ instance = plugmain(FF_INSTANTIATE, &vidinfo, 0).ivalue;
+ if (instance == FF_FAIL)
+ panic("plugin %s: init failed", pluginname);
+
+ numparameters = plugmain(FF_GETNUMPARAMETERS, NULL, 0).ivalue;
+ if (numparameters == FF_FAIL)
+ panic("plugin %s: numparameters failed", pluginname);
+
+ x->plugins[x->x_plugin_count].plugmain = plugmain;
+
+ strncpy(x->plugins[x->x_plugin_count].name, (char *)(pis->pluginName), 16);
+ x->plugins[x->x_plugin_count].name[16] = 0;
+
+ x->plugins[x->x_plugin_count].instance = instance;
+ x->plugins[x->x_plugin_count].numparameters = numparameters;
+
+ post("%s [%s] is loaded", x->plugins[x->x_plugin_count].name, pluginname);
+ x->x_plugin_count++;
+ }
+}
+
+void ff_processframe(t_pdp_freeframe *x, int plugin, void *buffer)
+{
+ x->plugins[plugin].plugmain(FF_PROCESSFRAME, buffer, x->plugins[plugin].instance);
+}
+
+void ff_freeplugins(t_pdp_freeframe *x)
+{
+ t_int i;
+
+ for (i=0; i<x->x_plugin_count; i++)
+ {
+ plugMainType *plugmain = x->plugins[i].plugmain;
+
+ plugmain(FF_DEINITIALISE, NULL, 0);
+ plugmain(FF_DEINSTANTIATE, NULL, 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_freeframe_process_rgb(t_pdp_freeframe *x)
+{
+ t_pdp *header = pdp_packet_header(x->x_packet0);
+ short int *data = (short int *)pdp_packet_data(x->x_packet0);
+ t_pdp *newheader = pdp_packet_header(x->x_packet1);
+ short int *newdata = (short int *)pdp_packet_data(x->x_packet1);
+
+ if ( x->x_plugin_count <= 0 )
+ {
+ return;
+ }
+
+ if ((x->x_width != (t_int)header->info.image.width) ||
+ (x->x_height != (t_int)header->info.image.height))
+ {
+
+ post("pdp_freeframe :: resizing plugins");
+
+ ff_freeplugins(x);
+
+ x->x_width = header->info.image.width;
+ x->x_height = header->info.image.height;
+ x->x_size = x->x_width*x->x_height;
+
+ //load the plugins
+ ff_loadplugins(x, FF_PLUGIN_DIR);
+ }
+
+ newheader->info.image.encoding = header->info.image.encoding;
+ newheader->info.image.width = x->x_width;
+ newheader->info.image.height = x->x_height;
+
+ memcpy( newdata, data, x->x_size*3 );
+
+ ff_processframe(x, x->x_plugin, newdata);
+
+ return;
+}
+
+static void pdp_freeframe_param(t_pdp_freeframe *x, t_floatarg f1, t_floatarg f2)
+{
+ int i=0;
+ plugMainType *plugmain = x->plugins[x->x_plugin].plugmain;
+ unsigned instance = x->plugins[x->x_plugin].instance;
+ unsigned numparameters = x->plugins[x->x_plugin].numparameters;
+
+ SetParameterStruct sps;
+
+ //for (i=0; i<numparameters; i++)
+ //{
+ //if (plugmain(FF_GETPARAMETERTYPE, (LPVOID)i, 0).ivalue == FF_TYPE_TEXT)
+ // continue;
+
+ //sps.value = plugmain(FF_GETPARAMETER, (LPVOID)i, instance).fvalue;
+
+ //post ("%d param.value %d", i, sps.value);
+
+ //if((f2<=1)&&(f2>=0))
+ sps.value = f2;
+ //sps.value += .01;
+ //if (sps.value > 1.0) sps.value = 1.0;
+ //else
+ //if (sps.value < 0.0) sps.value = 0.0;
+
+ sps.index = f1;
+ plugmain(FF_SETPARAMETER, &sps, instance);
+ //}
+}
+
+static void pdp_freeframe_plugin(t_pdp_freeframe *x, t_floatarg f)
+{
+ unsigned pi;
+ char *parname;
+ int partype;
+ float pardefault;
+ t_atom plist[2];
+ t_atom tlist[2];
+ t_atom vlist[2];
+
+ if ( x->x_plugin_count <= 0 )
+ {
+ post( "freeframe : no plugins loaded, check your plugin directory setup" );
+ return;
+ }
+ if((f<x->x_plugin_count)&&(f>-1))
+ {
+ x->x_plugin = f;
+ }
+ else
+ {
+ post( "freeframe : 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; pi<x->plugins[x->x_plugin].numparameters; pi++ )
+ {
+ parname = (x->plugins[x->x_plugin].plugmain(FF_GETPARAMETERNAME, (LPVOID)pi, 0)).svalue;
+ SETFLOAT(&plist[0], pi);
+ SETSYMBOL(&plist[1], gensym(parname) );
+ outlet_list( x->x_parname, &s_list, 2, &plist[0] );
+ }
+ for ( pi=0; pi<x->plugins[x->x_plugin].numparameters; pi++ )
+ {
+ partype = (x->plugins[x->x_plugin].plugmain(FF_GETPARAMETERTYPE, (LPVOID)pi, 0)).ivalue;
+ SETFLOAT(&tlist[0], pi);
+ SETFLOAT(&tlist[1], partype );
+ outlet_list( x->x_partype, &s_list, 2, &tlist[0] );
+ if ( ( partype != FF_TYPE_TEXT ) && ( partype > 0 ) )
+ {
+ pardefault = (x->plugins[x->x_plugin].plugmain(FF_GETPARAMETERDEFAULT, (LPVOID)pi, 0)).fvalue;
+ SETFLOAT(&vlist[0], pi);
+ SETFLOAT(&vlist[1], pardefault );
+ outlet_list( x->x_pardefault, &s_list, 2, &vlist[0] );
+ }
+ }
+}
+
+static void pdp_freeframe_sendpacket(t_pdp_freeframe *x)
+{
+ /* release the packet */
+ pdp_packet_mark_unused(x->x_packet0);
+ x->x_packet0 = -1;
+
+ /* unregister and propagate if valid dest packet */
+ pdp_packet_pass_if_valid(x->x_outlet0, &x->x_packet1);
+}
+
+static void pdp_freeframe_process(t_pdp_freeframe *x)
+{
+ int encoding;
+ t_pdp *header = 0;
+ char *parname;
+ unsigned pi;
+ int partype;
+ float pardefault;
+ t_atom plist[2];
+ t_atom tlist[2];
+ t_atom vlist[2];
+
+ /* check if image data packets are compatible */
+ if ( (header = pdp_packet_header(x->x_packet0))
+ && (PDP_BITMAP == header->type)){
+
+ /* pdp_freeframe_process inputs and write into active inlet */
+ switch(pdp_packet_header(x->x_packet0)->info.image.encoding){
+
+ case PDP_BITMAP_RGB:
+ x->x_packet1 = pdp_packet_clone_rw(x->x_packet0);
+ pdp_queue_add(x, pdp_freeframe_process_rgb, pdp_freeframe_sendpacket, &x->x_queue_id);
+ break;
+
+ default:
+ /* don't know the type, so dont pdp_freeframe_process */
+ break;
+
+ }
+ }
+
+ // hack to display infos of first loaded plugin
+ if ( (x->x_plugin_count > 0) && (!x->x_infosok) )
+ {
+ x->x_infosok = 1;
+ 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; pi<x->plugins[x->x_plugin].numparameters; pi++ )
+ {
+ parname = (x->plugins[x->x_plugin].plugmain(FF_GETPARAMETERNAME, (LPVOID)pi, 0)).svalue;
+ SETFLOAT(&plist[0], pi);
+ SETSYMBOL(&plist[1], gensym(parname) );
+ outlet_list( x->x_parname, &s_list, 2, &plist[0] );
+ }
+ for ( pi=0; pi<x->plugins[x->x_plugin].numparameters; pi++ )
+ {
+ partype = (x->plugins[x->x_plugin].plugmain(FF_GETPARAMETERTYPE, (LPVOID)pi, 0)).ivalue;
+ SETFLOAT(&tlist[0], pi);
+ SETFLOAT(&tlist[1], partype );
+ outlet_list( x->x_partype, &s_list, 2, &tlist[0] );
+ if ( ( partype != FF_TYPE_TEXT ) && ( partype > 0 ) )
+ {
+ pardefault = (x->plugins[x->x_plugin].plugmain(FF_GETPARAMETERDEFAULT, (LPVOID)pi, 0)).fvalue;
+ SETFLOAT(&vlist[0], pi);
+ SETFLOAT(&vlist[1], pardefault );
+ outlet_list( x->x_pardefault, &s_list, 2, &vlist[0] );
+ }
+ }
+ }
+}
+
+static void pdp_freeframe_input_0(t_pdp_freeframe *x, t_symbol *s, t_floatarg f)
+{
+ /* if this is a register_ro message or register_rw message, register with packet factory */
+
+ if (s == gensym("register_rw"))
+ x->x_dropped = pdp_packet_convert_ro_or_drop(&x->x_packet0, (int)f, pdp_gensym("bitmap/rgb/*") );
+
+ if ((s == gensym("process")) && (-1 != x->x_packet0) && (!x->x_dropped))
+ {
+ /* add the process method and callback to the process queue */
+ pdp_freeframe_process(x);
+ }
+}
+
+static void pdp_freeframe_free(t_pdp_freeframe *x)
+{
+ int i;
+
+ pdp_queue_finish(x->x_queue_id);
+ pdp_packet_mark_unused(x->x_packet0);
+ ff_freeplugins(x);
+}
+
+t_class *pdp_freeframe_class;
+
+
+void *pdp_freeframe_new(t_floatarg f)
+{
+ int i;
+
+ t_pdp_freeframe *x = (t_pdp_freeframe *)pd_new(pdp_freeframe_class);
+ 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_pardefault = outlet_new(&x->x_obj, &s_anything);
+
+ x->x_packet0 = -1;
+ x->x_packet1 = -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;
+ ff_loadplugins(x, FF_PLUGIN_DIR);
+
+ pdp_freeframe_plugin(x, f);
+
+ return (void *)x;
+}
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+void pdp_freeframe_setup(void)
+{
+
+ post( "pdp_freeframe :: FreeFrame host for Pure Data Packet version 0.3\n by Lluis Gomez i Bigorda (lluis@artefacte.org) \n & Yves Degoyon (ydegoyon@free.fr)\n using GPL code from http://freeframe.sf.net\n and Pete Warden http://petewarden.com" );
+ pdp_freeframe_class = class_new(gensym("pdp_freeframe"), (t_newmethod)pdp_freeframe_new,
+ (t_method)pdp_freeframe_free, sizeof(t_pdp_freeframe), 0, A_DEFFLOAT, A_NULL);
+
+ class_addmethod(pdp_freeframe_class, (t_method)pdp_freeframe_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL);
+ class_addmethod(pdp_freeframe_class, (t_method)pdp_freeframe_plugin, gensym("plugin"), A_FLOAT, A_NULL);
+ class_addmethod(pdp_freeframe_class, (t_method)pdp_freeframe_param, gensym("param"), A_FLOAT, A_FLOAT, A_NULL);
+
+
+}
+
+#ifdef __cplusplus
+}
+#endif