]> git.sesse.net Git - mlt/blob - mlt/src/inigo/inigo.c
inigo usage message
[mlt] / mlt / src / inigo / inigo.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #include <framework/mlt.h>
6
7 #include "io.h"
8
9 static void transport_action( mlt_producer producer, char *value )
10 {
11         mlt_properties properties = mlt_producer_properties( producer );
12         mlt_multitrack multitrack = mlt_properties_get_data( properties, "multitrack", NULL );
13
14         if ( strlen( value ) == 1 )
15         {
16                 switch( value[ 0 ] )
17                 {
18                         case 'q':
19                                 mlt_properties_set_int( properties, "done", 1 );
20                                 break;
21                         case '0':
22                                 mlt_producer_set_speed( producer, 1 );
23                                 mlt_producer_seek( producer, 0 );
24                                 break;
25                         case '1':
26                                 mlt_producer_set_speed( producer, -10 );
27                                 break;
28                         case '2':
29                                 mlt_producer_set_speed( producer, -5 );
30                                 break;
31                         case '3':
32                                 mlt_producer_set_speed( producer, -2 );
33                                 break;
34                         case '4':
35                                 mlt_producer_set_speed( producer, -1 );
36                                 break;
37                         case '5':
38                                 mlt_producer_set_speed( producer, 0 );
39                                 break;
40                         case '6':
41                         case ' ':
42                                 mlt_producer_set_speed( producer, 1 );
43                                 break;
44                         case '7':
45                                 mlt_producer_set_speed( producer, 2 );
46                                 break;
47                         case '8':
48                                 mlt_producer_set_speed( producer, 5 );
49                                 break;
50                         case '9':
51                                 mlt_producer_set_speed( producer, 10 );
52                                 break;
53                         case 'd':
54                                 if ( multitrack != NULL )
55                                 {
56                                         int i = 0;
57                                         mlt_position last = -1;
58                                         for ( i = 0; 1; i ++ )
59                                         {
60                                                 mlt_position time = mlt_multitrack_clip( multitrack, mlt_whence_relative_start, i );
61                                                 if ( time == last )
62                                                         break;
63                                                 last = time;
64                                                 fprintf( stderr, "%d: %lld\n", i, time );
65                                         }
66                                 }
67                                 break;
68
69                         case 'g':
70                                 if ( multitrack != NULL )
71                                 {
72                                         mlt_position time = mlt_multitrack_clip( multitrack, mlt_whence_relative_current, 0 );
73                                         mlt_producer_seek( producer, time );
74                                 }
75                                 break;
76                         case 'h':
77                                 if ( multitrack != NULL )
78                                 {
79                                         mlt_position position = mlt_producer_position( producer );
80                                         mlt_producer_set_speed( producer, 0 );
81                                         mlt_producer_seek( producer, position - 1 >= 0 ? position - 1 : 0 );
82                                 }
83                                 break;
84                         case 'j':
85                                 if ( multitrack != NULL )
86                                 {
87                                         mlt_position time = mlt_multitrack_clip( multitrack, mlt_whence_relative_current, 1 );
88                                         mlt_producer_seek( producer, time );
89                                 }
90                                 break;
91                         case 'k':
92                                 if ( multitrack != NULL )
93                                 {
94                                         mlt_position time = mlt_multitrack_clip( multitrack, mlt_whence_relative_current, -1 );
95                                         mlt_producer_seek( producer, time );
96                                 }
97                                 break;
98                         case 'l':
99                                 if ( multitrack != NULL )
100                                 {
101                                         mlt_position position = mlt_producer_position( producer );
102                                         mlt_producer_set_speed( producer, 0 );
103                                         mlt_producer_seek( producer, position + 1 );
104                                 }
105                                 break;
106                 }
107         }
108 }
109
110 static mlt_consumer create_consumer( char *id, mlt_producer producer )
111 {
112         char *arg = strchr( id, ':' );
113         if ( arg != NULL )
114                 *arg ++ = '\0';
115         mlt_consumer consumer = mlt_factory_consumer( id, arg );
116         if ( consumer != NULL )
117         {
118                 mlt_properties properties = mlt_consumer_properties( consumer );
119                 mlt_properties_set_data( properties, "transport_callback", transport_action, 0, NULL, NULL );
120                 mlt_properties_set_data( properties, "transport_producer", producer, 0, NULL, NULL );
121         }
122         return consumer;
123 }
124
125 static void transport( mlt_producer producer )
126 {
127         mlt_properties properties = mlt_producer_properties( producer );
128
129         term_init( );
130
131         fprintf( stderr, "+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+\n" );
132         fprintf( stderr, "|1=-10| |2= -5| |3= -2| |4= -1| |5=  0| |6=  1| |7=  2| |8=  5| |9= 10|\n" );
133         fprintf( stderr, "+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+\n" );
134
135         fprintf( stderr, "+---------------------------------------------------------------------+\n" );
136         fprintf( stderr, "|                      h = previous,  l = next                        |\n" );
137         fprintf( stderr, "|           g = start of clip, j = next clip, k = previous clip       |\n" );
138         fprintf( stderr, "|                0 = restart, q = quit, space = play                  |\n" );
139         fprintf( stderr, "+---------------------------------------------------------------------+\n" );
140
141         while( mlt_properties_get_int( properties, "done" ) == 0 )
142         {
143                 int value = term_read( );
144                 if ( value != -1 )
145                         transport_action( producer, ( char * )&value );
146         }
147 }
148
149 int main( int argc, char **argv )
150 {
151         int i;
152         mlt_consumer consumer = NULL;
153         mlt_producer inigo = NULL;
154         FILE *store = NULL;
155         char *name = NULL;
156
157         // Construct the factory
158         mlt_factory_init( getenv( "MLT_REPOSITORY" ) );
159
160         for ( i = 1; i < argc; i ++ )
161         {
162                 if ( !strcmp( argv[ i ], "-serialise" ) )
163                 {
164                         name = argv[ ++ i ];
165                         if ( strstr( name, ".inigo" ) )
166                                 store = fopen( name, "w" );
167                 }
168         }
169
170         // Get inigo producer
171         inigo = mlt_factory_producer( "inigo", &argv[ 1 ] );
172
173         if ( argc > 1 && inigo != NULL && mlt_producer_get_length( inigo ) > 0 )
174         {
175                 // Get inigo's properties
176                 mlt_properties inigo_props = mlt_producer_properties( inigo );
177
178                 // Get the field service from inigo
179                 mlt_field field = mlt_properties_get_data( inigo_props, "field", 0 );
180
181                 // Get the last group
182                 mlt_properties group = mlt_properties_get_data( inigo_props, "group", 0 );
183
184                 // Parse the arguments
185                 for ( i = 1; i < argc; i ++ )
186                 {
187                         if ( !strcmp( argv[ i ], "-consumer" ) )
188                         {
189                                 consumer = create_consumer( argv[ ++ i ], inigo );
190                                 while ( argv[ i + 1 ] != NULL && strstr( argv[ i + 1 ], "=" ) )
191                                         mlt_properties_parse( group, argv[ ++ i ] );
192                         }
193                         else if ( !strcmp( argv[ i ], "-serialise" ) )
194                         {
195                                 i ++;
196                         }
197                         else
198                         {
199                                 if ( store != NULL )
200                                         fprintf( store, "%s\n", argv[ i ] );
201
202                                 i ++;
203
204                                 while ( argv[ i ] != NULL && argv[ i ][ 0 ] != '-' )
205                                 {
206                                         if ( store != NULL )
207                                                 fprintf( store, "%s\n", argv[ i ] );
208                                         i += 1;
209                                 }
210
211                                 i --;
212                         }
213                 }
214
215                 // If we have no consumer, default to sdl
216                 if ( store == NULL && consumer == NULL )
217                         consumer = create_consumer( "sdl", inigo );
218
219                 if ( consumer != NULL && store == NULL )
220                 {
221                         // Apply group settings
222                         mlt_properties properties = mlt_consumer_properties( consumer );
223                         mlt_properties_inherit( properties, group );
224
225                         // Connect consumer to tractor
226                         mlt_consumer_connect( consumer, mlt_field_service( field ) );
227
228                         // Transport functionality
229                         transport( inigo );
230                 }
231                 else if ( store != NULL )
232                 {
233                         fprintf( stderr, "Project saved as %s.\n", name );
234                         fclose( store );
235                 }
236
237         }
238         else
239         {
240                 fprintf( stderr, "Usage: inigo [ -group [ name=value ]* ]\n"
241                                                  "             [ -consumer id[:arg] [ name=value ]* ]\n"
242                                          "             [ -filter id[:arg] [ name=value ] * ]\n"
243                                          "             [ -transition id[:arg] [ name=value ] * ]\n"
244                                                  "             [ -blank time ]\n"
245                                                  "             [ -track ]\n"
246                                          "             [ producer [ name=value ] * ]+\n" );
247         }
248
249         // Close the consumer
250         if ( consumer != NULL )
251                 mlt_consumer_close( consumer );
252
253         // Close the producer
254         if ( inigo != NULL )
255                 mlt_producer_close( inigo );
256
257         // Close the factory
258         mlt_factory_close( );
259
260         return 0;
261 }