From 114361cedc4be57566c01afa858bad65fb8ff1e6 Mon Sep 17 00:00:00 2001 From: Niels Elburg Date: Wed, 27 Sep 2006 20:31:56 +0000 Subject: [PATCH] fixed v4l deinterlacer, added UI factory, bugfixes, speed up,many changes git-svn-id: svn://code.dyne.org/veejay/trunk@601 eb8d1916-c9e9-0310-b8de-cf0c9472ead5 --- veejay-ng/vevosample/Makefile.am | 2 +- veejay-ng/vevosample/ldefs.h | 97 ++ veejay-ng/vevosample/uifactory.c | 927 ++++++++++++++ veejay-ng/vevosample/uifactory.h | 94 ++ veejay-ng/vevosample/vevosample.c | 1929 ++++++++++++++--------------- veejay-ng/vevosample/vevosample.h | 13 +- veejay-ng/vevosample/vj-unicap.c | 188 ++- veejay-ng/vevosample/vj-unicap.h | 2 + 8 files changed, 2202 insertions(+), 1050 deletions(-) create mode 100644 veejay-ng/vevosample/ldefs.h create mode 100644 veejay-ng/vevosample/uifactory.c create mode 100644 veejay-ng/vevosample/uifactory.h diff --git a/veejay-ng/vevosample/Makefile.am b/veejay-ng/vevosample/Makefile.am index c2a18664..81eb9aa3 100644 --- a/veejay-ng/vevosample/Makefile.am +++ b/veejay-ng/vevosample/Makefile.am @@ -26,7 +26,7 @@ VEVOSAMPLE_ALL_LIB_OPTS = \ -release $(LT_RELEASE) \ -export-dynamic -libvevosample_la_SOURCES = vj-unicap.c vj-yuv4mpeg.c vevosample.c +libvevosample_la_SOURCES = vj-unicap.c vj-yuv4mpeg.c uifactory.c vevosample.c libvevosample_la_LIBADD = \ -L$(top_builddir)/libhash -lhash \ -L$(top_builddir)/libvjmsg -lvjmsg \ diff --git a/veejay-ng/vevosample/ldefs.h b/veejay-ng/vevosample/ldefs.h new file mode 100644 index 00000000..1a9312a2 --- /dev/null +++ b/veejay-ng/vevosample/ldefs.h @@ -0,0 +1,97 @@ +#ifndef LOCALDEFS +#define LOCALDEFS +#include + +//! \typedef sampleinfo_t Sample A/V Information structure +typedef struct +{ + uint64_t start_pos; //!< Starting position + uint64_t end_pos; //!< Ending position + int looptype; //!< Looptype + int speed; //!< Playback speed + int repeat; + uint64_t in_point; //!< In point (overrides start_pos) + uint64_t out_point; //!< Out point (overrides end_pos) + uint64_t current_pos; //!< Current position + int marker_lock; //!< Keep in-out point length constant + int rel_pos; //!< Relative position + int has_audio; //!< Audio available + int repeat_count; + int type; //!< Type of Sample + uint64_t rate; //!< AudioRate + double fps; //!< Frame rate of Sample + int bps; + int bits; + int channels; + double rec; //!< Rec. percentage done +} sampleinfo_t; + + +typedef struct +{ + int id; + int active; + int fx_id; + void *fx_osc; + void *fx_instance; + void *in_values; + void *out_values; + void *in_channels; + void *out_channels; + void *bind; + char *window; + char *frame; + char *subwindow; + char *subframe; + double alpha; +} fx_slot_t; + +typedef struct +{ + double min[2]; + double max[2]; + int p[2]; + int entry; + int kind; +} bind_parameter_t; + + +typedef struct +{ + int rec; + int con; + int max_size; + int format; + char aformat; + void *fd; + long tf; + long nf; + uint8_t *buf; + void *codec; +} samplerecord_t; + +//! \typedef sample_runtime_data Sample Runtime Data structure +typedef struct +{ + void *data; /* private data, depends on stream type */ + void *info_port; /* collection of sample properties */ + int width; /* processing information */ + int height; + int format; + int palette; + int type; /* type of sample */ + samplerecord_t *record; + sampleinfo_t *info; + void *osc; + void *user_data; + void *mapping; + void *rmapping; + void *bundle; + int primary_key; + void *fmt_port; +} sample_runtime_data; + +char *sample_translate_property( void *sample, char *name ); + + +#endif diff --git a/veejay-ng/vevosample/uifactory.c b/veejay-ng/vevosample/uifactory.c new file mode 100644 index 00000000..4fabdc72 --- /dev/null +++ b/veejay-ng/vevosample/uifactory.c @@ -0,0 +1,927 @@ +/* + * Copyright (C) 2002-2006 Niels Elburg + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#ifdef STRICT_CHECKING +#include +#endif + +static void vevosample_ui_type_shared( void *sample, char *window ); +static void vevosample_ui_type_capture( void *sample, const char *window, const char *frame); +static void vevosample_ui_type_none( void *sample, const char *window, const char *frame); +static void vevosample_ui_construct_fx_contents( void *sample, int entry_id, const char *window , const char *fx_frame); +static char * vevosample_ui_new_window( sample_runtime_data *src, const char *window_prefix, const int id, const char *title, const char *infix, int suffix ); + + +void vevosample_ui_new_vframe( void *sample, const char *window, const char *frame, const char *label ) +{ + sample_runtime_data *srd = (sample_runtime_data*) sample; + void *osc_send = veejay_get_osc_sender(srd->user_data ); + if(!osc_send) + return; + veejay_ui_bundle_add( + osc_send, + "/create/vframe", + "sssx", + window, + frame, + label ); +} +void vevosample_ui_new_frame( void *sample, const char *window, const char *frame, const char *label ) +{ + sample_runtime_data *srd = (sample_runtime_data*) sample; + void *osc_send = veejay_get_osc_sender(srd->user_data ); + if(!osc_send) + return; + veejay_ui_bundle_add( + osc_send, + "/create/frame", + "sssx", + window, + frame, + label ); +} + +void vevosample_ui_new_button( void *sample, const char *window, const char *frame, const char *label, + const char *path, const char *tooltip ) +{ + sample_runtime_data *srd = (sample_runtime_data*) sample; + void *osc_send = veejay_get_osc_sender(srd->user_data ); + if(!osc_send) + return; + + veejay_ui_bundle_add( + osc_send, + "/create/button", + "sssssx", + window, + frame, + label, + path, + tooltip ); +} +void vevosample_ui_new_label( void *sample, const char *window, const char *frame, const char *label ) +{ + sample_runtime_data *srd = (sample_runtime_data*) sample; + void *osc_send = veejay_get_osc_sender(srd->user_data ); + if(!osc_send) + return; + + veejay_ui_bundle_add( + osc_send, + "/create/label", + "sssx", + window, + frame, + label ); +} + + +void vevosample_ui_new_numeric( void *sample, const char *window, const char *frame, const char *label, + double min, double max, double value, int wrap, int extra, const char *widget_name, + const char *path, const char *format, const char *tooltip) + +{ + sample_runtime_data *srd = (sample_runtime_data*) sample; + void *osc_send = veejay_get_osc_sender(srd->user_data ); + if(!osc_send) + return; + veejay_ui_bundle_add( + osc_send, + "/create/numeric", + "sssdddiissssx", + window, + frame, + label, + min, + max, + value, + wrap, + extra, + widget_name, + path, + format, + tooltip); +} + +void vevosample_ui_new_radiogroup( void *osc, const char *window, const char *framename , const char *prefix,const char *label_prefix, int n_buttons, int active_button ) +{ + veejay_ui_bundle_add( osc, "/create/radiogroup", "ssssii", window,framename,prefix,label_prefix, + n_buttons, active_button ); +} +void vevosample_ui_new_switch( void *sample, const char *window, const char *framename , const char *widget,const char *label, int active, const char *path, const char *tooltip) +{ + sample_runtime_data *srd = (sample_runtime_data*) sample; + void *osc_send = veejay_get_osc_sender(srd->user_data ); + if(!osc_send) + return; + veejay_ui_bundle_add( osc_send, "/create/switch", "ssssissx", window,framename,widget,label,active,path,tooltip ); +} + + + + +static void vevosample_ui_construct_fx_contents( void *sample, int entry_id, const char *window , const char *fx_frame) +{ + sample_runtime_data *srd = (sample_runtime_data*) sample; + void *osc_send = veejay_get_osc_sender( srd->user_data ); + int id = 0; + if(!osc_send) + return; + fx_slot_t *slot = sample_get_fx_port_ptr( srd, entry_id ); + if(slot->window) + free(slot->window); + slot->window = strdup( window ); + + int error = vevo_property_get( srd->info_port, "primary_key", 0, &id ); +#ifdef STRICT_CHECKING + assert( error == VEVO_NO_ERROR ); +#endif + void *filter_template = NULL; + error = vevo_property_get( slot->fx_instance, "filter_templ",0 ,&filter_template ); +#ifdef STRICT_CHECKING + assert( error == VEVO_NO_ERROR ); +#endif + char *label_str = vevo_property_get_string( filter_template, "name" ); + char label[128]; + sprintf( label, "FX slot %d with \"%s\" ", entry_id, label_str ); + free(label_str); + + sprintf(fx_frame, "fx_%d", entry_id ); + + veejay_ui_bundle_add( osc_send, "/create/frame", "sssx", window, fx_frame, label ); + + char alpha_tmp[128]; + sprintf( alpha_tmp, "/sample_%d/fx_%d/alpha", id, entry_id ); + + veejay_ui_bundle_add( osc_send, "/create/numeric", "sssdddiissssx",window,fx_frame, + "Alpha", 0.0, 1.0, slot->alpha,2,0,"VSlider",alpha_tmp, "d", "Transparency" ); + + + sprintf( alpha_tmp, "/sample_%d/fx_%d/status", id, entry_id); + + veejay_ui_bundle_add( osc_send, "/create/switch", "ssssissx", window, fx_frame, "Check", + "Enabled", slot->active, alpha_tmp, "Turn on/off FX" ); + + int q; + int n = vevo_property_num_elements( slot->fx_instance, "in_parameters" ); + + for( q = 0; q < n ; q ++ ) + { + void *parameter = NULL; + error = vevo_property_get( slot->fx_instance, "in_parameters", q, ¶meter ); +#ifdef STRICT_CHECKING + assert( error == VEVO_NO_ERROR ); +#endif + void *parameter_templ = NULL; + error = vevo_property_get( parameter, "parent_template",0,¶meter_templ); +#ifdef STRICT_CHECKING + assert( error == VEVO_NO_ERROR ); +#endif + int kind = 0; + error = vevo_property_get( parameter_templ, "HOST_kind",0,&kind ); +#ifdef STRICT_CHECKING + assert( error == VEVO_NO_ERROR ); +#endif + char *parameter_name = vevo_property_get_string(parameter_templ, "name" ); +#ifdef STRICT_CHECKING + assert( parameter_name != NULL ); +#endif + char *osc_path = vevo_property_get_string(parameter, "HOST_osc_path" ); +#ifdef STRICT_CHECKING + if( !osc_path ) + veejay_msg(0,"No osc path for '%s' ",parameter_name ); + assert( osc_path != NULL ); +#endif + int ival = 0; + double gval = 0.0; + int imin = 0, imax = 0; + double gmin = 0.0, gmax = 0.0; + char *hint = vevo_property_get_string( parameter_templ, "description" ); +#ifdef STRICT_CHECKING + assert( hint != NULL ); +#endif + switch( kind ) + { + case HOST_PARAM_INDEX: + vevo_property_get( parameter, "value",0,&ival); + gval = (double) ival; + vevo_property_get( parameter_templ, "min",0,&imin ); + gmin = (double) imin; + vevo_property_get( parameter_templ, "max",0,&imax ); + gmax = (double) imax; + veejay_ui_bundle_add( osc_send, "/create/numeric", "sssdddiissssx", window, fx_frame, + parameter_name,gmin,gmax,gval,0,0,"VSlider", osc_path, "i", hint ); + + break; + case HOST_PARAM_NUMBER: + vevo_property_get( parameter, "value",0,&gval); + vevo_property_get( parameter_templ, "min",0,&gmin ); + vevo_property_get( parameter_templ, "max",0,&gmax ); + veejay_ui_bundle_add( osc_send, "/create/numeric", "sssdddiissssx", + window,fx_frame,parameter_name,gmin,gmax,gval,2,0,"VSlider",osc_path,"d", hint); + break; + case HOST_PARAM_SWITCH: + vevo_property_get( parameter, "value",0,&ival ); + veejay_ui_bundle_add( osc_send, "/create/switch", "ssssissx", window,fx_frame, "Check", + parameter_name, ival ,osc_path, hint ); + break; + default: +#ifdef STRICT_CHECKING + veejay_msg(0 ,"Parameter types not implemented"); + assert(0); +#endif + break; + } + free(hint); + free(parameter_name); + free(osc_path); + } + + n = vevo_property_num_elements( slot->fx_instance, "in_channels" ); + +veejay_msg(0, "UI Factory: There are %d input channels", n ); + + if( n > 1 ) + { + char ch_path[128]; + sprintf( ch_path, "/sample_%d/fx_%d/input_channel", id, entry_id); + + + void *msg = veejay_message_new_widget( osc_send, window, + ch_path, n-1 ); + + void *ch = sample_get_fx_port_channels_ptr( id , entry_id ); + char **items = vevo_list_properties( ch ); + for( q = 0; items[q] != NULL ;q ++ ) + { + void *sample = NULL; + vevo_property_get( ch, items[q],0,&sample); + if(sample && strncasecmp( items[q] , "slot0", 5 ) != 0) + { + int id = sample_get_run_id( sample ); + char name[32]; + sprintf(name , "S%d", id ); + veejay_message_add_argument( osc_send, msg, "s", name ); + veejay_msg(0, "Added '%s' ", name); + } + free(items[q]); + } + free(items); + // veejay_message_add_argument( osc_send, msg, "s", name ); + + veejay_message_widget_done( osc_send, msg ); + } + + n = vevo_property_num_elements( slot->fx_instance, "out_parameters" ); + if( n <= 0 ) + { + return; + } + + char long_label[128]; + snprintf(long_label,128,"Output parameters", label); + sprintf(fx_frame, "bind_%d", entry_id ); + veejay_ui_bundle_add( osc_send, "/create/frame", "sssx", window, fx_frame, long_label ); + + char box_name[128]; + sprintf( box_name, "%s_box", fx_frame ); + + veejay_ui_bundle_add( osc_send, "/create/box", "sssix", window,fx_frame, box_name, 0 ); + + for( q = 0; q < n ; q ++ ) + { + void *parameter = NULL; + error = vevo_property_get( slot->fx_instance, "out_parameters", q, ¶meter ); +#ifdef STRICT_CHECKING + assert( error == VEVO_NO_ERROR ); +#endif + void *parameter_templ = NULL; + error = vevo_property_get( parameter, "parent_template",0,¶meter_templ); +#ifdef STRICT_CHECKING + assert( error == VEVO_NO_ERROR ); +#endif + int kind = 0; + error = vevo_property_get( parameter_templ, "HOST_kind",0,&kind ); +#ifdef STRICT_CHECKING + assert( error == VEVO_NO_ERROR ); +#endif + if( kind == HOST_PARAM_NUMBER || kind == HOST_PARAM_SWITCH || kind == HOST_PARAM_INDEX ) + { + char *parameter_name = vevo_property_get_string(parameter_templ, "name" ); +#ifdef STRICT_CHECKING + assert( parameter_name != NULL ); +#endif + sprintf(fx_frame, "fxb_%d",q ); + veejay_ui_bundle_add( osc_send, "/create/vframe", "ssssx", window, box_name,fx_frame, parameter_name ); + char param_id[32]; + sprintf(param_id,"o%02d",q ); + + char *parameter_value = vevo_sprintf_property_value( + parameter, "value " ); + + veejay_ui_bundle_add( osc_send, "/create/label", + "ssssx", window,fx_frame,param_id, (parameter_value==NULL ? "inf" : parameter_value) ); //@ updated by apply_bind !!! + if(parameter_value) + free(parameter_value); + free(parameter_name ); + + + + char hint[128]; + snprintf(hint, 128,"Bind %s to an Input Parameter of another FX slot"); + char bindname[32]; + char unbindname[32]; + sprintf(bindname,"bind_p%d", q); + sprintf(unbindname,"unbind_p%d",q ); + + //@ special button + veejay_ui_bundle_add( osc_send, "/create/button","sssssx", + window, fx_frame, "B", bindname, hint ); + + + //@ normal button, special parameters + veejay_ui_bundle_add( osc_send, "/create/button","sssssx", + window, fx_frame, "C", unbindname, "Reset binding"); + } + } + +} +static char *_get_out_parameter_name( void *instance, int id ) +{ + void *p = NULL; + int error = vevo_property_get( instance, "out_parameters", id, &p ); + if( error != VEVO_NO_ERROR ) + return NULL; + void *t = NULL; + error = vevo_property_get( p, "parent_template", 0, &t ); + if( error == VEVO_NO_ERROR ) + return vevo_property_get_string( t, "name" ); + return NULL; +} +static char *_get_in_parameter_name( void *instance, int id ) +{ + void *p = NULL; + int error = vevo_property_get( instance, "in_parameters", id, &p ); + if( error != VEVO_NO_ERROR ) + return NULL; + void *t = NULL; + error = vevo_property_get( p, "parent_template", 0, &t ); + if( error == VEVO_NO_ERROR ) + return vevo_property_get_string( t, "name" ); + return NULL; +} +static char *_get_in_channel_name( void *instance, int id ) +{ + void *p = NULL; + int error = vevo_property_get( instance, "in_channels", id, &p ); + if( error != VEVO_NO_ERROR ) + return NULL; + void *t = NULL; + error = vevo_property_get( p, "parent_template", 0, &t ); + if( error == VEVO_NO_ERROR ) + return vevo_property_get_string( t, "name" ); + return NULL; +} + +void vevosample_ui_get_input_parameter_list( void *sample, int fx_id, const char *window ) +{ + sample_runtime_data *srd = (sample_runtime_data*) sample; + fx_slot_t *rel = (fx_slot_t*) sample_get_fx_port_ptr( srd, fx_id); +#ifdef STRICT_CHECKING + assert( rel->fx_instance != NULL ); +#endif + void *osc_send = veejay_get_osc_sender(srd->user_data ); + if(!osc_send) + return; + +//@ we also update path! + char bind_path[128]; + sprintf(bind_path, "/sample_%d/fx_%d/bind", srd->primary_key,fx_id); + + +//@ pulldown abused for updatin ! see pulldown_done_update , it calls an update method in uiosc.c + void *msg = veejay_message_new_pulldown( osc_send, window, "n/a", "combobox_list_ip", "Input Parameter", bind_path, fx_id, "none" ); + + int n = vevo_property_num_elements( rel->fx_instance, "in_parameters" ); + int i; + veejay_msg(0, "Get FX Slot %d of sample %d, with %d parameters", + fx_id, srd->primary_key, n ); + for( i = 0; i < n ; i++ ) + { + char *pname = _get_in_parameter_name( rel->fx_instance, i ); +#ifdef STRICT_CHECKING + assert( pname != NULL ); +#endif + veejay_msg(0, "\t added parameter '%s'", pname ); + veejay_message_add_argument( + osc_send, msg, "s", pname ); + + free(pname); + } + veejay_message_pulldown_done_update( + osc_send, msg ); +} + +void vevosample_ui_get_bind_list( void *sample, const char *window ) +{ + int fx_id = 0; + int p_num = 0; + int dummy = 0; + sscanf(window, "SampleBind%dFX%dOP%d",&dummy,&fx_id,&p_num); + + + sample_runtime_data *srd = (sample_runtime_data*) sample; + fx_slot_t *sl = (fx_slot_t*) sample_get_fx_port_ptr( srd, fx_id); +#ifdef STRICT_CHECKING + assert( sl->fx_instance != NULL ); + assert( srd->primary_key == dummy ); +#endif + void *osc_send = veejay_get_osc_sender(srd->user_data ); + if(!osc_send) + return; + +//@ we also update path! + char bind_path[128]; + sprintf(bind_path, "/sample_%d/fx_%d/unbind", srd->primary_key,fx_id); + + +//@ pulldown abused for updatin ! see pulldown_done_update , it calls an update method in uiosc.c + void *msg = veejay_message_new_pulldown( osc_send, window, "n/a", "combobox_release_bind", "Choose Item to release", bind_path, 0, "None" ); + +// veejay_message_add_argument( +// osc_send, msg, "s", "None" ); + + char **items = vevo_list_properties( sl->bind ); + if(! items ) + { + veejay_message_pulldown_done_update( + osc_send, msg ); + + return; + } + int i; + for( i = 0; items[i] != NULL ; i ++ ) + { + int n[3]; + sscanf( items[i], "bp%d_%d_%d", &n[0],&n[1],&n[2] ); + fx_slot_t *rel = (fx_slot_t*) sample_get_fx_port_ptr( srd, n[1]); +#ifdef STRICT_CHECKING + assert( rel->fx_instance != NULL ); +#endif + + if( n[0] == p_num && vevo_property_get(sl->bind, items[i],0,NULL) == VEVO_NO_ERROR ) + { + veejay_msg(0, "'%s' is a valid bind",items[i]); + void *filter_template = NULL; + int error = vevo_property_get( rel->fx_instance, "filter_templ",0 ,&filter_template ); +#ifdef STRICT_CHECKING + assert( error == VEVO_NO_ERROR ); +#endif + char *fxname = vevo_property_get_string( filter_template, "name" ); + + char *pname = _get_in_parameter_name( rel->fx_instance, n[2] ); + char list_item[128]; + snprintf(list_item, 128, "fx_%d '%s' p%d '%s'", + n[1], fxname,n[2], pname ); + + veejay_message_add_argument( osc_send, msg, "s", list_item ); + + free(fxname); + free(pname); + + + } + free(items[i]); + } + free(items); + + veejay_message_pulldown_done_update( + osc_send, msg ); +} + +static void vevosample_ui_construct_bind_list( void *sample, int k, int p_num, void *dslot, const char *window, + const char *fx_frame ) +{ + //@ list all binds + sample_runtime_data *srd = (sample_runtime_data*) sample; + fx_slot_t *slot = (fx_slot_t*) dslot; + void *osc_send = veejay_get_osc_sender(srd->user_data ); + if(!osc_send) + return; + + char bind_path[128]; + sprintf(bind_path, "/sample_%d/fx_%d/unbind", srd->primary_key,k); + + void *msg = veejay_message_new_pulldown( + osc_send, window, fx_frame, "combobox_release_bind", "Choose item to release", bind_path, 0, "None" ); + + veejay_message_add_argument( osc_send, msg, "s", "None"); + + int i; + if(!slot->bind ) + { + veejay_message_pulldown_done(osc_send, msg); + return; + } + + char **items = vevo_list_properties( slot->bind ); + if(! items ) + { + veejay_message_pulldown_done(osc_send, msg); + return; + } + for( i = 0; items[i] != NULL ; i ++ ) + { + int n[3]; + sscanf( items[i], "bp%d_%d_%d", &n[0],&n[1],&n[2] ); + fx_slot_t *rel = (fx_slot_t*) sample_get_fx_port_ptr( srd, n[1]); +#ifdef STRICT_CHECKING + assert( rel->fx_instance != NULL ); +#endif + + if( n[0] == p_num && vevo_property_get( slot->bind, items[i],0,NULL) == VEVO_NO_ERROR) + { + void *filter_template = NULL; + int error = vevo_property_get( rel->fx_instance, "filter_templ",0 ,&filter_template ); +#ifdef STRICT_CHECKING + assert( error == VEVO_NO_ERROR ); +#endif + char *fxname = vevo_property_get_string( filter_template, "name" ); + + char *pname = _get_in_parameter_name( rel->fx_instance, n[2] ); + char list_item[128]; + snprintf(list_item, 128, "fx_%d '%s' p%d '%s'", + n[1], fxname, n[2],pname ); + + veejay_message_add_argument( osc_send, msg, "s", list_item ); + + free(fxname); + free(pname); + } + free(items[i]); + } + free(items); + veejay_message_pulldown_done(osc_send, msg); + +} + + +void vevosample_ui_construct_fx_bind_window( void *sample, int k, int p_id ) +{ + sample_runtime_data *srd = (sample_runtime_data*) sample; + int id = srd->primary_key; + void *osc_send = veejay_get_osc_sender(srd->user_data ); + if(!osc_send) + return; + fx_slot_t *sl = sample_get_fx_port_ptr( srd, k); + if(!sl->fx_instance) + return; +#ifdef STRICT_CHECKING + assert( osc_send != NULL ); +#endif + + int i; + char window_title[128]; + char fx_frame[128]; + char *pname = _get_out_parameter_name( sl->fx_instance, p_id ); + void *filter_template = NULL; + int error = vevo_property_get( sl->fx_instance, "filter_templ",0 ,&filter_template ); +#ifdef STRICT_CHECKING + assert( error == VEVO_NO_ERROR ); +#endif + char *fxname = vevo_property_get_string( filter_template, "name" ); + char fx_label[128]; + char owner[64]; + sprintf(owner,"SampleBind%dFX%d", id,k ); + + snprintf(window_title,128, "Bind output from %s",fxname); + snprintf(fx_label,128, "Bind '%s' to", pname ); + + char *window = vevosample_ui_new_window( srd, owner, k, window_title, "OP", p_id ); + + if(!window) + return; +#ifdef STRICT_CHECKING + assert( sl->fx_instance != NULL ); +#endif + + sprintf(fx_frame, "NewBind%d_%d_%d",k,p_id,id ); + char bindpath[128]; + sprintf(bindpath , "/sample_%d/fx_%d/bind", id,k ); + + veejay_ui_bundle_add( osc_send, "/create/frame", "sssx", window, fx_frame, fx_label ); + + //@ create pulldown with available Slots + void *msg = veejay_message_new_pulldown( osc_send, window, fx_frame, "combobox_load_ip", "FX Slot","/veejay/ipreq", 0, "none" ); + veejay_message_add_argument( osc_send, msg, "s", "None" ); + + char list_item[128]; + for( i = 0;i < SAMPLE_CHAIN_LEN ; i ++ ) + { + fx_slot_t *slot = sample_get_fx_port_ptr( srd, i ); + if(slot->fx_instance) + { + void *ft = NULL; + int error = vevo_property_get( slot->fx_instance, "filter_templ",0,&ft ); +#ifdef STRICT_CHECKING + assert( error == VEVO_NO_ERROR); +#endif + char *plug = vevo_property_get_string( ft, "name" ); + sprintf(list_item, "FX %d %s", i, plug ); + free(plug); + veejay_message_add_argument( osc_send, msg, "s", list_item ); + } + } + veejay_message_pulldown_done( osc_send, msg ); + + void *msg2 = veejay_message_new_pulldown( + osc_send, window, fx_frame, "combobox_list_ip", "Input Parameter", bindpath,0,"none" ); + veejay_message_add_argument( osc_send, msg2, "s", "none" ); + veejay_message_pulldown_done(osc_send, msg2); + + sprintf(fx_frame, "NewBindC%d_%d_%d",k,p_id,id ); + veejay_ui_bundle_add( osc_send, "/create/frame", "sssx", window, fx_frame, "Existing bindings" ); + + vevosample_ui_construct_bind_list( sample,k, p_id, sl, window, fx_frame ); + veejay_ui_bundle_add( osc_send, "/show/window", "sx", window ); + + free(fxname); + free(pname); + free(window); +} + +void vevosample_ui_construct_fx_window( void *sample, int k ) +{ + sample_runtime_data *srd = (sample_runtime_data*) sample; + int id = srd->primary_key; + void *osc_send = veejay_get_osc_sender(srd->user_data ); + if(!osc_send) + return; + char window_title[128]; + char fx_frame[128]; + char window[128]; + + sprintf(window, "Sample%dFX%d", id,k ); + sprintf(fx_frame, "fx_%d", k); + sprintf(window_title, "Sample %d FX slot %d", id,k ); + + if( !vevosample_ui_new_window( srd, "Sample", id, window_title, "FX", k ) ) + return; + + vevosample_ui_construct_fx_contents( sample, k,window, fx_frame ); + + veejay_ui_bundle_add( osc_send, "/show/window", "sx", window ); +} + + +static char * vevosample_ui_new_window( sample_runtime_data *src, const char *window_prefix, const int id, const char *title, const char *window_infix, const int suffix) +{ + + void *osc_send = veejay_get_osc_sender(src->user_data ); + if(!osc_send) + return NULL; + char window[128]; + if(window_infix) + sprintf(window,"%s%d%s%d", window_prefix, id, window_infix, suffix ); + else + sprintf(window, "%s%d", window_prefix, id ); + veejay_osc_set_window( osc_send , window ); + veejay_ui_bundle_add( osc_send, "/create/window", "ssx", window, title ); + return strdup(window); +} + +//@ create widget that only type none has +static void vevosample_ui_type_none( void *sample, const char *window, const char *frame) +{ + uint64_t end = sample_get_end_pos(sample); + uint64_t sta = sample_get_start_pos(sample); + char osc_path[128]; + char tmp_label[128]; + double ns = end-sta; + sample_runtime_data *srd = (sample_runtime_data*) sample; + void *osc_send = veejay_get_osc_sender(srd->user_data ); + + int id = srd->primary_key; + if(ns > 16 ) ns = 16; + + vevosample_ui_new_frame( sample, window, frame, "Navigation" ); + + snprintf(osc_path,128, "/sample_%d/video/goto_start", id ); + vevosample_ui_new_button( sample,window, frame, "gs", osc_path,"Goto starting position of sample"); + sprintf(osc_path, "/sample_%d/video/play", id ); + vevosample_ui_new_button( sample,window, frame, ">", osc_path, "Play forward" ); + sprintf(osc_path, "/sample_%d/video/pause", id ); + vevosample_ui_new_button( sample, window, frame, "||", osc_path, "Pause playing" ); + sprintf(osc_path, "/sample_%d/video/reverse", id ); + vevosample_ui_new_button( sample, window, frame, "r", osc_path, "Play backward" ); + sprintf(osc_path, "/sample_%d/video/goto_end", id ); + vevosample_ui_new_button( sample, window, frame, "ge", osc_path, "Goto ending position of sample" ); + sprintf(osc_path, "/sample_%d/video/prev_frame", id ); + vevosample_ui_new_button( sample, window, frame, "pf", osc_path, "Previous frame" ); + sprintf(osc_path, "/sample_%d/video/next_frame", id ); + vevosample_ui_new_button( sample, window, frame, "nf", osc_path, "Next frame" ); + sprintf(osc_path, "/sample_%d/speed", id ); + vevosample_ui_new_numeric( sample, window, frame, "Speed", + -1 * ns, ns ,(double) sample_get_speed(sample), + 0,0, "HSlider", osc_path, "i", "none" ); + + sprintf(frame, "sample%d_videobar", id ); + vevosample_ui_new_frame( sample,window, frame, "Timeline" ); + sprintf(osc_path, "/sample_%d/current_pos", id ); + vevosample_ui_new_numeric( sample, window, frame, "Position", + (double) sta, (double) end, (double) sample_get_current_pos(sample),0,0, + "HSlider", osc_path, "h","none" ); + + + sprintf(frame, "sample%d_ctrl", id ); + sprintf(tmp_label, "%s","Settings" ); + vevosample_ui_new_frame( sample,window, frame, tmp_label ); + sprintf(osc_path, "/sample_%d/looptype", id ); + + void *msg = veejay_message_new_pulldown( osc_send, + window, frame,"combobox_looptype_list", "Looptype", osc_path, (double) sample_get_looptype( sample ), "none" ); + + veejay_message_add_argument( osc_send, msg, "sss", "None","Normal" , "Bounce" ); + + veejay_message_pulldown_done( osc_send, msg ); + +} + +//@ create widgets for capture type +static void vevosample_ui_type_capture( void *sample, const char *window, const char *frame) +{ + sample_runtime_data *srd = (sample_runtime_data*) sample; + int i; + char **list = vj_unicap_get_list( srd->data ); +#ifdef STRICT_CHECKING + assert( list != NULL ); +#endif + double min=0.0; + double max=0.0; + char format[5]; + double dv = 0; + char path[128]; + int id = srd->primary_key; + + void *osc_send = veejay_get_osc_sender(srd->user_data ); + + vevosample_ui_new_frame( sample, window, "capframe", "Settings" ); + vevosample_ui_new_frame( sample, window, "capframe2", "Settings" ); + + for( i = 0; list[i] != NULL ; i++ ) + { + if(vj_unicap_get_range( srd->data, list[i], &min,&max )) + { + char *tkey = sample_translate_property(srd,list[i]); // translate property + + int type = vevo_property_atom_type( srd->info_port, list[i]); + if(type==VEVO_ATOM_TYPE_DOUBLE) + sprintf(format, "%s", "d" ); + else + sprintf(format, "%s", "i" ); + + sprintf(path, "/sample_%d/%s", id, tkey ); + + if( vj_unicap_property_is_menu( srd->data, list[i] )) + { + vevo_property_get( srd->info_port, list[i],0,&dv ); + // void *msg = veejay_message_new_pulldown( osc_send,window,"combobox_capframe", "capframe2", list[i], path,dv,"none" ); + void *msg = veejay_message_new_pulldown( osc_send,window,"capframe2", "combobox_capframe", list[i], path,dv,"none" ); + + + vj_unicap_pack_menu( srd->data, list[i], osc_send, msg ); + veejay_message_pulldown_done( osc_send, msg ); + } + else if( vj_unicap_property_is_range( srd->data, list[i] ) ) + { + vevosample_ui_new_numeric( sample,window, "capframe", + list[i], min,max, (max*0.5), 0,0, "VSlider", + path, format, "none" ); + } + free(tkey); + } + free(list[i]); + } + free(list); +} + +static void vevosample_ui_type_shared( void *sample, char *window ) +{ + sample_runtime_data *srd = (sample_runtime_data*) sample; + int id = srd->primary_key; + char osc_path[128]; + char frame_name[128]; + void *osc_send = veejay_get_osc_sender(srd->user_data ); + + + sprintf(frame_name, "%s", "fxchain" ); + + vevosample_ui_new_frame( sample, window, frame_name, "FX slots" ); + + vevosample_ui_new_radiogroup(osc_send, window, frame_name, "fx", "fx", SAMPLE_CHAIN_LEN, 0 ); + sprintf(frame_name, "%s", "fx_list" ); + vevosample_ui_new_frame( sample, window, frame_name, "Available plugins" ); + + sprintf(osc_path, "/sample_%d/fx_X/set", id ); + void *msg = veejay_message_new_linked_pulldown( osc_send, + window,frame_name,"Plugins", osc_path, "s", "Add plugin to FX slot" ); + plug_concatenate_all( osc_send, msg ); + veejay_message_linked_pulldown_done( osc_send, msg ); + vevosample_ui_new_button( sample, window, frame_name, "clear", "none", "Clear selected FX slot" ); + + + sprintf(frame_name, "%s", "sample_action" ); + vevosample_ui_new_frame( sample, window, frame_name, "Actions" ); + sprintf(osc_path, "/sample_%d/rec/start", id ); + vevosample_ui_new_button( sample,window, frame_name, "rec start", osc_path, "Start recording from sample" ); + sprintf(osc_path, "/sample_%d/rec/stop", id ); + vevosample_ui_new_button( sample,window, frame_name, "rec stop", osc_path, "Stop recording from sample" ); + sprintf(osc_path, "/sample_%d/print", id ); + vevosample_ui_new_button( sample, window, frame_name, "osc", osc_path, "Print OSC message space" ); + sprintf(osc_path, "/sample_%d/delete", id ); + vevosample_ui_new_button( sample, window, frame_name, "destroy", osc_path, "Destry this sample" ); + + if(srd->type == VJ_TAG_TYPE_NONE) + vevosample_ui_new_button( sample, window, frame_name, "clone", "clone","Copy sample to new sample" ); + +} + +void vevosample_construct_ui_fx_chain(void *sample) +{ + int k; + for( k = 0; k < SAMPLE_CHAIN_LEN ; k ++ ) + { + if( sample_get_fx_status( sample, k )) + vevosample_ui_construct_fx_window( sample, k ); + } +} + + +char * vevosample_construct_ui(void *sample) +{ + sample_runtime_data *srd = (sample_runtime_data*) sample; + char fx_frame[128]; + char window_title[128]; + void *osc_send = veejay_get_osc_sender(srd->user_data ); + + + sprintf(window_title, "Sample %d", srd->primary_key ); + + char *window = vevosample_ui_new_window( srd, "Sample", srd->primary_key, window_title ,NULL,0); + if(!window) + return NULL; + + char tmp_label[128]; + char osc_path[128]; + char frame_name[128]; + sprintf(frame_name, "sample%dactions", srd->primary_key ); + + switch(srd->type) + { + case VJ_TAG_TYPE_NONE: + vevosample_ui_type_none( sample, window, frame_name ); + break; + case VJ_TAG_TYPE_CAPTURE: + vevosample_ui_type_capture( sample,window,frame_name ); + break; + } + + + vevosample_ui_type_shared( sample, window ); + + veejay_ui_bundle_add( osc_send, "/show/window", "sx", window ); + + return window; +} + diff --git a/veejay-ng/vevosample/uifactory.h b/veejay-ng/vevosample/uifactory.h new file mode 100644 index 00000000..296a3a8d --- /dev/null +++ b/veejay-ng/vevosample/uifactory.h @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2002-2006 Niels Elburg + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + + +#ifndef UIFAC +#define UIFAC + +//@ returns window name , creates sample +char * vevosample_construct_ui(void *sample); +//@ create fx chain (all underlying windows) +void vevosample_construct_ui_fx_chain(void *sample); + +//@ create window for some fx slot +void vevosample_ui_construct_fx_window( void *sample, int k ); + +//@ create window for some bind slot +void vevosample_ui_construct_fx_bind_window( void *sample, int k , int i); + +void vevosample_ui_new_vframe( + void *sample, + const char *window, + const char *frame, + const char *label ); + +void vevosample_ui_new_frame( + void *sample, + const char *window, + const char *frame, + const char *label ); + +void vevosample_ui_new_button( + void *sample, + const char *window, + const char *frame, + const char *label, + const char *path, + const char *tooltip ); + +void vevosample_ui_new_label( + void *sample, + const char *window, + const char *frame, + const char *label ); + +void vevosample_ui_new_numeric( + void *sample, + const char *window, + const char *frame, + const char *label, + double min, + double max, + double value, + int wrap, + int extra, + const char *widget_name, + const char *path, + const char *format, + const char *tooltip); + +void vevosample_ui_new_radiogroup( + void *osc, + const char *window, + const char *framename, + const char *prefix, + const char *label_prefix, + int n_buttons, + int active_button ); + +void vevosample_ui_new_switch( + void *sample, + const char *window, + const char *framename, + const char *widget, + const char *label, + int active, + const char *path, + const char *tooltip); +#endif diff --git a/veejay-ng/vevosample/vevosample.c b/veejay-ng/vevosample/vevosample.c index 2a776f62..3fe5dc1a 100644 --- a/veejay-ng/vevosample/vevosample.c +++ b/veejay-ng/vevosample/vevosample.c @@ -27,6 +27,9 @@ * -# YUV4MPEG stream * -# Source generator (solid color) */ + + + #ifdef STRICT_CHECKING #include #endif @@ -46,10 +49,14 @@ #include #include #include +#include #include #include #include +#include +#include #include +#include #ifdef USE_GDK_PIXBUF #include #endif @@ -79,68 +86,10 @@ static int free_slots_[SAMPLE_LIMIT]; /* deleted sample id's */ static void *sample_bank_ = NULL; /* root of samplebank */ static void *unicap_data_ = NULL; -//! \typedef sampleinfo_t Sample A/V Information structure -typedef struct -{ - uint64_t start_pos; //!< Starting position - uint64_t end_pos; //!< Ending position - int looptype; //!< Looptype - int speed; //!< Playback speed - int repeat; - uint64_t in_point; //!< In point (overrides start_pos) - uint64_t out_point; //!< Out point (overrides end_pos) - uint64_t current_pos; //!< Current position - int marker_lock; //!< Keep in-out point length constant - int rel_pos; //!< Relative position - int has_audio; //!< Audio available - int repeat_count; - int type; //!< Type of Sample - uint64_t rate; //!< AudioRate - double fps; //!< Frame rate of Sample - int bps; - int bits; - int channels; - double rec; //!< Rec. percentage done -} sampleinfo_t; - -typedef struct -{ - int rec; - int con; - int max_size; - int format; - char aformat; - void *fd; - long tf; - long nf; - uint8_t *buf; - void *codec; -} samplerecord_t; - -//! \typedef sample_runtime_data Sample Runtime Data structure -typedef struct -{ - void *data; /* private data, depends on stream type */ - void *info_port; /* collection of sample properties */ - int width; /* processing information */ - int height; - int format; - int palette; - int type; /* type of sample */ - samplerecord_t *record; - sampleinfo_t *info; - void *osc; - void *user_data; -} sample_runtime_data; +static void *ui_register_ = NULL; -typedef struct -{ - int p[32]; - int e[32]; -} bind_t; - /* forward */ static void sample_fx_clean_up( void *port, void *user_data ); @@ -149,6 +98,10 @@ static void sample_expand_properties( void *sample, const char *key, xmlNodePtr static void sample_expand_port( void *port, xmlNodePtr node ); static void sample_close( sample_runtime_data *srd ); static void sample_new_fx_chain(void *sample); +char *sample_translate_property( void *sample, char *name ) ; +static char *sample_reverse_translate_property( void *sample, char *name ) ; +static void sample_ui_close_all( void *sample ); + /* * 1. cache sample properties to sampleinfo * 2. do events @@ -160,6 +113,7 @@ static void sample_new_fx_chain(void *sample); */ + /* * to reduce vevo set/get , cache each step */ @@ -169,17 +123,17 @@ static struct const char *name; } protected_properties[] = { - "type", - "audio_spas", - "bits", - "rate", - "has_audio", - "channels", - "fx_osc", - "primary_key", - "fps", - "bps", - NULL + { "type" }, + { "audio_spas" }, + { "bits" }, + { "rate" }, + { "has_audio" }, + { "channels" }, + { "fx_osc" }, + { "primary_key" }, + { "fps" }, + { "bps" }, + { NULL } }; @@ -215,21 +169,6 @@ static struct { NULL, 0 } }; -static struct -{ - const char *name; - int atom_type; -} fx_entry_list_[] = -{ - { "fx_status", VEVO_ATOM_TYPE_INT }, /* fx status */ - { "fx_alpha", VEVO_ATOM_TYPE_DOUBLE }, /* alpha */ - { "fx_instance", VEVO_ATOM_TYPE_VOIDPTR }, /* plugin instance point */ - { "fx_values", VEVO_ATOM_TYPE_PORTPTR }, /* port of p0 .. pN, containing copy of fx parameter values */ - { "fx_out_values", VEVO_ATOM_TYPE_PORTPTR }, /* output parmaters, p0 ... pN */ - { "fx_channels", VEVO_ATOM_TYPE_PORTPTR }, /* contains list of sample pointers to use as input channels */ - { "fx_osc", VEVO_ATOM_TYPE_STRING }, /* osc message string (output)*/ -}; - /** * elements common in all types of samples */ @@ -240,7 +179,6 @@ static struct } common_property_list[] = { { "title", VEVO_ATOM_TYPE_STRING }, /* Title of this sample */ - { "fx_status", VEVO_ATOM_TYPE_INT }, /* FX chain enabled/disabled */ { "primary_key", VEVO_ATOM_TYPE_INT }, /* Primary key of this sample */ { NULL, 0 } }; @@ -329,14 +267,14 @@ static struct void *find_sample(int id) { + if( id < 0 || id > SAMPLE_LIMIT ) + return NULL; + char key[20]; void *info = NULL; int error; -#ifdef STRICT_CHECKING - assert( id > 0 && id < SAMPLE_LIMIT ); -#endif + sprintf(key, "sample%04x", id ); - error = vevo_property_get( sample_bank_, key, 0, &info ); if(error != VEVO_NO_ERROR) @@ -394,8 +332,6 @@ static void free_slot(int key) static int sample_property_is_protected( void *sample , const char *key ) { - sample_runtime_data *srd = (sample_runtime_data*) sample; - int i; for( i = 0; protected_properties[i].name != NULL ;i ++ ) { @@ -405,6 +341,12 @@ static int sample_property_is_protected( void *sample , const char *key ) return 0; } +int sample_get_run_id( void *info ) +{ + sample_runtime_data *srd = (sample_runtime_data*) info; + return srd->primary_key; +} + int sample_get_key_ptr( void *info ) { if(!info) @@ -426,11 +368,17 @@ void sample_delete_ptr( void *info ) sample_runtime_data *srd = (sample_runtime_data*) info; //@ FIXME: get default channel configuratioe_data *srd = (sample_runtime_data*) info; #ifdef STRICT_CHECKING - if( info == NULL ) - trap_vevo_sample(); assert( info != NULL ); assert( srd->info_port != NULL ); #endif + + sample_ui_close_all( info ); + + void *sender = veejay_get_osc_sender( srd->user_data ); + if(sender) + veejay_ui_bundle_add( sender, "/destroy/sample", + "ix", srd->primary_key ); + int pk = 0; int error = vevo_property_get( srd->info_port, "primary_key", 0, &pk ); @@ -442,11 +390,14 @@ void sample_delete_ptr( void *info ) veejay_osc_del_methods( srd->user_data, osc_space,srd->info_port ,srd); - sample_fx_clean_up( srd->info_port, srd->user_data ); +// sample_fx_clean_up( info, srd->user_data ); + + sample_fx_chain_reset( info ); sample_close( srd ); vevo_port_recursive_free( srd->info_port ); + vevo_port_free( srd->fmt_port ); free_slot( pk ); free(srd->info); @@ -455,13 +406,11 @@ void sample_delete_ptr( void *info ) if( error == VEVO_NO_ERROR ) { - - char pri_key[20]; - sprintf(pri_key, "sample%04x", pk ); - error = vevo_property_set( sample_bank_, pri_key, VEVO_ATOM_TYPE_VOIDPTR, 0, NULL ); - + char pri_key[20]; + sprintf(pri_key, "sample%04x", pk ); + error = vevo_property_set( sample_bank_, pri_key, VEVO_ATOM_TYPE_VOIDPTR, 0, NULL ); #ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); + assert( error == VEVO_NO_ERROR ); #endif } } @@ -470,111 +419,118 @@ void sample_fx_chain_reset( void *sample ) { sample_runtime_data *srd = (sample_runtime_data*) sample; - sample_fx_clean_up( srd->info_port,srd->user_data ); + sample_fx_clean_up( sample,srd->user_data ); - sample_new_fx_chain ( srd->info_port ); + sample_new_fx_chain ( sample ); } void sample_fx_set_parameter( int id, int fx_entry, int param_id,int n_elem, void *value ) { - void *port = sample_get_fx_port( id, fx_entry ); - int fx_id = 0; - void *fx_instance = NULL; - int error = vevo_property_get( port, "fx_instance", 0, &fx_instance ); + fx_slot_t *port = (fx_slot_t*) sample_get_fx_port( id, fx_entry ); #ifdef STRICT_CHECKING - assert( error == 0 ); + assert( port->fx_instance != NULL ); #endif - plug_set_parameter( fx_instance, param_id, n_elem,value ); + plug_set_parameter( port->fx_instance, param_id, n_elem,value ); } +//@ can optimize sprintf(pley, .. ) void sample_fx_get_parameter( int id, int fx_entry, int param_id, int idx, void *dst) { void *fx_values = sample_get_fx_port_values_ptr( id, fx_entry ); char pkey[KEY_LEN]; sprintf(pkey, "p%02d", param_id ); vevo_property_get( fx_values, pkey, idx, dst ); + //@FIXME } +void sample_flush_bundle(void *info, const char * key ) +{ + sample_runtime_data *srd = (sample_runtime_data*) info; + void *sender = veejay_get_osc_sender_by_uri( srd->user_data , key ); + if(sender) + { + veejay_bundle_send( sender ); + veejay_bundle_destroy( sender ); + } +} + +static void sample_notify_parameter( void *sample, void *parameter, void *value ) +{ + char *osc_path = vevo_property_get_string( parameter, "HOST_osc_path" ); +#ifdef STRICT_CHECKING + assert( osc_path != NULL ); +#endif + char *osc_types = vevo_property_get_string( parameter, "HOST_osc_types"); + + sample_runtime_data *srd = (sample_runtime_data*) sample; + int fx_entry = sample_extract_fx_entry_from_path( sample, osc_path ); + void *sender = veejay_get_osc_sender( srd->user_data ); + + if( fx_entry >= 0 && fx_entry < SAMPLE_CHAIN_LEN && sender) + { + fx_slot_t *slot = sample_get_fx_port_ptr( sample, fx_entry ); + veejay_bundle_plugin_add( sender, slot->frame, osc_path, osc_types, value ); + } +} + + int sample_fx_set( void *info, int fx_entry, const int new_fx ) { - void *port = sample_get_fx_port_ptr( info,fx_entry ); - void *fx_values = NULL; - void *fx_channels = NULL; + fx_slot_t *slot = (fx_slot_t*) sample_get_fx_port_ptr( info,fx_entry ); +#ifdef STRICT_CHECKING + assert(slot!=NULL); +#endif sample_runtime_data *srd = (sample_runtime_data*) info; - //int cur_fx_id = 0; - int error; -#ifdef STRICT_CHECKING - assert( port != NULL ); -#endif - void *fxi = NULL; - error = vevo_property_get( port, "fx_instance", 0, &fxi ); - if( error == VEVO_NO_ERROR ) + if( slot->fx_instance ) { veejay_msg(0, "FX entry %d is used. Please select another", fx_entry); return 0; } - - error = vevo_property_set( port, "fx_id", VEVO_ATOM_TYPE_INT,1, &new_fx ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif - void *fx_instance = plug_activate( new_fx ); - if(!fx_instance) + + slot->fx_instance = plug_activate( new_fx ); + if(!slot->fx_instance) { veejay_msg(0, "Unable to initialize plugin %d", new_fx ); return 0; } - error = vevo_property_set( port, "fx_instance", VEVO_ATOM_TYPE_PORTPTR, - 1, &fx_instance ); -#ifdef STRICT_CHECKING - if(error != VEVO_NO_ERROR) - veejay_msg(0, "Error code %d",error); - assert( error == VEVO_NO_ERROR ); -#endif - error = vevo_property_get( port, "fx_values", 0, &fx_values ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif - error = vevo_property_get( port, "fx_channels", 0, &fx_channels ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif + slot->fx_id = new_fx; + slot->id = fx_entry; + char tmp[128]; + sprintf( tmp, "Sample%dFX%d", srd->primary_key, fx_entry ); + slot->frame = strdup( tmp ); - int n_channels = vevo_property_num_elements( fx_instance, "in_channels" ); - - error = vevo_property_set( fx_channels, "n_in_channels", VEVO_ATOM_TYPE_INT,1, &n_channels ); - - int o_channels = vevo_property_num_elements( fx_instance, "out_channels" ); - - error = vevo_property_set( fx_channels, "n_out_channels",VEVO_ATOM_TYPE_INT,1, &o_channels ); - - plug_get_defaults( fx_instance, fx_values ); - - plug_set_defaults( fx_instance, fx_values ); + plug_get_defaults( slot->fx_instance, slot->in_values ); + plug_set_defaults( slot->fx_instance, slot->in_values ); int i; + int n_channels = vevo_property_num_elements( slot->fx_instance, "in_channels" ); + + if( n_channels <= 0) + { + veejay_msg(0, "Veejay cannot handle generator plugins yet"); + return 0; + } + for(i=0; i < n_channels; i ++ ) sample_fx_set_in_channel(info,fx_entry,i, sample_get_key_ptr(info)); - - veejay_msg(0, "Entry %d Plug %d has %d Inputs, %d Outputs",fx_entry, new_fx,n_channels,o_channels ); - - //@ setup OSC namespace int pk = 0; vevo_property_get( srd->info_port, "primary_key", 0, &pk ); - plug_build_name_space( new_fx, fx_instance, srd->user_data, fx_entry ,pk); -//@ FIXME: get default channel configuration -// plug_get_channels( fx_instance, fx_channels ); + plug_build_name_space( new_fx, slot->fx_instance, srd->user_data, fx_entry ,pk, + sample_notify_parameter, info ); + + vevosample_ui_construct_fx_window( info, fx_entry ); + return 1; } int sample_osc_verify_format( void *vevo_port, char const *types ) { - char *format = get_str_vevo( vevo_port, "format" ); + char *format = vevo_property_get_string( vevo_port, "format" ); int n = strlen(types); if(!format) { @@ -593,8 +549,7 @@ int sample_osc_verify_format( void *vevo_port, char const *types ) static void sample_osc_print( void *osc_port ) { char **osc_events = vevo_list_properties ( osc_port ); - int i,k,n=0; - + int i; for( i = 0; osc_events[i] != NULL ; i ++ ) { void *osc_info = NULL; @@ -603,7 +558,6 @@ static void sample_osc_print( void *osc_port ) assert( error == VEVO_NO_ERROR ); #endif char *format = get_str_vevo( osc_info, "format" ); - veejay_msg(VEEJAY_MSG_INFO, "OSC PATH %s",osc_events[i] ); char *descr = get_str_vevo( osc_info, "description" ); if(descr) @@ -641,30 +595,28 @@ static void sample_osc_print( void *osc_port ) void sample_osc_namespace(void *sample) { sample_runtime_data *srd = (sample_runtime_data*) sample; - + int k; void *osc_namespace = NULL; int error = vevo_property_get( srd->info_port, "HOST_osc",0, &osc_namespace); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif + + if( error != VEVO_NO_ERROR) //@ plug has no namespace + return; + veejay_msg(VEEJAY_MSG_INFO,"OSC namespace:"); sample_osc_print( osc_namespace ); -veejay_msg(VEEJAY_MSG_INFO,"FX:"); - int k; + veejay_msg(VEEJAY_MSG_INFO,"FX:"); for( k = 0; k < SAMPLE_CHAIN_LEN ; k ++ ) { - void *port = sample_get_fx_port_ptr( srd, k ); - void *fx_instance = NULL; - error = vevo_property_get( port, "fx_instance", 0, &fx_instance ); - if( error == VEVO_NO_ERROR ) + fx_slot_t *slot = sample_get_fx_port_ptr( srd, k ); + if(slot->fx_instance) { - void *space = plug_get_name_space( fx_instance ); + void *space = plug_get_name_space( slot->fx_instance ); if(space) sample_osc_print( space ); } } -veejay_msg(VEEJAY_MSG_INFO,"End of OSC namespace"); + veejay_msg(VEEJAY_MSG_INFO,"End of OSC namespace"); } @@ -694,7 +646,7 @@ int sample_extract_fx_entry_from_path(void *sample, const char *path ) } -int sample_osc_property_calls_event( void *sample, const char *path, char *types, void **argv[] ) +int sample_osc_property_calls_event( void *sample, const char *path, char *types, void **argv[], void *raw ) { sample_runtime_data *srd = (sample_runtime_data*) sample; void *vevo_port = srd->info_port; @@ -706,7 +658,6 @@ int sample_osc_property_calls_event( void *sample, const char *path, char *type int atom_type = vevo_property_atom_type( osc_port, path ); if( atom_type == VEVO_ATOM_TYPE_PORTPTR ) { - // veejay_msg(0, "path %s is PORTPTR", path ); void *port = NULL; error = vevo_property_get( osc_port, path,0,&port ); #ifdef STRICT_CHECKING @@ -715,23 +666,12 @@ int sample_osc_property_calls_event( void *sample, const char *path, char *type if(error == VEVO_NO_ERROR ) { vevo_event_f f; -//veejay_msg(0, "verify '%s' : %p, types %s, instance=%p", path,port, types,sample); - - - // char *format = get_str_vevo( port, "format" ); -//veejay_msg(0, "format is %s", format); - - - - - - if( sample_osc_verify_format( port, types ) ) { error = vevo_property_get( port, "func",0,&f ); if( error == VEVO_NO_ERROR ) { - (*f)( sample, path,types, argv ); + (*f)( sample, path,types, argv, raw); return 1; } } @@ -741,20 +681,11 @@ int sample_osc_property_calls_event( void *sample, const char *path, char *type } int sample_fx_set_in_channel( void *info, int fx_entry, int seq_num, const int sample_id ) { - void *port = sample_get_fx_port_ptr( info, fx_entry ); - void *fx_channels = NULL; - void *fx_instance = NULL; - char key[64]; - int error = vevo_property_get( port, "fx_channels",0, &fx_channels ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif + fx_slot_t *slot = sample_get_fx_port_ptr( info, fx_entry ); + int max_in = 0; + void *inputs = sample_scan_in_channels( info, fx_entry, &max_in ); + char key[20]; - int max_in = 0; - error = vevo_property_get( fx_channels, "n_in_channels", 0, &max_in ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif if (seq_num < 0 || seq_num >= max_in ) { veejay_msg(0, "FX has at most %d input channel(s)", @@ -768,254 +699,125 @@ int sample_fx_set_in_channel( void *info, int fx_entry, int seq_num, const int s #ifdef STRICT_CHECKING assert( sample != NULL ); #endif - error = vevo_property_set( fx_channels, key, VEVO_ATOM_TYPE_VOIDPTR, 1, &sample ); + int error = vevo_property_set( inputs, key, VEVO_ATOM_TYPE_VOIDPTR, 1, &sample ); #ifdef STRICT_CHECKING assert( error == VEVO_NO_ERROR ); #endif + + veejay_msg(0, "Set input channel %d, sample %s", seq_num, key ); + return 1; } int sample_fx_push_in_channel( void *info, int fx_entry, int seq_num, void *frame_info ) { - void *port = sample_get_fx_port_ptr( info,fx_entry ); + fx_slot_t *slot = sample_get_fx_port_ptr( info,fx_entry ); #ifdef STRICT_CHECKING - assert( port != NULL ); + assert( slot != NULL ); #endif - void *fx_instance = NULL; - - int error = vevo_property_get( port, "fx_instance", 0, &fx_instance ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif - plug_push_frame( fx_instance, 0,seq_num, frame_info ); + plug_push_frame( slot->fx_instance, 0,seq_num, frame_info ); return 1; } int sample_fx_push_out_channel( void *info, int fx_entry, int seq_num, void *frame_info ) { - void *port = sample_get_fx_port_ptr( info,fx_entry ); + fx_slot_t *slot = sample_get_fx_port_ptr( info,fx_entry ); #ifdef STRICT_CHECKING - assert( port != NULL ); + assert( slot != NULL ); #endif - void *fx_instance = NULL; - - int error = vevo_property_get( port, "fx_instance", 0, &fx_instance ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif - plug_push_frame( fx_instance, 1,seq_num, frame_info ); - + plug_push_frame( slot->fx_instance, 1,seq_num, frame_info ); return 1; } -int sample_process_entry( void *data, int fx_entry ) -{ - void *port = sample_get_fx_port_ptr( data,fx_entry ); -#ifdef STRICT_CHECKING - assert( port != NULL ); -#endif - int fx_status; - int error = vevo_property_get( port, "fx_status",0,&fx_status); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif - return fx_status; -} double sample_get_fx_alpha( void *data, int fx_entry ) { - void *port = sample_get_fx_port_ptr( data,fx_entry ); -#ifdef STRICT_CHECKING - assert( port != NULL ); -#endif - double fx_alpha=0.0; - int error = vevo_property_get( port, "fx_alpha",0,&fx_alpha); - - if( error != VEVO_NO_ERROR ) - return 0.0; - - return fx_alpha; + fx_slot_t *slot = sample_get_fx_port_ptr( data,fx_entry ); + return slot->alpha; } void sample_set_fx_alpha( void *data, int fx_entry, double v ) { - void *port = sample_get_fx_port_ptr( data,fx_entry ); + sample_runtime_data *srd = (sample_runtime_data*) data; + + fx_slot_t *slot = sample_get_fx_port_ptr( data,fx_entry ); #ifdef STRICT_CHECKING - assert( port != NULL ); -#endif - int error = vevo_property_set( port, "fx_alpha",VEVO_ATOM_TYPE_DOUBLE,1,&v); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); + assert( slot != NULL ); #endif + if( v > 1.0 ) v = 1.0; else if (v < 0.0 ) v = 0.0; + if( v != slot->alpha ) + { + void *sender = veejay_get_osc_sender( srd->user_data ); + if(sender) + veejay_bundle_sample_fx_add(sender, srd->primary_key,fx_entry, "alpha", "d", v ); + + } + slot->alpha = v; } - -void sample_toggle_process_entry( void *data, int fx_entry, int v ) +int sample_get_fx_status( void *data, int fx_entry ) { - void *port = sample_get_fx_port_ptr( data,fx_entry ); -#ifdef STRICT_CHECKING - assert( port != NULL ); -#endif - int fx_status = v; - int error = 0; - void *fxi = NULL; - error = vevo_property_get( port, "fx_instance", - 0, &fxi ); - if( error != VEVO_NO_ERROR ) - { - veejay_msg(0,"Nothing to enable on entry %d",fx_entry); + fx_slot_t *slot = sample_get_fx_port_ptr( data,fx_entry ); + return slot->active; +} +void sample_set_fx_status( void *data, int fx_entry, int status ) +{ + sample_runtime_data *srd = (sample_runtime_data*) data; + if( fx_entry < 0 || fx_entry > SAMPLE_CHAIN_LEN ) return; - } - - error = vevo_property_set( port, "fx_status",VEVO_ATOM_TYPE_INT,1,&fx_status); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif -} -void *sample_scan_in_channels( void *data, int fx_entry ) -{ - void *port = sample_get_fx_port_ptr( data,fx_entry ); -#ifdef STRICT_CHECKING - assert( port != NULL ); -#endif - int n = sample_fx_num_in_channels( port ); - if( n <= 0 ) - return NULL; -//FIXME: fx_channels contains slot[d] with value sample ptr, -//// quque list expects sample[d] with value sample ptr - void *fx_channels = NULL; - int error = vevo_property_get( port, "fx_channels",0, &fx_channels); -#ifdef STRICT_CHECKING - assert( error == 0 ); -#endif - return fx_channels; -} -/*void *sample_scan_in_channels( void *data, int fx_entry ) -{ -#ifdef STRICT_CHECKING - assert( data != NULL); -#endif - sample_runtime_data *info = (sample_runtime_data*) data; -#ifdef STRICT_CHECKING - assert( info != NULL ); - assert( info->info_port != NULL ); -#endif - void *port = sample_get_fx_port_ptr( info,fx_entry ); - - int n = sample_fx_num_in_channels( port ); - - if( n <= 0 ) - return NULL; - void *fx_channels = NULL; - int error = vevo_property_get( port, "fx_channels",0, &fx_channels); -#ifdef STRICT_CHECKING - assert( error == 0 ); -#endif - veejay_msg(0, "Entry %d has port fx_channels: %p", fx_entry,fx_channels ); - char **list = vevo_list_properties( fx_channels ); - int k = 0; - for ( k = 0; list[k] != NULL ; k ++ ) + fx_slot_t *slot = sample_get_fx_port_ptr( data,fx_entry ); + if(status && !slot->fx_instance) { - veejay_msg(0, "\t'%s'", list[k]); - free(list[k]); - } - free(list); + veejay_msg(0, "Nothing to enable in FX slot %d", status); + return; + } + slot->active = status; + void *sender = veejay_get_osc_sender( srd->user_data ); + if(sender) + veejay_bundle_sample_fx_add(sender, srd->primary_key, fx_entry, "status", "i", status ); - - return fx_channels; -}*/ +} -int sample_scan_out_channels( void *data, int fx_entry ) +int sample_scan_out_channels( void *sample, int i ) { - void *port = sample_get_fx_port_ptr( data,fx_entry ); - if(!port) - return NULL; + fx_slot_t *slot = sample_get_fx_port_ptr( sample,i ); #ifdef STRICT_CHECKING - assert( port != NULL ); -#endif - return sample_fx_num_out_channels( port ); + assert( slot != NULL ); + assert( slot->fx_instance != NULL ); +#endif + return vevo_property_num_elements( slot->fx_instance, "out_channels" ); +} + +void *sample_scan_in_channels( void *sample, int i , int *num) +{ + fx_slot_t *slot = sample_get_fx_port_ptr( sample,i ); +#ifdef STRICT_CHECKING + assert( slot != NULL ); + assert( slot->fx_instance != NULL ); +#endif + *num = vevo_property_num_elements( slot->fx_instance, "in_channels" ); + + //return vevo_property_num_elements( slot->fx_instance, "in_channels" ); + return slot->in_channels; } // frame buffer passed by performer int sample_process_fx( void *sample, int fx_entry ) { - unsigned int i,k; - void *fx_instance = NULL; - void *fx_values = NULL; - void *fx_out_values = NULL; - - void *port = sample_get_fx_port_ptr( sample,fx_entry ); - sample_runtime_data *srd = (sample_runtime_data*) sample; + fx_slot_t *slot = sample_get_fx_port_ptr( sample,fx_entry ); #ifdef STRICT_CHECKING - assert( port != NULL ); + assert( slot != NULL ); #endif - int error = vevo_property_get( port, "fx_instance", 0, &fx_instance ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif - error = vevo_property_get( port, "fx_values", 0, &fx_values ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif + plug_clone_from_parameters( slot->fx_instance, slot->in_values ); - error = vevo_property_get( port, "fx_out_values",0,&fx_out_values ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif - - //update internal parameter values - plug_clone_from_parameters( fx_instance, fx_values ); + plug_process( slot->fx_instance ); + plug_clone_from_output_parameters( slot->fx_instance, slot->out_values ); + + if(slot->bind) sample_apply_bind( sample, slot , fx_entry ); - plug_process( fx_instance ); - - //get the output parameters,if any - - plug_clone_from_output_parameters( fx_instance, fx_out_values ); - - sample_apply_bind( sample, port ); - - if(srd->osc) - //@ send osc message if needed - sample_send_osc_path( sample, port ); - - return VEVO_NO_ERROR; } - - - -int sample_fx_num_in_channels( void *port ) -{ - void *fx_channels = NULL; - int error = vevo_property_get( port, "fx_channels",0, &fx_channels ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif - int n_channels = 0; - error = vevo_property_get( fx_channels, "n_in_channels", 0, &n_channels ); - if( error != VEVO_NO_ERROR ) - n_channels = 0; - - return n_channels; -} -int sample_fx_num_out_channels( void *port ) -{ - void *fx_channels = NULL; - int error = vevo_property_get( port, "fx_channels",0, &fx_channels ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif - int n_channels = 0; - vevo_property_get( fx_channels, "n_out_channels", 0, &n_channels ); - return n_channels; -} - -int sample_fx_set_by_name( int id, int fx_entry, const char *name ) -{ - return 0; -} - void *sample_get_fx_port_ptr( void *data, int fx_entry ) { sample_runtime_data *info = (sample_runtime_data*) data; @@ -1023,11 +825,14 @@ void *sample_get_fx_port_ptr( void *data, int fx_entry ) char fx[KEY_LEN]; sprintf(fx, "fx_%x", fx_entry ); #ifdef STRICT_CHECKING + assert( info != NULL ); assert( info->info_port != NULL ); #endif int error = vevo_property_get( info->info_port, fx, 0, &port ); #ifdef STRICT_CHECKING + if(error != 0 ) + veejay_msg(0,"%s: Entry %d returns error code %d", __FUNCTION__,fx_entry, error ); assert( error == 0 ); assert( port != NULL ); #endif @@ -1036,38 +841,48 @@ void *sample_get_fx_port_ptr( void *data, int fx_entry ) int sample_get_fx_id( void *data , int fx_entry ) { - void *port = sample_get_fx_port_ptr( data, fx_entry ); - int fx_id = -1; - int error = vevo_property_get( port, "fx_id",0, &fx_id ); - return fx_id; + fx_slot_t *slot = sample_get_fx_port_ptr( data, fx_entry ); + return slot->fx_id; +} + +int sample_has_fx( void *sample, int fx_entry ) +{ + fx_slot_t *slot = (fx_slot_t*) sample_get_fx_port_ptr( sample, fx_entry ); + if(!slot) + return 0; + + if(slot->fx_instance) + return 1; + return 0; } static void *sample_get_fx_port_values_ptr( int id, int fx_entry ) { - void *port = sample_get_fx_port( id, fx_entry ); - void *fx_values = NULL; - int error = vevo_property_get( port, "fx_values", 0, &fx_values ); - return fx_values; + fx_slot_t *slot = sample_get_fx_port( id, fx_entry ); + return slot->in_values; } void *sample_get_fx_port_channels_ptr( int id, int fx_entry ) { - void *port = sample_get_fx_port( id, fx_entry ); - void *fx_values = NULL; - int error = vevo_property_get( port, "fx_channels", 0, &fx_values ); - return fx_values; + fx_slot_t *slot = sample_get_fx_port( id, fx_entry ); + return slot->in_channels; } void *sample_get_fx_port( int id, int fx_entry ) { return sample_get_fx_port_ptr( find_sample(id),fx_entry ); } + int sample_set_property_ptr( void *ptr, const char *key, int atom_type, void *value ) { sample_runtime_data *info = (sample_runtime_data*) ptr; if( info->type == VJ_TAG_TYPE_CAPTURE) { - vj_unicap_select_value( info->data,key, atom_type,value ); + char *rkey = sample_translate_property( ptr, key ); + if(rkey) + { vj_unicap_select_value( info->data,rkey, atom_type,value ); + free(rkey); + } return VEVO_NO_ERROR; } return vevo_property_set( info->info_port, key, atom_type,1, value ); @@ -1078,10 +893,28 @@ void sample_set_property( int id, const char *key, int atom_type, void *value ) sample_runtime_data *info = (sample_runtime_data*) find_sample( id ); if( info->type == VJ_TAG_TYPE_CAPTURE) { - vj_unicap_select_value( info->data,key, atom_type,value ); + char *rkey = sample_translate_property( info, key ); + if(rkey) + { + vj_unicap_select_value( info->data,rkey, atom_type,value ); + void *sender = veejay_get_osc_sender( info->user_data ); + if(sender) //@ att , unicap class deals just with doubles for now + veejay_bundle_sample_add_atom(sender, info->primary_key, rkey, "d",VEVO_ATOM_TYPE_DOUBLE, value ); + + free(rkey); + } } if(info) - vevo_property_set( info->info_port, key, atom_type,1, value ); + if(vevo_property_set( info->info_port, key, atom_type,1, value ) == VEVO_NO_ERROR ) + { + void *sender = veejay_get_osc_sender( info->user_data ); + if(sender) + { + char *format = vevo_property_get_string( info->fmt_port, key ); + veejay_bundle_sample_add_atom( sender, info->primary_key, key, format, atom_type,value ); + free(format); + } + } } static char *strip_key( const char *path) @@ -1130,7 +963,7 @@ static char *strip_port( const char *path) return port; } -void sample_set_property_from_path( void *sample, const char *path, void *value ) +void sample_set_property_from_path( void *sample, const char *path,int elements, void *value ) { sample_runtime_data *info = (sample_runtime_data*) sample; int len = strlen(path); @@ -1141,12 +974,24 @@ void sample_set_property_from_path( void *sample, const char *path, void *value if( path[i] == '/' ) n++; + veejay_msg(0, "Change '%s'", path ); + char *key = strip_key( path ); if(!key) { veejay_msg(0, "Error getting key from path '%s'", path ); return; } + + if( info->type == VJ_TAG_TYPE_CAPTURE && vevo_property_get(info->info_port,key,0,NULL) != VEVO_NO_ERROR ) + { + char *my_key = sample_reverse_translate_property(sample, key ); + if(my_key) + { + free(key); + key = my_key; + } + } //@ TYPE CAPTURE ! int atom_type = vevo_property_atom_type( info->info_port, key ); if( n == 3 ) @@ -1161,8 +1006,17 @@ void sample_set_property_from_path( void *sample, const char *path, void *value { error = vevo_property_set( port,key, atom_type,1, value ); if( error == VEVO_NO_ERROR ) + { veejay_msg(VEEJAY_MSG_INFO, - "OSC path '%s' sets property '%s' %d", path, key,atom_type ); + "OSC path '%s' sets property '%s' %d", path, key,atom_type ); + void *sender = veejay_get_osc_sender( info->user_data ); + if(sender) + { + char *format = vevo_property_get_string( info->fmt_port, key ); + veejay_bundle_add_atom( sender, path, format, atom_type,value ); + free(format); + } + } if(pk) free(pk); return; } @@ -1188,17 +1042,24 @@ void sample_set_property_from_path( void *sample, const char *path, void *value if( info->type == VJ_TAG_TYPE_CAPTURE) { - veejay_msg(0,"Warning 'key %s' may not be valid", key ); - //@ can make translation map in unicap -> key -> key pairs vj_unicap_select_value( info->data,key, VEVO_ATOM_TYPE_DOUBLE,value ); } if(info) - error = vevo_property_set( info->info_port,key, atom_type,1, value ); + error = vevo_property_set( info->info_port,key, atom_type,elements, value ); if( error == VEVO_NO_ERROR ) + { veejay_msg(VEEJAY_MSG_INFO, "OSC path '%s' sets property '%s' %d", path, key,atom_type ); - + void *sender = veejay_get_osc_sender( info->user_data ); + if(sender) + { + char *format = vevo_property_get_string( info->fmt_port, key ); + veejay_bundle_add_atom( sender, path, format, atom_type,value ); + free(format); + } + } + free(key); } @@ -1216,7 +1077,20 @@ void sample_set_user_data( void *sample, void *data, int id ) sample_runtime_data *info = (sample_runtime_data*) sample; info->user_data = data; sample_init_namespace( data, sample, id ); - + void *sender = veejay_get_osc_sender( data ); + if(sender) + { + char name[64]; + sprintf(name, "Sample %d",id ); + veejay_ui_bundle_add( sender, "/update/sample", + "isx", id, name ); + } +} + +void *sample_get_user_data( void *sample ) +{ + sample_runtime_data *info = (sample_runtime_data*) sample; + return (void*) info->user_data; } void sample_get_property_ptr( void *ptr, const char *key, void *dst ) @@ -1312,47 +1186,81 @@ const char *sample_describe_type( int type ) return NULL; } +static void sample_ui_close( void *sample ) +{ + sample_runtime_data *srd = (sample_runtime_data*) sample; + void *sender = veejay_get_osc_sender( srd->user_data ); + if(sender) + { + char name[128]; + sprintf(name, "Sample%d", srd->primary_key ); + veejay_ui_bundle_add( sender, "/destroy/window", "sx", name ); + } +} + +static void sample_ui_fx_close( void *sample, int fx_entry , void *user_data) +{ + sample_runtime_data *srd = (sample_runtime_data*) sample; + fx_slot_t *slot = sample_get_fx_port_ptr( srd, fx_entry ); + + void *sender = veejay_get_osc_sender( user_data ); + if(sender) + { + veejay_msg(0, "Close '%s'", slot->window); + veejay_ui_bundle_add( sender, "/destroy/window", "sx", slot->window ); + } +} + +static void sample_ui_close_all( void *sample ) +{ + sample_runtime_data *srd = (sample_runtime_data*) sample; + int i; +// for( i = 0; i < SAMPLE_CHAIN_LEN ; i ++ ) +// { +// sample_ui_fx_close( sample, i, srd->user_data ); +// } + + sample_ui_close(sample); +} + + static void sample_fx_entry_clean_up( void *sample, int id, void *user_data ) { - char entry_key[KEY_LEN]; - void *entry_port = NULL; - - sprintf(entry_key, "fx_%x", id ); - int error = vevo_property_get( sample, entry_key,0, &entry_port ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif - void *instance = NULL; - error = vevo_property_get( entry_port, "fx_instance",0,&instance ); - if(error == VEVO_NO_ERROR ) - { - // delete OSC space - plug_clear_namespace( instance, user_data ); - - plug_deactivate( instance ); - } - void *fxv = NULL; - error = vevo_property_get( entry_port, "fx_values",0,&fxv ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif - void *fxc = NULL; - error = vevo_property_get(entry_port, "fx_channels",0,&fxc ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif - -// vevo_port_free( fxv ); -// vevo_port_free( fxc ); -// vevo_port_free( entry_port ); - - vevo_port_recursive_free( entry_port ); + sample_runtime_data *srd = (sample_runtime_data*) sample; + fx_slot_t *slot = sample_get_fx_port_ptr( srd, id ); - error = vevo_property_set( sample, entry_key, VEVO_ATOM_TYPE_PORTPTR, 0, NULL ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif + if(slot->window) + sample_ui_fx_close( sample, id, user_data ); + else + veejay_msg(0, "FX slot %d has no window, sample %d", id, + sample_get_key_ptr(sample) ); + if(slot->window) + free(slot->window); + if(slot->frame) + free(slot->frame); + + if( slot->fx_instance ) + { + plug_clear_namespace( slot->fx_instance, user_data ); + plug_deactivate( slot->fx_instance ); + } + vevo_port_free( slot->in_values ); + vevo_port_free( slot->out_values ); + vevo_port_free( slot->out_channels ); + + if( slot->bind ) + { + sample_reset_bind ( sample, slot ); + } + + free(slot); + + //@ set fx port ptr to NULL + char fx[KEY_LEN]; + sprintf(fx, "fx_%x", id ); + vevo_property_set( srd->info_port, fx, VEVO_ATOM_TYPE_PORTPTR,0,NULL ); + } static void sample_fx_clean_up( void *sample, void *user_data ) @@ -1368,50 +1276,19 @@ static void sample_fx_clean_up( void *sample, void *user_data ) static void sample_new_fx_chain_entry( void *sample, int id ) { -#ifdef STRICT_CHECKING - void *port = vevo_port_new( VEVO_FX_ENTRY_PORT,__FUNCTION__,__LINE__ ); -#else - void *port = vevo_port_new( VEVO_FX_ENTRY_PORT ); -#endif - char entry_key[KEY_LEN]; - + sample_runtime_data *srd = (sample_runtime_data*) sample; + + char entry_key[64]; + fx_slot_t *slot = (fx_slot_t*) vj_malloc(sizeof(fx_slot_t)); + memset( slot,0,sizeof(fx_slot_t)); + sprintf(entry_key, "fx_%x", id ); - int dstatus = 0; - int error = vevo_property_set( port, "fx_status", VEVO_ATOM_TYPE_INT,1,&dstatus ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif - double alpha = 0.0; - error = vevo_property_set( port, "fx_alpha", VEVO_ATOM_TYPE_DOUBLE,1,&alpha ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif -#ifdef STRICT_CHECKING - void *fx_values = vevo_port_new( VEVO_FX_VALUES_PORT, __FUNCTION__,__LINE__ ); - void *fx_channels = vevo_port_new( VEVO_ANONYMOUS_PORT, __FUNCTION__,__LINE__ ); - void *fx_out_values = vevo_port_new( VEVO_ANONYMOUS_PORT, __FUNCTION__,__LINE__ ); -#else - void *fx_values = vevo_port_new( VEVO_FX_VALUES_PORT ); - void *fx_channels = vevo_port_new( VEVO_ANONYMOUS_PORT ); - void *fx_out_values = vevo_port_new( VEVO_ANONYMOUS_PORT ); -#endif - error = vevo_property_set( port, "fx_values", VEVO_ATOM_TYPE_PORTPTR,1,&fx_values); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif - error = vevo_property_set( port, "fx_out_values", VEVO_ATOM_TYPE_PORTPTR,1,&fx_out_values); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif - error = vevo_property_set( port, "fx_channels",VEVO_ATOM_TYPE_PORTPTR,1,&fx_channels ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif - error = vevo_property_set( port, "fx_instance", VEVO_ATOM_TYPE_PORTPTR,0,NULL ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif - error = vevo_property_set( sample, entry_key, VEVO_ATOM_TYPE_PORTPTR,1, &port ); + slot->in_values = vpn( VEVO_FX_VALUES_PORT ); + slot->in_channels = vpn( VEVO_ANONYMOUS_PORT ); + slot->out_values = vpn( VEVO_ANONYMOUS_PORT ); + slot->out_channels = vpn( VEVO_ANONYMOUS_PORT ); + + int error = vevo_property_set( srd->info_port, entry_key, VEVO_ATOM_TYPE_PORTPTR,1, &slot ); #ifdef STRICT_CHECKING assert( error == VEVO_NO_ERROR ); #endif @@ -1435,10 +1312,12 @@ int sample_fx_chain_entry_clear(void *info, int id ) if( id >= 0 && id < SAMPLE_CHAIN_LEN ) { - sample_fx_entry_clean_up( sample->info_port, id,sample->user_data ); - sample_new_fx_chain_entry( sample->info_port, id ); + sample_fx_entry_clean_up( info, id,sample->user_data ); + sample_new_fx_chain_entry( info, id ); return 1; } + else + veejay_msg(0, "Invalid FX slot: %d",id); return 0; } @@ -1453,11 +1332,8 @@ void *sample_new( int type ) rtdata->record = (samplerecord_t*) vj_malloc(sizeof(samplerecord_t)); memset(rtdata->record,0,sizeof(samplerecord_t)); rtdata->type = type; -#ifdef STRICT_CHECKING - rtdata->info_port = (void*) vevo_port_new( VEVO_SAMPLE_PORT , __FUNCTION__ , __LINE__ ); -#else - rtdata->info_port = (void*) vevo_port_new( VEVO_SAMPLE_PORT ); -#endif + rtdata->info_port = (void*) vpn( VEVO_SAMPLE_PORT ); + rtdata->fmt_port =(void*) vpn( VEVO_ANONYMOUS_PORT ); for(i = 0 ; common_property_list[i].name != NULL ; i ++ ) vevo_property_set( rtdata->info_port, @@ -1481,7 +1357,7 @@ void *sample_new( int type ) } - sample_new_fx_chain( rtdata->info_port ); + sample_new_fx_chain( rtdata ); return res; } @@ -1498,11 +1374,20 @@ char *sample_property_format_osc( void *sample, const char *path ) if(n==2||n==3) { char *key = strip_key(path); + char *rkey = NULL; + char *fmt = NULL; if( key == NULL ) return NULL; - char *fmt = NULL; - // char *fmt = (char*) malloc( n + 1 ); - // bzero(fmt,n + 1); + + if( srd->type == VJ_TAG_TYPE_CAPTURE && vevo_property_get( srd->info_port, key,0,NULL ) != VEVO_NO_ERROR ) + { + char *tmpkey = sample_reverse_translate_property(sample, key ); + if(tmpkey) + { + free(key); + key = tmpkey; + } + } if( sample_property_is_protected( srd->info_port ,key)==1 ) { @@ -1569,6 +1454,7 @@ char *sample_property_format_osc( void *sample, const char *path ) return NULL; } } + veejay_msg(0, "++ '%s' has format '%s'", key,fmt ); free(key); return fmt; } @@ -1585,16 +1471,19 @@ void sample_init_namespace( void *data, void *sample , int id ) char **namespace = vevo_port_recurse_namespace( rtdata->info_port, name ); int n = 0; int k; -#ifdef STRICT_CHECKING - void *osc_namespace = vevo_port_new( VEVO_ANONYMOUS_PORT, __FUNCTION__ , __LINE__ ); -#else - void *osc_namespace = vevo_port_new(VEVO_ANONYMOUS_PORT); -#endif + + if(!namespace) + { + veejay_msg(0, "Sample %d has no OSC namespace",id); + return; + } + + + void *osc_namespace = vpn(VEVO_ANONYMOUS_PORT); for ( k = 0; namespace[k] != NULL ; k ++ ) { - // sample_set_property_from_path( void *sample, const char *path, void *value ); - char *format = sample_property_format_osc( sample, namespace[k] ); + if(format == NULL ) { if( vevo_property_atom_type( rtdata->info_port, namespace[k] ) == VEVO_ATOM_TYPE_PORTPTR ) @@ -1612,29 +1501,37 @@ void sample_init_namespace( void *data, void *sample , int id ) { char *fmt = sample_property_format_osc( port, ns_entries[q] ); vevosample_new_event( data, osc_namespace, sample,NULL, ns_entries[q], fmt, NULL,NULL, NULL,-1 ); - + if(fmt) + { + error = vevo_property_set( rtdata->fmt_port, ns_entries[q], + VEVO_ATOM_TYPE_STRING,1,&fmt ); + } if(fmt) free(fmt); free(ns_entries[q]); } free(ns_entries); } } - } else { vevosample_new_event( data, osc_namespace, sample, NULL, namespace[k], format,NULL, NULL,NULL, 0 ); + vevo_property_set( rtdata->fmt_port, namespace[k], VEVO_ATOM_TYPE_STRING,1,&format ); + free(format); + } free(namespace[k]); } free(namespace); + ///FIXME if(rtdata->type == VJ_TAG_TYPE_NONE ) veejay_osc_add_sample_nonstream_events(data,osc_namespace,rtdata,name); veejay_osc_add_sample_generic_events( data,osc_namespace,rtdata,name, SAMPLE_CHAIN_LEN ); + error = vevo_property_set( rtdata->info_port, "HOST_osc",VEVO_ATOM_TYPE_PORTPTR,1,&osc_namespace); #ifdef STRICT_CHECKING @@ -1650,11 +1547,7 @@ int vevo_num_devices() void samplebank_init() { -#ifdef STRICT_CHECKING - sample_bank_ = (void*) vevo_port_new( VEVO_SAMPLE_BANK_PORT, __FUNCTION__, __LINE__ ); -#else - sample_bank_ = (void*) vevo_port_new( VEVO_SAMPLE_BANK_PORT ); -#endif + sample_bank_ = (void*) vpn( VEVO_SAMPLE_BANK_PORT ); #ifdef STRICT_CHECKING veejay_msg(2,"VEVO Sampler initialized. (max=%d)", SAMPLE_LIMIT ); #endif @@ -1662,7 +1555,9 @@ void samplebank_init() unicap_data_ = (void*) vj_unicap_init(); #ifdef STRICT_CHECKING assert( unicap_data_ != NULL ); -#endif +#endif + ui_register_ = (void*) vpn( VEVO_SAMPLE_BANK_PORT ); + } char *samplebank_sprint_list() @@ -1695,6 +1590,153 @@ char *samplebank_sprint_list() return res; } +typedef struct +{ + struct timeval t; +} ui_alarm_t; +static void *alarm_init(void) +{ + ui_alarm_t *uia = (ui_alarm_t*) vj_malloc(sizeof(ui_alarm_t)); + gettimeofday( &(uia->t),NULL); + return (void*) uia; +} + +void samplebank_tick_ui_client( char *uri ) +{ + void *alarm = alarm_init(); + void *old_alarm = NULL; + int error = vevo_property_get( ui_register_, uri, 0,&old_alarm ); + if( old_alarm ) + free( old_alarm ); + + error = vevo_property_set( ui_register_, + uri, VEVO_ATOM_TYPE_VOIDPTR, 1, &alarm ); +} + +int samplebank_flush_ui_client( char *uri, struct timeval *now ) +{ + void *alarm = NULL; + if(vevo_property_get( ui_register_, uri, 0,&alarm )==VEVO_NO_ERROR) + { + ui_alarm_t *uia = (ui_alarm_t*) alarm; + if( now->tv_sec > (uia->t.tv_sec + 3)) + { + veejay_msg(0, "'%s' timeout", uri); + free(alarm); + vevo_property_set( ui_register_, uri,VEVO_ATOM_TYPE_VOIDPTR,0,NULL); + return 0; + } + } + return 1; +} + +void samplebank_flush_osc(void *info, void *clients) +{ + struct timeval now; + char **ccl = vevo_list_properties( clients ); + if(!ccl) + return; + char **props = (char**) vevo_list_properties( sample_bank_ ); + if(!props) + return; + int i,k; + + gettimeofday(&now,NULL); + for( k = 0; ccl[k] != NULL ; k ++ ) + { + if(!samplebank_flush_ui_client( ccl[k], &now )) + { + veejay_msg(0, "URI '%s' is not alive anymore?", ccl[k]); + void *sender = NULL; + if( vevo_property_get(clients, ccl[k],0,&sender) == VEVO_NO_ERROR ) + { + veejay_free_osc_sender(sender); + vevo_property_set( clients, ccl[k], VEVO_ATOM_TYPE_VOIDPTR,0,NULL ); + } + } + free(ccl[k]); + } + free(ccl); + + char **cl = vevo_list_properties( clients ); + if(!cl) + return; + + for( i = 0; props[i] != NULL;i ++ ) + { + if( props[i][0] == 's' ) + { + void *info = find_sample_by_key( props[i] ); + if(info) + { + for( k = 0; cl[k] != NULL ; k ++ ) + sample_flush_bundle(info, cl[k] ); + } + } + free(props[i]); + } + free(props); + + for( k = 0; cl[k] != NULL ; k ++ ) + free( cl[k] ); + free( cl ); + +} + +//waste +int samplebank_guess_row_sequence( void *osc, int id ) +{ + char **props = (char**) vevo_list_properties( sample_bank_ ); + if(!props) + return 0; + int i; + for( i = 0; props[i] != NULL;i ++ ) + { + if( props[i][0] == 's' ) + { + void *info = find_sample_by_key( props[i] ); + sample_runtime_data *s = (sample_runtime_data*) info; + if(s && s->primary_key == id ) + return i; + } + free(props[i]); + } + free(props); + return 0; // take the first +} + +void samplefx_push_pulldown_items( void *osc, void *msg) +{ + int i; + for( i = 0; i < SAMPLE_CHAIN_LEN; i ++ ) + { + char name[32]; + sprintf(name,"fx %d", i ); + veejay_message_add_argument( osc,msg, "s", name ); + } +} + +void samplebank_push_pulldown_items( void *osc, void *msg ) +{ + char **props = (char**) vevo_list_properties( sample_bank_ ); + if(!props) + return; + int i; + veejay_message_add_argument( osc, msg, "s", "none" ); + for( i = 0; props[i] != NULL;i ++ ) + { + if( props[i][0] == 's' ) + { + void *info = find_sample_by_key( props[i] ); + if(info) + { + veejay_message_add_argument( osc, msg, "s", props[i] ); + } + } + free(props[i]); + } + free(props); +} void samplebank_free() { @@ -1711,6 +1753,7 @@ void samplebank_free() if( props[i][0] == 's' ) { void *info = find_sample_by_key( props[i] ); + veejay_msg(0, "Sample '%s' -> %p", props[i], info ); if( info ) sample_delete_ptr( info ); } @@ -1727,6 +1770,37 @@ void samplebank_free() } +void samplebank_send_all_samples(void *sender) +{ + char **items = vevo_list_properties( sample_bank_ ); + if(!items ) + { + veejay_msg(0, "Samplebank empty"); + return; + } + int i; + for( i = 0 ; items[i] != NULL ; i ++ ) + { + void *sample = NULL; + int error = vevo_property_get( sample_bank_ , items[i],0,&sample ); + if(items[i][0] == 's' ) + { + if( error == VEVO_NO_ERROR ) + { + sample_runtime_data *dd = (sample_runtime_data*) sample; + veejay_ui_bundle_add( sender, "/update/sample", + "isx", dd->primary_key, items[i] ); + veejay_msg(0,"\t /update/sample %d", dd->primary_key ); + } + else + veejay_msg(0, "\tError in '%s'", items[i]); + } + free(items[i]); + } + + free(items); +} + int samplebank_add_sample( void *sample ) { char pri_key[20]; @@ -1758,6 +1832,10 @@ int samplebank_add_sample( void *sample ) assert( error == VEVO_NO_ERROR ); #endif num_samples_ += 1; + srd->primary_key = pk; + + + return pk; } @@ -1779,6 +1857,23 @@ void *sample_last(void) return found; } + +// "Video source" --> "video_source" +char *sample_translate_property( void *sample, char *name ) +{ + sample_runtime_data *srd = (sample_runtime_data*) sample; + char *result =vevo_property_get_string( srd->mapping, name ); + return result; +} + +// "video_source" --> "Video source" +static char *sample_reverse_translate_property( void *sample, char *name ) +{ + sample_runtime_data *srd = (sample_runtime_data*) sample; + char *result =vevo_property_get_string( srd->rmapping, name ); + return result; +} + static void sample_collect_unicap_properties( void *sample ) { sample_runtime_data *srd = (sample_runtime_data*) sample; @@ -1789,11 +1884,14 @@ static void sample_collect_unicap_properties( void *sample ) double dvalue = 0.0; int n = vj_unicap_get_value( srd->data, props[i], VEVO_ATOM_TYPE_DOUBLE, &dvalue ); - veejay_msg(0, "Add property '%s', default is %g", props[i], dvalue); + char *realname = veejay_valid_osc_name( props[i] ); vevo_property_set( srd->info_port, props[i], VEVO_ATOM_TYPE_DOUBLE,1,&dvalue ); + vevo_property_set( srd->mapping, props[i], VEVO_ATOM_TYPE_STRING,1,&realname); + vevo_property_set( srd->rmapping, realname, VEVO_ATOM_TYPE_STRING,1,&(props[i])); free( props[i] ); + free( realname ); } } @@ -1862,6 +1960,8 @@ int sample_open( void *sample, const char *token, int extra_token , sample_video case VJ_TAG_TYPE_CAPTURE: srd->data = vj_unicap_new_device( unicap_data_, extra_token ); + srd->mapping = vpn( VEVO_ANONYMOUS_PORT ); + srd->rmapping = vpn( VEVO_ANONYMOUS_PORT ); if(!vj_unicap_configure_device( srd->data, project_settings->fmt, project_settings->w, @@ -1936,33 +2036,6 @@ int sample_open( void *sample, const char *token, int extra_token , sample_video int sample_append_file( const char *filename, long n1, long n2, long n3 ) { - /*end = el->video_frames; - - * - * // create initial edit list for sample (is currently playing) - if(!sample_edl) - sample_edl = vj_el_init_with_args( files,1,info->preserve_pathnames,info->auto_deinterlace,0, - info->edit_list->video_norm , info->pixel_format); - // i - el->frame_list = (uint64_t *) realloc(el->frame_list, (end + el->num_frames[n])*sizeof(uint64_t)); - if (el->frame_list==NULL) - { - veejay_msg(VEEJAY_MSG_ERROR, "Insufficient memory to allocate frame_list"); - vj_el_free(el); - return 0; - } - - for (i = 0; i < el->num_frames[n]; i++) - { - el->frame_list[c] = EL_ENTRY(n, i); - c++; - } - - el->video_frames = c; -//@ set min and max frame num anew -//@ update start/end positions - - */ return 1; } @@ -2150,8 +2223,6 @@ void sample_increase_frame( void *current_sample ) sit->current_pos ++; return; } - - uint64_t cf = sit->current_pos; if(sit->repeat_count > 0) @@ -2218,6 +2289,12 @@ void sample_increase_frame( void *current_sample ) assert( sit->current_pos >= sit->start_pos ); assert( sit->current_pos <= sit->end_pos ); #endif + void *sender = veejay_get_osc_sender( srd->user_data ); + if(sender) + { + veejay_bundle_sample_add( sender, srd->primary_key, "current_pos", "h", sit->current_pos ); + } + } void sample_set_itu601( void *current_sample, int status ) @@ -2313,9 +2390,6 @@ int sample_get_frame( void *current_sample , void *dslot ) long frame_num = srd->info->current_pos; void *ptr = NULL; - - //srd->type !! - //@ assign function pointer at sample_open to kill this switch statement switch(srd->type) { case VJ_TAG_TYPE_NONE: @@ -2342,9 +2416,6 @@ int sample_get_frame( void *current_sample , void *dslot ) break; #endif } - - - return VEVO_NO_ERROR; } @@ -2366,7 +2437,6 @@ static void sample_close( sample_runtime_data *srd ) break; #ifdef USE_GDK_PIXBUF case VJ_TAG_TYPE_PICTURE: - //vj_picture_cleanup( break; #endif case VJ_TAG_TYPE_NET: @@ -2412,8 +2482,6 @@ static void sample_write_property( void *port, const char *key, xmlNodePtr node char *str_val = NULL; int error = 0; -printf("%s: %p, %s type = %d\n", __FUNCTION__, port, key, atom_type ); - switch( atom_type ) { case VEVO_ATOM_TYPE_INT: @@ -2687,40 +2755,21 @@ int sample_xml_load( const char *filename, void *samplebank ) int sample_set_param_from_str( void *srd, int fx_entry,int p, const char *str ) { - void *port = sample_get_fx_port_ptr( srd, fx_entry ); - if(port) - { - void *fx_instance = NULL; - int error = vevo_property_get( port, "fx_instance",0,&fx_instance ); - void *fx_values = NULL; - -veejay_msg(0, "Entry %d, Param %d, '%s'",fx_entry,p,str); - - if(error == VEVO_NO_ERROR) - { - void *fx_values = NULL; - error = vevo_property_get( port, "fx_values",0,&fx_values ); - return plug_set_param_from_str( fx_instance, p, str,fx_values ); - } - else - veejay_msg(0 ,"No fx instance on entry %d", fx_entry ); - } + fx_slot_t *slot = sample_get_fx_port_ptr( srd, fx_entry ); + + if(slot->fx_instance) + return plug_set_param_from_str( slot->fx_instance, p, str,slot->in_values ); else - veejay_msg(0, "Entry %d is invalid",fx_entry); + veejay_msg(0, "No FX in slot %d",fx_entry); + return 0; } - char *sample_describe_param( void *srd, int fx_entry, int p ) { - void *port = sample_get_fx_port_ptr( srd, fx_entry ); - if(port) - { - void *fx_instance = NULL; - int error = vevo_property_get( port, "fx_instance",0,&fx_instance ); - - return plug_describe_param( fx_instance, p ); - } + fx_slot_t *slot = sample_get_fx_port_ptr( srd, fx_entry ); + if(slot->fx_instance) + return plug_describe_param( slot->fx_instance, p ); return NULL; } @@ -2771,10 +2820,9 @@ static int sample_parse_param( void *fx_instance, int num, const char format[], } *format++; } - +veejay_msg(0, "Change parameter"); plug_set_parameter( fx_instance, num,n_elems, p ); - if( i ) free( i ); if( g ) free( g ); if( s ) free( s ); @@ -2787,53 +2835,24 @@ int sample_set_param( void *srd, int fx_entry, int p, const char format[] , ... va_list ap; int n = 0; - void *port = sample_get_fx_port_ptr( srd, fx_entry ); - if(!port) - return n; - - void *fx_instance = NULL; - int error = vevo_property_get( port, "fx_instance",0,&fx_instance ); - if( error != VEVO_NO_ERROR ) + fx_slot_t *slot = sample_get_fx_port_ptr( srd, fx_entry ); + if(!slot->fx_instance) return n; va_start( ap, format ); - n = sample_parse_param( fx_instance, p , format, ap ); + n = sample_parse_param( slot->fx_instance, p , format, ap ); va_end(ap); return n; } + void sample_process_fx_chain( void *srd ) { int k = 0; - for( k = 0; k < SAMPLE_CHAIN_LEN; k ++ ) { - void *port = sample_get_fx_port_ptr( srd, k ); - void *fx_instance = NULL; - /* int fx_status = 0; - - int error = vevo_property_get( port, "fx_status", 0, &fx_status); -#ifdef STRICT_CHECKING - assert( error == 0 ); -#endif - -//@TODO: Alpha fading - - if( fx_status ) - {*/ - int error = vevo_property_get( port, "fx_instance", 0, &fx_instance ); -#ifdef STRICT_CHECKING - assert( error == 0 ); -#endif - plug_process( fx_instance ); - - void *fx_values = NULL; - error = vevo_property_get( port, "fx_values", 0, &fx_values ); -#ifdef STRICT_CHECKING - assert( error == 0 ); -#endif - plug_clone_from_parameters( fx_instance, fx_values ); - // } + fx_slot_t *slot = sample_get_fx_port_ptr( srd, k ); + plug_process( slot->fx_instance ); } } @@ -2863,9 +2882,6 @@ void sample_cache_data( void *info ) vevo_property_get( srd->info_port, "has_audio",0,&(sit->has_audio)); vevo_property_get( srd->info_port, "rate",0,&(sit->rate)); vevo_property_get( srd->info_port, "repeat",0,&(sit->repeat)); -// veejay_msg(0, "start %d - end %d - speed %d - loop %d - position %d - in %d - out %d", -// sit->start_pos,sit->end_pos,sit->speed,sit->looptype,sit->current_pos, -// sit->in_point, sit->out_point ); } void sample_save_cache_data( void *info) @@ -2876,9 +2892,6 @@ void sample_save_cache_data( void *info) sample_runtime_data *srd = (sample_runtime_data*) info; sampleinfo_t *sit = srd->info; -// veejay_msg(0, "SAVE: start %d - end %d - speed %d - loop - %d position %d -in - %d -out %d", -/// sit->start_pos,sit->end_pos,sit->speed,sit->looptype,sit->current_pos, -// sit->in_point, sit->out_point ); vevo_property_set( srd->info_port, "start_pos",VEVO_ATOM_TYPE_UINT64,1,&(sit->start_pos )); vevo_property_set( srd->info_port, "end_pos", VEVO_ATOM_TYPE_UINT64,1,&(sit->end_pos)); vevo_property_set( srd->info_port, "speed", VEVO_ATOM_TYPE_INT,1,&(sit->speed )); @@ -3037,6 +3050,9 @@ int sample_fx_sscanf_port( void *sample, const char *s, const char *id ) #define MAX_ELEMENTS 16 static int sample_sscanf_property( sample_runtime_data *srd ,vevo_port_t *port, const char *s) { +#ifdef STRICT_CHECKING + assert(0); +#endif int done = 0; char key[PROPERTY_KEY_SIZE]; bzero(key, PROPERTY_KEY_SIZE ); @@ -3148,6 +3164,9 @@ static int sample_sscanf_property( sample_runtime_data *srd ,vevo_port_t *port, int sample_sscanf_port( void *sample, const char *s ) { +#ifdef STRICT_CHECKING + assert(0); +#endif sample_runtime_data *srd = (sample_runtime_data*) sample; const char *ptr = s; int len = strlen(s); @@ -3179,6 +3198,9 @@ int sample_sscanf_port( void *sample, const char *s ) char *sample_sprintf_port( void *sample ) { +#ifdef STRICT_CHECKING + assert(0); +#endif sample_runtime_data *srd = (sample_runtime_data*) sample; int k; int size = 0; @@ -3247,8 +3269,6 @@ int sample_configure_recorder( void *sample, int format, const char *filename, i return 1; } - - switch( format ) { //@ todo: not all encoders here, mod lav_io.c @@ -3485,419 +3505,284 @@ int sample_record_frame( void *sample, void *dframe, uint8_t *audio_buffer, int int sample_reset_bind( void *sample, void *src_entry ) { - void *bptr = NULL; - int error = vevo_property_get( src_entry, "bind",0,&bptr ); - if( error != VEVO_NO_ERROR ) - return 0; - bind_t *bt = (bind_t*) bptr; - free(bt); + sample_runtime_data *srd = (sample_runtime_data*) sample; + fx_slot_t *slot = (fx_slot_t*) src_entry; + + if(slot->bind) + { + int i = 0; + char **items = vevo_list_properties( slot->bind ); + for( i = 0; items[i] != NULL ; i ++ ) + { + void *p = NULL; + if(vevo_property_get(slot->bind, items[i],0,&p) == VEVO_NO_ERROR ) + free(p); + } + vevo_port_free( slot->bind ); + slot->bind = NULL; + } - error = vevo_property_set( src_entry, "bind", VEVO_ATOM_TYPE_VOIDPTR,0,NULL ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif return 1; } - -int sample_del_bind( void *sample, void *src_entry, int pi ) +int sample_del_bind_occ( void *sample, void *src_entry, int n_out_p, int k_entry ) { - void *bptr = NULL; - int error = vevo_property_get( src_entry, "bind",0,&bptr ); -#ifdef STRICT_CHECKING - assert( pi >= 0 && pi < 32 ); -#endif - if( error != VEVO_NO_ERROR ) - return 1; - bind_t *bt = (bind_t*) bptr; - bt->p[pi] = -1; - bt->e[pi] = -1; - error = vevo_property_set( src_entry, "bind", VEVO_ATOM_TYPE_VOIDPTR,1,&bptr ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif - return VEVO_NO_ERROR; -} + sample_runtime_data *srd = (sample_runtime_data*) sample; + fx_slot_t *slot = (fx_slot_t*) src_entry; + if(!slot->bind) + return 0; + char **items = slot->bind; + if(!items) + return 0; + char name[64]; + void *sender = veejay_get_osc_sender( srd->user_data ); + sprintf(name,"SampleBind%dFX%02dOP%d", srd->primary_key, k_entry, n_out_p ); + if(sender) + veejay_ui_bundle_add( sender, "/destroy/window", "sx", name ); + -int sample_new_bind( void *sample, void *src_entry, int entry, int pi, int pj ) -{ - void *bptr = NULL; - int error = vevo_property_get( src_entry, "bind",0,&bptr ); -#ifdef STRICT_CHECKING - assert( pi >= 0 && pi < 32 ); - assert( entry >= 0 && entry <= 19); -#endif - - if(error == VEVO_NO_ERROR ) + int i; + for( i = 0; items[i] != NULL ; i ++ ) { - bind_t *bt = (bind_t*) bptr; - bt->p[pi] = pj; - bt->e[pi] = entry; - } - else - { - bind_t *bt = (bind_t*) vj_malloc(sizeof(bind_t)); - int i; - for ( i = 0; i < 32; i ++ ) + int dummy = 0; + int dd=0; + int this_p = -1; + sscanf( items[i], "bp%d_%d_%d", &this_p,&dd,&dummy); + + if( this_p == n_out_p && vevo_property_get(slot->bind,items[i],0,NULL) == VEVO_NO_ERROR) { - bt->p[i] = -1; - bt->e[i] = -1; + void *bp = NULL; + int error = vevo_property_get( slot->bind, items[i],0,&bp ); + if( error == VEVO_NO_ERROR ) + { + free(bp); + vevo_property_set( slot->bind, items[i], VEVO_ATOM_TYPE_VOIDPTR,0,NULL ); + bp = NULL; + } } - bt->p[pi] = pj; - bt->e[pi] = entry; - bptr = (void*) bt; + free(items[i]); } - - error = vevo_property_set( src_entry, "bind", VEVO_ATOM_TYPE_VOIDPTR,1,&bptr ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif - + free(items); return VEVO_NO_ERROR; } -int sample_apply_bind( void *sample, void *current_entry ) +int sample_del_bind( void *sample, void *src_entry, int k_entry, int n_out_p, int fx_right, int in_p ) { + sample_runtime_data *srd = (sample_runtime_data*) sample; + fx_slot_t *slot = (fx_slot_t*) src_entry; + if(!slot->bind) + return 0; + char key[64]; + void *bp = NULL; + sprintf(key, "bp%02d_%02d_%02d", n_out_p, fx_right, in_p ); + char name[64]; + sprintf(name,"SampleBind%dFX%02dOP%d", srd->primary_key, k_entry, n_out_p ); + + int error = vevo_property_get( slot->bind, key,0,&bp ); + if( error == VEVO_NO_ERROR ) + { + free(bp); + error = vevo_property_set( slot->bind, key, VEVO_ATOM_TYPE_VOIDPTR,0,NULL ); + bp = NULL; + } + + vevosample_ui_get_bind_list( srd, name ); + + + return VEVO_NO_ERROR; +} + +void *sample_new_bind_parameter( void *fx_a, void *fx_b, int n_out_p, int n_in_p, int n_in_entry ) +{ + bind_parameter_t *bt = (bind_parameter_t*) vj_malloc(sizeof( bind_parameter_t)); + memset(bt,0,sizeof(bind_parameter_t)); + int dummy = 0; +#ifdef STRICT_CHECKING + assert( fx_a != NULL ); + assert( fx_b != NULL ); + assert( n_out_p >= 0 && n_in_p >= 0 && n_in_entry >= 0 && n_in_entry < SAMPLE_CHAIN_LEN ); +#endif + if( plug_parameter_get_range_dbl( fx_a, "out_parameters", n_out_p, &(bt->min[0]), &(bt->max[0]) , &dummy ) != VEVO_NO_ERROR ) + { + veejay_msg(0, "Can only bind parameters of type INDEX or NUMBER"); + free(bt); + return NULL; + } + if( plug_parameter_get_range_dbl( fx_b, "in_parameters", n_in_p, &(bt->min[1]), &(bt->max[1]), &(bt->kind) ) != VEVO_NO_ERROR ) + { + veejay_msg(0, "Can only bind parameters of type INDEX or NUMBER"); + free(bt); + return NULL; + } + bt->p[0] = n_out_p; + bt->p[1] = n_in_p; + bt->entry = n_in_entry; + + veejay_msg(0, "New bind %d %d %d", n_out_p,n_in_p, n_in_entry ); + + return (void*) bt; + +} + +int sample_new_bind( void *sample, void *src_entry,int n_out_p, int dst_entry, int n_in_p ) +{ + void *fx_a = NULL; + void *fx_b = NULL; + int error = 0; + char bind_key[64]; + char param_key[64]; + sample_runtime_data *srd = (sample_runtime_data*) sample; + + fx_slot_t *dst_slot = sample_get_fx_port_ptr( srd, dst_entry ); + fx_slot_t *src_slot = (fx_slot_t*) src_entry; + + if(!src_slot->fx_instance || !dst_slot->fx_instance ) + { + veejay_msg(0, "There must be a plugin in both FX slots"); + return 1; + } + + sprintf( param_key, "bp%02d_%02d_%02d",n_out_p, dst_entry, n_in_p); + + if(!src_slot->bind) + src_slot->bind = vpn( VEVO_ANONYMOUS_PORT ); + + if( vevo_property_get( src_slot->bind, param_key, 0, NULL ) == VEVO_NO_ERROR ) + { + veejay_msg(0, "There is a bind from this output parameter to Entry %d, input %d", + dst_entry,n_in_p ); + return 1; + } + + void *inp = sample_new_bind_parameter( + src_slot->fx_instance, + dst_slot->fx_instance, + n_out_p, + n_in_p, + dst_entry + ); + + if(!inp) + { + veejay_msg(0, "Error while binding parameter"); + return 1; + } + + error = vevo_property_set( src_slot->bind, param_key, VEVO_ATOM_TYPE_VOIDPTR,1,&inp ); +#ifdef STRICT_CHECKING + assert( error == VEVO_NO_ERROR ); +#endif + return VEVO_NO_ERROR; +} + +int sample_apply_bind( void *sample, void *current_entry, int k_entry ) +{ + sample_runtime_data *srd = (sample_runtime_data*) sample; + fx_slot_t *slot = (fx_slot_t*) current_entry; +#ifdef STRICT_CHECKING + assert( slot->bind != NULL ); +#endif + char **items = vevo_list_properties( slot->bind ); + if(! items ) + { + veejay_msg(0, "BIND empty for sample %d", + srd->primary_key ); + return 1; + } char key[64]; char dkey[64]; - void *bptr = NULL; - int error = vevo_property_get( current_entry, "bind",0,&bptr ); - void *fx_out_values = NULL; - void *fx_values = NULL; - if( error != VEVO_NO_ERROR ) - return 0; - - bind_t *bt = (bind_t*)bptr; + char dwin[32]; + sprintf(dwin , "Sample%dFX%d", srd->primary_key, k_entry ); int i; - for ( i = 0; i < 32 ; i ++ ) + + for( i = 0; items[i] != NULL ; i ++ ) { - if( bt->p[i] >= 0 ) + void *bp = NULL; + int error = vevo_property_get( slot->bind, items[i],0,&bp ); + +veejay_msg(0,"\t apply bind '%s' : error %d", items[i], error ); + if( error == VEVO_NO_ERROR ) { - sprintf(key, "p%02d", i ); - sprintf(dkey, "p%02d", bt->p[i] ); - - int dentry = bt->e[i]; - void *dst_entry = sample_get_fx_port_ptr( sample,dentry ); -#ifdef STRICT_CHECKING - assert( dst_entry != NULL ); -#endif - error = vevo_property_get( current_entry, "fx_out_values",0,&fx_out_values ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif - error = vevo_property_get( dst_entry, "fx_values",0,&fx_values ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif + bind_parameter_t *bpt = (bind_parameter_t*) bp; - //@ todo: is atom type compatible ? - clone_prop_vevo( - fx_out_values, - fx_values, - key, - dkey ); + void *fx_b = NULL; + fx_slot_t *dst_slot = sample_get_fx_port_ptr( srd, bpt->entry ); + + if(dst_slot->active && slot->active) + { + double weight = 0.0; + int iw = 0; + double value=0.0; + char *path = plug_get_osc_path_parameter( dst_slot->fx_instance, bpt->p[1] ); + char *fmt = plug_get_osc_format( dst_slot->fx_instance, bpt->p[1]); + char pkey[8]; + sprintf(pkey, "p%02d",bpt->p[0]); + void *sender = veejay_get_osc_sender( srd->user_data ); + + char *output_pname[128]; + char *output_pval = vevo_sprintf_property_value( slot->out_values, pkey ); + + sprintf(output_pname, "o%02d", bpt->p[0]); + if(bpt->kind == HOST_PARAM_INDEX) + { + if( vevo_property_get( slot->out_values, pkey,0,&value ) == VEVO_NO_ERROR ) + { + weight = 1.0 / (bpt->max[1] - bpt->min[1]); + iw = (int) ( value * weight ); + plug_set_parameter( dst_slot->fx_instance, bpt->p[1], 1, &iw ); + if(path && sender) + veejay_bundle_add( sender, path, fmt, iw ); + if(sender) + veejay_xbundle_add( sender,dwin , output_pname,"s", (output_pval==NULL ? " " : output_pval) ); + } + } + else if(bpt->kind == HOST_PARAM_NUMBER) + { + if( vevo_property_get( slot->out_values, pkey,0,&value ) == VEVO_NO_ERROR ) + { + double norm = (1.0 / (bpt->max[0] - bpt->min[0])) * value; + double gv = (bpt->max[1] - bpt->min[1]) * norm + bpt->min[1]; + plug_set_parameter( dst_slot->fx_instance, bpt->p[1], 1, &gv ); + if(path && sender) + veejay_bundle_add( sender, path, fmt, gv ); + if(sender) + veejay_xbundle_add( sender, dwin, output_pname,"s",(output_pval==NULL ? " " : output_pval)); + } + } + else + { + veejay_msg(0, "Kind is not compatible: %d", bpt->kind ); + } + if(path) free(path); + if(fmt) free(fmt); + if(output_pval) free(output_pval); } + } + free( items[i] ); } - + free(items); return 0; } -int sample_new_osc_sender(void *sample, const char *addr, const char *port ) +void *sample_clone_from( void *info, void *sample, sample_video_info_t *project_settings ) { sample_runtime_data *srd = (sample_runtime_data*) sample; - if(srd->osc) - { - veejay_msg(0, "There is already an OSC sender active"); - return 1; - } + int type = srd->type; + char **list = vj_el_get_file_list( srd->data ); - void *osc_client = veejay_new_osc_sender( addr, port ); - if(!osc_client) + void *new_sample = sample_new( type ); + + int i = 0; + + if( sample_open( new_sample, list[i], 0, project_settings ) ) { - veejay_msg(0, "Unable to start OSC sender"); - return 1; + veejay_msg(0, "Opened '%s' ",list[i]); + int new_id = samplebank_add_sample( new_sample ); + sample_set_user_data( new_sample, info, new_id ); } - srd->osc = osc_client; - - veejay_msg(VEEJAY_MSG_INFO, - "OSC address '%s' port '%s', Sender active", - addr,port ); - - return VEVO_NO_ERROR; -} - -void sample_close_osc_sender( void *sample ) -{ - sample_runtime_data *srd = (sample_runtime_data*) sample; - if(srd->osc) - { - veejay_free_osc_sender( srd->osc ); - srd->osc = NULL; - veejay_msg(VEEJAY_MSG_INFO, - "OSC sender inactive"); - } -} - -void sample_add_osc_path( void *sample, const char *path, int fx_entry_id ) -{ - sample_runtime_data *srd = (sample_runtime_data*) sample; - - //@ add osc path to entry - void *port = sample_get_fx_port_ptr( sample,fx_entry_id ); - - int error = vevo_property_set( port, "fx_osc", VEVO_ATOM_TYPE_STRING,1,&path ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif -} - -void sample_del_osc_path( void *sample, int fx_entry_id ) -{ - sample_runtime_data *srd = (sample_runtime_data*) sample; - - //@ add osc path to entry - void *port = sample_get_fx_port_ptr( sample,fx_entry_id ); - - int error = vevo_property_set( srd->info_port, "fx_osc", VEVO_ATOM_TYPE_STRING,0,NULL ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif -} - -void sample_send_osc_path( void *sample, void *fx_entry ) -{ - sample_runtime_data *srd = (sample_runtime_data*) sample; - - char *osc_path = get_str_vevo( fx_entry, "fx_osc" ); - if(!osc_path) - { - return; - } - - void *fx_out_values = NULL; - - int error = vevo_property_get( fx_entry, "fx_out_values",0,&fx_out_values ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); - assert( srd->osc != NULL ); -#endif - - if( osc_path ) - { - veejay_vevo_send_osc( srd->osc, - osc_path, - fx_out_values ); - - free(osc_path); - } -} - -static char *osc_path_to_khagan_path( const char *str ) -{ - int n = strlen( str ) + 5; - char *res = (char*) malloc( n ); - char arg = '%'; - snprintf(res,n, "%s %c", str ,arg); - return res; -} -int khagan_write_property( void *port, const char *key, xmlNodePtr node ) -{ - int atom_type = vevo_property_atom_type( port, key ); - int n_elem = vevo_property_num_elements( port , key ); - int error; - if( n_elem == 0 || n_elem > 1 ) - { - veejay_msg(0, "Khagan doesnt do list values ??"); - return 1; - } - - if( atom_type == VEVO_ATOM_TYPE_INT || atom_type == VEVO_ATOM_TYPE_BOOL ) - { - int ival = 0; - error = vevo_property_get( port, key, 0, &ival ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif - int_as_value( node, ival, key ); - return 0; - } - else if ( atom_type == VEVO_ATOM_TYPE_DOUBLE ) - { - double gval = 0.0; - error = vevo_property_get( port, key,0, &gval ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif - double_as_value( node, gval, key ); - return 0; - } - else if ( atom_type == VEVO_ATOM_TYPE_STRING ) - { - char *str = get_str_vevo( port, key ); - if( str ) - { - cstr_as_value( node, str, key ); - free(str); - } - return 0; - } - - return 1; -} - -int khagan_write_property_as( void *port, const char *key, xmlNodePtr node, const char *as_key ) -{ - int atom_type = vevo_property_atom_type( port, key ); - int n_elem = vevo_property_num_elements( port , key ); - int error; - if( n_elem == 0 || n_elem > 1 ) - { - veejay_msg(0, "Khagan doesnt do list values ??"); - return 1; - } - - if( atom_type == VEVO_ATOM_TYPE_INT || atom_type == VEVO_ATOM_TYPE_BOOL ) - { - int ival = 0; - error = vevo_property_get( port, key, 0, &ival ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif - int_as_value( node, ival, as_key ); - return 0; - } - else if ( atom_type == VEVO_ATOM_TYPE_DOUBLE ) - { - double gval = 0.0; - error = vevo_property_get( port, key,0, &gval ); -#ifdef STRICT_CHECKING - assert( error == VEVO_NO_ERROR ); -#endif - double_as_value( node, gval, as_key ); - return 0; - } - else if ( atom_type == VEVO_ATOM_TYPE_STRING ) - { - char *str = get_str_vevo( port, key ); - if( str ) - { - cstr_as_value( node, str, as_key ); - free(str); - } - return 0; - } - - return 1; -} - -/* - * Khagan, OSC live interface builder. - * - * - */ -static void sample_produce_khagan_widget(void *osc_port,int port_num, xmlNodePtr rootnode, int n) -{ - //sample_runtime_data *srd = (sample_runtime_data*) sample; - - char **list = vevo_list_properties ( osc_port ); - int i; - - int v_splits = n - 1; - - xmlNodePtr nodes[ v_splits ]; - xmlNodePtr cur_node = rootnode; - int n_widgets = 0; - for( i = 0; list[i] != NULL ; i ++ ) - { - void *osc = NULL; - int error = vevo_property_get( osc_port, list[i],0,&osc ); - - void *template = NULL; - error = vevo_property_get( osc, "parent",0,&template ); - if( error == VEVO_NO_ERROR ) - { - if( n_widgets < v_splits ) - { - nodes[n_widgets] = - xmlNewChild( cur_node, NULL, (const xmlChar*) "vsplit", NULL ); - } - else - nodes[n_widgets] = cur_node; - - xmlNodePtr node = - xmlNewChild( nodes[n_widgets] , NULL, (const xmlChar*) "widget", NULL ); - - - char *description = get_str_vevo( template, "description"); - char *khagan_path = osc_path_to_khagan_path( list[i] ); - - cstr_as_value( node, "PhatKnob", "name" ); - - khagan_write_property_as( template, "default", node, "value" ); - khagan_write_property( template, "min" , node ); - khagan_write_property( template, "max" , node ); - cstr_as_value( node, khagan_path, "osc_path" ); - int_as_value( node, port_num, "port" ); - cstr_as_value( node, description, "label" ); - cstr_as_value( node, "False", "is_log" ); - - free(description); - free(khagan_path); - - cur_node = nodes[n_widgets]; - - n_widgets ++; - - } - else - veejay_msg(0, "%s has no parent", list[i]); free(list[i]); - } free(list); -} - - -void sample_produce_khagan_file( void *sample ) -{ - sample_runtime_data *srd = (sample_runtime_data*) sample; - int port_num = veejay_get_port( srd->user_data ); - int error; - int k; - const char *encoding = "UTF-8"; - int id = 0; - error = vevo_property_get( srd->info_port, "primary_key", 0, &id ); - - for( k =0; k < SAMPLE_CHAIN_LEN; k ++ ) - { - void *fxp = sample_get_fx_port_ptr( srd, k ); - void *fxi = NULL; - error = vevo_property_get( fxp, "fx_instance",0,&fxi ); - - if( error == VEVO_NO_ERROR ) - { - xmlNodePtr rootnode; - xmlDocPtr doc = xmlNewDoc( "1.0" ); - rootnode = xmlNewDocNode( doc, NULL, (const xmlChar*) "gui", NULL ); - xmlDocSetRootElement( doc, rootnode ); - void *osc_port = plug_get_name_space( fxi ); - int n = vevo_property_num_elements( fxi, "in_parameters" ); - - if( osc_port ) - sample_produce_khagan_widget( osc_port, port_num, rootnode ,n); - - - char filename[256]; - sprintf(filename, "sample_%d_fx_%d.kh", id,k ); - FILE *res = fopen( filename , "w" ); - if(!res) - veejay_msg(0, "Cannot write to %s",filename); - else - xmlDocDump( res, doc ); - fclose(res); - - xmlFreeDoc( doc ); - } - } + return new_sample; } diff --git a/veejay-ng/vevosample/vevosample.h b/veejay-ng/vevosample/vevosample.h index 7059afdb..9f9f1f93 100644 --- a/veejay-ng/vevosample/vevosample.h +++ b/veejay-ng/vevosample/vevosample.h @@ -53,11 +53,12 @@ int sample_open( void *sample, const char *token, int extra_token, sample_video int sample_get_frame( void *current_sample, void *slot ); void sample_fx_set_parameter( int id, int fx_entry, int param_id,int n, void *data ); void sample_fx_get_parameter( int id, int fx_enty,int param_id,int idx, void *dst ); -void sample_toggle_process_entry( void *data, int fx_entry, int v ); int sample_fx_set_active( int id, int fx_entry, int switch_value); int sample_fx_set_channel( int id, int fx_entry, int n_input, int channel_id ); double sample_get_fx_alpha( void *data, int fx_entry ); void sample_set_fx_alpha( void *data, int fx_entry, double v ); +int sample_get_fx_status( void *data, int fx_entry ); +void sample_set_fx_status( void *data, int fx_entry, int status ); void sample_set_itu601( void *current_sample, int status ); int sample_fx_set( void *info, int fx_entry, const int new_fx ); void sample_process_fx_chain( void *srd ); @@ -89,7 +90,7 @@ char *sample_sprintf_port( void *sample ); int sample_fx_push_in_channel( void *info, int fx_entry, int seq_num, void *frame_info ); int sample_fx_push_out_channel(void *info, int fx_entry, int seq_num, void *frame_info ); int sample_scan_out_channels( void *data, int fx_entry ); -void *sample_scan_in_channels( void *data, int fx_entry ); +void *sample_scan_in_channels( void *data, int fx_entry, int *num ); void *sample_get_fx_port_ptr( void *data, int fx_entry ); void *sample_get_fx_port_channels_ptr( int id, int fx_entry ); int sample_get_key_ptr( void *sample ); @@ -109,17 +110,17 @@ void sample_send_osc_path( void *sample, void *fx_entry ); char *sample_describe_param( void *srd, int fx_entry, int p ); int sample_set_param( void *srd, int fx_entry, int p, const char format[] , ... ); void sample_set_user_data( void *sample, void *data, int id ); -void sample_set_property_from_path( void *sample, const char *path, void *value ); +void sample_set_property_from_path( void *sample, const char *path,int elements, void *value ); char *sample_property_format_osc( void *sample, const char *path ); void sample_init_namespace( void *data, void *sample , int id ); -int sample_osc_property_calls_event( void *sample, const char *path, char *types, void **argv[] ); +int sample_osc_property_calls_event( void *sample, const char *path, char *types, void **argv[] , void *data); -typedef void (*vevo_event_f)(void *ptr, const char *path,const char *types, void **argv); +typedef void (*vevo_event_f)(void *ptr, const char *path,const char *types, void **argv, void *raw); int sample_osc_new_sample_event( void *sample, const char *key, const char *fmt, const char **args, vevo_event_f *func ); int sample_osc_verify_format( void *vevo_port, char const *types ); - +void *sample_clone_from( void *info, void *sample, sample_video_info_t *project_settings ); #endif diff --git a/veejay-ng/vevosample/vj-unicap.c b/veejay-ng/vevosample/vj-unicap.c index efa7786b..abea8b43 100644 --- a/veejay-ng/vevosample/vj-unicap.c +++ b/veejay-ng/vevosample/vj-unicap.c @@ -67,7 +67,7 @@ static int vj_unicap_scan_enumerate_devices(void *unicap) int i; unicap_driver_t *ud = (unicap_driver_t*) unicap; char key[64]; - + for( i = 0; SUCCESS( unicap_enumerate_devices( NULL, &(ud->device), i ) ); i++ ) { unicap_property_t property; @@ -81,18 +81,15 @@ static int vj_unicap_scan_enumerate_devices(void *unicap) veejay_msg(0, "Failed to open: %s\n", &(ud->device.identifier) ); continue; } - + unicap_lock_properties( ud->handle ); + unicap_reenumerate_properties( ud->handle, &property_count ); unicap_reenumerate_formats( ud->handle, &format_count ); char *device_name = strdup( ud->device.identifier ); -#ifdef STRICT_CHECKING - void *device_port = vevo_port_new( VEVO_ANONYMOUS_PORT, device_name, i ); -#else - void *device_port = vevo_port_new( VEVO_ANONYMOUS_PORT ); -#endif + void *device_port = vpn( VEVO_ANONYMOUS_PORT ); char *device_location = strdup( ud->device.device ); int error = vevo_property_set( device_port, @@ -127,6 +124,8 @@ static int vj_unicap_scan_enumerate_devices(void *unicap) #ifdef STRICT_CHECKING assert( error == VEVO_NO_ERROR ); #endif + unicap_unlock_properties( ud->handle ); + unicap_close( ud->handle ); } return i; @@ -136,16 +135,19 @@ void *vj_unicap_init(void) { unicap_driver_t *ud = (unicap_driver_t*) vj_malloc(sizeof(unicap_driver_t)); memset( ud,0,sizeof(unicap_driver_t)); -#ifdef STRICT_CHECKING - ud->device_list = vevo_port_new( VEVO_ANONYMOUS_PORT, __FUNCTION__, __LINE__ ); -#else - ud->device_list = vevo_port_new( VEVO_ANONYMOUS_PORT ); -#endif + ud->device_list = vpn( VEVO_ANONYMOUS_PORT ); ud->num_devices = vj_unicap_scan_enumerate_devices( (void*) ud ); veejay_msg(2, "Found %d capture devices on this system", ud->num_devices); return ud; } +void *vj_unicap_get_devices(void *in) +{ + unicap_driver_t *ud = (unicap_driver_t*) in; + return ud->device_list; + +} + void vj_unicap_deinit(void *dud ) { unicap_driver_t *ud = (unicap_driver_t*) dud; @@ -192,16 +194,104 @@ int vj_unicap_set_property( void *ud, char *key, int atom_type, void *val ) return 1; } */ + +void vj_unicap_pack_menu( void *ud, char *key , void *osc, void *msg ) +{ + unicap_property_t property; + unicap_property_t property_spec; + int i; + unicap_void_property( &property_spec ); + unicap_void_property( &property ); + vj_unicap_t *vut = (vj_unicap_t*) ud; + unicap_lock_properties( vut->handle ); + + for( i = 0; SUCCESS( unicap_enumerate_properties( vut->handle, + &property_spec, &property, i ) ); i ++ ) + { + unicap_get_property( vut->handle, &property); + if( strcmp( property.identifier, key ) == 0 ) + { + int n = property.menu.menu_item_count; + int j; + for( j = 0; j < n ; j ++ ) + { + veejay_message_add_argument( osc, msg, "s", + property.menu.menu_items[j] ); + } + } + } + unicap_unlock_properties( vut->handle); +} + +int vj_unicap_property_is_menu( void *ud, char *key ) +{ + unicap_property_t property; + unicap_property_t property_spec; + int i; + unicap_void_property( &property_spec ); + unicap_void_property( &property ); + vj_unicap_t *vut = (vj_unicap_t*) ud; + unicap_lock_properties( vut->handle ); + + for( i = 0; SUCCESS( unicap_enumerate_properties( vut->handle, + &property_spec, &property, i ) ); i ++ ) + { + unicap_get_property( vut->handle, &property); + if( strcmp( property.identifier, key ) == 0 ) + { + unicap_unlock_properties( vut->handle); + if( property.type == UNICAP_PROPERTY_TYPE_MENU ) + return 1; + else + return 0; + } + } + unicap_unlock_properties( vut->handle); + return 0; +} +int vj_unicap_property_is_range( void *ud, char *key ) +{ + unicap_property_t property; + unicap_property_t property_spec; + int i; + unicap_void_property( &property_spec ); + unicap_void_property( &property ); + vj_unicap_t *vut = (vj_unicap_t*) ud; + unicap_lock_properties( vut->handle ); + + for( i = 0; SUCCESS( unicap_enumerate_properties( vut->handle, + &property_spec, &property, i ) ); i ++ ) + { + unicap_get_property( vut->handle, &property); + if( strcmp( property.identifier, key ) == 0 ) + { + unicap_unlock_properties( vut->handle); + if( property.type == UNICAP_PROPERTY_TYPE_RANGE ) + return 1; + else + return 0; + } + } + unicap_unlock_properties( vut->handle); + return 0; +} + int vj_unicap_select_value( void *ud, char *key, int atom_type, void *val ) { unicap_property_t property; unicap_property_t property_spec; int i; unicap_void_property( &property_spec ); + unicap_void_property( &property ); vj_unicap_t *vut = (vj_unicap_t*) ud; +// memset( &property,0 ,sizeof( unicap_property_t)); + unicap_lock_properties( vut->handle ); + for( i = 0; SUCCESS( unicap_enumerate_properties( vut->handle, &property_spec, &property, i ) ); i ++ ) { + // memset( &property,0 ,sizeof( unicap_property_t)); + unicap_get_property( vut->handle, &property); if( strcmp( property.identifier, key ) == 0 ) { @@ -213,13 +303,19 @@ int vj_unicap_select_value( void *ud, char *key, int atom_type, void *val ) assert( atom_type == VEVO_ATOM_TYPE_DOUBLE ); #endif int idx = (int) *( (double*) val ); - veejay_msg(0, "To menu item %d",idx); - strcpy( property.menu_item, property.menu.menu_items[idx] ); + veejay_msg(0, "To menu item %d, cur = '%s', new = '%s'", + idx, + property.menu_item, + property.menu.menu_items[idx] ); + + strcpy( property.menu_item, property.menu.menu_items[idx] ); unicap_set_property( vut->handle, &property ); - veejay_msg(0,"changed menu item %d to %s", n, property.menu_item ); + veejay_msg(0,"changed menu item %d to %s", idx, property.menu_item ); + unicap_unlock_properties( vut->handle ); + return 1; } if( property.type == UNICAP_PROPERTY_TYPE_RANGE ) @@ -235,10 +331,14 @@ int vj_unicap_select_value( void *ud, char *key, int atom_type, void *val ) property.value = (double) *((double*) val); unicap_set_property( vut->handle, &property ); veejay_msg(0, "Changed range value to %f", property.value ); + unicap_unlock_properties( vut->handle ); + return 1; } } } + unicap_unlock_properties( vut->handle ); + return 0; } @@ -248,29 +348,39 @@ int vj_unicap_get_range( void *ud, char *key, double *min , double *max ) unicap_property_t property_spec; int i; unicap_void_property( &property_spec ); + unicap_void_property( &property ); vj_unicap_t *vut = (vj_unicap_t*) ud; + unicap_lock_properties( vut->handle ); for( i = 0; SUCCESS( unicap_enumerate_properties( vut->handle, &property_spec, &property, i ) ); i ++ ) { + // memset( &property,0,sizeof(unicap_property_t)); unicap_get_property( vut->handle, &property); - if( strcmp( property.identifier, key ) == 0 ) - continue; + if( strcasecmp( property.identifier, key ) == 0 ) + { if( property.type == UNICAP_PROPERTY_TYPE_MENU ) { *min = 0.0; *max = (double) property.menu.menu_item_count; + unicap_unlock_properties( vut->handle ); + return 1; } if( property.type == UNICAP_PROPERTY_TYPE_RANGE ) { *min = property.range.min; *max = property.range.max; + unicap_unlock_properties( vut->handle ); + return 1; } + } } + unicap_unlock_properties( vut->handle ); + return 0; } @@ -281,6 +391,7 @@ char **vj_unicap_get_list( void *ud ) int i; unicap_void_property( &property_spec ); vj_unicap_t *vut = (vj_unicap_t*) ud; + unicap_lock_properties( vut->handle ); for( i = 0; SUCCESS( unicap_enumerate_properties( vut->handle, &property_spec, &property, i ) ); i ++ ) @@ -300,6 +411,9 @@ char **vj_unicap_get_list( void *ud ) res[i] = strdup( property.identifier ); } } + + unicap_unlock_properties( vut->handle ); + return res; } @@ -311,6 +425,7 @@ int vj_unicap_get_value( void *ud, char *key, int atom_type, void *value ) int i; unicap_void_property( &property_spec ); vj_unicap_t *vut = (vj_unicap_t*) ud; + unicap_lock_properties( vut->handle ); for( i = 0; SUCCESS( unicap_enumerate_properties( vut->handle, &property_spec, &property, i ) ); i ++ ) @@ -333,6 +448,8 @@ int vj_unicap_get_value( void *ud, char *key, int atom_type, void *value ) { double *dval = value; *dval = (double) j; + unicap_unlock_properties( vut->handle ); + return 1; } } @@ -344,9 +461,13 @@ int vj_unicap_get_value( void *ud, char *key, int atom_type, void *value ) #endif double *dval = value; *dval = property.value; + unicap_unlock_properties( vut->handle ); + return 1; } } + unicap_unlock_properties( vut->handle ); + return 0; } @@ -402,7 +523,8 @@ get_fourcc(char * fourcc) int vj_unicap_configure_device( void *ud, int pixel_format, int w, int h ) { vj_unicap_t *vut = (vj_unicap_t*) ud; - + unicap_lock_properties( vut->handle ); + unicap_void_format( &(vut->format_spec)); unsigned int fourcc = 0; @@ -455,6 +577,8 @@ int vj_unicap_configure_device( void *ud, int pixel_format, int w, int h ) { veejay_msg(0, "Unable to set video size %d x %d in format %s", w,h,vut->format.identifier ); + unicap_unlock_properties( vut->handle ); + return 0; } vut->deinterlace = 1; @@ -482,12 +606,16 @@ int vj_unicap_configure_device( void *ud, int pixel_format, int w, int h ) if(!vut->rgb) { veejay_msg(0, "No matching formats found. Camera not supported."); + unicap_unlock_properties( vut->handle ); + return 0; } else if( !SUCCESS( unicap_set_format( vut->handle, &rgb_format ) ) ) { veejay_msg(0, "Cannot set size %d x %d or format %s", w,h,rgb_format.identifier); + unicap_unlock_properties( vut->handle ); + return 0; } } @@ -514,6 +642,8 @@ int vj_unicap_configure_device( void *ud, int pixel_format, int w, int h ) if( !SUCCESS( unicap_set_format( vut->handle, &(vut->format) ) ) ) { veejay_msg(0, "Cannot set size %d x %d or format %s", w,h,vut->format.identifier); + unicap_unlock_properties( vut->handle ); + return 0; } veejay_msg(2, "Capture size set to %d x %d (%s)", w,h,vut->format.identifier); @@ -529,6 +659,8 @@ int vj_unicap_configure_device( void *ud, int pixel_format, int w, int h ) vut->buffer.data = vj_malloc( test.size.width * test.size.height * 4 ); vut->buffer.buffer_size = (sizeof(unsigned char) * 4 * test.size.width * test.size.height ); + unicap_unlock_properties( vut->handle ); + return 1; } @@ -550,28 +682,41 @@ int vj_unicap_grab_frame( void *vut, void *slot ) { VJFrame *f = (VJFrame*)slot; vj_unicap_t *v = (vj_unicap_t*) vut; + unicap_lock_properties( v->handle ); + if(!v->active) { if(!vj_unicap_start_capture( vut, slot )) + { + unicap_unlock_properties( v->handle ); + return 0; + } } if( !SUCCESS( unicap_queue_buffer( v->handle, &(v->buffer) ) ) ) { veejay_msg( 0, "Failed to queue a buffer on device: %s\n", v->device.identifier ); + unicap_unlock_properties( v->handle ); + return 0; } if( !SUCCESS( unicap_wait_buffer( v->handle, &(v->returned_buffer )) ) ) { veejay_msg(0,"Failed to wait for buffer on device: %s\n", v->device.identifier ); + unicap_unlock_properties( v->handle ); + return 0; } if( v->deinterlace ) { - yuv_deinterlace( f, v->buffer.data,v->buffer.data+v->sizes[0],v->buffer.data+v->sizes[0]+ - v->sizes[1] ); + yuv_deinterlace( f, + v->buffer.data, + v->buffer.data + v->sizes[0], + v->buffer.data +v->sizes[0] + v->sizes[1] + ); if( v->sampler ) chroma_supersample( SSM_422_444, v->sampler, f->data, f->width,f->height ); } @@ -591,7 +736,8 @@ int vj_unicap_grab_frame( void *vut, void *slot ) util_convertsrc( v->buffer.data, f->width,f->height,f->pixfmt, f->data ); } } - + unicap_unlock_properties( v->handle ); + return 1; } diff --git a/veejay-ng/vevosample/vj-unicap.h b/veejay-ng/vevosample/vj-unicap.h index 71929c1e..5af7f6c9 100644 --- a/veejay-ng/vevosample/vj-unicap.h +++ b/veejay-ng/vevosample/vj-unicap.h @@ -32,5 +32,7 @@ int vj_unicap_grab_frame( void *vut, void *slot ); int vj_unicap_stop_capture( void *vut ); void vj_unicap_free_device( void *vut ); +void *vj_unicap_get_devices(void *in); + #endif