rework proxy for 1:1 and new layout, fix proxy for resized assets, change track gang_...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / track.C
index bac9abd68050bed5c1f8908fa9e92e239f8e4b7d..5c07480e249799bbc242512d11764591a357cc6e 100644 (file)
@@ -33,6 +33,7 @@
 #include "keyframe.h"
 #include "labels.h"
 #include "localsession.h"
+#include "maskauto.h"
 #include "module.h"
 #include "patch.h"
 #include "patchbay.h"
@@ -56,17 +57,20 @@ Track::Track(EDL *edl, Tracks *tracks) : ListItem<Track>()
        this->edl = edl;
        this->tracks = tracks;
        y_pixel = 0;
+       data_h = 64;
        expand_view = 0;
        draw = 1;
-       gang = 1;
+       ganged = 1;
+       master = 0;
        title[0] = 0;
-       record = 1;
+       armed = 1;
        play = 1;
        nudge = 0;
        track_w = edl->session->output_w;
        track_h = edl->session->output_h;
        id = EDL::next_id();
        mixer_id = -1;
+       masks = (1<<SUBMASKS)-1;
 }
 
 Track::~Track()
@@ -85,13 +89,16 @@ int Track::copy_settings(Track *track)
 {
        this->expand_view = track->expand_view;
        this->draw = track->draw;
-       this->gang = track->gang;
-       this->record = track->record;
+       this->ganged = track->ganged;
+       this->master = track->master;
+       this->armed = track->armed;
        this->nudge = track->nudge;
        this->mixer_id = track->mixer_id;
        this->play = track->play;
+       this->data_h = track->data_h;
        this->track_w = track->track_w;
        this->track_h = track->track_h;
+       this->masks = track->masks;
        strcpy(this->title, track->title);
        return 0;
 }
@@ -163,43 +170,26 @@ void Track::equivalent_output(Track *track, double *result)
 }
 
 
