fix background of ArdourButtons with no Body
[ardour.git] / gtk2_ardour / editor_drag.cc
index bc640795fddfb49f2c47a067f5574c4ff948a283..d2fd96e685f14943779812d992c706b2c228d091 100644 (file)
@@ -525,12 +525,9 @@ Drag::add_midi_region (MidiTimeAxisView* view, bool commit)
        return boost::shared_ptr<Region>();
 }
 
-struct EditorOrderTimeAxisViewSorter {
+struct PresentationInfoTimeAxisViewSorter {
        bool operator() (TimeAxisView* a, TimeAxisView* b) {
-               RouteTimeAxisView* ra = dynamic_cast<RouteTimeAxisView*> (a);
-               RouteTimeAxisView* rb = dynamic_cast<RouteTimeAxisView*> (b);
-               assert (ra && rb);
-               return ra->route()->order_key () < rb->route()->order_key ();
+               return a->presentation_info().order() < b->presentation_info().order();
        }
 };
 
@@ -546,7 +543,7 @@ RegionDrag::RegionDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<Re
        */
 
        TrackViewList track_views = _editor->track_views;
-       track_views.sort (EditorOrderTimeAxisViewSorter ());
+       track_views.sort (PresentationInfoTimeAxisViewSorter ());
 
        for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
                _time_axis_views.push_back (*i);
@@ -846,7 +843,7 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move)
 
                RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (tv);
                if (!rtv || !rtv->is_track()) {
-                       /* ignore busses early on. we can't move any regions on them */
+                       /* ignore non-tracks early on. we can't move any regions on them */
                } else if (_last_pointer_time_axis_view < 0) {
                        /* Was in the drop-zone, now over a track.
                         * Hence it must be an upward move (from the bottom)
@@ -1397,7 +1394,7 @@ RegionMoveDrag::create_destination_time_axis (boost::shared_ptr<Region> region,
                        if ((Config->get_output_auto_connect() & AutoConnectMaster) && _editor->session()->master_out()) {
                                output_chan =  _editor->session()->master_out()->n_inputs().n_audio();
                        }
-                       audio_tracks = _editor->session()->new_audio_track (region->n_channels(), output_chan, ARDOUR::Normal, 0, 1, region->name());
+                       audio_tracks = _editor->session()->new_audio_track (region->n_channels(), output_chan, 0, 1, region->name(), PresentationInfo::max_order);
                        RouteTimeAxisView* rtav = _editor->axis_view_from_route (audio_tracks.front());
                        if (rtav) {
                                rtav->set_height (original->current_height());
@@ -1406,7 +1403,9 @@ RegionMoveDrag::create_destination_time_axis (boost::shared_ptr<Region> region,
                } else {
                        ChanCount one_midi_port (DataType::MIDI, 1);
                        list<boost::shared_ptr<MidiTrack> > midi_tracks;
-                       midi_tracks = _editor->session()->new_midi_track (one_midi_port, one_midi_port, boost::shared_ptr<ARDOUR::PluginInfo>(), ARDOUR::Normal, 0, 1, region->name());
+                       midi_tracks = _editor->session()->new_midi_track (one_midi_port, one_midi_port, boost::shared_ptr<ARDOUR::PluginInfo>(),
+                                                                         (ARDOUR::Plugin::PresetRecord*) 0,
+                                                                         (ARDOUR::RouteGroup*) 0, 1, region->name(), PresentationInfo::max_order);
                        RouteTimeAxisView* rtav = _editor->axis_view_from_route (midi_tracks.front());
                        if (rtav) {
                                rtav->set_height (original->current_height());
@@ -3274,7 +3273,7 @@ TempoMarkerDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
 void
 TempoMarkerDrag::setup_pointer_frame_offset ()
 {
-       _pointer_frame_offset = raw_grab_frame() - _marker->tempo().frame();
+       _pointer_frame_offset = raw_grab_frame() - _real_section->frame();
 }
 
 void
@@ -3336,42 +3335,16 @@ TempoMarkerDrag::motion (GdkEvent* event, bool first_move)
                show_verbose_cursor_text (strs.str());
 
        } else if (_movable && !_real_section->locked_to_meter()) {
-               TempoMap& map (_editor->session()->tempo_map());
-               const bool was_music = _real_section->position_lock_style() == MusicTime;
-
                const framepos_t pf = adjusted_current_frame (event);
+               TempoMap& map (_editor->session()->tempo_map());
 
-               if (!_editor->snap_musical()) {
-
-                       if (was_music) {
-                               _real_section->set_position_lock_style (AudioTime);
-                       }
-
-                       map.gui_move_tempo (_real_section, pf);
-
-                       if (was_music) {
-                               _real_section->set_position_lock_style (MusicTime);
-                       }
-
-               } else {
-
-                       if (!was_music) {
-                               _real_section->set_position_lock_style (MusicTime);
-                       }
-
-                       map.gui_move_tempo (_real_section, pf);
+               /* snap to beat is 1, snap to bar is -1 (sorry) */
+               int sub_num = _editor->get_grid_music_divisions (event->button.state);
 
-                       if (!was_music) {
-                               _real_section->set_position_lock_style (AudioTime);
-                       }
-               }
+               map.gui_move_tempo (_real_section, pf, sub_num);
 
                show_verbose_cursor_time (_real_section->frame());
        }
