update tranzport code
[ardour.git] / gtk2_ardour / route_time_axis.cc
index cb9883b8e6acf9f8835ac5e8272927510eafd6a2..f5f0f1dd103f1031c38e765b87601ead9f16ff51 100644 (file)
@@ -29,6 +29,7 @@
 #include <pbd/error.h>
 #include <pbd/stl_delete.h>
 #include <pbd/whitespace.h>
+#include <pbd/memento_command.h>
 
 #include <gtkmm/menu.h>
 #include <gtkmm/menuitem.h>
@@ -60,8 +61,6 @@
 #include "gui_thread.h"
 #include "keyboard.h"
 #include "playlist_selector.h"
-#include "plugin_selector.h"
-#include "plugin_ui.h"
 #include "point_selection.h"
 #include "prompter.h"
 #include "public_editor.h"
@@ -105,9 +104,6 @@ RouteTimeAxisView::RouteTimeAxisView (PublicEditor& ed, Session& sess, boost::sh
 
        ignore_toggle = false;
 
-       mute_button->set_active (false);
-       solo_button->set_active (false);
-       
        mute_button->set_name ("TrackMuteButton");
        solo_button->set_name ("SoloButton");
        edit_group_button.set_name ("TrackGroupButton");
@@ -119,18 +115,6 @@ RouteTimeAxisView::RouteTimeAxisView (PublicEditor& ed, Session& sess, boost::sh
 
        hide_button.add (*(manage (new Image (get_xpm("small_x.xpm")))));
 
-       solo_button->signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
-       mute_button->signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
-       playlist_button.signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
-       automation_button.signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
-       size_button.signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
-       visual_button.signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
-       hide_button.signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
-
-       solo_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::solo_press), false);
-       solo_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::solo_release), false);
-       mute_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::mute_press), false);
-       mute_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::mute_release), false);
        edit_group_button.signal_button_release_event().connect (mem_fun(*this, &RouteTimeAxisView::edit_click), false);
        playlist_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::playlist_click));
        automation_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::automation_click));
@@ -138,10 +122,13 @@ RouteTimeAxisView::RouteTimeAxisView (PublicEditor& ed, Session& sess, boost::sh
        visual_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::visual_click));
        hide_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::hide_click));
 
+       solo_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::solo_press), false);
+       solo_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::solo_release), false);
+       mute_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::mute_press), false);
+       mute_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::mute_release), false);
+
        if (is_track()) {
-               rec_enable_button->set_active (false);
                rec_enable_button->set_name ("TrackRecordEnableButton");
-               rec_enable_button->signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
                rec_enable_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::rec_enable_press));
                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"));
