Work towards removal of Session's Diskstream list.
[ardour.git] / gtk2_ardour / audio_time_axis.cc
index 42ad1656fadadffe1b5af68db54316f43f745226..ebaf3fdc2cc83467b25ec6966d595a28f1b58fab 100644 (file)
 #include <pbd/stl_delete.h>
 #include <pbd/whitespace.h>
 
-#include <gtkmm2ext/bindable_button.h>
 #include <gtkmm2ext/gtk_ui.h>
 #include <gtkmm2ext/selector.h>
 #include <gtkmm2ext/stop_signal.h>
+#include <gtkmm2ext/bindable_button.h>
 #include <gtkmm2ext/utils.h>
 
 #include <ardour/audioplaylist.h>
-#include <ardour/diskstream.h>
+#include <ardour/audio_diskstream.h>
 #include <ardour/insert.h>
 #include <ardour/ladspa_plugin.h>
 #include <ardour/location.h>
@@ -80,6 +80,7 @@
 #include "i18n.h"
 
 using namespace ARDOUR;
+using namespace PBD;
 using namespace LADSPA;
 using namespace Gtk;
 using namespace Editing;
@@ -119,11 +120,9 @@ AudioTimeAxisView::AudioTimeAxisView (PublicEditor& ed, Session& sess, Route& rt
 
        ignore_toggle = false;
 
-       rec_enable_button->set_active (false);
        mute_button->set_active (false);
        solo_button->set_active (false);
        
-       rec_enable_button->set_name ("TrackRecordEnableButton");
        mute_button->set_name ("TrackMuteButton");
        solo_button->set_name ("SoloButton");
        edit_group_button.set_name ("TrackGroupButton");
@@ -134,16 +133,9 @@ AudioTimeAxisView::AudioTimeAxisView (PublicEditor& ed, Session& sess, Route& rt
        hide_button.set_name ("TrackRemoveButton");
 
        hide_button.add (*(manage (new Image (get_xpm("small_x.xpm")))));
-       
-       _route.mute_changed.connect (mem_fun(*this, &RouteUI::mute_changed));
-       _route.solo_changed.connect (mem_fun(*this, &RouteUI::solo_changed));
-       _route.solo_safe_changed.connect (mem_fun(*this, &RouteUI::solo_changed));
-
-       _route.panner().Changed.connect (mem_fun(*this, &AudioTimeAxisView::update_pans));
 
        solo_button->signal_button_press_event().connect (mem_fun (*this, &AudioTimeAxisView::select_me), false);
        mute_button->signal_button_press_event().connect (mem_fun (*this, &AudioTimeAxisView::select_me), false);
-       rec_enable_button->signal_button_press_event().connect (mem_fun (*this, &AudioTimeAxisView::select_me), false);
        playlist_button.signal_button_press_event().connect (mem_fun (*this, &AudioTimeAxisView::select_me), false);
        automation_button.signal_button_press_event().connect (mem_fun (*this, &AudioTimeAxisView::select_me), false);
        size_button.signal_button_press_event().connect (mem_fun (*this, &AudioTimeAxisView::select_me), false);
@@ -154,7 +146,6 @@ AudioTimeAxisView::AudioTimeAxisView (PublicEditor& ed, Session& sess, Route& rt
        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);
-       rec_enable_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::rec_enable_press));
        edit_group_button.signal_button_release_event().connect (mem_fun(*this, &AudioTimeAxisView::edit_click), false);
        playlist_button.signal_clicked().connect (mem_fun(*this, &AudioTimeAxisView::playlist_click));
        automation_button.signal_clicked().connect (mem_fun(*this, &AudioTimeAxisView::automation_click));
