]> git.sesse.net Git - mlt/blob - src/modules/jackrack/factory.c
7ba3bf8585723efbae3557902e7eb3e7f4ccf539
[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
31 extern mlt_consumer consumer_jack_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg );
32
33 #ifdef GPL
34 #include "plugin_mgr.h"
35
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
39 plugin_mgr_t *g_jackrack_plugin_mgr = NULL;
40 #endif
41
42 static mlt_properties metadata( mlt_service_type type, const char *id, char *data )
43 {
44         char file[ PATH_MAX ];
45         snprintf( file, PATH_MAX, "%s/jackrack/%s",
46                           mlt_environment( "MLT_DATA" ), strncmp( id, "ladspa.", 7 ) ? data : "filter_ladspa.yml" );
47         mlt_properties result = mlt_properties_parse_yaml( file );
48
49 #ifdef GPL
50         if ( !strncmp( id, "ladspa.", 7 ) )
51         {
52                 // Annotate the yaml properties with ladspa control port info.
53                 plugin_desc_t *desc = plugin_mgr_get_any_desc( g_jackrack_plugin_mgr, strtol( id + 7, NULL, 10 ) );
54
55                 if ( desc )
56                 {
57                         mlt_properties params = mlt_properties_new();
58                         mlt_properties p;
59                         char key[20];
60                         int i;
61
62                         mlt_properties_set( result, "identifier", id );
63                         mlt_properties_set( result, "title", desc->name );
64                         mlt_properties_set( result, "creator", desc->maker ? desc->maker : "unknown" );
65                         mlt_properties_set( result, "description", "LADSPA plugin" );
66                         mlt_properties_set_data( result, "parameters", params, 0, (mlt_destructor) mlt_properties_close, NULL );
67                         for ( i = 0; i < desc->control_port_count; i++ )
68                         {
69                                 int j = desc->control_port_indicies[i];
70                                 LADSPA_Data sample_rate = 48000;
71                                 LADSPA_PortRangeHintDescriptor hint_descriptor = desc->port_range_hints[j].HintDescriptor;
72
73                                 p = mlt_properties_new();
74                                 snprintf( key, sizeof(key), "%d", i );
75                                 mlt_properties_set_data( params, key, p, 0, (mlt_destructor) mlt_properties_close, NULL );
76                                 snprintf( key, sizeof(key), "%d", j );
77                                 mlt_properties_set( p, "identifier", key );
78                                 mlt_properties_set( p, "title", desc->port_names[ j ] );
79                                 if ( LADSPA_IS_HINT_INTEGER( hint_descriptor ) )
80                                 {
81                                         mlt_properties_set( p, "type", "integer" );
82                                         mlt_properties_set_int( p, "default", plugin_desc_get_default_control_value( desc, j, sample_rate ) );
83                                 }
84                                 else if ( LADSPA_IS_HINT_TOGGLED( hint_descriptor ) )
85                                 {
86                                         mlt_properties_set( p, "type", "boolean" );
87                                         mlt_properties_set_int( p, "default", plugin_desc_get_default_control_value( desc, j, sample_rate ) );
88                                 }
89                                 else
90                                 {
91                                         mlt_properties_set( p, "type", "float" );
92                                         mlt_properties_set_double( p, "default", plugin_desc_get_default_control_value( desc, j, sample_rate ) );
93                                 }
94                                 /* set upper and lower, possibly adjusted to the sample rate */
95                                 if ( LADSPA_IS_HINT_BOUNDED_BELOW( hint_descriptor ) )
96                                 {
97                                         LADSPA_Data lower = desc->port_range_hints[j].LowerBound;
98                                         if ( LADSPA_IS_HINT_SAMPLE_RATE( hint_descriptor ) )
99                                                 lower *= sample_rate;
100                                         if ( LADSPA_IS_HINT_LOGARITHMIC( hint_descriptor ) )
101                                         {
102                                                 if (lower < FLT_EPSILON)
103                                                         lower = FLT_EPSILON;
104                                         }
105                                         mlt_properties_set_double( p, "minimum", lower );
106                                 }
107                                 if ( LADSPA_IS_HINT_BOUNDED_ABOVE( hint_descriptor ) )
108                                 {
109                                         LADSPA_Data upper = desc->port_range_hints[j].UpperBound;
110                                         if ( LADSPA_IS_HINT_SAMPLE_RATE( hint_descriptor ) )
111                                                 upper *= sample_rate;
112                                         mlt_properties_set_double( p, "maximum", upper );
113                                 }
114                                 if ( LADSPA_IS_HINT_LOGARITHMIC( hint_descriptor ) )
115                                         mlt_properties_set( p, "scale", "log" );
116                         }
117                         p = mlt_properties_new();
118                         snprintf( key, sizeof(key), "%d", i );
119                         mlt_properties_set_data( params, key, p, 0, (mlt_destructor) mlt_properties_close, NULL );
120                         mlt_properties_set( p, "identifier", "wetness" );
121                         mlt_properties_set( p, "title", "Wet/Dry" );
122                         mlt_properties_set( p, "type", "float" );
123                         mlt_properties_set_double( p, "default", 1 );
124                         mlt_properties_set_double( p, "minimum", 0 );
125                         mlt_properties_set_double( p, "maximum", 1 );
126                 }
127         }
128 #endif
129
130         return result;
131 }
132
133 MLT_REPOSITORY
134 {
135 #ifdef GPL
136         GSList *list;
137         g_jackrack_plugin_mgr = plugin_mgr_new();
138
139         for ( list = g_jackrack_plugin_mgr->all_plugins; list; list = g_slist_next( list ) )
140         {
141                 plugin_desc_t *desc = (plugin_desc_t *) list->data;
142                 char *s = malloc( strlen( "ladpsa." ) + 21 );
143
144                 sprintf( s, "ladspa.%lu", desc->id );
145                 MLT_REGISTER( filter_type, s, filter_ladspa_init );
146                 MLT_REGISTER_METADATA( filter_type, s, metadata, NULL );
147                 free( s );
148         }
149         mlt_factory_register_for_clean_up( g_jackrack_plugin_mgr, (mlt_destructor) plugin_mgr_destroy );
150
151         MLT_REGISTER( filter_type, "jackrack", filter_jackrack_init );
152         MLT_REGISTER_METADATA( filter_type, "jackrack", metadata, "filter_jackrack.yml" );
153         MLT_REGISTER( filter_type, "ladspa", filter_ladspa_init );
154         MLT_REGISTER_METADATA( filter_type, "ladspa", metadata, "filter_ladspa.yml" );
155 #endif
156         MLT_REGISTER( consumer_type, "jack", consumer_jack_init );
157         MLT_REGISTER_METADATA( consumer_type, "jack", metadata, "consumer_jack.yml" );
158 }