]> git.sesse.net Git - mlt/blob - src/modules/jackrack/factory.c
Add service metadata for jackrack, ladspa, and ladspa.id.
[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 static mlt_properties metadata( mlt_service_type type, const char *id, void *data )
36 {
37         char file[ PATH_MAX ];
38         snprintf( file, PATH_MAX, "%s/jackrack/filter_%s.yml",
39                 mlt_environment( "MLT_DATA" ), strncmp( id, "ladspa.", 7 ) ? id : "ladspa" );
40         mlt_properties result = mlt_properties_parse_yaml( file );
41
42         if ( !strncmp( id, "ladspa.", 7 ) )
43         {
44                 // Annotate the yaml properties with ladspa control port info.
45                 plugin_mgr_t *mgr = plugin_mgr_new();
46                 plugin_desc_t *desc = plugin_mgr_get_any_desc( mgr, strtol( id + 7, NULL, 10 ) );
47
48                 if ( desc )
49                 {
50                         mlt_properties params = mlt_properties_new();
51                         mlt_properties p;
52                         char key[20];
53                         int i;
54
55                         mlt_properties_set( result, "identifier", id );
56                         mlt_properties_set( result, "title", desc->name );
57                         mlt_properties_set_data( result, "parameters", params, 0, (mlt_destructor) mlt_properties_close, NULL );
58                         for ( i = 0; i < desc->control_port_count; i++ )
59                         {
60                                 int j = desc->control_port_indicies[i];
61                                 LADSPA_Data sample_rate = 48000;
62                                 LADSPA_PortRangeHintDescriptor hint_descriptor = desc->port_range_hints[j].HintDescriptor;
63
64                                 p = mlt_properties_new();
65                                 snprintf( key, sizeof(key), "%d", i );
66                                 mlt_properties_set_data( params, key, p, 0, (mlt_destructor) mlt_properties_close, NULL );
67                                 snprintf( key, sizeof(key), "%d", j );
68                                 mlt_properties_set( p, "identifier", key );
69                                 mlt_properties_set( p, "title", desc->port_names[ j ] );
70                                 if ( LADSPA_IS_HINT_INTEGER( hint_descriptor ) )
71                                 {
72                                         mlt_properties_set( p, "type", "integer" );
73                                         mlt_properties_set_int( p, "default", plugin_desc_get_default_control_value( desc, j, sample_rate ) );
74                                 }
75                                 else if ( LADSPA_IS_HINT_TOGGLED( hint_descriptor ) )
76                                 {
77                                         mlt_properties_set( p, "type", "boolean" );
78                                         mlt_properties_set_int( p, "default", plugin_desc_get_default_control_value( desc, j, sample_rate ) );
79                                 }
80                                 else
81                                 {
82                                         mlt_properties_set( p, "type", "float" );
83                                         mlt_properties_set_double( p, "default", plugin_desc_get_default_control_value( desc, j, sample_rate ) );
84                                 }
85                                 /* set upper and lower, possibly adjusted to the sample rate */
86                                 if ( LADSPA_IS_HINT_BOUNDED_BELOW( hint_descriptor ) )
87                                 {
88                                         LADSPA_Data lower = desc->port_range_hints[j].LowerBound;
89                                         if ( LADSPA_IS_HINT_SAMPLE_RATE( hint_descriptor ) )
90                                                 lower *= sample_rate;
91                                         if ( LADSPA_IS_HINT_LOGARITHMIC( hint_descriptor ) )
92                                         {
93                                                 if (lower < FLT_EPSILON)
94                                                         lower = FLT_EPSILON;
95                                         }
96                                         mlt_properties_set_double( p, "minimum", lower );
97                                 }
98                                 if ( LADSPA_IS_HINT_BOUNDED_ABOVE( hint_descriptor ) )
99                                 {
100                                         LADSPA_Data upper = desc->port_range_hints[j].UpperBound;
101                                         if ( LADSPA_IS_HINT_SAMPLE_RATE( hint_descriptor ) )
102                                                 upper *= sample_rate;
103                                         mlt_properties_set_double( p, "maximum", upper );
104                                 }
105                                 if ( LADSPA_IS_HINT_LOGARITHMIC( hint_descriptor ) )
106                                         mlt_properties_set( p, "scale", "log" );
107                         }
108                         p = mlt_properties_new();
109                         snprintf( key, sizeof(key), "%d", i );
110                         mlt_properties_set_data( params, key, p, 0, (mlt_destructor) mlt_properties_close, NULL );
111                         mlt_properties_set( p, "identifier", "wetness" );
112                         mlt_properties_set( p, "title", "Wet/Dry" );
113                         mlt_properties_set( p, "type", "float" );
114                         mlt_properties_set_double( p, "default", 1 );
115                         mlt_properties_set_double( p, "minimum", 0 );
116                         mlt_properties_set_double( p, "maximum", 1 );
117                 }
118                 plugin_mgr_destroy( mgr );
119         }
120
121         return result;
122 }
123
124 MLT_REPOSITORY
125 {
126         plugin_mgr_t *mgr = plugin_mgr_new();
127         GSList *list;
128
129         for ( list = 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         plugin_mgr_destroy( mgr );
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 }