Change redirectmenu to processormenu
[ardour.git] / gtk2_ardour / route_time_axis.cc
index 596f84c249f6f1c86ca4b247e096975f123c2b84..b3a988fd927318660ae47e787d2a44698eedc192 100644 (file)
@@ -52,6 +52,7 @@
 #include <ardour/session_playlist.h>
 #include <ardour/utils.h>
 #include <ardour/parameter.h>
+#include <ardour/profile.h>
 
 #include "ardour_ui.h"
 #include "route_time_axis.h"
 
 using namespace ARDOUR;
 using namespace PBD;
+using namespace Gtkmm2ext;
 using namespace Gtk;
 using namespace Editing;
 using namespace sigc;
+using namespace std;
 
+Glib::RefPtr<Gdk::Pixbuf> RouteTimeAxisView::slider;
+
+void
+RouteTimeAxisView::setup_slider_pix ()
+{
+       if ((slider = ::get_icon ("fader_belt_h")) == 0) {
+               throw failed_constructor ();
+       }
+}
 
 RouteTimeAxisView::RouteTimeAxisView (PublicEditor& ed, Session& sess, boost::shared_ptr<Route> rt, Canvas& canvas)
        : AxisView(sess),
@@ -93,16 +105,27 @@ RouteTimeAxisView::RouteTimeAxisView (PublicEditor& ed, Session& sess, boost::sh
          playlist_button (_("p")), 
          size_button (_("h")), // height
          automation_button (_("a")),
-         visual_button (_("v"))
+         visual_button (_("v")),
+         gm (rt, sess, slider, true)
 
 {
+       gm.get_level_meter().set_no_show_all();
+       gm.get_level_meter().setup_meters(50);
+
        _has_state = true;
        playlist_menu = 0;
        playlist_action_menu = 0;
        automation_action_menu = 0;
        _view = 0;
+
+       if (!_route->is_hidden()) {
+               _marked_for_display = true;
+       }
+
        timestretch_rect = 0;
        no_redraw = false;
+       destructive_track_mode_item = 0;
+       normal_track_mode_item = 0;
 
        ignore_toggle = false;
 
@@ -147,12 +170,19 @@ RouteTimeAxisView::RouteTimeAxisView (PublicEditor& ed, Session& sess, boost::sh
                rec_enable_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::rec_enable_release));
                controls_table.attach (*rec_enable_button, 5, 6, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
                ARDOUR_UI::instance()->tooltips().set_tip(*rec_enable_button, _("Record"));
+
        }
 
+       controls_hbox.pack_start(gm.get_level_meter(), false, false);
+       _route->meter_change.connect (mem_fun(*this, &RouteTimeAxisView::meter_changed));
+       _route->input_changed.connect (mem_fun(*this, &RouteTimeAxisView::io_changed));
+       _route->output_changed.connect (mem_fun(*this, &RouteTimeAxisView::io_changed));
+
        controls_table.attach (*mute_button, 6, 7, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
-       controls_table.attach (*solo_button, 7, 8, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::FILL|Gtk::EXPAND, 0, 0);
+       controls_table.attach (*solo_button, 7, 8, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
 
-       controls_table.attach (edit_group_button, 6, 7, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
+       controls_table.attach (edit_group_button, 7, 8, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
+       controls_table.attach (gm.get_gain_slider(), 0, 5, 1, 2, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
 
        ARDOUR_UI::instance()->tooltips().set_tip(*solo_button,_("Solo"));
        ARDOUR_UI::instance()->tooltips().set_tip(*mute_button,_("Mute"));
@@ -165,17 +195,24 @@ RouteTimeAxisView::RouteTimeAxisView (PublicEditor& ed, Session& sess, boost::sh
        
        label_view ();
 
-       controls_table.attach (hide_button, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
-       controls_table.attach (visual_button, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
-       controls_table.attach (size_button, 2, 3, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
-       controls_table.attach (automation_button, 3, 4, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
+       if (0) {
+
+               /* old school - when we used to put an extra row of buttons in place */
+
+               controls_table.attach (hide_button, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
+               controls_table.attach (visual_button, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
+               controls_table.attach (size_button, 2, 3, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
+               controls_table.attach (automation_button, 3, 4, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
+
+       } else {
+
+               controls_table.attach (automation_button, 6, 7, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
+       }
 
        if (is_track() && track()->mode() == ARDOUR::Normal) {
                controls_table.attach (playlist_button, 5, 6, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
        }
 
-       /* remove focus from the buttons */
-       
        y_position = -1;
 
        _route->mute_changed.connect (mem_fun(*this, &RouteUI::mute_changed));
@@ -199,6 +236,9 @@ RouteTimeAxisView::RouteTimeAxisView (PublicEditor& ed, Session& sess, boost::sh
 
        editor.ZoomChanged.connect (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
        ColorsChanged.connect (mem_fun (*this, &RouteTimeAxisView::color_handler));
+
+       gm.get_gain_slider().signal_scroll_event().connect(mem_fun(*this, &RouteTimeAxisView::controls_ebox_scroll), false);
+       gm.get_gain_slider().set_name ("TrackGainFader");
 }
 
 RouteTimeAxisView::~RouteTimeAxisView ()
@@ -223,6 +263,12 @@ RouteTimeAxisView::~RouteTimeAxisView ()
                delete _view;
                _view = 0;
        }
+
+       for (AutomationTracks::iterator i = _automation_tracks.begin(); i != _automation_tracks.end(); ++i) {
+               delete i->second;
+       }
+       
+       _automation_tracks.clear ();
 }
 
 void
@@ -231,6 +277,8 @@ RouteTimeAxisView::post_construct ()
        /* map current state of the route */
 
        update_diskstream_display ();
+
+       subplugin_menu.items().clear ();
        _route->foreach_processor (this, &RouteTimeAxisView::add_processor_to_subplugin_menu);
        _route->foreach_processor (this, &RouteTimeAxisView::add_existing_processor_automation_curves);
        reset_processor_automation_curves ();
@@ -251,60 +299,10 @@ RouteTimeAxisView::playlist_modified ()
 {
 }
 
-void
-RouteTimeAxisView::set_state (const XMLNode& node)
-{
-       const XMLProperty *prop;
-       
-       TimeAxisView::set_state (node);
-       
-       if ((prop = node.property ("shown_editor")) != 0) {
-               if (prop->value() == "no") {
-                       _marked_for_display = false;
-               } else {
-                       _marked_for_display = true;
-               }
-       } else {
-               _marked_for_display = true;
-       }
-       
-       XMLNodeList nlist = node.children();
-       XMLNodeConstIterator niter;
-       XMLNode *child_node;
-       
-       _show_automation.clear();
-       
-       for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
-               child_node = *niter;
-               
-               Parameter param(child_node->name());
-
-               if (param) {
-               
-                       XMLProperty* prop = child_node->property ("shown");
-                       
-                       if (_automation_tracks.find(param) == _automation_tracks.end())
-                               create_automation_child(param);
-
-                       if (prop != 0 && prop->value() == "yes")
-                               _show_automation.insert(Parameter(GainAutomation));
-
-               } else {
-                       warning << "GUI info exists, but no parameter " << child_node->name() << " found." << endmsg;
-               }
-       }
-}
-
-XMLNode* 
-RouteTimeAxisView::get_child_xml_node (const string & childname)
-{
-       return RouteUI::get_child_xml_node (childname);
-}
-
 gint
 RouteTimeAxisView::edit_click (GdkEventButton *ev)
 {
-       if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
+       if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
                _route->set_edit_group (0, this);
                return FALSE;
        } 
@@ -399,7 +397,8 @@ RouteTimeAxisView::playlist_click ()
        playlist_action_menu->set_name ("ArdourContextMenu");
        
        build_playlist_menu (playlist_action_menu);
-       editor.set_selected_track (*this, Selection::Add);
+
+       conditionally_add_to_selection ();
        playlist_action_menu->popup (1, gtk_get_current_event_time());
 }
 
@@ -412,7 +411,7 @@ RouteTimeAxisView::automation_click ()
                */
                build_display_menu ();
        }
-       editor.set_selected_track (*this, Selection::Add);
+       conditionally_add_to_selection ();
        automation_action_menu->popup (1, gtk_get_current_event_time());
 }
 
@@ -434,7 +433,7 @@ RouteTimeAxisView::build_automation_action_menu ()
        automation_items.push_back (MenuElem (_("Hide all automation"),
                                              mem_fun(*this, &RouteTimeAxisView::hide_all_automation)));
 
-       if (subplugin_menu.get_parent())
+       if (subplugin_menu.get_attach_widget())
                subplugin_menu.detach();
 
        automation_items.push_back (MenuElem (_("Plugins"), subplugin_menu));
@@ -481,66 +480,89 @@ RouteTimeAxisView::build_display_menu ()
        items.push_back (SeparatorElem());
 
        build_remote_control_menu ();
-       items.push_back (MenuElem (_("Remote Control ID"), *remote_control_menu));
-
        build_automation_action_menu ();
-       items.push_back (MenuElem (_("Automation"), *automation_action_menu));
+
+       if (!Profile->get_sae()) {
+               items.push_back (MenuElem (_("Remote Control ID"), *remote_control_menu));
+               items.push_back (MenuElem (_("Automation"), *automation_action_menu));
+               items.push_back (SeparatorElem());
+       }
 
        // Hook for derived classes to add type specific stuff
-       items.push_back (SeparatorElem());
        append_extra_display_menu_items ();
        items.push_back (SeparatorElem());
        
        if (is_track()) {
 
+               Menu *layers_menu = manage(new Menu);
+               MenuList &layers_items = layers_menu->items();
+               layers_menu->set_name("ArdourContextMenu");
+
+               RadioMenuItem::Group layers_group;
+
+               layers_items.push_back(RadioMenuElem (layers_group, _("Overlaid"),
+                               bind (mem_fun (*this, &RouteTimeAxisView::set_layer_display), Overlaid)));
+               layers_items.push_back(RadioMenuElem (layers_group, _("Stacked"),
+                               bind (mem_fun (*this, &RouteTimeAxisView::set_layer_display), Stacked)));
+
+               items.push_back (MenuElem (_("Layers"), *layers_menu));
+
                Menu* alignment_menu = manage (new Menu);
                MenuList& alignment_items = alignment_menu->items();
                alignment_menu->set_name ("ArdourContextMenu");
 
                RadioMenuItem::Group align_group;
-               
+
                alignment_items.push_back (RadioMenuElem (align_group, _("Align with existing material"),
-                       bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), ExistingMaterial)));
+                                       bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), ExistingMaterial)));
                align_existing_item = dynamic_cast<RadioMenuItem*>(&alignment_items.back());
                if (get_diskstream()->alignment_style() == ExistingMaterial)
                        align_existing_item->set_active();
-               
+
                alignment_items.push_back (RadioMenuElem (align_group, _("Align with capture time"),
-                       bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), CaptureTime)));
+                                       bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), CaptureTime)));
                align_capture_item = dynamic_cast<RadioMenuItem*>(&alignment_items.back());
                if (get_diskstream()->alignment_style() == CaptureTime)
                        align_capture_item->set_active();
-               
-               items.push_back (MenuElem (_("Alignment"), *alignment_menu));
+
+               if (!Profile->get_sae()) {
+                       items.push_back (MenuElem (_("Alignment"), *alignment_menu));
+                       get_diskstream()->AlignmentStyleChanged.connect (mem_fun(*this, &RouteTimeAxisView::align_style_changed));
+                       
+                       RadioMenuItem::Group mode_group;
+                       items.push_back (RadioMenuElem (mode_group, _("Normal mode"),
+                                                       bind (mem_fun (*this, &RouteTimeAxisView::set_track_mode), ARDOUR::Normal)));
+                       normal_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
+                       items.push_back (RadioMenuElem (mode_group, _("Tape mode"),
+                                                       bind (mem_fun (*this, &RouteTimeAxisView::set_track_mode), ARDOUR::Destructive)));
+                       destructive_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
+                       
+                       switch (track()->mode()) {
+                       case ARDOUR::Destructive:
+                               destructive_track_mode_item->set_active ();
+                               break;
+                       case ARDOUR::Normal:
+                               normal_track_mode_item->set_active ();
+                               break;
+                       }
 
                get_diskstream()->AlignmentStyleChanged.connect (
-                       mem_fun(*this, &RouteTimeAxisView::align_style_changed));
-
-               RadioMenuItem::Group mode_group;
-               items.push_back (RadioMenuElem (mode_group, _("Normal mode"),
-                                               bind (mem_fun (*this, &RouteTimeAxisView::set_track_mode), ARDOUR::Normal)));
-               normal_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
-               items.push_back (RadioMenuElem (mode_group, _("Tape mode"),
-                                               bind (mem_fun (*this, &RouteTimeAxisView::set_track_mode), ARDOUR::Destructive)));
-               destructive_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
-                                
-               
-               switch (track()->mode()) {
-               case ARDOUR::Destructive:
-                       destructive_track_mode_item->set_active ();
-                       break;
-               case ARDOUR::Normal:
-                       normal_track_mode_item->set_active ();
-                       break;
+                               mem_fun(*this, &RouteTimeAxisView::align_style_changed));
+
+               mode_menu = build_mode_menu();
+               if (mode_menu)
+                       items.push_back (MenuElem (_("Mode"), *mode_menu));
+                       
+               items.push_back (SeparatorElem());
                }
        }
 
