2 * factory.c -- the factory method interfaces
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Dan Dennedy <dan@dennedy.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include <framework/mlt.h>
31 extern mlt_consumer consumer_jack_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg );
34 #include "plugin_mgr.h"
36 extern mlt_filter filter_jackrack_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg );
37 extern mlt_filter filter_ladspa_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg );
38 extern mlt_producer producer_ladspa_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg );
40 plugin_mgr_t *g_jackrack_plugin_mgr = NULL;
43 static mlt_properties metadata( mlt_service_type type, const char *id, char *data )
45 char file[ PATH_MAX ];
46 if( type == filter_type )
48 snprintf( file, PATH_MAX, "%s/jackrack/%s",
49 mlt_environment( "MLT_DATA" ), strncmp( id, "ladspa.", 7 ) ? data : "filter_ladspa.yml" );
53 snprintf( file, PATH_MAX, "%s/jackrack/%s",
54 mlt_environment( "MLT_DATA" ), strncmp( id, "ladspa.", 7 ) ? data : "producer_ladspa.yml" );
56 mlt_properties result = mlt_properties_parse_yaml( file );
59 if ( !strncmp( id, "ladspa.", 7 ) )
61 // Annotate the yaml properties with ladspa control port info.
62 plugin_desc_t *desc = plugin_mgr_get_any_desc( g_jackrack_plugin_mgr, strtol( id + 7, NULL, 10 ) );
66 mlt_properties params = mlt_properties_new();
71 mlt_properties_set( result, "identifier", id );
72 mlt_properties_set( result, "title", desc->name );
73 mlt_properties_set( result, "creator", desc->maker ? desc->maker : "unknown" );
74 mlt_properties_set( result, "description", "LADSPA plugin" );
75 mlt_properties_set_data( result, "parameters", params, 0, (mlt_destructor) mlt_properties_close, NULL );
76 for ( i = 0; i < desc->control_port_count; i++ )
78 int j = desc->control_port_indicies[i];
79 LADSPA_Data sample_rate = 48000;
80 LADSPA_PortRangeHintDescriptor hint_descriptor = desc->port_range_hints[j].HintDescriptor;
82 p = mlt_properties_new();
83 snprintf( key, sizeof(key), "%d", i );
84 mlt_properties_set_data( params, key, p, 0, (mlt_destructor) mlt_properties_close, NULL );
85 snprintf( key, sizeof(key), "%d", j );
86 mlt_properties_set( p, "identifier", key );
87 mlt_properties_set( p, "title", desc->port_names[ j ] );
88 if ( LADSPA_IS_HINT_INTEGER( hint_descriptor ) )
90 mlt_properties_set( p, "type", "integer" );
91 mlt_properties_set_int( p, "default", plugin_desc_get_default_control_value( desc, j, sample_rate ) );
93 else if ( LADSPA_IS_HINT_TOGGLED( hint_descriptor ) )
95 mlt_properties_set( p, "type", "boolean" );
96 mlt_properties_set_int( p, "default", plugin_desc_get_default_control_value( desc, j, sample_rate ) );
100 mlt_properties_set( p, "type", "float" );
101 mlt_properties_set_double( p, "default", plugin_desc_get_default_control_value( desc, j, sample_rate ) );
103 /* set upper and lower, possibly adjusted to the sample rate */
104 if ( LADSPA_IS_HINT_BOUNDED_BELOW( hint_descriptor ) )
106 LADSPA_Data lower = desc->port_range_hints[j].LowerBound;
107 if ( LADSPA_IS_HINT_SAMPLE_RATE( hint_descriptor ) )
108 lower *= sample_rate;
109 if ( LADSPA_IS_HINT_LOGARITHMIC( hint_descriptor ) )
111 if (lower < FLT_EPSILON)
114 mlt_properties_set_double( p, "minimum", lower );
116 if ( LADSPA_IS_HINT_BOUNDED_ABOVE( hint_descriptor ) )
118 LADSPA_Data upper = desc->port_range_hints[j].UpperBound;
119 if ( LADSPA_IS_HINT_SAMPLE_RATE( hint_descriptor ) )
120 upper *= sample_rate;
121 mlt_properties_set_double( p, "maximum", upper );
123 if ( LADSPA_IS_HINT_LOGARITHMIC( hint_descriptor ) )
124 mlt_properties_set( p, "scale", "log" );
127 if( type == filter_type )
129 p = mlt_properties_new();
130 snprintf( key, sizeof(key), "%d", i );
131 mlt_properties_set_data( params, key, p, 0, (mlt_destructor) mlt_properties_close, NULL );
132 mlt_properties_set( p, "identifier", "wetness" );
133 mlt_properties_set( p, "title", "Wet/Dry" );
134 mlt_properties_set( p, "type", "float" );
135 mlt_properties_set_double( p, "default", 1 );
136 mlt_properties_set_double( p, "minimum", 0 );
137 mlt_properties_set_double( p, "maximum", 1 );
150 g_jackrack_plugin_mgr = plugin_mgr_new();
152 for ( list = g_jackrack_plugin_mgr->all_plugins; list; list = g_slist_next( list ) )
154 plugin_desc_t *desc = (plugin_desc_t *) list->data;
155 char *s = malloc( strlen( "ladpsa." ) + 21 );
157 sprintf( s, "ladspa.%lu", desc->id );
159 if( desc->has_input )
161 MLT_REGISTER( filter_type, s, filter_ladspa_init );
162 MLT_REGISTER_METADATA( filter_type, s, metadata, NULL );
166 MLT_REGISTER( producer_type, s, producer_ladspa_init );
167 MLT_REGISTER_METADATA( producer_type, s, metadata, NULL );
172 mlt_factory_register_for_clean_up( g_jackrack_plugin_mgr, (mlt_destructor) plugin_mgr_destroy );
174 MLT_REGISTER( filter_type, "jackrack", filter_jackrack_init );
175 MLT_REGISTER_METADATA( filter_type, "jackrack", metadata, "filter_jackrack.yml" );
176 MLT_REGISTER( filter_type, "ladspa", filter_ladspa_init );
177 MLT_REGISTER_METADATA( filter_type, "ladspa", metadata, "filter_ladspa.yml" );
179 MLT_REGISTER( consumer_type, "jack", consumer_jack_init );
180 MLT_REGISTER_METADATA( consumer_type, "jack", metadata, "consumer_jack.yml" );