@@ -186,17 +173,12 @@ RouteTimeAxisView::RouteTimeAxisView (PublicEditor& ed, Session& sess, boost::sh
        /* map current state of the route */
 
        update_diskstream_display ();
-       solo_changed(0);
-       mute_changed(0);
-       //redirects_changed (0);
-       //reset_redirect_automation_curves ();
+       redirects_changed (0);
+       reset_redirect_automation_curves ();
        y_position = -1;
 
-       _route->mute_changed.connect (mem_fun(*this, &RouteUI::mute_changed));
-       _route->solo_changed.connect (mem_fun(*this, &RouteUI::solo_changed));
        _route->redirects_changed.connect (mem_fun(*this, &RouteTimeAxisView::redirects_changed));
        _route->name_changed.connect (mem_fun(*this, &RouteTimeAxisView::route_name_changed));
-       _route->solo_safe_changed.connect (mem_fun(*this, &RouteUI::solo_changed));
 
        if (is_track()) {
 
@@ -216,6 +198,7 @@ RouteTimeAxisView::RouteTimeAxisView (PublicEditor& ed, Session& sess, boost::sh
 
        editor.ZoomChanged.connect (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
        ColorChanged.connect (mem_fun (*this, &RouteTimeAxisView::color_handler));
+
 }
 
 RouteTimeAxisView::~RouteTimeAxisView ()
@@ -251,9 +234,6 @@ RouteTimeAxisView::set_playlist (Playlist *newplaylist)
        assert(pl);
 
        modified_connection.disconnect ();
-       state_changed_connection.disconnect ();
-       
-       state_changed_connection = pl->StateChanged.connect (mem_fun(*this, &RouteTimeAxisView::playlist_state_changed));
        modified_connection = pl->Modified.connect (mem_fun(*this, &RouteTimeAxisView::playlist_modified));
 }
 
@@ -476,7 +456,7 @@ RouteTimeAxisView::build_display_menu ()
 
 
 void
-RouteTimeAxisView::show_timestretch (jack_nframes_t start, jack_nframes_t end)
+RouteTimeAxisView::show_timestretch (nframes_t start, nframes_t end)
 {
        double x1;
        double x2;
@@ -575,46 +555,88 @@ RouteTimeAxisView::set_height (TrackHeight h)
        switch (height_style) {
        case Largest:
                xml_node->add_property ("track_height", "largest");
-               show_name_entry ();
-               hide_name_label ();
-               controls_table.show_all();
                break;
+
        case Large:
                xml_node->add_property ("track_height", "large");
-               show_name_entry ();
-               hide_name_label ();
-               controls_table.show_all();
                break;
+
        case Larger:
                xml_node->add_property ("track_height", "larger");
-               show_name_entry ();
-               hide_name_label ();
-               controls_table.show_all();
                break;
+
        case Normal:
                xml_node->add_property ("track_height", "normal");
+               break;
+
+       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:
                show_name_entry ();
                hide_name_label ();
-               controls_table.show_all();
+
+               mute_button->show();
+               solo_button->show();
+               if (rec_enable_button)
+                       rec_enable_button->show();
+
+               edit_group_button.show();
+               hide_button.show();
+               visual_button.show();
+               size_button.show();
+               automation_button.show();
+               
+               if (is_track() && track()->mode() == ARDOUR::Normal) {
+                       playlist_button.show();
+               }
                break;
+
        case Smaller:
-               xml_node->add_property ("track_height", "smaller");
-               controls_table.show_all ();
                show_name_entry ();
                hide_name_label ();
+
+               mute_button->show();
+               solo_button->show();
+               if (rec_enable_button)
+                       rec_enable_button->show();
+
                edit_group_button.hide ();
                hide_button.hide ();
                visual_button.hide ();
                size_button.hide ();
                automation_button.hide ();
-               playlist_button.hide ();
+               
+               if (is_track() && track()->mode() == ARDOUR::Normal) {
+                       playlist_button.hide ();
+               }
                break;
+
        case Small:
-               xml_node->add_property ("track_height", "small");
-               controls_table.hide_all ();
-               controls_table.show ();
                hide_name_entry ();
                show_name_label ();
+
+               mute_button->hide();
+               solo_button->hide();
+               if (rec_enable_button)
+                       rec_enable_button->hide();
+
+               edit_group_button.hide ();
+               hide_button.hide ();
+               visual_button.hide ();
+               size_button.hide ();
+               automation_button.hide ();
+               playlist_button.hide ();
                name_label.set_text (_route->name());
                break;
        }
@@ -687,7 +709,7 @@ RouteTimeAxisView::rename_current_playlist ()
        ArdourPrompter prompter (true);
        string name;
 
-       Diskstream *const ds = get_diskstream();
+       boost::shared_ptr<Diskstream> ds = get_diskstream();
        if (!ds || ds->destructive())
                return;
 
@@ -718,7 +740,7 @@ RouteTimeAxisView::use_copy_playlist (bool prompt)
 {
        string name;
        
-       Diskstream *const ds = get_diskstream();
+       boost::shared_ptr<Diskstream> ds = get_diskstream();
        if (!ds || ds->destructive())
                return;
 
@@ -759,7 +781,7 @@ RouteTimeAxisView::use_new_playlist (bool prompt)
 {
        string name;
        
-       Diskstream *const ds = get_diskstream();
+       boost::shared_ptr<Diskstream> ds = get_diskstream();
        if (!ds || ds->destructive())
                return;
 
@@ -797,7 +819,7 @@ RouteTimeAxisView::use_new_playlist (bool prompt)
 void
 RouteTimeAxisView::clear_playlist ()
 {
-       Diskstream *const ds = get_diskstream();
+       boost::shared_ptr<Diskstream> ds = get_diskstream();
        if (!ds || ds->destructive())
                return;
 
@@ -837,8 +859,7 @@ RouteTimeAxisView::selection_click (GdkEventButton* ev)
 
        switch (Keyboard::selection_type (ev->state)) {
        case Selection::Toggle:
-               /* XXX this is not right */
-               editor.get_selection().add (*tracks);
+               editor.get_selection().toggle (*tracks);
                break;
                
        case Selection::Set:
@@ -868,7 +889,7 @@ RouteTimeAxisView::set_selected_regionviews (RegionSelection& regions)
 }
 
 void
-RouteTimeAxisView::get_selectables (jack_nframes_t start, jack_nframes_t end, double top, double bot, list<Selectable*>& results)
+RouteTimeAxisView::get_selectables (nframes_t start, nframes_t end, double top, double bot, list<Selectable*>& results)
 {
        double speed = 1.0;
        
@@ -876,8 +897,8 @@ RouteTimeAxisView::get_selectables (jack_nframes_t start, jack_nframes_t end, do
                speed = get_diskstream()->speed();
        }
        
-       jack_nframes_t start_adjusted = session_frame_to_track_frame(start, speed);
-       jack_nframes_t end_adjusted   = session_frame_to_track_frame(end, speed);
+       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)) {
                _view->get_selectables (start_adjusted, end_adjusted, results);
@@ -923,7 +944,7 @@ RouteTimeAxisView::name() const
 Playlist *
 RouteTimeAxisView::playlist () const 
 {
-       Diskstream *ds;
+       boost::shared_ptr<Diskstream> ds;
 
        if ((ds = get_diskstream()) != 0) {
                return ds->playlist(); 
@@ -970,24 +991,24 @@ RouteTimeAxisView::hide_click ()
        editor.hide_track_in_display (*this);
 }
 
-Region*
-RouteTimeAxisView::find_next_region (jack_nframes_t pos, RegionPoint point, int32_t dir)
+boost::shared_ptr<Region>
+RouteTimeAxisView::find_next_region (nframes_t pos, RegionPoint point, int32_t dir)
 {
-       Diskstream *stream;
+       boost::shared_ptr<Diskstream> stream;
        Playlist *playlist;
 
        if ((stream = get_diskstream()) != 0 && (playlist = stream->playlist()) != 0) {
                return playlist->find_next_region (pos, point, dir);
        }
 
-       return 0;
+       return boost::shared_ptr<Region> ();
 }
 
 bool
 RouteTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op)
 {
        Playlist* what_we_got;
-       Diskstream* ds = get_diskstream();
+       boost::shared_ptr<Diskstream> ds = get_diskstream();
        Playlist* playlist;
        bool ret = false;
 
@@ -1008,12 +1029,12 @@ RouteTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op)
                }
        }
        
+       XMLNode &before = playlist->get_state();
        switch (op) {
        case Cut:
-               _session.add_undo (playlist->get_memento());
                if ((what_we_got = playlist->cut (time)) != 0) {
                        editor.get_cut_buffer().add (what_we_got);
-                       _session.add_redo_no_execute (playlist->get_memento());
+                       _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
                        ret = true;
                }
                break;
@@ -1024,9 +1045,8 @@ RouteTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op)
                break;
 
        case Clear:
-               _session.add_undo (playlist->get_memento());
                if ((what_we_got = playlist->cut (time)) != 0) {
-                       _session.add_redo_no_execute (playlist->get_memento());
+                       _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
                        what_we_got->unref ();
                        ret = true;
                }
@@ -1037,7 +1057,7 @@ RouteTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op)
 }
 
 bool
-RouteTimeAxisView::paste (jack_nframes_t pos, float times, Selection& selection, size_t nth)
+RouteTimeAxisView::paste (nframes_t pos, float times, Selection& selection, size_t nth)
 {
        if (!is_track()) {
                return false;
@@ -1055,9 +1075,9 @@ RouteTimeAxisView::paste (jack_nframes_t pos, float times, Selection& selection,
        if (get_diskstream()->speed() != 1.0f)
                pos = session_frame_to_track_frame(pos, get_diskstream()->speed() );
        
-       _session.add_undo (playlist->get_memento());
+       XMLNode &before = playlist->get_state();
        playlist->paste (**p, pos, times);
-       _session.add_redo_no_execute (playlist->get_memento());
+       _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
 
        return true;
 }
@@ -1154,13 +1174,6 @@ RouteTimeAxisView::color_handler (ColorID id, uint32_t val)
        }
 }
 
-bool
-RouteTimeAxisView::select_me (GdkEventButton* ev)
-{
-       editor.get_selection().add (this);
-       return false;
-}
-
 void
 RouteTimeAxisView::show_all_automation ()
 {