-       items.push_back (SeparatorElem());
        items.push_back (CheckMenuElem (_("Active"), mem_fun(*this, &RouteUI::toggle_route_active)));
        route_active_menu_item = dynamic_cast<CheckMenuItem *> (&items.back());
        route_active_menu_item->set_active (_route->active());
 
        items.push_back (SeparatorElem());
+       items.push_back (MenuElem (_("Hide"), mem_fun(*this, &RouteTimeAxisView::hide_click)));
        items.push_back (MenuElem (_("Remove"), mem_fun(*this, &RouteUI::remove_this_route)));
 }
 
@@ -570,8 +592,8 @@ RouteTimeAxisView::set_track_mode (TrackMode mode)
                /*NOTREACHED*/
                return;
        }
-
-       if (item->get_active () && track()->mode() != mode) {
+       
+       if (item && other_item && item->get_active () && track()->mode() != mode) {
                _set_track_mode (track().get(), mode, other_item);
        }
 }
@@ -677,7 +699,7 @@ RouteTimeAxisView::show_timestretch (nframes_t start, nframes_t end)
 
        x1 = start / editor.get_current_zoom();
        x2 = (end - 1) / editor.get_current_zoom();
-       y2 = height - 2;
+       y2 = current_height() - 2;
        
        timestretch_rect->property_x1() = x1;
        timestretch_rect->property_y1() = 1.0;
