Reworked track settings.
[demorecorder] / src / DemoRecorder.vala
index 5af0fb9..56b9001 100644 (file)
@@ -29,7 +29,7 @@ public class DemoRecorder : Hildon.Program {
   RecordPipeline recordpipeline;
   PlayerTransport player;
   MixerBin mixer;
-  uint track_counter;
+  uint track_counter { get { return (null != tracks) ? tracks.get_children().length() : 0; }}
   bool recording;
   bool playing;
   bool encoding;
@@ -112,7 +112,6 @@ public class DemoRecorder : Hildon.Program {
     project = SettingsStructures.ProjectSettings();
     recording = false;
     playing = false;
-    track_counter = 0;
     window = new Hildon.StackableWindow();
     window.destroy.connect(Gtk.main_quit);
     window.delete_event.connect(on_delete_event);
@@ -184,26 +183,35 @@ public class DemoRecorder : Hildon.Program {
       keep_screen_on();
       if (0 != screen_timer_id) Source.remove(screen_timer_id);
       screen_timer_id = Timeout.add ((uint)Time.Milliseconds.SECOND * 20, keep_screen_on);
-//       for (int i = 0; i < tracks.children.length(); ++i) {
-//         TrackTransport tt = tracks.children.nth_data(i) as TrackTransport;
-//         if (null != tt) {
-//           if (tt.get_active_state()) {
-//             stdout.printf("Track %s active and has been added\n", i.to_string());
-//             //track.bin.set_start_time((Gst.ClockTime)(Time.Nanoseconds.SECOND * idx));
-//             mixer.add_track(tt.track_bin);
-//           }
-//         }
-//         tt = null;
-//       }
-       while (idx < project.tracks.length()) {
+      var children = tracks.get_children();
+      foreach (var child in children) {
+        TrackTransport tt = child as TrackTransport;
+        if (null != tt && tt.get_active_state()) {
+          mixer.add_track(tt.track_bin);
+        }
+      }
+      //for (int i = 0; i < tracks.children.length(); ++i) {
+         //Object tt = tracks.children.nth_data(i);
+         //stdout.printf("Type %s\n",tt.get_type().name());
+         //if (null != tt) {
+           //if (tt.track_bin.IsActive) {
+             //stdout.printf("Track %s active and has been added\n", i.to_string());
+             //track.bin.set_start_time((Gst.ClockTime)(Time.Nanoseconds.SECOND * idx));
+             //mixer.add_track(tt.track_bin);
+           //}
+         //}
+         //tt = null;
+       //}
+       /*while (idx < project.tracks.length()) {
          Track track = project.tracks.nth_data(idx);
          if (track.active) {
-           stdout.printf("Track %s active and has been added\n", idx.to_string());
+           //stdout.printf("Track %s active and has been added\n", idx.to_string());
+           stdout.printf("Track_bin %s active and has been added\n", track.bin.IsActive.to_string());
            //track.bin.set_start_time((Gst.ClockTime)(Time.Nanoseconds.SECOND * idx));
            mixer.add_track(track.bin);
          }
          ++idx;
-       }
+       }*/
       playpipeline = new PlayPipeline("player", mixer);
       this.playback_position_duration.connect(player.position_duration_callback);
       playpipeline.position_duration.connect(playpipeline_position_duration_callback);
@@ -452,6 +460,7 @@ public class DemoRecorder : Hildon.Program {
     for (int idx = ((int)project.tracks.length()) - 1; idx > -1; --idx) {
       project.tracks.delete_link(project.tracks.nth(idx));
     }
+    player.position_duration_callback(0, 0);
   }
   private void remove_track_interactive(TrackTransport tt) {
     string message = "";
@@ -494,10 +503,25 @@ public class DemoRecorder : Hildon.Program {
   private void remove_track(TrackTransport tt) {
     project.tracks.remove(tt.track);
     tracks.remove(tt);
+    // rebuild project.tracks
+    for (int idx = (int)project.tracks.length(); idx >= 0; --idx) {
+      project.tracks.remove_link(project.tracks.nth(idx));
+    }
+    foreach (var child in tracks.get_children()) {
+      project.tracks.append(((TrackTransport)child).track);
+    }
+    project_dirty = true;
     tt = null;
   }
   
   private void save_project() {
+    // rebuild track settings
+    for (int idx = (int)project.tracks.length(); idx >= 0; --idx) {
+      project.tracks.remove_link(project.tracks.nth(idx));
+    }
+    foreach (var child in tracks.get_children()) {
+      project.tracks.append(((TrackTransport)child).track);
+    }
     if (0 < project.location.length) {
       save_project_settings(project.location);
     }