confirm prefs update, fix bg_pixmap sz, plugin layout tweaks
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / track.C
index 482cbb1e024f7f9556624083c021380ee67be557..9fdc531a2b43854c299a7d076750a78a43fbc0b7 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"
@@ -67,6 +68,7 @@ Track::Track(EDL *edl, Tracks *tracks) : ListItem<Track>()
        track_h = edl->session->output_h;
        id = EDL::next_id();
        mixer_id = -1;
+       masks = (1<<SUBMASKS)-1;
 }
 
 Track::~Track()
@@ -92,6 +94,7 @@ int Track::copy_settings(Track *track)
        this->play = track->play;
        this->track_w = track->track_w;
        this->track_h = track->track_h;
+       this->masks = track->masks;
        strcpy(this->title, track->title);
        return 0;
 }
@@ -194,12 +197,9 @@ 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]);
        }
@@ -337,6 +337,7 @@ int Track::load(FileXML *file, int track_offset, uint32_t load_flags)
        expand_view = file->tag.get_property("EXPAND", expand_view);
        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,23 +475,17 @@ 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);
 }
 
 
@@ -670,11 +665,11 @@ 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);
        }
 }
 
@@ -859,46 +854,22 @@ void Track::synchronize_params(Track *track)
 }
 
 
-
-
-
 int Track::dump(FILE *fp)
 {
-       fprintf(fp,"   Data type %d\n", data_type);
+       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,"   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>()
 {
@@ -1068,10 +1039,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.
@@ -1091,6 +1060,7 @@ int Track::copy(double start,
        file->tag.set_property("EXPAND", expand_view);
        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 +1081,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 +1142,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;
@@ -1192,9 +1164,10 @@ int Track::clear(int64_t start, int64_t end,
        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(start, end, edit_autos);
+                               plugin_set.values[i]->clear(start, end, edit_keyframes);
                }
        }
        if( edit_edits )
@@ -1243,8 +1216,7 @@ int Track::modify_pluginhandles(double oldposition,
                if(!trim_edits || trim_edits == (Edits*)plugin_set.values[i])
                        plugin_set.values[i]->modify_handles(oldposition, newposition,
 // Don't allow plugin tweeks to affect edits.
-                               currentend, handle_mode, 0,
-                               edit_labels, 1, edit_autos, trim_edits, 0);
+                               currentend, handle_mode, 0, 0, 0, 0, 0, 0);
        }
        return 0;
 }
@@ -1262,7 +1234,7 @@ int Track::paste_silence(int64_t start, int64_t end, int edit_plugins, int edit_
        if( edit_autos )
                shift_keyframes(start, end - start);
        if( edit_plugins )
-               shift_effects(start, end - start, edit_autos);
+               shift_effects(start, end - start, edit_autos, 0);
        edits->optimize();
        return 0;
 }
@@ -1891,3 +1863,42 @@ 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);
+}
+