@@ -162,15 +153,26 @@ AudioTimeAxisView::AudioTimeAxisView (PublicEditor& ed, Session& sess, Route& rt
        visual_button.signal_clicked().connect (mem_fun(*this, &AudioTimeAxisView::visual_click));
        hide_button.signal_clicked().connect (mem_fun(*this, &AudioTimeAxisView::hide_click));
 
+       // FIXME: hack (pretty colours)
+       if (is_audio_track())
+               controls_ebox.set_name ("AudioTimeAxisViewControlsBaseUnselected");
+       else
+               controls_ebox.set_name ("MidiTimeAxisViewControlsBaseUnselected");
+
        if (is_audio_track()) {
+               rec_enable_button->set_active (false);
+               rec_enable_button->set_name ("TrackRecordEnableButton");
+               rec_enable_button->signal_button_press_event().connect (mem_fun (*this, &AudioTimeAxisView::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"));
        }
+
        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 (edit_group_button, 6, 7, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
 
-       ARDOUR_UI::instance()->tooltips().set_tip(*rec_enable_button, _("Record"));
        ARDOUR_UI::instance()->tooltips().set_tip(*solo_button,_("Solo"));
        ARDOUR_UI::instance()->tooltips().set_tip(*mute_button,_("Mute"));
        ARDOUR_UI::instance()->tooltips().set_tip(edit_group_button,_("Edit Group"));
@@ -218,8 +220,9 @@ AudioTimeAxisView::AudioTimeAxisView (PublicEditor& ed, Session& sess, Route& rt
        _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, &AudioTimeAxisView::redirects_changed));
-
        _route.name_changed.connect (mem_fun(*this, &AudioTimeAxisView::route_name_changed));
+       _route.solo_safe_changed.connect (mem_fun(*this, &RouteUI::solo_changed));
+       _route.panner().Changed.connect (mem_fun(*this, &AudioTimeAxisView::update_pans));
 
        if (is_audio_track()) {
 
@@ -227,8 +230,8 @@ AudioTimeAxisView::AudioTimeAxisView (PublicEditor& ed, Session& sess, Route& rt
 
                audio_track()->FreezeChange.connect (mem_fun(*this, &AudioTimeAxisView::map_frozen));
 
-               audio_track()->diskstream_changed.connect (mem_fun(*this, &AudioTimeAxisView::diskstream_changed));
-               get_diskstream()->speed_changed.connect (mem_fun(*this, &AudioTimeAxisView::speed_changed));
+               audio_track()->DiskstreamChanged.connect (mem_fun(*this, &AudioTimeAxisView::diskstream_changed));
+               get_diskstream()->SpeedChanged.connect (mem_fun(*this, &AudioTimeAxisView::speed_changed));
 
                controls_ebox.set_name ("AudioTrackControlsBaseUnselected");
                controls_base_selected_name = "AudioTrackControlsBaseSelected";
@@ -245,7 +248,6 @@ AudioTimeAxisView::AudioTimeAxisView (PublicEditor& ed, Session& sess, Route& rt
                map_frozen ();
 
        } else {
-
                /* bus */
 
                controls_ebox.set_name ("BusControlsBaseUnselected");
@@ -354,6 +356,8 @@ AudioTimeAxisView::add_edit_group_menu_item (RouteGroup *eg, RadioMenuItem::Grou
 
        MenuList &items = edit_group_menu.items();
 
+       cerr << "adding edit group called " << eg->name() << endl;
+
        items.push_back (RadioMenuElem (*group, eg->name(), bind (mem_fun(*this, &AudioTimeAxisView::set_edit_group_from_menu), eg)));
        if (_route.edit_group() == eg) {
                static_cast<RadioMenuItem*>(&items.back())->set_active ();
@@ -381,7 +385,7 @@ AudioTimeAxisView::playlist_changed ()
        label_view ();
 
        if (is_audio_track()) {
-               set_playlist (get_diskstream()->playlist());
+               set_playlist (dynamic_cast<AudioPlaylist*>(get_diskstream()->playlist()));
        }
 }
 
@@ -581,7 +585,7 @@ AudioTimeAxisView::set_state (const XMLNode& node)
 void
 AudioTimeAxisView::set_height (TrackHeight h)
 {
-       bool height_changed = (h != height_style);
+       bool height_changed = (height == 0) || (h != height_style);
 
        TimeAxisView::set_height (h);
 
@@ -717,23 +721,23 @@ AudioTimeAxisView::build_display_menu ()
        MenuList& automation_items = automation_action_menu->items();
        automation_action_menu->set_name ("ArdourContextMenu");
        
-       automation_items.push_back (MenuElem (_("show all automation"),
+       automation_items.push_back (MenuElem (_("Show all automation"),
                                              mem_fun(*this, &AudioTimeAxisView::show_all_automation)));
 
-       automation_items.push_back (MenuElem (_("show existing automation"),
+       automation_items.push_back (MenuElem (_("Show existing automation"),
                                              mem_fun(*this, &AudioTimeAxisView::show_existing_automation)));
 
-       automation_items.push_back (MenuElem (_("hide all automation"),
+       automation_items.push_back (MenuElem (_("Hide all automation"),
                                              mem_fun(*this, &AudioTimeAxisView::hide_all_automation)));
 
        automation_items.push_back (SeparatorElem());
 
-       automation_items.push_back (CheckMenuElem (_("gain"), 
+       automation_items.push_back (CheckMenuElem (_("Fader"), 
                                                   mem_fun(*this, &AudioTimeAxisView::toggle_gain_track)));
        gain_automation_item = static_cast<CheckMenuItem*> (&automation_items.back());
        gain_automation_item->set_active(show_gain_automation);
 
-       automation_items.push_back (CheckMenuElem (_("pan"),
+       automation_items.push_back (CheckMenuElem (_("Pan"),
                                                   mem_fun(*this, &AudioTimeAxisView::toggle_pan_track)));
        pan_automation_item = static_cast<CheckMenuItem*> (&automation_items.back());
        pan_automation_item->set_active(show_pan_automation);
@@ -770,12 +774,12 @@ AudioTimeAxisView::build_display_menu ()
 
                RadioMenuItem::Group align_group;
                
-               alignment_items.push_back (RadioMenuElem (align_group, _("align with existing material"), bind (mem_fun(*this, &AudioTimeAxisView::set_align_style), ExistingMaterial)));
+               alignment_items.push_back (RadioMenuElem (align_group, _("Align with existing material"), bind (mem_fun(*this, &AudioTimeAxisView::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, &AudioTimeAxisView::set_align_style), CaptureTime)));
+               alignment_items.push_back (RadioMenuElem (align_group, _("Align with capture time"), bind (mem_fun(*this, &AudioTimeAxisView::set_align_style), CaptureTime)));
                align_capture_item = dynamic_cast<RadioMenuItem*>(&alignment_items.back());
                if (get_diskstream()->alignment_style() == CaptureTime) {
                        align_capture_item->set_active();
@@ -826,15 +830,17 @@ AudioTimeAxisView::rename_current_playlist ()
        string name;
 
        AudioPlaylist *pl;
-       DiskStream *ds;
+       AudioDiskstream *ds;
 
-       if (((ds = get_diskstream()) == 0) || ds->destructive() || ((pl = ds->playlist()) == 0)) {
+       if (((ds = dynamic_cast<AudioDiskstream*>(get_diskstream())) == 0) || ds->destructive()
+                       || ((pl = dynamic_cast<AudioPlaylist*>(ds->playlist())) == 0)) {
                return;
        }
 
        prompter.set_prompt (_("Name for playlist"));
        prompter.set_initial_text (pl->name());
        prompter.add_button (_("Rename"), Gtk::RESPONSE_ACCEPT);
+       prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
 
        switch (prompter.run ()) {
        case Gtk::RESPONSE_ACCEPT:
@@ -853,10 +859,11 @@ void
 AudioTimeAxisView::use_copy_playlist (bool prompt)
 {
        AudioPlaylist *pl;
-       DiskStream *ds;
+       AudioDiskstream *ds;
        string name;
 
-       if (((ds = get_diskstream()) == 0) || ds->destructive() || ((pl = ds->playlist()) == 0)) {
+       if (((ds = dynamic_cast<AudioDiskstream*>(get_diskstream())) == 0) || ds->destructive()
+                       || ((pl = dynamic_cast<AudioPlaylist*>(ds->playlist())) == 0)) {
                return;
        }
        
@@ -869,6 +876,7 @@ AudioTimeAxisView::use_copy_playlist (bool prompt)
                prompter.set_prompt (_("Name for Playlist"));
                prompter.set_initial_text (name);
                prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
+               prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
                prompter.show_all ();
                
                switch (prompter.run ()) {
@@ -883,7 +891,7 @@ AudioTimeAxisView::use_copy_playlist (bool prompt)
 
        if (name.length()) {
                ds->use_copy_playlist ();
-               pl = ds->playlist();
+               pl = dynamic_cast<AudioPlaylist*>(ds->playlist());
                pl->set_name (name);
        }
 }
@@ -892,10 +900,11 @@ void
 AudioTimeAxisView::use_new_playlist (bool prompt)
 {
        AudioPlaylist *pl;
-       DiskStream *ds;
+       AudioDiskstream *ds;
        string name;
 
-       if (((ds = get_diskstream()) == 0) || ds->destructive() || ((pl = ds->playlist()) == 0)) {
+       if (((ds = dynamic_cast<AudioDiskstream*>(get_diskstream())) == 0) || ds->destructive()
+                       || ((pl = dynamic_cast<AudioPlaylist*>(ds->playlist())) == 0)) {
                return;
        }
        
@@ -908,6 +917,7 @@ AudioTimeAxisView::use_new_playlist (bool prompt)
                prompter.set_prompt (_("Name for Playlist"));
                prompter.set_initial_text (name);
                prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
+               prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
                
                switch (prompter.run ()) {
                case Gtk::RESPONSE_ACCEPT:
@@ -921,7 +931,7 @@ AudioTimeAxisView::use_new_playlist (bool prompt)
 
        if (name.length()) {
                ds->use_new_playlist ();
-               pl = ds->playlist();
+               pl = dynamic_cast<AudioPlaylist*>(ds->playlist());
                pl->set_name (name);
        }
 }
@@ -930,10 +940,10 @@ void
 AudioTimeAxisView::clear_playlist ()
 {
        AudioPlaylist *pl;
-       DiskStream *ds;
+       AudioDiskstream *ds;
        
-       if ((ds = get_diskstream()) != 0) {
-               if ((pl = ds->playlist()) != 0) {
+       if ((ds = dynamic_cast<AudioDiskstream*>(get_diskstream())) != 0) {
+               if ((pl = dynamic_cast<AudioPlaylist*>(ds->playlist())) != 0) {
                        editor.clear_playlist (*pl);
                }
        }
@@ -988,10 +998,10 @@ AudioTimeAxisView::diskstream_changed (void *src)
 void
 AudioTimeAxisView::update_diskstream_display ()
 {
-       DiskStream *ds;
+       AudioDiskstream *ds;
 
-       if ((ds = get_diskstream()) != 0) {
-               set_playlist (ds->playlist ());
+       if ((ds = dynamic_cast<AudioDiskstream*>(get_diskstream())) != 0) {
+               set_playlist (dynamic_cast<AudioPlaylist*> (ds->playlist ()));
        }
 
        map_frozen ();
@@ -1048,7 +1058,7 @@ AudioTimeAxisView::get_selectables (jack_nframes_t start, jack_nframes_t end, do
        jack_nframes_t start_adjusted = session_frame_to_track_frame(start, speed);
        jack_nframes_t end_adjusted   = session_frame_to_track_frame(end, speed);
 
-       if (view && touched (top, bot)) {
+       if (view && ((top < 0.0 && bot < 0.0)) || touched (top, bot)) {
                view->get_selectables (start_adjusted, end_adjusted, results);
        }
 
@@ -1092,7 +1102,7 @@ AudioTimeAxisView::name() const
 Playlist *
 AudioTimeAxisView::playlist () const 
 {
-       DiskStream *ds;
+       Diskstream *ds;
 
        if ((ds = get_diskstream()) != 0) {
                return ds->playlist(); 
@@ -1139,11 +1149,17 @@ AudioTimeAxisView::hide_click ()
        editor.hide_track_in_display (*this);
 }
 
+ARDOUR::AudioDiskstream*
+AudioTimeAxisView::get_diskstream() const
+{
+       return dynamic_cast<ARDOUR::AudioDiskstream*>(RouteUI::get_diskstream());
+}
+
 Region*
 AudioTimeAxisView::find_next_region (jack_nframes_t pos, RegionPoint point, int32_t dir)
 {
-       DiskStream *stream;
-       AudioPlaylist *playlist;
+       Diskstream *stream;
+       Playlist *playlist;
 
        if ((stream = get_diskstream()) != 0 && (playlist = stream->playlist()) != 0) {
                return playlist->find_next_region (pos, point, dir);
@@ -1717,7 +1733,7 @@ bool
 AudioTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op)
 {
        Playlist* what_we_got;
-       DiskStream* ds = get_diskstream();
+       AudioDiskstream* ds = dynamic_cast<AudioDiskstream*>(get_diskstream());
        Playlist* playlist;
        bool ret = false;
 
@@ -1875,7 +1891,6 @@ AudioTimeAxisView::map_frozen ()
 
        ENSURE_GUI_THREAD (mem_fun(*this, &AudioTimeAxisView::map_frozen));
 
-
        switch (audio_track()->freeze_state()) {
        case AudioTrack::Frozen:
                playlist_button.set_sensitive (false);