@@ -716,52 +738,30 @@ RouteTimeAxisView::show_selection (TimeSelection& ts)
 }
 
 void
-RouteTimeAxisView::set_height (TrackHeight h)
+RouteTimeAxisView::set_height (uint32_t h)
 {
-       bool height_changed = (height == 0) || (h != height_style);
+       int gmlen = h - 5;
+       bool height_changed = (height == 0) || (h != height);
+       gm.get_level_meter().setup_meters (gmlen);
 
        TimeAxisView::set_height (h);
 
        ensure_xml_node ();
 
        if (_view) {
-               _view->set_height ((double) height);
+               _view->set_height ((double) current_height());
        }
 
-       switch (height_style) {
-       case Largest:
-               xml_node->add_property ("track_height", "largest");
-               break;
-
-       case Large:
-               xml_node->add_property ("track_height", "large");
-               break;
-
-       case Larger:
-               xml_node->add_property ("track_height", "larger");
-               break;
-
-       case Normal:
-               xml_node->add_property ("track_height", "normal");
-               break;
+       char buf[32];
+       snprintf (buf, sizeof (buf), "%u", height);
+       xml_node->add_property ("height", buf);
 
-       case Smaller:
-               xml_node->add_property ("track_height", "smaller");
-               break;
-
-       case Small:
-               xml_node->add_property ("track_height", "small");
-               break;
-       }
-
-       switch (height_style) {
-       case Largest:
-       case Large:
-       case Larger:
-       case Normal:
+       if (height >= hNormal) {
+               reset_meter();
                show_name_entry ();
                hide_name_label ();
 
+               gm.get_gain_slider().show();
                mute_button->show();
                solo_button->show();
                if (rec_enable_button)
@@ -776,12 +776,14 @@ RouteTimeAxisView::set_height (TrackHeight h)
                if (is_track() && track()->mode() == ARDOUR::Normal) {
                        playlist_button.show();
                }
-               break;
 
-       case Smaller:
+       } else if (height >= hSmaller) {
+
+               reset_meter();
                show_name_entry ();
                hide_name_label ();
 
+               gm.get_gain_slider().hide();
                mute_button->show();
                solo_button->show();
                if (rec_enable_button)
@@ -796,12 +798,13 @@ RouteTimeAxisView::set_height (TrackHeight h)
                if (is_track() && track()->mode() == ARDOUR::Normal) {
                        playlist_button.hide ();
                }
-               break;
 
-       case Small:
+       } else {
+
                hide_name_entry ();
                show_name_label ();
-
+               
+               gm.get_gain_slider().hide();
                mute_button->hide();
                solo_button->hide();
                if (rec_enable_button)
@@ -814,7 +817,6 @@ RouteTimeAxisView::set_height (TrackHeight h)
                automation_button.hide ();
                playlist_button.hide ();
                name_label.set_text (_route->name());
-               break;
        }
 
        if (height_changed) {
@@ -1060,7 +1062,7 @@ RouteTimeAxisView::update_diskstream_display ()
 void
 RouteTimeAxisView::selection_click (GdkEventButton* ev)
 {
-       if (Keyboard::modifier_state_equals (ev->state, (Keyboard::Shift|Keyboard::Control))) {
+       if (Keyboard::modifier_state_equals (ev->state, (Keyboard::TertiaryModifier|Keyboard::PrimaryModifier))) {
 
                /* special case: select/deselect all tracks */
                if (editor.get_selection().selected (this)) {
@@ -1132,7 +1134,7 @@ RouteTimeAxisView::get_selectables (nframes_t start, nframes_t end, double top,
        nframes_t start_adjusted = session_frame_to_track_frame(start, speed);
        nframes_t end_adjusted   = session_frame_to_track_frame(end, speed);
 
-       if (_view && ((top < 0.0 && bot < 0.0)) || touched (top, bot)) {
+       if ((_view && ((top < 0.0 && bot < 0.0))) || touched (top, bot)) {
                _view->get_selectables (start_adjusted, end_adjusted, results);
        }
 
@@ -1268,6 +1270,19 @@ RouteTimeAxisView::find_next_region (nframes_t pos, RegionPoint point, int32_t d
        return boost::shared_ptr<Region> ();
 }
 
+nframes64_t 
+RouteTimeAxisView::find_next_region_boundary (nframes64_t pos, int32_t dir)
+{
+       boost::shared_ptr<Diskstream> stream;
+       boost::shared_ptr<Playlist> playlist;
+
+       if ((stream = get_diskstream()) != 0 && (playlist = stream->playlist()) != 0) {
+               return playlist->find_next_region_boundary (pos, dir);
+       }
+
+       return -1;
+}
+
 bool
 RouteTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op)
 {
@@ -1407,10 +1422,10 @@ RouteTimeAxisView::build_playlist_menu (Gtk::Menu * menu)
        playlist_items.push_back (MenuElem (_("Rename"), mem_fun(*this, &RouteTimeAxisView::rename_current_playlist)));
        playlist_items.push_back (SeparatorElem());
 
-       playlist_items.push_back (MenuElem (_("New"), mem_fun(editor, &PublicEditor::new_playlists)));
-       playlist_items.push_back (MenuElem (_("New Copy"), mem_fun(editor, &PublicEditor::copy_playlists)));
+       playlist_items.push_back (MenuElem (_("New"), bind(mem_fun(editor, &PublicEditor::new_playlists), this)));
+       playlist_items.push_back (MenuElem (_("New Copy"), bind(mem_fun(editor, &PublicEditor::copy_playlists), this)));
        playlist_items.push_back (SeparatorElem());
-       playlist_items.push_back (MenuElem (_("Clear Current"), mem_fun(editor, &PublicEditor::clear_playlists)));
+       playlist_items.push_back (MenuElem (_("Clear Current"), bind(mem_fun(editor, &PublicEditor::clear_playlists), this)));
        playlist_items.push_back (SeparatorElem());
 
        playlist_items.push_back (MenuElem(_("Select from all ..."), mem_fun(*this, &RouteTimeAxisView::show_playlist_selector)));
@@ -1473,6 +1488,7 @@ RouteTimeAxisView::color_handler ()
                timestretch_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TimeStretchFill.get();
        }
 
+       reset_meter();
 }
 
 void
@@ -1508,8 +1524,9 @@ void
 RouteTimeAxisView::automation_track_hidden (Parameter param)
 {
        RouteAutomationNode* ran = automation_track(param);
-       if (!ran)
+       if (!ran) {
                return;
+       }
 
        _show_automation.erase(param);
        ran->track->get_state_node()->add_property (X_("shown"), X_("no"));
@@ -1518,7 +1535,7 @@ RouteTimeAxisView::automation_track_hidden (Parameter param)
                ran->menu_item->set_active (false);
        }
 
-        _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
+        _route->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
 }
 
 
@@ -1552,10 +1569,9 @@ RouteTimeAxisView::show_all_automation ()
 
        no_redraw = false;
 
-
        /* Redraw */
 
-        _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
+        _route->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
 }
 
 void
@@ -1587,8 +1603,8 @@ RouteTimeAxisView::show_existing_automation ()
        }
 
        no_redraw = false;
-
-        _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
+       
+       _route->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
 }
 
 void
@@ -1596,6 +1612,17 @@ RouteTimeAxisView::hide_all_automation ()
 {
        no_redraw = true;
 
+       /* Hide our automation */
+
+       for (map<ARDOUR::Parameter, RouteAutomationNode*>::iterator i = _automation_tracks.begin(); i != _automation_tracks.end(); ++i) {
+               i->second->track->set_marked_for_display (false);
+               i->second->track->hide ();
+               i->second->track->get_state_node()->add_property ("shown", X_("no"));
+               i->second->menu_item->set_active (false);
+       }
+
+       /* Hide processor automation */
+
        for (list<ProcessorAutomationInfo*>::iterator i = processor_automation.begin(); i != processor_automation.end(); ++i) {
                for (vector<ProcessorAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
                        (*ii)->menu_item->set_active (false);
@@ -1605,26 +1632,27 @@ RouteTimeAxisView::hide_all_automation ()
        _show_automation.clear();
 
        no_redraw = false;
-        _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
+        _route->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
 }
 
 
 void
 RouteTimeAxisView::region_view_added (RegionView* rv)
 {
-       for (Children::iterator i = children.begin(); i != children.end(); ++i) {
-               boost::shared_ptr<AutomationTimeAxisView> atv;
-
-               if ((atv = boost::dynamic_pointer_cast<AutomationTimeAxisView> (*i)) != 0) {
-                       rv->add_ghost (*atv.get());
+       /* XXX need to find out if automation children have automationstreamviews. If yes, no ghosts */
+       if(is_audio_track()) {
+               for (Children::iterator i = children.begin(); i != children.end(); ++i) {
+                       boost::shared_ptr<AutomationTimeAxisView> atv;
+                       
+                       if ((atv = boost::dynamic_pointer_cast<AutomationTimeAxisView> (*i)) != 0) {
+                               atv->add_ghost(rv);
+                       }
                }
        }
-}
 
-void
-RouteTimeAxisView::add_ghost_to_processor (RegionView* rv, boost::shared_ptr<AutomationTimeAxisView> atv)
-{
-       rv->add_ghost (*atv.get());
+       for (UnderlayMirrorList::iterator i = _underlay_mirrors.begin(); i != _underlay_mirrors.end(); ++i) {
+               (*i)->add_ghost(rv);
+       }
 }
 
 RouteTimeAxisView::ProcessorAutomationInfo::~ProcessorAutomationInfo ()
@@ -1670,7 +1698,7 @@ static string
 legalize_for_xml_node (string str)
 {
        string::size_type pos;
-       string legal_chars = "abcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_+=:";
+       string legal_chars = "abcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_=:";
        string legal;
 
        legal = str;
@@ -1717,7 +1745,7 @@ RouteTimeAxisView::add_processor_automation_curve (boost::shared_ptr<Processor>
 
        pan->view = boost::shared_ptr<AutomationTimeAxisView>(
                        new AutomationTimeAxisView (_session, _route, processor, control,
-                               editor, *this, parent_canvas, name, state_name));
+                               editor, *this, false, parent_canvas, name, state_name));
 
        pan->view->Hiding.connect (bind (mem_fun(*this, &RouteTimeAxisView::processor_automation_track_hidden), pan, processor));
 
@@ -1730,7 +1758,7 @@ RouteTimeAxisView::add_processor_automation_curve (boost::shared_ptr<Processor>
        add_child (pan->view);
 
        if (_view) {
-               _view->foreach_regionview (bind (mem_fun(*this, &RouteTimeAxisView::add_ghost_to_processor), pan->view));
+               _view->foreach_regionview (mem_fun(*pan->view.get(), &TimeAxisView::add_ghost));
        }
 
        processor->mark_automation_visible (what, true);
@@ -1745,7 +1773,7 @@ RouteTimeAxisView::processor_automation_track_hidden (RouteTimeAxisView::Process
 
        i->mark_automation_visible (pan->what, false);
 
-        _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
+        _route->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
 }
 
 void
@@ -1767,19 +1795,18 @@ RouteTimeAxisView::add_existing_processor_automation_curves (boost::shared_ptr<P
 }
 
 void
-RouteTimeAxisView::add_automation_child(Parameter param, boost::shared_ptr<AutomationTimeAxisView> track)
+RouteTimeAxisView::add_automation_child(Parameter param, boost::shared_ptr<AutomationTimeAxisView> track, bool show)
 {
        using namespace Menu_Helpers;
 
        XMLProperty* prop;
+       XMLNode* node;
 
        add_child (track);
 
        track->Hiding.connect (bind (mem_fun (*this, &RouteTimeAxisView::automation_track_hidden), param));
 
-       bool hideit = false;
-       
-       XMLNode* node;
+       bool hideit = (!show);
 
        if ((node = track->get_state_node()) != 0) {
                if  ((prop = node->property ("shown")) != 0) {
@@ -1788,14 +1815,18 @@ RouteTimeAxisView::add_automation_child(Parameter param, boost::shared_ptr<Autom
                        }
                } 
        }
-       
+
        _automation_tracks.insert(std::make_pair(param, new RouteAutomationNode(param, NULL, track)));
 
        if (hideit) {
                track->hide ();
        } else {
-               _show_automation.insert(param);
-               _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
+               _show_automation.insert (param);
+
+
+               if (!no_redraw) {
+                       _route->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
+               }
        }
 
        build_display_menu();
@@ -1898,7 +1929,7 @@ RouteTimeAxisView::processor_menu_item_toggled (RouteTimeAxisView::ProcessorAuto
                redraw = true;
        }
 
-       if (showit != pan->view->marked_for_display()) {
+       if (pan->view && showit != pan->view->marked_for_display()) {
 
                if (showit) {
                        pan->view->set_marked_for_display (true);
@@ -1917,7 +1948,7 @@ RouteTimeAxisView::processor_menu_item_toggled (RouteTimeAxisView::ProcessorAuto
 
                /* now trigger a redisplay */
                
-                _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
+                _route->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
 
        }
 }
@@ -1926,7 +1957,7 @@ void
 RouteTimeAxisView::processors_changed ()
 {
        using namespace Menu_Helpers;
-
+       
        for (list<ProcessorAutomationInfo*>::iterator i = processor_automation.begin(); i != processor_automation.end(); ++i) {
                (*i)->valid = false;
        }
@@ -1955,7 +1986,7 @@ RouteTimeAxisView::processors_changed ()
 
        /* change in visibility was possible */
 
-       _route->gui_changed ("track_height", this);
+       _route->gui_changed ("visible_tracks", this);
 }
 
 boost::shared_ptr<AutomationLine>
@@ -1987,3 +2018,182 @@ RouteTimeAxisView::update_rec_display ()
        name_entry.set_sensitive (!_route->record_enabled());
 }
                
+void
+RouteTimeAxisView::set_layer_display (LayerDisplay d)
+{
+       _view->set_layer_display (d);
+}
+       
+
+boost::shared_ptr<AutomationTimeAxisView>
+RouteTimeAxisView::automation_child(ARDOUR::Parameter param)
+{
+       AutomationTracks::iterator i = _automation_tracks.find(param);
+       if (i != _automation_tracks.end())
+               return i->second->track;
+       else
+               return boost::shared_ptr<AutomationTimeAxisView>();
+}
+
+void
+RouteTimeAxisView::fast_update ()
+{
+       gm.get_level_meter().update_meters ();
+}
+
+void
+RouteTimeAxisView::hide_meter ()
+{
+       clear_meter ();
+       gm.get_level_meter().hide_meters ();
+}
+
+void
+RouteTimeAxisView::show_meter ()
+{
+       reset_meter ();
+}
+
+void
+RouteTimeAxisView::reset_meter ()
+{
+       if (Config->get_show_track_meters()) {
+               gm.get_level_meter().setup_meters (height-5);
+       } else {
+               hide_meter ();
+       }
+}
+
+void
+RouteTimeAxisView::clear_meter ()
+{
+       gm.get_level_meter().clear_meters ();
+}
+
+void
+RouteTimeAxisView::meter_changed (void *src)
+{
+       ENSURE_GUI_THREAD (bind (mem_fun(*this, &RouteTimeAxisView::meter_changed), src));
+       reset_meter();
+}
+
+void
+RouteTimeAxisView::io_changed (IOChange change, void *src)
+{
+       reset_meter ();
+}
+
+void
+RouteTimeAxisView::build_underlay_menu(Gtk::Menu* parent_menu) {
+       using namespace Menu_Helpers;
+
+       if(!_underlay_streams.empty()) {
+               MenuList& parent_items = parent_menu->items();
+               Menu* gs_menu = manage (new Menu);
+               gs_menu->set_name ("ArdourContextMenu");
+               MenuList& gs_items = gs_menu->items();
+               
+               parent_items.push_back (MenuElem (_("Underlays"), *gs_menu));
+               
+               for(UnderlayList::iterator it = _underlay_streams.begin(); it != _underlay_streams.end(); ++it) {
+                       gs_items.push_back(MenuElem(string_compose(_("Remove \"%1\""), (*it)->trackview().name()),
+                                                   bind(mem_fun(*this, &RouteTimeAxisView::remove_underlay), *it)));
+               }
+       }
+}
+
+bool
+RouteTimeAxisView::set_underlay_state() 
+{
+       if(!underlay_xml_node) {
+               return false;
+       }
+
+       XMLNodeList nlist = underlay_xml_node->children();
+       XMLNodeConstIterator niter;
+       XMLNode *child_node;
+       
+       for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
+               child_node = *niter;
+
+               if(child_node->name() != "Underlay") {
+                       continue;
+               }
+
+               XMLProperty* prop = child_node->property ("id");
+               if(prop) {
+                       PBD::ID id(prop->value());
+
+                       RouteTimeAxisView* v = editor.get_route_view_by_id(id);
+
+                       if(v) {
+                               add_underlay(v->view(), false);
+                       }
+               }
+       }
+
+       return false;
+}
+
+void
+RouteTimeAxisView::add_underlay(StreamView* v, bool update_xml) 
+{
+       if(!v) {
+               return;
+       }
+
+       RouteTimeAxisView& other = v->trackview();
+
+       if(find(_underlay_streams.begin(), _underlay_streams.end(), v) == _underlay_streams.end()) {
+               if(find(other._underlay_mirrors.begin(), other._underlay_mirrors.end(), this) != other._underlay_mirrors.end()) {
+                       fatal << _("programming error: underlay reference pointer pairs are inconsistent!") << endmsg;
+                       /*NOTREACHED*/
+               }
+
+               _underlay_streams.push_back(v);
+               other._underlay_mirrors.push_back(this);
+
+               v->foreach_regionview(mem_fun(*this, &RouteTimeAxisView::add_ghost));
+
+               if(update_xml) {
+                       if(!underlay_xml_node) {
+                               ensure_xml_node();
+                               underlay_xml_node = xml_node->add_child("Underlays");
+                       }
+
+                       XMLNode* node = underlay_xml_node->add_child("Underlay");
+                       XMLProperty* prop = node->add_property("id");
+                       prop->set_value(v->trackview().route()->id().to_s());
+               }
+       }
+}
+
+void
+RouteTimeAxisView::remove_underlay(StreamView* v) 
+{
+       if(!v) {
+               return;
+       }
+
+       UnderlayList::iterator it = find(_underlay_streams.begin(), _underlay_streams.end(), v);
+       RouteTimeAxisView& other = v->trackview();
+
+       if(it != _underlay_streams.end()) {
+               UnderlayMirrorList::iterator gm = find(other._underlay_mirrors.begin(), other._underlay_mirrors.end(), this);
+
+               if(gm == other._underlay_mirrors.end()) {
+                       fatal << _("programming error: underlay reference pointer pairs are inconsistent!") << endmsg;
+                       /*NOTREACHED*/
+               }
+
+               v->foreach_regionview(mem_fun(*this, &RouteTimeAxisView::remove_ghost));
+
+               _underlay_streams.erase(it);
+               other._underlay_mirrors.erase(gm);
+
+               if(underlay_xml_node) {
+                       underlay_xml_node->remove_nodes_and_delete("id", v->trackview().route()->id().to_s());
+               }
+       }
+}
+