ffmpeg scan remap fix, configure.ac all or none fix, 3rd party libs: ffmpeg, turbo...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / track.C
index af7b6cdb5b37788ab0ad335bda6d391ddbe0f49b..9e86481c8df919e4d01f441b2a60ce8ff292368f 100644 (file)
@@ -60,9 +60,10 @@ Track::Track(EDL *edl, Tracks *tracks) : ListItem<Track>()
        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;
@@ -88,8 +89,9 @@ 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;
@@ -316,9 +318,10 @@ 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);
@@ -477,90 +480,17 @@ void Track::insert_plugin_set(Track *track,
                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(1),
-                               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;
 }
@@ -638,8 +568,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;
@@ -665,26 +594,54 @@ void Track::shift_effects(int64_t position, int64_t length, int edit_autos, Edit
 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)
@@ -696,25 +653,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()
 {
@@ -845,9 +783,10 @@ void Track::synchronize_params(Track *track)
 
 int Track::dump(FILE *fp)
 {
-       fprintf(fp,"   Data type %d, draw %d, gang %d, play %d, record %d, nudge %jd, masks 0x%04x\n",
-               data_type, draw, gang, play, record, nudge, masks);
        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);
@@ -1005,11 +944,12 @@ int Track::copy(int copy_flags, double start, double end,
 
 
        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);
@@ -1851,6 +1791,64 @@ void Track::set_camera(float x, float y, float z)
        set_fauto_xyz(AUTOMATION_CAMERA_X, x, y, z);
 }
 
+Track *Track::gang_master()
+{
+       Track *track = this;
+       switch( edl->session->gang_tracks ) {
+       case GANG_NONE:
+               return track;
+       case GANG_CHANNELS: {
+               Track *current = track;
+               int data_type = track->data_type;
+               while( current && !track->master ) {
+                       if( !(current = current->previous) ) break;
+                       if( current->data_type == data_type ) track = current;
+                       if( track->master ) break;
+               }
+               break; }
+       case GANG_MEDIA: {
+               while( track && !track->master ) track = track->previous;
+               break; }
+       }
+       if( !track ) track = tracks->first;
+       return track;
+}
+
+int Track::is_hidden()
+{
+       if( master ) return 0;
+       if( edl->session->gang_tracks == GANG_MEDIA ) return 1;
+       if( edl->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;
+}
+int Track::is_armed()
+{
+       return gang_master()->armed;
+}
+
+int Track::is_ganged()
+{
+       return gang_master()->ganged;
+}
+
+int Track::armed_gang(Track *track)
+{
+       if( edl->session->gang_tracks == GANG_NONE ) return ganged;
+       Track *current = gang_master();
+       for(;;) {
+               if( track == current ) return 1;
+               current = current->next;
+               if( !current || current->master ) return 0;
+       }
+       return 1;
+}
+
+
 int Track::index_in(Mixer *mixer)
 {
        if( !mixer || mixer_id < 0 ) return -1;