-int Track::is_synthesis(int64_t position,
-       int direction)
+int Track::is_synthesis(int64_t position, int direction, int depth)
 {
-       int is_synthesis = 0;
-       for(int i = 0; i < plugin_set.total; i++)
-       {
-               Plugin *plugin = get_current_plugin(position,
-                       i,
-                       direction,
-                       0,
-                       0);
-               if(plugin)
-               {
+       int result = 0;
+       for( int i = 0; !result && i<plugin_set.total; ++i ) {
+               Plugin *plugin = get_current_plugin(position, i, direction, 0, 0);
+               if( !plugin ) continue;
 // Assume data from a shared track is synthesized
-                       if(plugin->plugin_type == PLUGIN_SHAREDMODULE)
-                               is_synthesis = 1;
-                       else
-                               is_synthesis = plugin->is_synthesis(position,
-                                       direction);
-
-//printf("Track::is_synthesis %d %d\n", __LINE__, is_synthesis);
-                       if(is_synthesis) break;
-               }
+               result = plugin->plugin_type == PLUGIN_SHAREDMODULE ? 1 :
+                       plugin->is_synthesis(position, direction, depth);
        }
-       return is_synthesis;
+       return result;
 }
 
 void Track::copy_from(Track *track)
 {
        copy_settings(track);
        edits->copy_from(track->edits);
-       for(int i = 0; i < this->plugin_set.total; i++)
-               delete this->plugin_set.values[i];
        this->plugin_set.remove_all_objects();
 
-       for(int i = 0; i < track->plugin_set.total; i++)
-       {
+       for( int i=0; i<track->plugin_set.total; ++i ) {
                PluginSet *new_plugin_set = plugin_set.append(new PluginSet(edl, this));
                new_plugin_set->copy_from(track->plugin_set.values[i]);
        }
@@ -221,7 +211,7 @@ int Track::vertical_span(Theme *theme)
        if( show_titles() )
                result += theme->get_image("title_bg_data")->get_h();
        if( show_assets() )
-               result += edl->local_session->zoom_track;
+               result += data_h;
        if( expand_view )
                result += plugin_set.total * theme->get_image("plugin_bg_data")->get_h();
        result = MAX(result, theme->title_h);
@@ -260,27 +250,28 @@ double Track::get_length()
 int Track::has_speed()
 {
        FloatAutos *autos = (FloatAutos*)automation->autos[AUTOMATION_SPEED];
-       if(autos)
-       {
-               if(autos->first)
-               {
-                       for(FloatAuto *current = (FloatAuto*)autos->first;
-                               current;
-                               current = (FloatAuto*)current->next)
-                       {
-                               if(!EQUIV(current->get_value(), 1.0) ||
-                                       !EQUIV(current->get_control_in_value(), 0.0) ||
-                                       !EQUIV(current->get_control_out_value(), 0.0))
-                               {
-                                       return 1;
-                               }
-                       }
+       if( autos ) {
+               FloatAuto *current = (FloatAuto*)autos->first;
+               for( ; current; current=(FloatAuto*)current->next ) {
+                       if( !EQUIV(current->get_value(0), 1.0) ||
+                           !EQUIV(current->get_control_in_value(), 0.0) ||
+                           !EQUIV(current->get_control_out_value(), 0.0))
+                               return 1;
+                       if( current->curve_mode == FloatAuto::BUMP &&
+                           !EQUIV(current->get_value(1), 1.0) )
+                               return 1;
                }
        }
-
        return 0;
 }
 
+int64_t Track::speed_length(int64_t start, int64_t end)
+{
+       if( !has_speed() ) return end - start;
+       FloatAutos *speeds = (FloatAutos *) automation->autos[AUTOMATION_SPEED];
+       return speeds->automation_integral(start, end-start, PLAY_FORWARD);
+}
+
 int Track::show_assets()
 {
        return expand_view || edl->session->show_assets ? 1 : 0;
@@ -328,15 +319,18 @@ int Track::load(FileXML *file, int track_offset, uint32_t load_flags)
        int current_plugin = 0;
 
 
-       record = file->tag.get_property("RECORD", record);
+       armed = file->tag.get_property("RECORD", armed);
        play = file->tag.get_property("PLAY", play);
-       gang = file->tag.get_property("GANG", gang);
+       ganged = file->tag.get_property("GANG", ganged);
+       master = file->tag.get_property("MASTER", 1);
        draw = file->tag.get_property("DRAW", draw);
        nudge = file->tag.get_property("NUDGE", nudge);
        mixer_id = file->tag.get_property("MIXER_ID", mixer_id);
        expand_view = file->tag.get_property("EXPAND", expand_view);
+       data_h = file->tag.get_property("DATA_H", data_h);
        track_w = file->tag.get_property("TRACK_W", track_w);
        track_h = file->tag.get_property("TRACK_H", track_h);
+       masks = file->tag.get_property("MASKS", masks);
 
        load_header(file, load_flags);
 
@@ -474,109 +468,30 @@ void Track::insert_plugin_set(Track *track,
        int edit_autos)
 {
 // Extend plugins if no incoming plugins
-       if(!track->plugin_set.total)
-       {
-               shift_effects(position,
-                       min_length,
-                       edit_autos);
-       }
-       else
-       for(int i = 0; i < track->plugin_set.total; i++)
-       {
-               if(i >= plugin_set.total)
-                       plugin_set.append(new PluginSet(edl, this));
+       if( track->plugin_set.total ) {
+               for(int i = 0; i < track->plugin_set.total; i++) {
+                       if(i >= plugin_set.total)
+                               plugin_set.append(new PluginSet(edl, this));
 
-               plugin_set.values[i]->insert_edits(track->plugin_set.values[i],
-                       position,
-                       min_length,
-                       edit_autos);
+                       plugin_set.values[i]->insert_edits(track->plugin_set.values[i],
+                                       position, min_length, edit_autos);
+               }
        }
+       else
+               shift_effects(position, min_length, edit_autos, 0);
 }
 
-
-Plugin* Track::insert_effect(const char *title,
-               SharedLocation *shared_location,
-               KeyFrame *default_keyframe,
-               PluginSet *plugin_set,
-               double start,
-               double length,
-               int plugin_type)
+Plugin* Track::insert_effect(const char *title, SharedLocation *shared_location,
+               KeyFrame *default_keyframe, PluginSet *plugin_set,
+               double start, double length, int plugin_type)
 {
-       if(!plugin_set)
-       {
+       if( !plugin_set ) {
                plugin_set = new PluginSet(edl, this);
                this->plugin_set.append(plugin_set);
        }
-
-       Plugin *plugin = 0;
-
-// Position is identical to source plugin
-       if(plugin_type == PLUGIN_SHAREDPLUGIN)
-       {
-               Track *source_track = tracks->get_item_number(shared_location->module);
-               if(source_track)
-               {
-                       Plugin *source_plugin = source_track->get_current_plugin(
-                               edl->local_session->get_selectionstart(),
-                               shared_location->plugin,
-                               PLAY_FORWARD,
-                               1,
-                               0);
-
-// From an attach operation
-                       if(source_plugin)
-                       {
-                               plugin = plugin_set->insert_plugin(title,
-                                       source_plugin->startproject,
-                                       source_plugin->length,
-                                       plugin_type,
-                                       shared_location,
-                                       default_keyframe,
-                                       1);
-                       }
-                       else
-// From a drag operation
-                       {
-                               plugin = plugin_set->insert_plugin(title,
-                                       to_units(start, 0),
-                                       to_units(length, 1),
-                                       plugin_type,
-                                       shared_location,
-                                       default_keyframe,
-                                       1);
-                       }
-               }
-       }
-       else
-       {
-// This should be done in the caller
-               if(EQUIV(length, 0))
-               {
-                       if(edl->local_session->get_selectionend() >
-                               edl->local_session->get_selectionstart())
-                       {
-                               start = edl->local_session->get_selectionstart();
-                               length = edl->local_session->get_selectionend() - start;
-                       }
-                       else
-                       {
-                               start = 0;
-                               length = get_length();
-                       }
-               }
-//printf("Track::insert_effect %f %f %d %d\n", start, length, to_units(start, 0),
-//                     to_units(length, 0));
-
-               plugin = plugin_set->insert_plugin(title,
-                       to_units(start, 0),
-                       to_units(length, 1),
-                       plugin_type,
-                       shared_location,
-                       default_keyframe,
-                       1);
-       }
-//printf("Track::insert_effect 2 %f %f\n", start, length);
-
+       Plugin *plugin = plugin_set->insert_plugin(title,
+                       to_units(start, 0), to_units(length, 1), plugin_type,
+                       shared_location, default_keyframe, 1);
        expand_view = 1;
        return plugin;
 }
@@ -654,8 +569,7 @@ void Track::remove_pluginset(PluginSet *plugin_set)
                if(plugin_set == this->plugin_set.values[i]) break;
 
        this->plugin_set.remove_object(plugin_set);
-       for(i++ ; i < this->plugin_set.total; i++)
-       {
+       for( ++i ; i<=this->plugin_set.total; ++i ) {
                SharedLocation old_location, new_location;
                new_location.module = old_location.module = tracks->number_of(this);
                old_location.plugin = i;
@@ -670,37 +584,65 @@ void Track::shift_keyframes(int64_t position, int64_t length)
 // Effect keyframes are shifted in shift_effects
 }
 
-void Track::shift_effects(int64_t position, int64_t length, int edit_autos)
+void Track::shift_effects(int64_t position, int64_t length, int edit_autos, Edits *trim_edits)
 {
-       for(int i = 0; i < plugin_set.total; i++)
-       {
-               plugin_set.values[i]->shift_effects(position, length, edit_autos);
+       for( int i=0; i<plugin_set.total; ++i ) {
+               if( !trim_edits || trim_edits == (Edits*)plugin_set.values[i] )
+                       plugin_set.values[i]->shift_effects(position, length, edit_autos);
        }
 }
 
 void Track::detach_effect(Plugin *plugin)
 {
 //printf("Track::detach_effect 1\n");
-       for(int i = 0; i < plugin_set.total; i++)
-       {
-               PluginSet *plugin_set = this->plugin_set.values[i];
-               for(Plugin *dest = (Plugin*)plugin_set->first;
-                       dest;
-                       dest = (Plugin*)dest->next)
-               {
-                       if(dest == plugin)
-                       {
-                               int64_t start = plugin->startproject;
-                               int64_t end = plugin->startproject + plugin->length;
-
-                               plugin_set->clear(start, end, 1);
-                               optimize();
+       for( int i=0; i<plugin_set.size(); ++i ) {
+               PluginSet *pluginset = plugin_set[i];
+               Plugin *dest = (Plugin*)pluginset->first;
+               while( dest && dest != plugin ) dest = (Plugin*)dest->next;
+               if( !dest ) continue;
+               tracks->detach_ganged_effects(plugin);
+               int64_t start = plugin->startproject;
+               int64_t end = start + plugin->length;
+               pluginset->clear(start, end, 1);
+               optimize();
 //printf("Track::detach_effect 2 %d\n", plugin_set->length());
 // Delete 0 length pluginsets
-                               return;
-                       }
+               return;
+       }
+}
+
+void Track::detach_shared_effects(int module)
+{
+       for( int i=0; i<plugin_set.size(); ++i ) {
+               PluginSet *pluginset = this->plugin_set[i];
+               Plugin *dest = (Plugin*)pluginset->first;
+               for( ; dest; dest=(Plugin*)dest->next ) {
+                       if( (dest->plugin_type != PLUGIN_SHAREDPLUGIN &&
+                            dest->plugin_type != PLUGIN_SHAREDMODULE) ) continue;
+                       if( dest->shared_location.module != module ) continue;
+                       int64_t start = dest->startproject;
+                       int64_t end = start + dest->length;
+                       pluginset->clear(start, end, 1);
                }
        }
+       optimize();
+}
+
+void Track::detach_ganged_effects(Plugin *plugin)
+{
+       for( int i=0; i<plugin_set.size(); ++i ) {
+               PluginSet *pluginset = this->plugin_set[i];
+               Plugin *dest = (Plugin*)pluginset->first;
+               for( ; dest; dest=(Plugin*)dest->next ) {
+                       if( strcmp(dest->title, plugin->title) != 0 ) continue;
+                       if( dest->startproject != plugin->startproject ) continue;
+                       if( dest->length != plugin->length ) continue;
+                       int64_t start = dest->startproject;
+                       int64_t end = start + dest->length;
+                       pluginset->clear(start, end, 1);
+               }
+       }
+       optimize();
 }
 
 void Track::resample(double old_rate, double new_rate)
@@ -712,25 +654,6 @@ void Track::resample(double old_rate, double new_rate)
        nudge = (int64_t)(nudge * new_rate / old_rate);
 }
 
-void Track::detach_shared_effects(int module)
-{
-       for(int i = 0; i < plugin_set.size(); i++) {
-               PluginSet *plugin_set = this->plugin_set.get(i);
-               for(Plugin *dest = (Plugin*)plugin_set->first; dest; ) {
-                       if( (dest->plugin_type == PLUGIN_SHAREDPLUGIN ||
-                               dest->plugin_type == PLUGIN_SHAREDMODULE) &&
-                               dest->shared_location.module == module ) {
-                               int64_t start = dest->startproject;
-                               int64_t end = dest->startproject + dest->length;
-                               plugin_set->clear(start, end, 1);
-                       }
-
-                       if(dest) dest = (Plugin*)dest->next;
-               }
-       }
-       optimize();
-}
-
 
 void Track::optimize()
 {
@@ -859,52 +782,23 @@ void Track::synchronize_params(Track *track)
 }
 
 
-
-
-
 int Track::dump(FILE *fp)
 {
-       fprintf(fp,"   Data type %d\n", data_type);
        fprintf(fp,"   Title %s\n", title);
+       fprintf(fp,"   Data type %d, draw %d, gang %d, master %d, mixer_id %d\n"
+                  "      play %d, armed %d, nudge %jd, masks 0x%04x\n",
+               data_type, draw, ganged, master, mixer_id, play, armed, nudge, masks);
        fprintf(fp,"   Edits:\n");
        for(Edit* current = edits->first; current; current = NEXT)
-       {
                current->dump(fp);
-       }
        automation->dump(fp);
        fprintf(fp,"   Plugin Sets: %d\n", plugin_set.total);
 
-       for(int i = 0; i < plugin_set.total; i++)
-               plugin_set.values[i]->dump(fp);
-//printf("Track::dump 2\n");
+       for( int i=0; i<plugin_set.total; ++i )
+               plugin_set[i]->dump(fp);
        return 0;
 }
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-Track::Track() : ListItem<Track>()
-{
-       y_pixel = 0;
-}
-
 // ======================================== accounting
 
 int Track::number_of()
@@ -914,16 +808,6 @@ int Track::number_of()
 
 
 
-
-
-
-
-
-
-
-
-
-
 // ================================================= editing
 
 int Track::select_auto(AutoConf *auto_conf, int cursor_x, int cursor_y)
@@ -982,56 +866,35 @@ int Track::copy_automation(double selectionstart,
        return 0;
 }
 
-int Track::paste_automation(double selectionstart,
-       double total_length,
-       double frame_rate,
-       int64_t sample_rate,
-       FileXML *file,
-       int default_only,
-       int active_only)
+int Track::paste_automation(FileXML *file,
+       double selectionstart, double src_length, double src_rate,
+       int default_only, int active_only)
 {
 // Only used for pasting automation alone.
-       int64_t start;
-       int64_t length;
-       int result;
-       double scale;
-       int current_pluginset;
-
-       if(data_type == TRACK_AUDIO)
-               scale = edl->session->sample_rate / sample_rate;
-       else
-               scale = edl->session->frame_rate / frame_rate;
-
-       total_length *= scale;
-       start = to_units(selectionstart, 0);
-       length = to_units(total_length, 1);
-       result = 0;
-       current_pluginset = 0;
+       double dst_rate = data_type == TRACK_AUDIO ?
+               edl->session->sample_rate : edl->session->frame_rate;
+       double scale = dst_rate / src_rate;
+       int64_t start = to_units(selectionstart, 1);
+       int64_t length = to_units(selectionstart + src_length, 1) - start;
+       int result = 0;
+       int current_pluginset = 0;
 //printf("Track::paste_automation 1\n");
 
-       while(!result)
-       {
-               result = file->read_tag();
-
-               if(!result)
-               {
-                       if(file->tag.title_is("/TRACK"))
-                               result = 1;
-                       else
-                       if(automation->paste(start, length, scale, file,
-                                       default_only, active_only, 0)) {}
-                       else if(file->tag.title_is("PLUGINSET")) {
-                               if(current_pluginset < plugin_set.total) {
-                                       plugin_set.values[current_pluginset]->
-                                               paste_keyframes(start, length, file,
+       while( !(result = file->read_tag()) ) {
+               if( file->tag.title_is("/TRACK") ) break;
+               if( automation->paste(start, length, scale, file,
+                               default_only, active_only, 0) )
+                       continue;
+               if( file->tag.title_is("PLUGINSET") ) {
+                       if( current_pluginset < plugin_set.total ) {
+                               plugin_set.values[current_pluginset]->
+                                       paste_keyframes(start, length, file,
                                                default_only, active_only);
-                                       current_pluginset++;
-                               }
+                               ++current_pluginset;
                        }
                }
        }
 
-
        return 0;
 }
 
@@ -1068,10 +931,8 @@ void Track::set_automation_mode(double selectionstart,
 
 
 
-int Track::copy(double start,
-       double end,
-       FileXML *file,
-       const char *output_path)
+int Track::copy(int copy_flags, double start, double end,
+               FileXML *file, const char *output_path)
 {
 // Use a copy of the selection in converted units
 // So copy_automation doesn't reconvert.
@@ -1082,15 +943,18 @@ int Track::copy(double start,
 
 
        file->tag.set_title("TRACK");
-       file->tag.set_property("RECORD", record);
+       file->tag.set_property("RECORD", armed);
        file->tag.set_property("NUDGE", nudge);
        file->tag.set_property("MIXER_ID", mixer_id);
        file->tag.set_property("PLAY", play);
-       file->tag.set_property("GANG", gang);
+       file->tag.set_property("GANG", ganged);
+       file->tag.set_property("MASTER", master);
        file->tag.set_property("DRAW", draw);
        file->tag.set_property("EXPAND", expand_view);
+       file->tag.set_property("DATA_H", data_h);
        file->tag.set_property("TRACK_W", track_w);
        file->tag.set_property("TRACK_H", track_h);
+       file->tag.set_property("MASKS", masks);
        save_header(file);
        file->append_tag();
        file->append_newline();
@@ -1111,16 +975,18 @@ int Track::copy(double start,
 //     file->append_tag();
 //     file->append_newline();
 
-       edits->copy(start_unit, end_unit, file, output_path);
-
-       AutoConf auto_conf;
-       auto_conf.set_all(1);
-       automation->copy(start_unit, end_unit, file, 0, 0);
+       if( (copy_flags & COPY_EDITS) )
+               edits->copy(start_unit, end_unit, file, output_path);
 
+       if( (copy_flags & COPY_AUTOS) ) {
+               AutoConf auto_conf;
+               auto_conf.set_all(1);
+               automation->copy(start_unit, end_unit, file, 0, 0);
+       }
 
-       for(int i = 0; i < plugin_set.total; i++)
-       {
-               plugin_set.values[i]->copy(start_unit, end_unit, file);
+       if( (copy_flags & COPY_PLUGINS) ) {
+               for( int i=0; i<plugin_set.total; ++i )
+                       plugin_set.values[i]->copy(start_unit, end_unit, file);
        }
 
        copy_derived(start_unit, end_unit, file);
@@ -1170,7 +1036,7 @@ int Track::blade(double position)
 {
        int64_t start = to_units(position, 0);
        Edit *edit = edits->split_edit(start);
-       if( !edit ) return 1;
+       if( !edit || edit->silence() ) return 1;
        edit->hard_left = 1;
        if( edit->previous ) edit->previous->hard_right = 1;
        return 0;
@@ -1178,32 +1044,28 @@ int Track::blade(double position)
 
 int Track::clear(double start, double end,
        int edit_edits, int edit_labels, int edit_plugins,
-       int edit_autos, int convert_units, Edits *trim_edits)
+       int edit_autos, Edits *trim_edits)
 {
-// Edits::move_auto calls this routine after the units are converted to the track
-// format.
-//printf("Track::clear 1 %d %d %d\n", edit_edits, edit_labels, edit_plugins);
-       if(convert_units)
-       {
-               start = to_units(start, 0);
-               end = to_units(end, 1);
-       }
-
-
-       if(edit_autos)
-               automation->clear((int64_t)start, (int64_t)end, 0, 1);
+       return clear(to_units(start, 0), to_units(end, 1),
+               edit_edits, edit_labels, edit_plugins, edit_autos, trim_edits);
+}
 
-       if(edit_plugins)
-       {
-               for(int i = 0; i < plugin_set.total; i++)
-               {
+int Track::clear(int64_t start, int64_t end,
+       int edit_edits, int edit_labels, int edit_plugins,
+       int edit_autos, Edits *trim_edits)
+{
+       if( edit_edits )
+               edits->clear(start, end);
+//printf("Track::clear 1 %d %d %d\n", edit_edits, edit_labels, edit_plugins);
+       if( edit_autos )
+               automation->clear(start, end, 0, 1);
+       if( edit_plugins ) {
+               int edit_keyframes = edit_plugins < 0 ? 1 : edit_autos;
+               for(int i = 0; i < plugin_set.total; i++) {
                        if(!trim_edits || trim_edits == (Edits*)plugin_set.values[i])
-                               plugin_set.values[i]->clear((int64_t)start, (int64_t)end, edit_autos);
+                               plugin_set.values[i]->clear(start, end, edit_keyframes);
                }
        }
-
-       if(edit_edits)
-               edits->clear((int64_t)start, (int64_t)end);
        return 0;
 }
 
@@ -1225,25 +1087,13 @@ int Track::popup_transition(int cursor_x, int cursor_y)
 
 
 
-int Track::modify_edithandles(double oldposition,
-       double newposition,
-       int currentend,
-       int handle_mode,
-       int edit_labels,
-       int edit_plugins,
-       int edit_autos)
+int Track::modify_edithandles(double oldposition, double newposition,
+       int currentend, int handle_mode, int edit_labels,
+       int edit_plugins, int edit_autos, int group_id)
 {
-       edits->modify_handles(oldposition,
-               newposition,
-               currentend,
-               handle_mode,
-               1,
-               edit_labels,
-               edit_plugins,
-               edit_autos,
-               0);
-
-
+       edits->modify_handles(oldposition, newposition,
+               currentend, handle_mode, 1, edit_labels, edit_plugins,
+               edit_autos, 0, group_id);
        return 0;
 }
 
@@ -1258,16 +1108,9 @@ int Track::modify_pluginhandles(double oldposition,
        for(int i = 0; i < plugin_set.total; i++)
        {
                if(!trim_edits || trim_edits == (Edits*)plugin_set.values[i])
-                       plugin_set.values[i]->modify_handles(oldposition,
-                               newposition,
-                               currentend,
-                               handle_mode,
+                       plugin_set.values[i]->modify_handles(oldposition, newposition,
 // Don't allow plugin tweeks to affect edits.
-                               0,
-                               edit_labels,
-                               1,
-                               edit_autos,
-                               trim_edits);
+                               currentend, handle_mode, 0, 0, 0, 0, 0, 0);
        }
        return 0;
 }
@@ -1275,13 +1118,17 @@ int Track::modify_pluginhandles(double oldposition,
 
 int Track::paste_silence(double start, double end, int edit_plugins, int edit_autos)
 {
-       int64_t start_i = to_units(start, 0);
-       int64_t end_i = to_units(end, 1);
-
-       edits->paste_silence(start_i, end_i);
-       if(edit_autos) shift_keyframes(start_i, end_i - start_i);
-       if(edit_plugins) shift_effects(start_i, end_i - start_i, edit_autos);
+       return paste_silence(to_units(start, 0), to_units(end, 1),
+                       edit_plugins, edit_autos);
+}
 
+int Track::paste_silence(int64_t start, int64_t end, int edit_plugins, int edit_autos)
+{
+       edits->paste_silence(start, end);
+       if( edit_autos )
+               shift_keyframes(start, end - start);
+       if( edit_plugins )
+               shift_effects(start, end - start, edit_autos, 0);
        edits->optimize();
        return 0;
 }
@@ -1735,64 +1582,63 @@ void Track::reverse_edits(double start, double end, int first_track)
        }
 }
 
-void Track::align_edits(double start,
-       double end,
-       ArrayList<double> *times)
+void Track::align_edits(double start, double end, Track *master_track)
 {
        int64_t start_units = to_units(start, 0);
        int64_t end_units = to_units(end, 0);
 
-// If 1st track with data, times is empty & we need to collect the edit times.
-       if(!times->size())
-       {
-               for(Edit *current = edits->first; current; current = NEXT)
-               {
-                       if(current->startproject >= start_units &&
-                               current->startproject + current->length <= end_units)
-                       {
-                               times->append(from_units(current->startproject));
-                       }
-               }
-       }
-       else
 // All other tracks get silence or cut to align the edits on the times.
-       {
-               int current_time = 0;
-               for(Edit *current = edits->first;
-                       current && current_time < times->size(); )
-               {
-                       if(current->startproject >= start_units &&
-                               current->startproject + current->length <= end_units)
-                       {
-                               int64_t desired_startunits = to_units(times->get(current_time), 0);
-                               int64_t current_startunits = current->startproject;
+       Edit *master = master_track->edits->first;
+       for(Edit *current = edits->first; current && master; ) {
+               if( current->startproject >= start_units &&
+                   current->startproject + current->length <= end_units ) {
+// edit is in highlighted region
+                       int64_t master_length_units = to_units(master_track->from_units(master->length), 0);
+// starting time of master edit
+                       int64_t master_start_units = to_units(master_track->from_units(master->startproject), 0);
+// starting time of current edit
+                       int64_t current_startunits = current->startproject;
+
+// the following occur if multiple aligns are performed
+// master edit is not silence but current edit is silence
+                       if( !master->silence() && current->silence() ) {
+// try again with next edit
                                current = NEXT;
+                               continue;
+                       }
+                       if( master->silence() && !current->silence() ) {
+// master edit is silence but current edit is not silence
+                               master = master->next;
+                               continue;
+                       }
+                       if( current->length < master_length_units / 2 ) {
+// current edit is a glitch edit between 2 required edits
+                               current = NEXT;
+                               continue;
+                       }
 
-
-                               if(current_startunits < desired_startunits)
-                               {
+                       current = NEXT;
+// current edit starts before master edit
+                       if( current_startunits < master_start_units ) {
 //printf("Track::align_edits %d\n", __LINE__);
-                                       edits->paste_silence(current_startunits,
-                                               desired_startunits);
-                                       shift_keyframes(current_startunits,
-                                               desired_startunits - current_startunits);
-                               }
-                               else
-                               if(current_startunits > desired_startunits)
-                               {
-                                       edits->clear(desired_startunits,
-                                               current_startunits);
-                                       if(edl->session->autos_follow_edits)
-                                               shift_keyframes(desired_startunits,
-                                                       current_startunits - desired_startunits);
-                               }
-
-                               current_time++;
+                               edits->paste_silence(current_startunits, master_start_units);
+                               shift_keyframes(current_startunits,
+                                       master_start_units - current_startunits);
                        }
-                       else
-                       {
-                               current = NEXT;
+                       else if( current_startunits > master_start_units ) {
+// current edit starts after master edit
+                               edits->clear(master_start_units,
+                                       current_startunits);
+                               if(edl->session->autos_follow_edits)
+                                       shift_keyframes(master_start_units,
+                                               current_startunits - master_start_units);
                        }
+
+                       master = master->next;
+               }
+               else {
+                       current = NEXT;
+                       master = master->next;
                }
        }
 
@@ -1876,26 +1722,21 @@ int64_t Track::frame_align(int64_t position, int round)
        return position;
 }
 
-int Track::plugin_exists(Plugin *plugin)
+Plugin *Track::plugin_exists(int plugin_id)
 {
-       for(int number = 0; number < plugin_set.size(); number++)
-       {
-               PluginSet *ptr = plugin_set.get(number);
-               for(Plugin *current_plugin = (Plugin*)ptr->first;
-                       current_plugin;
-                       current_plugin = (Plugin*)current_plugin->next)
-               {
-                       if(current_plugin == plugin) return 1;
+       for( int i=0; i<plugin_set.size(); ++i ) {
+               PluginSet *set = plugin_set.get(i);
+               Plugin *plugin = (Plugin*)set->first;
+               for( ; plugin; plugin=(Plugin*)plugin->next ) {
+                       if( plugin->orig_id == plugin_id )
+                               return plugin;
                }
        }
-
-       for(Edit *current = edits->first; current; current = NEXT)
-       {
-               if(current->transition &&
-                       (Plugin*)current->transition == plugin) return 1;
+       for( Edit *current=edits->first; current; current=NEXT ) {
+               Plugin *plugin = (Plugin *)current->transition;
+               if( plugin && plugin->orig_id == plugin_id )
+                       return plugin;
        }
-
-
        return 0;
 }
 
@@ -1910,3 +1751,135 @@ int Track::get_mixer_id()
        return mixer_id;
 }
 
+void Track::get_fauto_xyz(int fauto, float &x, float &y, float &z)
+{
+       FloatAutos **fautos = (FloatAutos **)&automation->autos;
+       FloatAuto *xauto = (FloatAuto *)fautos[fauto+0]->get_auto_for_editing(-1, 1);
+       if( xauto ) x = xauto->get_value();
+       FloatAuto *yauto = (FloatAuto *)fautos[fauto+1]->get_auto_for_editing(-1, 1);
+       if( yauto ) y = yauto->get_value();
+       FloatAuto *zauto = (FloatAuto *)fautos[fauto+2]->get_auto_for_editing(-1, 1);
+       if( zauto ) z = zauto->get_value();
+}
+void Track::set_fauto_xyz(int fauto, float x, float y, float z)
+{
+       FloatAutos **fautos = (FloatAutos **)&automation->autos;
+       FloatAuto *xauto = (FloatAuto *)fautos[fauto+0]->get_auto_for_editing(-1, 1);
+       if( xauto ) xauto->set_value(x);
+       FloatAuto *yauto = (FloatAuto *)fautos[fauto+1]->get_auto_for_editing(-1, 1);
+       if( yauto ) yauto->set_value(y);
+       FloatAuto *zauto = (FloatAuto *)fautos[fauto+2]->get_auto_for_editing(-1, 1);
+       if( zauto ) zauto->set_value(z);
+}
+
+void Track::get_projector(float &x, float &y, float &z)
+{
+       get_fauto_xyz(AUTOMATION_PROJECTOR_X, x, y, z);
+}
+void Track::set_projector(float x, float y, float z)
+{
+       set_fauto_xyz(AUTOMATION_PROJECTOR_X, x, y, z);
+}
+
+void Track::get_camera(float &x, float &y, float &z)
+{
+       get_fauto_xyz(AUTOMATION_CAMERA_X, x, y, z);
+}
+void Track::set_camera(float x, float y, float z)
+{
+       set_fauto_xyz(AUTOMATION_CAMERA_X, x, y, z);
+}
+
+int Track::is_hidden()
+{
+       if( master ) return 0;
+       if( edl->local_session->gang_tracks == GANG_MEDIA ) return 1;
+       if( edl->local_session->gang_tracks == GANG_CHANNELS ) {
+               for( Track *track=previous; track; track=track->previous ) {
+                       if( track->data_type == data_type ) return 1;
+                       if( track->master ) return 0;
+               }
+       }
+       return 0;
+}
+
+Track *Track::gang_master()
+{
+       Track *track = this;
+       switch( edl->local_session->gang_tracks ) {
+       case GANG_NONE:
+               return track;
+       case GANG_CHANNELS: {
+               Track *current = track;
+               int data_type = track->data_type;
+               while( current && !current->master ) {
+                       if( !(current = current->previous) ) break;
+                       if( current->data_type == data_type ) track = current;
+               }
+               break; }
+       case GANG_MEDIA: {
+               while( track && !track->master ) track = track->previous;
+               break; }
+       }
+       if( !track ) track = tracks->first;
+       return track;
+}
+
+int Track::in_gang(Track *track)
+{
+       if( edl->local_session->gang_tracks == GANG_NONE ) return ganged;
+       Track *current = this;
+       while( current && !current->master ) current = current->previous;
+       while( track && !track->master ) track = track->previous;
+       return current == track ? 1 : 0;
+}
+
+int Track::is_armed()
+{
+       return armed && gang_master()->armed;
+}
+
+int Track::is_ganged()
+{
+       return ganged && gang_master()->ganged;
+}
+
+int Track::armed_gang(Track *track)
+{
+       if( !track->ganged ) return 0;
+       if( edl->local_session->gang_tracks == GANG_NONE ) return ganged;
+       Track *current = gang_master();
+       if( !current->ganged ) return 0;
+       for(;;) {
+               if( track == current ) return 1;
+               current = current->next;
+               if( !current || current->master ) return 0;
+       }
+       return 1;
+}
+
+int Track::plays()
+{
+       return play && gang_master()->play;
+}
+
+int Track::index_in(Mixer *mixer)
+{
+       if( !mixer || mixer_id < 0 ) return -1;
+       int k = mixer->mixer_ids.size();
+       while( --k >= 0 && mixer_id != mixer->mixer_ids[k] );
+       return k;
+}
+
+void Track::create_keyframes(double position, int mask, int mode)
+{
+       for( int idx=0; idx<AUTOMATION_TOTAL; mask>>=1,++idx ) {
+               if( !(mask & 1) ) continue;
+               Autos *autos = automation->autos[idx];
+               if( !autos ) continue;
+               FloatAuto *float_auto = (FloatAuto *)
+                       autos->get_auto_for_editing(position, -1);
+               float_auto->change_curve_mode((FloatAuto::t_mode)mode, 0);
+       }
+}
+