Merge ../mlt
[melted] / src / modules / core / transition_mix.c
index ce0d06f..b2b3790 100644 (file)
@@ -3,22 +3,22 @@
  * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
  * Author: Dan Dennedy <dan@dennedy.org>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
  *
- * This program is distributed in the hope that it will be useful,
+ * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include "transition_mix.h"
+#include <framework/mlt_transition.h>
 #include <framework/mlt_frame.h>
 
 #include <stdio.h>
@@ -33,21 +33,31 @@ static int transition_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_fo
        // Get the b frame from the stack
        mlt_frame b_frame = mlt_frame_pop_audio( frame );
 
+       // Get the effect
+       mlt_transition effect = mlt_frame_pop_audio( frame );
+
        // Get the properties of the b frame
        mlt_properties b_props = MLT_FRAME_PROPERTIES( b_frame );
 
-       double mix_start = 0.5, mix_end = 0.5;
-       if ( mlt_properties_get( b_props, "audio.previous_mix" ) != NULL )
-               mix_start = mlt_properties_get_double( b_props, "audio.previous_mix" );
-       if ( mlt_properties_get( b_props, "audio.mix" ) != NULL )
-               mix_end = mlt_properties_get_double( b_props, "audio.mix" );
-       if ( mlt_properties_get_int( b_props, "audio.reverse" ) )
+       if ( mlt_properties_get_int( MLT_TRANSITION_PROPERTIES( effect ), "combine" ) == 0 )
        {
-               mix_start = 1 - mix_start;
-               mix_end = 1 - mix_end;
-       }
+               double mix_start = 0.5, mix_end = 0.5;
+               if ( mlt_properties_get( b_props, "audio.previous_mix" ) != NULL )
+                       mix_start = mlt_properties_get_double( b_props, "audio.previous_mix" );
+               if ( mlt_properties_get( b_props, "audio.mix" ) != NULL )
+                       mix_end = mlt_properties_get_double( b_props, "audio.mix" );
+               if ( mlt_properties_get_int( b_props, "audio.reverse" ) )
+               {
+                       mix_start = 1 - mix_start;
+                       mix_end = 1 - mix_end;
+               }
 
-       mlt_frame_mix_audio( frame, b_frame, mix_start, mix_end, buffer, format, frequency, channels, samples );
+               mlt_frame_mix_audio( frame, b_frame, mix_start, mix_end, buffer, format, frequency, channels, samples );
+       }
+       else
+       {
+               mlt_frame_combine_audio( frame, b_frame, buffer, format, frequency, channels, samples );
+       }
 
        return 0;
 }
@@ -94,14 +104,17 @@ static mlt_frame transition_process( mlt_transition this, mlt_frame a_frame, mlt
                        mlt_properties_set_double( b_props, "audio.mix", mix );
        
                        // Initialise transition previous mix value to prevent an inadvertant jump from 0
-                       if ( mlt_properties_get( properties, "previous_mix" ) == NULL )
-                               mlt_properties_set_double( properties, "previous_mix", mlt_properties_get_double( b_props, "audio.mix" ) );
+                       mlt_position last_position = mlt_properties_get_position( properties, "_last_position" );
+                       mlt_position current_position = mlt_frame_get_position( b_frame );
+                       if ( mlt_properties_get( properties, "_previous_mix" ) == NULL
+                            || current_position != last_position + 1 )
+                               mlt_properties_set_double( properties, "_previous_mix", mix );
                                
                        // Tell b frame what the previous mix level was
-                       mlt_properties_set_double( b_props, "audio.previous_mix", mlt_properties_get_double( properties, "previous_mix" ) );
+                       mlt_properties_set_double( b_props, "audio.previous_mix", mlt_properties_get_double( properties, "_previous_mix" ) );
 
                        // Save the current mix level for the next iteration
-                       mlt_properties_set_double( properties, "previous_mix", mlt_properties_get_double( b_props, "audio.mix" ) );
+                       mlt_properties_set_double( properties, "_previous_mix", mlt_properties_get_double( b_props, "audio.mix" ) );
                
                        mlt_properties_set_double( b_props, "audio.reverse", mlt_properties_get_double( properties, "reverse" ) );
                }
@@ -130,6 +143,7 @@ static mlt_frame transition_process( mlt_transition this, mlt_frame a_frame, mlt
        }
 
        // Override the get_audio method
+       mlt_frame_push_audio( a_frame, this );
        mlt_frame_push_audio( a_frame, b_frame );
        mlt_frame_push_audio( a_frame, transition_get_audio );
        
@@ -139,7 +153,7 @@ static mlt_frame transition_process( mlt_transition this, mlt_frame a_frame, mlt
 /** Constructor for the transition.
 */
 
-mlt_transition transition_mix_init( char *arg )
+mlt_transition transition_mix_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
 {
        mlt_transition this = calloc( sizeof( struct mlt_transition_s ), 1 );
        if ( this != NULL && mlt_transition_init( this, NULL ) == 0 )