]> git.sesse.net Git - mlt/blob - src/modules/jackrack/factory.c
c1086f1a7036665495a480fc1436ea4ea1f0fcca
[mlt] / src / modules / jackrack / factory.c
1 /*
2  * factory.c -- the factory method interfaces
3  * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4  * Author: Dan Dennedy <dan@dennedy.org>
5  *
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.
10  *
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.
15  *
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.
19  */
20
21 #include <framework/mlt.h>
22 #include <ladspa.h>
23
24 #include <string.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <limits.h>
28 #include <float.h>
29
30 #include "plugin_mgr.h"
31
32 extern mlt_filter filter_jackrack_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg );
33 extern mlt_filter filter_ladspa_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg );
34
35 plugin_mgr_t *g_jackrack_plugin_mgr = NULL;
36
37 static mlt_properties metadata( mlt_service_type type, const char *id, void *data )
38 {
39         char file[ PATH_MAX ];
40         snprintf( file, PATH_MAX, "%s/jackrack/filter_%s.yml",
41                 mlt_environment( "MLT_DATA" ), strncmp( id, "ladspa.", 7 ) ? id : "ladspa" );
42         mlt_properties result = mlt_properties_parse_yaml( file );
43
44         if ( !strncmp( id, "ladspa.", 7 ) )
45         {
46                 // Annotate the yaml properties with ladspa control port info.
47                 plugin_desc_t *desc = plugin_mgr_get_any_desc( g_jackrack_plugin_mgr, strtol( id + 7, NULL, 10 ) );
48
49                 if ( desc )
50                 {
51                         mlt_properties params = mlt_properties_new();
52                         mlt_properties p;
53                         char key[20];
54                         int i;
55
56                         mlt_properties_set( result, "identifier", id );
57                         mlt_properties_set( result, "title", desc->name );
58                         mlt_properties_set_data( result, "parameters", params, 0, (mlt_destructor) mlt_properties_close, NULL );
59                         for ( i = 0; i < desc->control_port_count; i++ )
60                         {
61                                 int j = desc->control_port_indicies[i];
62                                 LADSPA_Data sample_rate = 48000;
63                                 LADSPA_PortRangeHintDescriptor hint_descriptor = desc->port_range_hints[j].HintDescriptor;
64
65                                 p = mlt_properties_new();
66                                 snprintf( key, sizeof(key), "%d", i );
67                                 mlt_properties_set_data( params, key, p, 0, (mlt_destructor) mlt_properties_close, NULL );
68                                 snprintf( key, sizeof(key), "%d", j );
69                                 mlt_properties_set( p, "identifier", key );
70                                 mlt_properties_set( p, "title", desc->port_names[ j ] );
71                                 if ( LADSPA_IS_HINT_INTEGER( hint_descriptor ) )
72                                 {
73                                         mlt_properties_set( p, "type", "integer" );
74                                         mlt_properties_set_int( p, "default", plugin_desc_get_default_control_value( desc, j, sample_rate ) );
75                                 }
76                                 else if ( LADSPA_IS_HINT_TOGGLED( hint_descriptor ) )
77                                 {
78                                         mlt_properties_set( p, "type", "boolean" );
79                                         mlt_properties_set_int( p, "default", plugin_desc_get_default_control_value( desc, j, sample_rate ) );
80                                 }
81                                 else
82                                 {
83                                         mlt_properties_set( p, "type", "float" );
84                                         mlt_properties_set_double( p, "default", plugin_desc_get_default_control_value( desc, j, sample_rate ) );
85                                 }
86                                 /* set upper and lower, possibly adjusted to the sample rate */
87                                 if ( LADSPA_IS_HINT_BOUNDED_BELOW( hint_descriptor ) )
88                                 {
89                                         LADSPA_Data lower = desc->port_range_hints[j].LowerBound;
90                                         if ( LADSPA_IS_HINT_SAMPLE_RATE( hint_descriptor ) )
91                                                 lower *= sample_rate;
92                                         if ( LADSPA_IS_HINT_LOGARITHMIC( hint_descriptor ) )
93                                         {
94                                                 if (lower < FLT_EPSILON)
95                                                         lower = FLT_EPSILON;
96                                         }
97                                         mlt_properties_set_double( p, "minimum", lower );
98                                 }
99                                 if ( LADSPA_IS_HINT_BOUNDED_ABOVE( hint_descriptor ) )
100                                 {
101                                         LADSPA_Data upper = desc->port_range_hints[j].UpperBound;
102                                         if ( LADSPA_IS_HINT_SAMPLE_RATE( hint_descriptor ) )
103                                                 upper *= sample_rate;
104                                         mlt_properties_set_double( p, "maximum", upper );
105                                 }
106                                 if ( LADSPA_IS_HINT_LOGARITHMIC( hint_descriptor ) )
107                                         mlt_properties_set( p, "scale", "log" );
108                         }
109                         p = mlt_properties_new();
110                         snprintf( key, sizeof(key), "%d", i );
111                         mlt_properties_set_data( params, key, p, 0, (mlt_destructor) mlt_properties_close, NULL );
112                         mlt_properties_set( p, "identifier", "wetness" );
113                         mlt_properties_set( p, "title", "Wet/Dry" );
114                         mlt_properties_set( p, "type", "float" );
115                         mlt_properties_set_double( p, "default", 1 );
116                         mlt_properties_set_double( p, "minimum", 0 );
117                         mlt_properties_set_double( p, "maximum", 1 );
118                 }
119         }
120
121         return result;
122 }
123
124 MLT_REPOSITORY
125 {
126         GSList *list;
127         g_jackrack_plugin_mgr = plugin_mgr_new();
128
129         for ( list = g_jackrack_plugin_mgr->all_plugins; list; list = g_slist_next( list ) )
130         {
131                 plugin_desc_t *desc = (plugin_desc_t *) list->data;
132                 char *s = malloc( strlen( "ladpsa." ) + 21 );
133
134                 sprintf( s, "ladspa.%lu", desc->id );
135                 MLT_REGISTER( filter_type, s, filter_ladspa_init );
136                 MLT_REGISTER_METADATA( filter_type, s, metadata, NULL );
137         }
138 //      mlt_factory_register_for_clean_up( g_jackrack_plugin_mgr, (mlt_destructor) plugin_mgr_destroy );
139
140         MLT_REGISTER( filter_type, "jackrack", filter_jackrack_init );
141         MLT_REGISTER_METADATA( filter_type, "jackrack", metadata, NULL );
142         MLT_REGISTER( filter_type, "ladspa", filter_ladspa_init );
143         MLT_REGISTER_METADATA( filter_type, "ladspa", metadata, NULL );
144 }