-
-       /* this has moved the bar lines themselves, so recalibrate the offset */
-       setup_pointer_frame_offset();
-
        _marker->set_position (adjusted_current_frame (event, false));
 }
 
@@ -3415,7 +3388,6 @@ TempoMarkerDrag::aborted (bool moved)
 BBTRulerDrag::BBTRulerDrag (Editor* e, ArdourCanvas::Item* i)
        : Drag (e, i)
        , _pulse (0.0)
-       , _beat (0.0)
        , _tempo (0)
        , before_state (0)
 {
@@ -3427,11 +3399,10 @@ void
 BBTRulerDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
 {
        Drag::start_grab (event, cursor);
-
        TempoMap& map (_editor->session()->tempo_map());
+       _tempo = const_cast<TempoSection*> (&map.tempo_section_at_frame (raw_grab_frame()));
        ostringstream sstr;
 
-       _tempo = const_cast<TempoSection*> (&map.tempo_section_at_frame (raw_grab_frame()));
        sstr << "^" << fixed << setprecision(3) << map.tempo_at_frame (adjusted_current_frame (event)).beats_per_minute() << "\n";
        sstr << "<" << fixed << setprecision(3) << _tempo->beats_per_minute();
        show_verbose_cursor_text (sstr.str());
@@ -3444,17 +3415,22 @@ BBTRulerDrag::setup_pointer_frame_offset ()
        TempoMap& map (_editor->session()->tempo_map());
        const double beat_at_frame = map.beat_at_frame (raw_grab_frame());
        const uint32_t divisions = _editor->get_grid_beat_divisions (0);
+       double beat = 0.0;
+
        if (divisions > 0) {
-               _beat = floor (beat_at_frame) + (floor (((beat_at_frame - floor (beat_at_frame)) * divisions)) / divisions);
+               beat = floor (beat_at_frame) + (floor (((beat_at_frame - floor (beat_at_frame)) * divisions)) / divisions);
        } else {
                /* while it makes some sense for the user to determine the division to 'grab',
                   grabbing a bar often leads to confusing results wrt the actual tempo section being altered
                   and the result over steep tempo curves. Use sixteenths.
                */
-               _beat = floor (beat_at_frame) + (floor (((beat_at_frame - floor (beat_at_frame)) * 4)) / 4);
+               beat = floor (beat_at_frame) + (floor (((beat_at_frame - floor (beat_at_frame)) * 4)) / 4);
        }
-       _pulse = map.pulse_at_beat (_beat);
-       _pointer_frame_offset = raw_grab_frame() - map.frame_at_beat (_beat);
+
+       _pulse = map.pulse_at_beat (beat);
+
+       _pointer_frame_offset = raw_grab_frame() - map.frame_at_pulse (_pulse);
+
 }
 
 void
@@ -3468,7 +3444,13 @@ BBTRulerDrag::motion (GdkEvent* event, bool first_move)
                _editor->begin_reversible_command (_("dilate tempo"));
        }
 
-       framepos_t const pf = adjusted_current_frame (event);
+       framepos_t pf;
+
+       if (_editor->snap_musical()) {
+               pf = adjusted_current_frame (event, false);
+       } else {
+               pf = adjusted_current_frame (event);
+       }
 
        if (Keyboard::modifier_state_contains (event->button.state, ArdourKeyboard::constraint_modifier())) {
                /* adjust previous tempo to match pointer frame */
@@ -5102,7 +5084,7 @@ SelectionDrag::motion (GdkEvent* event, bool first_move)
                        TrackViewList grouped_add = new_selection;
                        for (TrackViewList::const_iterator i = new_selection.begin(); i != new_selection.end(); ++i) {
                                RouteTimeAxisView *n = dynamic_cast<RouteTimeAxisView *>(*i);
-                               if ( n && n->route()->route_group() && n->route()->route_group()->is_active() && n->route()->route_group()->enabled_property (ARDOUR::Properties::select.property_id) ) {
+                               if ( n && n->route()->route_group() && n->route()->route_group()->is_active() && n->route()->route_group()->enabled_property (ARDOUR::Properties::group_select.property_id) ) {
                                        for (TrackViewList::const_iterator j = all_tracks.begin(); j != all_tracks.end(); ++j) {
                                                RouteTimeAxisView *check = dynamic_cast<RouteTimeAxisView *>(*j);
                                                if ( check && (n != check) && (check->route()->route_group() == n->route()->route_group()) )
@@ -6010,6 +5992,9 @@ void
 PatchChangeDrag::finished (GdkEvent* ev, bool movement_occurred)
 {
        if (!movement_occurred) {
+               if (was_double_click()) {
+                       _region_view->edit_patch_change (_patch_change);
+               }
                return;
        }